flameresttable 1.0.103 → 1.0.104

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flameresttable",
3
- "version": "1.0.103",
3
+ "version": "1.0.104",
4
4
  "main": "./src/plugin.ts",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,37 +12,37 @@
12
12
  "dev": "vite"
13
13
  },
14
14
  "dependencies": {
15
- "@vuepic/vue-datepicker": "^7.2.1",
16
- "flamerest": "^1.0.94",
15
+ "@vuepic/vue-datepicker": "^7.4.1",
16
+ "flamerest": "^1.0.109",
17
17
  "lodash-es": "^4.17.21",
18
- "pinia": "^2.1.7",
18
+ "pinia": "^2.2.6",
19
19
  "pug": "github:FlameArt/pug-tailwind-only",
20
20
  "pug-lexer": "github:FlameArt/pug-lexer-only",
21
- "sass": "^1.69.5",
21
+ "sass": "^1.81.0",
22
22
  "vue": "^3.3.7",
23
- "vue-router": "^4.2.5",
23
+ "vue-router": "^4.4.5",
24
24
  "vue-select": "^4.0.0-beta.6"
25
25
  },
26
26
  "devDependencies": {
27
- "@heroicons/vue": "^2.0.18",
28
- "@types/lodash-es": "^4.17.10",
29
- "@types/lodash.merge": "^4.6.8",
27
+ "@heroicons/vue": "^2.1.5",
28
+ "@types/lodash-es": "^4.17.12",
29
+ "@types/lodash.merge": "^4.6.9",
30
30
  "@types/node": "20.8.9",
31
- "@types/vue-select": "^3.16.6",
32
- "@typescript-eslint/eslint-plugin": "^6.9.1",
33
- "@typescript-eslint/parser": "^6.9.1",
34
- "@vitejs/plugin-vue": "^4.4.0",
31
+ "@types/vue-select": "^3.16.8",
32
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
33
+ "@typescript-eslint/parser": "^6.21.0",
34
+ "@vitejs/plugin-vue": "^4.6.2",
35
35
  "@volar/vue-language-plugin-pug": "^1.6.5",
36
36
  "@vue/compiler-sfc": "^3.3.7",
37
- "autoprefixer": "^10.4.16",
38
- "eslint": "^8.53.0",
37
+ "autoprefixer": "^10.4.20",
38
+ "eslint": "^8.57.1",
39
39
  "eslint-plugin-vue": "^8.7.1",
40
- "postcss": "^8.4.31",
40
+ "postcss": "^8.4.49",
41
41
  "postcss-import": "^14.1.0",
42
- "tailwindcss": "^3.3.5",
43
- "typescript": "^5.2.2",
44
- "vite": "^4.5.0",
45
- "vue-tsc": "^1.8.22",
42
+ "tailwindcss": "^3.4.15",
43
+ "typescript": "^5.6.3",
44
+ "vite": "^4.5.5",
45
+ "vue-tsc": "^1.8.27",
46
46
  "vue-universal-modal": "^1.1.4"
47
47
  },
48
48
  "rules": {}
package/src/App.vue CHANGED
@@ -27,7 +27,7 @@ opts.set('name', { title: 'Название' });
27
27
  opts.set('dt1', { title: 'Дата 1' });
28
28
  opts.set('dt2', { title: 'Дата 2' });
29
29
  opts.set('id', { title: 'ID', Selector: { model: Relatedtable }, Filter: { isShow: true, type: 'selector', selector: { multiselect: true, mode: 'vertical' } } });
30
- opts.set('file', { title: 'файл', Filter: { isShow: false } });
30
+ opts.set('file', { title: 'файл', Popup: {popupType: 'image'}, Filter: { isShow: false } });
31
31
  opts.set("name", {
32
32
  title: 'Название', Table:
33
33
  {
@@ -5,6 +5,7 @@ import { reactive, UnwrapRef } from 'vue';
5
5
  import merge from 'lodash-es/merge'
6
6
  import ITableLoadParams from './TableLoadParams';
7
7
  import TableRowParams from './TableRowParams';
8
+ import cloneDeep from 'lodash-es/cloneDeep';
8
9
 
9
10
  // Подгрузчик типа класса
10
11
  type Class<T> = new (...args: any[]) => T
@@ -162,6 +163,7 @@ export default class FlameTable<T> {
162
163
  if (typeof this.RowsParams[row[pk]] === 'undefined') {
163
164
  const newParam = new TableRowParams;
164
165
  newParam.item = row;
166
+ newParam.previousAttributes = cloneDeep(row);
165
167
  this.RowsParams[row[pk]] = newParam;
166
168
  }
167
169
  })
@@ -423,8 +425,15 @@ export default class FlameTable<T> {
423
425
  // Сперва предобработка
424
426
  if (await this.opts.Popup.beforeEdit(columns, this) === false) { return null; }
425
427
 
428
+ // Убираем поля, которые не требуют изменения
429
+ const cleanedCols = this.RemoveUnchagedFields(columns);
430
+
431
+ // Если изменений нет, то не посылаем
432
+ if (Object.keys(cleanedCols).length === 0) return null;
433
+
426
434
  // Подготовка к загрузке
427
- const preparedCols = await (window as any).REST.prepare(columns, true);
435
+ const preparedCols = await (window as any).REST.prepare(cleanedCols, true);
436
+
428
437
 
429
438
  // Сохраняем
430
439
  const res: SavedObject<T> = await tClass.edit(columns[indexKey], preparedCols);
@@ -443,6 +452,42 @@ export default class FlameTable<T> {
443
452
 
444
453
  }
445
454
 
455
+ private RemoveUnchagedFields(row: { [key: string]: any }) {
456
+
457
+ // primarykey
458
+ const pk = (this.model as any).constructor.primaryKeys[0];
459
+ const isPlainObject = (obj: any) => typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
460
+
461
+ // Теперь не отправляем на обнову значения, что не обновились
462
+ const cleanRow: { [key: string]: any } = {};
463
+ for (const key in this.columns) {
464
+
465
+ const cParam = this.RowsParams[row[pk]];
466
+ switch (this.columns[key].Popup.popupType) {
467
+
468
+ case 'file':
469
+ case 'image':
470
+ // Неизменный объект будет как простой объект, а не событие, File итд
471
+ debugger;
472
+ if (row[key] === null || isPlainObject(row[key])) continue;
473
+ break;
474
+ case 'text':
475
+ case 'string':
476
+ case 'date':
477
+ case 'selector':
478
+ if (cParam.previousAttributes[key] === row[key]) continue;
479
+ break;
480
+ default:
481
+ }
482
+
483
+ cleanRow[key] = row[key];
484
+ }
485
+
486
+ return cleanRow;
487
+
488
+ }
489
+
490
+
446
491
 
447
492
  public async remove(row: T): Promise<SavedObject<T>> {
448
493
 
@@ -462,15 +507,18 @@ export default class FlameTable<T> {
462
507
  private getColumnsForUpdate(mode: "add" | "edit") {
463
508
  const res: { [key: string]: string } = {};
464
509
  for (const key in this.columns) {
510
+
465
511
  if (mode === 'add' && !this.columns[key].Popup.isSendFromAdd) continue;
466
512
  if (mode === 'edit' && !this.columns[key].Popup.isSendFromEdit) continue;
467
- // TODO: здесь может быть полезно сохранять пустую строку
468
- if (this.columns[key].Popup.model !== '') {
469
- if (this.columns[key].Popup.fileModel !== null)
470
- res[key] = this.columns[key].Popup.fileModel
471
- else
472
- res[key] = this.columns[key].Popup.model
473
- }
513
+
514
+ // пропускаем виртуальные поля
515
+ if (this.columns[key].isVirtual) continue;
516
+
517
+ if (this.columns[key].Popup.fileModel !== null)
518
+ res[key] = this.columns[key].Popup.fileModel
519
+ else
520
+ res[key] = this.columns[key].Popup.model
521
+
474
522
  }
475
523
  return res;
476
524
  }
@@ -4,4 +4,7 @@ export default class TableRowParams {
4
4
  public selected: boolean = false;
5
5
  public item: any = null;
6
6
 
7
+ // Аттрибуты до сохранения новых
8
+ public previousAttributes: {[key:string]:any} = {};
9
+
7
10
  }