diff --git a/src/app/accounting/chart-of-accounts/chart-of-accounts.component.html b/src/app/accounting/chart-of-accounts/chart-of-accounts.component.html index 0a1e250e1..99e3cc26d 100644 --- a/src/app/accounting/chart-of-accounts/chart-of-accounts.component.html +++ b/src/app/accounting/chart-of-accounts/chart-of-accounts.component.html @@ -85,12 +85,9 @@
-
- -
diff --git a/src/app/accounting/chart-of-accounts/chart-of-accounts.component.ts b/src/app/accounting/chart-of-accounts/chart-of-accounts.component.ts index 50b5cdd5b..a059512ef 100644 --- a/src/app/accounting/chart-of-accounts/chart-of-accounts.component.ts +++ b/src/app/accounting/chart-of-accounts/chart-of-accounts.component.ts @@ -18,6 +18,7 @@ import { GLAccountNode } from './gl-account-node.model'; import { GlAccountTreeService } from './gl-account-tree.service'; import { PopoverService } from '../../configuration-wizard/popover/popover.service'; import { ConfigurationWizardService } from '../../configuration-wizard/configuration-wizard.service'; +import { TreeControlService } from 'app/shared/common-logic/tree-control.service'; /** * Chart of accounts component. @@ -43,6 +44,8 @@ export class ChartOfAccountsComponent implements AfterViewInit, OnInit { nestedTreeDataSource: MatTreeNestedDataSource; /** Selected GL Account. */ glAccount: GLAccountNode; + /** Flag to check if tree is expanded or collapsed. */ + isTreeExpanded: boolean = true; /** Paginator for chart of accounts table. */ @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @@ -69,6 +72,7 @@ export class ChartOfAccountsComponent implements AfterViewInit, OnInit { constructor(private glAccountTreeService: GlAccountTreeService, private route: ActivatedRoute, private router: Router, + private treeControlService: TreeControlService, private configurationWizardService: ConfigurationWizardService, private popoverService: PopoverService) { this.route.data.subscribe((data: { chartOfAccounts: any }) => { @@ -177,4 +181,12 @@ export class ChartOfAccountsComponent implements AfterViewInit, OnInit { this.configurationWizardService.showChartofAccounts = true; this.router.navigate(['/accounting']); } + + /** + * Expand and Collapse the tree + */ + toggleExpandCollapse() { + this.isTreeExpanded = this.treeControlService.toggleExpandCollapse(this.nestedTreeControl, this.isTreeExpanded); + } + } diff --git a/src/app/organization/offices/offices.component.html b/src/app/organization/offices/offices.component.html index a3669c251..f4c21f8a9 100644 --- a/src/app/organization/offices/offices.component.html +++ b/src/app/organization/offices/offices.component.html @@ -75,11 +75,8 @@
- -
diff --git a/src/app/organization/offices/offices.component.ts b/src/app/organization/offices/offices.component.ts index 472ec4d73..4932eff77 100644 --- a/src/app/organization/offices/offices.component.ts +++ b/src/app/organization/offices/offices.component.ts @@ -16,6 +16,7 @@ import { OfficeNode } from './office-node.model'; import { NestedTreeControl } from '@angular/cdk/tree'; import { MatTreeNestedDataSource } from '@angular/material/tree'; import { OfficeTreeService } from './office-tree-service.service'; +import { TreeControlService } from 'app/shared/common-logic/tree-control.service'; /** * Offices component. @@ -43,6 +44,8 @@ export class OfficesComponent implements OnInit, AfterViewInit { office: OfficeNode; /** Office data tables. */ dataTablesData: any; + /** Flag to check if tree is expanded or collapsed. */ + isTreeExpanded: boolean = true; /** Paginator for offices table. */ @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @@ -70,6 +73,7 @@ export class OfficesComponent implements OnInit, AfterViewInit { constructor(private route: ActivatedRoute, private router: Router, private officeTreeService: OfficeTreeService, + private treeControlService: TreeControlService, private configurationWizardService: ConfigurationWizardService, private popoverService: PopoverService) { this.route.data.subscribe(( data: { offices: any, officeDataTables: any }) => { @@ -186,4 +190,11 @@ export class OfficesComponent implements OnInit, AfterViewInit { this.router.navigate(['/organization']); } + /** + * Expand and Collapse the tree + */ + toggleExpandCollapse() { + this.isTreeExpanded = this.treeControlService.toggleExpandCollapse(this.nestedTreeControl, this.isTreeExpanded); + } + } diff --git a/src/app/shared/common-logic/tree-control.service.ts b/src/app/shared/common-logic/tree-control.service.ts new file mode 100644 index 000000000..e70aaf291 --- /dev/null +++ b/src/app/shared/common-logic/tree-control.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { NestedTreeControl } from '@angular/cdk/tree'; + +@Injectable({ + providedIn: 'root' +}) +export class TreeControlService { + constructor() { } + + toggleExpandCollapse(nestedTreeControl: NestedTreeControl, isTreeExpanded: boolean) { + if (isTreeExpanded) { + nestedTreeControl.collapseAll(); + } else { + nestedTreeControl.expandAll(); + } + // Toggle the state + return !isTreeExpanded; + } +}