import { SolarRestService } from 'isogd-solar-rest'; import * as widgets from "oasi-widgets"; import * as _ from "lodash"; import { DocumentIsogd, DocumentRestService, DocumentIsogdWrapper } from "isogd-document-rest"; import { NSIRegistrationStatus, NsiRestService } from "oasi-nsi-rest"; class DocumentHeaderController { private document: DocumentIsogd; private loadingStatus: widgets.LoadingStatus; private registry: any private changedDoc: DocumentIsogd[] = []; private isDanger: boolean = false; private message: string = "Внесение изменений в зарегистрированный документ"; private statuses: any[]; private showUnregistered: boolean = false; private showRegistered: boolean = true; static $inject = ['$q', '$timeout', 'solarRestService', '$filter', 'nsiRestService', 'documentRestService']; constructor(private $q: ng.IQService, private $timeout: any, private solarRestService: SolarRestService, private $filter: ng.IFilterService, private nsiRestService: NsiRestService, private documentRestService: DocumentRestService) { } $onInit() { this.nsiRestService.get('registrationStatus').then((response: NSIRegistrationStatus[]) => { this.statuses = response; this.loadingStatus = widgets.LoadingStatus.LOADING; if (this.document && this.document.registration && this.document.registration.registrationStatus === 'CHANGE_QUEUE') { let search = null; if ((this.document.reestr === '8050') && (this.document.documentType = 'GPZU')) { search = { documentRegistrationCode: ['CHANGE_QUEUE', 'QUEUE', 'REGISTERED'], reestr: [this.document.reestr], documentNumber: this.document.documentRequisites.documentNumber }; } else { search = { documentRegistrationCode: ['CHANGE_QUEUE', 'QUEUE', 'REGISTERED'], reestr: [this.document.reestr], documentDateFrom: this.$filter('date')(this.document.documentRequisites.documentDate, 'yyyy-MM-dd'), documentDateTo: this.$filter('date')(this.document.documentRequisites.documentDate, 'yyyy-MM-dd'), documentNumber: this.document.documentRequisites.documentNumber }; } this.solarRestService.searchExt((search)).then(response => { if (response.docs.length > 0) { response.docs.forEach(d => { let promises: ng.IPromise[] = []; if (d.documentId !== this.document.documentID) { promises.push(this.documentRestService.getDocument(d.documentId)); this.$q.all(promises).then((docs: DocumentIsogdWrapper[]) => { docs.forEach(_d => { let d = _d.document; if (d.registration.registrationStatus === 'QUEUE') { this.isDanger = true; this.message = "Внесение изменений в незарегистрированный документ"; } this.changedDoc.push(d); }); if (this.changedDoc.length > 0 && !this.isDanger) { this.showUnregistered = true; } if (this.changedDoc.length > 0 && this.isDanger) { this.showRegistered = false; } this.loadingStatus = widgets.LoadingStatus.SUCCESS; }).catch(error => { console.log(error); this.loadingStatus = widgets.LoadingStatus.ERROR; }); } else { this.loadingStatus = widgets.LoadingStatus.SUCCESS; } }); } else { this.loadingStatus = widgets.LoadingStatus.SUCCESS; } }).catch(error => { this.loadingStatus = widgets.LoadingStatus.ERROR; console.log(error); }); } else { this.loadingStatus = widgets.LoadingStatus.SUCCESS; } }).catch(error => { console.log(error); this.loadingStatus = widgets.LoadingStatus.ERROR; }) } getAddressString(): string { let territoryValues = this.getTerritoryValues(); if (this.document.object && this.document.object.objectAddress) { let result = this.document.object.objectAddress; if (territoryValues && territoryValues.length > 0) { result += ' (' + territoryValues.join(', ') + ')'; } return result; } else if (territoryValues && territoryValues.length > 0) { return territoryValues.join(', '); } } getTerritoryValues(): string[] { let territory = (this.document.territory) ? this.document.territory : undefined; let areas: string[] = territory ? _.map(this.document.territory.area, (area) => { return area.areaName; }) : []; let districts: string[] = territory ? _.map(this.document.territory.district, (district) => { return district.districtName; }) : []; return areas.concat(districts); } } export const DocumentHeaderComponent: angular.IComponentOptions = { controller: DocumentHeaderController, template: require('./documentHeader.html'), bindings: { document: "<" }, transclude: { headerMenuSlot: "headerMenu" }, };