@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
@@ -3,19 +3,23 @@
3
3
  <v-data-table
4
4
  v-model="selection"
5
5
  v-bind="$attrs"
6
- :items="httpEnabled ? items : filteredItems"
6
+ :items="serverPaginationEnabled ? items : filteredItems"
7
7
  :loading="loading"
8
8
  :options.sync="options"
9
- :search="searchable && !httpEnabled ? searchValue : ''"
10
- :server-items-length="httpPaginator.count || -1"
11
- :class="{ 'mapo__listtable__all_selected': selectAll }"
9
+ :search="searchString"
10
+ :server-items-length="serverItemsLength"
11
+ :class="{ mapo__listtable__all_selected: selectAll }"
12
+ :item-key="lookup"
12
13
  >
13
14
  <template v-slot:top>
14
15
  <v-toolbar flat>
15
16
  <v-text-field
16
17
  v-if="searchable"
17
- v-model="searchValue"
18
- @input="loadingSearch = true; changeSearch()"
18
+ v-model="searchString"
19
+ @input="
20
+ loadingSearch = serverPaginationEnabled;
21
+ search();
22
+ "
19
23
  prepend-inner-icon="mdi-magnify"
20
24
  label="Search"
21
25
  single-line
@@ -24,16 +28,16 @@
24
28
  dense
25
29
  clearable
26
30
  :loading="loadingSearch"
27
- style="max-width: 300px"
31
+ class="search-input rounded-0"
28
32
  ></v-text-field>
29
33
  <v-spacer></v-spacer>
30
34
  <slot name="dtable.top.center"></slot>
31
35
  <v-spacer></v-spacer>
32
- <v-btn text v-if="shouldEdit" @click="editItem()">
33
- <v-icon small left class="mr-2"> mdi-plus </v-icon>
34
- Quick add
36
+ <v-btn text v-if="quickModeEnabled && userCan('add')" class="ml-2" @click="quickAction()">
37
+ <v-icon small left class="d-none d-sm-block mr-2"> mdi-plus </v-icon>
38
+ <span class="d-none d-sm-block">Quick</span> add
35
39
  </v-btn>
36
- <v-btn class="ma-2" @click="getDataFromApi(false)" icon>
40
+ <v-btn v-if="serverPaginationEnabled" class=" mx-sm-2 ma-2 mx-0" @click="getDataFromApi(false)" icon>
37
41
  <v-icon>mdi-update</v-icon>
38
42
  </v-btn>
39
43
  </v-toolbar>
@@ -51,42 +55,59 @@
51
55
  <v-simple-checkbox v-model="selectAll" @input="on.input"></v-simple-checkbox>
52
56
  </template>
53
57
  <template v-slot:[`item.actions`]="{ item }">
54
- <v-icon v-if="shouldEdit" small class="mr-2" @click="editItem(item)">
58
+ <v-icon :disabled="!userCan('change')" v-if="quickModeEnabled" small class="mr-2" @click="quickAction(item)">
55
59
  mdi-pencil
56
60
  </v-icon>
57
- <v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
61
+ <v-icon :disabled="!userCan('delete')" small @click="deleteItem(item)"> mdi-delete </v-icon>
58
62
  </template>
59
- <template v-for="slot in filterSlots($slots, 'dtable.')" :slot="slot">
63
+ <template v-for="slot in nameSpacedSlots($slots, 'dtable.')" :slot="slot">
60
64
  <slot :name="`dtable.${slot}`"></slot>
61
65
  </template>
62
66
  <template
63
- v-for="slot in filterSlots($scopedSlots, 'dtable.')"
67
+ v-for="slot in nameSpacedSlots($scopedSlots, 'dtable.')"
64
68
  v-slot:[slot]="props"
65
69
  >
66
70
  <slot :name="`dtable.${slot}`" v-bind="props" />
67
71
  </template>
68
72
  </v-data-table>
69
73
  <list-quick-edit
70
- v-if="shouldEdit"
74
+ v-if="quickModeEnabled"
71
75
  ref="editModal"
72
- v-bind="{ ...$attrs, value: false, crud }"
76
+ :offline="offlineMode"
77
+ v-bind="{ ...$attrs, value: false, crud, lookup: lookup }"
73
78
  >
74
- <template v-for="slot in filterSlots($slots, 'qedit.')" :slot="slot">
79
+ <template v-for="slot in nameSpacedSlots($slots, 'qedit.')" :slot="slot">
75
80
  <slot :name="`qedit.${slot}`"></slot>
76
81
  </template>
77
- <template v-for="slot in filterSlots($scopedSlots, 'qedit.')" v-slot:[slot]="props">
82
+ <template v-for="slot in nameSpacedSlots($scopedSlots, 'qedit.')" v-slot:[slot]="props">
78
83
  <slot :name="`qedit.${slot}`" v-bind="props" />
79
84
  </template>
80
85
  </list-quick-edit>
81
86
  </div>
82
87
  </template>
83
88
 
84
- <style lang="scss">
89
+ <style lang="scss" scoped>
85
90
  .mapo__listtable__all_selected {
86
91
  .v-data-table__selected {
87
92
  background: none !important;
88
93
  }
89
94
  }
95
+ .search-input{
96
+ max-width: 300px;
97
+ @media (max-width: 400px) {
98
+ &.v-input--is-focused{
99
+ position: absolute;
100
+ z-index: 1;
101
+ width: calc(100% - 32px);
102
+ &.theme--dark{
103
+ background: #272727;
104
+ }
105
+ &.theme--light{
106
+ background: #fff;
107
+ }
108
+ }
109
+ }
110
+ }
90
111
  </style>
91
112
 
92
113
  <script>
@@ -102,16 +123,16 @@ export default {
102
123
  selectAll: false,
103
124
  options: {},
104
125
  httpPaginator: {},
105
- searchValue: "",
126
+ searchString: "",
106
127
  loadingSearch: false,
107
- disableHttp: false
128
+ noPagination: false,
108
129
  }),
109
130
  props: {
110
131
  crud: {
111
132
  type: Object,
112
- required: true,
133
+ required: true
113
134
  },
114
- http: Boolean,
135
+ serverPagination: Boolean,
115
136
  navigable: Boolean,
116
137
  lookup: {
117
138
  type: String,
@@ -131,6 +152,10 @@ export default {
131
152
  type: Boolean,
132
153
  default: false,
133
154
  },
155
+ data: {
156
+ type: Array,
157
+ required: false
158
+ },
134
159
  },
135
160
  watch: {
136
161
  selection(val) {
@@ -142,20 +167,26 @@ export default {
142
167
  filters: {
143
168
  deep: true,
144
169
  handler() {
145
- this.httpEnabled && this.getDataFromApi();
170
+ this.serverPaginationEnabled && this.getDataFromApi();
146
171
  },
147
172
  },
148
173
  options: {
149
174
  deep: true,
150
175
  handler(options) {
151
- this.disableHttp = options.itemsPerPage === -1;
176
+ this.noPagination = options.itemsPerPage === -1;
152
177
  this.setQparams(options);
153
- this.httpEnabled && this.getDataFromApi(false);
178
+ this.serverPaginationEnabled && this.getDataFromApi(false);
154
179
  },
155
180
  },
156
- disableHttp() {
181
+ noPagination() {
157
182
  this.getDataFromApi();
158
183
  },
184
+ data: {
185
+ deep: true,
186
+ handler(data) {
187
+ if (data) this.items = data;
188
+ },
189
+ }
159
190
  },
160
191
  methods: {
161
192
  getDataFromApi(clearSelection = true) {
@@ -163,18 +194,19 @@ export default {
163
194
  this.selection = [];
164
195
  this.selectAll = false;
165
196
  }
166
- this.loading = true;
167
- this.debouncedDataFromApi();
197
+ this.loading = !this.offlineMode;
198
+ !this.offlineMode && this.debouncedDataFromApi();
168
199
  },
169
200
  debouncedDataFromApi: debounce(function () {
170
201
  return new Promise((resolve, reject) => {
171
202
  this.selection = [];
172
- if (!this.httpEnabled) {
203
+ if (!this.serverPaginationEnabled) {
173
204
  this.crud
174
205
  .list()
175
206
  .then((data) => {
176
207
  this.items = data;
177
208
  this.loading = false;
209
+ this.httpPaginator = {};
178
210
  resolve(data);
179
211
  })
180
212
  .catch((error) => reject(error));
@@ -203,20 +235,25 @@ export default {
203
235
  restoreFromQparams() {
204
236
  this.options = {
205
237
  ...this.options,
206
- sortBy: this.$route.query.sort?.split(".") || [],
207
- sortDesc: this.$route.query.order?.split(".").map((e) => e == "desc") || [],
238
+ sortBy:
239
+ this.$route.query.sort?.split(",").map((p) => p.replace(/^-/, "")) ||
240
+ this.options.sortBy ||
241
+ [],
242
+ sortDesc:
243
+ this.$route.query.order?.split(",").map((p) => p.startsWith("-")) ||
244
+ this.options.sortDesc ||
245
+ [],
208
246
  itemsPerPage:
209
247
  parseInt(this.$route.query.items) || this.options.itemsPerPage || 10,
248
+ page: parseInt(this.$route.query.page) || this.options.page || 1,
210
249
  };
211
- this.searchValue = this.$route.query.search;
250
+ this.searchString = this.$route.query.search;
212
251
  },
213
252
  getOrderParams(options) {
214
253
  const { sortBy, sortDesc, page, itemsPerPage } = options;
215
- const sort = sortBy.length ? sortBy.join(".") : undefined;
216
- const order = sortDesc.length
217
- ? sortDesc.map((e) => (e ? "desc" : "asc")).join(".")
218
- : undefined;
219
- return { sort, order, items: itemsPerPage, page: page !== 1 ? page : undefined };
254
+ const sort =
255
+ sortBy.map((field, i) => (sortDesc[i] ? "-" : "") + field).join(",") || undefined;
256
+ return { sort, items: itemsPerPage, page: page !== 1 ? page : undefined };
220
257
  },
221
258
  getHttpParams() {
222
259
  const params = new URLSearchParams();
@@ -237,27 +274,53 @@ export default {
237
274
  } else {
238
275
  query.push(`${format(fi.value)}=${fi.active[0].value}`);
239
276
  }
240
- query.forEach(q => params.append('fltr', q))
277
+ query.forEach((q) => params.append("fltr", q));
241
278
  });
242
- if (this.searchValue && this.searchable)
243
- params.append("search", this.searchValue);
279
+ if (this.searchString && this.searchable) params.append("search", this.searchString);
244
280
  return params;
245
281
  },
246
- editItem(item) {
247
- this.$refs.editModal.open(item).then((r) => r && this.getDataFromApi());
282
+ quickAction(item) {
283
+ this.$refs.editModal.open(item).then((r) => {
284
+ if (!r) return;
285
+ if (!this.offlineMode) {
286
+ this.getDataFromApi();
287
+ } else {
288
+ let index = item ? this.items.findIndex((i) => i[this.lookup] === item[this.lookup]) : -1;
289
+ let update = true;
290
+
291
+ if (index !== -1) {
292
+ this.items.splice(index, 1, r);
293
+ } else {
294
+ index = this.items.push(r);
295
+ update = false;
296
+ }
297
+ this.$emit("update:data", this.items, r, index);
298
+ }
299
+ });
248
300
  },
249
301
  deleteItem(item) {
250
- const callback = (item) =>
251
- this.crud.delete(item[this.lookup]).then(this.getDataFromApi);
302
+ const callback = (item) => {
303
+ if (!this.offlineMode) {
304
+ this.crud.delete(item[this.lookup]).then(this.getDataFromApi);
305
+ } else {
306
+ const index = this.items.findIndex((i) => i[this.lookup] === item[this.lookup]);
307
+
308
+ if (index !== -1) {
309
+ this.items.splice(index, 1);
310
+ this.$emit("update:data", this.items, r, index);
311
+ }
312
+ }
313
+ };
314
+
252
315
  this.$mapo.$confirm
253
316
  .open({
254
317
  title: "Delete",
255
318
  question: "Are you sure you want to delete this item?",
256
- approveButton: { text: "Delete", attrs: { color: "red" } },
319
+ approveButton: { text: "Delete", attrs: { color: "red", text: true } },
257
320
  })
258
321
  .then((res) => (res ? callback(item) : null));
259
322
  },
260
- filterSlots(slots, scope) {
323
+ nameSpacedSlots(slots, scope) {
261
324
  return Object.keys(slots)
262
325
  .filter((name) => name.startsWith(scope))
263
326
  .map((name) => name.replace(scope, ""));
@@ -265,17 +328,23 @@ export default {
265
328
  toggleSelectAll() {
266
329
  this.selectAll = !this.selectAll;
267
330
  },
268
- changeSearch: debounce(function () {
331
+ search: debounce(function () {
269
332
  this.$router.push({
270
333
  query: {
271
334
  ...this.$route.query,
272
- search: this.searchValue,
335
+ search: this.searchString || undefined,
273
336
  },
274
337
  });
275
338
 
276
- this.httpEnabled && this.getDataFromApi();
339
+ this.serverPaginationEnabled && this.getDataFromApi();
277
340
  this.loadingSearch = false;
278
- }, 1000)
341
+ }, 1000),
342
+ userCan(action) {
343
+ if (this.$mapo.$auth.routeMiddlewares.includes("permissions")){
344
+ return this.$mapo.$auth.user.permissions.includes(action)
345
+ }
346
+ return true
347
+ },
279
348
  },
280
349
  computed: {
281
350
  filteredItems() {
@@ -307,20 +376,31 @@ export default {
307
376
  this.$attrs.headers && this.$attrs.headers.length && this.$attrs.headers[0].value
308
377
  );
309
378
  },
310
- shouldEdit() {
379
+ quickModeEnabled() {
311
380
  return (
312
- this.filterSlots(this.$slots, "qedit.body").length ||
313
- this.filterSlots(this.$scopedSlots, "qedit.body").length ||
381
+ this.nameSpacedSlots(this.$slots, "qedit.body").length ||
382
+ this.nameSpacedSlots(this.$scopedSlots, "qedit.body").length ||
314
383
  (this.$attrs.editFields && this.$attrs.editFields.length)
315
384
  );
316
385
  },
317
- httpEnabled() {
318
- return this.http && !this.disableHttp;
386
+ serverPaginationEnabled() {
387
+ return this.serverPagination && !this.noPagination && !this.offlineMode;
388
+ },
389
+ offlineMode() {
390
+ return !!this.data;
391
+ },
392
+ serverItemsLength() {
393
+ return this.httpPaginator.count || (this.serverPaginationEnabled && (this.options.page * this.options.itemsPerPage)) || -1;
319
394
  },
320
395
  },
321
396
  mounted() {
322
397
  this.restoreFromQparams();
323
- this.httpEnabled || this.getDataFromApi();
398
+ if (!this.offlineMode) {
399
+ this.getDataFromApi();
400
+ } else {
401
+ this.items = this.data;
402
+ this.loading = false;
403
+ }
324
404
  },
325
405
  };
326
406
  </script>
@@ -17,6 +17,7 @@
17
17
  filled
18
18
  dense
19
19
  light
20
+ :error-messages="errors.username"
20
21
  ></v-text-field>
21
22
  <v-text-field
22
23
  class="rounded-0"
@@ -29,13 +30,20 @@
29
30
  dense
30
31
  filled
31
32
  light
33
+ :error-messages="errors.password"
32
34
  :type="showPass ? 'text' : 'password'"
33
35
  ></v-text-field>
34
36
  <div class="text-center">
35
37
  <v-btn type="submit" class="rounded-0" elevation="0" dark>
36
38
  Log In
37
39
  </v-btn>
40
+ <v-messages
41
+ v-model="errors.non_field_errors"
42
+ color="error"
43
+ class="mt-4 text-center"
44
+ />
38
45
  </div>
46
+
39
47
  </v-form>
40
48
  </div>
41
49
  </div>
@@ -48,6 +56,7 @@ export default {
48
56
  username: "",
49
57
  password: null,
50
58
  showPass: false,
59
+ errors: {}
51
60
  };
52
61
  },
53
62
  watch: {
@@ -77,11 +86,11 @@ export default {
77
86
  query: this.otherQuery,
78
87
  })
79
88
  )
80
- .catch((err) => {
81
- console.log(err)
82
- this.$mapo.$snack.open({message: err})
83
- this.hasErr = true;
84
- this.errMsg = err.message;
89
+ .catch((error) => {
90
+ this.errors = error.response?.data || {}
91
+ if (!Object.keys(this.errors).length){
92
+ this.$mapo.$snack.open({message: "Cannot login right now. Try again later.", color: "error"})
93
+ }
85
94
  });
86
95
  },
87
96
  },