5
5
<template >
6
6
<div ref =" taskTypeSelect"
7
7
class =" task-type-select" >
8
- <NcActions v-for =" variants in buttonTypesByInlineStatus.inline"
9
- :key =" variants.id"
10
- :force-menu =" true"
11
- :menu-name =" variants.text"
12
- :container =" $refs.taskTypeSelect"
13
- :primary =" selectedCategory(variants)"
14
- @click =" onMenuCategorySelected(variants.id, variants.tasks)" >
15
- <NcActionButton v-for =" t in variants.tasks"
16
- :key =" t.id"
17
- :disabled =" selectedTask(t)"
18
- :title =" t.description"
19
- :close-after-click =" true"
20
- @click =" onTaskSelected(t)" >
8
+ <template v-for =" variants in buttonTypesByInlineStatus .inline " >
9
+ <NcActions v-if =" hasSubMenu(variants)"
10
+ :key =" variants.id"
11
+ :force-menu =" true"
12
+ :menu-name =" variants.text"
13
+ :container =" $refs.taskTypeSelect"
14
+ :primary =" isCategorySelected(variants)"
15
+ @click =" onMenuCategorySelected(variants)" >
16
+ <NcActionButton v-for =" t in variants.tasks"
17
+ :key =" t.id"
18
+ :disabled =" selectedTask(t)"
19
+ :title =" t.description"
20
+ :close-after-click =" true"
21
+ @click =" onTaskSelected(t)" >
22
+ <template #icon >
23
+ <div style =" width : 16px " />
24
+ </template >
25
+ {{ t.name }}
26
+ </NcActionButton >
21
27
<template #icon >
22
- <div style = " width : 16 px " />
28
+ <component :is = " variants.icon " />
23
29
</template >
24
- {{ t.name }}
25
- </NcActionButton >
26
- <template #icon >
27
- <component :is =" variants.icon" />
28
- </template >
29
- </NcActions >
30
+ </NcActions >
31
+ <NcButton v-else
32
+ :key =" variants.id + '-button'"
33
+ :variant =" isCategorySelected(variants) ? 'primary' : 'secondary'"
34
+ :title =" variants.text"
35
+ @click =" onMenuCategorySelected(variants)" >
36
+ <template #icon >
37
+ <component :is =" variants.icon" />
38
+ </template >
39
+ {{ variants.text }}
40
+ </NcButton >
41
+ </template >
30
42
<NcActions
31
43
:force-menu =" true"
32
44
:container =" $refs.taskTypeSelect"
36
48
:key =" variant.id"
37
49
:is-menu =" variant.tasks.length > 1 || variant.id === 'other'"
38
50
:title =" variant.text"
39
- @click =" onMenuCategorySelected(variant.id, variant.tasks )" >
51
+ @click =" onMenuCategorySelected(variant)" >
40
52
<template #icon >
41
53
<component :is =" variant.icon" />
42
54
</template >
62
74
63
75
<script >
64
76
import NcActions from ' @nextcloud/vue/components/NcActions'
77
+ import NcButton from ' @nextcloud/vue/components/NcButton'
65
78
import NcActionButton from ' @nextcloud/vue/components/NcActionButton'
66
79
import MessageOutlineIcon from ' vue-material-design-icons/MessageOutline.vue'
67
80
import DotsHorizontalIcon from ' vue-material-design-icons/DotsHorizontal.vue'
@@ -79,6 +92,7 @@ export default {
79
92
NcActions,
80
93
NcActionButton,
81
94
MessageOutlineIcon,
95
+ NcButton,
82
96
},
83
97
84
98
props: {
@@ -124,15 +138,15 @@ export default {
124
138
taskTypes[type].push (task)
125
139
}
126
140
const result = []
127
- for (const part of Object .entries (taskTypes)) {
128
- if (part [0 ] === ' other' ) {
141
+ for (const entry of Object .entries (taskTypes)) {
142
+ if (entry [0 ] === ' other' ) {
129
143
continue
130
144
}
131
145
result .push ({
132
- id: part [0 ],
133
- text: this .getTextForCategory (part [0 ]),
134
- icon: this .getCategoryIcon (part [0 ]),
135
- tasks: part [1 ],
146
+ id: entry [0 ],
147
+ text: this .getTextForCategory (entry [0 ]),
148
+ icon: this .getCategoryIcon (entry [0 ]),
149
+ tasks: entry [1 ],
136
150
})
137
151
}
138
152
// Ensure the "other" category is always last
@@ -150,20 +164,20 @@ export default {
150
164
if (this .onlyInline ) {
151
165
return { inline: this .buttonTypes , overflow: [] }
152
166
}
153
- const inline = this .buttonTypes .slice (0 , this .inline )
154
- let overflow = this .buttonTypes .slice (this .inline )
167
+ const inlineButtonTypes = this .buttonTypes .slice (0 , this .inline )
168
+ let overflowButtonTypes = this .buttonTypes .slice (this .inline )
155
169
156
170
// Ensure that the selection is never inline otherwise swap with the last uninlined category
157
- const selection = overflow .find (t => this .selectedCategory (t))
171
+ const selection = overflowButtonTypes .find (t => this .isCategorySelected (t))
158
172
if (selection) {
159
- const removal = inline .pop ()
160
- inline .push (selection)
161
- overflow = overflow .filter (t => t .id !== selection .id )
173
+ const removal = inlineButtonTypes .pop ()
174
+ inlineButtonTypes .push (selection)
175
+ overflowButtonTypes = overflowButtonTypes .filter (t => t .id !== selection .id )
162
176
if (removal) {
163
- overflow .unshift (removal)
177
+ overflowButtonTypes .unshift (removal)
164
178
}
165
179
}
166
- return { overflow, inline }
180
+ return { overflow: overflowButtonTypes , inline: inlineButtonTypes }
167
181
},
168
182
categorySubMenuTaskType () {
169
183
return this .buttonTypesByInlineStatus .overflow .find (t => t .id === this .categorySubmenu )
@@ -177,17 +191,22 @@ export default {
177
191
selectedTask (taskType ) {
178
192
return taskType .id === this .modelValue
179
193
},
180
- selectedCategory (category ) {
194
+ isCategorySelected (category ) {
181
195
return category .id === this .getTaskCategory (this .modelValue || ' ' )
182
196
},
183
197
onTaskSelected (taskType ) {
184
198
this .$emit (' update:model-value' , taskType .id )
185
199
},
186
- onMenuCategorySelected (category , tasks ) {
187
- if (tasks .length === 1 && category !== ' other' ) {
188
- this .onTaskSelected (tasks[0 ])
200
+ hasSubMenu (taskType ) {
201
+ return taskType .tasks .length > 1 || taskType .id === ' other'
202
+ },
203
+ onMenuCategorySelected (taskType ) {
204
+ if (this .hasSubMenu (taskType)) {
205
+ this .categorySubmenu = taskType .id
206
+ } else {
207
+ this .onTaskSelected (taskType .tasks [0 ])
208
+ this .categorySubmenu = null
189
209
}
190
- this .categorySubmenu = category
191
210
},
192
211
getTaskCategory (id ) {
193
212
if (id .startsWith (' chatty' )) {
0 commit comments