@mapomodule/uikit 1.0.0-alpha.43 → 1.0.0-alpha.45

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,15 +1,55 @@
1
1
  <template>
2
2
  <div class="media-gallery--wrapper">
3
- <draggable v-model="draggableSelection" animation="150" v-if="selection && selection.length && selectMode == 'multi'" class="media-gallery--selection grey darken-2">
4
- <MediaPreview
5
- v-for="media in selection"
6
- :key="media.file"
7
- @click.native.stop="select(media)"
8
- :media="media"
9
- icon-size="20px"
10
- class="elevation-4 media-gallery--selection-item"
11
- />
3
+ <draggable
4
+ v-model="draggableSelection"
5
+ animation="150"
6
+ v-if="selection && selection.length && selectMode == 'multi'"
7
+ class="media-gallery--selection grey darken-2"
8
+ >
9
+ <MediaPreview
10
+ v-for="media in selection"
11
+ :key="media.file"
12
+ @click.native.stop="select(media)"
13
+ :media="media"
14
+ icon-size="20px"
15
+ class="elevation-4 media-gallery--selection-item"
16
+ />
12
17
  </draggable>
18
+ <div class="media-gallery--selectAll" v-if="editListSet.size">
19
+ <div class="media-gallery--select-action">
20
+ <v-icon
21
+ v-if="editListState.outside"
22
+ @click="editSelect('__clear__')"
23
+ dense
24
+ left
25
+ color="error"
26
+ >mdi-close-box-outline</v-icon
27
+ >
28
+ <span class="mr-2"
29
+ >{{ editListSet.size }}
30
+ {{ $t("mapo.mediaGallery.selectedAssets") }}</span
31
+ >
32
+ <!-- <v-btn text small> <v-icon left>mdi-image-move</v-icon> Move</v-btn> -->
33
+ <v-btn text small @click="deleteSelected">
34
+ <v-icon left>mdi-delete-sweep</v-icon> {{ $t("mapo.delete") }}</v-btn
35
+ >
36
+ </div>
37
+ <div class="media-gallery--select-action">
38
+ <v-checkbox
39
+ hide-details
40
+ dense
41
+ color="accent"
42
+ :label="
43
+ editListState.value
44
+ ? $t('mapo.mediaGallery.deselectAll')
45
+ : $t('mapo.mediaGallery.selectAll')
46
+ "
47
+ @click="editSelect(medias.map((m) => m.id))"
48
+ :input-value="editListState.value"
49
+ :indeterminate="editListState.indeterminate"
50
+ />
51
+ </div>
52
+ </div>
13
53
  <div ref="masonry" class="media-gallery--masonry" v-if="medias.length">
14
54
  <div
15
55
  v-for="media in medias"
@@ -17,16 +57,24 @@
17
57
  class="media-gallery--card"
18
58
  >
19
59
  <v-btn
60
+ v-if="selectMode != 'none'"
20
61
  @click.stop="openEditor(media)"
21
62
  icon
22
63
  small
23
64
  :ripple="false"
24
65
  color="white"
25
66
  class="media-gallery--card-btn"
26
- :class="{'d-none': selectMode == 'none'}"
27
67
  >
28
68
  <v-icon>mdi-circle-edit-outline</v-icon>
29
69
  </v-btn>
70
+ <v-checkbox
71
+ hide-details
72
+ dense
73
+ @click="editSelect(media.id)"
74
+ :input-value="editListSet.has(media.id)"
75
+ color="accent"
76
+ class="media-gallery--card-checkbox"
77
+ />
30
78
  <MediaPreview
31
79
  class="elevation-4 cursor-pointer"
32
80
  :media="media"
@@ -69,13 +117,39 @@
69
117
  background: #1e1e1ea1;
70
118
  border-radius: 50% 0 0;
71
119
  }
120
+ &-checkbox {
121
+ position: absolute;
122
+ z-index: 1;
123
+ right: 0;
124
+ top: 0;
125
+ margin: 0;
126
+ opacity: 0;
127
+ transition: opacity 0.5s;
128
+ &.v-input--is-label-active {
129
+ opacity: 1;
130
+ }
131
+ }
132
+ &:hover {
133
+ .media-gallery--card-checkbox {
134
+ opacity: 1;
135
+ }
136
+ }
137
+ }
138
+ .media-gallery--selectAll {
139
+ display: flex;
140
+ justify-content: space-between;
141
+ padding: 0 24px 0 10px;
142
+ flex-wrap: wrap;
143
+ }
144
+ .media-gallery--select-action {
145
+ display: flex;
146
+ align-items: center;
72
147
  }
73
148
 
74
149
  .media-gallery--wrapper{
75
150
  height: 100%;
76
151
  display: flex;
77
152
  flex-direction: column;
78
- justify-content: space-between;
79
153
  }
80
154
 
81
155
  $wcol: calc(100% / 6 - 12px);
@@ -171,7 +245,7 @@ export default {
171
245
  name: "MediaGallery",
172
246
  components: { draggable },
173
247
  computed: {
174
- ...mapGetters("mapo/media", ["page", "pages", "medias", "selection", "selectMode", "loading"]),
248
+ ...mapGetters("mapo/media", ["page", "pages", "medias", "selection", "selectMode", "loading", "editListState", "editListSet"]),
175
249
  draggableSelection: {
176
250
  get() { return this.selection; },
177
251
  set(val) { this.setSelection(val); }
@@ -188,7 +262,7 @@ export default {
188
262
  },
189
263
  },
190
264
  methods: {
191
- ...mapActions("mapo/media", ["getRoot", "openEditor", "select", "setSelection"]),
265
+ ...mapActions("mapo/media", ["getRoot", "openEditor", "select", "setSelection", "editSelect", "deleteSelected"]),
192
266
  isSelected(media) {
193
267
  switch (this.selectMode) {
194
268
  case "multi":
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="media-manager--wrapper">
3
- <MediaFolders v-show="!editMedia" v-if="!noFolders" />
3
+ <MediaFolders v-show="!editMedia" v-if="!noFolders" :mime="mime" />
4
4
  <v-card elevation="0" class="media-manager--v-card" :class="{ transparent: !fillBackgroud, editing:editMedia }">
5
5
  <v-card-title class="d-flex flex-wrap pa-0">
6
6
  <div class="d-flex flex-grow-1">
@@ -137,15 +137,23 @@ export default {
137
137
  methods: {
138
138
  ...mapActions("mapo/media", ["getRoot", "openEditor", "updateMedia", "updateOrCreateFolder", "deleteFolder", "deleteMedia", "reset"]),
139
139
  search: debounce(function () {
140
- this.getRoot({search: this.searchValue}).then(() => (this.loadingSearch = false));
140
+ this.getRoot({search: this.searchValue, all: true}).then(() => (this.loadingSearch = false));
141
141
  }, 500),
142
142
  },
143
143
  async fetch() {
144
144
  this.$store.commit("mapo/media/SET_MIME_TYPE", this.mime || null);
145
145
  await this.getRoot();
146
146
  },
147
+ mounted(){
148
+ this.storeUnsubscribe = this.$store.subscribeAction((action) => {
149
+ if (action.type == "mapo/media/getRoot" && this.searchValue != action.payload?.search) {
150
+ this.searchValue = action.payload?.search;
151
+ }
152
+ });
153
+ },
147
154
  destroyed(){
148
155
  this.reset();
156
+ this.storeUnsubscribe && this.storeUnsubscribe()
149
157
  }
150
158
  };
151
159
  </script>
@@ -24,12 +24,6 @@
24
24
  :label="$t('mapo.folder')"
25
25
  ></v-select>
26
26
  </v-col>
27
- <v-col cols="12">
28
- <v-text-field
29
- v-model="editedItem.name"
30
- :label="$t('mapo.name')"
31
- ></v-text-field>
32
- </v-col>
33
27
  <v-col cols="12">
34
28
  <v-text-field
35
29
  v-model="editedItem.title"
@@ -0,0 +1,327 @@
1
+ <template>
2
+ <div v-if="model" class="menu-manager--wrapper">
3
+ <v-navigation-drawer
4
+ v-model="mobileOpened"
5
+ :bottom="isMobile"
6
+ :absolute="isMobile"
7
+ :permanent="!isMobile"
8
+ >
9
+ <MenuTreeview
10
+ v-model="selected"
11
+ :nodes.sync="nodes"
12
+ :title="`Menu: ${model.key}`"
13
+ ref="treeview"
14
+ >
15
+ <template v-if="translationsActive" v-slot:treeview.top>
16
+ <DetailLangSwitch
17
+ :langs="languages"
18
+ v-model="currentLang"
19
+ :errors="errors"
20
+ />
21
+ </template>
22
+ <template v-slot:treeview.bottom>
23
+ <v-btn tile @click="save" :loading="loading">
24
+ {{ $t("mapo.save") }}
25
+ </v-btn>
26
+ </template>
27
+ </MenuTreeview>
28
+ </v-navigation-drawer>
29
+ <MenuNodeEditor
30
+ v-if="selected"
31
+ v-model="selected"
32
+ @delete="$refs.treeview.deleteSelectedNode"
33
+ :menu-endpoint="endpoint"
34
+ :nodes="nodes"
35
+ :lang="currentLang"
36
+ :languages="languages"
37
+ :readonly="isReadonly"
38
+ v-bind="$attrs"
39
+ >
40
+ <template v-for="slot in nameSpacedSlots($slots, 'editor.')" :slot="slot">
41
+ <slot :name="`editor.${slot}`"></slot>
42
+ </template>
43
+ <template v-for="slot in nameSpacedSlots($scopedSlots, 'editor.')" v-slot:[slot]="props">
44
+ <slot :name="`editor.${slot}`" v-bind="props" />
45
+ </template>
46
+ </MenuNodeEditor>
47
+ <div class="menu-manager--empty" v-else>
48
+ <v-icon size="60"> mdi-resistor-nodes </v-icon>
49
+ <p>{{ $t("mapo.menuManager.noSelectedNode") }}</p>
50
+ </div>
51
+ <v-btn
52
+ v-if="isMobile"
53
+ class="menu-manager--bottom-btn"
54
+ tile
55
+ block
56
+ @click="save"
57
+ :loading="loading"
58
+ >
59
+ {{ $t("mapo.save") }}
60
+ </v-btn>
61
+ <v-btn
62
+ v-if="isMobile"
63
+ color="primary"
64
+ class="menu-manager--bottom-btn"
65
+ tile
66
+ @click="mobileOpened = !mobileOpened"
67
+ ><v-icon>mdi-menu-open</v-icon></v-btn
68
+ >
69
+ </div>
70
+ </template>
71
+ <style lang="scss">
72
+ .menu-manager--wrapper {
73
+ display: flex;
74
+ flex-direction: row;
75
+ height: 100%;
76
+ .v-tabs {
77
+ flex: 0;
78
+ }
79
+ }
80
+ .menu-node-editor--wrapper {
81
+ flex: 1;
82
+ max-width: 100%;
83
+ }
84
+ .menu-manager--bottom-btn {
85
+ position: absolute;
86
+ bottom: 0;
87
+ }
88
+ .menu-manager--empty {
89
+ flex: 1;
90
+ max-width: 100%;
91
+ overflow: hidden;
92
+ display: flex;
93
+ flex-direction: column;
94
+ align-content: center;
95
+ justify-content: center;
96
+ text-align: center;
97
+ }
98
+ </style>
99
+
100
+ <script>
101
+ import { diffObjs, deepClone } from "@mapomodule/utils/helpers/objHelpers";
102
+ import { nameSpacedSlots } from "@mapomodule/utils/helpers/slots";
103
+
104
+ export default {
105
+ name: "MenuManager",
106
+ props: {
107
+ // V-model of the object we are editing.
108
+ value: {
109
+ type: Object,
110
+ required: false,
111
+ },
112
+ // Set the current lang to value.
113
+ translatable: {
114
+ type: Boolean,
115
+ default: true,
116
+ },
117
+ // Set the current lang to value.
118
+ lang: {
119
+ type: String,
120
+ required: false,
121
+ },
122
+ languages: {
123
+ type: Array,
124
+ default() {
125
+ return this.$mapo.$options?.content?.languages || [];
126
+ },
127
+ },
128
+ usePatch: {
129
+ type: Boolean,
130
+ default() {
131
+ return this.$mapo.$options?.content?.usePatch || false;
132
+ },
133
+ },
134
+ endpoint: {
135
+ type: String,
136
+ default: null,
137
+ },
138
+ identifier: {
139
+ // `String|Number`.
140
+ type: String | Number,
141
+ default: "new",
142
+ },
143
+ },
144
+ data() {
145
+ return {
146
+ selected: null,
147
+ mobileOpened: false,
148
+ currentLang: this.lang || this.$i18n.locale,
149
+ loading: false,
150
+ errors: {},
151
+ model: { key: Math.random().toString(36).slice(2) },
152
+ crud: this.$mapo.$api.crud(this.endpoint),
153
+ };
154
+ },
155
+ watch: {
156
+ currentLang(val) {
157
+ // Fired when the current language changes.
158
+ // @arg Emits the language name as a string.
159
+ this.$emit("update:lang", val);
160
+ },
161
+ model(val) {
162
+ // Fired when the v-model changes.
163
+ // @arg Emits the entire payload modified.
164
+ this.$emit("input", val);
165
+ },
166
+ lang(val) {
167
+ if (val && this.languages.includes(val)) {
168
+ this.currentLang = val;
169
+ }
170
+ },
171
+ value(val) {
172
+ if (val) {
173
+ this.model = val;
174
+ }
175
+ },
176
+ currentLang(val) {
177
+ this.selected = null;
178
+ },
179
+ },
180
+ computed: {
181
+ nodes: {
182
+ get() {
183
+ if (this.translationsActive) {
184
+ this.initTranslations();
185
+ return this.model.translations[this.currentLang].nodes;
186
+ } else {
187
+ return this.model.nodes;
188
+ }
189
+ },
190
+ set(val) {
191
+ if (this.translationsActive) {
192
+ this.initTranslations();
193
+ return this.$set(
194
+ this.model.translations[this.currentLang],
195
+ "nodes",
196
+ val
197
+ );
198
+ } else {
199
+ return this.$set(this.model, "nodes", val);
200
+ }
201
+ },
202
+ },
203
+ isNew() {
204
+ return this.identifier && this.identifier == "new";
205
+ },
206
+ isReadonly() {
207
+ if (this.$mapo.$auth.routeMiddlewares.includes("permissions")) {
208
+ return !this.$mapo.$auth.user.permissions.includes(
209
+ this.isNew ? "add" : "change"
210
+ );
211
+ }
212
+ return !!this.buttonClicked;
213
+ },
214
+ translationsActive() {
215
+ return this.translatable && !!this.languages?.length;
216
+ },
217
+ modelDiff() {
218
+ return diffObjs(this.modelBkp, this.model) || {};
219
+ },
220
+ hasDiff() {
221
+ return !!(this.modelDiff && Object.keys(this.modelDiff).length > 0);
222
+ },
223
+ apiSendPayload() {
224
+ let method, args;
225
+ if (!this.model.id) {
226
+ method = this.crud.create;
227
+ args = [this.model];
228
+ } else if (this.usePatch) {
229
+ method = this.crud.partialUpdate;
230
+ args = [this.model.id, this.modelDiff];
231
+ } else {
232
+ method = this.crud.update;
233
+ args = [this.model.id, this.model];
234
+ }
235
+ return async () => method(...args);
236
+ },
237
+ isMobile() {
238
+ return this.$vuetify.breakpoint.xs;
239
+ },
240
+ },
241
+ async mounted() {
242
+ if (this.identifier && this.identifier !== "new") {
243
+ try {
244
+ this.model = await this.crud.detail(this.identifier);
245
+ } catch (error) {
246
+ this.$nuxt.error({
247
+ statusCode: error.response.status,
248
+ message: error.response.data?.detail || this.$t("mapo.genericError"),
249
+ });
250
+ }
251
+ } else if (this.value) {
252
+ this.model = this.value;
253
+ }
254
+ this.modelBkp = deepClone(this.model);
255
+ },
256
+ methods: {
257
+ nameSpacedSlots,
258
+ save() {
259
+ this.errors = null;
260
+ this.loading = true;
261
+ this.apiSendPayload()
262
+ .then((resp) => {
263
+ this.model = resp;
264
+ this.modelBkp = deepClone(this.model);
265
+ this.$mapo.$snack.open({
266
+ message: this.isNew
267
+ ? this.$t("mapo.createSuccess")
268
+ : this.$t("mapo.saveSuccess"),
269
+ color: "success",
270
+ });
271
+ this.isNew && this.$router.replace({ params: { detail: resp.id } });
272
+ })
273
+ .catch((error) => {
274
+ this.errors =
275
+ (error.response?.status == 400 && error.response?.data) || null;
276
+ this.parseErrors(this.errors);
277
+ this.$mapo.$snack.open({
278
+ message:
279
+ error.response?.data?.detail || this.$t("mapo.genericError"),
280
+ color: "error",
281
+ });
282
+ })
283
+ .finally(() => {
284
+ this.loading = false;
285
+ });
286
+ },
287
+ initTranslations() {
288
+ this.model.translations = this.model.translations || {};
289
+ if (!this.model.translations[this.currentLang]) {
290
+ this.model.translations[this.currentLang] = { nodes: [] };
291
+ }
292
+ },
293
+
294
+ parseErrors(errors) {
295
+ if (!errors) return;
296
+ const recurse = (node, error, lang = null) => {
297
+ let { nodes, ...nodeErrors } = error || {};
298
+ if (Object.keys(nodeErrors).length > 0) {
299
+ if (this.currentLang == lang || !this.translationsActive) {
300
+ this.selected = node;
301
+ this.$refs?.treeview?.$refs.nodes?.forEach((nodeRef) =>
302
+ nodeRef.openIfChild(node)
303
+ );
304
+ }
305
+ this.$set(node, "errors", nodeErrors);
306
+ }
307
+ let index = 0;
308
+ while (nodes && index < nodes.length) {
309
+ recurse(node.nodes[index], error.nodes[index]);
310
+ index++;
311
+ }
312
+ };
313
+ if (this.translationsActive) {
314
+ Object.keys(errors.translations).forEach((lang) =>
315
+ recurse(
316
+ this.model.translations[lang],
317
+ errors.translations[lang],
318
+ lang
319
+ )
320
+ );
321
+ } else {
322
+ recurse(this.model, errors);
323
+ }
324
+ },
325
+ },
326
+ };
327
+ </script>