File

src/app/manage-learn/shared/components/entityfilter/entityfilter.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(localStorage: LocalStorageService, navParams: NavParams, loader: LoaderService, httpClient: HttpClient, modalCtrl: ModalController, assessmentService: AssessmentApiService, utils: UtilsService, ref: ChangeDetectorRef, kendra: KendraApiService)
Parameters :
Name Type Optional
localStorage LocalStorageService No
navParams NavParams No
loader LoaderService No
httpClient HttpClient No
modalCtrl ModalController No
assessmentService AssessmentApiService No
utils UtilsService No
ref ChangeDetectorRef No
kendra KendraApiService No

Methods

addSchools
addSchools()
Returns : void
cancel
cancel()
Returns : void
checkItem
checkItem(listItem)
Parameters :
Name Optional
listItem No
Returns : void
clearEntity
clearEntity()
Returns : void
doInfinite
doInfinite(infiniteScroll)
Parameters :
Name Optional
infiniteScroll No
Returns : void
Async getTargettedEntityType
getTargettedEntityType()
Returns : any
ngOnInit
ngOnInit()
Returns : void
onStateChange
onStateChange(event)
Parameters :
Name Optional
event No
Returns : void
openSelect
openSelect()
Returns : void
Async search
search(event?)
Parameters :
Name Optional
event Yes
Returns : any
searchEntity
searchEntity()
Returns : void
toggleInfiniteScroll
toggleInfiniteScroll(e)
Parameters :
Name Optional
e No
Returns : void

Properties

allStates
Type : Array<Object>
arr
Type : []
Default value : []
entity
Type : any
entityList
entityType
index
Type : any
Default value : 50
infiniteScroll
Type : IonInfiniteScroll
Decorators :
@ViewChild(IonInfiniteScroll, {static: true})
isProfileAssignedWithState
Type : boolean
limit
Type : number
Default value : 50
loading
Type : boolean
Default value : false
observationId
page
Type : number
Default value : 1
payload
profileData
Type : any
profileMappedState
Type : any
searchQuery
searchUrl
searchValue
Type : string
Default value : ''
selectableList
Type : any
Default value : []
selectedItems
Type : any
Default value : []
selectedListCount
Type : object
Default value : { count: 0, }
selectedState
selectStateRef
Decorators :
@ViewChild('selectStateRef', {static: true})
solutionId
Type : any
totalCount
Type : number
Default value : 0
import { HttpClient } from '@angular/common/http';
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { LoaderService, LocalStorageService, UtilsService } from '@app/app/manage-learn/core';
import { urlConstants } from '@app/app/manage-learn/core/constants/urlConstants';
import { AssessmentApiService } from '@app/app/manage-learn/core/services/assessment-api.service';
import { KendraApiService } from '@app/app/manage-learn/core/services/kendra-api.service';
import { IonInfiniteScroll, ModalController, NavParams } from '@ionic/angular';

@Component({
  selector: 'app-entityfilter',
  templateUrl: './entityfilter.component.html',
  styleUrls: ['./entityfilter.component.scss'],
})
export class EntityfilterComponent implements OnInit {
  @ViewChild('selectStateRef', { static: true }) selectStateRef;
  @ViewChild(IonInfiniteScroll, { static: true }) infiniteScroll: IonInfiniteScroll;
  entityList;
  observationId;
  searchUrl;
  limit = 50;
  page = 1;
  totalCount = 0;
  searchValue = '';
  selectableList: any = [];
  index: any = 50;
  arr = [];
  selectedListCount = {
    count: 0,
  };
  solutionId: any;
  searchQuery;
  allStates: Array<Object>;
  profileMappedState: any;
  isProfileAssignedWithState: boolean;
  profileData: any;
  selectedState;
  loading: boolean = false;
  payload;
  entityType;
  selectedItems: any = [];
  entity:any;
  constructor(
    private localStorage: LocalStorageService,
    private navParams: NavParams,
    private loader: LoaderService,
    private httpClient: HttpClient,
    private modalCtrl: ModalController,
    private assessmentService: AssessmentApiService,
    private utils: UtilsService,
    private ref: ChangeDetectorRef,
    private kendra: KendraApiService
  ) {
    this.searchUrl = urlConstants.API_URLS.SEARCH_ENTITY;
    this.observationId = this.navParams.get('data');
    this.solutionId = this.navParams.get('solutionId');
    this.entity = this.navParams.get('entity');
    // this.localStorage
    //   .getLocalStorage('profileRole')
  }

  async getTargettedEntityType() {
    this.payload = await this.utils.getProfileInfo();
    const config = {
      url: urlConstants.API_URLS.TARGETTED_ENTITY_TYPES + this.solutionId,
      payload: this.payload,
    };

    this.kendra.post(config).subscribe(success => {
      this.entityType = success.result ? success.result._id : null;
      this.search();
    }, error => {

    })
  }

  openSelect() {
    this.profileData.stateSelected || this.profileMappedState ? this.search() : null;
    this.selectedState
      ? null
      : setTimeout(() => {
        this.selectStateRef.open();
      }, 100);
  }

  onStateChange(event) {
    if (this.profileData) {
      this.profileData.stateSelected = event;
    }
    this.searchQuery = '';
  }
  addSchools() {
    this.modalCtrl.dismiss(this.selectedItems);
    this.selectedItems = [];
  }
  clearEntity() {
    this.selectableList = [];
  }
  cancel() {
    this.modalCtrl.dismiss();
  }
  checkItem(listItem) {
    if (!listItem.selected) {
      this.selectedItems.push(listItem)
    } else {
      let indexToRemove = this.selectedItems.indexOf(listItem)
      this.selectedItems.splice(indexToRemove, 1)
    }
    listItem.selected = !listItem.selected;
    listItem.selected ? this.selectedListCount.count++ : this.selectedListCount.count--;
  }

  async search(event?) {
    let payload = await this.utils.getProfileInfo();

    !event ? this.loader.startLoader() : '';
    this.page = !event ? 1 : this.page + 1;

    let apiUrl =
      this.searchUrl +
      '?observationId=' +
      this.observationId +
      '&search=' +
      encodeURIComponent(this.searchQuery ? this.searchQuery : '') +
      '&page=' +
      this.page +
      '&limit=' +
      this.limit;
    apiUrl =
      apiUrl +
      `&parentEntityId=${encodeURIComponent(
        this.entityType
        // this.isProfileAssignedWithState ? this.profileMappedState : this.selectedState
      )}`;
    this.loading = true;

    const config = {
      url: apiUrl,
      payload: payload,
    };
    this.assessmentService.post(config).subscribe(
      (success) => {
        this.loading = false;
        this.selectableList = !event ? [] : this.selectableList;
        for (let i = 0; i < success.result[0].data.length; i++) {
          success.result[0].data[i].isSelected = success.result[0].data[i].selected;
          success.result[0].data[i].preSelected = success.result[0].data[i].selected ? true : false;
        }
        this.totalCount = success.result[0].count;
        if (this.selectedItems.length) {
          if (!event) {
            if (this.searchQuery === "") {
              this.selectableList = [...this.selectedItems, ...success.result[0].data];
            } else {
              this.selectableList = [...this.selectableList, ...success.result[0].data];
            }
          } else {
            this.selectableList.forEach((element) => {
              this.selectedItems.forEach((item) => {
                if (element._id === item._id) {
                  let indexToReplace = this.selectableList.indexOf(element);
                  this.selectableList.splice(indexToReplace, 1, item)
                }
              })
            })
            this.selectableList = [...this.selectableList, ...success.result[0].data];
          }
        } else {
          this.selectableList = [...this.selectableList, ...success.result[0].data];
        }
        !event ? this.loader.stopLoader() : this.toggleInfiniteScroll(event);
      },
      (error) => {
        this.loading = false;
        !event ? this.loader.stopLoader() : this.toggleInfiniteScroll(event);
      }
    );
  }

  toggleInfiniteScroll(e) {
    e.target.complete()
  }

  doInfinite(infiniteScroll) {
    setTimeout(() => {
      this.search(infiniteScroll);
    }, 500);
  }
  searchEntity() {
    this.selectableList = [];
    this.search();
  }

  ngOnInit() {
    this.getTargettedEntityType();
  }
}
<ion-header>
  <ion-toolbar>
    <div class="_flex-box searchCard">
      <ion-searchbar
        debounce="500"
        (keyup.enter)="searchEntity()"
        [(ngModel)]="searchQuery"
        placeholder="Search {{entity}} "
        (ionClear)="searchQuery = ''; searchEntity()"
      ></ion-searchbar>
      <ion-button ion-button icon-only (click)="searchEntity()" class="serachBtn">
        <ion-icon role="button" aria-label="search" name="search" class="searchIcon"></ion-icon>
      </ion-button>
    </div>
  </ion-toolbar>
</ion-header>
<ion-content padding [ngStyle]="{ 'margin-top': profileMappedState ? '0px' : '50px' }">
  <div>
    <ion-list *ngIf="selectableList && selectableList?.length" (ionScroll)="detectBottom()">
      <ng-container *ngFor="let listItem of selectableList">
        <ion-item *ngIf="!listItem.isSelected">
          <ion-label text-wrap>{{ listItem.name }}</ion-label>
          <ion-checkbox color="dark" checked="{{ listItem.selected }}" (ionChange)="checkItem(listItem)"></ion-checkbox>
        </ion-item>
      </ng-container>
    </ion-list>
    <ion-list *ngIf="!selectableList?.length ">
      <div class="_flex-box _justify-content-center noDataMsg">
        {{ 'FRMELEMNTS_MSG_NO_SCHOOL_FOUND' |  translate:{'entity': entity} }}
      </div>
    </ion-list>
  </div>

  <div *ngIf="!(this.selectableList?.length == totalCount) && this.selectableList?.length > 0">
    <ion-infinite-scroll
      #infiniteScroll
      [enabled]="!(this.selectableList?.length == totalCount) && this.selectableList?.length > 0"
      (ionInfinite)="doInfinite($event)"
    >
      <ion-infinite-scroll-content loadingSpinner="bubbles" loadingText="Loading more data...">
      </ion-infinite-scroll-content>
    </ion-infinite-scroll>
  </div>
</ion-content>
<ion-footer no-shadow>
  <ion-toolbar class="_toolbar-background-md" position="bottom">
    <ion-row>
      <ion-col>
        <ion-button ion-button full (click)="cancel()" class="w-100 custom-btn-txt-transform-none">
          <ion-icon role="button" name="close" attr.aria-label="{{ 'CANCEL' | translate }}" margin-right></ion-icon>
          {{ 'CANCEL' | translate }}
        </ion-button>
      </ion-col>
      <ion-col>
        <ion-button ion-button full (click)="addSchools()" class="w-100 custom-btn-txt-transform-none" [disabled]="selectedListCount.count === 0">
          <ion-icon role="button" name="add" attr.aria-label="{{ 'FRMELEMENTS_BTN_ADD' | translate }}" margin-right></ion-icon>
          {{ 'FRMELEMENTS_BTN_ADD' | translate }}
        </ion-button>
      </ion-col>
    </ion-row>
  </ion-toolbar>
</ion-footer>

./entityfilter.component.scss

@import 'src/assets/styles/_variables.scss';

.seacrhInput {
  padding-left: 15px;
  border: 1px solid $gray-100 !important;
  // background-color: $white-color !important;
}
.toolbar-background-md {
  background-color: $white-color;
}
.serachBar {
  flex: 1;
}
.labelAdj {
  color: $black-color !important;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""