@molochko-dev/data 1.4.127 → 1.4.129

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.
@@ -0,0 +1,5 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="PROJECT_PROFILE" />
4
+ </settings>
5
+ </component>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PropertiesComponent">{
4
+ &quot;keyToString&quot;: {
5
+ &quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;
6
+ }
7
+ }</component>
8
+ </project>
@@ -132,10 +132,7 @@ class AnimalEventFilter {
132
132
  return this.transferOutFilter(animals);
133
133
  case event_1.EVENT_TYPES_ENUM.treatment:
134
134
  return this.treatmentFilter(animals);
135
- case (event_1.EVENT_TYPES_ENUM.ves,
136
- event_1.EVENT_TYPES_ENUM.rost,
137
- event_1.EVENT_TYPES_ENUM.upitannost,
138
- event_1.EVENT_TYPES_ENUM.ohota):
135
+ case event_1.EVENT_TYPES_ENUM.ohota:
139
136
  return this.weightFilter(animals);
140
137
  default:
141
138
  return animals;
@@ -77,31 +77,19 @@ export declare enum MEDMETHOD_ENUM {
77
77
  INTRAVAGINALLY = "intravaginally"
78
78
  }
79
79
  export declare enum EVENT_TYPES_ENUM {
80
- otel = "otel",
81
80
  calving = "calving",
82
81
  recheck = "recheck",
83
82
  ohota = "ohota",
84
83
  insemenation = "insemenation",
85
- stelnaya = "stelnaya",
86
- yalovaya = "yalovaya",
87
- stelneotpos = "stelneotpos",
88
84
  perevod = "perevod",
89
- kbiku = "kbiku",
90
85
  suhostoi = "suhostoi",
91
86
  abort = "abort",
92
87
  neosem = "neosem",
93
88
  prodazha = "prodazha",
94
- pala = "pala",
95
- zamenaNomera = "zamenaNomera",
96
- obrKopit = "obrKopit",
97
89
  pozSuhostoi = "pozSuhostoi",
98
- ves = "ves",
99
- rost = "rost",
100
90
  biometry = "biometry",
101
- upitannost = "upitannost",
102
- zaboi = "zaboi",
103
- sinchronizatsia = "sinchronizatsia",
104
91
  transferOut = "transferOut",
105
92
  treatment = "treatment",
106
- retagging = "retagging"
93
+ retagging = "retagging",
94
+ changeGroup = "changeGroup"
107
95
  }
@@ -87,34 +87,22 @@ var MEDMETHOD_ENUM;
87
87
  })(MEDMETHOD_ENUM = exports.MEDMETHOD_ENUM || (exports.MEDMETHOD_ENUM = {}));
88
88
  var EVENT_TYPES_ENUM;
89
89
  (function (EVENT_TYPES_ENUM) {
90
- // TODO otel - удалить
91
- EVENT_TYPES_ENUM["otel"] = "otel";
92
90
  EVENT_TYPES_ENUM["calving"] = "calving";
93
91
  EVENT_TYPES_ENUM["recheck"] = "recheck";
94
92
  EVENT_TYPES_ENUM["ohota"] = "ohota";
95
- // TODO osemenenie - удалить
96
- // osemenenie = 'osemenenie', // ОСЕМЕНЕНИЕ *
97
93
  EVENT_TYPES_ENUM["insemenation"] = "insemenation";
98
- EVENT_TYPES_ENUM["stelnaya"] = "stelnaya";
99
- EVENT_TYPES_ENUM["yalovaya"] = "yalovaya";
100
- EVENT_TYPES_ENUM["stelneotpos"] = "stelneotpos";
101
94
  EVENT_TYPES_ENUM["perevod"] = "perevod";
102
- EVENT_TYPES_ENUM["kbiku"] = "kbiku";
103
95
  EVENT_TYPES_ENUM["suhostoi"] = "suhostoi";
104
96
  EVENT_TYPES_ENUM["abort"] = "abort";
105
97
  EVENT_TYPES_ENUM["neosem"] = "neosem";
106
98
  EVENT_TYPES_ENUM["prodazha"] = "prodazha";
107
- EVENT_TYPES_ENUM["pala"] = "pala";
108
- EVENT_TYPES_ENUM["zamenaNomera"] = "zamenaNomera";
109
- EVENT_TYPES_ENUM["obrKopit"] = "obrKopit";
99
+ // pala = 'pala', // ПАЛА ----- addTocalendar
100
+ // obrKopit = 'obrKopit', // ОБРАБОТКА КОПЫТ
110
101
  EVENT_TYPES_ENUM["pozSuhostoi"] = "pozSuhostoi";
111
- EVENT_TYPES_ENUM["ves"] = "ves";
112
- EVENT_TYPES_ENUM["rost"] = "rost";
113
102
  EVENT_TYPES_ENUM["biometry"] = "biometry";
114
- EVENT_TYPES_ENUM["upitannost"] = "upitannost";
115
- EVENT_TYPES_ENUM["zaboi"] = "zaboi";
116
- EVENT_TYPES_ENUM["sinchronizatsia"] = "sinchronizatsia";
103
+ // sinchronizatsia = 'sinchronizatsia', // СИНХРОНИЗАЦИЯ
117
104
  EVENT_TYPES_ENUM["transferOut"] = "transferOut";
118
105
  EVENT_TYPES_ENUM["treatment"] = "treatment";
119
106
  EVENT_TYPES_ENUM["retagging"] = "retagging";
107
+ EVENT_TYPES_ENUM["changeGroup"] = "changeGroup";
120
108
  })(EVENT_TYPES_ENUM = exports.EVENT_TYPES_ENUM || (exports.EVENT_TYPES_ENUM = {}));
@@ -0,0 +1,5 @@
1
+ export declare enum HERD_KPI_AGGREGATION_ENUM {
2
+ day = "day",
3
+ week = "week",
4
+ month = "month"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HERD_KPI_AGGREGATION_ENUM = void 0;
4
+ var HERD_KPI_AGGREGATION_ENUM;
5
+ (function (HERD_KPI_AGGREGATION_ENUM) {
6
+ HERD_KPI_AGGREGATION_ENUM["day"] = "day";
7
+ HERD_KPI_AGGREGATION_ENUM["week"] = "week";
8
+ HERD_KPI_AGGREGATION_ENUM["month"] = "month";
9
+ })(HERD_KPI_AGGREGATION_ENUM = exports.HERD_KPI_AGGREGATION_ENUM || (exports.HERD_KPI_AGGREGATION_ENUM = {}));
@@ -0,0 +1,3 @@
1
+ import * as _enums from './enums';
2
+ export { _enums as enums };
3
+ export * from './models';
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.enums = void 0;
30
+ const _enums = __importStar(require("./enums"));
31
+ exports.enums = _enums;
32
+ __exportStar(require("./models"), exports);
@@ -0,0 +1,52 @@
1
+ export interface IHerdKpiSnapshot {
2
+ id: number;
3
+ orgId: string;
4
+ date: string;
5
+ pregnancyRate: number | null;
6
+ conceptionRate: number | null;
7
+ heatDetectionRate: number | null;
8
+ pregnancyRate21d: number | null;
9
+ avgDaysOpen: number | null;
10
+ avgDIM: number | null;
11
+ vwpCompliance: number | null;
12
+ cullingRate: number | null;
13
+ cullingCount: number;
14
+ totalAnimals: number;
15
+ avgMilkYield: number | null;
16
+ totalMilkYield: number | null;
17
+ milkingAnimalCount: number;
18
+ cullingByReason: Record<string, number>;
19
+ cullingByType: Record<string, number>;
20
+ dimDistribution: IDIMBucket[];
21
+ hdrPeriods: IHDRPeriod[];
22
+ }
23
+ export interface IDIMBucket {
24
+ bucket: string;
25
+ count: number;
26
+ }
27
+ export interface IHDRPeriod {
28
+ periodNumber: number;
29
+ periodStart: string;
30
+ periodEnd: string;
31
+ readinessCount: number;
32
+ bredCount: number;
33
+ pregnancyCount: number;
34
+ abortCount: number;
35
+ HDR: number;
36
+ CR: number;
37
+ PR: number;
38
+ }
39
+ export interface IMilkYieldPoint {
40
+ date: string;
41
+ totalYield: number;
42
+ animalCount: number;
43
+ avgYieldPerHead: number;
44
+ }
45
+ export interface IHerdKpiResponse {
46
+ data: IHerdKpiSnapshot[];
47
+ count: number;
48
+ }
49
+ export interface IMilkTrendResponse {
50
+ data: IMilkYieldPoint[];
51
+ count: number;
52
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import * as _eqEnums from './easy-query';
10
10
  import * as _orgConstants from './org';
11
11
  import * as _milkEnums from './milk';
12
12
  import * as _notificationEnums from './notification';
13
+ import * as _herdKpi from './herd-kpi';
13
14
  import * as _dateHelpers from './helpers/date';
14
15
  export declare const enums: {
15
16
  BREED: typeDefinitions.EnumItem[];
@@ -60,5 +61,6 @@ export declare const eqEnums: typeof _eqEnums.enums;
60
61
  export declare const orgConstants: typeof _orgConstants.constants;
61
62
  export declare const milkEnums: typeof _milkEnums.enums;
62
63
  export declare const notificationEnums: typeof _notificationEnums.enums;
64
+ export declare const herdKpiEnums: typeof _herdKpi.enums;
63
65
  export declare const dateHelpers: typeof _dateHelpers;
64
66
  export * as event from './event';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.event = exports.dateHelpers = exports.notificationEnums = exports.milkEnums = exports.orgConstants = exports.eqEnums = exports.eventEnums = exports.animalEnums = exports.animalForEventFilters = exports.importEnums = exports.animalTagEnums = exports.customListEnums = exports.types = exports.rolePermissions = exports.enums = void 0;
26
+ exports.event = exports.dateHelpers = exports.herdKpiEnums = exports.notificationEnums = exports.milkEnums = exports.orgConstants = exports.eqEnums = exports.eventEnums = exports.animalEnums = exports.animalForEventFilters = exports.importEnums = exports.animalTagEnums = exports.customListEnums = exports.types = exports.rolePermissions = exports.enums = void 0;
27
27
  const dataEnums = __importStar(require("./enums"));
28
28
  const breed_1 = require("./breed");
29
29
  const typeDefinitions = __importStar(require("./types"));
@@ -38,6 +38,7 @@ const _eqEnums = __importStar(require("./easy-query"));
38
38
  const _orgConstants = __importStar(require("./org"));
39
39
  const _milkEnums = __importStar(require("./milk"));
40
40
  const _notificationEnums = __importStar(require("./notification"));
41
+ const _herdKpi = __importStar(require("./herd-kpi"));
41
42
  const _dateHelpers = __importStar(require("./helpers/date"));
42
43
  exports.enums = Object.assign(Object.assign({}, dataEnums), { BREED: breed_1.BREED, BREED_AS_OBJECT: breed_1.BREED_AS_OBJECT });
43
44
  exports.rolePermissions = _rolePermissions;
@@ -52,6 +53,7 @@ exports.eqEnums = _eqEnums.enums;
52
53
  exports.orgConstants = _orgConstants.constants;
53
54
  exports.milkEnums = _milkEnums.enums;
54
55
  exports.notificationEnums = _notificationEnums.enums;
56
+ exports.herdKpiEnums = _herdKpi.enums;
55
57
  exports.dateHelpers = _dateHelpers;
56
58
  // export { events } from './event';
57
59
  // export type { events as EventType } from './event';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molochko-dev/data",
3
- "version": "1.4.127",
3
+ "version": "1.4.129",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
@@ -159,10 +159,7 @@ class AnimalEventFilter {
159
159
  return this.transferOutFilter(animals);
160
160
  case EVENT_TYPES_ENUM.treatment:
161
161
  return this.treatmentFilter(animals);
162
- case (EVENT_TYPES_ENUM.ves,
163
- EVENT_TYPES_ENUM.rost,
164
- EVENT_TYPES_ENUM.upitannost,
165
- EVENT_TYPES_ENUM.ohota):
162
+ case EVENT_TYPES_ENUM.ohota:
166
163
  return this.weightFilter(animals);
167
164
  default:
168
165
  return animals;
@@ -86,35 +86,23 @@ export enum MEDMETHOD_ENUM {
86
86
  }
87
87
 
88
88
  export enum EVENT_TYPES_ENUM {
89
- // TODO otel - удалить
90
- otel = 'otel', // ОТЕЛ ----- addTocalendar
91
89
  calving = 'calving', // ОТЕЛ ----- addTocalendar
92
90
  recheck = 'recheck', // ПЕРЕПРОВЕРИТЬ * ----- addTocalendar
93
91
  ohota = 'ohota', // ОХОТА ----- addTocalendar
94
- // TODO osemenenie - удалить
95
- // osemenenie = 'osemenenie', // ОСЕМЕНЕНИЕ *
96
92
  insemenation = 'insemenation', // ОСЕМЕНЕНИЕ *
97
- stelnaya = 'stelnaya', // СТЕЛЬНАЯ
98
- yalovaya = 'yalovaya', // ЯЛОВАЯ (НЕ СТЕЛЬНАЯ) ----- addTocalendar
99
- stelneotpos = 'stelneotpos', // СТЕЛЬНАЯ НЕ ОТ ПОС ОСЕМЕНЕНИЯ ----- addTocalendar
100
93
  perevod = 'perevod', // ПЕРЕВОД
101
- kbiku = 'kbiku', // КБЫКУ ----- addTocalendar
102
94
  suhostoi = 'suhostoi', //'СУХОСТОЙ ----- addTocalendar
103
95
  abort = 'abort', // АБОРТ
104
96
  neosem = 'neosem', // НЕОСЕМ (БРАК) *
105
97
  prodazha = 'prodazha', // ПРОДАЖА ----- addTocalendar
106
- pala = 'pala', // ПАЛА ----- addTocalendar
107
- zamenaNomera = 'zamenaNomera', // ЗАМЕНА НОМЕРА ----- addTocalendar
108
- obrKopit = 'obrKopit', // ОБРАБОТКА КОПЫТ
98
+ // pala = 'pala', // ПАЛА ----- addTocalendar
99
+ // obrKopit = 'obrKopit', // ОБРАБОТКА КОПЫТ
109
100
  pozSuhostoi = 'pozSuhostoi', // ПОЗСУХОСТОЙ
110
- ves = 'ves', // ВЕС
111
- rost = 'rost', // РОСТ
112
101
  biometry = 'biometry',
113
- upitannost = 'upitannost', // УПИТАННОСТЬ
114
- zaboi = 'zaboi', // ЗАБОЙ
115
- sinchronizatsia = 'sinchronizatsia', // СИНХРОНИЗАЦИЯ
102
+ // sinchronizatsia = 'sinchronizatsia', // СИНХРОНИЗАЦИЯ
116
103
  transferOut = 'transferOut', // выбытие
117
104
  treatment = 'treatment', // лечение
118
105
 
119
106
  retagging = 'retagging', // перебирковка
107
+ changeGroup = 'changeGroup', // смена группы
120
108
  }
@@ -0,0 +1,5 @@
1
+ export enum HERD_KPI_AGGREGATION_ENUM {
2
+ day = 'day',
3
+ week = 'week',
4
+ month = 'month',
5
+ }
@@ -0,0 +1,4 @@
1
+ import * as _enums from './enums';
2
+
3
+ export { _enums as enums };
4
+ export * from './models';
@@ -0,0 +1,57 @@
1
+ export interface IHerdKpiSnapshot {
2
+ id: number;
3
+ orgId: string;
4
+ date: string;
5
+ pregnancyRate: number | null;
6
+ conceptionRate: number | null;
7
+ heatDetectionRate: number | null;
8
+ pregnancyRate21d: number | null;
9
+ avgDaysOpen: number | null;
10
+ avgDIM: number | null;
11
+ vwpCompliance: number | null;
12
+ cullingRate: number | null;
13
+ cullingCount: number;
14
+ totalAnimals: number;
15
+ avgMilkYield: number | null;
16
+ totalMilkYield: number | null;
17
+ milkingAnimalCount: number;
18
+ cullingByReason: Record<string, number>;
19
+ cullingByType: Record<string, number>;
20
+ dimDistribution: IDIMBucket[];
21
+ hdrPeriods: IHDRPeriod[];
22
+ }
23
+
24
+ export interface IDIMBucket {
25
+ bucket: string;
26
+ count: number;
27
+ }
28
+
29
+ export interface IHDRPeriod {
30
+ periodNumber: number;
31
+ periodStart: string;
32
+ periodEnd: string;
33
+ readinessCount: number;
34
+ bredCount: number;
35
+ pregnancyCount: number;
36
+ abortCount: number;
37
+ HDR: number;
38
+ CR: number;
39
+ PR: number;
40
+ }
41
+
42
+ export interface IMilkYieldPoint {
43
+ date: string;
44
+ totalYield: number;
45
+ animalCount: number;
46
+ avgYieldPerHead: number;
47
+ }
48
+
49
+ export interface IHerdKpiResponse {
50
+ data: IHerdKpiSnapshot[];
51
+ count: number;
52
+ }
53
+
54
+ export interface IMilkTrendResponse {
55
+ data: IMilkYieldPoint[];
56
+ count: number;
57
+ }
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import * as _eqEnums from './easy-query';
12
12
  import * as _orgConstants from './org';
13
13
  import * as _milkEnums from './milk';
14
14
  import * as _notificationEnums from './notification';
15
+ import * as _herdKpi from './herd-kpi';
15
16
  import * as _dateHelpers from './helpers/date';
16
17
  export const enums = { ...dataEnums, BREED, BREED_AS_OBJECT };
17
18
  export const rolePermissions = _rolePermissions;
@@ -26,6 +27,7 @@ export const eqEnums = _eqEnums.enums;
26
27
  export const orgConstants = _orgConstants.constants;
27
28
  export const milkEnums = _milkEnums.enums;
28
29
  export const notificationEnums = _notificationEnums.enums;
30
+ export const herdKpiEnums = _herdKpi.enums;
29
31
  export const dateHelpers = _dateHelpers;
30
32
 
31
33
  // export { events } from './event';
@@ -1,180 +0,0 @@
1
- import { SelectionModel } from '@angular/cdk/collections';
2
- import { FlatTreeControl } from '@angular/cdk/tree';
3
- import { Component } from '@angular/core';
4
-
5
- import { NzButtonModule } from 'ng-zorro-antd/button';
6
- import { NzIconModule } from 'ng-zorro-antd/icon';
7
- import { NzInputModule } from 'ng-zorro-antd/input';
8
- import { NzTreeFlatDataSource, NzTreeFlattener, NzTreeViewModule } from 'ng-zorro-antd/tree-view';
9
-
10
- interface TreeNode {
11
- name: string;
12
- key: string;
13
- children?: TreeNode[];
14
- }
15
-
16
- const TREE_DATA: TreeNode[] = [
17
- {
18
- name: 'parent 1',
19
- key: '1',
20
- children: [
21
- {
22
- name: 'parent 1-0',
23
- key: '1-0',
24
- children: [
25
- { name: 'leaf', key: '1-0-0' },
26
- { name: 'leaf', key: '1-0-1' },
27
- ],
28
- },
29
- {
30
- name: 'parent 1-1',
31
- key: '1-1',
32
- children: [{ name: 'leaf', key: '1-1-0' }],
33
- },
34
- ],
35
- },
36
- {
37
- key: '2',
38
- name: 'parent 2',
39
- children: [{ name: 'leaf', key: '2-0' }],
40
- },
41
- ];
42
-
43
- interface FlatNode {
44
- expandable: boolean;
45
- name: string;
46
- key: string;
47
- level: number;
48
- }
49
-
50
- @Component({
51
- selector: 'nz-demo-tree-view-editable',
52
- standalone: true,
53
- imports: [NzButtonModule, NzInputModule, NzIconModule, NzTreeViewModule],
54
- template: `
55
- <nz-tree-view [nzTreeControl]="treeControl" [nzDataSource]="dataSource" [trackBy]="trackBy">
56
- <nz-tree-node *nzTreeNodeDef="let node" nzTreeNodeIndentLine>
57
- <nz-tree-node-option
58
- [nzDisabled]="node.disabled"
59
- [nzSelected]="selectListSelection.isSelected(node)"
60
- (nzClick)="selectListSelection.toggle(node)"
61
- >
62
- {{ node.name }}
63
- </nz-tree-node-option>
64
- <button nz-button nzType="text" nzSize="small" (click)="delete(node)">
65
- <span nz-icon nzType="minus" nzTheme="outline"></span>
66
- </button>
67
- </nz-tree-node>
68
-
69
- <nz-tree-node *nzTreeNodeDef="let node; when: hasNoContent" nzTreeNodeIndentLine>
70
- <input nz-input placeholder="Input node name" nzSize="small" #inputElement />
71
- &nbsp;
72
- <button nz-button nzSize="small" (click)="saveNode(node, inputElement.value)">Add</button>
73
- </nz-tree-node>
74
-
75
- <nz-tree-node *nzTreeNodeDef="let node; when: hasChild" nzTreeNodeIndentLine>
76
- <nz-tree-node-toggle>
77
- <span nz-icon nzType="caret-down" nzTreeNodeToggleRotateIcon></span>
78
- </nz-tree-node-toggle>
79
- {{ node.name }}
80
- <button nz-button nzType="text" nzSize="small" (click)="addNewNode(node)">
81
- <span nz-icon nzType="plus" nzTheme="outline"></span>
82
- </button>
83
- </nz-tree-node>
84
- </nz-tree-view>
85
- `,
86
- styles: [``],
87
- })
88
- export class NzDemoTreeViewEditableComponent {
89
- private transformer = (node: TreeNode, level: number): FlatNode => {
90
- const existingNode = this.nestedNodeMap.get(node);
91
- const flatNode =
92
- existingNode && existingNode.key === node.key
93
- ? existingNode
94
- : {
95
- expandable: !!node.children && node.children.length > 0,
96
- name: node.name,
97
- level,
98
- key: node.key,
99
- };
100
- flatNode.name = node.name;
101
- this.flatNodeMap.set(flatNode, node);
102
- this.nestedNodeMap.set(node, flatNode);
103
- return flatNode;
104
- };
105
-
106
- treeData = TREE_DATA;
107
- flatNodeMap = new Map<FlatNode, TreeNode>();
108
- nestedNodeMap = new Map<TreeNode, FlatNode>();
109
- selectListSelection = new SelectionModel<FlatNode>(true);
110
-
111
- treeControl = new FlatTreeControl<FlatNode>(
112
- (node) => node.level,
113
- (node) => node.expandable,
114
- );
115
- treeFlattener = new NzTreeFlattener(
116
- this.transformer,
117
- (node) => node.level,
118
- (node) => node.expandable,
119
- (node) => node.children,
120
- );
121
-
122
- dataSource = new NzTreeFlatDataSource(this.treeControl, this.treeFlattener);
123
-
124
- constructor() {
125
- this.dataSource.setData(this.treeData);
126
- this.treeControl.expandAll();
127
- }
128
-
129
- hasChild = (_: number, node: FlatNode): boolean => node.expandable;
130
- hasNoContent = (_: number, node: FlatNode): boolean => node.name === '';
131
- trackBy = (_: number, node: FlatNode): string => `${node.key}-${node.name}`;
132
-
133
- delete(node: FlatNode): void {
134
- const originNode = this.flatNodeMap.get(node);
135
-
136
- const dfsParentNode = (): TreeNode | null => {
137
- const stack = [...this.treeData];
138
- while (stack.length > 0) {
139
- const n = stack.pop()!;
140
- if (n.children) {
141
- if (n.children.find((e) => e === originNode)) {
142
- return n;
143
- }
144
-
145
- for (let i = n.children.length - 1; i >= 0; i--) {
146
- stack.push(n.children[i]);
147
- }
148
- }
149
- }
150
- return null;
151
- };
152
-
153
- const parentNode = dfsParentNode();
154
- if (parentNode && parentNode.children) {
155
- parentNode.children = parentNode.children.filter((e) => e !== originNode);
156
- }
157
-
158
- this.dataSource.setData(this.treeData);
159
- }
160
- addNewNode(node: FlatNode): void {
161
- const parentNode = this.flatNodeMap.get(node);
162
- if (parentNode) {
163
- parentNode.children = parentNode.children || [];
164
- parentNode.children.push({
165
- name: '',
166
- key: `${parentNode.key}-${parentNode.children.length}`,
167
- });
168
- this.dataSource.setData(this.treeData);
169
- this.treeControl.expand(node);
170
- }
171
- }
172
-
173
- saveNode(node: FlatNode, value: string): void {
174
- const nestedNode = this.flatNodeMap.get(node);
175
- if (nestedNode) {
176
- nestedNode.name = value;
177
- this.dataSource.setData(this.treeData);
178
- }
179
- }
180
- }