From 3405a42d4434bb77026c029ed20f2898ba665107 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Thu, 11 Jan 2018 09:25:50 +0800 Subject: [PATCH] 框架升级 --- src/app/routes/devices/version/version.component.ts | 213 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 144 insertions(+), 69 deletions(-) diff --git a/src/app/routes/devices/version/version.component.ts b/src/app/routes/devices/version/version.component.ts index 28cc822..6e970b7 100644 --- a/src/app/routes/devices/version/version.component.ts +++ b/src/app/routes/devices/version/version.component.ts @@ -1,137 +1,212 @@ +import { VersionSensorConfigComponent } from './version-sensor-config/version-sensor-config.component'; +import { DataType } from '@business/entity/grid'; +import { DeviceVersion, Sensor } from '@business/entity/data'; +import { Version } from '@angular/compiler/src/util'; import { Subject } from 'rxjs/Subject'; -import '../../../rxjs-operators'; -import { ToolsService } from '@core/services/tools.service'; +import { ToolsService } from '@business/services/util/tools.service'; import { Component, OnInit } from '@angular/core'; -import { NzMessageService } from 'ng-zorro-antd'; +import { NzMessageService, NzModalService } from 'ng-zorro-antd'; import { ModalHelper } from '@delon/theme'; import { HttpClient } from '@angular/common/http'; -import { environment } from '../../../../environments/environment'; -import { DateService } from '@core/services/date.service'; -import { VersionService } from 'app/routes/devices/version/version.service'; -import { Types } from '@core/enum/types.enum'; -import { Column, Grid, PageBean } from '@core/entity/grid'; +import { DateService } from '@business/services/util/date.service'; +import { VersionService } from '@business/services/http/version.service'; +import { Types } from '@business/enum/types.enum'; +import { Column, Grid, PageBean } from '@business/entity/grid'; +import { VersionEditComponent } from 'app/routes/devices/version/version-edit/version-edit.component'; -interface DeviceVersion { - createTime: Column; - description: Column; - id?: Column; - name: Column; - version: Column; -} + @Component({ selector: 'app-version', templateUrl: './version.component.html', styles: [] }) export class VersionComponent implements OnInit { - - grid: Grid = new Grid(null); + private version: DeviceVersion; + grid: Grid<DeviceVersion> = new Grid(null); queryMap = { text: '������������������������', value: ''}; queryTextStream: Subject<string> = new Subject<string>(); private initPage() { - const columns: DeviceVersion = { + this.version = { name: { text: '������', - width: '22%' + width: '18%' }, version: { text: '������', - width: '22%' + width: '18%', + isSort: true }, createTime: { text: '������������', - width: '22%', + width: '18%', type: { name: Types.Date, format: 'YYYY-MM-DD HH:mm:ss' - } + }, + isSort: true }, description: { text: '������', - width: '22%' + width: '18%' } }; this.grid.title = '������������'; - this.grid.setColumns(columns); + this.grid.setColumns(this.version); this.grid.pageSize = 10; } constructor( - public http: HttpClient, private versionService: VersionService, - public dateSrv: DateService, + + private confirmServ: NzModalService, public msgSrv: NzMessageService, private modalHelper: ModalHelper, - private toolsService: ToolsService) {} + ) {} ngOnInit() { this.initPage(); this.queryTextStream - .debounceTime(1000) + .debounceTime(500) .distinctUntilChanged() .subscribe(queryText => { this.load(); }); } queryTextChanged($event) { - // tslint:disable-next-line:no-debugger - debugger; - this.queryTextStream.next(this.queryText); + this.queryTextStream.next(this.queryMap.value); } - load(reload: boolean = false) { + load(reload: boolean = false) { if (reload) { this.grid.pageIndex = 1 ; } - this.versionService.getPagingList(this.grid, this.queryText).subscribe( + // ������������������ExpressionChangedAfterItHasBeenCheckedError + setTimeout(() => { + this.grid.loading = true; + }, 1); + this.versionService.getPagingList(this.grid, this.queryMap.value).subscribe( (res: PageBean) => { - if (res.total > 0 && res.data != null) { + this.grid.loading = true; + if (res != null && res.data != null) { this.grid.initData(res); this.grid.refreshStatus(); + setTimeout(() => { + this.grid.loading = false; + }, 1); } } ); } - edit() { - // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => { - // this.load(true); - // this.msgSrv.success('���������������������������'); - // }); - } - - add() { - // const user = {}; - // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => { - // this.load(true); - // this.msgSrv.success('���������������������������'); - // }); - } - - delete(user) { - this.http.delete(environment.SERVER_BASH_URL + '/user/operate_user/' + user.id).subscribe((res: any) => { - this.msgSrv.success('���������������������������'); - this.load(true); +// rowData���null��������������� + addOrModify(data) { + if ( data == null) { + data = {}; + } + const cols = this.version; + this.modalHelper.static(VersionEditComponent, { cols , data }).subscribe( + ( ret: { data: any, close: Function} ) => { + this.versionService.save(ret.data).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(); + ret.close(); + this.msgSrv.success(this.grid.title + '���������������'); + } + } + ); }); } - remove() { - + delete(...id: number[]) { + this.versionService.delete( ...id ).subscribe( + ( res: any) => { + if (res.code === 1) { + this.load(); + this.msgSrv.success(this.grid.title + '���������������'); + } + } + ); } - - dataChange(res: any) { - + deleteSelected() { + this.confirmServ.confirm({ + title: '������������', + content: '������������������������������������������������', + okText: '������', + cancelText: '������' + }).on('onOk', () => { + if (this.grid.selectedIndexs != null && this.grid.selectedIndexs.length > 0) { + const ids = this.grid.selectedIndexs.map( + (index: number) => { + const id = this.grid.data[index].id; + return Number.parseInt(id); + } + ); + this.delete( ...ids ); + } + }); } - - sort(field: string, value: any) { - // this.sortMap = {}; - // this.sortMap[field] = value; - // this.q.sorter = value ? `${field}_${value}` : ''; - // this.load(true); + sort(field: string, value: string) { + // ������������field + this.grid.sorts = this.grid.sorts.filter( + (fn: string) => { + return fn !== field; + } + ); + // ������value������null������������������������������filed + if ( value != null ) { + this.grid.sorts.push(field); + } + this.load(); } + configSensor(data) { + const deviceVersionId = data.id; + this.versionService.getSensorIds(deviceVersionId).subscribe( + (selectedSensorIds: number[]) => { + this.modalHelper.static(VersionSensorConfigComponent, { deviceVersionId, selectedSensorIds }).subscribe( + ( ret: { grid: Grid<Sensor>, close: Function} ) => { + // ������������id + const selectedIds = ret.grid.data.filter( + (r: any) => { + return r['checked'] === true; + } + ).map( + (r: any) => { + return r['id']; + } + ); + // ������������������������������ + let isModified = selectedIds.length !== selectedSensorIds.length; + // ��������������������������� + if (!isModified) { + isModified = !selectedIds.every( + (id: number) => { + // console.log('id:' + id); + const result = selectedSensorIds.some( + (sid: number) => { + return id === sid ; + } + ); + // console.log('result:' + result); + return result; + } + ); + } + if ( !isModified ) { + this.msgSrv.success(this.grid.title + '������������������'); + ret.close(); + return ; + } + this.versionService.versionSensorConfig(deviceVersionId, selectedIds).subscribe( + ( res: any) => { + if (res.code === 1) { + ret.close(); + this.msgSrv.success(this.grid.title + '���������������'); + } + } + ); + }); + } + ); - reset(ls: any[]) { - for (const item of ls) item.value = false; - this.load(true); - } - + } } -- Gitblit v1.8.0