import { ChangeDetectorRef, Component, EventEmitter, Injector, OnInit, Output, ViewChild } from '@angular/core'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { OrganizationUnitServiceProxy, OrganizationUnitRoleListDto, FleetVehicleServiceProxy, PagedResultDtoOfFleetVehicleListDto, FleetVehicleListDto, ContactGroupServiceProxy, CreateOrUpdateContactGroupSettingInputDto } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { Paginator } from 'primeng/components/paginator/paginator'; import { Table } from 'primeng/components/table/table'; import { finalize } from 'rxjs/operators'; import { IRoleWithOrganizationUnit } from '@app/admin/organization-units/role-with-organization-unit'; import { IRolesWithOrganizationUnit } from '@app/admin/organization-units/roles-with-organization-unit'; import { IBasicOrganizationUnitInfo } from '@app/admin/organization-units/basic-organization-unit-info'; import { AddCustomerModalComponent } from './add-customer.component'; // import { IFleetUnitInfo } from './fleets-unit-info'; // import { IVehicleWithFleet } from './vehicle-with-fleet.component'; // import { IVehiclesWithFleet } from './vehicles-with-fleet.component'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import { IClinicGroupUnit } from './clinic-groups-unit.info'; import { IClinicSettingsUnit } from './clinic-settings-unit.info'; import { ICustomerWithGroup } from './customer-with-group.component'; @Component({ selector: 'clinic-groups-settings', templateUrl: './clinic-groups-settings.component.html', styleUrls: ['./clinic-groups-settings.component.less'], animations: [appModuleAnimation()] }) export class ClinicGroupsSettings extends AppComponentBase implements OnInit { @Output() customerAdded = new EventEmitter(); @ViewChild('addSettingsModal', {static: true}) addSettingsModal: AddCustomerModalComponent; @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; groupId : number _entityTypeFullName = 'SprintTek.Shipping.Contacts.ContactGroupSetting'; entityHistoryEnabled = false; enableEtaLockValidation = false; checkDriverVicinity= false; putItemsInPurpleBag = false settingsColor:any; settingsMessage:any; SetEtaLock:any = false; BagColor:any; SetRequireBag:any = false; SetReportZeroCount:any = false; WillCallMessage:any; SetPhotoRequired:any = false; SettingsAttachmentsNote:any; SetRequireDeliveryPhoto:any; SetDeliveryPhotoNote:any; private _customerUnit: IClinicGroupUnit = null; constructor( injector: Injector, private _changeDetector: ChangeDetectorRef, private _organizationUnitService: OrganizationUnitServiceProxy, private _fleetVehicleService: FleetVehicleServiceProxy, private _contactGroupServiceProxy: ContactGroupServiceProxy, ) { super(injector); } get customerUnit(): IClinicGroupUnit { return this._customerUnit; } set customerUnit(ou: IClinicGroupUnit) { if (this._customerUnit === ou) { return; } this._customerUnit = ou; // this.addSettingsModal.groupId = this._customerUnit.id; if (ou) { this.reloadPage(); } } ngOnInit(): void { this.setIsEntityHistoryEnabled(); this.SettingsAttachmentsNote = ""; this.settingsMessage = ""; $('.textfield').val(""); } private setIsEntityHistoryEnabled(): void { let customSettings = (abp as any).custom; this.entityHistoryEnabled = customSettings.EntityHistory && customSettings.EntityHistory.isEnabled && _.filter(customSettings.EntityHistory.enabledEntities, entityType => entityType === this._entityTypeFullName).length === 1; } showHistory(role: FleetVehicleListDto): void { this.entityTypeHistoryModal.show({ entityId: role.id.toString(), entityTypeFullName: this._entityTypeFullName, entityTypeDescription: "" }); } getSettings(event?: LazyLoadEvent) { this.SettingsAttachmentsNote = ""; this.settingsMessage = ""; $('.textfield').val(""); this.SetEtaLock = false; this.settingsColor = ""; this.SetRequireBag = false; this.SetPhotoRequired = false; this.SetReportZeroCount = false; this.SetRequireDeliveryPhoto = false; this.SetDeliveryPhotoNote = ""; if (!this._customerUnit) { return; } if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._contactGroupServiceProxy.getContactGroupSettingTypes( // this._customerUnit.id, // this.primengTableHelper.getSorting(this.dataTable), // this.primengTableHelper.getMaxResultCount(this.paginator, event), // this.primengTableHelper.getSkipCount(this.paginator, event) ).pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { this.primengTableHelper.totalRecordsCount = result.length; this.primengTableHelper.records = result; //this.spinnerService.hide(); }); this._contactGroupServiceProxy.getSettingsForContactGroup( this._customerUnit.id, this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getMaxResultCount(this.paginator, event), this.primengTableHelper.getSkipCount(this.paginator, event) ).pipe(finalize(() => this.spinnerService.hide())).subscribe(result => { result.items.forEach(element => { if(element.code == 'EtaLock'){ this.SetEtaLock = (element.value == 'true' ? true: false); } else if (element.code == 'BagColor'){ this.settingsColor = element.value; } else if (element.code == 'WillCallMessage'){ this.settingsMessage = element.value; } else if (element.code == 'RequireBag'){ this.SetRequireBag = (element.value == 'true' ? true: false); } else if (element.code == 'PhotoRequired'){ this.SetPhotoRequired = (element.value == 'true' ? true: false); } else if (element.code == 'AttachmentsNote'){ this.SettingsAttachmentsNote = element.value; } else if (element.code == 'ReportZeroCount'){ this.SetReportZeroCount = (element.value == 'true' ? true: false); } else if (element.code == 'RequireDeliveryPhoto'){ this.SetRequireDeliveryPhoto = (element.value == 'true' ? true: false); } else if (element.code == 'DeliveryPhotoNote'){ this.SetDeliveryPhotoNote = element.value; } }); this.spinnerService.hide(); }); } reloadPage(): void { this.paginator.changePage(this.paginator.getPage()); } refreshRoles(): void { this.reloadPage(); } openAddSettingsModal(): void { this.addSettingsModal.show(); } // removeVehicle(vehicle: FleetVehicleListDto): void { // this.message.confirm( // '','Are you sure?', // (isConfirmed) => { // if (isConfirmed) { // this._fleetVehicleService.deleteFleetVehicle(vehicle.id) // .subscribe(() => { // this.vehicleRemoved.emit({ // vehicleId: vehicle.vehicleId, // ouId: this.organizationUnit.id // }); // this.getVehicles(); // this.notify.success(this.l('SuccessfullyDeleted')); // }); // } // } // ); // } // addSettings(data: any): void { // this.customerAdded.emit({ // contactIds: data.contactIds, // ouId: data.ouId // }); // this.refreshRoles(); // } addSettings(code): void { this.spinnerService.show() let input = new CreateOrUpdateContactGroupSettingInputDto(); input.groupId = this.groupId; input.code = code; if(code == 'EtaLock'){ input.value = this.SetEtaLock.toString(); } else if (code == 'RequireBag'){ input.value = this.SetRequireBag.toString(); } else if (code == 'WillCallMessage'){ input.value = this.settingsMessage; } else if (code == 'BagColor'){ input.value = this.settingsColor; } else if (code == 'PhotoRequired'){ input.value = this.SetPhotoRequired.toString(); } else if (code == 'AttachmentsNote'){ input.value = this.SettingsAttachmentsNote; } else if (code == 'ReportZeroCount'){ input.value = this.SetReportZeroCount.toString(); } else if (code == 'RequireDeliveryPhoto'){ input.value = this.SetRequireDeliveryPhoto.toString(); } else if (code == 'DeliveryPhotoNote'){ input.value = this.SetDeliveryPhotoNote; } this._contactGroupServiceProxy .createOrUpdateContactGroupSetting(input) .subscribe(() => { this.notify.success(this.l('SuccessfullyAdded')); // this.membersAdded.emit({ // contactIds: input.contactIds, // ouId: input.contactGroupId // }); // this.saving = false; // this.close(); this.spinnerService.hide() },error => { this.spinnerService.hide() }); // this.refreshRoles(); } saveEtaLockValidationSettings(){ this.spinnerService.show() let input = new CreateOrUpdateContactGroupSettingInputDto(); input.groupId = this.groupId; console.log(this.groupId) if(this.enableEtaLockValidation == true){ input.value = "true" } else{ input.value="false" } input.code="EtaLock" console.log(input) this._contactGroupServiceProxy.createOrUpdateEtaLock(input) .subscribe(()=>{ this.spinnerService.hide() this.notify.success(this.l('SavedSuccessfully')); }) } saveProximityLockSettings(){ this.spinnerService.show() let input = new CreateOrUpdateContactGroupSettingInputDto(); input.groupId = this.groupId; console.log(this.groupId) if(this.checkDriverVicinity == true){ input.value = "true" } else{ input.value="false" } input.code="ProximityLock" console.log(input) this._contactGroupServiceProxy.createOrUpdateProximityLock(input) .subscribe(()=>{ this.spinnerService.hide() this.notify.success(this.l('SavedSuccessfully')); }) } saveUsePurpleBagSettings(){ this.spinnerService.show() let input = new CreateOrUpdateContactGroupSettingInputDto(); input.groupId = this.groupId; console.log(this.groupId) if(this.putItemsInPurpleBag == true){ input.value = "true" } else{ input.value="false" } input.code="PurpleBag" console.log(input) this._contactGroupServiceProxy.createOrUpdateUsePurpleBag(input) .subscribe(()=>{ this.spinnerService.hide() this.notify.success(this.l('SavedSuccessfully')); }) } }