import { SearchResultDocument, SearchResult, SolarRestService} from 'isogd-solar-rest'; import { DocumentLinkRestService, IDocumentLink } from 'isogd-document-link-rest'; import * as _ from 'lodash'; import { ILinkWithDocument } from './linked-documents-edit'; import * as angular from 'angular'; import { ISearchParams } from './search-filter'; import { SortingType } from './search-result-sorting'; import { IPagination } from './search-pagination'; import { LinkedDocumentService } from "../../services/LinkedDocumentService"; import { DocumentIsogd } from 'isogd-document-rest'; import { NsiRestService } from 'oasi-nsi-rest'; export class SearchResultDocumentEx { documentDate: string; documentId: string; documentName: string; documentNumber: string; documentType: string; id: string; objectAddress: string; objectName: string; postAddress: string; reestr: string; registrationDate: string; registrationNumber: string; title: string; type: string; organizationName: string; organizationRoleCode: string; inn: string; ogrn: string; documentRegistrationCode: string; documentStatusCode: string; areaNames: string[]; cadastralNumbers: string[]; districtNames: string[]; checked: boolean; linkType: string; linkStatus: string; hasLink: boolean; } class SearchCandidatesController { static $inject = ['$filter', 'solarRestService', 'linkedDocumentService', '$timeout', 'toastr', 'blockUI', 'documentLinkRestService', 'nsiRestService', '$q']; private document: DocumentIsogd; private chapters: any[]; private groupedChapters: any[] = []; private searchParams: ISearchParams; private notFound: boolean = true; private onUpdate: () => void; private onFind: () => void; private linkdocTypes: any[]; private linkdocStatuses: any[]; private sortings: SortingType[]; private pagination: IPagination; private response: SearchResultDocument[]; private linkedDocuments: ILinkWithDocument[]; private myBlockUI: any; private statuses: any[]; 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 nsiRestService: NsiRestService, private $q: ng.IQService) { } $onDestroy() { this.myBlockUI.reset(); } $onInit() { this.myBlockUI = this.blockUI.instances.get('searchCandidateEditor'); this.chapters.forEach(ch => { if (ch.children) { ch.children.forEach(c => { let _ch = angular.copy(c); angular.extend(_ch, { parentName: ch.name }); this.groupedChapters.push(_ch); }); } }); } findLinkedDocumentById(id): ILinkWithDocument { let result = null; this.linkedDocuments.forEach(l => { if (l.document.documentID === id) { result = l; } }); return result; } find() { this.searchParams.searchType = "common"; this.searchParams.documentType = ""; this.searchParams.documentNumber = ""; this.searchParams.documentDate.startDate = null; this.searchParams.documentDate.endDate = null; this.onFind(); } search() { this.searchParams.searchType = "ext"; this.searchParams.search = ""; this.pagination.currentPage = 1; this.sortings = [ new SortingType('documentDate', 'desc', 'по дате'), new SortingType('documentNumber', 'desc', 'по номеру') ]; this.onFind(); } sortingsToString(): string { let result = ""; this.sortings.forEach((s, i) => { result += s.name + ' ' + s.value; if (i < this.sortings.length - 1) { result += ","; } }); return result; } onPaginationChange() { this.onFind(); } onSortingChange() { this.onFind(); } onFilterChanged() { this.searchParams.search = ""; this.pagination.currentPage = 1; this.sortings = [ new SortingType('documentDate', 'desc', 'по дате'), new SortingType('documentNumber', 'desc', 'по номеру') ]; this.onFind(); } addLink(link: any) { this.myBlockUI.start(); this.documentLinkRestService.create(link).then(response => { this.myBlockUI.stop(); this.toastr.success("Связь успешно добавлена!", "Успех"); this.onUpdate(); }).catch(error => { this.myBlockUI.stop(); this.toastr.error("Ошибка при добавлении связи!", "Ошибка"); }); } addLinks(links: any[]) { let promises: ng.IPromise[] = []; links.forEach(l => { promises.push(this.documentLinkRestService.create(l)); }); this.myBlockUI.start(); this.$q.all(promises).then(response => { this.myBlockUI.stop(); this.onUpdate(); this.toastr.success("Тип выделенных связей успешно изменён!", "Успех"); }).catch(error => { this.myBlockUI.stop(); this.toastr.error("Ошибка при изменении типа выделенных связей!", "Ошибка"); }); } } export const SearchCandidatesComponent: angular.IComponentOptions = { controller: SearchCandidatesController, template: require('./search-candidates.html'), bindings: { document: "<", chapters: "<", onUpdate: "&", onFind: "&", linkedDocuments: "<", linkdocStatuses: "<", linkdocTypes: "<", searchParams: "<", sortings: "<", pagination: "<", response: "<", statuses: "<" } };