SUPPORT-9133: перенос доработок из ervu-dashboard
This commit is contained in:
parent
8aa05afa48
commit
fed8b9c27f
2 changed files with 140 additions and 14 deletions
|
|
@ -0,0 +1,5 @@
|
||||||
|
export enum TreeValuesCacheStrategy {
|
||||||
|
BY_PAGE_OBJECT_ID = "BY_PAGE_OBJECT_ID",
|
||||||
|
BY_OBJECT_NAME = "BY_OBJECT_NAME",
|
||||||
|
BY_CUSTOM_NAME = "BY_CUSTOM_NAME",
|
||||||
|
}
|
||||||
|
|
@ -2,19 +2,29 @@ import {
|
||||||
ChangeDetectionStrategy,
|
ChangeDetectionStrategy,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
ElementRef
|
ElementRef,
|
||||||
|
Input
|
||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import {
|
import {
|
||||||
|
AdvancedProperty,
|
||||||
Event,
|
Event,
|
||||||
InputControl,
|
InputControl,
|
||||||
UserService,
|
LocalStorageService,
|
||||||
Visible
|
NotNull,
|
||||||
|
PageContextHolder,
|
||||||
|
PageObjectUtils,
|
||||||
|
TaskParamsProvider,
|
||||||
|
Visible,
|
||||||
|
WebbpmStorage
|
||||||
} from "@webbpm/base-package";
|
} from "@webbpm/base-package";
|
||||||
|
|
||||||
import {TreeItemDto} from "../../generated/component/model/TreeItemDto";
|
import {TreeItemDto} from "../../generated/component/model/TreeItemDto";
|
||||||
import {TreeItemRpcService} from "../../generated/component/rpc/TreeItemRpcService";
|
import {TreeItemRpcService} from "../../generated/component/rpc/TreeItemRpcService";
|
||||||
import {DropdownTreeviewSelectI18n} from "../external/ngx-treeview/dropdown-treeview-select/dropdown-treeview-select-i18n";
|
import {
|
||||||
|
DropdownTreeviewSelectI18n
|
||||||
|
} from "../external/ngx-treeview/dropdown-treeview-select/dropdown-treeview-select-i18n";
|
||||||
import {TreeItem, TreeviewItem} from "ngx-treeview";
|
import {TreeItem, TreeviewItem} from "ngx-treeview";
|
||||||
|
import {TreeValuesCacheStrategy} from "../enum/TreeValuesCacheStrategy";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
|
|
@ -26,44 +36,118 @@ import {TreeItem, TreeviewItem} from "ngx-treeview";
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class DropdownTreeViewComponent extends InputControl {
|
export class DropdownTreeViewComponent extends InputControl {
|
||||||
|
@Input()
|
||||||
|
@AdvancedProperty()
|
||||||
|
public treeValuesCacheStrategy: TreeValuesCacheStrategy;
|
||||||
|
@Visible("treeValuesCacheStrategy == TreeValuesCacheStrategy.BY_CUSTOM_NAME")
|
||||||
|
@NotNull("treeValuesCacheStrategy == TreeValuesCacheStrategy.BY_CUSTOM_NAME")
|
||||||
|
@AdvancedProperty()
|
||||||
|
public treeValuesCustomName: string;
|
||||||
|
@Visible("false")
|
||||||
|
public cachedValue: TreeItemDto;
|
||||||
|
|
||||||
public collapseLevel: number;
|
public collapseLevel: number;
|
||||||
public maxHeight: number;
|
public maxHeight: number;
|
||||||
@Visible("false")
|
@Visible("false")
|
||||||
public items: TreeviewItem[];
|
public items: TreeviewItem[];
|
||||||
@Visible("false")
|
@Visible("false")
|
||||||
public value: any;
|
public value: TreeItemDto;
|
||||||
|
|
||||||
@Visible("false")
|
@Visible("false")
|
||||||
public valueChangeEvent: Event<TreeItemDto> = new Event<TreeItemDto>();
|
public valueChangeEvent: Event<TreeItemDto> = new Event<TreeItemDto>();
|
||||||
|
|
||||||
private rpcService: TreeItemRpcService;
|
private rpcService: TreeItemRpcService;
|
||||||
|
|
||||||
constructor(el: ElementRef, cd: ChangeDetectorRef,
|
private localStorageService: LocalStorageService;
|
||||||
private i18n: DropdownTreeviewSelectI18n) {
|
private taskParamsProvider: TaskParamsProvider;
|
||||||
|
private pageContextHolder: PageContextHolder;
|
||||||
|
private webbpmStorage: WebbpmStorage;
|
||||||
|
private storageKey: string;
|
||||||
|
private rootValues: TreeItemDto[];
|
||||||
|
|
||||||
|
constructor(el: ElementRef, cd: ChangeDetectorRef, private i18n: DropdownTreeviewSelectI18n) {
|
||||||
super(el, cd);
|
super(el, cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public initialize() {
|
public initialize() {
|
||||||
super.initialize();
|
super.initialize();
|
||||||
this.rpcService = this.getScript(TreeItemRpcService);
|
this.rpcService = this.getScript(TreeItemRpcService);
|
||||||
|
|
||||||
|
this.taskParamsProvider = this.injector.get(TaskParamsProvider);
|
||||||
|
this.localStorageService = this.injector.get(LocalStorageService);
|
||||||
|
this.pageContextHolder = this.injector.get(PageContextHolder);
|
||||||
|
this.webbpmStorage =
|
||||||
|
this.getTreeValuesStorage(this.treeValuesCacheStrategy, this.treeValuesCustomName);
|
||||||
|
this.cachedValue = this.getCachedValue();
|
||||||
this.loadTreeItems();
|
this.loadTreeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getTreeValuesStorage(treeValuesCacheStrategy: TreeValuesCacheStrategy,
|
||||||
|
customKeyName: string) {
|
||||||
|
if (!treeValuesCacheStrategy) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch (treeValuesCacheStrategy) {
|
||||||
|
case TreeValuesCacheStrategy.BY_PAGE_OBJECT_ID:
|
||||||
|
this.storageKey = PageObjectUtils.getPageObjectKey(this);
|
||||||
|
return this.readWebbpmStorage(this.storageKey);
|
||||||
|
case TreeValuesCacheStrategy.BY_OBJECT_NAME:
|
||||||
|
this.storageKey = this.getObjectName();
|
||||||
|
return this.readWebbpmStorage(this.storageKey);
|
||||||
|
case TreeValuesCacheStrategy.BY_CUSTOM_NAME:
|
||||||
|
this.storageKey = customKeyName;
|
||||||
|
return this.readWebbpmStorage(this.storageKey);
|
||||||
|
default:
|
||||||
|
throw new Error("Unknown tree values storage type = " + treeValuesCacheStrategy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readWebbpmStorage(treeStorageKey: string) {
|
||||||
|
if (this.pageContextHolder.isPageInBpmnContext()) {
|
||||||
|
treeStorageKey = treeStorageKey + "$" + this.taskParamsProvider.processInstanceId
|
||||||
|
}
|
||||||
|
return this.localStorageService.readTemporalWebbpmStorage(treeStorageKey);
|
||||||
|
}
|
||||||
|
|
||||||
@Visible()
|
@Visible()
|
||||||
public loadTreeItems(): void {
|
public loadTreeItems(): void {
|
||||||
this.rpcService.loadTreeData()
|
this.rpcService.loadTreeData()
|
||||||
.then((res: TreeItemDto[]) => {
|
.then((res: TreeItemDto[]) => {
|
||||||
this.items = res.map(value => new TreeviewItem(this.createTreeItem(value)));
|
this.items = res.map(value => new TreeviewItem(this.createTreeItem(value)));
|
||||||
|
this.rootValues = res;
|
||||||
const rootItem = this.items[0];
|
const rootItem = this.items[0];
|
||||||
this.i18n.selectedItem = rootItem;
|
if (this.cachedValue) {
|
||||||
this.value = rootItem ? rootItem.value : rootItem;
|
const matchedItem = this.findTreeItemByValue(this.items, this.cachedValue);
|
||||||
|
if (matchedItem) {
|
||||||
|
this.i18n.selectedItem = matchedItem;
|
||||||
|
this.value = matchedItem.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.i18n.selectedItem = rootItem;
|
||||||
|
this.value = rootItem.value;
|
||||||
|
}
|
||||||
this.doCollapseLevel();
|
this.doCollapseLevel();
|
||||||
this.onValueChange(this.value);
|
this.onValueChange(this.value);
|
||||||
this.cd.markForCheck();
|
this.cd.markForCheck();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findTreeItemByValue(rootItems: TreeviewItem[], valueToFind: any): TreeviewItem | null {
|
||||||
|
for (const item of rootItems) {
|
||||||
|
if (JSON.stringify(item.value) === JSON.stringify(valueToFind)) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
if (item.children) {
|
||||||
|
const found = this.findTreeItemByValue(item.children, valueToFind);
|
||||||
|
if (found) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private createTreeItem(treeItemDto: TreeItemDto): TreeItem {
|
private createTreeItem(treeItemDto: TreeItemDto): TreeItem {
|
||||||
let treeItem: TreeItem;
|
let treeItem: TreeItem;
|
||||||
if (treeItemDto) {
|
if (treeItemDto) {
|
||||||
|
|
@ -84,6 +168,7 @@ export class DropdownTreeViewComponent extends InputControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public onValueChange($event: any) {
|
public onValueChange($event: any) {
|
||||||
|
this.setCachedValue(this.value);
|
||||||
this.valueChangeEvent.trigger($event);
|
this.valueChangeEvent.trigger($event);
|
||||||
this.applyListener(this.changeListeners);
|
this.applyListener(this.changeListeners);
|
||||||
}
|
}
|
||||||
|
|
@ -113,20 +198,51 @@ export class DropdownTreeViewComponent extends InputControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected setCachedValue(newValue: TreeItemDto): void {
|
||||||
|
if (this.webbpmStorage) {
|
||||||
|
this.webbpmStorage.put(this.storageKey, newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getCachedValue(): TreeItemDto {
|
||||||
|
if (this.webbpmStorage) {
|
||||||
|
return this.webbpmStorage.get(this.storageKey);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
getPresentationValue(): string | number | boolean {
|
getPresentationValue(): string | number | boolean {
|
||||||
return this.value;
|
return this.value ? this.value.label : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue(): any {
|
getValue(): any {
|
||||||
return this.value;
|
return this.value ? this.value.id : this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getValueAsModel(): any {
|
getValueAsModel(): TreeItemDto {
|
||||||
return this.value ? this.value : null;
|
return this.value ? this.value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(value: any): any {
|
setValue(value: any): void {
|
||||||
this.value = value;
|
const foundValue: TreeItemDto = this.findValueInRootsById(value);
|
||||||
|
if (foundValue) {
|
||||||
|
this.value = foundValue;
|
||||||
|
this.onValueChange(this.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private findValueInRootsById(id: any): TreeItemDto {
|
||||||
|
let searchArray: TreeItemDto[] = this.rootValues.slice();
|
||||||
|
while (searchArray.length > 0) {
|
||||||
|
const current = searchArray.shift();
|
||||||
|
if (current.id == id) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
if (current.children && current.children.length > 0) {
|
||||||
|
searchArray.push(...current.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange() {
|
onChange() {
|
||||||
|
|
@ -134,6 +250,11 @@ export class DropdownTreeViewComponent extends InputControl {
|
||||||
this.valueChangeEvent.trigger(this.value);
|
this.valueChangeEvent.trigger(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addChangeListener(onChangeFunction: Function): void {
|
||||||
|
super.addChangeListener(onChangeFunction);
|
||||||
|
onChangeFunction();
|
||||||
|
}
|
||||||
|
|
||||||
subscribeToModelChange() {
|
subscribeToModelChange() {
|
||||||
//empty because there is no ngModel here
|
//empty because there is no ngModel here
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue