diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.html index 215c92b2..b38e440d 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.html @@ -1 +1,3 @@ - + diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.ts index e22cd0d4..52b82887 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/organization.component.ts @@ -1,5 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { ucapAnimations } from '@ucap-webmessenger/ui'; +import { Observable } from 'rxjs'; +import { DeptInfo } from '@ucap-webmessenger/protocol-query'; +import { Store, select } from '@ngrx/store'; +import { NGXLogger } from 'ngx-logger'; + +import * as AppStore from '@app/store'; @Component({ selector: 'app-layout-chat-left-sidenav-organization', @@ -8,7 +14,13 @@ import { ucapAnimations } from '@ucap-webmessenger/ui'; animations: ucapAnimations }) export class OrganizationComponent implements OnInit { - constructor() {} + departmentInfoList$: Observable; - ngOnInit() {} + constructor(private store: Store, private logger: NGXLogger) {} + + ngOnInit() { + this.departmentInfoList$ = this.store.pipe( + select(AppStore.MessengerSelector.QuerySelector.departmentInfoList) + ); + } } diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts index 19e0af25..fb4a9e3d 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts @@ -127,29 +127,6 @@ export class Effects { { dispatch: false } ); - // buddy2SuccessPostRoom$ = createEffect(() => - // this.actions$.pipe( - // ofType(buddy2Success), - // map(action => { - // const loginInfo = this.sessionStorageService.get( - // KEY_LOGIN_INFO - // ); - - // return loginInfo.localeCode; - // }), - // withLatestFrom( - // this.store.pipe( - // select(state => { - // return state.messenger.sync.roomSyncDate as string; - // }) - // ) - // ), - // map(([localeCode, roomSyncDate]) => - // room({ syncDate: roomSyncDate, localeCode }) - // ) - // ) - // ); - room$ = createEffect( () => { let roomList: RoomInfo[]; @@ -203,12 +180,6 @@ export class Effects { break; case SSVC_TYPE_SYNC_ROOM_RES: { - this.logger.debug( - 'roomList', - roomList, - 'roomUserInfoMap', - roomUserInfoMap - ); this.store.dispatch( roomSuccess({ roomList, diff --git a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.html b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.html index e8738470..6d4f7b5b 100644 --- a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.html +++ b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.html @@ -1,8 +1,35 @@ - - - - - - - - + + + + {{ node.title }} + + + + + + + + {{ treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right' }} + + + {{ node.title }} + + + + + + + + + diff --git a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.scss b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.scss index e69de29b..a1ef3408 100644 --- a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.scss +++ b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.scss @@ -0,0 +1,12 @@ +.organization-tree { + ul, + li { + margin-top: 0; + margin-bottom: 0; + list-style-type: none; + } + + .organization-tree-node-invisible { + display: none; + } +} diff --git a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.ts b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.ts index cc3d442b..d517a81b 100644 --- a/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.ts +++ b/projects/ucap-webmessenger-ui-organization/src/lib/components/tree.component.ts @@ -1,4 +1,42 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { + Component, + OnInit, + Input, + ChangeDetectorRef, + ViewChild +} from '@angular/core'; +import { DeptInfo } from '@ucap-webmessenger/protocol-query'; +import { MatTreeNestedDataSource, MatTree } from '@angular/material'; +import { NestedTreeControl } from '@angular/cdk/tree'; +import { BehaviorSubject } from 'rxjs'; +import { NGXLogger } from 'ngx-logger'; + +export class OraganizationNode { + private childNodeBehaviorSubject: BehaviorSubject; + private childNodeList: OraganizationNode[]; + + get title(): string { + return this.deptInfo.name; + } + + get children(): BehaviorSubject { + if (!this.childNodeBehaviorSubject) { + this.childNodeBehaviorSubject = new BehaviorSubject( + undefined === this.childNodeList ? [] : this.childNodeList + ); + } + return this.childNodeBehaviorSubject; + } + + constructor(public deptInfo: DeptInfo) {} + + addChild(childNode: OraganizationNode) { + if (!this.childNodeList) { + this.childNodeList = []; + } + this.childNodeList.push(childNode); + } +} @Component({ selector: 'ucap-organization-tree', @@ -7,9 +45,62 @@ import { Component, OnInit, Input } from '@angular/core'; }) export class TreeComponent implements OnInit { @Input() - organizationList: any[]; + set oraganizationList(deptInfo: DeptInfo[]) { + const nodeMap = new Map(); + const rootNodeList: OraganizationNode[] = []; + const remainChildNodeList: OraganizationNode[] = []; - constructor() {} + deptInfo.forEach(value => { + const node = new OraganizationNode(value); + if (nodeMap.has(value.seq)) { + this.logger.warn('duplicate seq', value.seq); + return; + } + nodeMap.set(value.seq, node); + + if (0 === value.parentSeq) { + rootNodeList.push(node); + return; + } + + if (nodeMap.has(value.parentSeq)) { + nodeMap.get(value.parentSeq).addChild(node); + } else { + remainChildNodeList.push(node); + } + }); + + remainChildNodeList.forEach(value => { + if (nodeMap.has(value.deptInfo.parentSeq)) { + nodeMap.get(value.deptInfo.parentSeq).addChild(value); + } + }); + + this.dataSource.data = rootNodeList; + } + + @ViewChild('orgranizationTree', { static: true }) + orgranizationTree: MatTree; + + levels = new Map(); + treeControl: NestedTreeControl; + + dataSource: MatTreeNestedDataSource; + + constructor( + private changeDetectorRef: ChangeDetectorRef, + private logger: NGXLogger + ) { + this.treeControl = new NestedTreeControl( + this.getChildren + ); + this.dataSource = new MatTreeNestedDataSource(); + } ngOnInit() {} + + getChildren = (node: OraganizationNode) => node.children; + + hasChildren = (index: number, node: OraganizationNode) => + 0 < node.children.value.length; } diff --git a/projects/ucap-webmessenger-ui-organization/src/lib/ucap-ui-organization.module.ts b/projects/ucap-webmessenger-ui-organization/src/lib/ucap-ui-organization.module.ts index 0a251a63..2e2bf6fb 100644 --- a/projects/ucap-webmessenger-ui-organization/src/lib/ucap-ui-organization.module.ts +++ b/projects/ucap-webmessenger-ui-organization/src/lib/ucap-ui-organization.module.ts @@ -2,7 +2,9 @@ import { NgModule, ModuleWithProviders } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ReactiveFormsModule } from '@angular/forms'; -import { MatExpansionModule } from '@angular/material/expansion'; +import { MatButtonModule } from '@angular/material/button'; +import { MatIconModule } from '@angular/material/icon'; +import { MatTreeModule } from '@angular/material/tree'; import { TreeComponent } from './components/tree.component'; @@ -10,7 +12,13 @@ const COMPONENTS = [TreeComponent]; const SERVICES = []; @NgModule({ - imports: [CommonModule, ReactiveFormsModule, MatExpansionModule], + imports: [ + CommonModule, + ReactiveFormsModule, + MatButtonModule, + MatIconModule, + MatTreeModule + ], exports: [...COMPONENTS], declarations: [...COMPONENTS] })