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,DeletContactFromGroupInputDto, ContactGroupServiceProxy, DriverListInput } 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 { IFleetUnitInfo } from './fleets-unit-info'; // import { IVehiclesWithFleet } from './vehicles-with-fleet.component'; import { EntityTypeHistoryModalComponent } from '@app/shared/common/entityHistory/entity-type-history-modal.component'; import * as _ from 'lodash'; import { AddCustomerModalComponent } from './add-customer.component'; import { IClinicGroupUnit } from './create-or-edit-customer-groups.component'; import { ICustomerWithGroup } from './customer-with-group.component'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; @Component({ selector: 'clinic-groups-customer', templateUrl: './clinic-groups-customer.component.html', animations: [appModuleAnimation()] }) export class ClinicCustomerGroup extends AppComponentBase implements OnInit { @Output() customerRemoved = new EventEmitter(); @Output() customerAdded = new EventEmitter(); @ViewChild('addCustomerModal', {static: true}) addCustomerModal: AddCustomerModalComponent; @ViewChild('dataTable', {static: true}) dataTable: Table; @ViewChild('paginator', {static: true}) paginator: Paginator; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Shipping.Contacts.ContactGroup'; entityHistoryEnabled = false; @ViewChild('driversList', { static: true }) driversList: CommonLookupModalComponent; 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.fleetAddVehicleComponent.fleetId = ou.id; if (ou) { this.reloadPage(); } } ngOnInit(): void { // this.driversList.configure({ // title: this.l('Assign Driver'), // type: 'assignDriver', // dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?: number) => { // let input = new DriverListInput(); // input.filter = filter; // input.maxResultCount = maxResultCount; // input.skipCount = skipCount; // input.tenantId = tenantId; // input.locationId = parseInt(localStorage.getItem('operatingLocationId')); // return this._controllerRouteDetails.assignDriversList(input); // } // }); this.setIsEntityHistoryEnabled(); } 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: "" }); } getContacts(event?: LazyLoadEvent) { if (!this._customerUnit) { return; } if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); return; } this.spinnerService.show(); this._contactGroupServiceProxy.getContactsForGroup( 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.totalCount; for(var data in result.items){ result.items[data].firstName = result.items[data].company == null ? result.items[data].firstName : result.items[data].company.accountNo +" - " +result.items[data].company.name; } this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } reloadPage(): void { // this.paginator.changePage(this.paginator.getPage()); this.getContacts(); } // refreshRoles(): void { // this.reloadPage(); // } openAddCustomerModal(): void { this.addCustomerModal.show(); } removeCustomer(data): void { var input = new DeletContactFromGroupInputDto(); input.contactId = data.id; input.groupId = this._customerUnit.id; this.message.confirm( '','Are you sure?', (isConfirmed) => { if (isConfirmed) { this.spinnerService.show() this._contactGroupServiceProxy.deletContactFromGroup(input) .subscribe(() => { this.customerRemoved.emit({ contactIds: data.id, ouId: this._customerUnit.id }); this.spinnerService.hide() this.reloadPage(); this.notify.success(this.l('SuccessfullyDeleted')); }); } } ); } addCustomersToGroup(data: any): void { this.customerAdded.emit({ contactIds: data.contactIds, ouId: data.ouId }); console.log(this.customerAdded); this.reloadPage(); } }