@mapomodule/uikit 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +749 -0
  2. package/components/ConfirmDialog.vue +12 -16
  3. package/components/Detail/Detail.vue +406 -272
  4. package/components/Detail/DetailLangSwitch.vue +7 -2
  5. package/components/DropArea.vue +63 -56
  6. package/components/Form/Form.vue +218 -0
  7. package/components/Form/FormField.vue +213 -0
  8. package/components/Form/FormGroup.vue +146 -0
  9. package/components/Form/FormTabs.vue +188 -0
  10. package/components/Form/defaults.js +91 -0
  11. package/components/Form/fields/ColorField.vue +79 -0
  12. package/components/{fields → Form/fields}/DateField.vue +20 -11
  13. package/components/Form/fields/EnhancedMediaField.vue +224 -0
  14. package/components/Form/fields/FileField.vue +125 -0
  15. package/components/Form/fields/FksField.vue +88 -0
  16. package/components/Form/fields/MediaField.vue +159 -0
  17. package/components/Form/fields/MediaM2mField.vue +149 -0
  18. package/components/Form/fields/Repeater.vue +593 -0
  19. package/components/Form/fields/SeoPreview.vue +89 -0
  20. package/components/Form/fields/wygEditor/defaults.js +25 -0
  21. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/events.js +0 -0
  22. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/mapomedia.plugin.js +7 -6
  23. package/components/{fields/TinyMce → Form/fields/wygEditor}/utils/script.injector.js +0 -0
  24. package/components/Form/fields/wygEditor/wygEditor.vue +285 -0
  25. package/components/LangSwitcher.vue +44 -0
  26. package/components/List/List.vue +119 -42
  27. package/components/List/ListActions.vue +60 -21
  28. package/components/List/ListFilters.vue +166 -114
  29. package/components/List/ListHead.vue +30 -12
  30. package/components/List/ListQuickEdit.vue +130 -61
  31. package/components/List/ListTable.vue +292 -80
  32. package/components/Login.vue +17 -7
  33. package/components/LogoutButton.vue +43 -28
  34. package/components/MediaManager/MediaBreadcrumbs.vue +45 -0
  35. package/components/MediaManager/MediaEditor.vue +330 -122
  36. package/components/MediaManager/MediaFolders.vue +169 -116
  37. package/components/MediaManager/MediaGallery.vue +151 -146
  38. package/components/MediaManager/MediaManager.vue +117 -159
  39. package/components/MediaManager/MediaManagerDialog.vue +36 -31
  40. package/components/MediaManager/MediaPreview.vue +203 -0
  41. package/components/MediaManager/MediaUploader.vue +55 -43
  42. package/components/SnackBar.vue +5 -7
  43. package/components/ThemeToggle.vue +13 -0
  44. package/components/layout/Sidebar/Sidebar.vue +61 -30
  45. package/components/layout/Sidebar/SidebarList.vue +19 -15
  46. package/components/layout/Sidebar/SidebarListItem.vue +122 -38
  47. package/components/layout/Sidebar/SidebarProfile.vue +42 -0
  48. package/components/layout/Sidebar/SidebarTitle.vue +45 -0
  49. package/components/layout/Topbar/Topbar.vue +11 -42
  50. package/components/layout/routebuilder.js +3 -3
  51. package/defaults/i18n.js +37 -0
  52. package/defaults/vuetify.js +34 -0
  53. package/layouts/default.vue +33 -18
  54. package/layouts/empty.vue +10 -0
  55. package/module.js +7 -5
  56. package/package.json +6 -4
  57. package/pages/index.vue +19 -18
  58. package/static/{favicon.ico → mapo/favicon.ico} +0 -0
  59. package/static/mapo/tinymce-skins/mapo-dark/content.inline.min.css +7 -0
  60. package/static/mapo/tinymce-skins/mapo-dark/content.min.css +7 -0
  61. package/static/mapo/tinymce-skins/mapo-dark/content.mobile.min.css +7 -0
  62. package/static/mapo/tinymce-skins/mapo-dark/skin.min.css +7 -0
  63. package/static/mapo/tinymce-skins/mapo-dark/skin.mobile.min.css +7 -0
  64. package/static/mapo/tinymce-skins/mapo-light/content.inline.min.css +7 -0
  65. package/static/mapo/tinymce-skins/mapo-light/content.min.css +7 -0
  66. package/static/mapo/tinymce-skins/mapo-light/content.mobile.min.css +7 -0
  67. package/static/mapo/tinymce-skins/mapo-light/skin.min.css +7 -0
  68. package/static/mapo/tinymce-skins/mapo-light/skin.mobile.min.css +7 -0
  69. package/translations/en-US.js +135 -0
  70. package/translations/it-IT.js +137 -0
  71. package/components/Detail/DetailField.vue +0 -129
  72. package/components/Detail/defaults.js +0 -50
  73. package/components/fields/M2mField.vue +0 -95
  74. package/components/fields/MediaField.vue +0 -195
  75. package/components/fields/MediaM2mField.vue +0 -238
  76. package/components/fields/TinyMce/TinyMce.vue +0 -177
  77. package/components/fields/TinyMce/defaults.js +0 -55
  78. package/components/layout/Sidebar/SidebarFooter.vue +0 -75
  79. package/defaults.js +0 -29
  80. package/layouts/error.vue +0 -45
@@ -1,39 +1,64 @@
1
1
  <template>
2
2
  <div>
3
3
  <slot v-bind="{ on, attrs }" name="activator"></slot>
4
- <v-dialog v-model="dialog" width="600">
4
+ <v-dialog v-model="dialog" v-bind="dialogProps">
5
5
  <v-card v-bind="$attrs">
6
- <v-card-title>
7
- <slot name="title" v-bind="{ formTitle, editedItem }">
8
- <span class="headline">{{ formTitle }}</span>
6
+ <v-card-title class="pa-0 mb-3">
7
+ <div style="max-width: calc(100% - 40px)">
8
+ <slot name="lang" v-bind="slotBindings">
9
+ <!-- [`DetailLangSwitch`](/components/detail/DetailLangSwitch/) -->
10
+ <DetailLangSwitch
11
+ v-if="langs.length > 1"
12
+ v-model="currentLang"
13
+ :langs="langs"
14
+ :errors="errors"
15
+ /></slot>
16
+ </div>
17
+ <v-spacer></v-spacer>
18
+ <slot name="title" v-bind="slotBindings">
19
+ <v-hover v-slot="{ hover }">
20
+ <v-icon @click="hover && close()" class="mr-4" :class="{'mt-4': !langs.length}">{{
21
+ hover ? "mdi-close" : isNew ? "mdi-plus-circle-outline" : "mdi-pencil-outline"
22
+ }}</v-icon>
23
+ </v-hover>
9
24
  </slot>
10
25
  </v-card-title>
11
- <v-card-text>
26
+ <v-card-text class="pa-0 px-2">
12
27
  <v-container>
13
- <v-form v-if="editedItem" ref="form">
14
- <slot name="body" v-bind="{ editedItem }">
15
- <v-row>
16
- <v-col
17
- v-for="field in computedFields"
18
- :key="field.value"
19
- cols="12"
20
- :md="editFields.length > 1 ? 6 : 12"
21
- >
22
- <v-text-field
23
- v-bind="field.attrs"
24
- v-model="editedItem[field.value]"
25
- ></v-text-field>
26
- </v-col>
27
- </v-row>
28
+ <v-form v-if="model" ref="form">
29
+ <!-- Use this to add content on top of body. -->
30
+ <slot name="body.top" v-bind="slotBindings"></slot>
31
+
32
+ <slot name="body" v-bind="slotBindings">
33
+ <Form
34
+ v-model="model"
35
+ :currentLang="currentLang"
36
+ :languages="langs"
37
+ :errors="errors"
38
+ :fields="editFields"
39
+ :modeSlotBindings="slotBindings"
40
+ >
41
+ <template v-for="(_, slot) in $slots" :slot="slot">
42
+ <!-- @vuese-ignore -->
43
+ <slot :name="slot"></slot>
44
+ </template>
45
+ <template v-for="(_, slot) in $scopedSlots" v-slot:[slot]="props">
46
+ <!-- @vuese-ignore -->
47
+ <slot :name="slot" v-bind="props" />
48
+ </template>
49
+ </Form>
28
50
  </slot>
51
+ <!-- Use this to add content under the main body. -->
52
+ <slot name="body.bottom" v-bind="slotBindings"></slot>
29
53
  </v-form>
30
54
  </v-container>
31
55
  </v-card-text>
32
56
  <v-card-actions>
33
- <slot name="actions" v-bind="{ close, save }">
57
+ <v-messages v-if="nonFieldErrors.length" v-model="nonFieldErrors" color="error"></v-messages>
58
+ <slot name="actions" v-bind="slotBindings">
34
59
  <v-spacer></v-spacer>
35
- <v-btn text @click="close()"> Cancel </v-btn>
36
- <v-btn text @click="save"> Save </v-btn>
60
+ <v-btn text @click="close()">{{ $t("mapo.cancel") }}</v-btn>
61
+ <v-btn text @click="save">{{ $t("mapo.save") }}</v-btn>
37
62
  </slot>
38
63
  </v-card-actions>
39
64
  </v-card>
@@ -41,7 +66,7 @@
41
66
  </div>
42
67
  </template>
43
68
  <script>
44
- import { filterObj } from "@mapomodule/utils/helpers/objHelpers";
69
+ import { diffObjs, deepClone } from "@mapomodule/utils/helpers/objHelpers";
45
70
  /**
46
71
  * This components renders a dialog that let the user quick edit (or add) an element of the list.
47
72
  * The dialog provides several fields that will edit a payload that will be sent to the server. <br>
@@ -53,9 +78,11 @@ export default {
53
78
  return {
54
79
  dialog: false,
55
80
  attrs: { ...this.$attrs },
56
- itemRef: null,
57
- editedItem: null,
58
- newItem: false,
81
+ modelBkp: null,
82
+ model: null,
83
+ isNew: false,
84
+ currentLang: null,
85
+ errors: null,
59
86
  on: {
60
87
  click: (event) => {
61
88
  event.preventDefault();
@@ -70,14 +97,16 @@ export default {
70
97
  value: {
71
98
  type: Boolean,
72
99
  },
73
- editTitle: {
74
- type: String,
75
- default: "",
76
- },
100
+ // The main configuration that determines the arrangement of the fields in the detail layout.
77
101
  editFields: {
78
102
  type: Array,
79
103
  default: () => [],
80
104
  },
105
+ // A list of languages into which the payload needs to be translated.
106
+ languages: {
107
+ type: Array,
108
+ default() { return this.$mapo.$options?.content?.languages || []; },
109
+ },
81
110
  lookup: {
82
111
  type: String,
83
112
  default: "id",
@@ -86,6 +115,12 @@ export default {
86
115
  type: Object,
87
116
  required: true,
88
117
  },
118
+ dialogProps: {
119
+ type: Object,
120
+ required: false,
121
+ default: () => ({ width: 600, scrollable: true })
122
+ },
123
+ offline: Boolean,
89
124
  },
90
125
  watch: {
91
126
  value(val) {
@@ -100,35 +135,34 @@ export default {
100
135
  },
101
136
  },
102
137
  computed: {
103
- formTitle() {
104
- return `${this.newItem ? "Quick add" : "Quick edit"} ${this.editTitle}`;
105
- },
106
- computedFields() {
107
- return this.editFields.map((field, i) => {
108
- if (typeof field == "object") {
109
- return {
110
- ...field,
111
- attrs: {
112
- ...field.attrs,
113
- label: (field.attrs || {}).label || field.value.toUpperCase(),
114
- },
115
- };
116
- } else if (typeof field == "string") {
117
- return { attrs: { label: field.toUpperCase() }, value: field };
118
- } else {
119
- throw `editFields must me string or objects, error at index ${i}!`;
120
- }
121
- });
138
+ langs() {
139
+ return this.model?.lang_info?.site_languages.map((l) => l.id) || this.languages || [];
140
+ },
141
+ loading() {
142
+ return this.isNew ? false : !Object.keys(this.model || {}).length;
122
143
  },
123
- fieldNames() {
124
- return this.computedFields.map(({ value }) => value);
144
+ nonFieldErrors(){
145
+ return this.errors?.non_field_errors || []
146
+ },
147
+ slotBindings() {
148
+ return {
149
+ model: this.model,
150
+ currentLang: this.currentLang,
151
+ crud: this.crud,
152
+ isNew: this.isNew,
153
+ langs: this.langs,
154
+ loading: this.loading,
155
+ form: this.$refs.form,
156
+ save: this.save,
157
+ close: this.close,
158
+ };
125
159
  },
126
160
  },
127
161
  methods: {
128
- open(item) {
129
- this.newItem = !item;
130
- this.itemRef = item;
131
- this.editedItem = filterObj(item, this.fieldNames);
162
+ async open(item) {
163
+ this.isNew = !item;
164
+ this.modelBkp = await this.fetchItem(item);
165
+ this.model = deepClone(this.modelBkp);
132
166
  this.dialog = true;
133
167
  this.$refs.form?.resetValidation();
134
168
  return new Promise((resolve, reject) => {
@@ -138,21 +172,56 @@ export default {
138
172
  },
139
173
  async save() {
140
174
  if (this.$refs.form?.validate()) {
141
- return await (this.newItem ? this.apiCreate() : this.apiEdit());
175
+ return await (this.isNew ? this.apiCreate() : this.apiEdit());
142
176
  }
143
177
  },
144
178
  close(res) {
179
+ this.errors = null;
180
+ this.currentLang = null;
145
181
  this.$refs.form?.resetValidation();
146
182
  this.resolve && this.resolve(res);
147
183
  this.dialog = false;
148
184
  },
185
+ async fetchItem(item) {
186
+ if (!this.offline && item && item[this.lookup]) {
187
+ return await this.crud.detail(item[this.lookup]);
188
+ } else {
189
+ return item;
190
+ }
191
+ },
149
192
  apiEdit() {
150
- return this.crud
151
- .partialUpdate(this.itemRef[this.lookup], this.editedItem)
152
- .then((res) => this.close(res));
193
+ if (!this.offline) {
194
+ return this.crud
195
+ .partialUpdate(
196
+ this.modelBkp[this.lookup],
197
+ // diffObjs(this.modelBkp, this.model) disabled since it creates some errors in translations
198
+ this.model
199
+ )
200
+ .then((res) => this.close(res))
201
+ .catch(this.handleError);
202
+ } else {
203
+ this.close(this.model);
204
+ }
153
205
  },
154
206
  apiCreate() {
155
- return this.crud.create(this.editedItem).then((res) => this.close(res));
207
+ if (!this.offline) {
208
+ return this.crud
209
+ .create(this.model)
210
+ .then((res) => this.close(res))
211
+ .catch(this.handleError);
212
+ } else {
213
+ return this.close(this.model);
214
+ }
215
+ },
216
+ handleError(error) {
217
+ const badRequest = error.response.status == 400;
218
+ this.errors = (badRequest && error.response.data) || null;
219
+ this.$mapo.$snack.open({
220
+ message: badRequest
221
+ ? this.$t("mapo.listQuickEdit.badInput")
222
+ : error.response?.data?.detail || this.$t("mapo.genericError"),
223
+ color: "error",
224
+ });
156
225
  },
157
226
  },
158
227
  };