import { DocumentLinkRestService, IDocumentLink } from 'isogd-document-link-rest'; import { SolarRestService } from 'isogd-solar-rest'; import * as _ from 'lodash'; import { SearchResult } from 'isogd-solar-rest'; import { SearchResultDocument } from 'isogd-solar-rest'; import { SearchResultDocumentEx } from './search-candidates'; import { SearchExtData } from 'isogd-solar-rest'; import { SortingType } from './search-result-sorting'; import { LinkedDocumentService } from '../../services/LinkedDocumentService'; import { DocumentIsogd, DocumentRestService } from 'isogd-document-rest'; import { NsiRestService } from 'oasi-nsi-rest'; class SearchResultController { static $inject = ['$filter', 'solarRestService', 'linkedDocumentService', '$timeout', 'toastr', 'blockUI', 'documentLinkRestService', 'documentRestService', '$q', 'nsiRestService']; document: DocumentIsogd; documents: SearchResultDocumentEx[]; docTypes: any[]; chapters: any[]; statuses: any[]; sortings: SortingType[]; onSortingsChanged: (params: any) => void; count = 0; private linkdocTypes: any[]; private linkdocStatuses: any[]; onAddLink: (link: any) => void; onAddLinks: (links: any) => void; private disabledAll: boolean = true; private allLinkType: string = ""; private allLinkStatus: string = ""; constructor(private $filter: ng.IFilterService, private solarService: SolarRestService, private linkedDocumentService: LinkedDocumentService, private $timeout: ng.ITimeoutService, private toastr: Toastr, private blockUI: any, private documentLinkRestService: DocumentLinkRestService, private documentRestService: DocumentRestService, private $q: ng.IQService, private nsiRestService: NsiRestService) { } clear() { this.disabledAll = true; this.allLinkType = ""; this.allLinkStatus = ""; } $onChanges(changes: any) { if (changes.documents && changes.documents.currentValue) { this.clear(); } } getRegOgd(document: SearchResultDocument): string { let result: string = ""; if (document && document.registrationNumber) { result += "Регистрация в ИАИС ОГД — "; result += document.registrationNumber; if (document && document.registrationDate) { result += " от "; result += this.$filter('date')(document.registrationDate, 'dd.MM.yyyy'); } } return result; } getCad(document: SearchResultDocument): string { let result: string = ""; if (document && document.cadastralNumbers && document.cadastralNumbers.length > 0) { document.cadastralNumbers.forEach((d, i) => { result += d; if (i < document.cadastralNumbers.length - 1) { result += ", "; } }); } return result; } getFirstString(document: SearchResultDocument): string { let result: string = ""; result += this.findDocShortName(document); result += " № "; result += document.documentNumber; if (document && document.documentDate) { result += " от "; result += this.$filter('date')(document.documentDate, 'dd.MM.yyyy'); } return result; } findDocShortName(document: SearchResultDocument): string { let result: string = ""; this.docTypes.forEach(d => { if (d.docCode === document.documentType) { result = (d.docNameShort) ? d.docNameShort : ""; } }); return result; } getAddress(document: SearchResultDocument): string { let result: string = ''; if (document && document.objectAddress) { result += document.objectAddress; } else if (document && document.postAddress) { result += document.postAddress; } let areaName = ''; if (document && document.areaNames && document.areaNames.length > 0) { areaName = document.areaNames[0]; } let districtName = ''; if (document && document.districtNames && document.districtNames.length > 0) { districtName = document.districtNames[0]; } let secondPart = ''; if (areaName) { secondPart += areaName; } if (districtName) { secondPart += (areaName) ? ', ' : ''; secondPart += districtName; } if (result !== "") { if (secondPart) { secondPart = ' (' + secondPart + ')'; } } result += secondPart; console.log("address"); return result; } change(sorting: SortingType) { this.update(sorting.name); this.onSortingsChanged({ sorting: sorting }); } private update(columnName: string) { this.sortings.forEach(v => { if (v.name === columnName) { switch (v.value) { case 'desc': v.value = 'asc'; break; default: v.value = 'desc'; break; } } }); } addLink(d: SearchResultDocumentEx, index: number) { this.onAddLink({ link: { doc1Id: this.document.documentID, doc2Id: d.documentId, linkType: d.linkType, status: d.linkStatus } }); } getLinkStatusNameByCode(code: string): string { let result: string = ""; this.linkdocStatuses.forEach(s => { if (s.code === code) { result = s.name; } }); return result; } getLinkTypeNameByCode(code: string): string { let result: string = ""; this.linkdocTypes.forEach(s => { if (s.code === code) { result = s.name; } }); return result; } changeSelection() { let selectAll = true; let anyChecked = false; this.documents.forEach(l => { if (l.checked === false) { selectAll = false; } if (l.checked === true) { anyChecked = true; } }); this.disabledAll = !anyChecked; } changeSelectedLinkType() { this.documents.forEach(l => { if (l.checked === true) { l.linkType = this.allLinkType; } }); } changeSelectedLinkStatus() { this.documents.forEach(l => { if (l.checked === true) { l.linkStatus = this.allLinkStatus; } }); } addSelectedLink() { let links: any[] = []; this.documents.forEach(l => { if (l.checked === true) { links.push({ doc1Id: this.document.documentID, doc2Id: l.documentId, linkType: l.linkType, status: l.linkStatus }) } }); this.onAddLinks({ links: links }); } } export const SearchResultComponent: angular.IComponentOptions = { controller: SearchResultController, template: require('./search-result.html'), bindings: { document: '<', documents: '<', docTypes: '<', chapters: '<', statuses: '<', sortings: '<', onSortingsChanged: '&', linkdocStatuses: "<", linkdocTypes: "<", onAddLink: "&", onAddLinks: "&" } };