This is an automated email from the ASF dual-hosted git repository. liuxun pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push: new ea4d1a3 SUBMARINE-470. [WEB]Implement database connection in department page ea4d1a3 is described below commit ea4d1a38024216c7289d953f21521d43426e56f2 Author: jasoonn <b05901...@ntu.edu.tw> AuthorDate: Tue May 5 10:17:28 2020 +0800 SUBMARINE-470. [WEB]Implement database connection in department page ### What is this PR for? Implement database connection in department page with Angular. ### What type of PR is it? [Feature] ### Todos ### What is the Jira issue? https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-470?filter=allopenissues ### How should this be tested? https://travis-ci.org/github/apache/submarine/builds/683207421 ### Screenshots (if appropriate) ![](https://i.imgur.com/XafuQyg.gif) ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: jasoonn <b05901...@ntu.edu.tw> Closes #276 from jasoonn/SUBMARINE-470 and squashes the following commits: f080cc9 [jasoonn] update --- .../apache/submarine/integration/departmentIT.java | 10 +- .../src/app/interfaces/sys-dept-item.ts | 33 ++ .../manager/department/department.component.html | 57 ++-- .../manager/department/department.component.ts | 339 +++++++++++++-------- .../src/app/services/department.service.ts | 63 ++++ 5 files changed, 345 insertions(+), 157 deletions(-) diff --git a/submarine-test/test-e2e/src/test/java/org/apache/submarine/integration/departmentIT.java b/submarine-test/test-e2e/src/test/java/org/apache/submarine/integration/departmentIT.java index 32764b4..846f00c 100644 --- a/submarine-test/test-e2e/src/test/java/org/apache/submarine/integration/departmentIT.java +++ b/submarine-test/test-e2e/src/test/java/org/apache/submarine/integration/departmentIT.java @@ -62,12 +62,12 @@ public class departmentIT extends AbstractSubmarineIT{ // Test create new department pollingWait(By.xpath("//button[@id='btnAddDepartment']"), MAX_BROWSER_TIMEOUT_SEC).click(); - pollingWait(By.xpath("//input[@id='codeInput']"), MAX_BROWSER_TIMEOUT_SEC).sendKeys("e2e test code"); - pollingWait(By.xpath("//input[@id='nameInput']"), MAX_BROWSER_TIMEOUT_SEC).sendKeys("e2e test name"); + pollingWait(By.xpath("//input[@id='codeInput'] "), MAX_BROWSER_TIMEOUT_SEC).sendKeys("e2e Test"); + pollingWait(By.xpath("//input[@id='nameInput']"), MAX_BROWSER_TIMEOUT_SEC).sendKeys("e2e Test"); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[@id='validCode']"))); pollingWait(By.xpath("//button[@id='btnSubmit']"), MAX_BROWSER_TIMEOUT_SEC).click(); - - //TODO(jasoonn): Assert whether new project be created - + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//nz-table[@id='departmentTable']"))); + Assert.assertEquals(pollingWait(By.xpath("//td[contains(., 'e2e Test')]"), MAX_BROWSER_TIMEOUT_SEC).isDisplayed(), true); } } diff --git a/submarine-workbench/workbench-web-ng/src/app/interfaces/sys-dept-item.ts b/submarine-workbench/workbench-web-ng/src/app/interfaces/sys-dept-item.ts new file mode 100644 index 0000000..563320e --- /dev/null +++ b/submarine-workbench/workbench-web-ng/src/app/interfaces/sys-dept-item.ts @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export interface SysDeptItem { + key: number; + deptCode: string; + description: string; + deleted: number; + deptName: string; + sortOrder: number; + children: SysDeptItem[]; + id: string; + parent?: SysDeptItem + parentCode?: string; + level?: number; + expand?: boolean; +} diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.html b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.html index 2cb5571..4cde529 100644 --- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.html +++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.html @@ -17,7 +17,6 @@ ~ under the License. --> - <nz-card> <div class="department-header"> <form nz-form [nzLayout]="'inline'" [formGroup]="dapartmentDictForm"> @@ -39,7 +38,7 @@ <i nz-icon nzType="search"></i> Query </button> - <button nz-button id='btnAddDepartment' style="margin-left: 8px" (click)="isVisible=true;editMode = false;"> + <button nz-button id='btnAddDepartment' style="margin-left: 8px" (click)="addDept()"> <i nz-icon nzType="plus"></i> Add </button> @@ -48,7 +47,7 @@ </form> </div> - <nz-table *ngIf="isLoading==false" #expandTable nzBordered [nzData]="isExpandTable ? listOfMapData : filterArr"> + <nz-table *ngIf="isLoading==false" id='departmentTable' #expandTable nzBordered [nzData]="isExpandTable ? listOfMapData : filterArr"> <thead> <tr> <th nzWidth="15%">Code</th> @@ -65,21 +64,21 @@ <tr *ngIf="(item.parent && item.parent.expand) || !item.parent"> <td [nzIndentSize]="item.level * 20" - [nzShowExpand]="item.children!==none" + [nzShowExpand]="item.children!==null" [(nzExpand)]="item.expand" (nzExpandChange)="collapse(mapOfExpandedData[data.key], item, $event)" > - {{ item.title }} + {{ item.deptCode }} </td> - <td>{{ item.code }}</td> + <td>{{ item.deptName }}</td> <td>{{ showParent(item) }}</td> <td>{{ item.description }}</td> - <td><nz-tag [nzColor]="item.status==='Deleted'? 'red' : 'blue'">{{ item.status }}</nz-tag></td> + <td><nz-tag [nzColor]="item.deleted===1? 'red' : 'blue'">{{ item.deleted? 'Deleted' : 'Available' }}</nz-tag></td> <td> <button nz-button nzType="link" (click)="editDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Edit</button> | - <button *ngIf="item.status==='Available'" nz-button nzType="link" (click)="deleteDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Delete</button> - <button *ngIf="item.status==='Deleted'" nz-button nzType="link" (click)="restoreDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Restore</button> + <button *ngIf="item.deleted===0" nz-button nzType="link" (click)="deleteDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Delete</button> + <button *ngIf="item.deleted===1" nz-button nzType="link" (click)="restoreDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Restore</button> </td> </tr> </ng-container> @@ -89,16 +88,16 @@ <tbody *ngIf="!isExpandTable"> <ng-container *ngFor="let item of expandTable.data"> <tr> - <td>{{ item.title }}</td> - <td>{{ item.code }}</td> + <td>{{ item.deptName }}</td> + <td>{{ item.deptCode }}</td> <td>{{ showParent(item) }}</td> <td>{{ item.description }}</td> - <td><nz-tag [nzColor]="item.status==='Deleted'? 'red' : 'blue'">{{ item.status }}</nz-tag></td> + <td><nz-tag [nzColor]="item.deleted===1? 'red' : 'blue'">{{ item.deleted? 'Available': 'Deleted' }}</nz-tag></td> <td> <button nz-button nzType="link" (click)="editDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Edit</button> | - <button *ngIf="item.status==='Available'" nz-button nzType="link" (click)="deleteDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Delete</button> - <button *ngIf="item.status==='Deleted'" nz-button nzType="link" (click)="restoreDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Restore</button> + <button *ngIf="item.deleted===0" nz-button nzType="link" (click)="deleteDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Delete</button> + <button *ngIf="item.deleted===1" nz-button nzType="link" (click)="restoreDepartment(item)" style="padding-left: 2px;padding-right: 5px;">Restore</button> </td> </tr> </ng-container> @@ -118,7 +117,8 @@ > <form [formGroup]="newDepartmentForm"> <div> - <label class="form-label"><span class="red-star">* </span> Code:</label> + <label *ngIf="newDepartmentForm.get('code').valid" id='validCode' class="form-label"><span class="red-star">* </span> Code:</label> + <label *ngIf="!newDepartmentForm.get('code').valid" id='invalidCode' class="form-label"><span class="red-star">* </span> Code:</label> <input nz-input id='codeInput' @@ -128,24 +128,27 @@ class="form-control" formControlName="code"> </div> + <h4 style="color: red;margin-left: 22%;">{{ (newDepartmentForm.get('code').valid || (!editMode&&!newDepartmentForm.get('code').touched)) ? "" : formCodeErrMsg }}<br></h4> <div> - <label class="form-label"><span class="red-star">* </span> Name:</label> + <label class="form-label" style="margin-top: 5px;"><span class="red-star">* </span> Name:</label> <input nz-input id='nameInput' type="text" placeholder="Please enter department name" - style="margin-top: 25px;width: 70%;" + style="margin-top: 1px;width: 70%;" class="form-control" formControlName="name" > </div> + <h4 style="color: red;margin-left: 22%;">{{ (newDepartmentForm.get('name').valid || (!editMode&&!newDepartmentForm.get('name').touched)) ? "" : "Please entry department name!" }}<br></h4> <div> - <label class="form-label"> Parent:</label> + <label class="form-label" style="margin-top: 5px;"> Parent:</label> <nz-tree-select - style="width: 70%;margin-top: 25px;" + [ngStyle]="{'border': parentCodeValid? '0px' : '1px solid red'}" + style="width: 70%;margin-top: 1px;" [nzExpandedKeys]="expandKeys" - [nzNodes]="listOfMapData" + [nzNodes]="sysTreeParent" nzShowSearch nzPlaceHolder="Please select" class="form-control" @@ -153,29 +156,31 @@ > </nz-tree-select> </div> + <h4 style="color: red;margin-left: 22%;">{{ parentCodeValid ? "" : "Cannot change parent to itself or its child!" }}<br></h4> <div> - <label class="form-label" > Sort:</label> - <nz-input-number class="form-control" formControlName="sort" style="margin-top: 25px;"></nz-input-number> + <label class="form-label" style="margin-top: 5px;"> Sort:</label> + <nz-input-number class="form-control" formControlName="sort" style="margin-top: 1px;"></nz-input-number> </div> <div> <label class="form-label" > Status:</label> - <nz-switch nzCheckedChildren="Available" nzUnCheckedChildren="Deleted" class="form-control" formControlName="status" style="margin-top: 30px;"></nz-switch> + <nz-switch nzCheckedChildren="Available" nzUnCheckedChildren="Deleted" class="form-control" formControlName="deleted" style="margin-top: 30px;"></nz-switch> </div> <div> <label class="form-label">Description:</label> <textarea rows="6" nz-input class="form-control" formControlName="description" style="width: 70%;margin-top: 25px;"></textarea> </div> - </form> <div class="footer"> <button type="button" (click)="isVisible = false;" class="ant-btn" style="margin-right: 8px;"><span>Cancel</span></button> <button - type="button" + nz-button + type="button" + [nzLoading]="submitBtnIsLoading" (click)="submitDepartment()" class="ant-btn ant-btn-primary" id='btnSubmit' - [disabled]="!(newDepartmentForm.get('name')).valid || !(newDepartmentForm.get('code').valid)" + [disabled]="!(newDepartmentForm.get('name')).valid || !(newDepartmentForm.get('code').valid) || !parentCodeValid" ><span>Submit</span></button> </div> </nz-drawer> diff --git a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.ts b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.ts index fe7753f..e2d613e 100644 --- a/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.ts +++ b/submarine-workbench/workbench-web-ng/src/app/pages/workbench/manager/department/department.component.ts @@ -18,19 +18,12 @@ */ import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; - -export interface TreeNodeInterface { - key: number; - title: string; //need to be title so that can be displayed in ng tree node - code: string; - description: string; - status: string; - level?: number; - expand?: boolean; - children?: TreeNodeInterface[]; - parent?: TreeNodeInterface; -} +import { FormGroup, FormControl, Validators, ValidationErrors } from '@angular/forms'; +import { DepartmentService } from '@submarine/services'; +import { SysDeptItem } from '@submarine/interfaces/sys-dept-item'; +import { SysDeptSelect } from '@submarine/interfaces/sys-dept-select'; +import { NzMessageService } from 'ng-zorro-antd'; + @Component({ selector: 'app-department', @@ -38,106 +31,47 @@ export interface TreeNodeInterface { styleUrls: ['./department.component.scss'] }) export class DepartmentComponent implements OnInit { + //About display departments + sysTreeParent: SysDeptSelect[] = []; + sysDeptTreeList: SysDeptItem[] = []; + listOfMapData: SysDeptItem[] = []; isLoading = true; dapartmentDictForm: FormGroup; + isExpandTable = true; + filterArr: SysDeptItem[] = []; + mapOfExpandedData: { [key: string]: SysDeptItem[] } = {}; + //About new or edit department newDepartmentForm: FormGroup; editMode = false; - editNode: TreeNodeInterface; + editNode: SysDeptItem; + submitBtnIsLoading = false; + formCodeErrMsg = ""; + parentCodeValid = true; isVisible = false; - isExpandTable = true; - filterArr: TreeNodeInterface[] = [ - { - key: 120, - title: 'ABCD', - code: '123', - description: 'Company ABCD ', - status: 'Deleted' - } - ]; - - listOfMapData: TreeNodeInterface[] = [ - { - key: 1, - title: 'A', - code: '123', - description: 'Company A', - status: 'Available', - children: [ - { - key: 11, - title: 'AA', - code: '123', - description: 'Company AA', - status: 'Deleted' - }, - { - key: 12, - title: 'AB', - code: '123', - description: 'Company AB', - status: 'Deleted', - children: [ - { - key: 121, - title: 'ABC', - code: '123', - description: 'Company ABC', - status: 'Deleted', - children: [ - { - key: 120, - title: 'ABCD', - code: '123', - description: 'Company ABCD ', - status: 'Deleted' - } - ] - } - ] - } - ] - }, - { - key: 123, - title: 'E', - code: '999', - description: 'Company E', - status: 'Deleted' - } - ]; - constructor() { } + constructor(private departmentService: DepartmentService, private nzMessageService:NzMessageService) { } - //TODO(jasoonn): Load departments data ngOnInit() { this.dapartmentDictForm = new FormGroup({ 'departmentName': new FormControl(''), 'departmentCode': new FormControl('') }); this.newDepartmentForm = new FormGroup({ - 'code': new FormControl(null, Validators.required), + 'code': new FormControl(null, [Validators.required, this.checkRequire.bind(this), this.checkIfParent.bind(this)], this.duplicateDeptCodeCheck.bind(this)), 'name': new FormControl(null, Validators.required), - 'parent': new FormControl(null), + 'parent': new FormControl(null, this.checkEditParent.bind(this)), 'sort': new FormControl(0), - 'status': new FormControl(null), - 'description' : new FormControl(null) - }); - setTimeout(() => { - this.isLoading = false; - }, 500); - this.listOfMapData.forEach(item => { - this.mapOfExpandedData[item.key] = this.convertTreeToList(item); + 'deleted': new FormControl(null), + 'description' : new FormControl("") }); - - + this.loadDepartment(); } queryDepartment(){ this.filterArr = []; Object.keys(this.mapOfExpandedData).forEach(item => { this.mapOfExpandedData[item].forEach(node => { - if (node.title.includes(this.dapartmentDictForm.get('departmentName').value) && node.code.includes(this.dapartmentDictForm.get('departmentCode').value)){ - console.log('bingo', node) + if (node.deptName.includes(this.dapartmentDictForm.get('departmentName').value) && node.deptCode.includes(this.dapartmentDictForm.get('departmentCode').value)){ this.filterArr.push(node); } }); @@ -146,52 +80,115 @@ export class DepartmentComponent implements OnInit { this.filterArr=[...this.filterArr]; } - //TODO(jasoonn): Create or edit department, need to communicate with db submitDepartment(){ - //Edit department + this.submitBtnIsLoading = true; if (this.editMode === true){ - this.editNode.title = this.newDepartmentForm.get('name').value; - this.editNode.code = this.newDepartmentForm.get('code').value; + this.editNode.deptName = this.newDepartmentForm.get('name').value; + this.editNode.deptCode = this.newDepartmentForm.get('code').value; this.editNode.description = this.newDepartmentForm.get('description').value; - this.editNode.status = this.newDepartmentForm.get('status').value ? 'Available' : 'Deleted'; + this.editNode.deleted = this.newDepartmentForm.get('deleted').value ? 0 : 1; + this.editNode.sortOrder = this.newDepartmentForm.get('sort').value; + this.editNode.parentCode = this.newDepartmentForm.get('parent').value; + this.setDepartment(this.editNode); } else{ - console.log('createDepartment'); + this.departmentService.createDept({ + deptName: this.newDepartmentForm.get('name').value, + deptCode: this.newDepartmentForm.get('code').value, + sortOrder: this.newDepartmentForm.get('sort').value, + description: this.newDepartmentForm.get('description').value, + deleted: this.newDepartmentForm.get('deleted').value ? 0 : 1, + parentCode: this.newDepartmentForm.get('parent').value + }).subscribe(() => { + this.nzMessageService.success('Add department success!'); + this.loadDepartment(); + this.isVisible = false; + this.submitBtnIsLoading = false; + }, err => { + this.nzMessageService.error(err.message); + this.submitBtnIsLoading = false; + }); } - this.isVisible = false; } - //TODO(jasoonn): Delete the department, need to comunicate with db - deleteDepartment(node: TreeNodeInterface){ - node.status = 'Deleted'; + addDept(){ + this.departmentService.fetchSysDeptSelect().subscribe(list => { + this.sysTreeParent = list; + }); + this.parentCodeValid = true; + this.newDepartmentForm = new FormGroup({ + 'code': new FormControl("", [Validators.required, this.checkRequire.bind(this), this.checkIfParent.bind(this)], this.duplicateDeptCodeCheck.bind(this)), + 'name': new FormControl(null, Validators.required), + 'parent': new FormControl(null), + 'sort': new FormControl(0), + 'deleted': new FormControl(null), + 'description' : new FormControl("") + }); + this.formCodeErrMsg = "Please entry department code!"; + this.isVisible=true; + this.editMode = false; + } + + loadDepartment(){ + this.departmentService.fetchSysDeptList().subscribe(list => { + this.listOfMapData = list; + this.listOfMapData.forEach(item => { + this.mapOfExpandedData[item.key] = this.convertTreeToList(item); + }); + this.isLoading = false; + }); } - //TODO(jasoonn): Restore the department, need to comunicate with db - restoreDepartment(node: TreeNodeInterface){ - node.status = 'Available'; + setDepartment(node: SysDeptItem){ + this.departmentService.editDept( + { + deptCode: node.deptCode, + deptName: node.deptName, + sortOrder: node.sortOrder, + id: node.id, + description: node.description, + deleted: node.deleted, + parentCode: node.parentCode + } + ).subscribe(() => { + this.nzMessageService.success('Update success!'); + this.loadDepartment(); + this.isVisible = false; + this.submitBtnIsLoading = false; + }, err => { + this.nzMessageService.error(err.message); + }); } + deleteDepartment(node: SysDeptItem){ + node.deleted = 1; + this.setDepartment(node); + } + + restoreDepartment(node: SysDeptItem){ + node.deleted = 0; + this.setDepartment(node); + } - //TODO(jasoonn): Edit the department, need to comunicate with db, and reorder the list - editDepartment(node: TreeNodeInterface){ + editDepartment(node: SysDeptItem){ + this.departmentService.fetchSysDeptSelect().subscribe(list => { + this.sysTreeParent = list; + }); + this.newDepartmentForm = new FormGroup({ + 'code': new FormControl(node.deptCode, [Validators.required, this.checkRequire.bind(this), this.checkIfParent.bind(this)], this.duplicateDeptCodeCheck.bind(this)), + 'name': new FormControl(node.deptName, Validators.required), + 'parent': new FormControl(node.parent?node.parent.key:null), + 'sort': new FormControl(node.sortOrder), + 'deleted': new FormControl(node.deleted === 0 ? true : false), + 'description' : new FormControl(node.description) + }); this.editNode = node; this.editMode = true; this.isVisible = true; - this.newDepartmentForm.get('code').setValue(node.code); - this.newDepartmentForm.get('name').setValue(node.title); - if (node.parent){ - this.newDepartmentForm.get('parent').setValue(node.parent.key); - } - else { - this.newDepartmentForm.get('parent').setValue(null); - } - this.newDepartmentForm.get('status').setValue(node.status === 'Available' ? true : false); - this.newDepartmentForm.get('description').setValue(node.description); + this.parentCodeValid = true;; } - mapOfExpandedData: { [key: string]: TreeNodeInterface[] } = {}; - - collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void { + collapse(array: SysDeptItem[], data: SysDeptItem, $event: boolean): void { if ($event === false) { if (data.children) { data.children.forEach(d => { @@ -206,9 +203,9 @@ export class DepartmentComponent implements OnInit { } } - convertTreeToList(root: TreeNodeInterface): TreeNodeInterface[] { - const stack: TreeNodeInterface[] = []; - const array: TreeNodeInterface[] = []; + convertTreeToList(root: SysDeptItem): SysDeptItem[] { + const stack: SysDeptItem[] = []; + const array: SysDeptItem[] = []; const hashMap = {}; stack.push({ ...root, level: 0, expand: false }); @@ -221,22 +218,112 @@ export class DepartmentComponent implements OnInit { } } } - return array; } - visitNode(node: TreeNodeInterface, hashMap: { [key: string]: boolean }, array: TreeNodeInterface[]): void { + visitNode(node: SysDeptItem, hashMap: { [key: string]: boolean }, array: SysDeptItem[]): void { if (!hashMap[node.key]) { hashMap[node.key] = true; array.push(node); } } - showParent(node: TreeNodeInterface){ + showParent(node: SysDeptItem){ if (node.parent) { - return node.parent.title; + return node.parent.deptName; } return 'None' } + duplicateDeptCodeCheck(control: FormControl): Promise<ValidationErrors|null>{ + var params = { + tableName: 'sys_department', + fieldName: 'dept_code', + fieldVal: control.value, + dataId: this.editMode? this.editNode.id :undefined + } + const promise = new Promise((resolve, reject) => { + this.departmentService.codeCheck(params).then((success) => { + if (success){ + resolve(null); + } + else{ + this.formCodeErrMsg = "This value already exists is not available!"; + resolve({"Duplicate Code": true}); + } + },(err)=>{ + reject(err); + }); + }); + return promise; + } + + checkIfParent(control: FormControl): {[key: string]:any}|null{ + if (this.editMode){ + if(this.editNode.children == null||this.editNode.deptCode===control.value){ + return null; + } + else{ + console.log(this.newDepartmentForm.get('code')) + var mesg = this.editNode.deptCode + 'is the parent code of other departments, can not be modified!'; + this.formCodeErrMsg = mesg; + return {mesg: true}; + } + } + else{ + return null; + } + } + + checkRequire(control: FormControl): {[key: string]:any}|null{ + if (control.value === ""){ + var mesg = "Please enter department code!"; + this.formCodeErrMsg = mesg; + return {mesg: true} + } + else{ + this.formCodeErrMsg = ""; + return null; + } + } + + //Use code to find node + checkNodeCode(node: SysDeptItem, targetCode: string, checkExistCode: string){ + if (node.deptCode === targetCode) { + this.checkCodeExist(node, checkExistCode); + } + else{ + if (node.children !== null){ + for (let i=0;i<node.children.length;i++){ + this.checkNodeCode(node.children[i], targetCode, checkExistCode); + } + } + } + } + + //Check node exist under the node + checkCodeExist(node: SysDeptItem, targetCode: string){ + if (node.deptCode === targetCode){ + this.parentCodeValid = false; + } + else{ + if (node.children !== null){ + node.children.forEach(element => { + this.checkCodeExist(element, targetCode); + }); + } + + } + } + + checkEditParent(control: FormControl): {[key: string]:any}|null{ + this.parentCodeValid = true; + if (this.editMode){ + this.listOfMapData.forEach(element => { + this.checkNodeCode(element, this.editNode.deptCode,control.value); + }); + } + return null; + } + } diff --git a/submarine-workbench/workbench-web-ng/src/app/services/department.service.ts b/submarine-workbench/workbench-web-ng/src/app/services/department.service.ts index 0872420..801108f 100644 --- a/submarine-workbench/workbench-web-ng/src/app/services/department.service.ts +++ b/submarine-workbench/workbench-web-ng/src/app/services/department.service.ts @@ -24,6 +24,8 @@ import { SysDeptSelect } from '@submarine/interfaces/sys-dept-select'; import { of, Observable } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { BaseApiService } from './base-api.service'; +import { SysDeptItem } from '@submarine/interfaces/sys-dept-item'; +import { ValidationErrors } from '@angular/forms'; @Injectable({ providedIn: 'root' @@ -45,4 +47,65 @@ export class DepartmentService { }) ); } + + fetchSysDeptList() : Observable<SysDeptItem[]> { + const apiUrl = this.baseApi.getRestApi('/sys/dept/tree'); + return this.httpClient.get<Rest<any>>(apiUrl).pipe( + switchMap(res => { + if (res.success) { + console.log(res.result); + return of(res.result.records); + } else { + throw this.baseApi.createRequestError(res.message, res.code, apiUrl, 'get'); + } + }) + ); + } + + codeCheck(codeParams): Promise<ValidationErrors|null> { + const promise = new Promise((resolve, reject) => { + const apiUrl = this.baseApi.getRestApi('/sys/duplicateCheck'); + this.httpClient.get<any>(apiUrl,{ + params: codeParams + }).toPromise() + .then((res: any) => { + console.log(res) + resolve(res.success); + }, + err => { + console.log(err); + reject(err); + } + ); + }); + return promise; + } + + createDept(params): Observable<SysDeptItem> { + const apiUrl = this.baseApi.getRestApi('/sys/dept/add'); + return this.httpClient.post<Rest<SysDeptItem>>(apiUrl, params).pipe( + switchMap(res => { + console.log(res) + if (res.success) { + return of(res.result); + } else { + throw this.baseApi.createRequestError(res.message, res.code, apiUrl, 'post', params); + } + }) + ); + } + + editDept(params): Observable<boolean> { + const apiUrl = this.baseApi.getRestApi('/sys/dept/edit'); + return this.httpClient.put<Rest<any>>(apiUrl, params).pipe( + switchMap(res => { + if (res.success) { + return of(true); + } else { + throw this.baseApi.createRequestError(res.message, res.code, apiUrl, 'put', params); + } + }) + ); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org For additional commands, e-mail: dev-h...@submarine.apache.org