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

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 (31) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/components/Detail/Detail.vue +156 -95
  3. package/components/Detail/DetailField.vue +14 -11
  4. package/components/Detail/defaults.js +6 -1
  5. package/components/DropArea.vue +1 -1
  6. package/components/List/List.vue +100 -40
  7. package/components/List/ListActions.vue +38 -17
  8. package/components/List/ListFilters.vue +127 -113
  9. package/components/List/ListHead.vue +23 -13
  10. package/components/List/ListQuickEdit.vue +14 -5
  11. package/components/List/ListTable.vue +218 -76
  12. package/components/MediaManager/MediaEditor.vue +247 -107
  13. package/components/MediaManager/MediaFolders.vue +122 -38
  14. package/components/MediaManager/MediaGallery.vue +56 -52
  15. package/components/MediaManager/MediaManager.vue +114 -74
  16. package/components/MediaManager/MediaManagerDialog.vue +19 -22
  17. package/components/MediaManager/MediaPreview.vue +180 -0
  18. package/components/MediaManager/MediaUploader.vue +35 -32
  19. package/components/fields/MediaField.vue +12 -2
  20. package/components/fields/SeoPreview.vue +89 -0
  21. package/components/fields/TinyMce/TinyMce.vue +29 -10
  22. package/components/fields/TinyMce/defaults.js +1 -1
  23. package/components/layout/Sidebar/Sidebar.vue +46 -24
  24. package/components/layout/Sidebar/SidebarFooter.vue +41 -46
  25. package/components/layout/Sidebar/SidebarList.vue +12 -14
  26. package/components/layout/Sidebar/SidebarListItem.vue +65 -38
  27. package/components/layout/Topbar/Topbar.vue +3 -36
  28. package/components/layout/routebuilder.js +1 -1
  29. package/layouts/default.vue +3 -14
  30. package/package.json +2 -2
  31. package/pages/index.vue +1 -2
@@ -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"
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,10 @@ 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,
47
- },
56
+ addItem: Boolean
57
+ }
48
58
  };
49
59
  </script>
@@ -84,8 +84,9 @@ export default {
84
84
  },
85
85
  crud: {
86
86
  type: Object,
87
- required: true,
87
+ required: true
88
88
  },
89
+ offline: Boolean
89
90
  },
90
91
  watch: {
91
92
  value(val) {
@@ -147,12 +148,20 @@ export default {
147
148
  this.dialog = false;
148
149
  },
149
150
  apiEdit() {
150
- return this.crud
151
- .partialUpdate(this.itemRef[this.lookup], this.editedItem)
152
- .then((res) => this.close(res));
151
+ if (!this.offline) {
152
+ return this.crud
153
+ .partialUpdate(this.itemRef[this.lookup], this.editedItem)
154
+ .then((res) => this.close(res));
155
+ } else {
156
+ this.close(this.editedItem);
157
+ }
153
158
  },
154
159
  apiCreate() {
155
- return this.crud.create(this.editedItem).then((res) => this.close(res));
160
+ if (!this.offline) {
161
+ return this.crud.create(this.editedItem).then((res) => this.close(res));
162
+ } else {
163
+ return this.close(this.editedItem);
164
+ }
156
165
  },
157
166
  },
158
167
  };
@@ -3,21 +3,41 @@
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
- :server-items-length="httpPaginator.count || -1"
9
+ :search="searchString"
10
+ :server-items-length="serverItemsLength"
11
+ :class="{ mapo__listtable__all_selected: selectAll }"
12
+ :item-key="lookup"
10
13
  >
11
14
  <template v-slot:top>
12
15
  <v-toolbar flat>
13
- <v-btn text v-if="shouldEdit" @click="editItem()">
14
- <v-icon small left class="mr-2"> mdi-plus </v-icon>
15
- Quick add
16
- </v-btn>
16
+ <v-text-field
17
+ v-if="searchable"
18
+ v-model="searchString"
19
+ @input="
20
+ loadingSearch = serverPaginationEnabled;
21
+ search();
22
+ "
23
+ prepend-inner-icon="mdi-magnify"
24
+ label="Search"
25
+ single-line
26
+ hide-details
27
+ outlined
28
+ dense
29
+ clearable
30
+ :loading="loadingSearch"
31
+ class="search-input"
32
+ ></v-text-field>
17
33
  <v-spacer></v-spacer>
18
34
  <slot name="dtable.top.center"></slot>
19
35
  <v-spacer></v-spacer>
20
- <v-btn class="ma-2" @click="getDataFromApi" icon>
36
+ <v-btn text v-if="quickModeEnabled" 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
39
+ </v-btn>
40
+ <v-btn v-if="serverPaginationEnabled" class=" mx-sm-2 ma-2 mx-0" @click="getDataFromApi(false)" icon>
21
41
  <v-icon>mdi-update</v-icon>
22
42
  </v-btn>
23
43
  </v-toolbar>
@@ -28,43 +48,71 @@
28
48
  {{ item[firstColName] }}
29
49
  </NuxtLink>
30
50
  </template>
51
+ <template v-slot:item.data-table-select="{ isSelected, select }" v-if="selectAll">
52
+ <v-simple-checkbox v-model="selectAll" @input="select"></v-simple-checkbox>
53
+ </template>
54
+ <template v-slot:header.data-table-select="{ on, props }" v-if="selectAll">
55
+ <v-simple-checkbox v-model="selectAll" @input="on.input"></v-simple-checkbox>
56
+ </template>
31
57
  <template v-slot:[`item.actions`]="{ item }">
32
- <v-icon v-if="shouldEdit" small class="mr-2" @click="editItem(item)">
58
+ <v-icon v-if="quickModeEnabled" small class="mr-2" @click="quickAction(item)">
33
59
  mdi-pencil
34
60
  </v-icon>
35
61
  <v-icon small @click="deleteItem(item)"> mdi-delete </v-icon>
36
62
  </template>
37
- <template v-for="slot in filterSlots($slots, 'dtable.')" :slot="slot">
63
+ <template v-for="slot in nameSpacedSlots($slots, 'dtable.')" :slot="slot">
38
64
  <slot :name="`dtable.${slot}`"></slot>
39
65
  </template>
40
66
  <template
41
- v-for="slot in filterSlots($scopedSlots, 'dtable.')"
67
+ v-for="slot in nameSpacedSlots($scopedSlots, 'dtable.')"
42
68
  v-slot:[slot]="props"
43
69
  >
44
70
  <slot :name="`dtable.${slot}`" v-bind="props" />
45
71
  </template>
46
72
  </v-data-table>
47
73
  <list-quick-edit
48
- v-if="shouldEdit"
74
+ v-if="quickModeEnabled"
49
75
  ref="editModal"
50
- v-bind="{ ...$attrs, value: false, crud }"
76
+ :offline="offlineMode"
77
+ v-bind="{ ...$attrs, value: false, crud, lookup: lookup }"
51
78
  >
52
- <template v-for="slot in filterSlots($slots, 'qedit.')" :slot="slot">
79
+ <template v-for="slot in nameSpacedSlots($slots, 'qedit.')" :slot="slot">
53
80
  <slot :name="`qedit.${slot}`"></slot>
54
81
  </template>
55
- <template
56
- v-for="slot in filterSlots($scopedSlots, 'qedit.')"
57
- v-slot:[slot]="props"
58
- >
82
+ <template v-for="slot in nameSpacedSlots($scopedSlots, 'qedit.')" v-slot:[slot]="props">
59
83
  <slot :name="`qedit.${slot}`" v-bind="props" />
60
84
  </template>
61
85
  </list-quick-edit>
62
86
  </div>
63
87
  </template>
64
88
 
89
+ <style lang="scss" scoped>
90
+ .mapo__listtable__all_selected {
91
+ .v-data-table__selected {
92
+ background: none !important;
93
+ }
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
+ }
111
+ </style>
65
112
 
66
113
  <script>
67
114
  import { getPointed } from "@mapomodule/utils/helpers/objHelpers";
115
+ import { debounce } from "@mapomodule/utils/helpers/debounce";
68
116
 
69
117
  export default {
70
118
  name: "ListTable",
@@ -72,16 +120,19 @@ export default {
72
120
  items: [],
73
121
  loading: true,
74
122
  selection: [],
123
+ selectAll: false,
75
124
  options: {},
76
125
  httpPaginator: {},
77
- disableHttp: false
126
+ searchString: "",
127
+ loadingSearch: false,
128
+ noPagination: false,
78
129
  }),
79
130
  props: {
80
131
  crud: {
81
132
  type: Object,
82
- required: true,
133
+ required: true
83
134
  },
84
- http: Boolean,
135
+ serverPagination: Boolean,
85
136
  navigable: Boolean,
86
137
  lookup: {
87
138
  type: String,
@@ -97,44 +148,73 @@ export default {
97
148
  type: Array,
98
149
  default: () => [],
99
150
  },
151
+ searchable: {
152
+ type: Boolean,
153
+ default: false,
154
+ },
155
+ data: {
156
+ type: Array,
157
+ required: false
158
+ },
100
159
  },
101
160
  watch: {
102
161
  selection(val) {
103
162
  this.$emit("input", val);
104
163
  },
105
- filters:{
164
+ selectAll(val) {
165
+ this.$emit("input", val ? "all" : this.selection);
166
+ },
167
+ filters: {
106
168
  deep: true,
107
- handler(){
108
- this.httpEnabled && this.getDataFromApi();
109
- }
169
+ handler() {
170
+ this.serverPaginationEnabled && this.getDataFromApi();
171
+ },
110
172
  },
111
173
  options: {
112
174
  deep: true,
113
175
  handler(options) {
114
- this.disableHttp = options.itemsPerPage === -1;
176
+ this.noPagination = options.itemsPerPage === -1;
115
177
  this.setQparams(options);
116
- this.httpEnabled && this.getDataFromApi();
178
+ this.serverPaginationEnabled && this.getDataFromApi(false);
117
179
  },
118
180
  },
119
- disableHttp(){
181
+ noPagination() {
120
182
  this.getDataFromApi();
183
+ },
184
+ data: {
185
+ deep: true,
186
+ handler(data) {
187
+ if (data) this.items = data;
188
+ },
121
189
  }
122
190
  },
123
191
  methods: {
124
- getDataFromApi() {
192
+ getDataFromApi(clearSelection = true) {
193
+ if (clearSelection) {
194
+ this.selection = [];
195
+ this.selectAll = false;
196
+ }
197
+ this.loading = !this.offlineMode;
198
+ !this.offlineMode && this.debouncedDataFromApi();
199
+ },
200
+ debouncedDataFromApi: debounce(function () {
125
201
  return new Promise((resolve, reject) => {
126
202
  this.selection = [];
127
- this.loading = true;
128
- if (!this.httpEnabled) {
129
- this.crud.list().then((data) => {
203
+ if (!this.serverPaginationEnabled) {
204
+ this.crud
205
+ .list()
206
+ .then((data) => {
130
207
  this.items = data;
131
208
  this.loading = false;
209
+ this.httpPaginator = {};
132
210
  resolve(data);
133
211
  })
134
212
  .catch((error) => reject(error));
135
213
  } else {
136
- const params = this.getHttpParams()
137
- this.crud.list({ params }).then((data) => {
214
+ const params = this.getHttpParams();
215
+ this.crud
216
+ .list({ params })
217
+ .then((data) => {
138
218
  this.items = data.items;
139
219
  this.httpPaginator = data.paginator;
140
220
  this.loading = false;
@@ -143,7 +223,7 @@ export default {
143
223
  .catch((error) => reject(error));
144
224
  }
145
225
  });
146
- },
226
+ }, 500),
147
227
  setQparams(options) {
148
228
  this.$router.push({
149
229
  query: {
@@ -152,60 +232,113 @@ export default {
152
232
  },
153
233
  });
154
234
  },
155
- restoreFromQparams(){
235
+ restoreFromQparams() {
156
236
  this.options = {
157
237
  ...this.options,
158
- sortBy: this.$route.query.sort?.split(".") || [],
159
- sortDesc: this.$route.query.order?.split(".").map((e) => e == "desc") || [],
160
- itemsPerPage: parseInt(this.$route.query.items) || this.options.itemsPerPage || 10,
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
+ [],
246
+ itemsPerPage:
247
+ parseInt(this.$route.query.items) || this.options.itemsPerPage || 10,
248
+ page: parseInt(this.$route.query.page) || this.options.page || 1,
161
249
  };
250
+ this.searchString = this.$route.query.search;
162
251
  },
163
252
  getOrderParams(options) {
164
253
  const { sortBy, sortDesc, page, itemsPerPage } = options;
165
- const sort = sortBy.length ? sortBy.join(".") : undefined;
166
- const order = sortDesc.length
167
- ? sortDesc.map((e) => (e ? "desc" : "asc")).join(".")
168
- : undefined;
169
- 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 };
170
257
  },
171
258
  getHttpParams() {
172
259
  const params = new URLSearchParams();
173
260
  for (const [key, value] of Object.entries(this.getOrderParams(this.options))) {
174
- value !== undefined && params.append(key, value)
261
+ value !== undefined && params.append(key, value);
175
262
  }
176
- this.filters.forEach(fi => {
177
- const query = []
178
- const format = (val) => val.replaceAll('.', '__')
179
- if (fi.datepicker){
180
- const dates = fi.active[0].value.split(',')
181
- query.push(`${format(fi.value)}__gte=${dates[0]}`, `${format(fi.value)}__lte=${dates[1]}`)
263
+ this.filters.forEach((fi) => {
264
+ const query = [];
265
+ const format = (val) => val.replaceAll(".", "__");
266
+ if (fi.datepicker) {
267
+ const dates = fi.active[0].value.split(",");
268
+ query.push(
269
+ `${format(fi.value)}__gte=${dates[0]}`,
270
+ `${format(fi.value)}__lte=${dates[1]}`
271
+ );
182
272
  } else if (fi.active.length > 1) {
183
- query.push(`${format(fi.value)}=[${ fi.active.map(a=>a.value).join(",")}]`)
273
+ query.push(`${format(fi.value)}=[${fi.active.map((a) => a.value).join(",")}]`);
184
274
  } else {
185
- query.push(`${format(fi.value)}=${ fi.active[0].value}`)
275
+ query.push(`${format(fi.value)}=${fi.active[0].value}`);
186
276
  }
187
- query.forEach(q => params.append('fltr', q))
188
- })
277
+ query.forEach((q) => params.append("fltr", q));
278
+ });
279
+ if (this.searchString && this.searchable) params.append("search", this.searchString);
189
280
  return params;
190
281
  },
191
- editItem(item) {
192
- 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
+ });
193
300
  },
194
301
  deleteItem(item) {
195
- const callback = (item) =>
196
- this.crud.delete(item[this.lookup]).then(this.getDataFromApi);
197
- this.$mapo.$confirm
198
- .open({
199
- title: "Delete",
200
- question: "Are you sure you want to delete this item?",
201
- approveButton: { text: "Delete", attrs: { color: "red" } }
202
- }).then((res) => (res ? callback(item) : null));
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
+
315
+ this.$mapo.$confirm
316
+ .open({
317
+ title: "Delete",
318
+ question: "Are you sure you want to delete this item?",
319
+ approveButton: { text: "Delete", attrs: { color: "red" } },
320
+ })
321
+ .then((res) => (res ? callback(item) : null));
203
322
  },
204
- filterSlots(slots, scope) {
323
+ nameSpacedSlots(slots, scope) {
205
324
  return Object.keys(slots)
206
325
  .filter((name) => name.startsWith(scope))
207
326
  .map((name) => name.replace(scope, ""));
208
327
  },
328
+ toggleSelectAll() {
329
+ this.selectAll = !this.selectAll;
330
+ },
331
+ search: debounce(function () {
332
+ this.$router.push({
333
+ query: {
334
+ ...this.$route.query,
335
+ search: this.searchString || undefined,
336
+ },
337
+ });
338
+
339
+ this.serverPaginationEnabled && this.getDataFromApi();
340
+ this.loadingSearch = false;
341
+ }, 1000),
209
342
  },
210
343
  computed: {
211
344
  filteredItems() {
@@ -234,25 +367,34 @@ export default {
234
367
  },
235
368
  firstColName() {
236
369
  return (
237
- this.$attrs.headers &&
238
- this.$attrs.headers.length &&
239
- this.$attrs.headers[0].value
370
+ this.$attrs.headers && this.$attrs.headers.length && this.$attrs.headers[0].value
240
371
  );
241
372
  },
242
- shouldEdit() {
373
+ quickModeEnabled() {
243
374
  return (
244
- this.filterSlots(this.$slots, "qedit.body").length ||
245
- this.filterSlots(this.$scopedSlots, "qedit.body").length ||
375
+ this.nameSpacedSlots(this.$slots, "qedit.body").length ||
376
+ this.nameSpacedSlots(this.$scopedSlots, "qedit.body").length ||
246
377
  (this.$attrs.editFields && this.$attrs.editFields.length)
247
378
  );
248
379
  },
249
- httpEnabled(){
250
- return this.http && !this.disableHttp
251
- }
380
+ serverPaginationEnabled() {
381
+ return this.serverPagination && !this.noPagination && !this.offlineMode;
382
+ },
383
+ offlineMode() {
384
+ return !!this.data;
385
+ },
386
+ serverItemsLength() {
387
+ return this.httpPaginator.count || (this.serverPaginationEnabled && (this.options.page * this.options.itemsPerPage)) || -1;
388
+ },
252
389
  },
253
390
  mounted() {
254
- this.restoreFromQparams()
255
- this.httpEnabled || this.getDataFromApi();
391
+ this.restoreFromQparams();
392
+ if (!this.offlineMode) {
393
+ this.getDataFromApi();
394
+ } else {
395
+ this.items = this.data;
396
+ this.loading = false;
397
+ }
256
398
  },
257
399
  };
258
400
  </script>