Skip to content

Commit

Permalink
Add Add completing todo
Browse files Browse the repository at this point in the history
  • Loading branch information
tackeyy committed Jun 18, 2017
1 parent a44ea7e commit 51559fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/components/Todo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
</div>
</div>
</div>
<div class='ui bottom attached green basic button' v-show="!isEditing &&todo.done" disabled>
Completed
<div class='ui bottom attached green basic button' v-show="!isEditing && todo.done" disabled>
Completed
</div>
<div class='ui bottom attached red basic button' v-show="!isEditing && !todo.done">
Pending
<div class='ui bottom attached red basic button' v-on:click="completeTodo(todo)" v-show="!isEditing && !todo.done">
Pending
</div>
</div>
</template>
Expand All @@ -51,6 +51,9 @@
}
},
methods: {
completeTodo(todo) {
this.$emit('complete-todo', todo);
},
deleteTodo(todo) {
this.$emit('delete-todo', todo)
},
Expand Down
7 changes: 6 additions & 1 deletion src/components/TodoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<p class="tasks">完了したタスク: {{ todos.filter(todo => { return todo.done === true }).length }}</p>
<p class="tasks">未完了のタスク: {{ todos.filter(todo => { return todo.done === false }).length}}</p>
<todo v-on:delete-todo="deleteTodo" v-for="todo in todos" v-bind:todo="todo"></todo>
<todo v-on:delete-todo="deleteTodo" v-on:complete-todo="completeTodo" v-for="todo in todos" v-bind:todo="todo"></todo>
</div>
</template>

Expand Down Expand Up @@ -31,6 +31,11 @@ export default {
this.todos.splice(todoIndex, 1);
sweetalert('Deleted!', 'Your To-Do has been deleted.', 'success');
});
},
completeTodo(todo) {
const todoIndex = this.todos.indexOf(todo)
this.todos[todoIndex].done = true
sweetalert('Success!', 'To-Do completed!', 'success')
}
}
}
Expand Down

0 comments on commit 51559fe

Please sign in to comment.