@acorex/platform 18.2.3 → 18.2.4
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/esm2022/common/lib/layout/sticky.directive.mjs +15 -11
- package/esm2022/layout/builder/lib/builder/widget-column-renderer.mjs +22 -11
- package/esm2022/layout/designer/lib/designer/components/size-mode/view-size-toolbar.component.mjs +27 -32
- package/esm2022/layout/entity/lib/entity-master-list.viewmodel.mjs +33 -8
- package/esm2022/layout/entity/lib/entity.module.mjs +1 -17
- package/esm2022/layout/entity/lib/index.mjs +5 -4
- package/esm2022/layout/setting/lib/convert-setting-data.mjs +59 -0
- package/esm2022/layout/setting/lib/setting.viewmodel.mjs +123 -41
- package/esm2022/layouts/lib/admin/entity-layout/entity-list-view/entity-list-view.component.mjs +3 -3
- package/esm2022/themes/default/lib/default.module.mjs +83 -39
- package/esm2022/themes/default/lib/layouts/entity-layouts/entity-detail-list-view/entity-detail-list-view.component.mjs +3 -3
- package/esm2022/themes/default/lib/layouts/entity-layouts/entity-master-list-view/entity-master-list-view.component.mjs +18 -18
- package/esm2022/themes/default/lib/layouts/entity-layouts/entity-master-list-view/list-view-option-columns/list-view-option-columns.component.mjs +18 -8
- package/esm2022/themes/default/lib/layouts/root-layout/components/menu/root-menu.component.mjs +1 -1
- package/esm2022/themes/default/lib/layouts/setting-layout/index.mjs +3 -3
- package/esm2022/themes/default/lib/layouts/setting-layout/setting-menu/setting-menu.component.mjs +28 -0
- package/esm2022/themes/default/lib/layouts/setting-layout/setting-view/setting-view.component.mjs +42 -0
- package/esm2022/widgets/lib/widgets/advance/cron-job/cron-job-widget-edit.component.mjs +2 -2
- package/esm2022/widgets/lib/widgets/advance/cron-job/cron-job-widget.config.mjs +3 -2
- package/esm2022/workflow/lib/workflow.service.mjs +1 -1
- package/fesm2022/acorex-platform-common.mjs +13 -9
- package/fesm2022/acorex-platform-common.mjs.map +1 -1
- package/fesm2022/acorex-platform-layout-builder.mjs +18 -7
- package/fesm2022/acorex-platform-layout-builder.mjs.map +1 -1
- package/fesm2022/acorex-platform-layout-designer.mjs +25 -30
- package/fesm2022/acorex-platform-layout-designer.mjs.map +1 -1
- package/fesm2022/acorex-platform-layout-entity.mjs +842 -833
- package/fesm2022/acorex-platform-layout-entity.mjs.map +1 -1
- package/fesm2022/acorex-platform-layout-setting.mjs +180 -40
- package/fesm2022/acorex-platform-layout-setting.mjs.map +1 -1
- package/fesm2022/acorex-platform-layouts.mjs.map +1 -1
- package/fesm2022/{acorex-platform-themes-default-entity-master-create-view.component-CJY8R3sa.mjs → acorex-platform-themes-default-entity-master-create-view.component-Bs6fn6z2.mjs} +3 -3
- package/fesm2022/{acorex-platform-themes-default-entity-master-create-view.component-CJY8R3sa.mjs.map → acorex-platform-themes-default-entity-master-create-view.component-Bs6fn6z2.mjs.map} +1 -1
- package/fesm2022/{acorex-platform-themes-default-entity-master-list-view.component-C6zgLyry.mjs → acorex-platform-themes-default-entity-master-list-view.component-DPHXeucj.mjs} +39 -30
- package/fesm2022/acorex-platform-themes-default-entity-master-list-view.component-DPHXeucj.mjs.map +1 -0
- package/fesm2022/{acorex-platform-themes-default-entity-master-modify-view.component-wPZPhMgy.mjs → acorex-platform-themes-default-entity-master-modify-view.component-CWrpcOC2.mjs} +3 -3
- package/fesm2022/{acorex-platform-themes-default-entity-master-modify-view.component-wPZPhMgy.mjs.map → acorex-platform-themes-default-entity-master-modify-view.component-CWrpcOC2.mjs.map} +1 -1
- package/fesm2022/{acorex-platform-themes-default-entity-master-single-view.component-DNXWb6ij.mjs → acorex-platform-themes-default-entity-master-single-view.component-DHfe0Qtu.mjs} +10 -10
- package/fesm2022/{acorex-platform-themes-default-entity-master-single-view.component-DNXWb6ij.mjs.map → acorex-platform-themes-default-entity-master-single-view.component-DHfe0Qtu.mjs.map} +1 -1
- package/fesm2022/acorex-platform-themes-default.mjs +153 -257
- package/fesm2022/acorex-platform-themes-default.mjs.map +1 -1
- package/fesm2022/acorex-platform-widgets.mjs +3 -2
- package/fesm2022/acorex-platform-widgets.mjs.map +1 -1
- package/fesm2022/acorex-platform-workflow.mjs.map +1 -1
- package/layout/builder/lib/builder/widget-column-renderer.d.ts +1 -1
- package/layout/entity/lib/entity-master-list.viewmodel.d.ts +6 -2
- package/layout/entity/lib/index.d.ts +4 -3
- package/layout/setting/README.md +2 -3
- package/{themes/default/lib/layouts/setting-layout → layout/setting/lib}/convert-setting-data.d.ts +6 -6
- package/layout/setting/lib/setting.viewmodel.d.ts +35 -9
- package/package.json +7 -7
- package/themes/default/lib/default.module.d.ts +3 -4
- package/themes/default/lib/layouts/entity-layouts/entity-master-list-view/list-view-option-columns/list-view-option-columns.component.d.ts +3 -0
- package/themes/default/lib/layouts/setting-layout/index.d.ts +2 -2
- package/themes/default/lib/layouts/setting-layout/setting-menu/setting-menu.component.d.ts +12 -0
- package/themes/default/lib/layouts/setting-layout/setting-view/setting-view.component.d.ts +7 -0
- package/widgets/lib/widgets/advance/cron-job/cron-job-widget-edit.component.d.ts +1 -2
- package/workflow/lib/workflow.service.d.ts +1 -1
- package/esm2022/themes/default/lib/layout.routes.mjs +0 -20
- package/esm2022/themes/default/lib/layouts/setting-layout/convert-setting-data.mjs +0 -49
- package/esm2022/themes/default/lib/layouts/setting-layout/setting-preview/setting-preview.component.mjs +0 -104
- package/esm2022/themes/default/lib/layouts/setting-layout/setting-view/setting-menu.component.mjs +0 -44
- package/fesm2022/acorex-platform-themes-default-entity-master-list-view.component-C6zgLyry.mjs.map +0 -1
- package/themes/default/lib/layout.routes.d.ts +0 -2
- package/themes/default/lib/layouts/setting-layout/setting-preview/setting-preview.component.d.ts +0 -24
- package/themes/default/lib/layouts/setting-layout/setting-view/setting-menu.component.d.ts +0 -20
|
@@ -1,53 +1,193 @@
|
|
|
1
|
+
import { AXToastService } from '@acorex/components/toast';
|
|
2
|
+
import { AXPlatform } from '@acorex/core/platform';
|
|
3
|
+
import { AXPSettingDefinitionProviderService } from '@acorex/platform/common';
|
|
1
4
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { signal, Injectable } from '@angular/core';
|
|
3
|
-
import {
|
|
5
|
+
import { inject, signal, computed, Injectable } from '@angular/core';
|
|
6
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
7
|
+
import { filter, take } from 'rxjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts a list of AXPSettingDefinitionGroup into a tree structure of AXTreeViewSchema.
|
|
11
|
+
* This function processes groups and their nested sub-groups, recursively creating a tree.
|
|
12
|
+
*
|
|
13
|
+
* @param groups - Array of top-level setting groups to be converted into tree view schema.
|
|
14
|
+
* @param parentId - The parent ID for nested groups, passed down recursively. (Optional, default is undefined)
|
|
15
|
+
*
|
|
16
|
+
* @returns An array of AXTreeViewSchema representing the hierarchical structure of groups.
|
|
17
|
+
*/
|
|
18
|
+
function convertToTreeViewSchema(groups, parentId) {
|
|
19
|
+
// Helper function to traverse and convert a single group (and its sub-groups)
|
|
20
|
+
const traverseGroups = (group, parent) => {
|
|
21
|
+
const currentId = group.name;
|
|
22
|
+
// Schema for the current group
|
|
23
|
+
const schema = {
|
|
24
|
+
id: currentId, // Unique identifier for the group (using group name)
|
|
25
|
+
parentId: parent, // Parent group ID, passed down recursively
|
|
26
|
+
text: group.title, // Display title of the group
|
|
27
|
+
//tooltip: group.description, // Optional description as tooltip
|
|
28
|
+
hasChild: group.groups.length > 0, // Whether the group has child groups
|
|
29
|
+
isExpanded: false, // Default state for expansion (optional)
|
|
30
|
+
childrens: group.groups.length > 0 ? [] : undefined, // Child groups array (undefined if no children)
|
|
31
|
+
};
|
|
32
|
+
// Recursively process nested groups (sub-groups inside the current group)
|
|
33
|
+
group.groups.forEach((subGroup) => {
|
|
34
|
+
const childSchema = traverseGroups(subGroup, currentId); // Create schema for sub-group
|
|
35
|
+
schema.childrens?.push(childSchema); // Add the child schema to the parent group's children
|
|
36
|
+
});
|
|
37
|
+
return schema; // Return the group schema with its children (if any)
|
|
38
|
+
};
|
|
39
|
+
// Initialize an array to hold the top-level groups' schemas
|
|
40
|
+
const treeViewSchemas = [];
|
|
41
|
+
// Process each top-level group and convert it into tree view schema
|
|
42
|
+
groups.forEach((group) => {
|
|
43
|
+
treeViewSchemas.push(traverseGroups(group, parentId)); // Add the schema for each group
|
|
44
|
+
});
|
|
45
|
+
// Return the resulting hierarchical structure
|
|
46
|
+
return treeViewSchemas;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recursively searches for a specific `id` in a tree structure and updates its `active` property to `true`.
|
|
50
|
+
* Additionally, ensures all other nodes have their `active` property set to `false`.
|
|
51
|
+
*
|
|
52
|
+
* @param tree - The tree structure to search, represented as an array of AXTreeViewSchema nodes.
|
|
53
|
+
* @param targetId - The `id` of the node to activate.
|
|
54
|
+
* @returns The updated tree structure with the target node activated and others deactivated.
|
|
55
|
+
*/
|
|
56
|
+
function setActiveByValueField(tree, targetId) {
|
|
57
|
+
return tree.map((node) => {
|
|
58
|
+
// Set active property for the target node
|
|
59
|
+
node.active = node.id === targetId;
|
|
60
|
+
// Recursively process children if they exist
|
|
61
|
+
if (node.childrens && node.childrens.length > 0) {
|
|
62
|
+
node.childrens = setActiveByValueField(node.childrens, targetId);
|
|
63
|
+
}
|
|
64
|
+
return node;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
4
67
|
|
|
5
68
|
class AXPSettingsViewModel {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
69
|
+
constructor() {
|
|
70
|
+
this.router = inject(Router);
|
|
71
|
+
this.settingService = inject(AXPSettingDefinitionProviderService);
|
|
72
|
+
this.platform = inject(AXPlatform);
|
|
73
|
+
this.toastService = inject(AXToastService);
|
|
74
|
+
this.data = signal(null);
|
|
75
|
+
this.isMobile = signal(this.platform.is('MD'));
|
|
76
|
+
this.fullRoute = this.router.url.split('/settings')[0] + '/settings/';
|
|
77
|
+
this.activatedGroup = signal(undefined);
|
|
78
|
+
this.dataDetails = computed(() => {
|
|
79
|
+
if (this.activatedGroup()) {
|
|
80
|
+
return this.fetchGroupDetails(this.activatedGroup());
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
return null;
|
|
84
|
+
});
|
|
85
|
+
this.formattedData = signal([]);
|
|
86
|
+
this.context = signal({});
|
|
87
|
+
this.previousContext = signal({});
|
|
88
|
+
this.isSaving = signal(false);
|
|
89
|
+
this.canCancel = computed(() => this.isObjectEmpty(this.context()));
|
|
90
|
+
this.canSave = computed(() => !this.isSaving() &&
|
|
91
|
+
!this.isObjectEmpty(this.context()) &&
|
|
92
|
+
!this.areObjectsEqual(this.context(), this.previousContext()));
|
|
93
|
+
}
|
|
94
|
+
async initializeService(activatedRoute) {
|
|
95
|
+
// Initial setup
|
|
96
|
+
this.activatedRoute = activatedRoute;
|
|
97
|
+
this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe(() => {
|
|
98
|
+
this.updateGroupParam();
|
|
99
|
+
});
|
|
100
|
+
this.updateGroupParam();
|
|
101
|
+
await this.getData();
|
|
102
|
+
}
|
|
103
|
+
ngOnDestroy() {
|
|
104
|
+
this.subscription.unsubscribe();
|
|
105
|
+
}
|
|
106
|
+
// Fetch settings data
|
|
107
|
+
async getData() {
|
|
108
|
+
const items = await this.settingService.items();
|
|
109
|
+
this.data.set(items);
|
|
110
|
+
this.formattedData.set(convertToTreeViewSchema(this.data()));
|
|
111
|
+
}
|
|
112
|
+
// Fetch group details for preview
|
|
113
|
+
fetchGroupDetails(groupName) {
|
|
114
|
+
return this.settingService.findGroupDetails(groupName);
|
|
115
|
+
}
|
|
116
|
+
// Update group param logic
|
|
117
|
+
updateGroupParam() {
|
|
118
|
+
// If no child routes exist, set groupParam to null
|
|
119
|
+
if (this.activatedRoute.children.length === 0) {
|
|
120
|
+
this.activatedGroup.set(undefined);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// Traverse child routes to check for the group parameter
|
|
124
|
+
this.activatedRoute.children.forEach((childRoute) => {
|
|
125
|
+
childRoute.paramMap.pipe(take(1)).subscribe((params) => {
|
|
126
|
+
const group = params.get('group');
|
|
127
|
+
console.log(group);
|
|
128
|
+
this.activatedGroup.set(group || undefined);
|
|
129
|
+
if (group) {
|
|
130
|
+
this.formattedData.set(setActiveByValueField(this.formattedData(), group));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
20
133
|
});
|
|
21
134
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
135
|
+
onChooseGroup(item) {
|
|
136
|
+
const value = item.data?.['id'];
|
|
137
|
+
this.router.navigate([value], { relativeTo: this.activatedRoute });
|
|
138
|
+
}
|
|
139
|
+
setContext(value) {
|
|
140
|
+
this.context.set(value);
|
|
141
|
+
}
|
|
142
|
+
// Save settings logic
|
|
143
|
+
async onSaveSettings() {
|
|
144
|
+
this.previousContext.set(this.context());
|
|
145
|
+
this.isSaving.set(true);
|
|
146
|
+
// Simulate an API call
|
|
147
|
+
this.toastService.show({
|
|
148
|
+
color: 'success',
|
|
149
|
+
title: `Saved successfully`,
|
|
150
|
+
location: 'bottom-center',
|
|
151
|
+
closeButton: true,
|
|
152
|
+
timeOut: 3000,
|
|
153
|
+
timeOutProgress: false,
|
|
154
|
+
});
|
|
155
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
156
|
+
this.isSaving.set(false);
|
|
157
|
+
}
|
|
158
|
+
// Cancel settings logic
|
|
159
|
+
onCancelSettings() {
|
|
160
|
+
this.context.set({});
|
|
161
|
+
}
|
|
162
|
+
// Helper: Check if object is empty
|
|
163
|
+
isObjectEmpty(obj) {
|
|
164
|
+
return Object.keys(obj).length === 0;
|
|
165
|
+
}
|
|
166
|
+
// Helper: Compare objects
|
|
167
|
+
areObjectsEqual(obj1, obj2) {
|
|
168
|
+
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) {
|
|
169
|
+
return obj1 === obj2;
|
|
170
|
+
}
|
|
171
|
+
const keys1 = Object.keys(obj1);
|
|
172
|
+
const keys2 = Object.keys(obj2);
|
|
173
|
+
if (keys1.length !== keys2.length) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
for (const key of keys1) {
|
|
177
|
+
const keyTyped = key;
|
|
178
|
+
if (!obj2.hasOwnProperty(key) || !this.areObjectsEqual(obj1[keyTyped], obj2[keyTyped])) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: AXPSettingsViewModel, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
45
185
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: AXPSettingsViewModel, providedIn: 'root' }); }
|
|
46
186
|
}
|
|
47
187
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.0", ngImport: i0, type: AXPSettingsViewModel, decorators: [{
|
|
48
188
|
type: Injectable,
|
|
49
189
|
args: [{ providedIn: 'root' }]
|
|
50
|
-
}], ctorParameters: () => [
|
|
190
|
+
}], ctorParameters: () => [] });
|
|
51
191
|
|
|
52
192
|
/**
|
|
53
193
|
* Generated bundle index. Do not edit.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acorex-platform-layout-setting.mjs","sources":["../../../../libs/platform/layout/setting/src/lib/setting.viewmodel.ts","../../../../libs/platform/layout/setting/src/acorex-platform-layout-setting.ts"],"sourcesContent":["import { Injectable, Injector, signal } from '@angular/core';\nimport { AXDataSource, AXDataSourceQuery } from '@acorex/components/common';\n\n@Injectable({ providedIn: 'root' })\nexport class AXPSettingsViewModel {\n // منبع داده\n public dataSource: AXDataSource;\n\n // مقدار جستجو\n private searchQuery = signal<string>('');\n\n constructor(private injector: Injector) {\n this.dataSource = new AXDataSource({\n pageSize: 10, // تعداد آیتمها در هر صفحه\n load: (loadOptions: AXDataSourceQuery) => {\n // ادغام مقدار جستجو با درخواست API\n const params = {\n ...loadOptions,\n search: this.searchQuery(),\n };\n return this.loadSettingsFromAPI(params);\n },\n });\n }\n\n // اعمال مقدار جستجو\n public applySearch(query: string) {\n this.searchQuery.set(query); // مقدار جستجو را تنظیم میکنیم\n this.dataSource.refresh(); // بارگذاری مجدد دادهها\n }\n\n // متد برای بارگذاری دادهها از API\n private async loadSettingsFromAPI(params: any): Promise<any> {\n console.log('Fetching settings with params:', params);\n\n // ارسال درخواست به API (نمونه داده به صورت Mock ارائه شده)\n return Promise.resolve([\n {\n name: 'theme',\n title: 'Interface Theme',\n description: 'Select the interface theme for your dashboard.',\n },\n {\n name: 'language',\n title: 'Language',\n description: 'Choose the default language for the system.',\n },\n ]);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAIa,oBAAoB,CAAA;AAO/B,IAAA,WAAA,CAAoB,QAAkB,EAAA;QAAlB,IAAQ,CAAA,QAAA,GAAR,QAAQ;;AAFpB,QAAA,IAAA,CAAA,WAAW,GAAG,MAAM,CAAS,EAAE,CAAC;AAGtC,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,YAAY,CAAC;YACjC,QAAQ,EAAE,EAAE;AACZ,YAAA,IAAI,EAAE,CAAC,WAA8B,KAAI;;AA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,"file":"acorex-platform-layout-setting.mjs","sources":["../../../../libs/platform/layout/setting/src/lib/convert-setting-data.ts","../../../../libs/platform/layout/setting/src/lib/setting.viewmodel.ts","../../../../libs/platform/layout/setting/src/acorex-platform-layout-setting.ts"],"sourcesContent":["import { AXTreeViewSchema } from '@acorex/components/tree-view/lib/tree-view.class';\nimport { AXPSettingDefinitionGroup } from '@acorex/platform/common';\n\n/**\n * Converts a list of AXPSettingDefinitionGroup into a tree structure of AXTreeViewSchema.\n * This function processes groups and their nested sub-groups, recursively creating a tree.\n *\n * @param groups - Array of top-level setting groups to be converted into tree view schema.\n * @param parentId - The parent ID for nested groups, passed down recursively. (Optional, default is undefined)\n *\n * @returns An array of AXTreeViewSchema representing the hierarchical structure of groups.\n */\nexport function convertToTreeViewSchema(\n groups: AXPSettingDefinitionGroup[],\n parentId?: string | number\n): AXTreeViewSchema[] {\n // Helper function to traverse and convert a single group (and its sub-groups)\n const traverseGroups = (group: AXPSettingDefinitionGroup, parent?: string | number): AXTreeViewSchema => {\n const currentId = group.name;\n\n // Schema for the current group\n const schema: AXTreeViewSchema = {\n id: currentId, // Unique identifier for the group (using group name)\n parentId: parent, // Parent group ID, passed down recursively\n text: group.title, // Display title of the group\n //tooltip: group.description, // Optional description as tooltip\n hasChild: group.groups.length > 0, // Whether the group has child groups\n isExpanded: false, // Default state for expansion (optional)\n childrens: group.groups.length > 0 ? [] : undefined, // Child groups array (undefined if no children)\n };\n\n // Recursively process nested groups (sub-groups inside the current group)\n group.groups.forEach((subGroup) => {\n const childSchema = traverseGroups(subGroup, currentId); // Create schema for sub-group\n schema.childrens?.push(childSchema); // Add the child schema to the parent group's children\n });\n\n return schema; // Return the group schema with its children (if any)\n };\n\n // Initialize an array to hold the top-level groups' schemas\n const treeViewSchemas: AXTreeViewSchema[] = [];\n\n // Process each top-level group and convert it into tree view schema\n groups.forEach((group) => {\n treeViewSchemas.push(traverseGroups(group, parentId)); // Add the schema for each group\n });\n\n // Return the resulting hierarchical structure\n return treeViewSchemas;\n}\n\n/**\n * Recursively searches for a specific `id` in a tree structure and updates its `active` property to `true`.\n * Additionally, ensures all other nodes have their `active` property set to `false`.\n *\n * @param tree - The tree structure to search, represented as an array of AXTreeViewSchema nodes.\n * @param targetId - The `id` of the node to activate.\n * @returns The updated tree structure with the target node activated and others deactivated.\n */\nexport function setActiveByValueField(tree: AXTreeViewSchema[], targetId: string | number): AXTreeViewSchema[] {\n return tree.map((node) => {\n // Set active property for the target node\n node.active = node.id === targetId;\n\n // Recursively process children if they exist\n if (node.childrens && node.childrens.length > 0) {\n node.childrens = setActiveByValueField(node.childrens, targetId);\n }\n\n return node;\n });\n}\n","import { AXToastService } from '@acorex/components/toast';\nimport { AXTreeItemClickBaseEvent, AXTreeViewSchema } from '@acorex/components/tree-view/lib/tree-view.class';\nimport { AXPlatform } from '@acorex/core/platform';\nimport {\n AXPGroupDetails,\n AXPSettingDefinitionItem,\n AXPSettingDefinitionProviderService,\n} from '@acorex/platform/common';\nimport { computed, inject, Injectable, OnDestroy, signal } from '@angular/core';\nimport { ActivatedRoute, NavigationEnd, Router } from '@angular/router';\nimport { filter, Subscription, take } from 'rxjs';\nimport { convertToTreeViewSchema, setActiveByValueField } from './convert-setting-data';\n\n@Injectable({ providedIn: 'root' })\nexport class AXPSettingsViewModel implements OnDestroy {\n private readonly router = inject(Router);\n private readonly settingService = inject(AXPSettingDefinitionProviderService);\n private readonly platform = inject(AXPlatform);\n private readonly toastService = inject(AXToastService);\n\n private activatedRoute: ActivatedRoute;\n\n subscription: Subscription;\n data = signal<AXPSettingDefinitionItem[] | null>(null);\n isMobile = signal(this.platform.is('MD'));\n fullRoute = this.router.url.split('/settings')[0] + '/settings/';\n\n activatedGroup = signal<string | undefined>(undefined);\n dataDetails = computed<AXPGroupDetails | null>(() => {\n if (this.activatedGroup()) {\n return this.fetchGroupDetails(this.activatedGroup()!);\n } else return null;\n });\n\n formattedData = signal<AXTreeViewSchema[]>([]);\n\n constructor() {}\n\n async initializeService(activatedRoute: ActivatedRoute) {\n // Initial setup\n this.activatedRoute = activatedRoute;\n this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe(() => {\n this.updateGroupParam();\n });\n this.updateGroupParam();\n await this.getData();\n }\n\n ngOnDestroy(): void {\n this.subscription.unsubscribe();\n }\n\n // Fetch settings data\n async getData(): Promise<void> {\n const items = await this.settingService.items();\n this.data.set(items);\n this.formattedData.set(convertToTreeViewSchema(this.data()!));\n }\n\n // Fetch group details for preview\n fetchGroupDetails(groupName: string): AXPGroupDetails | null {\n return this.settingService.findGroupDetails(groupName);\n }\n\n // Update group param logic\n private updateGroupParam(): void {\n // If no child routes exist, set groupParam to null\n if (this.activatedRoute.children.length === 0) {\n this.activatedGroup.set(undefined);\n return;\n }\n // Traverse child routes to check for the group parameter\n this.activatedRoute.children.forEach((childRoute) => {\n childRoute.paramMap.pipe(take(1)).subscribe((params) => {\n const group = params.get('group');\n console.log(group);\n this.activatedGroup.set(group || undefined);\n if (group) {\n this.formattedData.set(setActiveByValueField(this.formattedData(), group));\n }\n });\n });\n }\n\n public onChooseGroup(item: AXTreeItemClickBaseEvent) {\n const value = item.data?.['id'];\n this.router.navigate([value], { relativeTo: this.activatedRoute });\n }\n\n context = signal<Record<any, any>>({});\n previousContext = signal<Record<any, any>>({});\n setContext(value: any) {\n this.context.set(value);\n }\n isSaving = signal(false);\n\n canCancel = computed(() => this.isObjectEmpty(this.context()));\n canSave = computed(\n () =>\n !this.isSaving() &&\n !this.isObjectEmpty(this.context()) &&\n !this.areObjectsEqual(this.context(), this.previousContext())\n );\n // Save settings logic\n public async onSaveSettings(): Promise<void> {\n this.previousContext.set(this.context());\n this.isSaving.set(true);\n\n // Simulate an API call\n this.toastService.show({\n color: 'success',\n title: `Saved successfully`,\n location: 'bottom-center',\n closeButton: true,\n timeOut: 3000,\n timeOutProgress: false,\n });\n\n await new Promise((resolve) => setTimeout(resolve, 500));\n this.isSaving.set(false);\n }\n\n // Cancel settings logic\n public onCancelSettings(): void {\n this.context.set({});\n }\n\n // Helper: Check if object is empty\n private isObjectEmpty(obj: object): boolean {\n return Object.keys(obj).length === 0;\n }\n\n // Helper: Compare objects\n private areObjectsEqual<T>(obj1: T, obj2: T): boolean {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n const keys1 = Object.keys(obj1);\n const keys2 = Object.keys(obj2);\n\n if (keys1.length !== keys2.length) {\n return false;\n }\n for (const key of keys1) {\n const keyTyped = key as keyof T;\n if (!obj2.hasOwnProperty(key) || !this.areObjectsEqual(obj1[keyTyped], obj2[keyTyped])) {\n return false;\n }\n }\n return true;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAGA;;;;;;;;AAQG;AACa,SAAA,uBAAuB,CACrC,MAAmC,EACnC,QAA0B,EAAA;;AAG1B,IAAA,MAAM,cAAc,GAAG,CAAC,KAAgC,EAAE,MAAwB,KAAsB;AACtG,QAAA,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI;;AAG5B,QAAA,MAAM,MAAM,GAAqB;YAC/B,EAAE,EAAE,SAAS;YACb,QAAQ,EAAE,MAAM;AAChB,YAAA,IAAI,EAAE,KAAK,CAAC,KAAK;;YAEjB,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YACjC,UAAU,EAAE,KAAK;AACjB,YAAA,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS;SACpD;;QAGD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,KAAI;YAChC,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YACxD,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;AACtC,SAAC,CAAC;QAEF,OAAO,MAAM,CAAC;AAChB,KAAC;;IAG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