@mapomodule/uikit 1.0.0-alpha.33 → 1.0.0-alpha.34

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,113 +1,147 @@
1
1
  <template>
2
- <div class="pa-4">
3
- <v-row v-if="internalSelection.length && select == 'multi'" class="selection mb-4 grey darken-2">
4
- <v-col
5
- v-for="media in internalSelection"
6
- :key="media.file"
7
- class="d-flex"
8
- cols="2"
9
- sm="1"
10
- md="1"
11
- @click.stop="selectMedia(media)"
12
- >
2
+ <div class="media-gallery--wrapper">
3
+ <div v-if="selection && selection.length && selectMode == 'multi'" class="media-gallery--selection grey darken-2">
13
4
  <MediaPreview
5
+ v-for="media in selection"
6
+ :key="media.file"
7
+ @click.native.stop="select(media)"
14
8
  :media="media"
15
9
  icon-size="20px"
16
- class="elevation-4 cursor-pointer selection__item"
10
+ class="elevation-4 media-gallery--selection-item"
17
11
  />
18
- </v-col>
19
- </v-row>
20
- <v-row
21
- v-if="!medias.length"
22
- class="d-flex flex-column"
23
- dense
24
- align="center"
25
- justify="center"
26
- >
27
- <v-icon size="60"> mdi-alert-circle-outline </v-icon>
12
+ </div>
13
+
14
+ <div class="media-gallery--empty" v-if="!medias.length">
15
+ <v-icon size="60"> mdi-image-off-outline </v-icon>
28
16
  <p>{{ $t("mapo.mediaGallery.noMediaFound") }}</p>
29
- </v-row>
30
- <v-row v-if="medias.length">
31
- <v-col
17
+ </div>
18
+ <div class="media-gallery--masonry" v-if="medias.length">
19
+ <div
32
20
  v-for="media in medias"
33
21
  :key="media.file"
34
- class="img-container"
35
- cols="6"
36
- sm="3"
37
- md="2"
22
+ class="media-gallery--card"
38
23
  >
39
24
  <v-btn
40
- @click.stop="editMedia(media)"
25
+ @click.stop="openEditor(media)"
41
26
  icon
42
27
  small
43
28
  :ripple="false"
44
29
  color="white"
45
- class="img-container__btn"
46
- :class="{'d-none': select == 'none'}"
30
+ class="media-gallery--card-btn"
31
+ :class="{'d-none': selectMode == 'none'}"
47
32
  >
48
33
  <v-icon>mdi-circle-edit-outline</v-icon>
49
34
  </v-btn>
50
35
  <MediaPreview
51
36
  class="elevation-4 cursor-pointer"
52
37
  :media="media"
53
- :selected="isSelected(media)"
54
- @click.native="selectMedia(media)"
38
+ :class="{ 'media-gallery--selected': isSelected(media)}"
39
+ @click.native="select(media)"
55
40
  filename
56
41
  video-preview
57
42
  />
58
- </v-col>
59
- </v-row>
60
- <v-row>
61
- <v-col cols="12">
62
- <v-pagination
63
- v-if="pages > 1"
64
- v-model="currentPage"
65
- :length="pages"
66
- ></v-pagination>
67
- </v-col>
68
- </v-row>
43
+ </div>
44
+ </div>
45
+ <v-pagination
46
+ class="mt-2"
47
+ v-if="pages > 1"
48
+ v-model="currentPage"
49
+ :length="pages"
50
+ ></v-pagination>
69
51
  </div>
70
52
  </template>
71
53
 
72
- <style lang="scss" scoped>
54
+ <style lang="scss">
73
55
  .cursor-pointer{
74
56
  cursor: pointer;
75
57
  }
76
- .img-container {
58
+ .media-gallery--card {
77
59
  display: flex;
78
60
  position: relative;
79
- &__btn {
61
+ &-btn {
80
62
  position: absolute;
81
63
  z-index: 1;
82
- right: 12px;
83
- bottom: 12px;
64
+ right: 0;
65
+ bottom: 0;
84
66
  background: #1e1e1ea1;
85
67
  border-radius: 50% 0 0;
86
68
  }
87
69
  }
88
- .selection {
89
- margin: -16px;
90
- &__confirm {
91
- margin: auto 0 auto auto;
92
- display: flex;
93
- justify-content: center;
94
- align-content: center;
95
- height: 100%;
70
+
71
+ .media-gallery--wrapper{
72
+ height: 100%;
73
+ display: flex;
74
+ flex-direction: column;
75
+ justify-content: space-between;
76
+ }
77
+
78
+ $wcol: calc(100% / 6 - 12px);
79
+
80
+
81
+ .media-gallery--masonry {
82
+ width: 100%;
83
+ padding: 10px;
84
+ overflow-y: auto;
85
+ overflow-x: hidden;
86
+ display: grid;
87
+ grid-template-columns: $wcol $wcol $wcol $wcol $wcol $wcol;
88
+ grid-template-rows: auto auto auto ;
89
+ column-gap: 12px;
90
+ row-gap: 12px;
91
+ }
92
+
93
+ @media (max-width: 960px) {
94
+ $wcol: calc(100% / 3 - 12px);
95
+ .media-gallery--masonry{
96
+ grid-template-columns: $wcol $wcol $wcol;
96
97
  }
97
- &__item:hover::before {
98
- content: "\F0156";
99
- font: normal normal normal 30px/1 "Material Design Icons";
100
- width: 100%;
101
- display: flex;
102
- justify-content: center;
103
- align-items: center;
104
- height: 100%;
105
- background: #00000082;
106
- border: solid #ffffff6e 2px;
107
- color: white;
98
+ }
99
+
100
+ @media (max-width: 600px) {
101
+ $wcol: calc(100% / 2 - 6px);
102
+ .media-gallery--masonry{
103
+ grid-template-columns: $wcol $wcol;
108
104
  }
105
+ }
106
+
107
+ .media-gallery--empty{
108
+ height: 100%;
109
+ display: flex;
110
+ flex-direction: column;
111
+ align-content: center;
112
+ justify-content: center;
113
+ text-align: center;
109
114
  }
110
- .selected {
115
+
116
+ .media-gallery--selection {
117
+ min-height: 60px;
118
+ display: flex;
119
+ overflow-x: auto;
120
+ overflow-y: hidden;
121
+
122
+ margin-bottom: 10px;
123
+ &-item{
124
+ width: 50px;
125
+ height: 50px;
126
+ flex-grow: 0;
127
+ margin: 5px;
128
+ cursor: pointer;
129
+ &:hover::before {
130
+ content: "\F0156";
131
+ font: normal normal normal 30px/1 "Material Design Icons";
132
+ width: 100%;
133
+ display: flex;
134
+ justify-content: center;
135
+ align-items: center;
136
+ height: 100%;
137
+ background: #00000082;
138
+ border: solid #ffffff6e 2px;
139
+ color: white;
140
+ }
141
+ }
142
+
143
+ }
144
+ .media-gallery--selected {
111
145
  &::after {
112
146
  content: "";
113
147
  background: #56be5057;
@@ -119,88 +153,36 @@
119
153
  </style>
120
154
 
121
155
  <script>
156
+ import { mapGetters, mapActions } from "vuex"
157
+
122
158
  export default {
123
159
  name: "MediaGallery",
124
- data() {
125
- return {
126
- internalSelection: [],
127
- };
128
- },
129
- props: {
130
- medias: {
131
- type: Array,
132
- required: true,
133
- default: () => ({}),
134
- },
135
- page: {
136
- type: Number,
137
- default: 1,
138
- },
139
- pages: {
140
- type: Number,
141
- default: 1,
142
- },
143
- select: {
144
- defaut: "none",
145
- type: String,
146
- validator(value) {
147
- return ["none", "single", "multi"].indexOf(value) !== -1;
148
- },
149
- },
150
- selection: {
151
- type: Array,
152
- required: false
153
- },
154
- },
155
- watch: {
156
- selection(value) {
157
- if (value !== undefined) this.internalSelection = value;
158
- },
159
- },
160
160
  computed: {
161
+ ...mapGetters("mapo/media", ["page", "pages", "medias", "selection", "selectMode"]),
161
162
  currentPage: {
162
163
  get() {
163
164
  return this.page;
164
165
  },
165
166
  set(val) {
166
- this.$emit("pageChange", val);
167
+ this.getRoot({ page: val })
167
168
  },
168
169
  },
169
170
  },
170
171
  methods: {
172
+ ...mapActions("mapo/media", ["getRoot", "openEditor", "select"]),
171
173
  isSelected(media) {
172
- return this.internalSelection.findIndex((m) => m.id === media.id) !== -1;
173
- },
174
- selectMedia(media) {
175
- switch (this.select) {
176
- case "single":
177
- this.$emit("selectionChange", media);
178
- this.internalSelection = [media];
179
- this.$emit("update:selection", this.internalSelection);
180
- break;
174
+ switch (this.selectMode) {
181
175
  case "multi":
182
- const index = this.internalSelection.findIndex(m => m.id === media.id);
183
- index == -1
184
- ? this.internalSelection.push(media)
185
- : this.internalSelection.splice(index, 1);
186
- this.internalSelection = this.internalSelection.slice();
187
- this.$emit("selectionChange", this.internalSelection);
188
- this.$emit("update:selection", this.internalSelection);
189
- break;
176
+ return this.selection.findIndex((m) => m.id === media.id) !== -1;
177
+ case "single":
178
+ return this.selection?.id === media.id;
190
179
  default:
191
- this.editMedia(media);
192
- break;
180
+ return false;
193
181
  }
194
182
  },
195
- editMedia(media) {
196
- this.$emit("editMedia", media);
197
- },
198
183
  fileName(media) {
199
184
  return media && media.file && media.file.split("/").pop();
200
185
  },
201
186
  },
202
- mounted() {
203
- if (this.selection !== undefined) this.internalSelection = this.selection;
204
- },
205
187
  };
206
188
  </script>
@@ -1,16 +1,19 @@
1
1
  <template>
2
- <v-card elevation="0">
2
+ <div class="media-manager--wrapper">
3
+ <MediaFolders v-show="!editMedia" v-if="!noFolders" />
4
+ <v-card elevation="0" class="media-manager--v-card" :class="{ transparent: !fillBackgroud, editing:editMedia }">
3
5
  <v-card-title class="d-flex flex-wrap pa-0">
4
- <div>
5
- <v-tabs v-model="tab" right background-color="transparent">
6
+ <div class="d-flex flex-grow-1">
7
+ <v-tabs v-model="tab" background-color="transparent" :show-arrows="false">
6
8
  <v-tab>{{ $t("mapo.mediaManager.gallery") }}</v-tab>
7
9
  <v-tab>{{ $t("mapo.mediaManager.uploader") }}</v-tab>
8
10
  </v-tabs>
11
+ <v-spacer></v-spacer>
12
+ <v-btn v-show="$vuetify.breakpoint.xs" class="ma-2 ml-auto" @click="getRoot" icon>
13
+ <v-icon>mdi-update</v-icon>
14
+ </v-btn>
9
15
  </div>
10
- <v-btn v-show="$vuetify.breakpoint.xs" class="ma-2 ml-auto" @click="getRoot" icon>
11
- <v-icon>mdi-update</v-icon>
12
- </v-btn>
13
- <div class="d-flex ma-auto mr-0" :style="$vuetify.breakpoint.xs ? 'width: 100%' : ''">
16
+ <div class="d-flex ma-auto mr-0 pb-2 pb-sm-0" :style="$vuetify.breakpoint.xs ? 'width: 100%' : ''">
14
17
  <v-text-field
15
18
  v-show="!editMedia && tab == 0"
16
19
  v-model="searchValue"
@@ -28,43 +31,20 @@
28
31
  :loading="loadingSearch"
29
32
  class="mx-2 mt-2"
30
33
  ></v-text-field>
31
- <v-btn v-show="!$vuetify.breakpoint.xs" class="ma-2" @click="getRoot" icon>
34
+ <v-btn v-show="!$vuetify.breakpoint.xs" class="ma-2 ml-0" @click="getRoot" icon>
32
35
  <v-icon>mdi-update</v-icon>
33
36
  </v-btn>
34
37
  </div>
35
- <MediaFolders
36
- v-show="!editMedia"
37
- v-if="!noFolders"
38
- v-bind="{ folders, parentFolders, loading }"
39
- @updateFolder="updateOrCreateFolder($event)"
40
- @deleteFolder="deleteFolder($event)"
41
- @goToFolder="
42
- parentFolder = $event;
43
- getRoot();
44
- "
45
- />
46
38
  </v-card-title>
47
- <v-card-text class="pa-0">
48
- <v-tabs-items v-model="tab" class="transparent">
49
- <v-tab-item>
50
- <MediaGallery
51
- v-show="!editMedia"
52
- v-bind="{ select, page, pages, medias }"
53
- :selection="$attrs.selection"
54
- @update:selection="$emit('update:selection', $event)"
55
- @selectionChange="selectionChange($event)"
56
- @pageChange="getRoot({ page: $event })"
57
- @editMedia="openEditor($event)"
58
- />
59
- <MediaEditor
60
- v-model="editMedia"
61
- @deleteMedia="deleteMedia($event)"
62
- @updateMedia="updateMedia($event)"
63
- />
39
+ <MediaBreadcrumbs/>
40
+ <v-card-text class="media-manager--card-text pa-0">
41
+ <v-tabs-items touchless v-model="tab" class="transparent fill-height">
42
+ <v-tab-item class="fill-height">
43
+ <MediaGallery v-show="!editMedia"/>
44
+ <MediaEditor/>
64
45
  </v-tab-item>
65
- <v-tab-item>
46
+ <v-tab-item class="fill-height">
66
47
  <MediaUploader
67
- v-bind="{ folders, parentFolder }"
68
48
  @Upload="
69
49
  tab = 0;
70
50
  getRoot({ page: 1 });
@@ -73,42 +53,69 @@
73
53
  </v-tab-item>
74
54
  </v-tabs-items>
75
55
  </v-card-text>
76
- <v-card-actions>
56
+ <v-card-actions class="pa-0">
77
57
  <!-- Slot to provide custom button actions inside the media manager -->
78
58
  <slot name="actions"></slot>
79
59
  </v-card-actions>
80
60
  </v-card>
61
+ </div>
62
+
81
63
  </template>
64
+ <style lang="scss">
65
+ .v-card.media-manager--v-card{
66
+ display: flex;
67
+ flex-direction: column;
68
+ flex-grow: 1;
69
+ border-radius: 0px;
70
+ max-width: calc(100% - 56px);
71
+ &.editing{
72
+ max-width: 100%;
73
+ }
74
+ @media (max-width: 600px){
75
+ max-width: 100%;
76
+ }
77
+ }
78
+ .v-slide-group__next--disabled, .v-slide-group__prev--disabled{
79
+ display: none !important;
80
+ }
81
+ .media-manager--card-text{
82
+ max-height: calc(100vh - 100px);
83
+ min-height: 400px;
84
+ flex-grow: 1;
85
+ @media (max-width: 600px){
86
+ max-height: calc(100vh - 195px);
87
+ }
88
+ }
89
+ .v-dialog .media-manager--card-text{
90
+ max-height: calc(100vh - 300px);
91
+ }
92
+ .media-manager--wrapper{
93
+ display: flex;
94
+ height: inherit;
95
+ flex-direction: column-reverse;
96
+ position: relative;
97
+ justify-content: flex-end;
98
+ @media (min-width: 600px){
99
+ flex-direction: row;
100
+ }
101
+ }
102
+ </style>
82
103
 
83
104
  <script>
84
105
  import { debounce } from "@mapomodule/utils/helpers/debounce";
106
+ import { mapGetters, mapActions } from "vuex"
85
107
 
86
- const initialData = () => ({
87
- _mediaFolderCrud: null,
88
- _mediaFileCrud: null,
89
- medias: [],
90
- folders: [],
91
- parentFolders: [],
92
- page: 1,
93
- pages: 1,
94
- tab: 0,
95
- editMedia: null,
96
- loading: false,
97
- searchValue: "",
98
- loadingSearch: false,
99
- });
100
108
 
101
109
  export default {
102
110
  name: "MediaManager",
103
- data: initialData,
111
+ data(){
112
+ return {
113
+ tab: 0,
114
+ searchValue: "",
115
+ loadingSearch: false,
116
+ }
117
+ },
104
118
  props: {
105
- select: {
106
- type: String,
107
- default: "none",
108
- validator(val) {
109
- return ["none", "single", "multi"].indexOf(val) !== -1;
110
- },
111
- },
112
119
  noFolders: {
113
120
  type: Boolean,
114
121
  default: false,
@@ -117,128 +124,26 @@ export default {
117
124
  type: String,
118
125
  required: false,
119
126
  },
127
+ fillBackgroud: Boolean
120
128
  },
121
129
  watch: {
122
130
  '$i18n.locale': async function(locale) {
123
131
  if (this.editMedia)
124
- this.editMedia = await this.detailMedia(this.editMedia.id);
132
+ this.openEditor(this.editMedia);
125
133
  }
126
134
  },
127
- computed: {
128
- mediaFolderCrud() {
129
- this._mediaFolderCrud =
130
- this._mediaFolderCrud || this.$mapo.$api.crud("api/media-folders");
131
- return this._mediaFolderCrud;
132
- },
133
- mediaFileCrud() {
134
- this._mediaFileCrud = this._mediaFileCrud || this.$mapo.$api.crud("api/media");
135
- return this._mediaFileCrud;
136
- },
137
- parentFolder: {
138
- get() {
139
- return (
140
- (this.parentFolders.length &&
141
- this.parentFolders[this.parentFolders.length - 1]) ||
142
- null
143
- );
144
- },
145
- set(val) {
146
- if (!val || !val.path) {
147
- this.parentFolders = [];
148
- } else {
149
- const index = this.parentFolders.findIndex((f) => f.path == val.path);
150
- if (index == -1) {
151
- this.parentFolders.push(val);
152
- } else {
153
- this.parentFolders.splice(index + 1, this.parentFolders.length - (index + 1));
154
- }
155
- }
156
- },
157
- },
158
- },
135
+ computed: mapGetters("mapo/media", ["parentFolder", "medias", "folders", "parentFolders", "page", "pages", "loading", "editMedia" ]),
159
136
  methods: {
160
- async getRoot(context) {
161
- this.loading = true;
162
- const { page, folder } = context || {};
163
- const { id } = folder || this.parentFolder || {};
164
- let response;
165
- this.page = page || this.page;
166
- const params = {
167
- page: this.page,
168
- search: this.searchValue || undefined,
169
- fltr: this.mime ? `mime_type=${this.mime}` : undefined,
170
- };
171
- try {
172
- response = id
173
- ? await this.mediaFolderCrud.detail(id, { params })
174
- : await this.mediaFolderCrud.list({ params });
175
- } catch (error) {
176
- console.error({ code: error.response.status, response: error.response.data });
177
- }
178
-
179
- this.processResponse(response);
180
- this.loading = false;
181
- this.editMedia = null;
182
- },
183
-
184
- updateOrCreateFolder(folder) {
185
- return this.mediaFolderCrud.updateOrCreate(folder).then(() => this.getRoot());
186
- },
187
-
188
- deleteFolder(folder) {
189
- return this.mediaFolderCrud.delete(folder.id).then(() => this.getRoot());
190
- },
191
-
192
- deleteMedia(media) {
193
- return this.mediaFileCrud.delete(media.id).then(() => {
194
- (this.editMedia = null), this.getRoot();
195
- });
196
- },
197
-
198
- detailMedia(media_id) {
199
- return this.mediaFileCrud.detail(media_id, {
200
- params: { language_code: this.$i18n.locale },
201
- });
202
- },
203
-
204
- async updateMedia(media) {
205
- const files = ["file", "objectURL", "thumbnail"];
206
- const payload = this.$mapo.$api.multipart(media, files);
207
- const conf = { headers: { "Content-Type": "multipart/form-data" } };
208
- const res = await this.mediaFileCrud.partialUpdate(media.id, payload, conf);
209
- if (media.file) {
210
- this.medias = [];
211
- await this.getRoot();
212
- }
213
- this.editMedia = res;
214
- this.$mapo.$snack.open({
215
- message: this.$t("mapo.mediaManager.fileInfo"),
216
- });
217
- return res;
218
- },
219
- processResponse(resp) {
220
- this.medias = resp?.media?.items || [];
221
- this.folders = resp?.folders || [];
222
- this.parentFolder = resp?.parent_folder;
223
- this.page = resp?.media?.paginator?.page;
224
- this.pages = resp?.media?.paginator?.pages;
225
- },
226
- selectionChange(event) {
227
- this.$emit("selectionChange", event);
228
- },
229
- async openEditor(event) {
230
- this.editMedia = await this.detailMedia(event.id);
231
- },
137
+ ...mapActions("mapo/media", ["getRoot", "openEditor", "updateMedia", "updateOrCreateFolder", "deleteFolder", "deleteMedia", "reset"]),
232
138
  search: debounce(function () {
233
- this.getRoot().then(() => (this.loadingSearch = false));
139
+ this.getRoot({search: this.searchValue}).then(() => (this.loadingSearch = false));
234
140
  }, 500),
235
- reset() {
236
- Object.assign(this.$data, initialData());
237
- this.getRoot();
238
- },
239
141
  },
240
142
  async fetch() {
241
143
  await this.getRoot();
242
144
  },
145
+ destroyed(){
146
+ this.reset();
147
+ }
243
148
  };
244
149
  </script>