Skip to content

Commit

Permalink
Store subtasks in task
Browse files Browse the repository at this point in the history
  • Loading branch information
raimund-schluessler committed Nov 12, 2018
1 parent e07ea8f commit ecdcb82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/Task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
@keyup.27="showSubtaskInput = false">
</form>
</li>
<task-body-component v-for="subtask in subTasks(task)"
<task-body-component v-for="subtask in task.subTasks"
:key="subtask.uid"
:task="subtask" :base-url="baseUrl"
class="subtask" />
Expand All @@ -119,7 +119,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<script>
import { overdue, valid } from '../store/storeHelper'
import clickOutside from 'vue-click-outside'
import { mapActions, mapGetters } from 'vuex'
import { mapActions } from 'vuex'

export default {
name: 'TaskBodyComponent',
Expand Down Expand Up @@ -160,7 +160,7 @@ export default {
isAddingTask: false
}
},
computed: Object.assign({
computed: {
iconStar: function() {
if (this.task.priority > 5) {
return 'icon-task-star-low'
Expand All @@ -169,11 +169,8 @@ export default {
} else if (this.task.priority > 0 && this.task.priority < 5) {
return 'icon-task-star-high'
}
} },
mapGetters({
subTasks: 'getTasksByParent'
})
),
}
},
methods: Object.assign(
mapActions([
'toggleCompleted',
Expand Down
2 changes: 2 additions & 0 deletions src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default class Task {
this.calendar = calendar
this.vCalendar = new ICAL.Component(this.jCal)

this.subTasks = {}

// used to state a task is not up to date with
// the server and cannot be pushed (etag)
this.conflict = false
Expand Down
11 changes: 11 additions & 0 deletions src/store/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ const actions = {
Vue.set(task, 'dav', item)
return task
})

// Initialize subtasks so we don't have to search for them on every change.
// We do have to manually adjust this list when a task is added, deleted or moved.
tasks.forEach(
parent => {
parent.subTasks = tasks.filter(task => {
return task.related === parent.uid
})
}
)

context.commit('appendTasksToCalendar', { calendar, tasks })
context.commit('appendTasks', tasks)
return tasks
Expand Down

0 comments on commit ecdcb82

Please sign in to comment.