src/app/plugins/location/components/location-selection/location-selection.component.ts
OnInit
OnDestroy
AfterViewInit
selector | app-location-selection |
styleUrls | ./location-selection.component.scss |
templateUrl | ./location-selection.component.html |
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(resourceService: ResourceService, toasterService: ToasterService, locationService: LocationService, router: Router, userService: UserService, deviceRegisterService: DeviceRegisterService, navigationHelperService: NavigationHelperService, popupControlService: PopupControlService, telemetryService: TelemetryService, formService: FormService, orgDetailsService: OrgDetailsService, utilService: UtilService, matDialog: MatDialog)
|
||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
deviceProfile | |
Type : IDeviceProfile
|
|
isClosable | |
Type : boolean
|
|
Default value : true
|
|
isStepper | |
Type : boolean
|
|
Default value : false
|
|
showModal | |
Type : boolean
|
|
Default value : true
|
|
close | |
Type : EventEmitter
|
|
onFormValueChange | |
Type : EventEmitter<boolean>
|
|
registerSubmit | |
Type : EventEmitter
|
|
Async clearUserLocationSelections |
clearUserLocationSelections()
|
Returns :
any
|
closeModal |
closeModal()
|
Returns :
void
|
Private generateCancelInteractEvent |
generateCancelInteractEvent()
|
Returns :
void
|
Private generateSubmitInteractEvent | ||||||
generateSubmitInteractEvent(changes: string)
|
||||||
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onSbFormValueChange | ||||||
onSbFormValueChange(changes: any)
|
||||||
Parameters :
Returns :
void
|
Private telemetryLogEvents |
telemetryLogEvents(locationType: any, isSuccessful: boolean)
|
Returns :
void
|
Async updateUserLocation |
updateUserLocation()
|
Returns :
any
|
Public deviceRegisterService |
Type : DeviceRegisterService
|
isSubmitted |
Default value : false
|
Public locationSelectionModalId |
Type : string
|
Default value : 'location-selection'
|
Public locationService |
Type : LocationService
|
Public navigationHelperService |
Type : NavigationHelperService
|
onboardingModal |
Decorators :
@ViewChild('onboardingModal', {static: true})
|
Public popupControlService |
Type : PopupControlService
|
Public resourceService |
Type : ResourceService
|
Public router |
Type : Router
|
sbFormLocationSelectionDelegate |
Type : SbFormLocationSelectionDelegate
|
telemetryImpression |
Type : IImpressionEventInput
|
Public toasterService |
Type : ToasterService
|
Public userService |
Type : UserService
|
import { AfterViewInit, Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { ResourceService, ToasterService, NavigationHelperService, UtilService } from '@sunbird/shared';
import { DeviceRegisterService, FormService, OrgDetailsService, UserService } from '../../../../modules/core/services';
import { Router } from '@angular/router';
import { LocationService } from '../../services/location/location.service';
import { IImpressionEventInput, IInteractEventInput, TelemetryService } from '@sunbird/telemetry';
import { PopupControlService } from '../../../../service/popup-control.service';
import { IDeviceProfile } from '../../../../modules/shared-feature/interfaces/deviceProfile';
import { SbFormLocationSelectionDelegate } from '../delegate/sb-form-location-selection.delegate';
import { MatDialog } from '@angular/material/dialog';
import * as _ from 'lodash-es';
import {Location as SbLocation} from '@project-sunbird/client-services/models/location';
@Component({
selector: 'app-location-selection',
templateUrl: './location-selection.component.html',
styleUrls: ['./location-selection.component.scss']
})
export class LocationSelectionComponent implements OnInit, OnDestroy, AfterViewInit {
@Input() isClosable = true;
@Input() showModal = true;
@Input() deviceProfile: IDeviceProfile;
@Output() close = new EventEmitter<any>();
@Output() registerSubmit = new EventEmitter<any>();
@Output() onFormValueChange: EventEmitter<boolean> = new EventEmitter<boolean>();
@ViewChild('onboardingModal', { static: true }) onboardingModal;
telemetryImpression: IImpressionEventInput;
sbFormLocationSelectionDelegate: SbFormLocationSelectionDelegate;
isSubmitted = false;
public locationSelectionModalId = 'location-selection';
@Input() isStepper = false;
constructor(
public resourceService: ResourceService,
public toasterService: ToasterService,
public locationService: LocationService,
public router: Router,
public userService: UserService,
public deviceRegisterService: DeviceRegisterService,
public navigationHelperService: NavigationHelperService,
public popupControlService: PopupControlService,
protected telemetryService: TelemetryService,
protected formService: FormService,
private orgDetailsService: OrgDetailsService,
private utilService: UtilService,
private matDialog: MatDialog
) {
this.sbFormLocationSelectionDelegate = new SbFormLocationSelectionDelegate(
this.userService,
this.locationService,
this.formService,
this.deviceRegisterService,
this.orgDetailsService
);
}
ngOnInit() {
this.popupControlService.changePopupStatus(false);
this.sbFormLocationSelectionDelegate.init(this.deviceProfile, this.showModal, this.isStepper )
.catch(() => {
this.closeModal();
this.toasterService.error(this.resourceService.messages.fmsg.m0049);
});
}
ngOnDestroy() {
this.sbFormLocationSelectionDelegate.destroy();
}
ngAfterViewInit() {
setTimeout(() => {
this.telemetryImpression = {
context: {
env: 'user-location',
cdata: [{ id: 'user:state:districtConfirmation', type: 'Feature' },
{ id: 'SH-40', type: 'Task' }
]
},
edata: {
type: 'view',
pageid: 'location-popup',
uri: this.router.url,
duration: this.navigationHelperService.getPageLoadTime()
}
};
});
}
closeModal() {
const dialogRef = this.matDialog.getDialogById(this.locationSelectionModalId);
dialogRef && dialogRef.close();
this.popupControlService.changePopupStatus(true);
this.close.emit({isSubmitted: this.isSubmitted});
}
async updateUserLocation() {
if (this.showModal) {
try {
const result: any = await this.sbFormLocationSelectionDelegate.updateUserLocation();
/* istanbul ignore else */
if (result.userProfile) {
this.telemetryLogEvents('User Profile', result.userProfile === 'success');
this.utilService.updateRoleChange(result.type);
}
/* istanbul ignore else */
if (result.deviceProfile) {
if (!result.type) {
this.utilService.updateRoleChange(localStorage.getItem('userType'));
}
this.telemetryLogEvents('Device Profile', result.userProfile === 'success');
}
this.generateSubmitInteractEvent(result.changes);
} catch (e) {
this.toasterService.error(this.resourceService.messages.fmsg.m0049);
} finally {
this.isSubmitted = true;
this.closeModal();
}
} else if (_.get(this.userService, 'loggedIn') && _.get(this.userService, 'userid')) {
const result: any = await this.sbFormLocationSelectionDelegate.formGroup;
const locationDetails: SbLocation[] = Object.keys(_.get(result, 'value.children.persona'))
.reduce<SbLocation[]>((acc, key) => {
const locationDetail: SbLocation | null = _.get(result, 'value.children.persona')[key];
if (_.get(locationDetail, 'code')) {
acc.push(locationDetail);
}
return acc;
}, []);
const userTypes = [{ type: 'teacher' }];
const payload: any = {
userId: _.get(this.userService, 'userid'),
profileLocation: locationDetails,
profileUserTypes: userTypes
};
this.locationService.updateProfile(payload).toPromise()
.then((res) => {
this.registerSubmit.emit(_.get(result, 'value'));
this.toasterService.success(this.resourceService?.messages?.smsg?.m0057);
}).catch((err) => {
this.toasterService.error(this.resourceService?.messages?.emsg?.m0005);
});
} else {
const result: any = await this.sbFormLocationSelectionDelegate.formGroup;
this.registerSubmit.emit(_.get(result, 'value'));
}
}
async clearUserLocationSelections() {
await this.sbFormLocationSelectionDelegate.clearUserLocationSelections();
this.generateCancelInteractEvent();
}
private generateCancelInteractEvent() {
this.telemetryService.interact({
context: {
env: 'user-location',
cdata: [
{ id: 'user:location_capture', type: 'Feature' },
{ id: 'SB-21152', type: 'Task' }
],
},
edata: {
id: 'cancel-clicked',
type: 'TOUCH'
}
});
}
private generateSubmitInteractEvent(changes: string) {
const interactEData = {
id: 'submit-clicked',
type: changes ? 'location-changed' : 'location-unchanged',
subtype: changes
};
const telemetryCdata = [
{ id: 'user:location_capture', type: 'Feature' },
{ id: 'SB-21152', type: 'Task' }
];
/* istanbul ignore else */
if (interactEData) {
const appTelemetryInteractData: IInteractEventInput = {
context: {
env: 'user-location',
cdata: [
{ id: 'user:location_capture', type: 'Feature' },
{ id: 'SB-21152', type: 'Task' }
],
},
edata: interactEData
};
/* istanbul ignore else */
if (telemetryCdata) {
appTelemetryInteractData.object = telemetryCdata as any;
}
this.telemetryService.interact(appTelemetryInteractData);
}
}
private telemetryLogEvents(locationType: any, isSuccessful: boolean) {
const { level, msg } = (() => {
if (isSuccessful) {
return { level: 'SUCCESS', msg: 'Updation of ' + locationType + ' success' };
}
return { level: 'ERROR', msg: 'Updation of ' + locationType + ' failed' };
})();
const event = {
context: {
env: 'portal'
},
edata: {
type: 'update-location',
level: level,
message: msg
}
};
this.telemetryService.log(event);
}
onSbFormValueChange(changes: any) {
this.onFormValueChange.emit(true);
}
}
<!-- New Pop up -->
<app-modal-wrapper *ngIf="showModal && !isStepper" [config]="{disableClose: true, id: locationSelectionModalId, panelClass: ['overflow-visible', 'material-modal']}" (dismiss)="closeModal()">
<ng-template sbModalContent let-data>
<div class="sb-mat__modal sb-onboard">
<div mat-dialog-title class="flex-jc-center">
<div class="sb-onboard__header">
<ng-content select="[slot=popup-header]"></ng-content>
</div>
<button aria-label="close dialog" mat-dialog-close class="close-btn" *ngIf="isClosable">
</button>
</div>
<mat-dialog-content>
<div class="sb-mat__modal__content">
<div>
<ng-content select="[slot=popup-sub-header]"></ng-content>
</div>
<div>
<div class="schooling-location" [appTelemetryImpression]="telemetryImpression">
<div class="w-100">
<sb-form
*ngIf="sbFormLocationSelectionDelegate.locationFormConfig && sbFormLocationSelectionDelegate.locationFormConfig.length"
[config]="sbFormLocationSelectionDelegate.locationFormConfig"
(initialize)="sbFormLocationSelectionDelegate.onFormInitialize($event)"
(valueChanges)="sbFormLocationSelectionDelegate.onFormValueChange($event)"
(dataLoadStatus)="sbFormLocationSelectionDelegate.onDataLoadStatusChange($event)">
</sb-form>
</div>
</div>
</div>
</div>
</mat-dialog-content>
<mat-dialog-actions class="mb-0 sb-mat__modal__actions flex-jc-center d-block">
<div class="sb-onboard__footer mt-0">
<ng-content select="[slot=popup-footer]"></ng-content>
</div>
<div class="sb-onboard__footer d-flex flex-ai-center flex-jc-center w-80 m-auto">
<button type="button" class="sb-btn sb-btn-sm sb-btn-white text-uppercase flex-basis-1" type="submit"
[class.sb-btn-disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading"
[disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading" (click)="clearUserLocationSelections()"
tabindex="0">{{resourceService?.frmelmnts?.btn?.clear}}
</button>
<button type="button" class="sb-btn sb-btn-sm sb-btn-primary text-uppercase flex-basis-1 ml-24" type="submit"
[class.sb-btn-disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading || sbFormLocationSelectionDelegate.formGroup?.invalid"
[disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading || sbFormLocationSelectionDelegate.formGroup?.invalid"
(click)="updateUserLocation()" tabindex="0">{{resourceService?.frmelmnts?.btn?.submit}}
<span class='arrow-icon'>
<em class="icon-svg icon-svg--xxs icon-back">
<svg class="icon icon-svg--white">
<use xlink:href="assets/images/sprite.svg#arrow-long-right"></use>
</svg>
</em>
</span>
</button>
</div>
</mat-dialog-actions>
</div>
</ng-template>
</app-modal-wrapper>
<div *ngIf="!showModal || isStepper" class="sb-mat__modal sb-onboard">
<mat-dialog-content>
<div class="sb-mat__modal__content">
<div>
<div class="schooling-location" [appTelemetryImpression]="telemetryImpression">
<div class="w-100">
<sb-form
*ngIf="sbFormLocationSelectionDelegate && sbFormLocationSelectionDelegate.locationFormConfig && sbFormLocationSelectionDelegate.locationFormConfig.length"
[config]="sbFormLocationSelectionDelegate?.locationFormConfig"
(initialize)="sbFormLocationSelectionDelegate?.onFormInitialize($event)"
(valueChanges)="sbFormLocationSelectionDelegate?.onFormValueChange($event); onSbFormValueChange($event);"
(dataLoadStatus)="sbFormLocationSelectionDelegate?.onDataLoadStatusChange($event, showModal,isStepper)">
</sb-form>
</div>
</div>
</div>
</div>
</mat-dialog-content>
<mat-dialog-actions class="mb-0 sb-mat__modal__actions flex-jc-center d-block">
<div class="sb-onboard__footer mt-0">
<ng-content select="[slot=popup-footer]"></ng-content>
</div>
<div class="sb-onboard__footer d-flex">
<button type="button" class="sb-btn sb-btn-sm sb-btn-white text-uppercase flex-basis-1" type="submit"
[class.sb-btn-disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading"
[disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading" (click)="clearUserLocationSelections()"
tabindex="0">{{resourceService?.frmelmnts?.btn?.clear}}
</button>
<div class="w-10"></div>
<button type="button" class="sb-btn sb-btn-sm sb-btn-primary text-uppercase flex-basis-1" type="submit"
[class.sb-btn-disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading || sbFormLocationSelectionDelegate.formGroup?.invalid"
[disabled]="sbFormLocationSelectionDelegate.isLocationFormLoading || sbFormLocationSelectionDelegate.formGroup?.invalid"
(click)="updateUserLocation()" tabindex="0">{{resourceService?.frmelmnts?.btn?.submit}}
<span class='arrow-icon'>
<em class="icon-svg icon-svg--xxs icon-back">
<svg class="icon icon-svg--white">
<use xlink:href="assets/images/sprite.svg#arrow-long-right"></use>
</svg>
</em>
</span>
</button>
</div>
</mat-dialog-actions>
</div>
./location-selection.component.scss
::ng-deep {
html[layout=joy] app-location-selection .sb-mat__dropdown.mat-form-field-appearance-fill .mat-form-field-flex {
border-color: var(--gray-200);
}
}