aloha-vue 1.0.26 → 1.0.29

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/docs/src/main.js CHANGED
@@ -2,7 +2,7 @@ import App from "./App/App.vue";
2
2
  import { createApp } from "vue";
3
3
  import store from "./store/index";
4
4
  import router from "./router/index";
5
- import i18nPlugin from "../../src/plugins/i18nPlugin";
5
+ import AI18nPlugin from "../../src/plugins/AI18nPlugin";
6
6
  // import alohaPlugin from "../src/plugins/alohaPlugin";
7
7
  import AIconPlugin from "../../src/plugins/AIconPlugin";
8
8
 
@@ -23,7 +23,7 @@ const TRANSLATIONS = {
23
23
  hr: { ...hrGlobal, ...hr },
24
24
  ru: { ...ruGlobal, ...ru },
25
25
  };
26
- APP.use(i18nPlugin, TRANSLATIONS, "de");
26
+ APP.use(AI18nPlugin, TRANSLATIONS, "de");
27
27
  APP.use(AIconPlugin, {
28
28
  Plus2: `<svg
29
29
  xmlns="http://www.w3.org/2000/svg"
@@ -9,6 +9,9 @@ div
9
9
  :table-actions="tableActions"
10
10
  preview="right"
11
11
  :is-quick-search="true"
12
+ :is-action-column-visible="true"
13
+ :is-columns-dnd="true"
14
+ :is-pagination="true"
12
15
  v-model:modelQuickSearch="modelQuickSearch"
13
16
  @change-columns-ordering="changeColumnsOrdering"
14
17
  )
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "aloha-vue",
3
3
  "description": "Project aloha",
4
- "version": "1.0.26",
4
+ "version": "1.0.29",
5
5
  "author": "Ilia Brykin",
6
6
  "dependencies": {
7
7
  "@popperjs/core": "2.11.5",
8
- "aloha-css": "1.0.29",
8
+ "aloha-css": "1.0.35",
9
+ "axios": "^0.27.2",
9
10
  "lodash-es": "^4.17.21",
10
11
  "vue": "3.2.37"
11
12
  }
@@ -0,0 +1,24 @@
1
+ import {
2
+ toRef,
3
+ } from "vue";
4
+
5
+ import APageTabTitleAPI from "../compositionAPI/APageTabTitleAPI";
6
+
7
+ // @vue/component
8
+ export default {
9
+ name: "APageTabTitle",
10
+ props: {
11
+ title: {
12
+ type: String,
13
+ required: true,
14
+ },
15
+ },
16
+ setup(props) {
17
+ APageTabTitleAPI({
18
+ title: toRef(props, "title"),
19
+ });
20
+ },
21
+ render() {
22
+ return "";
23
+ },
24
+ };
@@ -141,6 +141,11 @@ export default {
141
141
  required: false,
142
142
  default: () => [],
143
143
  },
144
+ isPagination: {
145
+ type: Boolean,
146
+ required: false,
147
+ default: true,
148
+ },
144
149
  isPaginationOutside: {
145
150
  type: Boolean,
146
151
  required: false,
@@ -174,6 +179,16 @@ export default {
174
179
  required: false,
175
180
  default: "",
176
181
  },
182
+ isActionColumnVisible: {
183
+ type: Boolean,
184
+ required: false,
185
+ default: true,
186
+ },
187
+ isColumnsDnd: {
188
+ type: Boolean,
189
+ required: false,
190
+ default: true,
191
+ },
177
192
  },
178
193
  emits: [
179
194
  "update:modelColumnsOrder",
@@ -195,6 +210,8 @@ export default {
195
210
  columns: computed(() => this.columns),
196
211
  columnActionsWidthLocal: computed(() => this.columnActionsWidth),
197
212
  columnWidthDefault: computed(() => this.columnWidthDefault),
213
+ isActionColumnVisible: computed(() => this.isActionColumnVisible),
214
+ isColumnsDnd: computed(() => this.isColumnsDnd),
198
215
  isLoadingOptions: computed(() => this.isLoadingOptions),
199
216
  isLoadingTable: computed(() => this.isLoadingTable),
200
217
  rowActions: computed(() => this.rowActions),
@@ -305,7 +322,7 @@ export default {
305
322
  },
306
323
 
307
324
  dataPaginated() {
308
- if (this.limit && !this.isPaginationOutside) {
325
+ if (this.limit && !this.isPaginationOutside && this.isPagination) {
309
326
  const DATA_SORTED = cloneDeep(this.dataSorted);
310
327
  const INDEX_START = this.offset;
311
328
  const INDEX_END = INDEX_START + this.limit;
@@ -498,7 +515,7 @@ export default {
498
515
  !this.hasRows && h("div", {
499
516
  class: "a_table__empty_text",
500
517
  }, "Keine Einträge vorhanden."),
501
- h("div", {
518
+ this.isPagination && h("div", {
502
519
  class: "a_pagination__parent"
503
520
  }, [
504
521
  h(ATableCountProPage, {
@@ -20,6 +20,7 @@ export default {
20
20
  },
21
21
  },
22
22
  inject: [
23
+ "isActionColumnVisible",
23
24
  "changeColumnsOrdering",
24
25
  "columnsOrdered",
25
26
  ],
@@ -72,7 +73,7 @@ export default {
72
73
  onDragendParent: this.dragend,
73
74
  });
74
75
  }),
75
- h(ATableHeaderThAction),
76
+ this.isActionColumnVisible && h(ATableHeaderThAction),
76
77
  ]),
77
78
  ]);
78
79
  },
@@ -36,6 +36,7 @@ export default {
36
36
  ],
37
37
  inject: [
38
38
  "changeModelSort",
39
+ "isColumnsDnd",
39
40
  "isLoadingOptions",
40
41
  "isLoadingTable",
41
42
  "modelColumnsVisibleMapping",
@@ -77,8 +78,9 @@ export default {
77
78
  classForTh() {
78
79
  return [
79
80
  "a_table__th a_table__cell",
81
+ this.column.class,
80
82
  {
81
- a_table__th_draggable: !this.isLocked && !this.isLoadingOptions,
83
+ a_table__th_draggable: !this.isLocked && !this.isLoadingOptions && this.isColumnsDnd,
82
84
  a_table__th_sorting: this.isSorting,
83
85
  }
84
86
  ];
@@ -45,6 +45,7 @@ export default {
45
45
  "changeColumnsOrdering",
46
46
  "changeModelColumnsVisible",
47
47
  "columnsOrdered",
48
+ "isColumnsDnd",
48
49
  "isLoadingOptions",
49
50
  "isLoadingTable",
50
51
  "modelColumnsVisibleLocal",
@@ -118,7 +119,7 @@ export default {
118
119
  },
119
120
 
120
121
  arrowButtons() {
121
- if (!this.isLocked) {
122
+ if (!this.isLocked && this.isColumnsDnd) {
122
123
  return [
123
124
  this.isButtonArrowUpVisible && h("button", {
124
125
  id: this.idButtonArrowUp,
@@ -246,7 +247,7 @@ export default {
246
247
  }),
247
248
  ...this.arrowButtons,
248
249
  ]),
249
- !this.isLocked && h(AIcon, {
250
+ (!this.isLocked && this.isColumnsDnd) && h(AIcon, {
250
251
  icon: "Dnd",
251
252
  class: "a_table__th__dropdown_item__icon_dnd"
252
253
  }),
@@ -64,9 +64,13 @@ export default {
64
64
  attributesForTd() {
65
65
  const ATTRIBUTES = {
66
66
  role: "cell",
67
- class: ["a_table__td a_table__cell", {
68
- a_table__cell_click: this.hasPreview,
69
- }],
67
+ class: [
68
+ "a_table__td a_table__cell",
69
+ this.column.class,
70
+ {
71
+ a_table__cell_click: this.hasPreview,
72
+ },
73
+ ],
70
74
  style: this.columnsStyles,
71
75
  };
72
76
  if (this.hasPreview) {
@@ -24,6 +24,7 @@ export default {
24
24
  inject: [
25
25
  "columnsOrdered",
26
26
  "hasPreview",
27
+ "isActionColumnVisible",
27
28
  "previewRightRowIndex",
28
29
  "previewRightRowIndexLast",
29
30
  "tableId",
@@ -71,7 +72,7 @@ export default {
71
72
  rowIndex: this.rowIndex,
72
73
  }, this.$slots);
73
74
  }),
74
- h(ATableTdAction, {
75
+ this.isActionColumnVisible && h(ATableTdAction, {
75
76
  row: this.row,
76
77
  rowIndex: this.rowIndex,
77
78
  }, this.$slots),
@@ -10,6 +10,7 @@ export default function DragAndDropChildAPI(props, { emit }, { classOver = "" })
10
10
  const columnIndex = toRef(props, "columnIndex");
11
11
 
12
12
  const isLoadingOptions = inject("isLoadingOptions");
13
+ const isColumnsDnd = inject("isColumnsDnd");
13
14
 
14
15
  const root = ref(null);
15
16
 
@@ -60,7 +61,7 @@ export default function DragAndDropChildAPI(props, { emit }, { classOver = "" })
60
61
  const ATTRIBUTES = {
61
62
  ref: "root",
62
63
  };
63
- if (!isLocked.value) {
64
+ if (!isLocked.value && isColumnsDnd.value) {
64
65
  ATTRIBUTES.draggable = !isLoadingOptions.value;
65
66
  ATTRIBUTES.onDragstart = dragstart;
66
67
  ATTRIBUTES.onDragend = dragend;
@@ -0,0 +1,363 @@
1
+ import {
2
+ ref,
3
+ } from "vue";
4
+
5
+ import axios from "axios";
6
+ import {
7
+ forEach,
8
+ isArray,
9
+ isFunction,
10
+ isNil,
11
+ isPlainObject,
12
+ keyBy,
13
+ } from "lodash-es";
14
+
15
+
16
+ const BASE_URL = ref("/api/");
17
+ const API = ref(axios.create());
18
+ const API_SAVED = ref({});
19
+ const ERROR_CALLBACKS = ref({});
20
+
21
+ export function create({ axiosCreateOptions = {} }) {
22
+ API.value = axios.create(axiosCreateOptions);
23
+ }
24
+
25
+ export function setBaseUrl({ baseUrl = "" }) {
26
+ BASE_URL.value = baseUrl;
27
+ }
28
+
29
+ export function setErrorCallbacks({ errorCallbacks = {} }) {
30
+ ERROR_CALLBACKS.value = errorCallbacks;
31
+ }
32
+
33
+ export default function AHttpAPI() {
34
+ const checkErrorStatus = ({ error, showError, client, resolve, reject }) => {
35
+ if (!error) {
36
+ return true;
37
+ }
38
+ const ERROR_CALLBACK = () => {
39
+ const CALLBACK = ERROR_CALLBACKS[error.status];
40
+ if (isFunction(CALLBACK)) {
41
+ return CALLBACK({ error, showError, client, resolve, reject });
42
+ }
43
+ };
44
+
45
+ ERROR_CALLBACK();
46
+ // Let the promise handle the error
47
+ return true;
48
+ };
49
+
50
+ const callHttpRequestAndCheckSavedApi = ({
51
+ methodHttp,
52
+ url,
53
+ urlParams,
54
+ data,
55
+ headerParams,
56
+ responseType = "json",
57
+ apiSaveId,
58
+ keyId,
59
+ fullResponse,
60
+ showError = false,
61
+ expectedList
62
+ }) => {
63
+ let apiSavedData = undefined;
64
+ if (apiSaveId) {
65
+ apiSavedData = API_SAVED.value[apiSaveId];
66
+ if (apiSavedData) {
67
+ if (apiSavedData.loading) {
68
+ return apiSavedData.promise;
69
+ }
70
+ }
71
+ }
72
+
73
+ const PROMISE = new Promise((resolve, reject) => {
74
+ if (apiSavedData) {
75
+ if (!apiSavedData.loading) {
76
+ if (keyId) {
77
+ if (apiSavedData.keyData) {
78
+ return resolve(apiSavedData.keyData);
79
+ }
80
+ const KEY_DATA = setKeyData({ data: apiSavedData.data, keyId });
81
+ API_SAVED.value[apiSaveId].keyData = KEY_DATA;
82
+ return resolve(KEY_DATA);
83
+ }
84
+ return resolve(apiSavedData.data);
85
+ }
86
+ }
87
+ const URL_NEW = setUrlWithParams({ url, params: urlParams });
88
+ let url_full = `${ BASE_URL.value }${ URL_NEW }`;
89
+ url_full = url_full.replace(/\/\//g, "/");
90
+ API.value({
91
+ method: methodHttp,
92
+ url: url_full,
93
+ data,
94
+ headers: headerParams,
95
+ responseType,
96
+ }).then(
97
+ response => {
98
+ if (fullResponse) {
99
+ return resolve(response);
100
+ }
101
+ const DATA = checkedExpectedList({ expectedList, response });
102
+ const KEY_DATA = setKeyData({ data: DATA, keyId });
103
+ if (apiSaveId) {
104
+ API_SAVED.value[apiSaveId].data = DATA;
105
+ API_SAVED.value[apiSaveId].keyData = KEY_DATA;
106
+ API_SAVED.value[apiSaveId].loading = false;
107
+ }
108
+ if (keyId) {
109
+ return resolve(KEY_DATA);
110
+ }
111
+ return resolve(DATA);
112
+ },
113
+ error => {
114
+ if (checkErrorStatus({ error: error.response, showError, client: API, reject, resolve })) {
115
+ return reject(error.response);
116
+ }
117
+ }
118
+ );
119
+ });
120
+
121
+ if (!apiSavedData) {
122
+ API_SAVED.value[apiSaveId] = API_SAVED.value[apiSaveId] || {};
123
+ API_SAVED.value[apiSaveId].loading = true;
124
+ API_SAVED.value[apiSaveId].promise = PROMISE;
125
+ }
126
+
127
+ return PROMISE;
128
+ };
129
+
130
+ function getHttp({
131
+ url,
132
+ data,
133
+ urlParams = {},
134
+ headerParams,
135
+ responseType,
136
+ apiSaveId,
137
+ keyId,
138
+ fullResponse,
139
+ showError,
140
+ }) {
141
+ return callHttpRequestAndCheckSavedApi({
142
+ methodHttp: "get",
143
+ url,
144
+ urlParams,
145
+ data,
146
+ headerParams,
147
+ responseType,
148
+ apiSaveId,
149
+ keyId,
150
+ fullResponse,
151
+ showError,
152
+ });
153
+ }
154
+
155
+ function getListHttp({
156
+ url,
157
+ data,
158
+ urlParams = {},
159
+ headerParams,
160
+ responseType,
161
+ apiSaveId,
162
+ keyId,
163
+ fullResponse,
164
+ showError,
165
+ }) {
166
+ return callHttpRequestAndCheckSavedApi({
167
+ methodHttp: "get",
168
+ url,
169
+ urlParams,
170
+ data,
171
+ headerParams,
172
+ responseType,
173
+ apiSaveId,
174
+ keyId,
175
+ fullResponse,
176
+ showError,
177
+ expectedList: true,
178
+ });
179
+ }
180
+
181
+ function getOptionsHttp({
182
+ url,
183
+ data,
184
+ urlParams = {},
185
+ headerParams,
186
+ responseType,
187
+ keyId,
188
+ fullResponse,
189
+ showError,
190
+ }) {
191
+ return callHttpRequestAndCheckSavedApi({
192
+ methodHttp: "options",
193
+ url,
194
+ urlParams,
195
+ data,
196
+ headerParams,
197
+ responseType,
198
+ keyId,
199
+ fullResponse,
200
+ showError,
201
+ });
202
+ }
203
+
204
+ function postHttp({
205
+ url,
206
+ data,
207
+ urlParams = {},
208
+ headerParams,
209
+ responseType,
210
+ fullResponse,
211
+ showError,
212
+ }) {
213
+ return callHttpRequestAndCheckSavedApi({
214
+ methodHttp: "post",
215
+ url,
216
+ urlParams,
217
+ data,
218
+ headerParams,
219
+ responseType,
220
+ fullResponse,
221
+ showError,
222
+ });
223
+ }
224
+
225
+ function putHttp({
226
+ url,
227
+ data,
228
+ urlParams = {},
229
+ headerParams,
230
+ responseType,
231
+ fullResponse,
232
+ showError,
233
+ }) {
234
+ return callHttpRequestAndCheckSavedApi({
235
+ methodHttp: "put",
236
+ url,
237
+ urlParams,
238
+ data,
239
+ headerParams,
240
+ responseType,
241
+ fullResponse,
242
+ showError,
243
+ });
244
+ }
245
+
246
+ function patchHttp({
247
+ url,
248
+ data,
249
+ urlParams = {},
250
+ headerParams,
251
+ responseType,
252
+ fullResponse,
253
+ showError,
254
+ }) {
255
+ return callHttpRequestAndCheckSavedApi({
256
+ methodHttp: "patch",
257
+ url,
258
+ urlParams,
259
+ data,
260
+ headerParams,
261
+ responseType,
262
+ fullResponse,
263
+ showError,
264
+ });
265
+ }
266
+
267
+ function deleteHttp({
268
+ url,
269
+ data,
270
+ urlParams = {},
271
+ headerParams,
272
+ responseType,
273
+ fullResponse,
274
+ showError,
275
+ }) {
276
+ return callHttpRequestAndCheckSavedApi({
277
+ methodHttp: "delete",
278
+ url,
279
+ urlParams,
280
+ data,
281
+ headerParams,
282
+ responseType,
283
+ fullResponse,
284
+ showError,
285
+ });
286
+ }
287
+
288
+ return {
289
+ deleteHttp,
290
+ getHttp,
291
+ getListHttp,
292
+ getOptionsHttp,
293
+ patchHttp,
294
+ postHttp,
295
+ putHttp,
296
+ };
297
+ }
298
+
299
+ export function setUrlWithParams({ url, params }) {
300
+ const URL = url || "";
301
+ let urlParams = "";
302
+ forEach(params, (value, key) => {
303
+ if (isArray(value)) {
304
+ urlParams = setUrlForArray({ id: key, array: value, url: urlParams });
305
+ } else if (isPlainObject(value)) {
306
+ forEach(value, (v, k) => {
307
+ if (v) {
308
+ if (urlParams) {
309
+ urlParams += "&";
310
+ }
311
+ urlParams += `${ k }=${ v }`;
312
+ }
313
+ });
314
+ } else if (!isNil(value)) {
315
+ if (urlParams) {
316
+ urlParams += "&";
317
+ }
318
+ urlParams += `${ key }=${ value }`;
319
+ }
320
+ });
321
+ const prefix = urlParams && URL ? URL.indexOf("?") === -1 ? "?" : "&" : "";
322
+
323
+ return `${ URL }${ prefix }${ urlParams }`;
324
+ }
325
+
326
+ export function setUrlForArray({ array, url, id }) {
327
+ if (!array.length) {
328
+ return url;
329
+ }
330
+ let URL = url || "";
331
+ if (id === "fields") {
332
+ if (URL) {
333
+ URL += "&";
334
+ }
335
+ URL += `${ id }=`;
336
+ URL += array.join(",");
337
+ } else {
338
+ forEach(array, v => {
339
+ if (URL) {
340
+ URL += "&";
341
+ }
342
+ URL += `${ id }=${ v }`;
343
+ });
344
+ }
345
+ return URL;
346
+ }
347
+
348
+ function setKeyData({ data, keyId }) {
349
+ if (!keyId) {
350
+ return undefined;
351
+ }
352
+ return keyBy(data, keyId);
353
+ }
354
+
355
+ function checkedExpectedList({ expectedList, response }) {
356
+ if (expectedList) {
357
+ if (isArray(response.data)) {
358
+ return response.data;
359
+ }
360
+ return response.data.results ? response.data.results : [];
361
+ }
362
+ return response.data;
363
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ ref, watch,
3
+ } from "vue";
4
+
5
+ const BASE_TITLE = ref("");
6
+
7
+ export default function APageTabTitleAPI({
8
+ title = ref(""),
9
+ }) {
10
+ const setPageTabTitle = () => {
11
+ let pageTitle = BASE_TITLE.value;
12
+ if (title.value) {
13
+ pageTitle = `${ title.value } - ${ pageTitle }`;
14
+ }
15
+ document.title = pageTitle;
16
+ };
17
+
18
+ setPageTabTitle();
19
+
20
+ watch(title, () => {
21
+ setPageTabTitle();
22
+ });
23
+ }
24
+
25
+ export function setBaseTitle({ baseTitle = "" }) {
26
+ BASE_TITLE.value = baseTitle;
27
+ }
@@ -0,0 +1,12 @@
1
+ import {
2
+ create,
3
+ setBaseUrl, setErrorCallbacks,
4
+ } from "../compositionAPI/AHttpAPI";
5
+
6
+ export default {
7
+ install: (app, { axiosCreateOptions = {}, baseUrl = "/api/", errorCallbacks = {} } = {}) => {
8
+ create({ axiosCreateOptions });
9
+ setBaseUrl({ baseUrl });
10
+ setErrorCallbacks({ errorCallbacks });
11
+ },
12
+ };
File without changes
@@ -0,0 +1,9 @@
1
+ import {
2
+ setBaseTitle,
3
+ } from "../compositionAPI/APageTabTitleAPI";
4
+
5
+ export default {
6
+ install: (app, baseTitle = "") => {
7
+ setBaseTitle({ baseTitle });
8
+ },
9
+ };
@@ -171,6 +171,7 @@
171
171
  .a_table__top_panel__label {
172
172
  font-weight: bolder;
173
173
  display: inline-block;
174
+ font-size: 2rem;
174
175
  }
175
176
  .a_table__top_panel__label__count {
176
177
  padding-left: var(--a_table_between_actions_margin);