File
Implements
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
checkUserMapping
|
checkUserMapping()
|
|
|
getEntities
|
getEntities(entityType)
|
|
Parameters :
Name |
Optional |
entityType |
No
|
|
getSubEntities
|
getSubEntities(stateId)
|
|
|
loadMoreEntities
|
loadMoreEntities()
|
|
|
selectEntity
|
selectEntity(event)
|
|
|
selectSubEntity
|
selectSubEntity(subEntity)
|
|
Parameters :
Name |
Optional |
subEntity |
No
|
|
entities
|
Type : []
|
Default value : []
|
|
limit
|
Type : number
|
Default value : 20
|
|
noSubEntity
|
Type : boolean
|
Default value : false
|
|
page
|
Type : number
|
Default value : 1
|
|
searchText
|
Type : string
|
Default value : ""
|
|
import { Component, OnInit, Input } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { LoaderService, LocalStorageService, NetworkService, ToastService, UtilsService } from '../../core';
import { urlConstants } from '../../core/constants/urlConstants';
import { KendraApiService } from '../../core/services/kendra-api.service';
import * as _ from 'underscore';
@Component({
selector: 'app-add-entity',
templateUrl: './add-entity.component.html',
styleUrls: ['./add-entity.component.scss'],
})
export class AddEntityComponent implements OnInit {
subEntities;
noSubEntity: boolean = false;
entities = [];
page = 1;
limit = 20;
childEntity;
searchText = "";
profileData;
stateId;
selectedEntity;
title;
entityCount
@Input() entityType: any;
constructor(
private loader: LoaderService,
private toast: ToastService,
private storage: LocalStorageService,
private kendraApiService: KendraApiService,
private modalCtrl: ModalController,
private networkService: NetworkService,
private utils: UtilsService
) {
this.onSearch = _.debounce(this.onSearch, 500);
}
ngOnInit() {
this.checkUserMapping();
}
selectEntity(event) {
this.selectedEntity = event;
}
selectSubEntity(subEntity) {
this.childEntity = subEntity.detail.value;
this.entities = [];
this.page = 1;
this.getEntities(subEntity.detail.value);
}
getEntities(entityType) {
if (this.networkService.isNetworkAvailable) {
const config = {
url:
urlConstants.API_URLS.GET_ENTITY_LIST +
this.stateId +
"?type=" +
entityType +
"&search=" +
encodeURIComponent(this.searchText) +
"&page=" +
this.page +
"&limit=" +
this.limit,
};
this.kendraApiService.get(config).subscribe(
(data) => {
if (data.result.data && data.result.data.length) {
this.entities = this.entities.concat(data.result.data);
this.entityCount = data.result.count;
this.noSubEntity = false;
} else {
this.noSubEntity = true;
}
},
(error) => {
}
);
} else {
this.toast.showMessage("FRMELEMNTS_MSG_YOU_ARE_WORKING_OFFLINE_TRY_AGAIN", "danger");
}
}
checkUserMapping() {
this.utils.getProfileData().then(profileData => {
this.profileData = profileData;
this.stateId = this.profileData.state;
this.getSubEntities(this.stateId);
})
}
loadMoreEntities() {
this.page++;
this.getEntities(this.childEntity);
}
getSubEntities(stateId) {
// to select entityType if already provided
if (this.entityType) {
let selist = [];
let entity = {
name: this.entityType,
value: this.entityType,
};
selist.push(entity);
this.subEntities = selist.reverse();
this.childEntity = this.subEntities[0].value;
this.getEntities(this.subEntities[0].value);
return
}
if (this.networkService.isNetworkAvailable) {
const config = {
url:urlConstants.API_URLS.GET_SUB_ENITIES_FOR_ROLES+stateId+`?role=${this.profileData.role}`
};
this.kendraApiService.get(config).subscribe(
(data) => {
if (data.result) {
let selist = [];
data.result.forEach((se) => {
let entity = {
name: se,
value: se,
};
selist.push(entity);
});
this.subEntities = selist.reverse();
this.childEntity = this.subEntities[0].value;
this.getEntities(this.subEntities[0].value);
}
},
(error) => {
}
);
} else {
this.toast.showMessage("FRMELEMNTS_MSG_YOU_ARE_WORKING_OFFLINE_TRY_AGAIN", "danger");
}
}
onSearch(event) {
this.entities = [];
this.page = 1;
this.searchText = event.detail ? event.detail.data : "";
if (event.detail && event.detail.data == null) {
this.searchText = "";
}
this.getEntities(this.childEntity);
}
close() {
this.modalCtrl.dismiss();
}
addEntity() {
if (this.selectedEntity) {
this.modalCtrl.dismiss(this.selectedEntity);
}
}
}
<ion-toolbar class="_bottomBorder">
<ion-title>
{{title | translate}}
</ion-title>
<ion-buttons (click)="close()" slot="start" class="padding custom-btn-txt-transform-none">
<ion-icon role="button" name="arrow-back" aria-label="back" slot="icon-only" style="padding-left: 10px;"></ion-icon>
</ion-buttons>
</ion-toolbar>
<ion-content>
<div *ngIf="subEntities ">
<ion-searchbar debounce="1000" (ionInput)="onSearch($event)" search-icon="search"></ion-searchbar>
<div class="ion-padding">
<ion-icon name="funnel" color="primary"></ion-icon> {{'FRMELEMNTS_LBL_FILTER' | translate}}
<ion-row>
<ion-col>
<ion-item>
<ion-label>{{'FRMELEMNTS_BTN_ENTITY' | translate}}</ion-label>
<ion-select interface="popover" value={{childEntity}} (ionChange)="selectSubEntity($event)">
<ion-select-option style="text-transform: capitalize !important;" *ngFor="let subEntity of subEntities" value="{{subEntity.value}}">{{subEntity.name | titlecase}}</ion-select-option>
</ion-select>
</ion-item>
</ion-col>
</ion-row>
<h5 class="entity-name"> {{childEntity}}</h5>
<ion-radio-group>
<ion-card class="enitity-list" *ngFor="let entity of entities">
<ion-item lines="none">
<ion-label>{{entity.name}}</ion-label>
<ion-radio slot="start" (click)="selectEntity(entity)" value="{{entity.value}}">
</ion-radio>
</ion-item>
</ion-card>
</ion-radio-group>
<div class="loadmore-btn" *ngIf="entities.length && entityCount > entities.length">
<ion-button (click)="loadMoreEntities()" class="custom-btn-txt-transform-none">
{{'FRMELEMNTS_BTN_LOAD_MORE' | translate}}</ion-button>
</div>
<app-no-data *ngIf="noSubEntity"></app-no-data>
</div>
</div>
</ion-content>
<ion-footer>
<div class="footer-btn" (click)="addEntity()">{{'FRMELEMNTS_LBL_ADD_ENTITY' | translate}}
</div>
</ion-footer>
@import "../../../../assets/styles/variables";
@import "../../../../assets/styles/base/variables";
.entity-name{
text-align: center;
color: var(--ion-color-primary);
text-transform: capitalize;
}
.enitity-list{
ion-label{
text-overflow: unset;
white-space: normal;
}
ion-checkbox{
margin-right: 15px;
}
}
.footer-btn{
text-align: center;
padding: 15px;
background: var(--app-primary);
color: $white;
}
.loadmore-btn{
text-align: center;
ion-button{
--border-radius:50px;
}
}
Legend
Html element with directive