import { DocumentIsogd } from 'isogd-document-rest'; import * as widgets from "oasi-widgets"; import { GisRestService } from 'isogd-gis-rest/dist/types/isogd-gis-rest/services/GisRestService'; class GisViewController { static $inject = ['$state', '$timeout', 'gisRestService', '$filter', 'blockUI']; private document: DocumentIsogd; private allLinks: any[] private links: any[]; private myBlockUI: any; private errorMessage: string; private loadingStatus: widgets.LoadingStatus = widgets.LoadingStatus.LOADING; constructor(private $state: ng.ui.IStateService, private $timeout: ng.ITimeoutService, private gisRestService: GisRestService, private $filter: ng.IFilterService, private blockUI: any) { } $onInit() { let allLinks: any; let links: any; this.myBlockUI = this.blockUI.instances.get('gisLoad'); this.gisRestService.linksSearch({ registryCode: this.document.reestr, docNumber: this.document.documentRequisites.documentNumber, docDate: this.$filter('date')(new Date(this.document.documentRequisites.documentDate.toString()), 'yyyy-MM-dd') }).then(response => { allLinks = this.transformAllLinks(response); return this.gisRestService.findByDocId(this.document.documentID); }).then(response => { links = this.transformLinks(response); let newAllLinks = []; allLinks.forEach(al => { let find = false; links.forEach(l => { if (al.layerTableId === l.layerTableId && al.objectContourId === l.objectContourId) { find = true; } }); if (!find) { newAllLinks.push(al); } }); this.allLinks = newAllLinks; this.links = links; this.loadingStatus = widgets.LoadingStatus.SUCCESS; }).catch(error => { this.errorMessage = "Данные не найдены" this.loadingStatus = widgets.LoadingStatus.ERROR; }); } $onDestroy() { this.myBlockUI.reset(); } updateData() { let allLinks: any; let links: any; this.gisRestService.linksSearch({ registryCode: this.document.reestr, docNumber: this.document.documentRequisites.documentNumber, docDate: this.$filter('date')(new Date(this.document.documentRequisites.documentDate.toString()), 'yyyy-MM-dd') }).then(response => { allLinks = this.transformAllLinks(response); return this.gisRestService.findByDocId(this.document.documentID); }).then(response => { links = this.transformLinks(response); let newAllLinks = []; allLinks.forEach(al => { let find = false; links.forEach(l => { if (al.layerTableId === l.layerTableId && al.objectContourId === l.objectContourId) { find = true; } }); if (!find) { newAllLinks.push(al); } }); this.allLinks = newAllLinks; this.links = links; this.myBlockUI.stop(); }).catch(error => { this.myBlockUI.stop(); }); } transformAllLinks(response: any[]): any[] { let allLinks = []; response.forEach(r => { allLinks.push({ layerTable: r.layerTable, layerTableId: r.layerTableId, objectContourId: r.objectContourId }); }); return allLinks; } transformLinks(response: any): any[] { let links = []; response._embedded.links.forEach(r => { links.push({ docId: r.docId, hide: (r.hide), id: r.id, layerTable: r.layerTable, layerTableId: r.layerTableId, objectContourId: r.objectContourId }); }); return links; } openMap(l: any) { let url = "/portal-gis/" + l.layerTableId + "/" + l.objectContourId; window.open(url, '_blank'); } bind(l: any) { this.myBlockUI.start(); this.$timeout(1500).then(response => { let newLinks: any[] = [];; this.links.forEach(ll => { newLinks.push({ docId: this.document.documentID, layerTable: ll.layerTable, layerTableId: ll.layerTableId, objectContourId: ll.objectContourId }); }); newLinks.push({ docId: this.document.documentID, layerTable: l.layerTable, layerTableId: l.layerTableId, objectContourId: l.objectContourId }) this.gisRestService.replaceLinks(newLinks).then(response => { this.updateData(); }).catch(error => { this.myBlockUI.stop(); }); }); } } export const GisViewComponent: angular.IComponentOptions = { controller: GisViewController, template: require('./gis-view.html'), bindings: { document: '<' } };