@mapomodule/uikit 1.0.0-alpha.9 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +18 -0
- package/dist/module.d.cts +2 -0
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +18 -0
- package/dist/types.d.mts +13 -0
- package/package.json +63 -10
- package/src/index.ts +10 -0
- package/src/module.ts +181 -0
- package/src/runtime/assets/main.css +59 -0
- package/src/runtime/components/MapoConfirmDialog.vue +34 -0
- package/src/runtime/components/MapoDetail.vue +861 -0
- package/src/runtime/components/MapoDetailLangSwitch.vue +166 -0
- package/src/runtime/components/MapoList.vue +339 -0
- package/src/runtime/components/MapoListActions.vue +152 -0
- package/src/runtime/components/MapoListFilters.vue +289 -0
- package/src/runtime/components/MapoListHead.vue +12 -0
- package/src/runtime/components/MapoListQuickEdit.vue +163 -0
- package/src/runtime/components/MapoListTable.vue +926 -0
- package/src/runtime/components/MapoListTabs.vue +48 -0
- package/src/runtime/components/MapoLogin.vue +209 -0
- package/src/runtime/components/MapoLogoutButton.vue +46 -0
- package/src/runtime/components/MapoRootComponents.vue +9 -0
- package/src/runtime/components/MapoSidebar.vue +112 -0
- package/src/runtime/components/MapoSidebarList.vue +35 -0
- package/src/runtime/components/MapoSidebarListItem.vue +79 -0
- package/src/runtime/components/MapoSidebarProfile.vue +57 -0
- package/src/runtime/components/MapoSnackBar.vue +42 -0
- package/src/runtime/components/MapoThemeToggle.vue +23 -0
- package/src/runtime/components/MapoTopbar.vue +36 -0
- package/src/runtime/layouts/default.vue +53 -0
- package/src/runtime/layouts/empty.vue +9 -0
- package/src/runtime/page-meta.nuxt.d.ts +45 -0
- package/src/runtime/pages/index.vue +14 -0
- package/src/runtime/pages/login.vue +7 -0
- package/src/runtime/types/list.ts +64 -0
- package/CHANGELOG.md +0 -177
- package/LICENSE.md +0 -20
- package/assets/mixins.scss +0 -22
- package/assets/variables.scss +0 -18
- package/components/ConfirmDialog.vue +0 -152
- package/components/Detail/Detail.vue +0 -566
- package/components/Detail/DetailField.vue +0 -142
- package/components/Detail/DetailLangSwitch.vue +0 -72
- package/components/Detail/defaults.js +0 -57
- package/components/DropArea.vue +0 -250
- package/components/List/List.vue +0 -254
- package/components/List/ListActions.vue +0 -164
- package/components/List/ListFilters.vue +0 -334
- package/components/List/ListHead.vue +0 -67
- package/components/List/ListQuickEdit.vue +0 -302
- package/components/List/ListTable.vue +0 -406
- package/components/List/ListTabs.vue +0 -65
- package/components/Login.vue +0 -124
- package/components/Logo.vue +0 -79
- package/components/LogoutButton.vue +0 -39
- package/components/MediaManager/MediaEditor.vue +0 -309
- package/components/MediaManager/MediaFolders.vue +0 -263
- package/components/MediaManager/MediaGallery.vue +0 -206
- package/components/MediaManager/MediaManager.vue +0 -233
- package/components/MediaManager/MediaManagerDialog.vue +0 -96
- package/components/MediaManager/MediaPreview.vue +0 -180
- package/components/MediaManager/MediaUploader.vue +0 -165
- package/components/RootComponents.vue +0 -25
- package/components/SnackBar.vue +0 -70
- package/components/fields/DateField.vue +0 -74
- package/components/fields/FksField.vue +0 -60
- package/components/fields/MediaField.vue +0 -213
- package/components/fields/MediaM2mField.vue +0 -243
- package/components/fields/SeoPreview.vue +0 -89
- package/components/fields/wygEditor/defaults.js +0 -55
- package/components/fields/wygEditor/utils/events.js +0 -64
- package/components/fields/wygEditor/utils/mapomedia.plugin.js +0 -31
- package/components/fields/wygEditor/utils/script.injector.js +0 -29
- package/components/fields/wygEditor/wygEditor.vue +0 -196
- package/components/layout/Sidebar/Sidebar.vue +0 -80
- package/components/layout/Sidebar/SidebarFooter.vue +0 -71
- package/components/layout/Sidebar/SidebarList.vue +0 -44
- package/components/layout/Sidebar/SidebarListItem.vue +0 -144
- package/components/layout/Topbar/Topbar.vue +0 -27
- package/components/layout/routebuilder.js +0 -48
- package/defaults.js +0 -29
- package/layouts/default.vue +0 -21
- package/layouts/empty.vue +0 -6
- package/layouts/error.vue +0 -45
- package/module.js +0 -78
- package/pages/index.vue +0 -35
- package/pages/login.vue +0 -10
- package/static/favicon.ico +0 -0
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div v-if="compFilters.length" class="main">
|
|
3
|
-
<v-row class="flex-sm-row-reverse">
|
|
4
|
-
<v-col cols="12" sm="3" class="d-flex justify-end align-center">
|
|
5
|
-
<v-menu offset-y min-width="250px" max-width="400px" nudge-top="-5px" tile :close-on-content-click="false" v-bind="{ ...$attrs, value: null }" >
|
|
6
|
-
<template v-slot:activator="{ on }">
|
|
7
|
-
<v-btn v-bind="$attrs" v-on="on" text>
|
|
8
|
-
filter <v-icon>mdi-filter-variant</v-icon>
|
|
9
|
-
</v-btn>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<v-list class="pa-0">
|
|
13
|
-
<div v-for="(filter, index) in compFilters" :key="index">
|
|
14
|
-
<!-- This is a dynamic slot. You can use it to override filters. <br> For example use `filter.status` to completely override the rendering of the filter with `"status"` as value. -->
|
|
15
|
-
<slot
|
|
16
|
-
:name="`filter.${filter.value}`"
|
|
17
|
-
v-bind="{
|
|
18
|
-
filter,
|
|
19
|
-
addFilter,
|
|
20
|
-
removeFilterChoice,
|
|
21
|
-
toggleChoice,
|
|
22
|
-
activeFilters,
|
|
23
|
-
}"
|
|
24
|
-
>
|
|
25
|
-
<v-list-group>
|
|
26
|
-
<v-list-item-title slot="activator">
|
|
27
|
-
<!-- This is a dynamic slot. You can use it to override filters title. -->
|
|
28
|
-
<slot
|
|
29
|
-
:name="`filter.${filter.value}.title`"
|
|
30
|
-
v-bind="{
|
|
31
|
-
filter,
|
|
32
|
-
addFilter,
|
|
33
|
-
removeFilterChoice,
|
|
34
|
-
toggleChoice,
|
|
35
|
-
activeFilters,
|
|
36
|
-
}"
|
|
37
|
-
>
|
|
38
|
-
{{ filter.text }}
|
|
39
|
-
</slot>
|
|
40
|
-
</v-list-item-title>
|
|
41
|
-
<!-- This is a dynamic slot. You can use it to override filters content.-->
|
|
42
|
-
<slot
|
|
43
|
-
:name="`filter.${filter.value}.content`"
|
|
44
|
-
v-bind="{
|
|
45
|
-
filter,
|
|
46
|
-
addFilter,
|
|
47
|
-
removeFilterChoice,
|
|
48
|
-
toggleChoice,
|
|
49
|
-
activeFilters,
|
|
50
|
-
}"
|
|
51
|
-
>
|
|
52
|
-
<div v-if="filter.datepicker" class="d-flex flex-column align-end justify-center pb-2">
|
|
53
|
-
<v-date-picker
|
|
54
|
-
@input="addDateFilter(filter)"
|
|
55
|
-
class="rounded-0"
|
|
56
|
-
v-model="filter.dates"
|
|
57
|
-
range
|
|
58
|
-
full-width
|
|
59
|
-
no-title
|
|
60
|
-
color="primary"
|
|
61
|
-
>
|
|
62
|
-
</v-date-picker>
|
|
63
|
-
<v-btn
|
|
64
|
-
class="datapicker-clear-btn elevation-0"
|
|
65
|
-
@click="removeFilter(filter)"
|
|
66
|
-
small
|
|
67
|
-
tile
|
|
68
|
-
>clear</v-btn
|
|
69
|
-
>
|
|
70
|
-
</div>
|
|
71
|
-
<v-list v-else class="overflow-y-auto pa-0" max-height="200" dense>
|
|
72
|
-
<v-list-item
|
|
73
|
-
v-for="(choice, i) in filter.choices"
|
|
74
|
-
:key="i"
|
|
75
|
-
class="v-list-item--link"
|
|
76
|
-
active-class="primary--text"
|
|
77
|
-
:input-value="isChoiceActive(filter, choice)"
|
|
78
|
-
@click.native.stop="toggleChoice(filter, choice)"
|
|
79
|
-
>
|
|
80
|
-
<!-- This is a dynamic slot. You can use it to override filters icon. -->
|
|
81
|
-
<slot
|
|
82
|
-
:name="`filter.${filter.value}.icon`"
|
|
83
|
-
v-bind="{ filter, choice }"
|
|
84
|
-
>
|
|
85
|
-
<v-list-item-icon>
|
|
86
|
-
<v-icon
|
|
87
|
-
v-text="choice.icon || 'mdi-circle-small'"
|
|
88
|
-
></v-icon>
|
|
89
|
-
</v-list-item-icon>
|
|
90
|
-
</slot>
|
|
91
|
-
|
|
92
|
-
<v-list-item-content>
|
|
93
|
-
<v-list-item-title
|
|
94
|
-
v-text="choice.text"
|
|
95
|
-
></v-list-item-title>
|
|
96
|
-
</v-list-item-content>
|
|
97
|
-
</v-list-item>
|
|
98
|
-
</v-list>
|
|
99
|
-
</slot>
|
|
100
|
-
</v-list-group>
|
|
101
|
-
</slot>
|
|
102
|
-
</div>
|
|
103
|
-
</v-list>
|
|
104
|
-
</v-menu>
|
|
105
|
-
</v-col>
|
|
106
|
-
<v-col v-if="activeFilters.length" cols="12" sm="9">
|
|
107
|
-
<v-slide-group v-bind="$attrs" show-arrows>
|
|
108
|
-
<v-chip
|
|
109
|
-
v-bind="$attrs"
|
|
110
|
-
class="ma-1"
|
|
111
|
-
close
|
|
112
|
-
label
|
|
113
|
-
@click:close="removeFilter(filter)"
|
|
114
|
-
v-for="(filter, i) in activeFilters"
|
|
115
|
-
:key="i"
|
|
116
|
-
>
|
|
117
|
-
<span>
|
|
118
|
-
<small>
|
|
119
|
-
<b>{{ filter.text.toUpperCase() }}: </b>
|
|
120
|
-
{{ formatActiveChoices(filter.active).toUpperCase() }}
|
|
121
|
-
</small>
|
|
122
|
-
</span>
|
|
123
|
-
</v-chip>
|
|
124
|
-
</v-slide-group>
|
|
125
|
-
</v-col>
|
|
126
|
-
</v-row>
|
|
127
|
-
</div>
|
|
128
|
-
</template>
|
|
129
|
-
|
|
130
|
-
<style lang="scss" scoped>
|
|
131
|
-
.main{
|
|
132
|
-
width: 100%;
|
|
133
|
-
}
|
|
134
|
-
.datapicker-clear-btn {
|
|
135
|
-
margin: -20px 15px 0 0 ;
|
|
136
|
-
}
|
|
137
|
-
</style>
|
|
138
|
-
|
|
139
|
-
<script>
|
|
140
|
-
import { debounce } from "@mapomodule/utils/helpers/debounce";
|
|
141
|
-
/**
|
|
142
|
-
* This components renders the filter menu in the upper-right. The menu provides a selection of filters applicable to the list.
|
|
143
|
-
* The list of applied filters appears next to the menu as a list of chips containing the name of the filter and the applied values. <br>
|
|
144
|
-
* If no filters are passed to the component it will not be rendered.
|
|
145
|
-
*/
|
|
146
|
-
export default {
|
|
147
|
-
name: "ListFilters",
|
|
148
|
-
data() {
|
|
149
|
-
return {
|
|
150
|
-
compFilters: [],
|
|
151
|
-
activeFilters: [],
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
props: {
|
|
155
|
-
// This is the main configuration of the component. It contains a list of filters.
|
|
156
|
-
filters: {
|
|
157
|
-
// [`Array<Filter>`](#filter-config)
|
|
158
|
-
type: Array,
|
|
159
|
-
default: () => [],
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
methods: {
|
|
163
|
-
addDateFilter(filter) {
|
|
164
|
-
const { dates } = filter;
|
|
165
|
-
dates.sort((a,b) => Date.parse(a) - Date.parse(b));
|
|
166
|
-
if (dates && dates.length > 1) {
|
|
167
|
-
this.addFilter(filter, {
|
|
168
|
-
text: dates.map(date => new Date(date).toLocaleDateString()).join(" ~ "),
|
|
169
|
-
value: dates.join(","),
|
|
170
|
-
});
|
|
171
|
-
} else if (!dates || !dates.length) {
|
|
172
|
-
this.removeFilter(filter);
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
removeFilter(filter) {
|
|
176
|
-
if (filter.datepicker) {
|
|
177
|
-
const idx = this.compFilters.findIndex((f) => f.value === filter.value);
|
|
178
|
-
if (this.compFilters[idx].dates) this.compFilters[idx].dates = [];
|
|
179
|
-
}
|
|
180
|
-
const i = this.activeFilters.findIndex((f) => f.value === filter.value);
|
|
181
|
-
this.activeFilters.splice(i, 1);
|
|
182
|
-
},
|
|
183
|
-
toggleChoice(filter, choice) {
|
|
184
|
-
if (this.isChoiceActive(filter, choice)) {
|
|
185
|
-
this.removeFilterChoice(filter, choice);
|
|
186
|
-
} else {
|
|
187
|
-
this.addFilter(filter, choice);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
removeFilterChoice(filter, choice) {
|
|
191
|
-
const index = this.activeFilters.findIndex(
|
|
192
|
-
(f) => f.value === filter.value
|
|
193
|
-
);
|
|
194
|
-
if (index !== -1) {
|
|
195
|
-
const chI = this.activeFilters[index].active.findIndex(
|
|
196
|
-
(c) => c.value === choice.value
|
|
197
|
-
);
|
|
198
|
-
if (chI !== -1) {
|
|
199
|
-
this.activeFilters[index].active.splice(chI, 1);
|
|
200
|
-
}
|
|
201
|
-
this.activeFilters[index].active.length ||
|
|
202
|
-
this.activeFilters.splice(index, 1);
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
addFilter(filter, choice) {
|
|
206
|
-
const index = this.activeFilters.findIndex(
|
|
207
|
-
(f) => f.value === filter.value
|
|
208
|
-
);
|
|
209
|
-
if (index !== -1) {
|
|
210
|
-
const chI = this.activeFilters[index].active.findIndex(
|
|
211
|
-
(c) => c.value === choice.value
|
|
212
|
-
);
|
|
213
|
-
if (chI !== -1) {
|
|
214
|
-
return;
|
|
215
|
-
} else if (filter.multiple && !filter.datepicker) {
|
|
216
|
-
this.activeFilters[index].active.push(choice);
|
|
217
|
-
} else {
|
|
218
|
-
this.activeFilters[index].active = [choice];
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
this.activeFilters.push({ ...filter, active: [choice] });
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
isChoiceActive(filter, choice) {
|
|
225
|
-
const found = this.activeFilters.find((f) => f.value == filter.value);
|
|
226
|
-
return (
|
|
227
|
-
(found?.active || []).findIndex((c) => c.value == choice.value) !== -1
|
|
228
|
-
);
|
|
229
|
-
},
|
|
230
|
-
formatActiveChoices(choices) {
|
|
231
|
-
return choices.map((c) => c.text).join(", ");
|
|
232
|
-
},
|
|
233
|
-
setQparams(filters) {
|
|
234
|
-
const ourQ = filters.reduce(
|
|
235
|
-
(acc, filter) => ({
|
|
236
|
-
...acc,
|
|
237
|
-
[filter.value]: filter.active.map((c) => c.value).join(","),
|
|
238
|
-
}),
|
|
239
|
-
{}
|
|
240
|
-
);
|
|
241
|
-
const otherQ = Object.keys(this.$route.query)
|
|
242
|
-
.filter((k) => !this.compFilters.some((f) => f.value == k))
|
|
243
|
-
.reduce((acc, k) => ({ ...acc, [k]: this.$route.query[k] }), {});
|
|
244
|
-
this.$router.push({ query: { ...otherQ, ...ourQ } });
|
|
245
|
-
},
|
|
246
|
-
restoreFromQparams() {
|
|
247
|
-
Object.keys(this.$route.query).forEach((k) => {
|
|
248
|
-
const index = this.compFilters.findIndex((f) => f.value == k);
|
|
249
|
-
if (index !== -1) {
|
|
250
|
-
let filter = this.compFilters[index];
|
|
251
|
-
if (filter.datepicker) {
|
|
252
|
-
filter.dates = [...this.$route.query[k].split(",")];
|
|
253
|
-
this.addDateFilter(filter);
|
|
254
|
-
} else {
|
|
255
|
-
filter.choices.forEach((c) => {
|
|
256
|
-
this.$route.query[k].split(",").includes(c.value + "") &&
|
|
257
|
-
this.addFilter(filter, c);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
},
|
|
263
|
-
loadFilters() {
|
|
264
|
-
this.compFilters = this.filters.map(filter => {
|
|
265
|
-
if (filter.datepicker) {
|
|
266
|
-
return {
|
|
267
|
-
...filter,
|
|
268
|
-
dates: [],
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
return filter;
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
watch: {
|
|
276
|
-
activeFilters: {
|
|
277
|
-
deep: true,
|
|
278
|
-
handler: debounce(function (val) {
|
|
279
|
-
// This is an internal event to bind the active filters with other List parts.
|
|
280
|
-
this.$emit("input", val);
|
|
281
|
-
this.setQparams(val);
|
|
282
|
-
}, 200),
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
created() {
|
|
286
|
-
this.loadFilters();
|
|
287
|
-
this.restoreFromQparams();
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
</script>
|
|
291
|
-
|
|
292
|
-
<docs>
|
|
293
|
-
## Filter config
|
|
294
|
-
|
|
295
|
-
The filters prop is a list of `Filter` objects made of several keys:
|
|
296
|
-
|
|
297
|
-
- **"text"** `String` ==> The name of the filter that will be renered inside the filter menu.
|
|
298
|
-
- **"value"** `String` ==> The dotted path of the value we need to filter on.
|
|
299
|
-
- **"choices"** `Array<Choice>` ==> The list of choices rendered inside the filter. The text is the label, the value is the string we use as a filter.
|
|
300
|
-
- **"datepicker"** `Boolean` ==> This is a boolean that determines if the filter has a datepicker layout.
|
|
301
|
-
- **"multiple"** `Boolean` ==> This is a boolean that determines if the filter is exclusive or inclusive. In other words, if by selecting a choice it is added to the previous one or if it replaces it.
|
|
302
|
-
|
|
303
|
-
### Choice object
|
|
304
|
-
|
|
305
|
-
The choice object is used to list all the available choices of a single filter.
|
|
306
|
-
It is made of:
|
|
307
|
-
|
|
308
|
-
- **"text"** `String` ==> The label of the choice.
|
|
309
|
-
- **"value"** `String` ==> The value that will be used to filter the list if this choice is active.
|
|
310
|
-
- **"icon"** `String` ==> The icon at the left of the choice label, by default we use 'mdi-circle-small'. For a list of all available icons, visit the official [Material Design Icons](https://materialdesignicons.com/) page.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
## Example
|
|
314
|
-
Here an example of two filters for an article list; one based on article status and the other on the publication date:
|
|
315
|
-
|
|
316
|
-
```js
|
|
317
|
-
const filters = [
|
|
318
|
-
{
|
|
319
|
-
text: "Status",
|
|
320
|
-
value: "status",
|
|
321
|
-
choices: [
|
|
322
|
-
{ text: "Draft", value: "DRF" },
|
|
323
|
-
{ text: "Published", value: "PUB" },
|
|
324
|
-
{ text: "Trash", value: "TRS" },
|
|
325
|
-
],
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
text: "Date",
|
|
329
|
-
value: "date",
|
|
330
|
-
datepicker: true
|
|
331
|
-
},
|
|
332
|
-
]
|
|
333
|
-
```
|
|
334
|
-
</docs>
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="list__head">
|
|
3
|
-
<h1 class="list__head__title display-1">{{ title }}</h1>
|
|
4
|
-
<div class="list__head__button">
|
|
5
|
-
<v-btn
|
|
6
|
-
v-if="addItem && canAdd"
|
|
7
|
-
class="rounded-0 elevation-0"
|
|
8
|
-
color="primary"
|
|
9
|
-
:to="{ path: `${$route.path}/new` }"
|
|
10
|
-
>Add new   <v-icon>mdi-plus</v-icon></v-btn
|
|
11
|
-
>
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
</template>
|
|
15
|
-
|
|
16
|
-
<style lang="scss" scoped>
|
|
17
|
-
@import "@mapomodule/uikit/assets/variables.scss";
|
|
18
|
-
|
|
19
|
-
.list {
|
|
20
|
-
&__head {
|
|
21
|
-
display: flex;
|
|
22
|
-
align-items: center;
|
|
23
|
-
justify-content: space-between;
|
|
24
|
-
flex-wrap: wrap;
|
|
25
|
-
margin-bottom: 2rem;
|
|
26
|
-
&__title {
|
|
27
|
-
margin-right: 2rem;
|
|
28
|
-
margin-bottom: 1rem;
|
|
29
|
-
}
|
|
30
|
-
&__button {
|
|
31
|
-
display: flex;
|
|
32
|
-
flex: 1;
|
|
33
|
-
justify-content: flex-end;
|
|
34
|
-
margin-bottom: 1rem;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
</style>
|
|
39
|
-
|
|
40
|
-
<script>
|
|
41
|
-
/**
|
|
42
|
-
* This component renders the upper part of the list. Specifically, the page title and the button to add new content.
|
|
43
|
-
*/
|
|
44
|
-
export default {
|
|
45
|
-
name: "ListHead",
|
|
46
|
-
props: {
|
|
47
|
-
// This is the title of the page.
|
|
48
|
-
title: {
|
|
49
|
-
type: String,
|
|
50
|
-
// The route name.
|
|
51
|
-
default() {
|
|
52
|
-
return this.$route.name;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
// This is a boolean that determines the visibility of "new item" button. If set to true will provide the user a link to a detail page for new content creation.
|
|
56
|
-
addItem: Boolean
|
|
57
|
-
},
|
|
58
|
-
computed: {
|
|
59
|
-
canAdd() {
|
|
60
|
-
if (this.$mapo.$auth.routeMiddlewares.includes("permissions")){
|
|
61
|
-
return this.$mapo.$auth.user.permissions.includes("add")
|
|
62
|
-
}
|
|
63
|
-
return true
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
</script>
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<slot v-bind="{ on, attrs }" name="activator"></slot>
|
|
4
|
-
<v-dialog v-model="dialog" width="600" scrollable>
|
|
5
|
-
<v-card v-bind="$attrs">
|
|
6
|
-
<v-card-title class="pa-0 mb-3">
|
|
7
|
-
<div style="max-width: calc(100% - 40px)">
|
|
8
|
-
<slot name="lang" v-bind="slotBindings">
|
|
9
|
-
<!-- [`DetailLangSwitch`](/components/detail/DetailLangSwitch/) -->
|
|
10
|
-
<DetailLangSwitch
|
|
11
|
-
v-if="langs.length > 1"
|
|
12
|
-
v-model="currentLang"
|
|
13
|
-
:langs="langs"
|
|
14
|
-
:errors="errors"
|
|
15
|
-
/></slot>
|
|
16
|
-
</div>
|
|
17
|
-
<v-spacer></v-spacer>
|
|
18
|
-
<slot name="title" v-bind="slotBindings">
|
|
19
|
-
<v-hover v-slot="{ hover }">
|
|
20
|
-
<v-icon @click="hover && close()" class="mr-4" :class="{'mt-4': !langs.length}">{{
|
|
21
|
-
hover ? "mdi-close" : isNew ? "mdi-plus-circle-outline" : "mdi-pencil-outline"
|
|
22
|
-
}}</v-icon>
|
|
23
|
-
</v-hover>
|
|
24
|
-
</slot>
|
|
25
|
-
</v-card-title>
|
|
26
|
-
<v-card-text class="pa-0 px-2">
|
|
27
|
-
<v-container>
|
|
28
|
-
<v-form v-if="model" ref="form">
|
|
29
|
-
<!-- Use this to add content on top of body. -->
|
|
30
|
-
<slot name="body.top" v-bind="slotBindings"></slot>
|
|
31
|
-
|
|
32
|
-
<slot name="body" v-bind="slotBindings">
|
|
33
|
-
<v-row>
|
|
34
|
-
<div
|
|
35
|
-
class="col-12"
|
|
36
|
-
:class="field.class"
|
|
37
|
-
v-for="(field, index) in computedFields"
|
|
38
|
-
:key="index"
|
|
39
|
-
>
|
|
40
|
-
<v-card v-if="field.group" class="my-2">
|
|
41
|
-
<v-card-title>
|
|
42
|
-
<v-icon left> {{ field.group.icon }} </v-icon>
|
|
43
|
-
<span>{{ field.group.name }}</span>
|
|
44
|
-
</v-card-title>
|
|
45
|
-
<div class="container">
|
|
46
|
-
<div class="row">
|
|
47
|
-
<div
|
|
48
|
-
v-for="(fields, fieldsI) in field.fields"
|
|
49
|
-
:key="fieldsI"
|
|
50
|
-
class="col-12"
|
|
51
|
-
:class="fields.class"
|
|
52
|
-
>
|
|
53
|
-
<!-- This is a dynamic slot. You can use it to override a field component. For example use `qedit.fields.title` to override the component of the field with value `title`. -->
|
|
54
|
-
<slot
|
|
55
|
-
:name="fields.slotName"
|
|
56
|
-
v-bind="{
|
|
57
|
-
conf: fields,
|
|
58
|
-
...slotBindings,
|
|
59
|
-
}"
|
|
60
|
-
>
|
|
61
|
-
<!-- A [`DetailField`](/components/detail/DetailField/) configured by a [`FieldConfiguration`](#fieldconfiguration). -->
|
|
62
|
-
<DetailField
|
|
63
|
-
v-model="model"
|
|
64
|
-
:conf="fields"
|
|
65
|
-
:errors="errors"
|
|
66
|
-
/>
|
|
67
|
-
</slot>
|
|
68
|
-
</div>
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
</v-card>
|
|
72
|
-
<slot
|
|
73
|
-
v-else
|
|
74
|
-
:name="field.slotName"
|
|
75
|
-
v-bind="{
|
|
76
|
-
conf: field,
|
|
77
|
-
...slotBindings,
|
|
78
|
-
}"
|
|
79
|
-
>
|
|
80
|
-
<DetailField
|
|
81
|
-
v-model="model"
|
|
82
|
-
:conf="field"
|
|
83
|
-
:errors="errors"
|
|
84
|
-
/>
|
|
85
|
-
</slot>
|
|
86
|
-
</div>
|
|
87
|
-
</v-row>
|
|
88
|
-
</slot>
|
|
89
|
-
<!-- Use this to add content under the main body. -->
|
|
90
|
-
<slot name="body.bottom" v-bind="slotBindings"></slot>
|
|
91
|
-
</v-form>
|
|
92
|
-
</v-container>
|
|
93
|
-
</v-card-text>
|
|
94
|
-
<v-card-actions>
|
|
95
|
-
<v-messages v-if="nonFieldErrors.length" v-model="nonFieldErrors" color="error"></v-messages>
|
|
96
|
-
<slot name="actions" v-bind="slotBindings">
|
|
97
|
-
<v-spacer></v-spacer>
|
|
98
|
-
<v-btn text @click="close()"> Cancel </v-btn>
|
|
99
|
-
<v-btn text @click="save"> Save </v-btn>
|
|
100
|
-
</slot>
|
|
101
|
-
</v-card-actions>
|
|
102
|
-
</v-card>
|
|
103
|
-
</v-dialog>
|
|
104
|
-
</div>
|
|
105
|
-
</template>
|
|
106
|
-
<script>
|
|
107
|
-
import { diffObjs, deepClone } from "@mapomodule/utils/helpers/objHelpers";
|
|
108
|
-
/**
|
|
109
|
-
* This components renders a dialog that let the user quick edit (or add) an element of the list.
|
|
110
|
-
* The dialog provides several fields that will edit a payload that will be sent to the server. <br>
|
|
111
|
-
* The component checks for editFields config or dedicated slots to decide if it should be available to the user.
|
|
112
|
-
*/
|
|
113
|
-
export default {
|
|
114
|
-
name: "ListQuickEdit",
|
|
115
|
-
data() {
|
|
116
|
-
return {
|
|
117
|
-
dialog: false,
|
|
118
|
-
attrs: { ...this.$attrs },
|
|
119
|
-
modelBkp: null,
|
|
120
|
-
model: null,
|
|
121
|
-
isNew: false,
|
|
122
|
-
currentLang: null,
|
|
123
|
-
errors: null,
|
|
124
|
-
on: {
|
|
125
|
-
click: (event) => {
|
|
126
|
-
event.preventDefault();
|
|
127
|
-
event.stopPropagation();
|
|
128
|
-
this.dialog = !this.dialog;
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
props: {
|
|
134
|
-
// V-model
|
|
135
|
-
value: {
|
|
136
|
-
type: Boolean,
|
|
137
|
-
},
|
|
138
|
-
// The main configuration that determines the arrangement of the fields in the detail layout.
|
|
139
|
-
editFields: {
|
|
140
|
-
type: Array,
|
|
141
|
-
default: () => [],
|
|
142
|
-
},
|
|
143
|
-
// A list of languages into which the payload needs to be translated.
|
|
144
|
-
languages: {
|
|
145
|
-
type: Array,
|
|
146
|
-
default: () => [],
|
|
147
|
-
},
|
|
148
|
-
lookup: {
|
|
149
|
-
type: String,
|
|
150
|
-
default: "id",
|
|
151
|
-
},
|
|
152
|
-
crud: {
|
|
153
|
-
type: Object,
|
|
154
|
-
required: true,
|
|
155
|
-
},
|
|
156
|
-
offline: Boolean,
|
|
157
|
-
},
|
|
158
|
-
watch: {
|
|
159
|
-
value(val) {
|
|
160
|
-
this.dialog = val;
|
|
161
|
-
},
|
|
162
|
-
dialog(val) {
|
|
163
|
-
this.$emit("input", val);
|
|
164
|
-
this.$emit(val ? "open" : "close");
|
|
165
|
-
if (!val) {
|
|
166
|
-
this.close();
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
currentLang() {
|
|
170
|
-
this.initLang();
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
computed: {
|
|
174
|
-
computedFields() {
|
|
175
|
-
return this.mapConf(this.editFields || []);
|
|
176
|
-
},
|
|
177
|
-
langs() {
|
|
178
|
-
return this.model?.lang_info?.site_languages.map((l) => l.id) || this.languages || [];
|
|
179
|
-
},
|
|
180
|
-
loading() {
|
|
181
|
-
return this.isNew ? false : !Object.keys(this.model || {}).length;
|
|
182
|
-
},
|
|
183
|
-
nonFieldErrors(){
|
|
184
|
-
return this.errors?.non_field_errors || []
|
|
185
|
-
},
|
|
186
|
-
slotBindings() {
|
|
187
|
-
return {
|
|
188
|
-
model: this.model,
|
|
189
|
-
currentLang: this.currentLang,
|
|
190
|
-
crud: this.crud,
|
|
191
|
-
isNew: this.isNew,
|
|
192
|
-
langs: this.langs,
|
|
193
|
-
loading: this.loading,
|
|
194
|
-
form: this.$refs.form,
|
|
195
|
-
save: this.save,
|
|
196
|
-
close: this.close,
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
methods: {
|
|
201
|
-
async open(item) {
|
|
202
|
-
this.isNew = !item;
|
|
203
|
-
this.modelBkp = await this.fetchItem(item);
|
|
204
|
-
this.model = deepClone(this.modelBkp);
|
|
205
|
-
this.initLang();
|
|
206
|
-
this.dialog = true;
|
|
207
|
-
this.$refs.form?.resetValidation();
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
this.resolve = resolve;
|
|
210
|
-
this.reject = reject;
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
async save() {
|
|
214
|
-
if (this.$refs.form?.validate()) {
|
|
215
|
-
return await (this.isNew ? this.apiCreate() : this.apiEdit());
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
close(res) {
|
|
219
|
-
this.errors = null;
|
|
220
|
-
this.currentLang = null;
|
|
221
|
-
this.$refs.form?.resetValidation();
|
|
222
|
-
this.resolve && this.resolve(res);
|
|
223
|
-
this.dialog = false;
|
|
224
|
-
},
|
|
225
|
-
parseConf(field, i) {
|
|
226
|
-
const conf = typeof field === "string" ? { value: field } : field;
|
|
227
|
-
conf.value = conf.value || "";
|
|
228
|
-
conf.value = conf.value.replace(
|
|
229
|
-
new RegExp(`^translations\.(${this.langs.join("|")})\.?`),
|
|
230
|
-
""
|
|
231
|
-
);
|
|
232
|
-
conf.slotName = `fields.${conf.value || i}`;
|
|
233
|
-
if (this.currentLang && !field.synci18n) {
|
|
234
|
-
const base = `translations.${this.currentLang}`;
|
|
235
|
-
conf.value = (conf.value && `${base}.${conf.value}`) || base;
|
|
236
|
-
}
|
|
237
|
-
return conf;
|
|
238
|
-
},
|
|
239
|
-
mapConf(fields) {
|
|
240
|
-
const icon = "mdi-cube-outline";
|
|
241
|
-
const parseGroup = (group) =>
|
|
242
|
-
typeof group === "string"
|
|
243
|
-
? { name: group, icon }
|
|
244
|
-
: { ...group, icon: group.icon !== undefined ? group.icon : icon };
|
|
245
|
-
return fields.map((f, i) =>
|
|
246
|
-
f.group
|
|
247
|
-
? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
|
|
248
|
-
: this.parseConf(f, i)
|
|
249
|
-
);
|
|
250
|
-
},
|
|
251
|
-
initLang(lang = this.currentLang) {
|
|
252
|
-
if (lang && !this.model.translations) {
|
|
253
|
-
this.model.translations = {};
|
|
254
|
-
}
|
|
255
|
-
if (lang && !this.model.translations[lang]) {
|
|
256
|
-
this.model.translations[lang] = {};
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
async fetchItem(item) {
|
|
260
|
-
if (!this.offline && item && item[this.lookup]) {
|
|
261
|
-
return await this.crud.detail(item[this.lookup]);
|
|
262
|
-
} else {
|
|
263
|
-
return item;
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
apiEdit() {
|
|
267
|
-
if (!this.offline) {
|
|
268
|
-
return this.crud
|
|
269
|
-
.partialUpdate(
|
|
270
|
-
this.modelBkp[this.lookup],
|
|
271
|
-
// diffObjs(this.modelBkp, this.model) disabled since it creates some errors in translations
|
|
272
|
-
this.model
|
|
273
|
-
)
|
|
274
|
-
.then((res) => this.close(res))
|
|
275
|
-
.catch(this.handleError);
|
|
276
|
-
} else {
|
|
277
|
-
this.close(this.model);
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
apiCreate() {
|
|
281
|
-
if (!this.offline) {
|
|
282
|
-
return this.crud
|
|
283
|
-
.create(this.model)
|
|
284
|
-
.then((res) => this.close(res))
|
|
285
|
-
.catch(this.handleError);
|
|
286
|
-
} else {
|
|
287
|
-
return this.close(this.model);
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
handleError(error) {
|
|
291
|
-
const badRequest = error.response.status == 400;
|
|
292
|
-
this.errors = (badRequest && error.response.data) || null;
|
|
293
|
-
this.$mapo.$snack.open({
|
|
294
|
-
message: badRequest
|
|
295
|
-
? "Bad input, correct wrong fields."
|
|
296
|
-
: error.response?.data?.detail || "Something whent bad, please try again later...",
|
|
297
|
-
color: "error",
|
|
298
|
-
});
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
};
|
|
302
|
-
</script>
|