Skip to content

Commit 6ac1a52

Browse files
authored
Merge pull request #7 from vycoder/feature/project-selection-when-adding-new-task
🛠️ Included Project within New Task
2 parents e5addaf + 584c2ee commit 6ac1a52

File tree

7 files changed

+61
-13
lines changed

7 files changed

+61
-13
lines changed

lib/commons/OpusDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</q-footer>
3030

3131
<q-page-container>
32-
<q-page padding>
32+
<q-page class="q-px-sm q-pb-none">
3333
<q-card flat>
3434
<slot></slot>
3535
</q-card>

src/api/tasks.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { toJSON } from './helpers'
66
export const createTask = async ({
77
name,
88
description,
9+
project,
910
urgent = false,
1011
important = false,
1112
timestamp = Date.now()
@@ -14,6 +15,7 @@ export const createTask = async ({
1415
id: uid(),
1516
name,
1617
description,
18+
project,
1719
urgent,
1820
important,
1921
progress: 0,

src/components/projects/EditProjectDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export default {
140140
showNewTaskDialog () {
141141
this.$q.dialog({
142142
component: NewTaskDialog,
143-
parent: this
143+
parent: this,
144+
noProjectInput: true
144145
}).onOk(this.addTask)
145146
},
146147
addTask (task) {

src/components/projects/NewProjectDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ export default {
111111
showNewTaskDialog () {
112112
this.$q.dialog({
113113
component: NewTaskDialog,
114-
parent: this
114+
parent: this,
115+
noProjectInput: true
115116
}).onOk(this.addTask)
116117
},
117118
addTask (task) {

src/components/tasks/EditTaskDialog.vue

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/>
1515
</template>
1616
<template>
17-
<q-card-section class="column q-gutter-y-lg">
17+
<q-card-section class="column q-gutter-y-md">
1818
<q-input
1919
v-model.trim="model.name"
2020
:placeholder="task.name"
@@ -33,6 +33,18 @@
3333
counter
3434
hide-bottom-space
3535
/>
36+
<q-select
37+
v-if="allProjects.length"
38+
v-model="model.project"
39+
:options="allProjects"
40+
:placeholder="task.project"
41+
label="Project Name"
42+
option-value="id"
43+
option-label="name"
44+
emit-value map-options
45+
clearable clear-icon="clear"
46+
hint="Move to a different project?"
47+
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'"/>
3648
<div class="column q-pt-md">
3749
<div class="q-field__label q-mb-sm">Task Priority</div>
3850
<div class="column">
@@ -48,7 +60,7 @@
4860
import UseOpusDialog from 'lib/commons/opus-dialog-functions'
4961
import OpusDialog from 'lib/commons/OpusDialog'
5062
51-
import { mapActions } from 'vuex'
63+
import { mapActions, mapGetters } from 'vuex'
5264
5365
export default {
5466
name: 'EditTaskDialog',
@@ -64,16 +76,19 @@ export default {
6476
return {
6577
model: {
6678
name: '',
79+
project: '',
6780
description: '',
6881
urgent: false,
6982
important: false
7083
}
7184
}
7285
},
7386
computed: {
87+
...mapGetters('projects', ['allProjects']),
7488
hasChanged () {
7589
return this.model.name !== this.task.name ||
7690
this.model.description !== this.task.description ||
91+
this.model.project !== this.task.project ||
7792
this.model.urgent !== this.task.urgent ||
7893
this.model.important !== this.task.important
7994
}
@@ -82,11 +97,15 @@ export default {
8297
...mapActions('tasks', ['updateTask']),
8398
initialize (task) {
8499
if (task) {
85-
const { name, description, urgent, important } = task
86-
this.model = { name, description, urgent, important }
100+
const { name, description, project, urgent, important } = task
101+
this.model = { name, description, project, urgent, important }
87102
}
88103
},
89104
async save () {
105+
// the task schema is not nullable,
106+
// QSelect sets it to null when cleared,
107+
// Overriding to an empty string
108+
this.model.project = this.model.project || ''
90109
await this.updateTask({ id: this.task.id, update: this.model })
91110
this.$emit('ok')
92111
this.hide()
@@ -95,6 +114,7 @@ export default {
95114
this.model = {
96115
name: '',
97116
description: '',
117+
project: '',
98118
urgent: false,
99119
important: false
100120
}

src/components/tasks/NewTaskDialog.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/>
1515
</template>
1616
<template>
17-
<q-card-section class="column q-gutter-y-lg">
17+
<q-card-section class="column q-gutter-y-md">
1818
<q-input
1919
v-model.trim="model.name"
2020
label="Task Name"
@@ -33,6 +33,17 @@
3333
counter
3434
hide-bottom-space
3535
/>
36+
<q-select
37+
v-if="isProjectSelectionEnabled"
38+
v-model="projectSelection"
39+
:options="allProjects"
40+
label="Project Name"
41+
option-value="id"
42+
option-label="name"
43+
emit-value map-options
44+
clearable clear-icon="clear"
45+
hint="Add to existing project (Optional)"
46+
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'"/>
3647
<div class="column q-pt-md">
3748
<div class="q-field__label q-mb-sm">Task Priority</div>
3849
<div class="column">
@@ -48,14 +59,18 @@
4859
import UseOpusDialog from 'lib/commons/opus-dialog-functions'
4960
import OpusDialog from 'lib/commons/OpusDialog'
5061
51-
import { mapActions } from 'vuex'
62+
import { mapActions, mapGetters } from 'vuex'
5263
5364
export default {
5465
name: 'NewTaskDialog',
5566
mixins: [UseOpusDialog],
5667
components: { OpusDialog },
68+
props: {
69+
noProjectInput: { type: Boolean, default: false }
70+
},
5771
data () {
5872
return {
73+
projectSelection: '',
5974
model: {
6075
name: '',
6176
description: '',
@@ -64,10 +79,19 @@ export default {
6479
}
6580
}
6681
},
82+
computed: {
83+
...mapGetters('projects', ['allProjects']),
84+
isProjectSelectionEnabled () {
85+
return !this.noProjectInput && this.allProjects.length
86+
}
87+
},
6788
methods: {
6889
...mapActions('tasks', ['createTask']),
6990
async save () {
70-
const task = await this.createTask(this.model)
91+
const payload = this.isProjectSelectionEnabled && this.projectSelection
92+
? { ...this.model, project: this.projectSelection }
93+
: { ...this.model }
94+
const task = await this.createTask(payload)
7195
this.$emit('ok', task)
7296
this.hide()
7397
this.clear()
@@ -79,6 +103,7 @@ export default {
79103
urgent: false,
80104
important: false
81105
}
106+
this.projectSelection = null
82107
}
83108
}
84109
}

src/pages/desktop/Projects.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
</q-list>
99
<q-list
1010
v-if="projects.length"
11-
class="q-px-sm column q-gutter-y-sm">
11+
class="q-px-sm column q-gutter-y-xs">
1212
<project-item
1313
v-for="project in projects"
1414
@click="selectedProject = project"
1515
:key="project.id"
1616
:project="project"
1717
hide-breakdown flat
18-
bg-color="none"
19-
class="q-py-md">
18+
bg-color="none">
2019
<template v-slot:title="{ project }">
2120
<div class="text-subtitle2 text-black ellipsis">
2221
{{ project.name }}

0 commit comments

Comments
 (0)