@mapomodule/uikit 1.0.0-alpha.14 → 1.0.0-alpha.15

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.15](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.14...v1.0.0-alpha.15) (2022-03-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix detail component for single translatable languages ([cab50e5](https://github.com/lotrekagency/mapo/commit/cab50e5f62ee0a23ae58831b6800d36ca1006377))
12
+ * fix detail-field bad mounting if v-model is too quick ([6198a7d](https://github.com/lotrekagency/mapo/commit/6198a7d695b6b5fee1f86030d8ca0c7fcfe232e4))
13
+ * fix media-field bad mounting if v-model is too quick ([335a7c2](https://github.com/lotrekagency/mapo/commit/335a7c2b5e1b164f1e741fdae3ecd45dc2bb4e0f))
14
+ * removed permanent scrollbar on page body ([2cb3f13](https://github.com/lotrekagency/mapo/commit/2cb3f132f00ee72f14c4327fd595340c9dcdac34))
15
+
16
+
17
+ ### Features
18
+
19
+ * add sortable capabilities to repeater field ([c962f62](https://github.com/lotrekagency/mapo/commit/c962f626aaf84df4d57ede0b60aca34e4cbd10dd))
20
+ * add sortCallback also to add and remove items in Repeater field ([1ae82c3](https://github.com/lotrekagency/mapo/commit/1ae82c3f63dd7f7ab28e90b308ccdcdf69219226))
21
+ * added Repeater field 🌶 ([f388094](https://github.com/lotrekagency/mapo/commit/f388094ebf93341f8559f13fd73ee1d2172cd73d))
22
+ * **list:** added filtersChange event ([3d2a560](https://github.com/lotrekagency/mapo/commit/3d2a5607e7ecb368314b192af5b58613c57ff9d0))
23
+ * manage backend errors on reordering ([1df55c2](https://github.com/lotrekagency/mapo/commit/1df55c22fe4def3723027a07845d9cd804e6ef3c))
24
+ * **ordering:** added sortablejs to drag and reorder list ([eb8bf21](https://github.com/lotrekagency/mapo/commit/eb8bf21c3178c3ad62db5aa7c06c0562e944dea6))
25
+ * added loading status to fksfield while fetching options ([07137ee](https://github.com/lotrekagency/mapo/commit/07137ee5b0fcc2ee23df7687af0066555cf2a53e))
26
+
27
+
28
+
29
+
30
+
6
31
  # [1.0.0-alpha.14](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.13...v1.0.0-alpha.14) (2022-03-01)
7
32
 
8
33
 
@@ -29,7 +29,8 @@
29
29
  <slot name="body.lang" v-bind="slotBindings">
30
30
  <!-- [`DetailLangSwitch`](/components/detail/DetailLangSwitch/) -->
31
31
  <DetailLangSwitch
32
- v-if="langs && langs.length > 1"
32
+ v-if="langs && langs.length"
33
+ v-show="langs.length > 1"
33
34
  class="mb-4"
34
35
  v-model="currentLang"
35
36
  :langs="langs"
@@ -19,6 +19,7 @@ import MediaM2mField from "@mapomodule/uikit/components/fields/MediaM2mField.vue
19
19
  import MediaField from "@mapomodule/uikit/components/fields/MediaField.vue";
20
20
  import SeoPreview from "@mapomodule/uikit/components/fields/SeoPreview.vue";
21
21
  import FileField from "@mapomodule/uikit/components/fields/FileField.vue";
22
+ import Repeater from "@mapomodule/uikit/components/fields/Repeater.vue"
22
23
 
23
24
  import { getPointed, setPointed } from "@mapomodule/utils/helpers/objHelpers";
24
25
  import defaults from "./defaults";
@@ -36,6 +37,7 @@ export default {
36
37
  MediaField,
37
38
  SeoPreview,
38
39
  FileField,
40
+ Repeater,
39
41
  },
40
42
 
41
43
  data() {
@@ -152,5 +154,8 @@ export default {
152
154
  );
153
155
  },
154
156
  },
157
+ mounted(){
158
+ this.setModel()
159
+ }
155
160
  };
156
161
  </script>
@@ -11,7 +11,8 @@ const mapping = {
11
11
  fks: "FksField",
12
12
  m2m: "FksField",
13
13
  mediaList: "MediaM2mField",
14
- seoPreview: "SeoPreview"
14
+ seoPreview: "SeoPreview",
15
+ repeater: "Repeater",
15
16
  }
16
17
 
17
18
  const props = {
@@ -14,7 +14,7 @@
14
14
  />
15
15
  </v-col>
16
16
  <v-col cols="12" md="8" class="d-flex flex-nowrap justify-end align-center">
17
- <ListFilters v-bind="$attrs" v-model="filters">
17
+ <ListFilters v-bind="$attrs" v-model="filters" :disabled="dragOrderingActive">
18
18
  <template v-for="(_, slot) in $slots" :slot="slot">
19
19
  <!-- @vuese-ignore -->
20
20
  <slot :name="slot"></slot>
@@ -52,6 +52,7 @@
52
52
  v-model="selection"
53
53
  v-bind="{...$attrs, crud, filters}"
54
54
  v-on="$listeners"
55
+ @drag-order-change="setDragOrdering"
55
56
  ref="dtable"
56
57
  >
57
58
  <template v-for="(_, slot) in $slots" :slot="slot">
@@ -82,7 +83,8 @@ export default {
82
83
  tabActiveStatus: 1,
83
84
  selection: [],
84
85
  allSelected: false,
85
- filters: []
86
+ filters: [],
87
+ dragOrderingActive: false
86
88
  };
87
89
  },
88
90
  props: {
@@ -108,6 +110,14 @@ export default {
108
110
  // @arg Emit "all" if all items are selected, else the list of the selected rows.
109
111
  this.$emit("selectionChange", val);
110
112
  },
113
+ filters: {
114
+ deep: true,
115
+ handler(val) {
116
+ // Fires when you change filters options.
117
+ // @arg Emits the same array prop `filters` passed to the component and every filter object inside it contains an `active` array that contains the selected options.
118
+ this.$emit("filtersChange", val);
119
+ }
120
+ }
111
121
  },
112
122
  methods: {
113
123
  refresh() {
@@ -115,6 +125,12 @@ export default {
115
125
  },
116
126
  toggleSelectAll() {
117
127
  return this.$refs?.dtable?.toggleSelectAll();
128
+ },
129
+ setDragOrdering(val){
130
+ this.dragOrderingActive = val;
131
+ if(val){
132
+ this.filters = [];
133
+ }
118
134
  }
119
135
  },
120
136
  mounted() {},
@@ -158,6 +158,12 @@ export default {
158
158
  type: Array,
159
159
  default: () => [],
160
160
  },
161
+ // This is the v-model of the component. It contains the active filters.
162
+ value: {
163
+ // [`Array<Filter>`](#filter-config)
164
+ type: Array,
165
+ default: () => [],
166
+ },
161
167
  },
162
168
  methods: {
163
169
  addDateFilter(filter) {
@@ -278,7 +284,13 @@ export default {
278
284
  }
279
285
  }
280
286
  })
281
-
287
+ },
288
+ cleanActiveFilters(){
289
+ this.compFilters.forEach(filter => {
290
+ if (!this.activeFilters.find((f) => f.value == filter.value)) {
291
+ this.removeFilter(filter)
292
+ }
293
+ })
282
294
  }
283
295
  },
284
296
  watch: {
@@ -290,6 +302,15 @@ export default {
290
302
  this.setQparams(val);
291
303
  }, 200),
292
304
  },
305
+ value: {
306
+ deep: true,
307
+ handler(val){
308
+ if (JSON.stringify(val) !== JSON.stringify(this.activeFilters)){
309
+ this.activeFilters = val
310
+ this.cleanActiveFilters()
311
+ }
312
+ }
313
+ }
293
314
  },
294
315
  created() {
295
316
  this.loadFilters();
@@ -3,6 +3,8 @@
3
3
  <v-data-table
4
4
  v-model="selection"
5
5
  v-bind="$attrs"
6
+ :headers="headers"
7
+ :show-select="!dragOrderingActive && $attrs['show-select']"
6
8
  :items="serverPaginationEnabled ? items : filteredItems"
7
9
  :loading="loading"
8
10
  :options.sync="options"
@@ -10,6 +12,9 @@
10
12
  :server-items-length="serverItemsLength"
11
13
  :class="{ mapo__listtable__all_selected: selectAll }"
12
14
  :item-key="lookup"
15
+ :disable-sort="dragOrderingActive"
16
+ v-sortable-data-table
17
+ @sorted="changeOrder"
13
18
  >
14
19
  <template v-slot:top>
15
20
  <v-toolbar flat>
@@ -43,6 +48,15 @@
43
48
  </v-toolbar>
44
49
  <slot name="dtable.top.under"></slot>
45
50
  </template>
51
+ <template v-if="dragReorder" v-slot:footer.prepend>
52
+ <v-tooltip right>
53
+ <template v-slot:activator="{ on, attrs }">
54
+ <v-btn v-bind="attrs" v-on="on" style="margin-left: 2px;" :class="{'primary--text': dragOrderingActive}" @click="dragOrderingActive = !dragOrderingActive" icon>
55
+ <v-icon>mdi-order-bool-ascending</v-icon></v-btn>
56
+ </template>
57
+ <span>Toggle reordering</span>
58
+ </v-tooltip>
59
+ </template>
46
60
  <template v-if="navigable" v-slot:[`item.${firstColName}`]="{ item }">
47
61
  <NuxtLink :to="detailLink(item)">
48
62
  {{ getPointed(item, firstColName, "Unknown") }}
@@ -60,6 +74,9 @@
60
74
  </v-icon>
61
75
  <v-icon :disabled="!userCan('delete')" small @click="deleteItem(item)"> mdi-delete </v-icon>
62
76
  </template>
77
+ <template v-slot:item.drag-column>
78
+ <v-icon class="handle-drag">mdi-drag</v-icon>
79
+ </template>
63
80
  <template v-for="slot in nameSpacedSlots($slots, 'dtable.')" :slot="slot">
64
81
  <slot :name="`dtable.${slot}`"></slot>
65
82
  </template>
@@ -108,11 +125,13 @@
108
125
  }
109
126
  }
110
127
  }
128
+ .handle-drag{ cursor: grab; }
111
129
  </style>
112
130
 
113
131
  <script>
114
132
  import { getPointed } from "@mapomodule/utils/helpers/objHelpers";
115
133
  import { debounce } from "@mapomodule/utils/helpers/debounce";
134
+ import Sortable from "sortablejs"
116
135
 
117
136
  export default {
118
137
  name: "ListTable",
@@ -126,6 +145,7 @@ export default {
126
145
  searchString: "",
127
146
  loadingSearch: false,
128
147
  noPagination: false,
148
+ dragOrderingActive: false
129
149
  }),
130
150
  props: {
131
151
  crud: {
@@ -156,6 +176,24 @@ export default {
156
176
  type: Array,
157
177
  required: false
158
178
  },
179
+ dragReorder: {
180
+ type: Boolean,
181
+ default: false,
182
+ },
183
+ },
184
+ directives: {
185
+ sortableDataTable: {
186
+ bind (el, binding, vnode) {
187
+ const options = {
188
+ animation: 150,
189
+ handle: '.handle-drag',
190
+ onUpdate: function (event) {
191
+ vnode.child.$emit('sorted', event)
192
+ },
193
+ }
194
+ Sortable.create(el.getElementsByTagName('tbody')[0], options)
195
+ }
196
+ }
159
197
  },
160
198
  watch: {
161
199
  selection(val) {
@@ -164,6 +202,13 @@ export default {
164
202
  selectAll(val) {
165
203
  this.$emit("input", val ? "all" : this.selection);
166
204
  },
205
+ dragOrderingActive(val) {
206
+ if (val) {
207
+ this.searchString = ""
208
+ this.options = {...this.options, sortBy: []}
209
+ }
210
+ this.$emit("drag-order-change", val)
211
+ },
167
212
  filters: {
168
213
  deep: true,
169
214
  handler() {
@@ -225,6 +270,17 @@ export default {
225
270
  }
226
271
  });
227
272
  }, 500),
273
+ changeOrder(event){
274
+ this.crud.update_order(this.items[event.oldIndex][this.lookup], this.items[event.newIndex][this.lookup]).then(
275
+ res => res.reordered && this.getDataFromApi()
276
+ ).catch(error => {
277
+ this.getDataFromApi()
278
+ this.$mapo.$snack.open({
279
+ message: error.response?.data?.detail || "Reorder failed",
280
+ color: "error",
281
+ })
282
+ });
283
+ },
228
284
  setQparams(options) {
229
285
  this.$router.push({
230
286
  query: {
@@ -377,6 +433,10 @@ export default {
377
433
  this.$attrs.headers && this.$attrs.headers.length && this.$attrs.headers[0].value
378
434
  );
379
435
  },
436
+ headers() {
437
+ const dragColumn = { sortable: false, value: 'drag-column', width: '64px' }
438
+ return this.dragOrderingActive ? [ dragColumn,...this.$attrs.headers ] : this.$attrs.headers
439
+ },
380
440
  quickModeEnabled() {
381
441
  return (
382
442
  this.nameSpacedSlots(this.$slots, "qedit.body").length ||
@@ -8,7 +8,7 @@
8
8
 
9
9
  <script>
10
10
  /**
11
- * This component is made to simplify Many To Many associations. With this component you can modify an array selecting items from a list of checkboxes.
11
+ * This component is made to simplify ManyToMany and ForeignKeys associations. With this component you can modify an array selecting items from a list of checkboxes or a signle item selecting from a checkbox.
12
12
  */
13
13
 
14
14
  export default {
@@ -17,10 +17,11 @@ export default {
17
17
  return {
18
18
  model: null,
19
19
  options: [],
20
+ loading: false,
20
21
  };
21
22
  },
22
23
  props: {
23
- // V-model property. It is the array to be modified.
24
+ // V-model property. It is the attribute to be modified.
24
25
  value: {
25
26
  type: Object | Array | null,
26
27
  required: true,
@@ -30,6 +31,7 @@ export default {
30
31
  type: Array,
31
32
  default: () => [],
32
33
  },
34
+ // This is the endpoint where the component can fetch options.
33
35
  endpoint: String | Object,
34
36
  },
35
37
  computed: {
@@ -37,6 +39,8 @@ export default {
37
39
  return {
38
40
  chips: this.$attrs.multiple === false ? false : true,
39
41
  multiple: true,
42
+ loading: this.loading,
43
+ noDataText: this.loading ? "Fetching data.." : undefined,
40
44
  ...this.$attrs,
41
45
  };
42
46
  },
@@ -70,10 +74,14 @@ export default {
70
74
  },
71
75
  mounted() {
72
76
  if (this.crudConfig.url) {
77
+ this.loading = true;
73
78
  this.$mapo.$api
74
79
  .crud(this.crudConfig.url)
75
80
  .list(this.crudConfig.conf)
76
- .then((res) => (this.options = res));
81
+ .then((res) => {
82
+ this.options = res;
83
+ this.loading = false;
84
+ });
77
85
  }
78
86
  },
79
87
  };
@@ -218,5 +218,8 @@ export default {
218
218
  this.$emit("input", val);
219
219
  },
220
220
  },
221
+ mounted(){
222
+ this.internalValue = this.val
223
+ }
221
224
  };
222
225
  </script>
@@ -0,0 +1,232 @@
1
+ <template>
2
+ <div class="container pa-0">
3
+ <span class="repeater-label">{{ label }}:</span>
4
+ <v-divider />
5
+ <draggable
6
+ v-model="items"
7
+ handle=".repeater-handle-sort"
8
+ @change="sortCallback({ ...$event, items, eventType: 'move' })"
9
+ >
10
+ <div
11
+ class="repeater-wrapper"
12
+ v-for="(model, index) in items"
13
+ :key="index"
14
+ >
15
+ <div class="d-flex">
16
+ <v-divider vertical />
17
+ <div class="row ma-0">
18
+ <div
19
+ v-for="(field, i) in parsedFields"
20
+ :key="i"
21
+ :class="field.class || 'col-12'"
22
+ >
23
+ <DetailField
24
+ v-model="items[index]"
25
+ :conf="field"
26
+ :errors="getErrors(index)"
27
+ />
28
+ </div>
29
+ </div>
30
+ <div class="repeater-side-bar grey lighten-2">
31
+ <span
32
+ class="repeater-counter grey--text text--darken-2 text-truncate"
33
+ >{{ index + 1 }}</span
34
+ >
35
+ <v-tooltip right>
36
+ <template v-slot:activator="{ on, attrs }">
37
+ <v-icon
38
+ v-if="sortable"
39
+ v-bind="attrs"
40
+ v-on="on"
41
+ color="grey darken-3"
42
+ class="grey lighten-2 repeater-action repeater-add-line-index"
43
+ @click="addItem(index)"
44
+ >mdi-plus-circle-outline</v-icon
45
+ >
46
+ </template>
47
+ <span>Add here</span>
48
+ </v-tooltip>
49
+
50
+ <v-tooltip right>
51
+ <template v-slot:activator="{ on, attrs }">
52
+ <v-hover v-slot="{ hover }">
53
+ <v-icon
54
+ v-bind="attrs"
55
+ v-on="on"
56
+ :color="hover ? 'error' : 'grey darken-3'"
57
+ class="repeater-action repeater-remove-line"
58
+ @click="removeItem(index)"
59
+ >mdi-minus-circle-outline</v-icon
60
+ >
61
+ </v-hover>
62
+ </template>
63
+ <span>Remove</span>
64
+ </v-tooltip>
65
+ <v-icon
66
+ v-if="sortable"
67
+ color="grey darken-3"
68
+ class="repeater-action repeater-handle-sort"
69
+ >mdi-drag</v-icon
70
+ >
71
+ </div>
72
+ </div>
73
+ <v-divider />
74
+ </div>
75
+ </draggable>
76
+ <div class="d-flex justify-end">
77
+ <v-btn class="repeater-add-line" @click="addItem" outlined tile text>
78
+ <v-icon>mdi-plus</v-icon> Add</v-btn
79
+ >
80
+ </div>
81
+ </div>
82
+ </template>
83
+
84
+ <style lang="scss" scoped>
85
+ .repeater-action {
86
+ display: none;
87
+ }
88
+ .repeater-side-bar {
89
+ min-width: 24px;
90
+ position: relative;
91
+ display: flex;
92
+ flex-direction: column;
93
+ align-content: center;
94
+ justify-content: center;
95
+ &:hover {
96
+ .repeater-action {
97
+ display: inline-flex;
98
+ }
99
+ }
100
+ .repeater-counter {
101
+ position: absolute;
102
+ align-self: center;
103
+ top: 10px;
104
+ }
105
+ .repeater-add-line-index {
106
+ position: absolute;
107
+ align-self: center;
108
+ top: -11px;
109
+ border-radius: 50%;
110
+ }
111
+ .repeater-handle-sort {
112
+ position: absolute;
113
+ align-self: center;
114
+ bottom: 2px;
115
+ cursor: grab;
116
+ }
117
+ }
118
+ .repeater-add-line {
119
+ border-top: none;
120
+ }
121
+ </style>
122
+
123
+ <script>
124
+ import draggable from "vuedraggable";
125
+
126
+ /**
127
+ * This component is made to manage a list of object that can be added/removed/reordered with a simple form.
128
+ */
129
+ export default {
130
+ name: "Repeater",
131
+ components: {
132
+ draggable,
133
+ },
134
+ data() {
135
+ return {
136
+ items: null,
137
+ };
138
+ },
139
+ props: {
140
+ // V-model of the array needed to edit the objects in realtime.
141
+ value: {
142
+ type: Array,
143
+ default: () => [],
144
+ },
145
+ // Puts the input in an error state and passes through custom error messages.
146
+ errorMessages: {
147
+ type: Array,
148
+ default: () => [],
149
+ },
150
+ // Sets input label.
151
+ label: {
152
+ type: String,
153
+ },
154
+ // The main configuration that determines the arrangement of the fields in each line.
155
+ fields: {
156
+ // [`DetailConfiguration`](/components/Detail/Detail/#detailconfiguration)
157
+ type: Array,
158
+ default: () => [],
159
+ },
160
+ // Makes the repeater field sortable.
161
+ sortable: Boolean,
162
+ // This callback is called during sort/add/remove item if the Repeater is sortable. Use this callback to change some prop of the items in the list.
163
+ sortCallback: {
164
+ type: Function,
165
+ default: () => {},
166
+ },
167
+ },
168
+ watch: {
169
+ value(val) {
170
+ this.items = val;
171
+ },
172
+ items(val) {
173
+ this.$emit("input", val);
174
+ },
175
+ },
176
+ methods: {
177
+ addItem(index) {
178
+ const element = {};
179
+ const newIndex = typeof index == "number" ? index : this.items.length;
180
+ this.items.splice(newIndex, 0, element);
181
+ this.sortable &&
182
+ this.sortCallback({
183
+ moved: { element, newIndex },
184
+ items: this.items,
185
+ eventType: "add",
186
+ });
187
+ },
188
+ removeItem(index) {
189
+ const element = this.items[index];
190
+ this.items.splice(index, 1);
191
+ this.sortable &&
192
+ this.sortCallback({
193
+ moved: { element, oldIndex: index },
194
+ items: this.items,
195
+ eventType: "remove",
196
+ });
197
+ },
198
+ getErrors(index) {
199
+ return (this.errorMessages || [])[index] || {};
200
+ },
201
+ parseConf(field, i) {
202
+ const conf = typeof field === "string" ? { value: field } : field;
203
+ conf.value = conf.value || "";
204
+ conf.slotName = `fields.${conf.value || i}`;
205
+ if (this.isReadonly) {
206
+ conf.attrs = { ...conf.attrs, readonly: true };
207
+ }
208
+ return conf;
209
+ },
210
+ mapConf(fields) {
211
+ const icon = "mdi-cube-outline";
212
+ const parseGroup = (group) =>
213
+ typeof group === "string"
214
+ ? { name: group, icon }
215
+ : { ...group, icon: group.icon !== undefined ? group.icon : icon };
216
+ return fields.map((f, i) =>
217
+ f.group
218
+ ? { group: parseGroup(f.group), fields: this.mapConf(f.fields) }
219
+ : this.parseConf(f, i)
220
+ );
221
+ },
222
+ },
223
+ computed: {
224
+ parsedFields() {
225
+ return this.mapConf(this.fields);
226
+ },
227
+ },
228
+ mounted() {
229
+ this.items = this.value;
230
+ },
231
+ };
232
+ </script>
@@ -10,6 +10,7 @@
10
10
  </template>
11
11
 
12
12
  <style lang="scss">
13
+ html { overflow-y: auto }
13
14
  .v-main__wrap {
14
15
  .__nuxt-error-page {
15
16
  background: transparent;
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.15",
4
4
  "license": "MIT",
5
5
  "description": "This is part of Mapo nuxt module. Injects Mapo ui components in the nuxt component discovery system.",
6
6
  "author": "bnznamco <gabriele.baldi.01@gmail.com>",
7
7
  "repository": "https://github.com/lotrekagency/mapo",
8
8
  "main": "./module.js",
9
9
  "dependencies": {
10
- "@mapomodule/utils": "^1.0.0-alpha.13",
11
- "@nuxtjs/vuetify": "^1.12.1"
10
+ "@mapomodule/utils": "^1.0.0-alpha.15",
11
+ "@nuxtjs/vuetify": "^1.12.3",
12
+ "vuedraggable": "^2.24.3"
12
13
  },
13
14
  "publishConfig": {
14
15
  "access": "public"
15
16
  },
16
- "gitHead": "0975dada05d34efb26a3c7ab0f3ebe8c01f1ca30"
17
+ "gitHead": "cd42b3dd094ef3bf743c67819e6059bf9ccac491"
17
18
  }