From 0d8b1828eea6bb027bbf71ddcd9c28a7bcf0ca3b Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 26 Jan 2018 14:38:12 +0800
Subject: [PATCH] 组织配置
---
src/app/business/services/util/tools.service.ts | 13 ++
src/app/business/entity/data.ts | 1
src/app/business/services/http/sensors.service.ts | 6 +
src/app/routes/systems/organization/organization-config/organization-config.component.ts | 114 +++++++++++++---------
src/app/routes/systems/organization/organization-config/organization-config.component.html | 93 ++++++++++--------
src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts | 34 ++++--
src/app/business/services/http/alarm-config.service.ts | 1
7 files changed, 161 insertions(+), 101 deletions(-)
diff --git a/src/app/business/entity/data.ts b/src/app/business/entity/data.ts
index 93354c3..2aa99c6 100644
--- a/src/app/business/entity/data.ts
+++ b/src/app/business/entity/data.ts
@@ -83,6 +83,7 @@
export interface AlarmSensorLevel {
enable: boolean|any [];
increment: number []|any[];
+ degressEnable:boolean|any [];
degression: number []|any [];
}
export interface Device {
diff --git a/src/app/business/services/http/alarm-config.service.ts b/src/app/business/services/http/alarm-config.service.ts
index 9296a4e..9fd4271 100644
--- a/src/app/business/services/http/alarm-config.service.ts
+++ b/src/app/business/services/http/alarm-config.service.ts
@@ -29,6 +29,7 @@
{
enable: false,
increment: [0,0,0],
+ degressEnable: false,
degression: [0,0,0]
} : alarmLevels[key];
}
diff --git a/src/app/business/services/http/sensors.service.ts b/src/app/business/services/http/sensors.service.ts
index 5ba7466..91ae9d5 100644
--- a/src/app/business/services/http/sensors.service.ts
+++ b/src/app/business/services/http/sensors.service.ts
@@ -12,7 +12,8 @@
private urls = {
list: environment.SERVER_BASH_URL + '/sensor/page-list',
save: environment.SERVER_BASH_URL + '/sensor/add-or-modify',
- delete: environment.SERVER_BASH_URL + '/sensor/delete-by-ids'
+ delete: environment.SERVER_BASH_URL + '/sensor/delete-by-ids',
+ listByVersionId:environment.SERVER_BASH_URL + '/sensor/list-by-vid',
};
constructor(private http: _HttpClient) { }
public getPagingList(page: PageBean, queryText: string): Observable<PageBean> {
@@ -29,6 +30,9 @@
queryParams: example.getSqlParam(), orderByClause: orderByClause};
return this.http.get(this.urls.list, param);
}
+public getPageByVersionId(versionId:number): Observable<PageBean> {
+ return this.http.get(this.urls.listByVersionId,{versionId:versionId});
+}
public save(data: any): Observable<any> {
return this.http.post(this.urls.save, data);
}
diff --git a/src/app/business/services/util/tools.service.ts b/src/app/business/services/util/tools.service.ts
index 3afa1b1..affe82f 100644
--- a/src/app/business/services/util/tools.service.ts
+++ b/src/app/business/services/util/tools.service.ts
@@ -15,4 +15,17 @@
}
)
}
+ public static removePrivate(obj:object){
+ Object.keys(obj).forEach(
+ (key:string) => {
+ if(key.startsWith('_')){
+ delete obj[key];
+ }else{
+ if(obj[key] instanceof Object){
+ ToolsService.removePrivate(obj[key]);
+ }
+ }
+ }
+ );
+ }
}
diff --git a/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts b/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
index 2ae7c10..0332aa3 100644
--- a/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
+++ b/src/app/routes/devices/basic-info/adjust-config/adjust-config.component.ts
@@ -5,6 +5,8 @@
import { Component, OnInit } from '@angular/core';
import { DeviceAdjustValue, Sensor, Device } from '@business/entity/data';
import { Grid, PageBean, ResultBean } from '@business/entity/grid';
+import { ContentChild } from '@angular/core/src/metadata/di';
+import swal, { SweetAlertType } from 'sweetalert2';
@Component({
selector: 'app-adjust-config',
@@ -56,6 +58,10 @@
) { }
ngOnInit() {
+ if(this.record.deviceVersionId==null){
+ swal(`������������������������`, '������������������������������������������������������������', 'info');
+ this.subject.destroy();
+ }
this.initPage();
this.load();
}
@@ -66,22 +72,23 @@
}, 1);
zip(
this.adjustValueService.getByDid(this.record.id),
- this.sensorsService.getPagingList(this.grid, null)
+ this.sensorsService.getPageByVersionId(this.record.deviceVersionId)
).subscribe(
([adjustRes,sensorsRes]) => {
if(adjustRes!=null && adjustRes.code==1 && sensorsRes != null && sensorsRes.data != null){
- this.data = adjustRes.data;
- if(this.data == null||this.data.deviceId== null){
- this.data = {};
- this.data.value = {};
- this.data['deviceId'] = this.record.id;
- }
- // ���������������������
- Object.assign(this._dataValue,this.data.value);
+ this.data = {
+ deviceId:this.record.id,
+ value:{}
+ };
+ if(adjustRes.data!=null){
+ // ���������������������
+ Object.assign(this._dataValue,adjustRes.data.value);
+ this.data['id'] =adjustRes.data.id;
+ }
this.grid.initData(sensorsRes);
sensorsRes.data.forEach(
(item:Sensor) => {
- this.data.value[item.sensorKey] = this.data.value[item.sensorKey] == null?0:this.data.value[item.sensorKey];
+ this.data.value[item.sensorKey] = this._dataValue[item.sensorKey] == null?0:this._dataValue[item.sensorKey];
}
);
this.grid.refreshStatus();
@@ -97,11 +104,14 @@
}
save($event) {
// $event.preventDefault();
- let isModify = Object.keys(this.data.value).some(
+ let isModify = Object.keys(this._dataValue).length != Object.keys(this.data.value).length;
+ if(!isModify){
+ isModify = Object.keys(this.data.value).some(
key => {
return this.data.value[key] !== this._dataValue[key];
}
- );
+ );
+ }
debugger;
if(isModify){
this.adjustValueService.save(this.data).subscribe(
diff --git a/src/app/routes/systems/organization/organization-config/organization-config.component.html b/src/app/routes/systems/organization/organization-config/organization-config.component.html
index 20c2c97..e5b43b0 100644
--- a/src/app/routes/systems/organization/organization-config/organization-config.component.html
+++ b/src/app/routes/systems/organization/organization-config/organization-config.component.html
@@ -19,14 +19,17 @@
<th nz-th>
������
</th>
- <th nz-th>
- ������������
+ <th nz-th [ngStyle]="{'width': '72px'}">
+ ������������
</th>
<th nz-th>
- ������������
+ <span *ngIf="hasDegression">������������</span>
</th>
<th nz-th>
- ������������
+ <span *ngIf="hasDegression">������������</span>
+ </th>
+ <th nz-th>
+ <span *ngIf="hasDegression">������������</span>
</th>
</tr>
</thead>
@@ -36,59 +39,65 @@
<td nz-td [nzCheckbox]="true">
<label nz-checkbox formControlName="enable"></label>
</td>
- <td>
+ <td nz-td>
<span>
{{ row.name }}({{ row.unit }})
</span>
</td>
- <td formArrayName="increment" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.increment').controls; index as i">
- <div nz-form-item>
- <div nz-form-control nzHasFeedback>
- <nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input>
- </div>
- </div>
- </td>
- <td formArrayName="degression" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.degression').controls; index as i">
+ <td nz-td formArrayName="increment" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.increment').controls; index as i">
<div nz-form-item>
<div nz-form-control nzHasFeedback>
<nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input>
</div>
</div>
- </td>
+ </td>
+ <td nz-td style="padding-top:0px;">
+ <div nz-form-control>
+ <nz-switch formControlName="degressEnable" (click)="refreshHasDegression(f.value['alarmLevels'][row.sensorKey]['degressEnable'])"
+ nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-switch>
+ </div>
+ </td>
+ <td nz-td formArrayName="degression" *ngFor="let in of validateForm.get('alarmLevels.'+row.sensorKey+'.degression').controls; index as i">
+ <div *ngIf="f.value['alarmLevels'][row.sensorKey]['degressEnable']" nz-form-item>
+ <div nz-form-control nzHasFeedback>
+ <nz-input [formControlName]="i" maxlength="20" nzDisabled="{{ !f.value['alarmLevels'][row.sensorKey]['enable'] }}"></nz-input>
+ </div>
+ </div>
+ </td>
</tr>
</tbody>
</nz-table>
</nz-card>
<div [ngStyle]="{'background-color':'#f5f7fa','width':'110%','left':'-5%','height':'20px','position':'relative'}"></div>
- <nz-card [nzBordered]="false" nzTitle="������������" formGroupName="alarmMode">
- <label nz-checkbox formControlName="enable">
- <span>������������</span>
- </label>
- <div [ngStyle]="{'margin-left': '20%'}">
- <br/>
- <br/>
- <br/>
- <div *ngFor="let i of [1,2,3]" nz-form-item nz-row class="mb-sm">
- <div nz-form-label nz-col [nzSm]="3" [nzXs]="24">
- <span [ngSwitch]="i">
- <label *ngSwitchCase="1">������������������:</label>
- <label *ngSwitchCase="2">������������������:</label>
- <label *ngSwitchCase="3">������������������:</label>
- </span>
- </div>
- <div nz-form-control nz-col [nzSpan]="12" nzHasFeedback>
- <nz-select formControlName="{{ 'level'+i }}" [nzMode]="'multiple'" [nzPlaceHolder]="'������ ������������'" [nzNotFoundContent]="'������������'"
- nzDisabled="{{ !f.value['alarmMode']['enable'] }}">
- <nz-option *ngFor="let option of alarmModes" [nzLabel]="option.label" [nzValue]="option.value" [nzDisabled]="option.disabled">
- </nz-option>
- </nz-select>
- </div>
- <br/>
- <br/>
- <br/>
+ <nz-card [nzBordered]="false" nzTitle="������������" formGroupName="alarmMode">
+ <label nz-checkbox formControlName="enable">
+ <span>������������</span>
+ </label>
+ <div [ngStyle]="{'margin-left': '20%'}">
+ <br/>
+ <br/>
+ <br/>
+ <div *ngFor="let i of [1,2,3]" nz-form-item nz-row class="mb-sm">
+ <div nz-form-label nz-col [nzSm]="3" [nzXs]="24">
+ <span [ngSwitch]="i">
+ <label *ngSwitchCase="1">������������������:</label>
+ <label *ngSwitchCase="2">������������������:</label>
+ <label *ngSwitchCase="3">������������������:</label>
+ </span>
</div>
+ <div nz-form-control nz-col [nzSpan]="12" nzHasFeedback>
+ <nz-select formControlName="{{ 'level'+i }}" [nzMode]="'multiple'" [nzPlaceHolder]="'������ ������������'" [nzNotFoundContent]="'������������'"
+ nzDisabled="{{ !f.value['alarmMode']['enable'] }}">
+ <nz-option *ngFor="let option of alarmModes" [nzLabel]="option.label" [nzValue]="option.value" [nzDisabled]="option.disabled">
+ </nz-option>
+ </nz-select>
+ </div>
+ <br/>
+ <br/>
+ <br/>
</div>
- </nz-card>
+ </div>
+ </nz-card>
<footer-toolbar errorCollect>
<span [ngStyle]="{'color':'red','width':'300px','margin-right':'40px'}">{{ errorMessage }}</span>
<label>���������������</label>
@@ -100,5 +109,5 @@
<span *ngIf="isSaving">���</span>
</span>
</button>
- </footer-toolbar>
+ </footer-toolbar>
</form>
diff --git a/src/app/routes/systems/organization/organization-config/organization-config.component.ts b/src/app/routes/systems/organization/organization-config/organization-config.component.ts
index a40ad12..f4cee54 100644
--- a/src/app/routes/systems/organization/organization-config/organization-config.component.ts
+++ b/src/app/routes/systems/organization/organization-config/organization-config.component.ts
@@ -1,7 +1,7 @@
import { NzMessageService } from 'ng-zorro-antd';
import { filter } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
-import { FormGroup, FormBuilder, FormControl, Validators, FormArray } from '@angular/forms';
+import { FormGroup, FormBuilder, FormControl, Validators, FormArray, AbstractControl } from '@angular/forms';
import { SensorsService } from '@business/services/http/sensors.service';
import { Grid, PageBean } from '@business/entity/grid';
import { Organization, AlarmConfig, AlarmSensorLevel, AlarmConfigValue } from '@business/entity/data';
@@ -11,6 +11,7 @@
import { AlarmConfigService } from '@business/services/http/alarm-config.service';
import { AlarmStyle } from '@business/enum/types.enum';
import { patterns } from '@business/enum/patterns.enum';
+import { ToolsService } from '@business/services/util/tools.service';
@Component({
selector: 'app-organization-config',
@@ -81,8 +82,12 @@
[degression[1], Validators.pattern(patterns.num)],
[degression[2], Validators.pattern(patterns.num)]
]);
+ //������������������������
+ // let _degressionEnable = degression[0] != 0 || degression[1] != 0 || degression[2] != 0;
+
const alarmSensorGroup = this.formBuilder.group(
{
+ degressEnable:[alarmLevels[key].degressEnable],
enable: [alarmLevels[key].enable],
increment: incrementArray,
degression: degressionArray,
@@ -126,6 +131,7 @@
)
this.refreshIndeterminate();
}
+ this.refreshHasDegression(false);
// ������������������ExpressionChangedAfterItHasBeenCheckedError
setTimeout(() => {
this.grid.loading = false;
@@ -173,6 +179,7 @@
organizationId:this.organization.id,
value:value
}
+ // ToolsService.removePrivate(data.value);
this.alarmConfigService.save(data).subscribe(
result => {
if(result!=null&&result.code==1){
@@ -182,6 +189,7 @@
}
);
}
+ debugger;
}
setErrorMessage(){
@@ -198,53 +206,55 @@
}
}
errorMessage:string = '';
+ private removeError(error:'increment'|'degression',...controls:AbstractControl[]){
+ controls.forEach(
+ item => {
+ if(item.hasError(error)&&Object.keys(item.errors).length==1){
+ item.setErrors(null);
+ }
+ }
+ );
+ }
+ private addError(error:'increment'|'degression',...controls:AbstractControl[]){
+ controls.forEach(
+ item => {
+ let errs = {};
+ errs[error] = true;
+ item.setErrors(errs);
+ item.markAsDirty();
+ }
+ );
+ }
private alarmLevelValidator = (control: FormControl): { [s: string]: boolean } => {
- let result = {};
- const i0 = control.get("increment.0");
- const i1 = control.get("increment.1");
- const i2 = control.get("increment.2");
- if ((i0.value != 0 || i1.value != 0 || i2.value != 0)&&(i0.value >= i1.value||i1.value >= i2.value)) {
- i0.setErrors({ increment: true });
- i0.markAsDirty();
- i1.setErrors({ increment: true });
- i1.markAsDirty();
- i2.setErrors({ increment: true });
- i2.markAsDirty();
- result["increment"] = true;
- }else{
- if(i0.hasError('increment')&&Object.keys(i0.errors).length==1){
- i0.setErrors(null);
+ const enable = control.get("enable").value;
+ const degressEnable = control.get("degressEnable").value;
+ const i0 = control.get("increment.0");
+ const i1 = control.get("increment.1");
+ const i2 = control.get("increment.2");
+ const d0 = control.get("degression.0");
+ const d1 = control.get("degression.1");
+ const d2 = control.get("degression.2");
+ // ��������������� ������������������������������
+ if(!enable){
+ this.removeError('increment',i0,i1,i2);
+ this.removeError('degression',d0,d1,d2);
+ return null;
}
- if(i1.hasError('increment')&&Object.keys(i1.errors).length==1){
- i1.setErrors(null);
- }
- if(i2.hasError('increment')&&Object.keys(i2.errors).length==1){
- i2.setErrors(null);
- }
- }
- const d0 = control.get("degression.0");
- const d1 = control.get("degression.1");
- const d2 = control.get("degression.2");
- if ((d0.value != 0 || d1.value != 0 || d2.value != 0)&&(d1.value >= d0.value||d2.value >= d1.value)) {
- d0.setErrors({ degression: true });
- d0.markAsDirty();
- d1.setErrors({ degression: true });
- d1.markAsDirty();
- d2.setErrors({ degression: true });
- d2.markAsDirty();
- result["degression"] = true;
- }else{
- if(d0.hasError('degression')&&Object.keys(d0.errors).length==1){
- d0.setErrors(null);
- }
- if(d1.hasError('degression')&&Object.keys(d1.errors).length==1){
- d1.setErrors(null);
- }
- if(d2.hasError('degression')&&Object.keys(d2.errors).length==1){
- d2.setErrors(null);
- }
- }
- return Object.keys(result).length == 0?null:result;
+ let result = {};
+ if ((i0.value != 0 || i1.value != 0 || i2.value != 0)&&(i0.value >= i1.value||i1.value >= i2.value)) {
+ this.addError('increment',i0,i1,i2);
+ result["increment"] = true;
+ }else{
+ this.removeError('increment',i0,i1,i2);
+ }
+ debugger;
+ if(degressEnable&&(d0.value != 0 || d1.value != 0 || d2.value != 0)&&(d1.value >= d0.value||d2.value >= d1.value)) {
+ this.addError('degression',d0,d1,d2);
+ result["degression"] = true;
+ }else{
+ this.removeError('degression',d0,d1,d2);
+ }
+ return Object.keys(result).length == 0?null:result;
};
getLastError(control:FormGroup|FormArray){
if(control.errors!=null){
@@ -264,4 +274,16 @@
}
}
}
+ private hasDegression = false;
+ refreshHasDegression(value){
+ if(value){
+ this.hasDegression = true;
+ }else{
+ this.hasDegression = Object.values(this.validateForm.value['alarmLevels']).some(
+ ( item:any) => {
+ return item['degressEnable'];
+ }
+ )
+ }
+ }
}
--
Gitblit v1.8.0