@mapomodule/uikit 1.0.0-alpha.1 → 1.0.0-alpha.6

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.
@@ -1,13 +1,15 @@
1
1
  <template>
2
2
  <div class="list__head">
3
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
- >
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
+ style="max-width: 300px"
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" @click="quickAction()">
37
+ <v-icon small left class="mr-2"> mdi-plus </v-icon>
38
+ Quick add
39
+ </v-btn>
40
+ <v-btn v-if="serverPaginationEnabled" class="ma-2" @click="getDataFromApi(false)" icon>
21
41
  <v-icon>mdi-update</v-icon>
22
42
  </v-btn>
23
43
  </v-toolbar>
@@ -28,43 +48,55 @@
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">
90
+ .mapo__listtable__all_selected {
91
+ .v-data-table__selected {
92
+ background: none !important;
93
+ }
94
+ }
95
+ </style>
65
96
 
66
97
  <script>
67
98
  import { getPointed } from "@mapomodule/utils/helpers/objHelpers";
99
+ import { debounce } from "@mapomodule/utils/helpers/debounce";
68
100
 
69
101
  export default {
70
102
  name: "ListTable",
@@ -72,16 +104,19 @@ export default {
72
104
  items: [],
73
105
  loading: true,
74
106
  selection: [],
107
+ selectAll: false,
75
108
  options: {},
76
109
  httpPaginator: {},
77
- disableHttp: false
110
+ searchString: "",
111
+ loadingSearch: false,
112
+ noPagination: false,
78
113
  }),
79
114
  props: {
80
115
  crud: {
81
116
  type: Object,
82
- required: true,
117
+ required: true
83
118
  },
84
- http: Boolean,
119
+ serverPagination: Boolean,
85
120
  navigable: Boolean,
86
121
  lookup: {
87
122
  type: String,
@@ -97,44 +132,73 @@ export default {
97
132
  type: Array,
98
133
  default: () => [],
99
134
  },
135
+ searchable: {
136
+ type: Boolean,
137
+ default: false,
138
+ },
139
+ data: {
140
+ type: Array,
141
+ required: false
142
+ },
100
143
  },
101
144
  watch: {
102
145
  selection(val) {
103
146
  this.$emit("input", val);
104
147
  },
105
- filters:{
148
+ selectAll(val) {
149
+ this.$emit("input", val ? "all" : this.selection);
150
+ },
151
+ filters: {
106
152
  deep: true,
107
- handler(){
108
- this.httpEnabled && this.getDataFromApi();
109
- }
153
+ handler() {
154
+ this.serverPaginationEnabled && this.getDataFromApi();
155
+ },
110
156
  },
111
157
  options: {
112
158
  deep: true,
113
159
  handler(options) {
114
- this.disableHttp = options.itemsPerPage === -1;
160
+ this.noPagination = options.itemsPerPage === -1;
115
161
  this.setQparams(options);
116
- this.httpEnabled && this.getDataFromApi();
162
+ this.serverPaginationEnabled && this.getDataFromApi(false);
117
163
  },
118
164
  },
119
- disableHttp(){
165
+ noPagination() {
120
166
  this.getDataFromApi();
167
+ },
168
+ data: {
169
+ deep: true,
170
+ handler(data) {
171
+ if (data) this.items = data;
172
+ },
121
173
  }
122
174
  },
123
175
  methods: {
124
- getDataFromApi() {
176
+ getDataFromApi(clearSelection = true) {
177
+ if (clearSelection) {
178
+ this.selection = [];
179
+ this.selectAll = false;
180
+ }
181
+ this.loading = !this.offlineMode;
182
+ !this.offlineMode && this.debouncedDataFromApi();
183
+ },
184
+ debouncedDataFromApi: debounce(function () {
125
185
  return new Promise((resolve, reject) => {
126
186
  this.selection = [];
127
- this.loading = true;
128
- if (!this.httpEnabled) {
129
- this.crud.list().then((data) => {
187
+ if (!this.serverPaginationEnabled) {
188
+ this.crud
189
+ .list()
190
+ .then((data) => {
130
191
  this.items = data;
131
192
  this.loading = false;
193
+ this.httpPaginator = {};
132
194
  resolve(data);
133
195
  })
134
196
  .catch((error) => reject(error));
135
197
  } else {
136
- const params = this.getHttpParams()
137
- this.crud.list({ params }).then((data) => {
198
+ const params = this.getHttpParams();
199
+ this.crud
200
+ .list({ params })
201
+ .then((data) => {
138
202
  this.items = data.items;
139
203
  this.httpPaginator = data.paginator;
140
204
  this.loading = false;
@@ -143,7 +207,7 @@ export default {
143
207
  .catch((error) => reject(error));
144
208
  }
145
209
  });
146
- },
210
+ }, 500),
147
211
  setQparams(options) {
148
212
  this.$router.push({
149
213
  query: {
@@ -152,60 +216,113 @@ export default {
152
216
  },
153
217
  });
154
218
  },
155
- restoreFromQparams(){
219
+ restoreFromQparams() {
156
220
  this.options = {
157
221
  ...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,
222
+ sortBy:
223
+ this.$route.query.sort?.split(",").map((p) => p.replace(/^-/, "")) ||
224
+ this.options.sortBy ||
225
+ [],
226
+ sortDesc:
227
+ this.$route.query.order?.split(",").map((p) => p.startsWith("-")) ||
228
+ this.options.sortDesc ||
229
+ [],
230
+ itemsPerPage:
231
+ parseInt(this.$route.query.items) || this.options.itemsPerPage || 10,
232
+ page: parseInt(this.$route.query.page) || this.options.page || 1,
161
233
  };
234
+ this.searchString = this.$route.query.search;
162
235
  },
163
236
  getOrderParams(options) {
164
237
  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 };
238
+ const sort =
239
+ sortBy.map((field, i) => (sortDesc[i] ? "-" : "") + field).join(",") || undefined;
240
+ return { sort, items: itemsPerPage, page: page !== 1 ? page : undefined };
170
241
  },
171
242
  getHttpParams() {
172
243
  const params = new URLSearchParams();
173
244
  for (const [key, value] of Object.entries(this.getOrderParams(this.options))) {
174
- value !== undefined && params.append(key, value)
245
+ value !== undefined && params.append(key, value);
175
246
  }
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]}`)
247
+ this.filters.forEach((fi) => {
248
+ const query = [];
249
+ const format = (val) => val.replaceAll(".", "__");
250
+ if (fi.datepicker) {
251
+ const dates = fi.active[0].value.split(",");
252
+ query.push(
253
+ `${format(fi.value)}__gte=${dates[0]}`,
254
+ `${format(fi.value)}__lte=${dates[1]}`
255
+ );
182
256
  } else if (fi.active.length > 1) {
183
- query.push(`${format(fi.value)}=[${ fi.active.map(a=>a.value).join(",")}]`)
257
+ query.push(`${format(fi.value)}=[${fi.active.map((a) => a.value).join(",")}]`);
184
258
  } else {
185
- query.push(`${format(fi.value)}=${ fi.active[0].value}`)
259
+ query.push(`${format(fi.value)}=${fi.active[0].value}`);
186
260
  }
187
- query.forEach(q => params.append('fltr', q))
188
- })
261
+ query.forEach((q) => params.append("fltr", q));
262
+ });
263
+ if (this.searchString && this.searchable) params.append("search", this.searchString);
189
264
  return params;
190
265
  },
191
- editItem(item) {
192
- this.$refs.editModal.open(item).then((r) => r && this.getDataFromApi());
266
+ quickAction(item) {
267
+ this.$refs.editModal.open(item).then((r) => {
268
+ if (!r) return;
269
+ if (!this.offlineMode) {
270
+ this.getDataFromApi();
271
+ } else {
272
+ let index = item ? this.items.findIndex((i) => i[this.lookup] === item[this.lookup]) : -1;
273
+ let update = true;
274
+
275
+ if (index !== -1) {
276
+ this.items.splice(index, 1, r);
277
+ } else {
278
+ index = this.items.push(r);
279
+ update = false;
280
+ }
281
+ this.$emit("update:data", this.items, r, index);
282
+ }
283
+ });
193
284
  },
194
285
  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));
286
+ const callback = (item) => {
287
+ if (!this.offlineMode) {
288
+ this.crud.delete(item[this.lookup]).then(this.getDataFromApi);
289
+ } else {
290
+ const index = this.items.findIndex((i) => i[this.lookup] === item[this.lookup]);
291
+
292
+ if (index !== -1) {
293
+ this.items.splice(index, 1);
294
+ this.$emit("update:data", this.items, r, index);
295
+ }
296
+ }
297
+ };
298
+
299
+ this.$mapo.$confirm
300
+ .open({
301
+ title: "Delete",
302
+ question: "Are you sure you want to delete this item?",
303
+ approveButton: { text: "Delete", attrs: { color: "red" } },
304
+ })
305
+ .then((res) => (res ? callback(item) : null));
203
306
  },
204
- filterSlots(slots, scope) {
307
+ nameSpacedSlots(slots, scope) {
205
308
  return Object.keys(slots)
206
309
  .filter((name) => name.startsWith(scope))
207
310
  .map((name) => name.replace(scope, ""));
208
311
  },
312
+ toggleSelectAll() {
313
+ this.selectAll = !this.selectAll;
314
+ },
315
+ search: debounce(function () {
316
+ this.$router.push({
317
+ query: {
318
+ ...this.$route.query,
319
+ search: this.searchString || undefined,
320
+ },
321
+ });
322
+
323
+ this.serverPaginationEnabled && this.getDataFromApi();
324
+ this.loadingSearch = false;
325
+ }, 1000),
209
326
  },
210
327
  computed: {
211
328
  filteredItems() {
@@ -234,25 +351,34 @@ export default {
234
351
  },
235
352
  firstColName() {
236
353
  return (
237
- this.$attrs.headers &&
238
- this.$attrs.headers.length &&
239
- this.$attrs.headers[0].value
354
+ this.$attrs.headers && this.$attrs.headers.length && this.$attrs.headers[0].value
240
355
  );
241
356
  },
242
- shouldEdit() {
357
+ quickModeEnabled() {
243
358
  return (
244
- this.filterSlots(this.$slots, "qedit.body").length ||
245
- this.filterSlots(this.$scopedSlots, "qedit.body").length ||
359
+ this.nameSpacedSlots(this.$slots, "qedit.body").length ||
360
+ this.nameSpacedSlots(this.$scopedSlots, "qedit.body").length ||
246
361
  (this.$attrs.editFields && this.$attrs.editFields.length)
247
362
  );
248
363
  },
249
- httpEnabled(){
250
- return this.http && !this.disableHttp
251
- }
364
+ serverPaginationEnabled() {
365
+ return this.serverPagination && !this.noPagination && !this.offlineMode;
366
+ },
367
+ offlineMode() {
368
+ return !!this.data;
369
+ },
370
+ serverItemsLength() {
371
+ return this.httpPaginator.count || (this.serverPaginationEnabled && (this.options.page * this.options.itemsPerPage)) || -1;
372
+ },
252
373
  },
253
374
  mounted() {
254
- this.restoreFromQparams()
255
- this.httpEnabled || this.getDataFromApi();
375
+ this.restoreFromQparams();
376
+ if (!this.offlineMode) {
377
+ this.getDataFromApi();
378
+ } else {
379
+ this.items = this.data;
380
+ this.loading = false;
381
+ }
256
382
  },
257
383
  };
258
384
  </script>
@@ -0,0 +1,89 @@
1
+ <template>
2
+ <div class="container">
3
+ <div class="preview">
4
+ <span class="preview__title">{{ getTitle }}</span>
5
+ <br />
6
+ <span class="preview__url">{{ getPermalink }}</span>
7
+ <br />
8
+ <span class="preview__desc">{{ getDescription }}</span>
9
+ </div>
10
+ </div>
11
+ </template>
12
+
13
+ <style lang="scss" scoped>
14
+ .container {
15
+ background: #ffffff;
16
+ border-radius: 3px;
17
+ }
18
+ .preview {
19
+ display: block;
20
+ max-width: 32em;
21
+ margin: 30px 8px;
22
+ &__title {
23
+ color: #035ac6;
24
+ font-size: 1.2em;
25
+ cursor: pointer;
26
+ &:hover {
27
+ text-decoration: underline;
28
+ }
29
+ }
30
+ &__url {
31
+ color: green;
32
+ font-size: 0.92em;
33
+ }
34
+ &__desc {
35
+ color: #9b9da1;
36
+ }
37
+ }
38
+ </style>
39
+
40
+ <script>
41
+ /**
42
+ * This component is used to make a preview of seo data.
43
+ */
44
+ export default {
45
+ name: "SeoPreview",
46
+ props: {
47
+ // V-model for DetailField (need to be an object `{title, permalink, description}`)
48
+ value:{
49
+ type: Object,
50
+ default: () => {}
51
+ },
52
+ // Seo title
53
+ title: {
54
+ type: String,
55
+ default:
56
+ "It was the best of times, it was the blurst of times, it was the ..."
57
+ },
58
+ // Seo permalink
59
+ permalink: {
60
+ type: String,
61
+ default: "example.com/how_to_dive"
62
+ },
63
+ // Seo description
64
+ description: {
65
+ type: String,
66
+ default:
67
+ "This is an example description that will get replaced when you start typing. Make sure to keep descriptions mobile-friendly and keyword-rich!"
68
+ }
69
+ },
70
+ computed: {
71
+ getTitle(){
72
+ if (this.value && this.value.title)
73
+ return this.value.title
74
+ return this.title
75
+ },
76
+ getPermalink(){
77
+ if (this.value && this.value.permalink)
78
+ return this.value.permalink
79
+ return this.permalink
80
+ },
81
+ getDescription(){
82
+ if (this.value && this.value.description)
83
+ return this.value.description
84
+ return this.description
85
+ }
86
+ },
87
+
88
+ };
89
+ </script>
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div>
3
3
  <media-manager-dialog ref="mediaManager"></media-manager-dialog>
4
- <span v-if="label">{{ label }}:</span>
4
+ <span v-if="label" class="v-label" :class="{'error--text': errorMessages && errorMessages.length}">{{ label }}:</span>
5
5
  <div ref="editorNode">
6
6
  <v-skeleton-loader
7
7
  type="table-heading, list-item-two-line, list-item-avatar-two-line, list-item-three-lineimage, table-tfoot"
@@ -145,6 +145,9 @@ export default {
145
145
  .tox-statusbar__branding {
146
146
  display: none;
147
147
  }
148
+ .v-label.error--text{
149
+ animation: v-shake 0.6s cubic-bezier(0.25, 0.8, 0.5, 1);
150
+ }
148
151
  </style>
149
152
 
150
153
  <docs>
@@ -43,7 +43,7 @@ export default {
43
43
  // ],
44
44
  template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
45
45
  template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
46
- height: 600,
46
+ height: 400,
47
47
  image_caption: true,
48
48
  quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
49
49
  noneditable_noneditable_class: 'mceNonEditable',