@mapomodule/uikit 1.0.0-alpha.5 → 1.0.0-alpha.9

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 (41) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/components/Detail/Detail.vue +182 -105
  3. package/components/Detail/DetailField.vue +42 -29
  4. package/components/Detail/DetailLangSwitch.vue +1 -1
  5. package/components/Detail/defaults.js +32 -25
  6. package/components/DropArea.vue +3 -3
  7. package/components/List/List.vue +77 -42
  8. package/components/List/ListActions.vue +19 -1
  9. package/components/List/ListFilters.vue +127 -113
  10. package/components/List/ListHead.vue +30 -12
  11. package/components/List/ListQuickEdit.vue +198 -55
  12. package/components/List/ListTable.vue +138 -58
  13. package/components/Login.vue +14 -5
  14. package/components/MediaManager/MediaEditor.vue +253 -107
  15. package/components/MediaManager/MediaFolders.vue +125 -41
  16. package/components/MediaManager/MediaGallery.vue +56 -52
  17. package/components/MediaManager/MediaManager.vue +114 -74
  18. package/components/MediaManager/MediaManagerDialog.vue +19 -22
  19. package/components/MediaManager/MediaPreview.vue +180 -0
  20. package/components/MediaManager/MediaUploader.vue +35 -32
  21. package/components/SnackBar.vue +3 -4
  22. package/components/fields/DateField.vue +9 -3
  23. package/components/fields/FksField.vue +60 -0
  24. package/components/fields/MediaField.vue +24 -6
  25. package/components/fields/MediaM2mField.vue +8 -3
  26. package/components/fields/SeoPreview.vue +89 -0
  27. package/components/fields/{TinyMce → wygEditor}/defaults.js +1 -1
  28. package/components/fields/{TinyMce → wygEditor}/utils/events.js +0 -0
  29. package/components/fields/{TinyMce → wygEditor}/utils/mapomedia.plugin.js +0 -0
  30. package/components/fields/{TinyMce → wygEditor}/utils/script.injector.js +0 -0
  31. package/components/fields/{TinyMce/TinyMce.vue → wygEditor/wygEditor.vue} +40 -21
  32. package/components/layout/Sidebar/Sidebar.vue +46 -24
  33. package/components/layout/Sidebar/SidebarFooter.vue +42 -46
  34. package/components/layout/Sidebar/SidebarList.vue +13 -14
  35. package/components/layout/Sidebar/SidebarListItem.vue +81 -38
  36. package/components/layout/Topbar/Topbar.vue +3 -36
  37. package/components/layout/routebuilder.js +1 -1
  38. package/layouts/default.vue +3 -14
  39. package/package.json +3 -3
  40. package/pages/index.vue +0 -1
  41. package/components/fields/M2mField.vue +0 -95
@@ -1,13 +1,24 @@
1
1
  <template>
2
- <component :is="is" v-model="model" v-bind="fieldProp"></component>
2
+ <div>
3
+ <span class="mapo-label" :class="`mapo-label-${conf.value}`">{{label}}</span>
4
+ <component :is="is" v-model="model" v-bind="fieldAttrs"></component>
5
+ </div>
3
6
  </template>
4
7
 
8
+ <style>
9
+ .mapo-label {
10
+ display: none;
11
+ }
12
+ </style>
13
+
5
14
  <script>
6
- import TinyMce from "@mapomodule/uikit/components/fields/TinyMce/TinyMce.vue";
15
+ import wygEditor from "@mapomodule/uikit/components/fields/wygEditor/wygEditor.vue";
7
16
  import DateField from "@mapomodule/uikit/components/fields/DateField.vue";
8
- import M2mField from "@mapomodule/uikit/components/fields/M2mField.vue";
17
+ import FksField from "@mapomodule/uikit/components/fields/FksField.vue";
9
18
  import MediaM2mField from "@mapomodule/uikit/components/fields/MediaM2mField.vue";
10
19
  import MediaField from "@mapomodule/uikit/components/fields/MediaField.vue";
20
+ import SeoPreview from "@mapomodule/uikit/components/fields/SeoPreview.vue";
21
+
11
22
 
12
23
  import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
13
24
  import defaults from "./defaults";
@@ -18,26 +29,27 @@ import defaults from "./defaults";
18
29
  export default {
19
30
  name: "DetailField",
20
31
  components: {
21
- TinyMce,
32
+ wygEditor,
22
33
  DateField,
23
- M2mField,
34
+ FksField,
24
35
  MediaM2mField,
25
- MediaField
36
+ MediaField,
37
+ SeoPreview,
26
38
  },
27
39
 
28
40
  data() {
29
41
  return {
30
42
  model: null,
31
- fieldsMap: defaults.mapping,
32
- fieldsProps: defaults.props,
33
- fieldsAccess: defaults.accessor
43
+ defaultMap: defaults.mapping,
44
+ defaultAttrs: defaults.props,
45
+ defaultAccess: defaults.accessor,
34
46
  };
35
47
  },
36
48
  props: {
37
49
  // V-model of the payload needed to edit the field value in realtime.
38
50
  value: {
39
51
  type: Object,
40
- required: true
52
+ required: true,
41
53
  },
42
54
  // An object representing all the errors of all fields. This means that this component will find the error of its field following the dottedPath of the value in the error dict.
43
55
  errors: Object,
@@ -45,18 +57,18 @@ export default {
45
57
  conf: {
46
58
  // [`FieldConfiguration`](/components/detail/Detail/#fieldconfiguration)
47
59
  type: Object,
48
- required: true
49
- }
60
+ required: true,
61
+ },
50
62
  },
51
63
  watch: {
52
64
  value: {
53
65
  deep: true,
54
66
  handler(val) {
55
67
  this.setModel(val);
56
- }
68
+ },
57
69
  },
58
- conf(newConf, oldConf) {
59
- if (newConf.value !== oldConf.value) {
70
+ "conf.value"(newValue, oldValue) {
71
+ if (newValue !== oldValue) {
60
72
  this.setModel();
61
73
  }
62
74
  },
@@ -70,43 +82,44 @@ export default {
70
82
  // Fired when the v-model changes.
71
83
  // @arg Emits the entire payload modified.
72
84
  this.$emit("input", dump);
73
- }
85
+ },
74
86
  },
75
87
  methods: {
76
88
  setModel(val = this.value) {
77
89
  var model = this.accessor.get({
78
90
  model: { ...val },
79
- val: getPointed({ ...val }, this.conf.value)
91
+ val: getPointed({ ...val }, this.conf.value),
80
92
  });
81
93
  if (val && JSON.stringify(this.model) !== JSON.stringify(model))
82
94
  this.model = model;
83
- }
95
+ },
84
96
  },
85
97
  computed: {
86
98
  accessor() {
87
- let func = function({ val }) {
99
+ let func = function ({ val }) {
88
100
  return val;
89
101
  };
90
102
  return {
91
103
  get: func,
92
104
  set: func,
93
- ...(this.fieldsAccess[this.is] || {}),
94
- ...this.conf.accessor
105
+ ...(this.defaultAccess[this.is] || {}),
106
+ ...this.conf.accessor,
95
107
  };
96
108
  },
97
- fieldProp() {
109
+ fieldAttrs() {
98
110
  return {
99
111
  label: this.label,
100
112
  errorMessages: getPointed(this.errors || {}, this.conf.value, []),
101
- ...(this.fieldsProps[this.is] || {}),
102
- ...this.conf.attrs
113
+ ...this.defaultAttrs.All,
114
+ ...(this.defaultAttrs[this.is.replace(/-./g, x=>x[1].toUpperCase())] || {}),
115
+ ...this.conf.attrs,
103
116
  };
104
117
  },
105
118
  label() {
106
119
  if (this.conf.label !== undefined) {
107
120
  return this.conf.label;
108
121
  }
109
- const titleCase = string =>
122
+ const titleCase = (string) =>
110
123
  (string && string[0].toUpperCase() + string.slice(1).toLowerCase()) ||
111
124
  "";
112
125
  return titleCase(
@@ -120,10 +133,10 @@ export default {
120
133
  is() {
121
134
  return (
122
135
  this.conf.is ||
123
- (this.conf.type && this.fieldsMap[this.conf.type]) ||
124
- "v-text-field"
136
+ (this.conf.type && this.defaultMap[this.conf.type]) ||
137
+ "vTextField"
125
138
  );
126
- }
127
- }
139
+ },
140
+ },
128
141
  };
129
142
  </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <v-tabs v-model="tab">
2
+ <v-tabs v-model="tab" show-arrows>
3
3
  <v-tab v-for="lang in langs" :key="lang">
4
4
  <v-badge :value="hasErrors(lang)" color="error" dot>
5
5
  {{ lang }}
@@ -1,35 +1,38 @@
1
1
  const mapping = {
2
- text: "v-text-field",
3
- select: "v-select",
4
- date: "date-field",
5
- textarea: "v-textarea",
6
- switch: "v-switch",
7
- slider: "v-slider",
8
- file: "v-file-input",
9
- editor: "tiny-mce",
10
- media: "media-field",
11
- m2m: "m2m-field",
12
- mediaList: "media-m2m-field"
2
+ text: "vTextField",
3
+ select: "vSelect",
4
+ date: "DateField",
5
+ textarea: "vTextarea",
6
+ switch: "vSwitch",
7
+ slider: "vSlider",
8
+ file: "vFileInput",
9
+ editor: "wygEditor",
10
+ media: "MediaField",
11
+ fks: "FksField",
12
+ m2m: "FksField",
13
+ mediaList: "MediaM2mField",
14
+ seoPreview: "SeoPreview"
13
15
  }
14
16
 
15
17
  const props = {
16
- "v-text-field": {
17
- outlined: true
18
- },
19
- "v-textarea": {
20
- outlined: true
21
- },
22
- "date-field": {
23
- outlined: true
24
- },
25
- "v-select": {
26
- outlined: true,
18
+ vSelect: {
27
19
  itemText: "text",
28
20
  itemValue: "value"
29
21
  },
30
- "v-switch": {
22
+ MediaField: {
23
+ outlined: false
24
+ },
25
+ vSwitch: {
31
26
  inset: true,
32
27
  ripple: false
28
+ },
29
+ FksField:{
30
+ itemValue: "id",
31
+ returnObject: true,
32
+ },
33
+ All : {
34
+ outlined: true,
35
+ class: "rounded-0",
33
36
  }
34
37
  }
35
38
 
@@ -38,11 +41,15 @@ const dateFunc = function ({ val }) {
38
41
  };
39
42
 
40
43
  const accessor = {
41
- "v-date-picker": {
44
+ vDatePicker: {
42
45
  get: dateFunc, set: dateFunc
43
46
  },
44
- "date-field": {
47
+ DateField: {
45
48
  get: dateFunc, set: dateFunc
49
+ },
50
+ SeoPreview: {
51
+ get: ({ val }) => ({ title: "", permalink: "", description: "", ...val }),
52
+ set: ({ val }) => ({ title: "", permalink: "", description: "", ...val })
46
53
  }
47
54
  }
48
55
  export default {
@@ -69,7 +69,7 @@
69
69
  <!-- Slot to provide custom button actions inside the drop area -->
70
70
  <slot v-bind:clearList="clearList" name="actions">
71
71
  <!-- `<v-btn @click="clearList" icon><v-icon>mdi-close</v-icon></v-btn>` -->
72
- <v-btn @click="clearList" icon>
72
+ <v-btn v-if="uploadedFiles && uploadedFiles.length" @click="clearList" icon>
73
73
  <v-icon>mdi-close</v-icon>
74
74
  </v-btn>
75
75
  </slot>
@@ -112,8 +112,8 @@
112
112
 
113
113
  <v-card-actions>
114
114
  <v-spacer></v-spacer>
115
- <v-btn color="green darken-1" text @click="closeEdit"> Cancel </v-btn>
116
- <v-btn color="green darken-1" text @click="saveEdit"> Save </v-btn>
115
+ <v-btn color="primary" text @click="closeEdit"> Cancel </v-btn>
116
+ <v-btn color="primary" text @click="saveEdit"> Save </v-btn>
117
117
  </v-card-actions>
118
118
  </v-card>
119
119
  </v-dialog>
@@ -3,7 +3,7 @@
3
3
  <ListHead v-bind="$attrs" />
4
4
 
5
5
  <div>
6
- <v-row class="mb-4">
6
+ <v-row class="mb-1">
7
7
  <v-col cols="12" md="4">
8
8
  <ListActions
9
9
  v-bind="$attrs"
@@ -14,9 +14,22 @@
14
14
  />
15
15
  </v-col>
16
16
  <v-col cols="12" md="8" class="d-flex flex-nowrap justify-end align-center">
17
- <!-- Overrides counter for selected items. -->
17
+ <ListFilters v-bind="$attrs" v-model="filters">
18
+ <template v-for="(_, slot) in $slots" :slot="slot">
19
+ <!-- @vuese-ignore -->
20
+ <slot :name="slot"></slot>
21
+ </template>
22
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
23
+ <!-- @vuese-ignore -->
24
+ <slot :name="slot" v-bind="props" />
25
+ </template>
26
+ </ListFilters>
27
+ </v-col>
28
+ </v-row>
29
+ <div class="d-flex justify-end">
30
+ <!-- Overrides counter for selected items. -->
18
31
  <slot name="item-counter" v-bind="{ selection, canSelectAll, allSelected, toggleSelectAll }">
19
- <div class="caption mr-1">
32
+ <div v-if="selection" class="caption mr-1 mb-1">
20
33
  <b v-if="allSelected">All items selected</b>
21
34
  <span v-else-if="selection.length">
22
35
  {{ selection.length }} items selected
@@ -32,18 +45,7 @@
32
45
  </span>
33
46
  </div>
34
47
  </slot>
35
- <ListFilters v-bind="$attrs" v-model="filters">
36
- <template v-for="(_, slot) in $slots" :slot="slot">
37
- <!-- @vuese-ignore -->
38
- <slot :name="slot"></slot>
39
- </template>
40
- <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
41
- <!-- @vuese-ignore -->
42
- <slot :name="slot" v-bind="props" />
43
- </template>
44
- </ListFilters>
45
- </v-col>
46
- </v-row>
48
+ </div>
47
49
  </div>
48
50
  <div>
49
51
  <ListTable
@@ -86,8 +88,7 @@ export default {
86
88
  props: {
87
89
  // The url of the endpoint that provides the data to display. From this url a complete crud (See [this.$mapo.$api.crud](/core/#$api.crud)) will be created.
88
90
  endpoint: {
89
- type: String,
90
- required: true,
91
+ type: String
91
92
  },
92
93
  // Add option to select all items in all pages
93
94
  canSelectAll: Boolean,
@@ -156,20 +157,25 @@ This is an interactive example. You can play with it but remember that all http
156
157
 
157
158
  ::: demo
158
159
  <template>
159
- <v-app >
160
- <List
160
+ <v-app>
161
+ <List
161
162
  show-select
163
+ title="Sweets archive:"
164
+ lookup="name"
162
165
  :headers="headers"
163
166
  :editFields="editFields"
164
167
  :filters="availableFilters"
165
- endpoint="api/camomilla/articles"
166
- title="List Example"
167
- addItem
168
- canSelectAll
168
+ multi-sort
169
+ can-select-all
169
170
  searchable
170
- >
171
- </List>
172
- </v-app>
171
+ :data.sync="desserts"
172
+ :actions="[]"
173
+ >
174
+ </List>
175
+ <br>
176
+ <h3> Data: </h3>
177
+ <pre>{{ desserts }}</pre>
178
+ </v-app>
173
179
  </template>
174
180
 
175
181
  <script>
@@ -178,37 +184,66 @@ export default {
178
184
  return {
179
185
  headers: [
180
186
  {
181
- text: "ID",
187
+ text: "Dessert (100g serving)",
182
188
  align: "start",
183
189
  sortable: false,
184
- value: "id",
190
+ value: "name",
185
191
  },
186
- { text: "Title", value: "title" },
187
- { text: "Identifier", value: "identifier" },
192
+ { text: "Protein (g)", value: "protein" },
193
+ { text: "Gluten-Free", value: "glutenfree" },
188
194
  { text: "Actions", value: "actions", sortable: false },
189
195
  ],
190
196
  editFields: [
191
- { attrs: { rules:[v => !!v || 'Title is required'] }, value: "title" },
192
- { attrs: { rules:[v => !!v || 'Permalink is required'] }, value: "permalink" },
193
- { attrs: { rules:[v => !!v || 'Identifier is required'] }, value: "identifier" },
197
+ { attrs: { rules: [(v) => !!v || "Name is required"] }, value: "name" },
198
+ { value: "protein" }
194
199
  ],
195
200
  availableFilters: [
196
201
  {
197
- text: "Status",
198
- value: "status",
202
+ text: "Gluten Free",
203
+ value: "glutenfree",
199
204
  choices: [
200
- { text: "Draft", value: "DRF" },
201
- { text: "Published", value: "PUB" },
202
- { text: "Trash", value: "TRS" },
205
+ { text: "Yes", value: true },
206
+ { text: "No", value: false },
203
207
  ],
204
208
  },
209
+ ],
210
+ desserts: [
211
+ {
212
+ name: "Frozen Yogurt",
213
+ protein: 4.0,
214
+ glutenfree: true,
215
+ },
216
+ {
217
+ name: "Ice cream sandwich",
218
+ protein: 4.3,
219
+ glutenfree: false,
220
+ },
205
221
  {
206
- text: "Date",
207
- value: "date",
208
- datepicker: true
222
+ name: "Eclair",
223
+ protein: 6.0,
224
+ glutenfree: false,
225
+ },
226
+ {
227
+ name: "Jelly bean",
228
+ protein: 0.0,
229
+ glutenfree: true,
230
+ },
231
+ {
232
+ name: "Lollipop",
233
+ protein: 0,
234
+ glutenfree: true,
235
+ },
236
+ {
237
+ name: "KitKat",
238
+ protein: 7,
239
+ glutenfree: false,
240
+ },
241
+ {
242
+ name: "KitKat2",
243
+ protein: 77,
244
+ glutenfree: false,
209
245
  },
210
246
  ],
211
-
212
247
  };
213
248
  },
214
249
  };
@@ -5,6 +5,7 @@
5
5
  v-bind="$attrs"
6
6
  v-model="action"
7
7
  :items="filteredActions"
8
+ :item-disabled="isDisabled"
8
9
  item-text="label"
9
10
  item-value="handler"
10
11
  outlined
@@ -12,6 +13,7 @@
12
13
  hide-details
13
14
  clearable
14
15
  no-data-text="No actions available"
16
+ class="rounded-0"
15
17
  ></v-select>
16
18
  <v-btn
17
19
  class="rounded-0 elevation-0 ml-2"
@@ -51,8 +53,9 @@ export default {
51
53
  {
52
54
  label: "Permanent delete",
53
55
  handler: function ({ selection, lookup, crud }) {
54
- return Promise.all(selection.map((i) => crud.delete(i[lookup])));
56
+ return Promise.all(selection.map((i) => crud && crud.delete(i[lookup])));
55
57
  },
58
+ permissions: "delete"
56
59
  },
57
60
  ];
58
61
  },
@@ -89,6 +92,19 @@ export default {
89
92
  }
90
93
  },
91
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
+ },
92
108
  handleAction() {
93
109
  if (!this.selectAll && !this.selection.length) {
94
110
  return this.$mapo.$snack.open({
@@ -120,6 +136,7 @@ The actions prop is a list of `Action` objects containing these keys:
120
136
  - **"handleMultiple"** `Boolean` ==> Make the action callable on multiple items. Default: `true`.
121
137
  - **"handleAll"** `Boolean` ==> Make the action callable on all items. Default: `false`.
122
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
123
140
 
124
141
  The handler function will be called with a ctx containing:
125
142
  - **"selection"** `Array<Object>` or `String` ==> `"all"` if all items are selected else the list of selected objects.
@@ -140,6 +157,7 @@ const actions = [
140
157
  selection.map((i) => crud.delete(i[lookup]))
141
158
  );
142
159
  },
160
+ permissions: "delete"
143
161
  }
144
162
  ]
145
163
  ```