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

Ember Frontend Developer Challenge #5

Open
wants to merge 3 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
12 changes: 6 additions & 6 deletions app/components/single-task.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</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' this.togglePin}}>
{{if this.isPinned "Unpin" "Pin"}}
</BsButton>
<ToggleComplete @onToggle={{this.toggleComplete}}>
{{if this.task.isComplete "Undo" "Done"}}
</ToggleComplete>
</div>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions app/components/single-task.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import Component from '@ember/component';
import { tagName } from '@ember-decorators/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

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

constructor() {
super(...arguments);
this.isPinned = false;
}

@action
togglePin() {
this.isPinned = !this.isPinned;
this.task.isNotPinned = !this.isPinned;
this.onPinSentUp(this.task);
}

@action
toggleComplete() {
this.task.isComplete = !this.task.isComplete;
}
}
4 changes: 3 additions & 1 deletion app/components/task-list.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="card">
<ul class="list-group list-group-flush">
{{#each this.tasks as |task|}}
<SingleTask @task={{task}} />
{{#if task.isNotPinned }}
<SingleTask @task={{task}} @onPinSentUp={{this.receivedPinAction}}/>
{{/if}}
{{/each}}
</ul>
</div>
5 changes: 5 additions & 0 deletions app/components/task-list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Component from '@ember/component';
import { tagName } from '@ember-decorators/component';
import { action } from '@ember/object';

export default
@tagName('')
class TaskListComponent extends Component {
@action
receivedPinAction() {
this.onPinSentUp(arguments[0]);
}
}
3 changes: 3 additions & 0 deletions app/components/toggle-complete.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<BsButton @type="primary" {{on 'click' @onToggle}}>
{{yield}}
</BsButton>
20 changes: 20 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class IndexController extends Controller {
@tracked pinnedTask = null;

@action
receivedPinAction() {
if(this.pinnedTask == null) { // pin a task if there is no current pinned task
this.pinnedTask = arguments[0];
} else if(this.pinnedTask.id == arguments[0].id){ // unpinning a task
this.pinnedTask = null;
} else { // replacing the current pinned task
this.pinnedTask.isNotPinned = true;
this.pinnedTask = arguments[0];
}
}

@computed("model.@each.isComplete")
get completedTasks() {
return this.model.filterBy('isComplete', true).length;
}
}
3 changes: 3 additions & 0 deletions app/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export default class TaskModel extends Model {

@attr('boolean')
isComplete

@attr('boolean', { defaultValue: true })
isNotPinned
}
23 changes: 2 additions & 21 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>
<SingleTask @isPinned={{true}} @task={{this.pinnedTask}} @onPinSentUp={{this.receivedPinAction}}/>
{{else}}
No Pinned Tasks
{{/if}}
<h4>Other Tasks</h4>
<TaskList @tasks={{this.model}} />
<TaskList @tasks={{this.model}} @onPinSentUp={{this.receivedPinAction}}/>

<nav class="navbar navbar-light bg-light">
<span class="navbar-text">
Expand Down
Loading