diff --git a/src/todolist.js b/src/todolist.js new file mode 100644 index 0000000000000000000000000000000000000000..88506396e6f572b01ba54c4151c457a575671e13 --- /dev/null +++ b/src/todolist.js @@ -0,0 +1,68 @@ +Vue.component('togglebutton', { + props: ['label', 'name'], + template: `
`, + model: { + prop: 'checked', + event: 'change' + }, + data: function() { + return { + isactive:false + } + }, + methods: { + onToogle: function() { + this.$emit('clicked', this.isactive) + } + } + }); + + var todolist = new Vue({ + el: '#todolist', + data: { + newitem:'', + sortByStatus:false, + todo: [ + { id:1, label: "Learn VueJs", done: true }, + { id:2, label: "Code a todo list", done: false }, + { id:3, label: "Learn something else", done: false } + ] + }, + methods: { + addItem: function() { + this.todo.push({id: Math.floor(Math.random() * 9999) + 10, label: this.newitem, done: false}); + this.newitem = ''; + }, + markAsDoneOrUndone: function(item) { + item.done = !item.done; + }, + deleteItemFromList: function(item) { + let index = this.todo.indexOf(item) + this.todo.splice(index, 1); + }, + clickontoogle: function(active) { + this.sortByStatus = active; + } + }, + computed: { + todoByStatus: function() { + + if(!this.sortByStatus) { + return this.todo; + } + + var sortedArray = [] + var doneArray = this.todo.filter(function(item) { return item.done; }); + var notDoneArray = this.todo.filter(function(item) { return !item.done; }); + + sortedArray = [...notDoneArray, ...doneArray]; + return sortedArray; + } + } + }); \ No newline at end of file