@mapomodule/uikit 1.0.0-alpha.5 → 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.
@@ -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
@@ -29,11 +33,11 @@
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()">
36
+ <v-btn text v-if="quickModeEnabled" @click="quickAction()">
33
37
  <v-icon small left class="mr-2"> mdi-plus </v-icon>
34
38
  Quick add
35
39
  </v-btn>
36
- <v-btn class="ma-2" @click="getDataFromApi(false)" icon>
40
+ <v-btn v-if="serverPaginationEnabled" class="ma-2" @click="getDataFromApi(false)" icon>
37
41
  <v-icon>mdi-update</v-icon>
38
42
  </v-btn>
39
43
  </v-toolbar>
@@ -51,30 +55,31 @@
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 v-if="quickModeEnabled" small class="mr-2" @click="quickAction(item)">
55
59
  mdi-pencil
56
60
  </v-icon>
57
61
  <v-icon 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>
@@ -102,16 +107,16 @@ export default {
102
107
  selectAll: false,
103
108
  options: {},
104
109
  httpPaginator: {},
105
- searchValue: "",
110
+ searchString: "",
106
111
  loadingSearch: false,
107
- disableHttp: false
112
+ noPagination: false,
108
113
  }),
109
114
  props: {
110
115
  crud: {
111
116
  type: Object,
112
- required: true,
117
+ required: true
113
118
  },
114
- http: Boolean,
119
+ serverPagination: Boolean,
115
120
  navigable: Boolean,
116
121
  lookup: {
117
122
  type: String,
@@ -131,6 +136,10 @@ export default {
131
136
  type: Boolean,
132
137
  default: false,
133
138
  },
139
+ data: {
140
+ type: Array,
141
+ required: false
142
+ },
134
143
  },
135
144
  watch: {
136
145
  selection(val) {
@@ -142,20 +151,26 @@ export default {
142
151
  filters: {
143
152
  deep: true,
144
153
  handler() {
145
- this.httpEnabled && this.getDataFromApi();
154
+ this.serverPaginationEnabled && this.getDataFromApi();
146
155
  },
147
156
  },
148
157
  options: {
149
158
  deep: true,
150
159
  handler(options) {
151
- this.disableHttp = options.itemsPerPage === -1;
160
+ this.noPagination = options.itemsPerPage === -1;
152
161
  this.setQparams(options);
153
- this.httpEnabled && this.getDataFromApi(false);
162
+ this.serverPaginationEnabled && this.getDataFromApi(false);
154
163
  },
155
164
  },
156
- disableHttp() {
165
+ noPagination() {
157
166
  this.getDataFromApi();
158
167
  },
168
+ data: {
169
+ deep: true,
170
+ handler(data) {
171
+ if (data) this.items = data;
172
+ },
173
+ }
159
174
  },
160
175
  methods: {
161
176
  getDataFromApi(clearSelection = true) {
@@ -163,18 +178,19 @@ export default {
163
178
  this.selection = [];
164
179
  this.selectAll = false;
165
180
  }
166
- this.loading = true;
167
- this.debouncedDataFromApi();
181
+ this.loading = !this.offlineMode;
182
+ !this.offlineMode && this.debouncedDataFromApi();
168
183
  },
169
184
  debouncedDataFromApi: debounce(function () {
170
185
  return new Promise((resolve, reject) => {
171
186
  this.selection = [];
172
- if (!this.httpEnabled) {
187
+ if (!this.serverPaginationEnabled) {
173
188
  this.crud
174
189
  .list()
175
190
  .then((data) => {
176
191
  this.items = data;
177
192
  this.loading = false;
193
+ this.httpPaginator = {};
178
194
  resolve(data);
179
195
  })
180
196
  .catch((error) => reject(error));
@@ -203,20 +219,25 @@ export default {
203
219
  restoreFromQparams() {
204
220
  this.options = {
205
221
  ...this.options,
206
- sortBy: this.$route.query.sort?.split(".") || [],
207
- sortDesc: this.$route.query.order?.split(".").map((e) => e == "desc") || [],
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
+ [],
208
230
  itemsPerPage:
209
231
  parseInt(this.$route.query.items) || this.options.itemsPerPage || 10,
232
+ page: parseInt(this.$route.query.page) || this.options.page || 1,
210
233
  };
211
- this.searchValue = this.$route.query.search;
234
+ this.searchString = this.$route.query.search;
212
235
  },
213
236
  getOrderParams(options) {
214
237
  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 };
238
+ const sort =
239
+ sortBy.map((field, i) => (sortDesc[i] ? "-" : "") + field).join(",") || undefined;
240
+ return { sort, items: itemsPerPage, page: page !== 1 ? page : undefined };
220
241
  },
221
242
  getHttpParams() {
222
243
  const params = new URLSearchParams();
@@ -237,18 +258,44 @@ export default {
237
258
  } else {
238
259
  query.push(`${format(fi.value)}=${fi.active[0].value}`);
239
260
  }
240
- query.forEach(q => params.append('fltr', q))
261
+ query.forEach((q) => params.append("fltr", q));
241
262
  });
242
- if (this.searchValue && this.searchable)
243
- params.append("search", this.searchValue);
263
+ if (this.searchString && this.searchable) params.append("search", this.searchString);
244
264
  return params;
245
265
  },
246
- editItem(item) {
247
- 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
+ });
248
284
  },
249
285
  deleteItem(item) {
250
- const callback = (item) =>
251
- this.crud.delete(item[this.lookup]).then(this.getDataFromApi);
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
+
252
299
  this.$mapo.$confirm
253
300
  .open({
254
301
  title: "Delete",
@@ -257,7 +304,7 @@ export default {
257
304
  })
258
305
  .then((res) => (res ? callback(item) : null));
259
306
  },
260
- filterSlots(slots, scope) {
307
+ nameSpacedSlots(slots, scope) {
261
308
  return Object.keys(slots)
262
309
  .filter((name) => name.startsWith(scope))
263
310
  .map((name) => name.replace(scope, ""));
@@ -265,17 +312,17 @@ export default {
265
312
  toggleSelectAll() {
266
313
  this.selectAll = !this.selectAll;
267
314
  },
268
- changeSearch: debounce(function () {
315
+ search: debounce(function () {
269
316
  this.$router.push({
270
317
  query: {
271
318
  ...this.$route.query,
272
- search: this.searchValue,
319
+ search: this.searchString || undefined,
273
320
  },
274
321
  });
275
322
 
276
- this.httpEnabled && this.getDataFromApi();
323
+ this.serverPaginationEnabled && this.getDataFromApi();
277
324
  this.loadingSearch = false;
278
- }, 1000)
325
+ }, 1000),
279
326
  },
280
327
  computed: {
281
328
  filteredItems() {
@@ -307,20 +354,31 @@ export default {
307
354
  this.$attrs.headers && this.$attrs.headers.length && this.$attrs.headers[0].value
308
355
  );
309
356
  },
310
- shouldEdit() {
357
+ quickModeEnabled() {
311
358
  return (
312
- this.filterSlots(this.$slots, "qedit.body").length ||
313
- this.filterSlots(this.$scopedSlots, "qedit.body").length ||
359
+ this.nameSpacedSlots(this.$slots, "qedit.body").length ||
360
+ this.nameSpacedSlots(this.$scopedSlots, "qedit.body").length ||
314
361
  (this.$attrs.editFields && this.$attrs.editFields.length)
315
362
  );
316
363
  },
317
- httpEnabled() {
318
- return this.http && !this.disableHttp;
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;
319
372
  },
320
373
  },
321
374
  mounted() {
322
375
  this.restoreFromQparams();
323
- this.httpEnabled || this.getDataFromApi();
376
+ if (!this.offlineMode) {
377
+ this.getDataFromApi();
378
+ } else {
379
+ this.items = this.data;
380
+ this.loading = false;
381
+ }
324
382
  },
325
383
  };
326
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',
@@ -1,58 +1,80 @@
1
1
  <template>
2
2
  <v-navigation-drawer
3
3
  v-model="drawerSetter"
4
- :mini-variant="miniVariant"
4
+ :mini-variant.sync="miniVariant"
5
+ width="300"
5
6
  :clipped="this.$store.getters['mapo/app/clipped']"
6
7
  fixed
7
8
  app
8
9
  >
9
- <div class="sidebar__core">
10
- <SidebarList />
11
- <SidebarFooter />
10
+ <div class="menu_container">
11
+ <div>
12
+ <v-list-item>
13
+ <v-list-item-avatar v-if="avatar">
14
+ <v-img :src="avatar"></v-img>
15
+ </v-list-item-avatar>
16
+ <v-list-item-icon v-else>
17
+ <v-icon>mdi-account</v-icon>
18
+ </v-list-item-icon>
19
+ <v-list-item-title>{{
20
+ this.$mapo.$auth.user.username
21
+ }}</v-list-item-title>
22
+ <v-btn icon @click.stop="miniVariant = !miniVariant">
23
+ <v-icon>mdi-chevron-left</v-icon>
24
+ </v-btn>
25
+ </v-list-item>
26
+ <v-divider></v-divider>
27
+ </div>
28
+ <div class="menu_container">
29
+ <SidebarList :force-collapse="miniVariant" />
30
+ <SidebarFooter :force-collapse="miniVariant" />
31
+ </div>
12
32
  </div>
13
33
  </v-navigation-drawer>
14
34
  </template>
15
35
 
16
36
  <style lang="scss" scoped>
17
- @import '@mapomodule/uikit/assets/variables.scss';
18
-
19
- .sidebar {
20
- &__core {
21
- display: flex;
22
- flex-direction: column;
23
- height: 100%;
24
- // background: $b-1;
25
- // color: $white;
26
- }
37
+ @import "@mapomodule/uikit/assets/variables.scss";
38
+ .menu_container {
39
+ display: flex;
40
+ flex-direction: column;
41
+ height: 100%;
42
+ justify-content: space-between;
43
+ flex: 1;
27
44
  }
28
45
  </style>
29
46
 
30
47
  <script>
31
- import { mapMutations } from 'vuex'
32
48
  // @vuese
33
49
  export default {
34
50
  name: "Sidebar",
35
- data () {
51
+ data() {
36
52
  return {
37
- miniVariant: false,
38
- }
53
+ miniVariant: false
54
+ };
39
55
  },
40
56
  computed: {
41
57
  drawerSetter: {
42
58
  get() {
43
- return this.$store.getters['mapo/app/drawer'];
59
+ return this.$store.getters["mapo/app/drawer"];
44
60
  },
45
61
  set(value) {
46
- if (this.$store.getters['mapo/app/drawer'] !== value)
62
+ if (this.$store.getters["mapo/app/drawer"] !== value)
47
63
  this.$store.dispatch("mapo/app/toggleSidebarDrawer");
48
64
  return value;
49
65
  }
66
+ },
67
+ username() {
68
+ return this.$mapo.$auth.user.username;
69
+ },
70
+ avatar() {
71
+ return this.$mapo.$auth.user.avatar;
50
72
  }
51
73
  },
52
74
  methods: {
53
- drawerReverse () {
54
- return this.drawer = !this.drawer
55
- },
75
+ drawerReverse() {
76
+ return (this.drawer = !this.drawer);
77
+ }
56
78
  }
57
- }
79
+ };
58
80
  </script>
@@ -1,68 +1,60 @@
1
1
  <template>
2
- <div class="sidebar__ender">
3
- <sidebar-list-item
4
- class="sidebar__ender__item"
5
- v-for="(item, i) in routes"
6
- :key="i"
7
- :link="item.link"
8
- :label="item.label"
9
- :childrens="item.childrens"
10
- :icon="item.icon"
11
- />
12
- <logout-button class="sidebar__ender__item sidebar__ender__item--logout" />
2
+ <div>
3
+ <v-divider></v-divider>
4
+ <v-list dense class="py-0">
5
+ <SidebarListItem
6
+ v-for="(item, i) in routes"
7
+ :key="i"
8
+ :link="item.link"
9
+ :label="item.label"
10
+ :childrens="item.childrens"
11
+ :icon="item.icon"
12
+ :force-collapse="forceCollapse"
13
+ />
14
+ </v-list>
15
+ <v-divider></v-divider>
16
+ <v-list-item dense class="logout__button" link @click.native="logout">
17
+ <v-list-item-icon>
18
+ <v-icon>mdi-logout</v-icon>
19
+ </v-list-item-icon>
20
+ <v-list-item-title> Logout </v-list-item-title>
21
+ </v-list-item>
13
22
  </div>
14
23
  </template>
15
24
 
16
25
  <style lang="scss" scoped>
17
- @import "@mapomodule/uikit/assets/variables.scss";
18
-
19
- .sidebar {
20
- &__ender {
21
- margin-top: auto;
22
- display: flex;
23
- flex-direction: column;
24
- &__icon {
25
- font-size: 1rem;
26
- margin-right: 0.5rem;
27
- }
28
- &__item {
29
- display: block;
30
- width: 100%;
31
- text-decoration: none;
32
- color: white;
33
- background: $b-2;
34
- transition: all linear 0.25s;
35
- border-radius: 0;
36
- &:hover {
37
- background: rgba($b-2, 0.25);
38
- }
39
- &--logout {
40
- background: $black !important;
41
- &:hover {
42
- background: rgba($black, 0.25) !important;
43
- }
44
- }
45
- }
26
+ .logout__button{
27
+ &.theme--light{
28
+ background: #ffffffd6;
29
+ filter: invert(1);
30
+ }
31
+ &.theme--dark{
32
+ background: #121212;
46
33
  }
47
34
  }
48
35
  </style>
49
-
50
36
  <script>
51
37
  import { buildRoutes } from "../routebuilder";
52
38
 
53
39
  // @vuese
54
40
  export default {
55
41
  name: "SidebarFooter",
42
+ props: {
43
+ forceCollapse: {
44
+ type: Boolean,
45
+ default: false
46
+ }
47
+ },
56
48
  data() {
57
49
  return {
58
- defaultIcon: ({label}) => `mdi-alpha-${label[0]}-box`.toLowerCase(),
59
- routes: this.routes,
50
+ defaultIcon: ({ label }) => `mdi-alpha-${label[0]}-box`.toLowerCase(),
51
+ routes: this.routes
60
52
  };
61
53
  },
62
- mounted: function () {
54
+ mounted() {
63
55
  this.routes = this.buildRoutes(
64
56
  this.$router.options.routes.filter(
65
- (route) => route.meta && route.meta.sidebarFooter === true
57
+ route => route.meta && route.meta.sidebarFooter === true
66
58
  )
67
59
  );
68
60
  },
@@ -70,6 +62,9 @@ export default {
70
62
  buildRoutes(routes) {
71
63
  return buildRoutes(routes, this.defaultIcon);
72
64
  },
73
- },
65
+ logout() {
66
+ this.$store.dispatch("mapo/user/logout");
67
+ }
68
+ }
74
69
  };
75
70
  </script>