import { Component, Injector, ViewChild, ViewEncapsulation, } from "@angular/core"; import { UserServiceProxy, CustomerServiceProxy, BusinessHoursServiceProxy, GetCustomerProfileDto, GetBusinessHoursDto, ContactPersonsServiceProxy, GetContactPersonsDto, ProfileServiceProxy, GetContactPersonsList, } from "@shared/service-proxies/service-proxies"; import { AppComponentBase } from "@shared/common/app-component-base"; import { appModuleAnimation } from "@shared/animations/routerTransition"; import { Table } from "primeng/components/table/table"; import { LazyLoadEvent } from "primeng/api"; import { Paginator } from 'primeng/components/paginator/paginator'; import { catchError, finalize } from 'rxjs/operators'; import { PermissionTreeModalComponent } from '@app/admin/shared/permission-tree-modal.component'; import { PrimengTableHelper } from "@shared/helpers/PrimengTableHelper"; import { AppConsts } from "@shared/AppConsts"; import { ChangeProfilePictureModalComponent } from "@app/shared/layout/profile/change-profile-picture-modal.component"; import { EntityTypeHistoryModalComponent } from "@app/shared/common/entityHistory/entity-type-history-modal.component"; import { nullableFloatToModel } from "devexpress-dashboard/model/index.metadata"; import { result } from "lodash"; // import { PermissionTreeModalComponent } from '../shared/permission-tree-modal.component'; @Component({ selector: "app-customer-portal", templateUrl: "./customer-portal.component.html", styleUrls: ["./customer-portal.component.css"], encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class CustomerPortalComponent extends AppComponentBase { @ViewChild('dataTable', { static: true }) dataTable: Table; @ViewChild('paginator', { static: true }) paginator: Paginator; @ViewChild('changeProfilePictureModal', { static: true }) changeProfilePictureModal: ChangeProfilePictureModalComponent; @ViewChild('permissionFilterTreeModal', { static: true }) permissionFilterTreeModal: PermissionTreeModalComponent; uploadUrl: string; //Filters advancedFiltersAreShown = false; filterText = ''; role = ''; onlyLockedUsers = false; saving: boolean; profile: GetCustomerProfileDto = new GetCustomerProfileDto(); hour: GetBusinessHoursDto[]; persons: GetContactPersonsList[]; contactPerson = new GetContactPersonsDto(); primengTableHelper: PrimengTableHelper; profilePicture = AppConsts.appBaseUrl + '/assets/common/images/default-profile-picture.png'; retriving:boolean=true; numMore: number = 0; hasContactPerson: boolean = false; @ViewChild('entityTypeHistoryModal', { static: true }) entityTypeHistoryModal: EntityTypeHistoryModalComponent; _entityTypeFullName = 'SprintTek.Shipping.OrderTypes.OrderType'; entityHistoryEnabled = false; address: string=""; clinicName: string=""; onLoad: boolean; constructor(injector: Injector, private _contactPersonProxy: ContactPersonsServiceProxy, private _customerProfileProxy: CustomerServiceProxy, private _businessHoursServiceProxy : BusinessHoursServiceProxy, private _profileServiceProxy: ProfileServiceProxy, ) { super(injector); } ngOnInit(): void { this.getCustomerProfile(); this.getProfilePicture(); this.registerEvent(); } getCustomerProfile(){ this.spinnerService.show(); this.retriving = true; this._customerProfileProxy.getCustomerProfile() .pipe(catchError((err, caught): any => { this.spinnerService.hide(); })) .subscribe((result: GetCustomerProfileDto) => { this.profile = result; this.retriving = false; this.spinnerService.hide(); if(result.userId!=null){ this.profilePicture = result.profilePicture == null || result.profilePicture == "" ? AppConsts.appBaseUrl + '/assets/common/images/default-profile-picture.png' : 'data:image/jpeg;base64,' + result.profilePicture; localStorage.setItem("customerUserId", result.userId.toString()); } var addressLine2 = result.addressLine2==null ? "" : " " +result.addressLine2 this.address = result.addressLine1 +addressLine2 +" " +result.city +", " +result.state +" " +result.postalCode; this.clinicName = result.accountNo +" | " +result.clinicName; if(result.phone!=''|| result.phone == null){ this.onLoad = true; } this.spinnerService.hide(); }); this.getBusinessHours(); } getBusinessHours(){ this.spinnerService.show(); this._businessHoursServiceProxy.getBusinessHours() .pipe(catchError((err, caught): any => { this.spinnerService.hide(); })) .subscribe((result: GetBusinessHoursDto[]) => { this.hour = result; this.spinnerService.hide(); }); } getContactPersons(event?: LazyLoadEvent){ if (this.primengTableHelper.shouldResetPaging(event)) { this.paginator.changePage(0); console.log("no data"); return; } this.spinnerService.show(); this._customerProfileProxy.getAllContactPerson(this.primengTableHelper.getSorting(this.dataTable), this.primengTableHelper.getSkipCount(this.paginator, event), this.primengTableHelper.getMaxResultCount(this.paginator, event)) .subscribe(result => { this.primengTableHelper.totalRecordsCount = result.totalCount; this.primengTableHelper.records = result.items; this.spinnerService.hide(); }); } // getContactPerson(){ // this.spinnerService.show(); // this._contactPersonProxy.getContactPersons() // .pipe(catchError((err, caught): any => { // this.spinnerService.hide(); // })) // .subscribe((result: GetContactPersonsDto) => { // if(result!=null){ // this.hasContactPerson = true; // this.contactPerson = result; // this.numMore = this.contactPerson.getContactPersons.length - 3; // console.log(this.contactPerson.getContactPersons.length); // } // }); // } gotoEditProfile(): void { // abp.event.trigger('app.show.mySettingsModal'); abp.event.trigger('app.show.appchangecustomerprofilemodal'); } changeProfilePicture(): void { abp.event.trigger('app.show.changeProfilePictureModal'); } getProfilePicture(): void { this._profileServiceProxy.getProfilePicture().subscribe(result => { if (result && result.profilePicture) { this.profilePicture = 'data:image/jpeg;base64,' + result.profilePicture; } }); } registerEvent(){ abp.event.on('profilePictureChanged', () => { this.getProfilePicture(); }); } }