File

src/app/manage-learn/generic-reports/reports/reports.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(router: Router, toast: ToastService, loader: LoaderService, dhiti: DhitiApiService, modal: ModalController, headerService: AppHeaderService)
Parameters :
Name Type Optional
router Router No
toast ToastService No
loader LoaderService No
dhiti DhitiApiService No
modal ModalController No
headerService AppHeaderService No

Methods

allEvidence
allEvidence(element: any)
Parameters :
Name Type Optional
element any No
Returns : any
config
config()
Returns : { url: any; payload: any; }
filterBySegment
filterBySegment()
Returns : any
getReport
getReport()
Returns : void
goToImpSugg
goToImpSugg()
Returns : void
instanceReport
instanceReport(e)
Parameters :
Name Optional
e No
Returns : void
Async loadMoreReports
loadMoreReports(element, data, questionNumber)
Parameters :
Name Optional
element No
data No
questionNumber No
Returns : any
ngOnInit
ngOnInit()
Returns : void
Async openFilter
openFilter(data, keyToSend)
Parameters :
Name Optional
data No
keyToSend No
Returns : any
segmentChanged
segmentChanged(segment)
Parameters :
Name Optional
segment No
Returns : void

Properties

_headerConfig
action
data
Type : any
error
Type : literal type
filteredData
Type : any
filters
Type : any
modalFilterData
Type : any
reportSections
Type : any
segmentValue
Type : string
state
Type : literal type
submissionId
Type : any
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { LoaderService, ToastService } from '../../core';
import * as _ from 'lodash-es';
import { urlConstants } from '../../core/constants/urlConstants';
import { DhitiApiService } from '../../core/services/dhiti-api.service';
import { ModalController } from '@ionic/angular';
import { ReportModalFilter } from '../../shared/components/report-modal-filter/report.modal.filter';
import { RouterLinks } from '@app/app/app.constant';
import { AppHeaderService } from '@app/services';
import { ReportListComponent } from '../../shared';

@Component({
  selector: 'app-reports',
  templateUrl: './reports.component.html',
  styleUrls: ['./reports.component.scss'],
})
export class ReportsComponent implements OnInit {
  state: { [k: string]: any };
  data: any;
  error: { result: boolean; message: string };
  submissionId: any;
  action;
  filters: any;
  segmentValue: string;
  filteredData: any;
  modalFilterData: any;
  reportSections: any;
  _headerConfig;
  constructor(
    private router: Router,
    private toast: ToastService,
    private loader: LoaderService,
    private dhiti: DhitiApiService,
    private modal: ModalController,
    private headerService: AppHeaderService
  ) {
    this.state = this.router.getCurrentNavigation().extras.state;
  }

  ngOnInit() {
    this.segmentValue = 'questionwise';
    this.state['pdf'] = false;
    this.getReport();
    this._headerConfig = this.headerService.getDefaultPageConfig();
    this._headerConfig.actionButtons = [];
    this._headerConfig.showHeader = true;
    this._headerConfig.showBurgerMenu = false;
    this._headerConfig.pageTitle = ""
    this.headerService.updatePageConfig(this._headerConfig);
  }
  getReport() {
    // remove null and undefined
    this.state = _.omitBy(this.state, _.isNil);
    this.error = null;
    this.loader.startLoader();
    const config = {
      url: urlConstants.API_URLS.GENERIC_REPORTS,
      payload: this.state,
    };

    this.dhiti.post(config).subscribe(
      (success) => {
        this.loader.stopLoader();
        if (success.result === true && success.reportSections) {
          this.data = success;
          this.reportSections = this.filterBySegment();

          if (this.data.filters && !this.filters) {
            this.filters = this.data.filters;
          }

          if (this.data.filters) {
            let modalFilter = this.data.filters.filter((filter) => filter.filter.type == 'modal')[0];
            this.filters = this.filters.map((filter) => {
              if (filter.filter.type == 'modal') {
                filter = modalFilter;
              }
              return filter;
            });
          }
        } else {
          this.toast.openToast(success.message);
          this.error = success;
          this.reportSections = [];
        }
      },
      (error) => {
        this.toast.openToast(error.message);
        this.loader.stopLoader();
        this.reportSections = [];
        this.error = error;
      }
    );
  }

  instanceReport(e) {
    this.state.submissionId = this.submissionId;
    this.getReport();
  }

  config() {
    let payload = Object.assign({}, this.state, { pdf: true }); // will not change state obj
    const config = {
      url: urlConstants.API_URLS.GENERIC_REPORTS,
      payload: payload,
    };

    return config;
  }

  segmentChanged(segment) {
    segment === 'criteriawise' ? (this.state.criteriaWise = true) : (this.state.criteriaWise = false);
    this.state.filter = null;
    this.modalFilterData = null;
    this.getReport();
  }

  filterBySegment() {
    if (this.segmentValue == 'questionwise') {
      let reportSections = [{ questionArray: this.data.reportSections }];
      return reportSections;
    }

    return this.data.reportSections;
  }

  async openFilter(data, keyToSend) {
    this.modalFilterData ? null : (this.modalFilterData = data);
    let filteredData;
    if (this.state.filter && this.state.filter.length) {
      filteredData = this.state.filter[keyToSend];
    } else {
      filteredData = data.map((d) => d._id);
    }

    let dataType= this.state.criteriaWise ?'criteria': 'question'
    const modal = await this.modal.create({
      component: ReportModalFilter,
      componentProps: {
        data: this.modalFilterData,
        filteredData: JSON.parse(JSON.stringify(filteredData)),
        dataType:dataType 
      },
    });
    await modal.present();
    await modal.onDidDismiss().then((response: any) => {
      if (
        response.data &&
        response.data.action === 'updated' &&
        JSON.stringify(response.data.filter) !== JSON.stringify(filteredData)
      ) {
        this.state.filter = {};
        this.state.filter[keyToSend] = response.data.filter;
        this.getReport();
      }
    });
  }

  allEvidence(element:any):any {
    const queryParams = {
      submissionId: this.state.submissionId,
      observationId: this.state.observationId,
      entityId: this.state.entityId,
      questionExternalId: element.order,
      entityType: this.state.entityType,
    };
    if (this.state.survey) {
      queryParams["surveyEvidence"] = true;
    }
    if (this.state.survey && this.state.solutionId) {
      queryParams["solutionId"] = this.state.solutionId;
    }
    this.router.navigate([RouterLinks.ALL_EVIDENCE], {
      queryParams:queryParams,
    });
  }

  goToImpSugg() {
     const state  = {
       data: this.data.improvementProjectSuggestions,
       solutionName: this.data.solutionName,
       solutionId: this.data.solutionId,
       observationId: this.state.observationId,
       entityId: this.state.entityId,
     };
    this.router.navigate([RouterLinks.IMP_SUGGESTIONS], {
      state: state,
    });
  }

  async loadMoreReports(element,data,questionNumber){
    const modal = await this.modal.create({
      component: ReportListComponent,
      componentProps: {
        data:  JSON.parse(JSON.stringify(data)),
        element : JSON.parse(JSON.stringify(element)),
        questionNumber:questionNumber,
        config :{
          url : urlConstants.API_URLS.SURVEY_FEEDBACK.GET_ALL_ANSWERS,
          payload:{
            solutionId: this.state.solutionId,
            questionExternalId: element.order,
            completedDate:element.completedDate
          }
      },
    }
    });
    await modal.present();
  }
}
<ion-content >
  <h3 class="txt-capitalize">{{ data?.solutionName }}</h3>
  <h6 class="grade_ellipsis txt-capitalize">{{ data?.entityName }}</h6>
  <ion-grid *ngIf="data?.totalObservations">
    <ion-row>
      <ion-col style="margin-left: 15px">
        {{ 'FRMELEMNTS_LBL_TOTAL_OBSERVATIONS' | translate }} : {{ data?.totalObservations }}</ion-col
      >
    </ion-row>
  </ion-grid>
  <div *ngFor="let filter of filters">
    <!-- for instance filter -->
    <div *ngIf="filter.filter.type == 'dropdown'" class="d-flex flex-ai-center w-100">
      <div>
        <ion-select
          okText="Select"
          cancelText="Dismiss"
          placeholder="Submission Filter"
          [(ngModel)]="submissionId"
          (ionChange)="instanceReport($event)"
          [interfaceOptions]="{
            cssClass: 'select-box',
            animated: false
          }"
        >
          <ion-select-option [value]="s._id" *ngFor="let s of filter.filter.data">{{
            s.name
          }}</ion-select-option></ion-select
        >
      </div>
      <div>
        <ion-icon name="close" class="sb-modal-close" (click)="submissionId = null" *ngIf="submisison"></ion-icon>
      </div>
    </div>

    <!-- for question and criteria filter modal/ only show when report is present -->
    <div *ngIf="filter.filter.type == 'modal' && !error" class="d-flex flex-jc-flex-end py-10">
      <ion-button ion-button icon-start (click)="openFilter(filter.filter.data, filter.filter.keyToSend)" margin class="custom-btn-txt-transform-none">
        <ion-icon name="options"></ion-icon>
        {{ 'FRMELEMNTS_BTN_FILTER' | translate }}
      </ion-button>
    </div>

    <!-- for dropdown type  -->
    <ion-segment
      (ionChange)="segmentChanged(segmentValue)"
      [(ngModel)]="segmentValue"
      *ngIf="filter.filter.type == 'segment'"
    >
      <ion-segment-button value="questionwise">
        <ion-label> {{ 'FRMELEMNTS_LBL_QUESTION_WISE' | translate }}</ion-label>
      </ion-segment-button>
      <ion-segment-button value="criteriawise">
        <ion-label> {{ 'FRMELEMNTS_LBL_CRITERIA_WISE' | translate }}</ion-label>
      </ion-segment-button>
    </ion-segment>
    <!--  -->
  </div>
  <div *ngFor="let section of reportSections">
    <ion-card-content *ngIf="section?.criteriaName">
      <h3>{{ section.criteriaName }}</h3>
    </ion-card-content>
    <div *ngFor="let element of section?.questionArray; let i = index">
      <ion-card [ngSwitch]="element?.responseType">
        <reports-text [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'text'" [isFeedBackSurvey]="state?.survey" [solutionId]="state?.solutionId"></reports-text>
        <reports-text [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'number'"></reports-text>
        <reports-text [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'date'"></reports-text>
        <pie-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'radio'"></pie-chart>
        <bar-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'multiselect'"></bar-chart>
        <matrix-chart
          [data]="element"
          [questionNumber]="i + 1"
          *ngSwitchCase="'matrix'"
          (allEvidence)="allEvidence($event)"
        ></matrix-chart>
        <percentage-column-charts
          [chartData]="element"
          *ngSwitchCase="'horizontalBar'"
          (clickOnGraphEventEmit)="clickOnGraphEventEmit($event)"
        ></percentage-column-charts>
        <expansion-panel [datas]="element" *ngSwitchCase="'expansion'"></expansion-panel>
        <expansion-table [datas]="element" *ngSwitchCase="'expansion-table'"></expansion-table>
        <pie-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'pie'"></pie-chart>
        <scatter-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'scatter'"></scatter-chart>
        <bar-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'column'"></bar-chart>
        <bar-chart [data]="element" [questionNumber]="i + 1" *ngSwitchCase="'bar'"></bar-chart>
        <reports-text [data]="element" [questionNumber]="i + 1" *ngSwitchDefault></reports-text>
      </ion-card>
      <ion-button class="view-more custom-btn-txt-transform-none" expand="block" (click)="loadMoreReports(element,section?.questionArray,i+1)"   *ngIf="element?.answers?.length && element?.count > element?.answers?.length">
        {{ "VIEW_MORE" | translate }}
      </ion-button>
      <ion-grid>
        <ion-row>
          <ion-col size="4" *ngFor="let e of element.evidences">
            <attachments [url]="e.url" [extension]="e.extension"></attachments>
          </ion-col>
          <ion-col size="12" *ngIf="element.evidence_count > 3">
            <small class="pull-right text-ios-danger" (click)="allEvidence(element)">{{
              'FRMELEMNTS_LBL_VIEW_ALL_EVIDNECES' | translate
            }}</small>
          </ion-col>
        </ion-row>
      </ion-grid>
    </div>

    <!-- observation -->

    <!--  -->
  </div>
  <div *ngIf="error" class="_flex-box _justify-content-center">
    {{ error?.message }}
  </div>
  <div class="_flex-box _justify-content-center" *ngIf="data?.improvementProjectSuggestions && data?.improvementProjectSuggestions.length ">
    <ion-button ion-button round class="custom-btn-txt-transform-none viewReportBtn" (click)="goToImpSugg()">
      {{'FRMELEMNTS_CLICK_TO_IMPROVE' | translate}}
    </ion-button>
  </div>
  <!-- INFO: click to improve feature not threre as of now  -->
</ion-content>
<!-- dont show when error or when showing survey reports -->
<ion-footer *ngIf="!error && !state.survey">
  <download-share [extension]="'.pdf'" [interface]="'fab'" [config]="config()"> </download-share>
</ion-footer>

./reports.component.scss

@import 'src/assets/styles/base/_variables.scss';
@import 'src/assets/styles/_custom-mixins.scss';
@import 'src/assets/styles/_variables.scss';
.filterIcon {
  font-size: 1.875rem;
  float: right;
  margin: 10px 15px;
  color: $primary-color;
}
.reportName {
  text-transform: capitalize;
  margin-bottom: 0;
  padding: 0 15px;
}
.heading {
  margin: 10px 15px;
  color: $gray-300;
}

h3 {
  font-size: 1.5rem;
}
h4 {
  font-size: 1rem;
}
:host ::ng-deep h4 {
  font-size: 1rem;
}
.viewReportBtn {
  text-transform: none !important;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""