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

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,34 @@
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.47](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.46...v1.0.0-alpha.47) (2023-06-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix media gallery keys ([f9fb666](https://github.com/lotrekagency/mapo/commit/f9fb6664456488b0b32b730ef7236d2e8bddea80))
12
+
13
+
14
+ ### Features
15
+
16
+ * improve media uloader progress ([bbc9628](https://github.com/lotrekagency/mapo/commit/bbc9628653c18ebbcb37011302e698d9dc8f29a8))
17
+ * update translations ([a51ae6d](https://github.com/lotrekagency/mapo/commit/a51ae6d86da32248b6377f1d4ce6bfab7fc413d1))
18
+
19
+
20
+
21
+
22
+
23
+ # [1.0.0-alpha.46](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.45...v1.0.0-alpha.46) (2023-06-24)
24
+
25
+
26
+ ### Features
27
+
28
+ * media manager enhancements ([994a8f0](https://github.com/lotrekagency/mapo/commit/994a8f05207d85b92133ede63b70d5f33750158c))
29
+
30
+
31
+
32
+
33
+
6
34
  # [1.0.0-alpha.45](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.44...v1.0.0-alpha.45) (2023-06-10)
7
35
 
8
36
  **Note:** Version bump only for package @mapomodule/uikit
@@ -140,6 +140,7 @@ export default {
140
140
  },
141
141
  },
142
142
  mounted() {
143
+ throw Error("TimeField is actually broken. Use something else.")
143
144
  this.model = this.setupModel(this.value);
144
145
  },
145
146
  };
@@ -300,13 +300,18 @@ export default {
300
300
  },
301
301
  },
302
302
  methods: {
303
- ...mapActions("mapo/media", ["closeEditor", "deleteMedia", "updateMedia"]),
303
+ ...mapActions("mapo/media", ["getRoot", "closeEditor", "deleteMedia", "updateMedia"]),
304
304
  saveMedia() {
305
305
  this.updateMedia({
306
306
  ...this.media,
307
307
  file: this.newFile || undefined,
308
308
  same_url: (this.newFile && this.sameUrl) || undefined,
309
309
  language_code: this.$i18n.locale,
310
+ }).catch(error => {
311
+ this.$mapo.$snack.open({
312
+ message: error.response?.data?.detail || this.$t("mapo.genericError"),
313
+ color: "error",
314
+ })
310
315
  }).finally(() => {
311
316
  this.newFile = null;
312
317
  this.sameUrl = false;
@@ -322,7 +327,13 @@ export default {
322
327
  attrs: { color: "red", text: true },
323
328
  },
324
329
  })
325
- .then((res) => res && this.deleteMedia(this.media));
330
+ .then((res) => res && this.deleteMedia(this.media)
331
+ .catch(error =>
332
+ this.$mapo.$snack.open({
333
+ message: error.response?.data?.detail || this.$t("mapo.genericError"),
334
+ color: "error",
335
+ })
336
+ ).finally(() => {this.getRoot(); this.closeEditor()}));
326
337
  },
327
338
  },
328
339
  };
@@ -8,7 +8,7 @@
8
8
  >
9
9
  <MediaPreview
10
10
  v-for="media in selection"
11
- :key="media.file"
11
+ :key="media.id"
12
12
  @click.native.stop="select(media)"
13
13
  :media="media"
14
14
  icon-size="20px"
@@ -53,7 +53,7 @@
53
53
  <div ref="masonry" class="media-gallery--masonry" v-if="medias.length">
54
54
  <div
55
55
  v-for="media in medias"
56
- :key="media.file"
56
+ :key="media.id"
57
57
  class="media-gallery--card"
58
58
  >
59
59
  <v-btn
@@ -179,7 +179,7 @@ $wcol: calc(100% / 6 - 12px);
179
179
  .media-gallery--masonry{
180
180
  grid-template-columns: $wcol $wcol;
181
181
  }
182
- }
182
+ }
183
183
 
184
184
  .media-gallery--empty{
185
185
  height: 100%;
@@ -224,7 +224,7 @@ $wcol: calc(100% / 6 - 12px);
224
224
  color: white;
225
225
  }
226
226
  }
227
-
227
+
228
228
  }
229
229
  .media-gallery--selected {
230
230
  &::after {
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <v-img
2
+ <v-img
3
3
  :src="(isImage && media.file) || null"
4
4
  :lazy-src="(isImage && media.thumbnail) || null"
5
5
  aspect-ratio="1"
@@ -10,6 +10,8 @@
10
10
  }"
11
11
  v-bind="$attrs"
12
12
  v-on="videoListeners"
13
+ @mouseover.native="hover = true"
14
+ @mouseleave.native="hover = false; showInfo = false"
13
15
  :title="media.title || media.name"
14
16
  >
15
17
  <template v-slot:placeholder>
@@ -67,10 +69,54 @@
67
69
  </div>
68
70
  </v-row>
69
71
  </template>
72
+ <template>
73
+ <div @click.stop="showInfo=true" class="file-info text-right" :class="{hover, showInfo}">
74
+ <span class="file-name text-truncate">{{ (filename && name) || undefined }}</span>
75
+ <span class="file-details text-caption " :class="{showInfo}">
76
+ <span>{{ dateCreated }}</span><br>
77
+ <span>{{ fileSize }}</span>
78
+ </span>
79
+ </div>
80
+ </template>
70
81
  </v-img>
71
82
  </template>
72
83
 
73
84
  <style lang="scss">
85
+ .file-info{
86
+ position: absolute;
87
+ bottom: 0;
88
+ padding: 0.2em 1em;
89
+ background: #1f1f1f;
90
+ opacity: 0;
91
+ transition: opacity .5s;
92
+ width: 100%;
93
+ display: block;
94
+ max-height: 80%;
95
+ overflow: auto ;
96
+ &.hover{
97
+ opacity: .7;
98
+ }
99
+ &.showInfo{
100
+ opacity: .9;
101
+ padding: 0.2em 0.5em;
102
+ .file-name{
103
+ font-weight: bold;
104
+ }
105
+ }
106
+ }
107
+ .file-name{
108
+ display: block;
109
+ }
110
+ .file-details{
111
+ max-height: 0;
112
+ overflow: hidden;
113
+ transition: all .5s;
114
+ display: block;
115
+ &.showInfo{
116
+ max-height: 500px;
117
+ overflow: auto;
118
+ }
119
+ }
74
120
  .v-image.media-controls {
75
121
  .v-image__placeholder {
76
122
  z-index: 0;
@@ -93,6 +139,7 @@
93
139
  </style>
94
140
 
95
141
  <script>
142
+ import { humanFileSize } from "@mapomodule/utils/helpers/formatters";
96
143
 
97
144
  const extensions = {
98
145
  image: ["png", "jpg", "jpeg", "avif", "webp"],
@@ -105,6 +152,8 @@ export default {
105
152
  return {
106
153
  playing: false,
107
154
  playPromise: null,
155
+ hover: false,
156
+ showInfo: false
108
157
  };
109
158
  },
110
159
  props: {
@@ -151,7 +200,7 @@ export default {
151
200
  if (this.media?.mime_type)
152
201
  return this.media.mime_type.startsWith("video/");
153
202
  return extensions.video.includes(this.media?.file?.split(".").pop()?.toLowerCase())
154
- },
203
+ },
155
204
  isAudio() {
156
205
  if (this.media?.mime_type)
157
206
  return this.media.mime_type.startsWith("audio/");
@@ -166,6 +215,12 @@ export default {
166
215
  };
167
216
  }
168
217
  },
218
+ fileSize() {
219
+ return this.media && humanFileSize(this.media.size);
220
+ },
221
+ dateCreated() {
222
+ return this.media && new Date(this.media.created).toLocaleDateString();
223
+ },
169
224
  },
170
225
  methods: {
171
226
  handleTouch(event){
@@ -12,43 +12,30 @@
12
12
  </div>
13
13
  </template>
14
14
  <template v-slot:list-item.content.after="{ item }">
15
- <v-chip dense v-if="isTooLarge(item)" color="error">{{$t("mapo.mediaUploader.tooLarge")}}</v-chip>
15
+ <v-chip dense v-if="isTooLarge(item)" color="error">{{ $t("mapo.mediaUploader.tooLarge") }}</v-chip>
16
16
  </template>
17
17
  <template v-slot:editContent="{ editedItem }">
18
18
  <v-container>
19
19
  <v-row>
20
20
  <v-col cols="12">
21
- <v-select
22
- v-model="editedItem.folder"
23
- :items="folderOptions"
24
- :label="$t('mapo.folder')"
25
- ></v-select>
21
+ <v-select v-model="editedItem.folder" :items="folderOptions" :label="$t('mapo.folder')"></v-select>
26
22
  </v-col>
27
23
  <v-col cols="12">
28
- <v-text-field
29
- v-model="editedItem.title"
30
- :label="$t('titleTag')"
31
- ></v-text-field>
24
+ <v-text-field v-model="editedItem.title" :label="$t('titleTag')"></v-text-field>
32
25
  </v-col>
33
26
  <v-col cols="12">
34
- <v-text-field
35
- v-model="editedItem.description"
36
- :label="$t('mapo.description')"
37
- ></v-text-field>
27
+ <v-text-field v-model="editedItem.description" :label="$t('mapo.description')"></v-text-field>
38
28
  </v-col>
39
29
  <v-col cols="12">
40
- <v-text-field
41
- v-model="editedItem.alt_text"
42
- :label="$t('mapo.altTag')"
43
- ></v-text-field>
30
+ <v-text-field v-model="editedItem.alt_text" :label="$t('mapo.altTag')"></v-text-field>
44
31
  </v-col>
45
32
  </v-row>
46
33
  </v-container>
47
34
  </template>
48
35
  </drop-area>
49
36
  <div v-if="mediaList.length" class="mt-3">
50
- <p class="text-right mr-3 mb-2">{{ completed }}</p>
51
- <v-progress-linear :value="progress"></v-progress-linear>
37
+ <p class="text-right mr-3 mb-2">{{ bufferProgress >= 100 ? $t('mapo.mediaUploader.optimizingFiles') : (progress > 0 ? $t('mapo.mediaUploader.uploadingFiles'):'')}} {{ completed }}</p>
38
+ <v-progress-linear :stream="stream" :indeterminate="progress == 100" :value="progress" :buffer-value="bufferProgress"></v-progress-linear>
52
39
  </div>
53
40
  </v-container>
54
41
  </template>
@@ -69,8 +56,9 @@ export default {
69
56
  name: "MediaUploader",
70
57
  data() {
71
58
  return {
72
- count: 0,
73
- progress: 0,
59
+ buffer : 0,
60
+ stream: false,
61
+ responses: [],
74
62
  mediaList: [],
75
63
  _mediaFileCrud: null
76
64
  };
@@ -84,7 +72,7 @@ export default {
84
72
  return this._mediaFileCrud;
85
73
  },
86
74
  completed() {
87
- return `${this.count}/${this.mediaList.length}`;
75
+ return `${this.responses.length}/${this.mediaList.length}`;
88
76
  },
89
77
  folderOptions() {
90
78
  return [
@@ -97,11 +85,17 @@ export default {
97
85
  value: folder.id
98
86
  }))
99
87
  ];
88
+ },
89
+ progress(){
90
+ return this.responses.length/this.mediaList.length * 100;
91
+ },
92
+ bufferProgress(){
93
+ return this.buffer/this.mediaList.length * 100;
100
94
  }
101
95
  },
102
96
  methods: {
103
- isTooLarge({ info }){
104
- const {type} = info;
97
+ isTooLarge({ info }) {
98
+ const { type } = info;
105
99
  switch (type.split("/")[0]) {
106
100
  case "image":
107
101
  return info.rawsize > MAX_IMAGE_SIZE;
@@ -122,53 +116,47 @@ export default {
122
116
  (this.parentFolder && this.parentFolder.id) ||
123
117
  null;
124
118
  });
125
- this.count = 0;
126
- this.progress = 0;
119
+ this.responses = [];
120
+ this.buffer = 0;
121
+ this.stream = false
127
122
  },
128
- updateAll() {
129
- return Promise.all(
130
- this.mediaList.map(media =>
131
- this.uploadMedia(
132
- Object.assign(
133
- { file: media.blob },
134
- {
135
- title: media.info.title,
136
- alt_text: media.info.alt_text,
137
- description: media.info.description,
138
- folder: media.info.folder
139
- }
140
- )
123
+ async updateAll() {
124
+ this.stream = true
125
+ for (const media of this.mediaList) {
126
+ await this.uploadMedia(
127
+ Object.assign(
128
+ { file: media.blob },
129
+ {
130
+ title: media.info.title,
131
+ alt_text: media.info.alt_text,
132
+ description: media.info.description,
133
+ folder: media.info.folder
134
+ }
141
135
  )
142
- )
143
- ).then(response => {
144
- if (this.mediaList && this.mediaList.length) {
136
+ ).then(r => this.responses.push(r)).catch(error => {
145
137
  this.$mapo.$snack.open({
146
- message: this.$t("mapo.mediaUploader.success", {numberFiles: response.length || this.mediaList.length})
147
- });
148
- this.$emit("Upload", (response.length && response) || this.mediaList);
149
- this.$refs.closeButton.$el.click();
150
- }
151
- });
138
+ message: error.response?.data?.detail || this.$t("mapo.genericError"),
139
+ color: "error",
140
+ })
141
+ })
142
+ }
143
+ if (this.mediaList && this.mediaList.length) {
144
+ this.$mapo.$snack.open({
145
+ message: this.$t("mapo.mediaUploader.success", { numberFiles: this.responses.length || this.mediaList.length })
146
+ });
147
+ this.$emit("Upload", (this.responses.length && this.responses) || this.mediaList);
148
+ this.$refs.closeButton.$el.click();
149
+ }
152
150
  },
153
- uploadMedia(media) {
154
- const index = this.mediaList.findIndex(el => el.blob === media.file);
151
+ async uploadMedia(media) {
155
152
  const payload = this.$mapo.$api.multipart(media, ["file"]);
156
153
  const conf = {
157
154
  headers: { "Content-Type": "multipart/form-data" },
158
155
  onUploadProgress: function(event) {
159
- this.mediaList[index].progress = Math.ceil(
160
- (event.loaded / event.total) * 100
161
- );
162
- this.progress =
163
- this.mediaList.reduce((acc, media) => acc + media.progress, 0) /
164
- this.mediaList.length;
165
- this.count = this.mediaList.reduce(
166
- (acc, media) => acc + (media.progress === 100),
167
- 0
168
- );
156
+ this.buffer = Math.ceil(this.buffer) + (event.loaded / event.total)
169
157
  }.bind(this)
170
158
  };
171
- return this.mediaFileCrud.create(payload, conf);
159
+ return await this.mediaFileCrud.create(payload, conf);
172
160
  }
173
161
  }
174
162
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.45",
3
+ "version": "1.0.0-alpha.47",
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": "14f60bfff75726de0f9353e601de37dc27143efd"
18
+ "gitHead": "40ab5eb6bb2508c9e3a0e8f7cef850cf809a472e"
19
19
  }
@@ -162,6 +162,6 @@ export default {
162
162
  fileInfo: "File info succesfully updated",
163
163
  },
164
164
  // MediaManager/MediaUploader.vue
165
- mediaUploader: { success: "{numberFiles} files succesfully uploaded", tooLarge: "Warning! Optimize before upload!" },
165
+ mediaUploader: { optimizingFiles: "Optimizing files..", uploadingFiles: "Uploading files..", success: "{numberFiles} files succesfully uploaded", tooLarge: "Warning! Optimize before upload!" },
166
166
  },
167
167
  };
@@ -165,6 +165,6 @@ export default {
165
165
  fileInfo: "File info succesfully updated",
166
166
  },
167
167
  // MediaManager/MediaUploader.vue
168
- mediaUploader: { success: "{numberFiles} file caricati", tooLarge: "Attenzione! Ottimizza prima di caricare!" },
168
+ mediaUploader: { optimizingFiles: "Ottimizzazione dei file..", uploadingFiles: "Upload dei file..", success: "{numberFiles} file caricati", tooLarge: "Attenzione! Ottimizza prima di caricare!" },
169
169
  },
170
170
  };