@mapomodule/uikit 1.0.0-alpha.2 → 1.0.0-alpha.22

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +406 -0
  2. package/components/Detail/Detail.vue +288 -260
  3. package/components/Detail/DetailLangSwitch.vue +1 -1
  4. package/components/DropArea.vue +3 -3
  5. package/components/Form/Form.vue +224 -0
  6. package/components/Form/FormField.vue +185 -0
  7. package/components/Form/FormGroup.vue +88 -0
  8. package/components/Form/FormTabs.vue +134 -0
  9. package/components/Form/defaults.js +58 -0
  10. package/components/{fields → Form/fields}/DateField.vue +9 -3
  11. package/components/Form/fields/FileField.vue +125 -0
  12. package/components/Form/fields/FksField.vue +88 -0
  13. package/components/{fields → Form/fields}/MediaField.vue +36 -6
  14. package/components/{fields → Form/fields}/MediaM2mField.vue +8 -3
  15. package/components/Form/fields/Repeater.vue +562 -0
  16. package/components/Form/fields/SeoPreview.vue +89 -0
  17. package/components/{fields/TinyMce → Form/fields/wygEditor}/defaults.js +7 -5
  18. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/events.js +0 -0
  19. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/mapomedia.plugin.js +7 -6
  20. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/script.injector.js +0 -0
  21. package/components/Form/fields/wygEditor/wygEditor.vue +256 -0
  22. package/components/List/List.vue +120 -42
  23. package/components/List/ListActions.vue +56 -17
  24. package/components/List/ListFilters.vue +158 -113
  25. package/components/List/ListHead.vue +30 -12
  26. package/components/List/ListQuickEdit.vue +128 -59
  27. package/components/List/ListTable.vue +293 -80
  28. package/components/Login.vue +14 -5
  29. package/components/MediaManager/MediaEditor.vue +253 -107
  30. package/components/MediaManager/MediaFolders.vue +134 -43
  31. package/components/MediaManager/MediaGallery.vue +56 -52
  32. package/components/MediaManager/MediaManager.vue +127 -83
  33. package/components/MediaManager/MediaManagerDialog.vue +19 -22
  34. package/components/MediaManager/MediaPreview.vue +180 -0
  35. package/components/MediaManager/MediaUploader.vue +35 -32
  36. package/components/SnackBar.vue +3 -4
  37. package/components/ThemeToggle.vue +13 -0
  38. package/components/layout/Sidebar/Sidebar.vue +35 -32
  39. package/components/layout/Sidebar/SidebarFooter.vue +42 -46
  40. package/components/layout/Sidebar/SidebarList.vue +13 -14
  41. package/components/layout/Sidebar/SidebarListItem.vue +99 -38
  42. package/components/layout/Sidebar/SidebarProfile.vue +42 -0
  43. package/components/layout/Topbar/Topbar.vue +3 -35
  44. package/components/layout/routebuilder.js +3 -3
  45. package/defaults.js +2 -2
  46. package/layouts/default.vue +20 -18
  47. package/layouts/empty.vue +10 -0
  48. package/module.js +1 -1
  49. package/package.json +5 -4
  50. package/pages/index.vue +1 -2
  51. package/components/Detail/DetailField.vue +0 -129
  52. package/components/Detail/defaults.js +0 -50
  53. package/components/fields/M2mField.vue +0 -95
  54. package/components/fields/TinyMce/TinyMce.vue +0 -177
  55. package/layouts/error.vue +0 -45
@@ -4,13 +4,16 @@
4
4
  label="Group Actions"
5
5
  v-bind="$attrs"
6
6
  v-model="action"
7
- :items="actions"
7
+ :items="filteredActions"
8
+ :item-disabled="isDisabled"
8
9
  item-text="label"
9
10
  item-value="handler"
10
11
  outlined
11
12
  dense
12
13
  hide-details
13
14
  clearable
15
+ no-data-text="No actions available"
16
+ class="rounded-0"
14
17
  ></v-select>
15
18
  <v-btn
16
19
  class="rounded-0 elevation-0 ml-2"
@@ -50,43 +53,74 @@ export default {
50
53
  {
51
54
  label: "Permanent delete",
52
55
  handler: function ({ selection, lookup, crud }) {
53
- return Promise.all(
54
- selection.map((i) => crud.delete(i[lookup]))
55
- );
56
+ return Promise.all(selection.map((i) => crud && crud.delete(i[lookup])));
56
57
  },
58
+ permissions: "delete"
57
59
  },
58
60
  ];
59
61
  },
60
62
  },
61
63
  // ❌ This is an internal prop. Sorry..
62
64
  selection: {
63
- // -
64
- type: Array,
65
- // -
65
+ // -
66
+ type: [Array, String],
67
+ // -
66
68
  default: () => [],
67
69
  },
68
70
  // ❌ This is an internal prop. Sorry..
71
+ selectionQuery: {
72
+ // -
73
+ type: URLSearchParams,
74
+ // -
75
+ default: () => new URLSearchParams(),
76
+ },
77
+ // ❌ This is an internal prop. Sorry..
69
78
  crud: {
70
- // -
79
+ // -
71
80
  type: Object,
72
81
  required: true,
73
82
  },
74
83
  },
75
- computed:{
76
- isActive(){
77
- return this.$attrs['show-select'] !== undefined
84
+ computed: {
85
+ isActive() {
86
+ return this.$attrs["show-select"] !== undefined;
87
+ },
88
+ filteredActions() {
89
+ return this.actions.filter((action) => {
90
+ return (this.selection != "all" && (action.handleMultiple ?? true)) || (this.selection == "all" && (action.handleAll ?? false));
91
+ });
78
92
  }
79
93
  },
80
94
  methods: {
95
+ isDisabled(action){
96
+ const p = typeof action.permissions == "string" ? [action.permissions] : action.permissions || []
97
+ if (p.length){
98
+ return !p.every(a => this.userCan(a))
99
+ }
100
+ return false
101
+ },
102
+ userCan(action) {
103
+ if (this.$mapo.$auth.routeMiddlewares.includes("permissions")){
104
+ return this.$mapo.$auth.user.permissions.includes(action)
105
+ }
106
+ return true
107
+ },
81
108
  handleAction() {
82
- if (!this.selection.length) {
109
+ if (!this.selectAll && !this.selection.length) {
83
110
  return this.$mapo.$snack.open({
84
111
  message: "You need to select at least one item.",
85
112
  color: "error",
86
113
  });
87
114
  }
88
- const ctx = { selection: this.selection, lookup: this.lookup, crud: this.crud }
89
- return this.action ? this.action(ctx).then((res) => this.$emit('actionCompleted', res)) : () => {};
115
+ const ctx = {
116
+ selection: this.selection,
117
+ selectionQuery: this.selectionQuery,
118
+ lookup: this.lookup,
119
+ crud: this.crud,
120
+ };
121
+ return this.action
122
+ ? this.action(ctx).then((res) => this.$emit("actionCompleted", res))
123
+ : () => {};
90
124
  },
91
125
  },
92
126
  };
@@ -96,13 +130,17 @@ export default {
96
130
  ## Action config
97
131
 
98
132
 
99
- The actions prop is a list of `Action` objects made of two keys:
133
+ The actions prop is a list of `Action` objects containing these keys:
100
134
 
101
135
  - **"label"** `String` ==> The name of the action that will be renered inside the select button.
136
+ - **"handleMultiple"** `Boolean` ==> Make the action callable on multiple items. Default: `true`.
137
+ - **"handleAll"** `Boolean` ==> Make the action callable on all items. Default: `false`.
102
138
  - **"handler"** `Function` ==> The callback function that will be executed once the user confirms the action.
139
+ - **"permissions"** `String | Array` ==> The list of permissions needed by the user to perform action in a page with permission middleware
103
140
 
104
141
  The handler function will be called with a ctx containing:
105
- - **"selection"** `Array<Object>`==> The list of selected objects.
142
+ - **"selection"** `Array<Object>` or `String` ==> `"all"` if all items are selected else the list of selected objects.
143
+ - **"selectionQuery"** `URLSearchParams` ==> GET parameters for the current list of objects.
106
144
  - **"lookup"** `String` ==> The lookup prop.
107
145
  - **"crud"** [`Crud`](/core/#api.crud) ==> The inherited crud from [List](../List/) component.
108
146
 
@@ -119,7 +157,8 @@ const actions = [
119
157
  selection.map((i) => crud.delete(i[lookup]))
120
158
  );
121
159
  },
160
+ permissions: "delete"
122
161
  }
123
162
  ]
124
163
  ```
125
- </docs>
164
+ </docs>
@@ -1,68 +1,19 @@
1
1
  <template>
2
- <div v-if="compFilters.length">
3
- <v-menu offset-y nudge-right="380px" max-width="400px" tile :close-on-content-click="false" v-bind="{ ...$attrs, value: null }" >
4
- <template v-slot:activator="{ on }">
5
- <v-row class="flex-sm-row-reverse">
6
- <v-col cols="12" sm="3" class="d-flex justify-end align-center">
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
7
  <v-btn v-bind="$attrs" v-on="on" text>
8
8
  filter <v-icon>mdi-filter-variant</v-icon>
9
9
  </v-btn>
10
- </v-col>
11
- <v-col v-if="activeFilters.length" cols="12" sm="9">
12
- <v-slide-group v-bind="$attrs" show-arrows>
13
- <v-chip
14
- v-bind="$attrs"
15
- class="ma-1"
16
- close
17
- label
18
- @click:close="removeFilter(filter)"
19
- v-for="(filter, i) in activeFilters"
20
- :key="i"
21
- >
22
- <span>
23
- <small>
24
- <b>{{ filter.text.toUpperCase() }}: </b>
25
- {{ formatActiveChoices(filter.active).toUpperCase() }}
26
- </small>
27
- </span>
28
- </v-chip>
29
- </v-slide-group>
30
- </v-col>
31
- </v-row>
32
- </template>
10
+ </template>
33
11
 
34
- <v-list class="pa-0">
35
- <div v-for="(filter, index) in compFilters" :key="index">
36
- <!-- 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. -->
37
- <slot
38
- :name="`filter.${filter.value}`"
39
- v-bind="{
40
- filter,
41
- addFilter,
42
- removeFilterChoice,
43
- toggleChoice,
44
- activeFilters,
45
- }"
46
- >
47
- <v-list-group>
48
- <v-list-item-title slot="activator">
49
- <!-- This is a dynamic slot. You can use it to override filters title. -->
50
- <slot
51
- :name="`filter.${filter.value}.title`"
52
- v-bind="{
53
- filter,
54
- addFilter,
55
- removeFilterChoice,
56
- toggleChoice,
57
- activeFilters,
58
- }"
59
- >
60
- {{ filter.text }}
61
- </slot>
62
- </v-list-item-title>
63
- <!-- This is a dynamic slot. You can use it to override filters content.-->
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. -->
64
15
  <slot
65
- :name="`filter.${filter.value}.content`"
16
+ :name="`filter.${filter.value}`"
66
17
  v-bind="{
67
18
  filter,
68
19
  addFilter,
@@ -71,63 +22,115 @@
71
22
  activeFilters,
72
23
  }"
73
24
  >
74
- <div v-if="filter.datepicker" class="d-flex flex-column align-end justify-center pb-2">
75
- <v-date-picker
76
- @input="addDateFilter(filter)"
77
- class="rounded-0"
78
- v-model="filter.dates"
79
- range
80
- full-width
81
- no-title
82
- color="primary"
83
- >
84
- </v-date-picker>
85
- <v-btn
86
- class="datapicker-clear-btn elevation-0"
87
- @click="removeFilter(filter)"
88
- small
89
- tile
90
- >clear</v-btn
91
- >
92
- </div>
93
- <v-list v-else class="overflow-y-auto pa-0" max-height="200" dense>
94
- <v-list-item
95
- v-for="(choice, i) in filter.choices"
96
- :key="i"
97
- class="v-list-item--link"
98
- active-class="primary--text"
99
- :input-value="isChoiceActive(filter, choice)"
100
- @click.native.stop="toggleChoice(filter, choice)"
101
- >
102
- <!-- This is a dynamic slot. You can use it to override filters icon. -->
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. -->
103
28
  <slot
104
- :name="`filter.${filter.value}.icon`"
105
- v-bind="{ filter, choice }"
29
+ :name="`filter.${filter.value}.title`"
30
+ v-bind="{
31
+ filter,
32
+ addFilter,
33
+ removeFilterChoice,
34
+ toggleChoice,
35
+ activeFilters,
36
+ }"
106
37
  >
107
- <v-list-item-icon>
108
- <v-icon
109
- v-text="choice.icon || 'mdi-circle-small'"
110
- ></v-icon>
111
- </v-list-item-icon>
38
+ {{ filter.text }}
112
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>
113
91
 
114
- <v-list-item-content>
115
- <v-list-item-title
116
- v-text="choice.text"
117
- ></v-list-item-title>
118
- </v-list-item-content>
119
- </v-list-item>
120
- </v-list>
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>
121
101
  </slot>
122
- </v-list-group>
123
- </slot>
124
- </div>
125
- </v-list>
126
- </v-menu>
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
127
  </div>
128
128
  </template>
129
129
 
130
130
  <style lang="scss" scoped>
131
+ .main{
132
+ width: 100%;
133
+ }
131
134
  .datapicker-clear-btn {
132
135
  margin: -20px 15px 0 0 ;
133
136
  }
@@ -155,13 +158,20 @@ export default {
155
158
  type: Array,
156
159
  default: () => [],
157
160
  },
161
+ // This is the v-model of the component. It contains the active filters.
162
+ value: {
163
+ // [`Array<Filter>`](#filter-config)
164
+ type: Array,
165
+ default: () => [],
166
+ },
158
167
  },
159
168
  methods: {
160
169
  addDateFilter(filter) {
161
170
  const { dates } = filter;
171
+ dates.sort((a,b) => Date.parse(a) - Date.parse(b));
162
172
  if (dates && dates.length > 1) {
163
173
  this.addFilter(filter, {
164
- text: dates.join(" ~ "),
174
+ text: dates.map(date => new Date(date).toLocaleDateString()).join(" ~ "),
165
175
  value: dates.join(","),
166
176
  });
167
177
  } else if (!dates || !dates.length) {
@@ -245,7 +255,6 @@ export default {
245
255
  if (index !== -1) {
246
256
  let filter = this.compFilters[index];
247
257
  if (filter.datepicker) {
248
- filter = { ...filter };
249
258
  filter.dates = [...this.$route.query[k].split(",")];
250
259
  this.addDateFilter(filter);
251
260
  } else {
@@ -257,6 +266,32 @@ export default {
257
266
  }
258
267
  });
259
268
  },
269
+ loadFilters() {
270
+ this.compFilters = this.filters.map(filter => ({...filter, dates: filter.datepicker ? [] : undefined}));
271
+ this.applyDefaultChoices()
272
+ },
273
+ applyDefaultChoices(){
274
+ this.compFilters.forEach(filter=>{
275
+ if (filter.defaultChoice){
276
+ if (filter.datepicker) {
277
+ filter.dates = [...filter.defaultChoice.split(",")];
278
+ this.addDateFilter(filter);
279
+ } else {
280
+ filter.choices.forEach((c) => {
281
+ filter.defaultChoice.split(",").includes(c.value + "") &&
282
+ this.addFilter(filter, c);
283
+ });
284
+ }
285
+ }
286
+ })
287
+ },
288
+ cleanActiveFilters(){
289
+ this.compFilters.forEach(filter => {
290
+ if (!this.activeFilters.find((f) => f.value == filter.value)) {
291
+ this.removeFilter(filter)
292
+ }
293
+ })
294
+ }
260
295
  },
261
296
  watch: {
262
297
  activeFilters: {
@@ -267,9 +302,18 @@ export default {
267
302
  this.setQparams(val);
268
303
  }, 200),
269
304
  },
305
+ value: {
306
+ deep: true,
307
+ handler(val){
308
+ if (JSON.stringify(val) !== JSON.stringify(this.activeFilters)){
309
+ this.activeFilters = val
310
+ this.cleanActiveFilters()
311
+ }
312
+ }
313
+ }
270
314
  },
271
- mounted() {
272
- this.compFilters = this.filters;
315
+ created() {
316
+ this.loadFilters();
273
317
  this.restoreFromQparams();
274
318
  },
275
319
  };
@@ -278,10 +322,11 @@ export default {
278
322
  <docs>
279
323
  ## Filter config
280
324
 
281
- The filters prop is a list of `Filter` objects made of several keys:
325
+ The filters prop is a list of `Filter` objects made of several keys:
282
326
 
283
327
  - **"text"** `String` ==> The name of the filter that will be renered inside the filter menu.
284
328
  - **"value"** `String` ==> The dotted path of the value we need to filter on.
329
+ - **"defaultChoice"** `String` ==> A choice value that is applied on the startup of the component. This lets you start the list with some filter already applied.
285
330
  - **"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.
286
331
  - **"datepicker"** `Boolean` ==> This is a boolean that determines if the filter has a datepicker layout.
287
332
  - **"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.
@@ -317,4 +362,4 @@ const filters = [
317
362
  },
318
363
  ]
319
364
  ```
320
- </docs>
365
+ </docs>
@@ -1,13 +1,15 @@
1
1
  <template>
2
2
  <div class="list__head">
3
- <h2 class="list__head__title display-1">{{ title }}</h2>
4
- <v-btn
5
- v-if="addItem"
6
- class="rounded-0 elevation-0"
7
- color="primary"
8
- :to="{path: `${$route.path}/new`}"
9
- >Add new <v-icon>mdi-plus</v-icon></v-btn
10
- >
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 &emsp; <v-icon>mdi-plus</v-icon></v-btn
11
+ >
12
+ </div>
11
13
  </div>
12
14
  </template>
13
15
 
@@ -18,10 +20,18 @@
18
20
  &__head {
19
21
  display: flex;
20
22
  align-items: center;
21
- justify-content: flex-start;
22
- margin-bottom: 4rem;
23
+ justify-content: space-between;
24
+ flex-wrap: wrap;
25
+ margin-bottom: 2rem;
23
26
  &__title {
24
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;
25
35
  }
26
36
  }
27
37
  }
@@ -40,10 +50,18 @@ export default {
40
50
  // The route name.
41
51
  default() {
42
52
  return this.$route.name;
43
- },
53
+ }
44
54
  },
45
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.
46
- addItem: Boolean,
56
+ addItem: Boolean
47
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
+ }
48
66
  };
49
67
  </script>