import { Component, Injector, ViewChild, OnInit, ViewEncapsulation } from '@angular/core'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { OrganizationTreeComponent } from '@app/admin/organization-units/organization-tree.component'; // import { FleetUsersComponent } from './fleet-users.component'; import { ClinicCustomerGroup } from './clinic-groups-customer.component'; // import { FleetRatesComponent } from './fleet-rates.component'; // import { IFleetUnitInfo } from './fleets-unit-info'; // import { FleetsTreeComponent } from './fleets-tree.component'; import { FeatureCheckerService } from '@abp/features/feature-checker.service'; import { ClinicGroupTreeComponent } from './clinic-groups-tree.component'; import { ClinicGroupsSettings } from './clinic-groups-settings.component'; import { AppConsts } from '@shared/AppConsts'; import { HttpClient } from '@angular/common/http'; import * as moment from 'moment'; import * as _ from 'lodash'; import { interval } from 'rxjs'; import { ContactGroupServiceProxy } from '@shared/service-proxies/service-proxies'; import { ProgressBarService } from '@app/shared/layout/progressbar/progressbar.service'; import * as signalR from '@aspnet/signalr'; @Component({ templateUrl: './clinic-groups-unit.component.html', encapsulation: ViewEncapsulation.None, styleUrls: ['./clinic-groups-unit.component.less'], animations: [appModuleAnimation()] }) export class ClinicGroupsUnitComponent extends AppComponentBase { // @ViewChild('fleetUsers', {static: true}) fleetUsers: FleetUsersComponent; @ViewChild('customer', {static: true}) customer: ClinicCustomerGroup; @ViewChild('settings', {static: true}) settings: ClinicGroupsSettings; @ViewChild('clinicGroupsTree', {static: true}) clinicGroupsTree: ClinicGroupTreeComponent; // organizationUnit: IFleetUnitInfo = null; // showRates: boolean = true; uploadUrl: string; private hubConnection: signalR.HubConnection; constructor( injector: Injector, private _featureCheckerService: FeatureCheckerService, private _httpClient: HttpClient, private _contactGroupService: ContactGroupServiceProxy, private _progressBar: ProgressBarService ) { super(injector); } ngOnInit(): void { this.uploadUrl = AppConsts.remoteServiceBaseUrl + '/Import/ImportFromExcel'; // if(this._featureCheckerService.isEnabled('App.RouteManagementFeauture.ClinicManagement')) // { // $( document ).ready(function() { // $("#rates-link" ).css("display", "none"); // }); // this.showRates = false; // } this.backgroundProcessListener(); } ouSelected(event: any): void { this.customer.customerUnit = event; this.customer.addCustomerModal.groupId = event.id; this.settings.customerUnit = event; this.settings.groupId = event.id; // this.fleetUsers.organizationUnit = event; // this.fleetVehicles.organizationUnit = event; // if(this.showRates) { // this.fleetRates.organizationUnit = event; // } } reloadSettings(event): void{ //this.settings.getSettings = event; } uploadExcel(data: { files: File }): void { this.toggle(true); const formData: FormData = new FormData(); const file = data.files[0]; formData.append('file', file, file.name); formData.append('key','customerGroup'); let jobId: any; this._httpClient .post(this.uploadUrl, formData) .subscribe(response => { if (response.success) { jobId = response.result["responseText"].toString(); this.notify.info('Import process is queued. Please wait'); if (jobId != null) this.getJobState(jobId); } else if (response.error != null) { this.notify.error(this.l('ImportFailed')); this.toggle(false); } }); } toggle(toggle: boolean) { this._progressBar.toggleProgressBar(toggle); } sendMessage(message: string) { this._progressBar.sendMessage(message); } backgroundProcessListener() { this.hubConnection = new signalR.HubConnectionBuilder() .withUrl(AppConsts.remoteServiceBaseUrl + '/import') .build(); this.hubConnection .start() .then(() => console.log('Connection started')) .catch(err => { console.log('Error while starting connection: ' + err); this.toggle(false); }); this.hubConnection.on('BackgroundMessage', (message) => { console.log(message) if (message.match(/End Importing/)) { this.toggle(false); this.notify.success('Importing is complete'); } this.sendMessage(message); }); } uploadContactGroup(data: { files: File }): void { const formData: FormData = new FormData(); const file = data.files[0]; formData.append('file', file, file.name); formData.append('key','contactgroup'); let jobId: any; this._httpClient .post(this.uploadUrl, formData) .subscribe(response => { if (response.success) { jobId = response.result["responseText"].toString(); this.notify.info('Import process is queued. Please wait'); if (jobId != null) this.getJobState(jobId); this.toggle(true); } else if (response.error != null) { this.notify.error(this.l('ImportFailed')); //this.toggle(false); } }); } onUploadExcelError(): void { this.notify.error(this.l('ImportFailed')); } getJobState(jobId: string): void { let observable = interval(1500).subscribe((val) => { this._contactGroupService.getJobState(jobId).subscribe(result => { if (result) { this.notify.success('Import process is complete'); this.toggle(false); this.clinicGroupsTree.reload(); observable.unsubscribe(); } }) }); } }