Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend Developer Challenge #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try


/.idea/
13 changes: 7 additions & 6 deletions app/components/single-task.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
</h5>
<div class="toggle-done ml-auto">
<div class="btn-group btn-group-sm" role="group">
<BsButton @type="secondary">Pin</BsButton>
{{#if this.task.isComplete}}
<BsButton @type="primary" onClick={{action (mut this.task.isComplete) false}}>Undo</BsButton>
{{else}}
<BsButton @type="primary" onClick={{action (mut this.task.isComplete) true}}>Done</BsButton>
{{/if}}
<BsButton @type="secondary" {{on "click" (fn @toggleTaskPin this.task)}}>
{{if this.task.isPinned "Unpin" "Pin" }}
</BsButton>

<ToggleComplete @toggleComplete={{this.toggleComplete}} @isComplete={{this.task.isComplete}}>
</ToggleComplete>

</div>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions app/components/single-task.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import Component from '@ember/component';
import { tagName } from '@ember-decorators/component';
import {tagName} from '@ember-decorators/component';
import {action} from '@ember/object';

export default
export default
@tagName('')
class SingleTaskComponent extends Component {

@action
toggleComplete(complete) {
this.task.isComplete = !complete;
}

}
2 changes: 1 addition & 1 deletion app/components/task-list.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="card">
<ul class="list-group list-group-flush">
{{#each this.tasks as |task|}}
<SingleTask @task={{task}} />
<SingleTask @task={{task}} @toggleTaskPin={{this.toggleTaskPin}}/>
{{/each}}
</ul>
</div>
4 changes: 4 additions & 0 deletions app/components/toggle-complete.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<BsButton @type="primary" {{on "click" (fn @toggleComplete @isComplete)}}>
{{if @isComplete "Undo" "Done"}}
</BsButton>
29 changes: 29 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
import Controller from '@ember/controller';
import {action} from '@ember/object';
import {filterBy} from '@ember/object/computed';

export default class IndexController extends Controller {

isPinnedTask = false;

@action
toggleTaskPin(task) {
task.toggleProperty('isPinned');
}

@filterBy('model', 'isPinned', true) pinnedTasks; //computed property using filterBy decorator


get unpinnedTasks() {
/**
* Filter unpinned tasks from tasks model
* returns @computed property : all task where isPinned key doesn't exit or it's value is false
*/
return [...this.model.filterBy('isPinned', undefined),
...this.model.filterBy('isPinned', false)];
}

get completedTasks() {
/**
* Get the total count of completed tasks
* returns @number: count of all tasks marked as complete
*/
return this.model.filterBy('isComplete').length;
}
}
25 changes: 3 additions & 22 deletions app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
<h1>Task List</h1>
<h4>Pinned Task</h4>
{{#if this.pinnedTask}}
<div class="list-group-item {{if this.pinnedTask.isComplete "is-complete"}}">
<div class="d-flex">
<h5 class="card-title flex-fill">
{{this.pinnedTask.name}}
</h5>
<div class="toggle-done ml-auto">
<div class="btn-group btn-group-sm" role="group">
<BsButton @type="secondary">Unpin</BsButton>
{{#if this.pinnedTask.isComplete}}
<BsButton @type="primary">Undo</BsButton>
{{else}}
<BsButton @type="primary">Done</BsButton>
{{/if}}
</div>
</div>
</div>
<div class="task-description">
{{this.pinnedTask.description}}
</div>
</div>
{{#if this.pinnedTasks}}
<TaskList @tasks={{this.pinnedTasks}} @toggleTaskPin={{this.toggleTaskPin}} />
{{else}}
No Pinned Tasks
{{/if}}
<h4>Other Tasks</h4>
<TaskList @tasks={{this.model}} />
<TaskList @tasks={{this.unpinnedTasks}} @toggleTaskPin={{this.toggleTaskPin}}/>

<nav class="navbar navbar-light bg-light">
<span class="navbar-text">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"engines": {
"node": "8.* || >= 10.*"
}
}
}