File

src/app/modules/observation/components/add-entity/add-entity.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(observationService: ObservationService, kendraService: KendraService, resourceService: ResourceService, observationUtilService: ObservationUtilService, config: ConfigService, location: LocationStrategy)
Parameters :
Name Type Optional
observationService ObservationService No
kendraService KendraService No
resourceService ResourceService No
observationUtilService ObservationUtilService No
config ConfigService No
location LocationStrategy No

Inputs

observationId
Type : any
solutionId
Type : any

Outputs

closeEvent
Type : EventEmitter

Methods

Public closeModal
closeModal()
Returns : void
getProfileData
getProfileData()
Returns : void
getTargettedEntityType
getTargettedEntityType()
Returns : void
loadMore
loadMore()
Returns : void
ngOnInit
ngOnInit()
Returns : void
search
search()
Returns : void
searchEntity
searchEntity()
Returns : void
selectEntity
selectEntity(event)
Parameters :
Name Optional
event No
Returns : void
submit
submit()
Returns : void

Properties

config
count
Type : number
Default value : 0
entities
limit
Type : number
Default value : 25
Public loaderMessage
Type : ILoaderMessage
Public location
Type : LocationStrategy
modal
Decorators :
@ViewChild('modal')
Public noResultMessage
Type : INoResultMessage
Default value : { 'messageText': 'frmelmnts.lbl.noDataFound' }
Public observationUtilService
Type : ObservationUtilService
page
Type : number
Default value : 1
payload
Public resourceService
Type : ResourceService
Public scrollDistance
Type : number
Default value : 1
searchQuery
selectedEntities
Type : []
Default value : []
selectedListCount
Type : number
Default value : 0
showDownloadModal
Default value : true
showDownloadSuccessModal
showLoaderBox
Default value : false
targetEntity
Public throttle
Type : number
Default value : 50
import { Component, OnInit, ViewChild, Input, EventEmitter, Output } from '@angular/core';
import { ObservationService, KendraService, ObservationUtilService } from '@sunbird/core';
import { ConfigService, ResourceService, ILoaderMessage, INoResultMessage } from '@sunbird/shared';
import { LocationStrategy } from '@angular/common';

@Component({
    selector: 'add-entity',
    templateUrl: './add-entity.component.html',
    styleUrls: ['./add-entity.component.scss']
})
export class AddEntityComponent implements OnInit {
    @ViewChild('modal') modal;
    @Output() closeEvent = new EventEmitter<any>();
    @Input() observationId;
    @Input() solutionId;
    public throttle = 50;
    public scrollDistance = 1;
    config;
    targetEntity;
    selectedListCount = 0;
    searchQuery;
    limit = 25;
    page = 1;
    count = 0;
    entities;
    payload;
    showDownloadModal = true;
    showLoaderBox = false;
    public loaderMessage: ILoaderMessage;
    public noResultMessage: INoResultMessage = {
        'messageText': 'frmelmnts.lbl.noDataFound'
      };
    showDownloadSuccessModal;
    selectedEntities = [];
    constructor(
        private observationService: ObservationService,
        private kendraService: KendraService,
        public resourceService: ResourceService,
        public observationUtilService: ObservationUtilService,
        config: ConfigService, public location: LocationStrategy, ) {
        this.config = config;
    }
    ngOnInit() {
        this.getProfileData();
    }
    getProfileData() {
        this.observationUtilService.getProfileDataList().then(data => {
            this.payload = data;
            this.getTargettedEntityType();
        });
    }
    public closeModal() {
        this.showDownloadModal = false;
        this.closeEvent.emit();
    }
    getTargettedEntityType() {
        this.showLoaderBox = true;
        const paramOptions = {
            url: this.config.urlConFig.URLS.KENDRA.TARGETTED_ENTITY_TYPES + this.solutionId,
            param: {},
            data: this.payload,
        };
        this.kendraService.post(paramOptions).subscribe(data => {
            this.showLoaderBox = false;
            this.targetEntity = data.result;
            this.entities = [];
            this.search();
        }, error => {
            this.showLoaderBox = false;
        });

    }
    selectEntity(event) {
        if (this.selectedEntities.includes(event._id)) {
            const i = this.selectedEntities.indexOf(event._id);
            this.selectedEntities.splice(i, 1);
        } else {
            this.selectedEntities.push(event._id);
        }
        if (!event.isSelected) {
            event.selected = !event.selected;
        }
        event.selected ? this.selectedListCount++ : this.selectedListCount--;
    }
    search() {
        this.showLoaderBox = true;
        const url = this.config.urlConFig.URLS.OBSERVATION.SEARCH_ENTITY + '?observationId=' + this.observationId + '&search=' + encodeURIComponent(this.searchQuery ? this.searchQuery : '') + '&page=' + this.page + '&limit=' + this.limit;
        const paramOptions = {
            url: url + `&parentEntityId=${encodeURIComponent(
                this.targetEntity._id
            )}`,
            param: {},
            data: this.payload,
        };
        this.observationService.post(paramOptions).subscribe(data => {
            this.showLoaderBox = false;
            const resp = data.result[0];
            if (resp.data.length) {
                for (let i = 0; i < resp.data.length; i++) {
                    resp.data[i].isSelected = resp.data[i].selected;
                    resp.data[i].preSelected = resp.data[i].selected ? true : false;
                }
                this.entities = this.entities.concat(resp.data);
                this.count = resp.count;
            }
        }, error => {
            this.showLoaderBox = false;
        });
    }

    searchEntity() {
        this.page = 1;
        this.entities = [];
        this.search();
    }
    loadMore() {
        if (this.count > this.entities.length) {
            this.page = this.page + 1;
            this.search();
        }
    }
    submit() {
        this.payload.data = this.selectedEntities;
        const paramOptions = {
            url: this.config.urlConFig.URLS.OBSERVATION.OBSERVATION_UPDATE_ENTITES + `${this.observationId}`,
            param: {},
            data: this.payload,
        };
        this.observationService.post(paramOptions).subscribe(data => {
            this.closeModal();
        }, error => {
        });
    }
}
<app-modal-wrapper [config]="{disableClose: true,size: 'normal',panelClass: ['overflow-visible', 'material-modal']}" (dismiss)="showDownloadSuccessModal = false" #modal>
    <ng-template sbModalContent>
        <div class="sb-mat__modal sb-onboard">
            <div mat-dialog-title class="flex-jc-center">
                <div class="sb-onboard__header">
                    <h4> {{resourceService.frmelmnts?.btn?.addEntity}} </h4>
                </div>
                <button aria-label="close dialog" mat-dialog-close class="close-btn" (click)="closeModal()">
                </button>
            </div>
            <mat-dialog-content>
                <div class="sb-mat__modal__content">
                    <div class="sbt-search-box search-box">
                        <div class="input-div relative" id="search-input-container">
                            <img src="assets/images/search-icon.svg" class="search icon" alt="Search Icon">
                            <input type="text" name="filter_search" class="sb-search-input" [(ngModel)]="searchQuery"
                                placeholder="{{resourceService?.frmelmnts.lbl.search}}" (ngModelChange)="searchEntity()" />
                        </div>
                    </div>
                </div>
            </mat-dialog-content>
            <mat-dialog-content>
                <div class="sb-mat__modal__content">
                        <div class="sb-modal-content content search-results">
                        <div *ngIf="entities?.length">
                            <div *ngFor="let entity of entities">
                                <div class="sb-checkbox sb-checkbox-secondary pt-24 ui checkbox">
                                    <input value="{{entity._id}}" type="checkbox" id="{{entity._id}}"
                                        [ngClass]="{'disabled-checkbox' :entity.isSelected}" (change)="selectEntity(entity)"
                                        [disabled]="entity.isSelected"
                                        [checked]="entity.selected || selectedEntities?.includes(entity._id)">
                                    <label for="{{entity._id}}" class="text-left fsmall">{{entity.name}}</label>
                                </div>
                            </div>
                        </div>
                        <div class="twelve wide column" *ngIf="showLoaderBox">
                            <app-loader [data]='loaderMessage'></app-loader>
                        </div>
                        <div class="twelve wide column" *ngIf="!showLoaderBox && entities?.length === 0">
                            <app-no-result [data]="noResultMessage"></app-no-result>
                        </div>
                    </div>
                </div>
            </mat-dialog-content>
            <mat-dialog-actions class="mb-0 sb-mat__modal__actions flex-jc-center">
                <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" tabindex="0" (click)="closeModal()">
                        {{resourceService.frmelmnts?.btn?.close}}
                    </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" tabindex="0" (click)="submit()" [disabled]="selectedListCount == 0"
                        [ngClass]="{'sb-btn-disabled' : selectedListCount == 0}">
                        {{resourceService.frmelmnts?.btn?.submit}}
                    </button>
                </div>
            </mat-dialog-actions>
        </div>
    </ng-template>
</app-modal-wrapper>

./add-entity.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;

  .sb-modal-content {
    height: calc(100vh - 21.875rem) !important;
    }
  .content{
    max-height: 65vh;
    label{
      color: var(--sb-prominent-filter-title);
    }
    label:hover{
      cursor: pointer;
    }
  }
  .footer{
    width: 100%;
    text-align: center;
    display: flex;
    background: var(--sb-card-bg);
    border-top: none;
  }
  .search-box{
    margin-top: calculateRem(15px);
  }

  .sb-onboard {
    &__header {
      width: 100%;
      margin: calculateRem(20px) 0px;
      padding-left : calculateRem(15px);
    }
  
    &__content {
      width: calculateRem(648px);
      max-width: 100%;
      margin-bottom: auto;
      overflow: hidden;
      overflow-y: auto;
    }
  
    &__footer {
      margin-top: calculateRem(16px);
      width: 100%;
      text-align: center;
    }
  }
  

::ng-deep {
  .sb-onbrd-modal {
    @include respond-below(sm) {
      .ui.modal {
        margin: 0 0 0 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
      }

      .ui.modal.scroll {
        position: fixed !important;
        top: 0;
        width: 100%;
        left: 0px;
        right: 0px;
        margin: 0 !important;
      }
    }
  }
}
  .sbt-search-box{
    box-shadow: none;
    margin: 0;
  }
  .load-mr-btn{
    height: 2rem;
    font-size: 1rem;
    padding: 0.5rem 2rem;
  }
  .load-mr-bt-center{
    text-align:center
}

input[type=checkbox][disabled] {
  background: var(--sb-card-bg);
  border: var(--gray-100);
}
.search-results{ height : 100%; overflow-y: scroll; }
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""