acammies
2018-04-04 1f415e2892158066c2fd16c6698383427f1a203c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
  <div>
    <md-list>
      <!-- TODO - change to an actual KEY when i connect to the DB -->
      <div v-for="item in todos" :key="item.id" >
        <TodoItem
          :todoItem=item
        ></TodoItem>
      </div>
    </md-list>
    <XofYitems />
    <div class="xofyDone">
      <span>{{sumDoneTodoItems(todos)}} out of {{this.todos.length}} done. </span>
      <button v-on:click="clearDoneTodos()">CLEAR DONE</button>
      <button v-on:click="clearTodos()">CLEAR ALL</button>
    </div>
  </div>
</template>
 
 
<script>
import TodoItem from "@/components/TodoItem.vue";
import XofYitems from "@/components/XofYitems.vue";
import EventBus from "@/services/EventBus";
import { mapGetters } from "vuex";
 
export default {
  name: "ListOfTodos",
  props: {},
  components: {
    TodoItem,
    XofYitems
  },
  computed: {
    ...mapGetters(["todos"])
  },
  // data () {
  // return {
  //   todos: [{
  //     title: 'Have a poop',
  //     id: '123',
  //     complete: true
  //   },{
  //     title: 'Learn Vue JS',
  //     id: '132',
  //     complete: true
  //   },{
  //     title: 'Love DevOps',
  //     id: '321',
  //     complete: false
  //   }]
  // }
  // },
  created() {
    const self = this;
    // EventBus.$on("NEWTODOADDED", function(todo) {
    //   console.info("INFO - NEWTODOADDED received ", todo);
    //   self.todos.push(todo);
    // });
  },
  methods: {
    // updateTodoList(todo) {
    //   this.todos.push(todo);
    // },
    sumDoneTodoItems(todos) {
      return todos.reduce(
        (result, tdItem) => (tdItem.complete ? result + 1 : result),
        0
      );
    },
    clearDoneTodos() {
      this.$store.dispatch("clearAllDoneTodos");
    },
    clearTodos() {
      this.$store.dispatch("clearAllTodos");
    }
  }
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.xofyDone {
  display: inline-block;
}
</style>