@mapomodule/uikit 1.0.0-alpha.40 → 1.0.0-alpha.42

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,176 +1,201 @@
1
1
  <template>
2
2
  <div v-if="media" class="media-editor--wrapper">
3
- <div class="img_overlay">
4
- <v-btn class="img_overlay__button img_overlay__button--back" small icon @click="closeEditor">
5
- <v-icon>mdi-arrow-left</v-icon>
6
- </v-btn>
7
- <v-btn class="img_overlay__button img_overlay__button--href" small icon :href="media.file" target="_blank" >
8
- <v-icon>mdi-open-in-new</v-icon>
9
- </v-btn>
10
- </div>
11
- <MediaPreview
12
- :media="media"
13
- contain
14
- filename
15
- media-controls
16
- class="media-editor--preview elevation-2"
17
- />
18
- <v-overlay
19
- absolute
20
- v-model="editing"
21
- @click="editing = false"
22
- ></v-overlay>
23
- <div class="dialog">
24
- <div class="dialog__container">
25
- <v-card flat tile class="dialog__content overflow-y-auto"
26
- :class="{ 'py-0': !editing }"
27
- :max-height="editing ? height : '0px'"
28
- >
29
- <v-card-text class="flex-grow-0">
30
- <v-row class="flex-md-row-reverse">
31
- <v-col md="6" cols="12" class="info-media">
32
- <table class="text-caption fill-height pb-md-10">
33
- <tr>
34
- <td class="pr-3"><b>{{ $t("mapo.fileName") }}:</b></td>
35
- <td>{{ fileName }}</td>
36
- </tr>
37
- <tr>
38
- <td class="pr-3"><b>{{ $t("mapo.mime") }}:</b></td>
39
- <td>{{ media.mime_type }}</td>
40
- </tr>
41
- <tr>
42
- <td class="pr-3"><b>{{ $t("mapo.created") }}:</b></td>
43
- <td>{{ dateCreated }}</td>
44
- </tr>
45
- <tr>
46
- <td class="pr-3"><b>{{ $t("mapo.size") }}:</b></td>
47
- <td>{{ fileSize }}</td>
48
- </tr>
49
- <tr>
50
- <td class="pr-3"><b>URL:</b></td>
51
- <td>
52
- <a :href="media.file" target="_blank">{{ media.file }}</a>
53
- </td>
54
- </tr>
55
- <tr>
56
- <td class="pr-3"><b>{{ $t("mapo.linkedModels") }}:</b></td>
57
- <td>
58
- <ul>
59
- <li v-for="link in media.links" :key="link.id">
60
- <b>{{link.model}} (id:{{link.id}})</b> - {{link.name}}
61
- </li>
62
- </ul>
63
- </td>
64
- </tr>
65
- </table>
66
- </v-col>
67
- <v-col md="6" cols="12">
68
- <v-row>
69
- <v-col sm="6" md="12" cols="12">
70
- <v-text-field
3
+ <div class="img_overlay">
4
+ <v-btn
5
+ class="img_overlay__button img_overlay__button--back"
6
+ small
7
+ icon
8
+ @click="closeEditor"
9
+ >
10
+ <v-icon>mdi-arrow-left</v-icon>
11
+ </v-btn>
12
+ <v-btn
13
+ class="img_overlay__button img_overlay__button--href"
14
+ small
15
+ icon
16
+ :href="media.file"
17
+ target="_blank"
18
+ >
19
+ <v-icon>mdi-open-in-new</v-icon>
20
+ </v-btn>
21
+ </div>
22
+ <MediaPreview
23
+ :media="media"
24
+ contain
25
+ filename
26
+ media-controls
27
+ class="media-editor--preview elevation-2"
28
+ />
29
+ <v-overlay absolute v-model="editing" @click="editing = false"></v-overlay>
30
+ <div class="dialog">
31
+ <div class="dialog__container">
32
+ <v-card
33
+ flat
34
+ tile
35
+ class="dialog__content overflow-y-auto"
36
+ :class="{ 'py-0': !editing }"
37
+ :max-height="editing ? height : '0px'"
38
+ >
39
+ <v-card-text class="flex-grow-0">
40
+ <v-row class="flex-md-row-reverse">
41
+ <v-col md="6" cols="12" class="info-media">
42
+ <table class="text-caption fill-height pb-md-10">
43
+ <tr>
44
+ <td class="pr-3">
45
+ <b>{{ $t("mapo.fileName") }}:</b>
46
+ </td>
47
+ <td>{{ fileName }}</td>
48
+ </tr>
49
+ <tr>
50
+ <td class="pr-3">
51
+ <b>{{ $t("mapo.mime") }}:</b>
52
+ </td>
53
+ <td>{{ media.mime_type }}</td>
54
+ </tr>
55
+ <tr>
56
+ <td class="pr-3">
57
+ <b>{{ $t("mapo.created") }}:</b>
58
+ </td>
59
+ <td>{{ dateCreated }}</td>
60
+ </tr>
61
+ <tr>
62
+ <td class="pr-3">
63
+ <b>{{ $t("mapo.size") }}:</b>
64
+ </td>
65
+ <td>{{ fileSize }}</td>
66
+ </tr>
67
+ <tr>
68
+ <td class="pr-3"><b>URL:</b></td>
69
+ <td>
70
+ <a :href="media.file" target="_blank">{{ media.file }}</a>
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <td class="pr-3">
75
+ <b>{{ $t("mapo.linkedModels") }}:</b>
76
+ </td>
77
+ <td>
78
+ <ul>
79
+ <li v-for="link in media.links" :key="link.id">
80
+ <b>{{ link.model }} (id:{{ link.id }})</b> - {{ link.name }}
81
+ </li>
82
+ </ul>
83
+ </td>
84
+ </tr>
85
+ </table>
86
+ </v-col>
87
+ <v-col md="6" cols="12">
88
+ <v-row>
89
+ <v-col sm="6" md="12" cols="12">
90
+ <v-text-field
91
+ dense
92
+ v-model="media.name"
93
+ :label="$t('mapo.name')"
94
+ :readonly="!canEdit"
95
+ ></v-text-field>
96
+ </v-col>
97
+ <v-col sm="6" md="12" cols="12">
98
+ <v-text-field
99
+ dense
100
+ v-model="media.title"
101
+ :label="$t('mapo.titleTag')"
102
+ :readonly="!canEdit"
103
+ ></v-text-field>
104
+ </v-col>
105
+ <v-col sm="6" md="12" cols="12">
106
+ <v-text-field
107
+ dense
108
+ v-model="media.description"
109
+ :label="$t('mapo.description')"
110
+ :readonly="!canEdit"
111
+ ></v-text-field>
112
+ </v-col>
113
+ <v-col sm="6" md="12" cols="12">
114
+ <v-text-field
115
+ dense
116
+ v-model="media.alt_text"
117
+ :label="$t('mapo.altTag')"
118
+ :readonly="!canEdit"
119
+ ></v-text-field>
120
+ </v-col>
121
+ <v-col
122
+ sm="6"
123
+ md="12"
124
+ cols="12"
125
+ class="d-flex align-center"
126
+ v-if="canEdit"
127
+ >
128
+ <div class="d-flex flex-column flex-grow-1">
129
+ <v-file-input
130
+ v-model="newFile"
131
+ :accept="accept"
132
+ :label="$t('mapo.mediaEditor.changeFile')"
133
+ show-size
71
134
  dense
72
- v-model="media.name"
73
- :label="$t('mapo.name')"
74
- ></v-text-field>
75
- </v-col>
76
- <v-col sm="6" md="12" cols="12">
77
- <v-text-field
135
+ prepend-icon
136
+ ></v-file-input>
137
+ <v-checkbox
138
+ v-if="newFile"
139
+ v-model="sameUrl"
140
+ :label="$t('mapo.mediaEditor.maintainOldUrl')"
141
+ class="ma-0"
142
+ hide-details
78
143
  dense
79
- v-model="media.title"
80
- :label="$t('mapo.titleTag')"
81
- ></v-text-field>
82
- </v-col>
83
- <v-col sm="6" md="12" cols="12">
84
- <v-text-field
85
- dense
86
- v-model="media.description"
87
- :label="$t('mapo.description')"
88
- ></v-text-field>
89
- </v-col>
90
- <v-col sm="6" md="12" cols="12">
91
- <v-text-field
92
- dense
93
- v-model="media.alt_text"
94
- :label="$t('mapo.altTag')"
95
- ></v-text-field>
96
- </v-col>
97
- <v-col sm="6" md="12" cols="12" class="d-flex align-center">
98
- <div class="d-flex flex-column flex-grow-1">
99
- <v-file-input
100
- v-model="newFile"
101
- :accept="accept"
102
- :label="$t('mapo.mediaEditor.changeFile')"
103
- show-size
104
- dense
105
- prepend-icon
106
- ></v-file-input>
107
- <v-checkbox
108
- v-if="newFile"
109
- v-model="sameUrl"
110
- :label="$t('mapo.mediaEditor.maintainOldUrl')"
111
- class="ma-0"
112
- hide-details
113
- dense
114
- ></v-checkbox>
115
- </div>
116
- <v-img
117
- v-if="newFile && newFilePreview"
118
- :src="newFilePreview"
119
- aspect-ratio="1"
120
- min-width="70px"
121
- max-width="110px"
122
- class="grey lighten-2 ml-3"
123
- >
124
- <template v-slot:placeholder>
125
- <v-row
126
- class="fill-height ma-0"
127
- align="center"
128
- justify="center"
129
- >
130
- <v-progress-circular
131
- indeterminate
132
- color="grey lighten-5"
133
- ></v-progress-circular>
134
- </v-row>
135
- </template>
136
- </v-img>
137
- </v-col>
138
- </v-row>
139
- </v-col>
140
- </v-row>
141
- </v-card-text>
142
- </v-card>
144
+ ></v-checkbox>
145
+ </div>
146
+ <v-img
147
+ v-if="newFile && newFilePreview"
148
+ :src="newFilePreview"
149
+ aspect-ratio="1"
150
+ min-width="70px"
151
+ max-width="110px"
152
+ class="grey lighten-2 ml-3"
153
+ >
154
+ <template v-slot:placeholder>
155
+ <v-row class="fill-height ma-0" align="center" justify="center">
156
+ <v-progress-circular
157
+ indeterminate
158
+ color="grey lighten-5"
159
+ ></v-progress-circular>
160
+ </v-row>
161
+ </template>
162
+ </v-img>
163
+ </v-col>
164
+ </v-row>
165
+ </v-col>
166
+ </v-row>
167
+ </v-card-text>
168
+ </v-card>
169
+ <v-btn
170
+ tile
171
+ depressed
172
+ width="100%"
173
+ :class="{ 'pr-0': editing }"
174
+ @click="editing = !editing"
175
+ >
176
+ <span>{{ canEdit ? $t("mapo.edit") : $t("mapo.mediaEditor.details") }}</span>
177
+ <v-icon :style="rotate">mdi-chevron-up</v-icon>
178
+ <div class="edit_spacer" :class="{ 'flex-grow-1': editing }"></div>
179
+ <v-btn v-if="editing && canEdit" text tile color="primary" @click="saveMedia">
180
+ {{ $t("mapo.save") }}
181
+ </v-btn>
143
182
  <v-btn
183
+ v-if="editing && canDelete"
184
+ text
144
185
  tile
145
- depressed
146
- width="100%"
147
- :class="{ 'pr-0': editing }"
148
- @click="editing = !editing"
186
+ color="error"
187
+ @click.stop="confirmDelete"
149
188
  >
150
- <span>{{ $t("mapo.edit") }}</span>
151
- <v-icon :style="rotate">mdi-chevron-up</v-icon>
152
- <div class="edit_spacer" :class="{ 'flex-grow-1': editing }"></div>
153
- <v-btn v-if="editing" text tile color="primary" @click="saveMedia">
154
- {{ $t("mapo.save") }}
155
- </v-btn>
156
- <v-btn
157
- v-if="editing"
158
- text
159
- tile
160
- color="error"
161
- @click.stop="confirmDelete"
162
- >
163
- {{ $t("mapo.delete") }}
164
- </v-btn>
189
+ {{ $t("mapo.delete") }}
165
190
  </v-btn>
166
- </div>
191
+ </v-btn>
167
192
  </div>
193
+ </div>
168
194
  </div>
169
195
  </template>
170
196
 
171
197
  <style lang="scss" scoped>
172
-
173
- .media-editor--wrapper{
198
+ .media-editor--wrapper {
174
199
  height: 100%;
175
200
  display: flex;
176
201
  flex-direction: column;
@@ -195,16 +220,17 @@ table tr td:nth-child(2) {
195
220
  transition-timing-function: ease-out;
196
221
  }
197
222
  }
198
- .media-editor--preview{
223
+ .media-editor--preview {
199
224
  max-height: calc(100vh - 180px);
200
225
  flex-grow: 1;
201
- @media (max-width: 600px){
226
+ @media (max-width: 600px) {
202
227
  max-height: calc(100vh - 260px);
203
- min-height: calc(100vh - 260px); }
228
+ min-height: calc(100vh - 260px);
229
+ }
204
230
  }
205
- .v-dialog .media-editor--preview{
231
+ .v-dialog .media-editor--preview {
206
232
  max-height: calc(100vh - 510px);
207
- @media (max-width: 600px){
233
+ @media (max-width: 600px) {
208
234
  max-height: calc(100vh - 375px);
209
235
  min-height: unset;
210
236
  }
@@ -231,8 +257,9 @@ table tr td:nth-child(2) {
231
257
  }
232
258
  </style>
233
259
  <script>
260
+ import { deepClone } from "@mapomodule/utils/helpers/objHelpers";
234
261
  import { humanFileSize } from "@mapomodule/utils/helpers/formatters";
235
- import { mapGetters, mapActions } from "vuex"
262
+ import { mapGetters, mapActions } from "vuex";
236
263
 
237
264
  export default {
238
265
  name: "MediaEditor",
@@ -269,25 +296,42 @@ export default {
269
296
  return 425;
270
297
  }
271
298
  },
272
- accept(){
299
+ accept() {
273
300
  switch (this.media.mime_type && this.media.mime_type.split("/")[0]) {
274
301
  case "image":
275
- return "image/*"
302
+ return "image/*";
276
303
  case "video":
277
- return "video/*"
304
+ return "video/*";
278
305
  case "audio":
279
- return "audio/*"
306
+ return "audio/*";
280
307
  default:
281
- return "*"
308
+ return "*";
282
309
  }
283
310
  },
284
311
  newFilePreview() {
285
- return this.newFile.type.startsWith("image/") ? URL.createObjectURL(this.newFile) : null;
312
+ return this.newFile.type.startsWith("image/")
313
+ ? URL.createObjectURL(this.newFile)
314
+ : null;
315
+ },
316
+ permissionsModel() {
317
+ return this.$mapo.$options?.medias?.permissionsModel || "media";
318
+ },
319
+ canEdit() {
320
+ return this.$store.getters["mapo/user/hasModelPermission"](
321
+ this.permissionsModel,
322
+ "change"
323
+ );
324
+ },
325
+ canDelete() {
326
+ return this.$store.getters["mapo/user/hasModelPermission"](
327
+ this.permissionsModel,
328
+ "delete"
329
+ );
286
330
  },
287
331
  },
288
332
  watch: {
289
333
  editMedia(val) {
290
- this.media = val;
334
+ this.media = deepClone(val);
291
335
  this.editing = false;
292
336
  this.newFile = null;
293
337
  this.sameUrl = false;
@@ -304,7 +348,7 @@ export default {
304
348
  alt_text: this.media.alt_text,
305
349
  file: this.newFile || undefined,
306
350
  same_url: (this.newFile && this.sameUrl) || undefined,
307
- language_code: this.$i18n.locale
351
+ language_code: this.$i18n.locale,
308
352
  }).then(() => {
309
353
  this.newFile = null;
310
354
  this.sameUrl = false;
@@ -315,10 +359,13 @@ export default {
315
359
  .open({
316
360
  title: this.$t("mapo.delete"),
317
361
  question: this.$t("mapo.mediaEditor.confirmDelete"),
318
- approveButton: { text: this.$t("mapo.delete"), attrs: { color: "red", text: true } },
362
+ approveButton: {
363
+ text: this.$t("mapo.delete"),
364
+ attrs: { color: "red", text: true },
365
+ },
319
366
  })
320
367
  .then((res) => res && this.deleteMedia(this.media));
321
- }
368
+ },
322
369
  },
323
370
  };
324
371
  </script>
@@ -23,7 +23,11 @@
23
23
  >
24
24
  </v-list-item>
25
25
 
26
- <div class="child-menu" :style="indent" v-if="childrens.length && expanded && !forceCollapse">
26
+ <div
27
+ class="child-menu"
28
+ :style="indent"
29
+ v-if="childrens.length && expanded && !forceCollapse"
30
+ >
27
31
  <SidebarListItem
28
32
  v-for="(item, i) in childrens"
29
33
  :key="i"
@@ -44,15 +48,15 @@
44
48
  <style lang="scss" scoped>
45
49
  @import "@mapomodule/uikit/assets/variables.scss";
46
50
 
47
- .v-list-item::after{
48
- content: '';
51
+ .v-list-item::after {
52
+ content: "";
49
53
  position: absolute;
50
54
  background: rgba(0, 0, 0, 0.2);
51
55
  height: 100%;
52
56
  width: 4px;
53
57
  left: 0;
54
58
  }
55
- .v-list-item.v-list-item--active::after{
59
+ .v-list-item.v-list-item--active::after {
56
60
  background: var(--v-primary-base);
57
61
  }
58
62
  .expand-icon {
@@ -110,7 +114,7 @@
110
114
  border-bottom-left-radius: 3px;
111
115
  }
112
116
  }
113
- .child-menu{
117
+ .child-menu {
114
118
  &::after {
115
119
  height: 0px;
116
120
  }
@@ -131,7 +135,8 @@ export default {
131
135
  indent() {
132
136
  return {
133
137
  paddingLeft: `calc(1rem + ${+this.depth * this.nestDepth}px)`,
134
- marginLeft: this.depth > 1 && `calc(-1rem - ${(this.depth - 1) * this.nestDepth}px)`,
138
+ marginLeft:
139
+ this.depth > 1 && `calc(-1rem - ${(this.depth - 1) * this.nestDepth}px)`,
135
140
  };
136
141
  },
137
142
  rotate() {
@@ -141,21 +146,28 @@ export default {
141
146
  };
142
147
  },
143
148
  activeChild() {
144
- return (this.childrens || []).some((child) => this.$nuxt.$route.path.startsWith(child.link));
149
+ return (this.childrens || []).some((child) =>
150
+ this.$nuxt.$route.path.startsWith(child.link)
151
+ );
145
152
  },
146
153
  userCanSee() {
147
- const middleware = this.$mapo.$auth.getRouteMiddlewares({ meta: this.meta })
148
- if (middleware.includes("permissions")){
149
- const userInfo = this.$mapo.$auth.user.info
150
- if (userInfo.is_superuser) return true
151
- const { model } = this.meta?.permissions || {}
152
- const userPermission = (userInfo.user_permissions || []).filter(perm => perm.codename.endsWith(model)).map(({ codename }) => codename.replace(`_${model}`, ''))
153
- return userPermission.includes('view')
154
+ return this.checkPermissions();
155
+ },
156
+ },
157
+ methods: {
158
+ checkPermissions(child = undefined) {
159
+ const item = child || this;
160
+ const middleware = this.$mapo.$auth.getRouteMiddlewares({ meta: item.meta });
161
+ if (middleware.includes("permissions")) {
162
+ const { model } = item.meta?.permissions || {};
163
+ return this.$store.getters["mapo/user/hasModelPermission"](model, "view");
154
164
  }
155
- if (middleware.includes("auth")){
156
- return this.$mapo.$auth.user.isLoggedIn
165
+ if (middleware.includes("auth")) {
166
+ return this.$mapo.$auth.user.isLoggedIn;
157
167
  }
158
- return true
168
+ return (
169
+ item.childrens.length == 0 || item.childrens.some((c) => this.checkPermissions(c))
170
+ );
159
171
  },
160
172
  },
161
173
  props: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.40",
3
+ "version": "1.0.0-alpha.42",
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>",
@@ -15,5 +15,5 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "gitHead": "918d8d3ed9a6edc9be25e082f9917866e8c73c57"
18
+ "gitHead": "9f5a3f301377c547f69103e91201144b726b784c"
19
19
  }
@@ -109,10 +109,11 @@ export default {
109
109
  changeFile: "Change File",
110
110
  maintainOldUrl: "Maintain old URL",
111
111
  confirmDelete: "Are you sure you want to delete this media?",
112
+ details: "Details",
112
113
  },
113
114
  // MediaManager/MediaFolders.vue
114
115
  mediaFolders: {
115
- goBack: "Go back",
116
+ goBack: "Go back",
116
117
  noFolders: "No folders here... Create a new one!",
117
118
  newFolder: "Add new folder",
118
119
  editFolder: "Edit folder",
@@ -111,10 +111,11 @@ export default {
111
111
  changeFile: "Cambia File",
112
112
  maintainOldUrl: "Mantieni URL precedente",
113
113
  confirmDelete: "Vuoi veramente eliminare questo media?",
114
+ details: "Dettagli",
114
115
  },
115
116
  // MediaManager/MediaFolders.vue
116
117
  mediaFolders: {
117
- goBack: "Torna indietro",
118
+ goBack: "Torna indietro",
118
119
  noFolders: "Non sono presenti cartelle... Creane una!",
119
120
  newFolder: "Crea nuova cartella",
120
121
  editFolder: "Modifica cartella",