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

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,161 @@
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
+ <div class="media-gallery--loading" v-if="loading">
14
+ <v-progress-circular
15
+ size="60"
16
+ color="primary"
17
+ indeterminate
18
+ ></v-progress-circular>
19
+ </div>
20
+ <div class="media-gallery--empty" v-else-if="!medias.length">
21
+ <v-icon size="60"> mdi-image-off-outline </v-icon>
28
22
  <p>{{ $t("mapo.mediaGallery.noMediaFound") }}</p>
29
- </v-row>
30
- <v-row v-if="medias.length">
31
- <v-col
23
+ </div>
24
+ <div class="media-gallery--masonry" v-else>
25
+ <div
32
26
  v-for="media in medias"
33
27
  :key="media.file"
34
- class="img-container"
35
- cols="6"
36
- sm="3"
37
- md="2"
28
+ class="media-gallery--card"
38
29
  >
39
30
  <v-btn
40
- @click.stop="editMedia(media)"
31
+ @click.stop="openEditor(media)"
41
32
  icon
42
33
  small
43
34
  :ripple="false"
44
35
  color="white"
45
- class="img-container__btn"
46
- :class="{'d-none': select == 'none'}"
36
+ class="media-gallery--card-btn"
37
+ :class="{'d-none': selectMode == 'none'}"
47
38
  >
48
39
  <v-icon>mdi-circle-edit-outline</v-icon>
49
40
  </v-btn>
50
41
  <MediaPreview
51
42
  class="elevation-4 cursor-pointer"
52
43
  :media="media"
53
- :selected="isSelected(media)"
54
- @click.native="selectMedia(media)"
44
+ :class="{ 'media-gallery--selected': isSelected(media)}"
45
+ @click.native="select(media)"
55
46
  filename
56
47
  video-preview
57
48
  />
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>
49
+ </div>
50
+ </div>
51
+ <v-pagination
52
+ class="mt-2"
53
+ v-if="pages > 1"
54
+ v-model="currentPage"
55
+ :length="pages"
56
+ ></v-pagination>
69
57
  </div>
70
58
  </template>
71
59
 
72
- <style lang="scss" scoped>
60
+ <style lang="scss">
73
61
  .cursor-pointer{
74
62
  cursor: pointer;
75
63
  }
76
- .img-container {
64
+ .media-gallery--card {
77
65
  display: flex;
78
66
  position: relative;
79
- &__btn {
67
+ &-btn {
80
68
  position: absolute;
81
69
  z-index: 1;
82
- right: 12px;
83
- bottom: 12px;
70
+ right: 0;
71
+ bottom: 0;
84
72
  background: #1e1e1ea1;
85
73
  border-radius: 50% 0 0;
86
74
  }
87
75
  }
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%;
76
+
77
+ .media-gallery--wrapper{
78
+ height: 100%;
79
+ display: flex;
80
+ flex-direction: column;
81
+ justify-content: space-between;
82
+ }
83
+
84
+ $wcol: calc(100% / 6 - 12px);
85
+
86
+
87
+ .media-gallery--masonry {
88
+ width: 100%;
89
+ padding: 10px;
90
+ overflow-y: auto;
91
+ overflow-x: hidden;
92
+ display: grid;
93
+ grid-template-columns: $wcol $wcol $wcol $wcol $wcol $wcol;
94
+ grid-template-rows: auto auto auto ;
95
+ column-gap: 12px;
96
+ row-gap: 12px;
97
+ }
98
+
99
+ @media (max-width: 960px) {
100
+ $wcol: calc(100% / 3 - 12px);
101
+ .media-gallery--masonry{
102
+ grid-template-columns: $wcol $wcol $wcol;
96
103
  }
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;
104
+ }
105
+
106
+ @media (max-width: 600px) {
107
+ $wcol: calc(100% / 2 - 6px);
108
+ .media-gallery--masonry{
109
+ grid-template-columns: $wcol $wcol;
110
+ }
111
+ }
112
+
113
+ .media-gallery--empty{
114
+ height: 100%;
115
+ display: flex;
116
+ flex-direction: column;
117
+ align-content: center;
118
+ justify-content: center;
119
+ text-align: center;
120
+ }
121
+ .media-gallery--loading{
122
+ height: 100%;
123
+ display: flex;
124
+ flex-direction: column;
125
+ align-items: center;
126
+ justify-content: center;
127
+ text-align: center;
128
+ }
129
+
130
+ .media-gallery--selection {
131
+ min-height: 60px;
132
+ display: flex;
133
+ overflow-x: auto;
134
+ overflow-y: hidden;
135
+
136
+ margin-bottom: 10px;
137
+ &-item{
138
+ width: 50px;
139
+ height: 50px;
140
+ flex-grow: 0;
141
+ margin: 5px;
142
+ cursor: pointer;
143
+ &:hover::before {
144
+ content: "\F0156";
145
+ font: normal normal normal 30px/1 "Material Design Icons";
146
+ width: 100%;
147
+ display: flex;
148
+ justify-content: center;
149
+ align-items: center;
150
+ height: 100%;
151
+ background: #00000082;
152
+ border: solid #ffffff6e 2px;
153
+ color: white;
154
+ }
108
155
  }
156
+
109
157
  }
110
- .selected {
158
+ .media-gallery--selected {
111
159
  &::after {
112
160
  content: "";
113
161
  background: #56be5057;
@@ -119,88 +167,36 @@
119
167
  </style>
120
168
 
121
169
  <script>
170
+ import { mapGetters, mapActions } from "vuex"
171
+
122
172
  export default {
123
173
  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
174
  computed: {
175
+ ...mapGetters("mapo/media", ["page", "pages", "medias", "selection", "selectMode", "loading"]),
161
176
  currentPage: {
162
177
  get() {
163
178
  return this.page;
164
179
  },
165
180
  set(val) {
166
- this.$emit("pageChange", val);
181
+ this.getRoot({ page: val })
167
182
  },
168
183
  },
169
184
  },
170
185
  methods: {
186
+ ...mapActions("mapo/media", ["getRoot", "openEditor", "select"]),
171
187
  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;
188
+ switch (this.selectMode) {
181
189
  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;
190
+ return this.selection.findIndex((m) => m.id === media.id) !== -1;
191
+ case "single":
192
+ return this.selection?.id === media.id;
190
193
  default:
191
- this.editMedia(media);
192
- break;
194
+ return false;
193
195
  }
194
196
  },
195
- editMedia(media) {
196
- this.$emit("editMedia", media);
197
- },
198
197
  fileName(media) {
199
198
  return media && media.file && media.file.split("/").pop();
200
199
  },
201
200
  },
202
- mounted() {
203
- if (this.selection !== undefined) this.internalSelection = this.selection;
204
- },
205
201
  };
206
202
  </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,27 @@ 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() {
143
+ this.$store.commit("mapo/media/SET_MIME_TYPE", this.mime || null);
241
144
  await this.getRoot();
242
145
  },
146
+ destroyed(){
147
+ this.reset();
148
+ }
243
149
  };
244
150
  </script>