File

src/app/manage-learn/project-report/project-report/project-report.component.ts

Metadata

Index

Properties
Methods

Constructor

constructor(translate: TranslateService, httpClient: HttpClient, utils: UtilsService, alertController: AlertController, router: Router, reportSrvc: ProjectReportService, modalController: ModalController, unnatiService: UnnatiDataService, headerService: AppHeaderService)
Parameters :
Name Type Optional
translate TranslateService No
httpClient HttpClient No
utils UtilsService No
alertController AlertController No
router Router No
reportSrvc ProjectReportService No
modalController ModalController No
unnatiService UnnatiDataService No
headerService AppHeaderService No

Methods

config
config()
Returns : { url: any; }
fileName
fileName()
Returns : {}
generateCircleData
generateCircleData(obj, innerRadius)
Parameters :
Name Optional
obj No
innerRadius No
Returns : {}
generateCircleData_new
generateCircleData_new(obj, radius)
Parameters :
Name Optional
obj No
radius No
Returns : { label: {}; data: {}; color: {}; radius: any; total: any; }
Async getReports
getReports(preFilter?)
Parameters :
Name Optional
preFilter Yes
Returns : any
ionViewDidLeave
ionViewDidLeave()
Returns : void
ionViewWillEnter
ionViewWillEnter()
Returns : void
loadFilterType
loadFilterType()
Returns : void
Async openFilterModal
openFilterModal(type)
Parameters :
Name Optional
type No
Returns : any
Async presentAlert
presentAlert(heading, msg)
Parameters :
Name Optional
heading No
msg No
Returns : any
reportTypeChange
reportTypeChange()
Returns : void

Properties

Public alertController
Type : AlertController
filter
Type : object
Default value : { type: 1, entity: undefined, program: undefined }
filterType
Type : literal type[]
Public modalController
Type : ModalController
projectsArr
Type : []
Default value : [ { name: 'FRMELEMNTS_LBL_TOTAL_PROJECTS', img: '../../assets/imgs/reports-page/Note 1.svg', key: 'total', }, { name: 'FRMELEMNTS_LBL_PROJECTS_SUBMITTED', img: '../../assets/imgs/reports-page/note.svg', key: 'submitted', }, { name: 'FRMELEMNTS_LBL_PROJECTS_IN_PROGRESS', img: '../../assets/imgs/reports-page/Note 4.svg', key: 'inProgress', }, { name: 'FRMELEMNTS_LBL_PROJECTS_STARTED', img: '../../assets/imgs/reports-page/Note 3.svg', key: 'started', }, ]
reportData
Type : any
selectRef
Type : IonSelect
Decorators :
@ViewChild('mySelect', {static: false})
showFilter
Type : boolean
Default value : false
texts
Type : any
Public unnatiService
Type : UnnatiDataService
import { HttpClient } from '@angular/common/http';
import { Component, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { AlertController, IonSelect, ModalController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { statusType, UtilsService } from '../../core';
import { ProjectReportService } from '../../core/services/project-report.service';
import { FilterModalComponent } from '../../shared/components/filter-modal/filter-modal.component';
import { urlConstants } from '../../core/constants/urlConstants';
import { UnnatiDataService } from '../../core/services/unnati-data.service';
import { AppHeaderService } from '@app/services';

@Component({
  selector: 'app-project-report',
  templateUrl: './project-report.component.html',
  styleUrls: ['./project-report.component.scss'],
})
export class ProjectReportComponent {
  reportData: any;
  showFilter: boolean = false;
  filterType: { label: string; value: number }[];
  filter = { type: 1, entity: undefined, program: undefined };
  @ViewChild('mySelect', { static: false }) selectRef: IonSelect;
  texts: any;
  constructor(
    private translate: TranslateService,
    private httpClient: HttpClient,
    private utils: UtilsService,
    public alertController: AlertController,
    private router: Router,
    private reportSrvc: ProjectReportService,
    public modalController: ModalController,
    public unnatiService: UnnatiDataService,
    private headerService: AppHeaderService
  ) {
    this.translate
      .get([
        'FRMELEMENTS_LBL_SELECT_ENTITY',
        'FRMELEMNTS_MSG_SELECT_ENTITY_TO_SELECT_PROGRAM',
        'FRMELEMNTS_MSG_NO_DATA_AVAILABLE',
        'FRMELEMNTS_MSG_NO_DATA_AVAILABLE_FOR_ENTITY_OR_PROGRAM',
        'FRMELEMNTS_LBL_OK',
      ])
      .subscribe((data) => {
        this.texts = data;
      });
  }

  projectsArr = [
    {
      name: 'FRMELEMNTS_LBL_TOTAL_PROJECTS',
      img: '../../assets/imgs/reports-page/Note 1.svg',
      key: 'total',
    },
    {
      name: 'FRMELEMNTS_LBL_PROJECTS_SUBMITTED',
      img: '../../assets/imgs/reports-page/note.svg',
      key: 'submitted',
    },
    {
      name: 'FRMELEMNTS_LBL_PROJECTS_IN_PROGRESS',
      img: '../../assets/imgs/reports-page/Note 4.svg',
      key: 'inProgress',
    },
    {
      name: 'FRMELEMNTS_LBL_PROJECTS_STARTED',
      img: '../../assets/imgs/reports-page/Note 3.svg',
      key: 'started',
    },
  ];
  ionViewWillEnter() {
    this.headerService.showHeaderWithBackButton();
    this.getReports();
    this.loadFilterType();
  }


  loadFilterType() {
    this.filterType = [
      {
        label: 'FRMELEMNTS_LBL_WEEKLY',
        value: 0,
      },
      {
        label: 'FRMELEMNTS_LBL_MONTHLY',
        value: 1,
      },
      {
        label: 'FRMELEMNTS_LBL_QUARTERLY',
        value: 2,
      },
    ];
  }

  async getReports(preFilter?) {
    const entityId = this.filter.entity ? this.filter.entity._id : null;
    let url;
    if (entityId) {
      url = urlConstants.API_URLS.GET_REPORT + entityId; // to get entity report
    } else {
      url = urlConstants.API_URLS.GET_REPORT; // overall report
    }
    const query = {
      reportType: this.filter.type,
      programId: this.filter.program ? this.filter.program._id : null,
    };
    url = this.utils.queryUrl(url, query);
    let payload = await this.utils.getProfileData();
    if (payload) {
      const config = {
        url: url,
        payload: payload,
      };
      this.unnatiService.post(config).subscribe(
        (data) => {
          if (data.result && !data.result.dataAvailable) {
            this.presentAlert(
              this.texts['FRMELEMNTS_MSG_NO_DATA_AVAILABLE'],
              this.texts['FRMELEMNTS_MSG_NO_DATA_AVAILABLE_FOR_ENTITY_OR_PROGRAM']
            );
            preFilter ? (this.filter = JSON.parse(preFilter)) : null;
            if (this.reportData) {
              return;
            }
          }
          this.reportData = data.result ? data.result.data : {};
          this.reportData.tasks.series = this.generateCircleData(this.reportData.tasks, 57);
          this.reportData.tasks.series_new = this.generateCircleData_new(this.reportData.tasks, 57);

          this.reportData.categories.series = this.generateCircleData(this.reportData.categories, 50);
          this.reportData.categories.series_new = this.generateCircleData_new(this.reportData.categories, 50);
        },
        (err) => {}
      );
    } else {
    }
  }

  generateCircleData_new(obj, radius) {
    let label = [];
    let data = [];
    let color = [];
    let count = 0;
    for (const key in obj) {
      if (key == 'total' || key == 'series' || obj[key] == 0) {
        continue;
      }

      label.push(this.utils.cameltoNormalCase(key));
      data.push(obj[key]);
      if (key == statusType.completed ) {
        color.push({ color: '#29621B', pos: count });
      }

      if (key == statusType.notStarted) {
        color.push({ color: '#DA090D', pos: count });
      }
      if (key == statusType.started) {
        color.push({ color: '#ffd31a', pos: count });
      }
      count++;
    }

    let series = {
      label: label,
      data: data,
      color: color,
      radius: radius,
      total: obj['total'],
    };

    return series;
  }

  generateCircleData(obj, innerRadius) {
    let data = [];
    for (const key in obj) {
      if (key == 'total') {
        continue;
      }
      let x = {};
      x['name'] = this.utils.cameltoNormalCase(key);
      x['value'] = ((obj[key] / obj.total) * 100).toFixed(1) + '%';
      x['y'] = obj[key];
      x['z'] = 0;
      if (key == 'submitted') {
        x['color'] = '#b4e3aa';
      }

      if (key == 'started') {
        x['color'] = '#e86d6d  ';
      }

      data.push(x);
    }
    let series = [
      {
        minPointSize: 100 - innerRadius,
        innerSize: innerRadius + '%',
        zMin: 0,
        showInLegend: true,
        data: data,
      },
    ];
    return series;
  }
  ionViewDidLeave() {
    this.filter = { type: 1, entity: null, program: null };
  }
  reportTypeChange() {
    this.getReports();
  }

  async presentAlert(heading, msg) {
    const alert = await this.alertController.create({
      header: heading,
      message: msg,
      buttons: [this.texts['FRMELEMNTS_LBL_OK']],
    });

    await alert.present();
  }


  fileName() {
    let arr = ['report'];
    this.filter.program ? arr.push(this.filter.program.name) : null;
    return arr;
  }

  config() {
    let url = urlConstants.API_URLS.GET_REPORT;
    if (this.filter.entity) {
      url = url + this.filter.entity._id;
    }

    let query = {
      requestPdf: true,
      reportType: this.filter.type,
      programId: this.filter.program ? this.filter.program._id : null,
    };

    url = this.utils.queryUrl(url, query);

    return { url: url };
  }

  async openFilterModal(type) {
    console.log(type, 'type');
    console.log(this.filter.entity, 'this.filter.entity');
    let preFilter = JSON.stringify(this.filter);

    const modal = await this.modalController.create({
      component: FilterModalComponent,
      cssClass: 'my-custom-class',
      componentProps: {
        type: type,
        entityId: this.filter.entity ? this.filter.entity._id : null,
      },
    });
    await modal.present();
    const { data } = await modal.onWillDismiss();
    type == 'entity' ? (this.filter.entity = data) : (this.filter.program = data);
    JSON.stringify(this.filter) !== preFilter ? this.getReports(preFilter) : null;
  }
}
<ion-content>
  <div class="ion-margin">
    <div class="filter-container" (click)="showFilter = !showFilter">
      <div class="filter-icon">
        <ion-icon item-start name="funnel" color="primary" class="icon"></ion-icon>
      </div>
      <div class="clr-primary">{{ 'FRMELEMNTS_BTN_FILTER' | translate }}</div>
      <div class="filter-icon">
        <ion-icon name="chevron-forward-outline" color="primary" *ngIf="!showFilter"></ion-icon>
        <ion-icon name="chevron-down-outline" color="primary" *ngIf="showFilter"></ion-icon>
      </div>
    </div>
    <div *ngIf="showFilter">
      <ion-item>
        <div (click)="openFilterModal('program')">
          <p>{{ filter?.program?.name || 'Select Program' }}</p>
        </div>
      </ion-item>
    </div>
    <!-- Project overview section -->
    <section *ngIf="reportData?.projects">
      <div class="overview-container">
        <div class="overview-heading">
          <div>
            <h5 class="clr-primary">{{ 'FRMELEMNTS_LBL_PROJECT_OVERVIEW' | translate }}</h5>
          </div>
          <div class="filter-download-container">
            <div *ngIf="filterType">
              <ion-select
                [(ngModel)]="filter.type"
                [interfaceOptions]="{
                  cssClass: 'select-box',
                  animated: false
                }"
              >
                <ion-select-option [value]="t.value" *ngFor="let t of filterType">{{ t.label | translate}}</ion-select-option>
              </ion-select>
            </div>
            <download-share
              [name]="fileName()"
              [extension]="'.pdf'"
              [config]="config()"
              [interface]="'simple'"
            ></download-share>
          </div>
        </div>

        <div class="project-overview-body">
          <div class="card" *ngFor="let p of projectsArr">
            <div class="card-image">
              <img src="{{ p?.img }}" alt="" />
            </div>
            <div class="card-content sb--card__title">
              <div class="content-heading">{{ p?.name | translate}}</div>
              <div class="count">{{ reportData?.projects[p?.key] }}</div>
            </div>
          </div>
        </div>

      </div>
    </section>

    <!-- task overview section -->

    <section *ngIf="reportData?.tasks">
      <div class="overview-container">
        <div class="overview-heading">
          <div>
            <h5 class="clr-primary">{{ 'FRMELEMNTS_LBL_TASK_OVERVIEW' | translate }}</h5>
          </div>
          <div class="filter-download-container">
            <div *ngIf="filterType">
              <ion-select
                [(ngModel)]="filter.type"
                (ionChange)="reportTypeChange()"
                [interfaceOptions]="{
                  cssClass: 'select-box',
                  animated: false
                }"
              >
                <ion-select-option [value]="t.value" *ngFor="let t of filterType">{{ t.label | translate}}</ion-select-option>
              </ion-select>
            </div>
            <download-share
              [name]="fileName()"
              [extension]="'.pdf'"
              [config]="config()"
              [interface]="'simple'"
            ></download-share>
          </div>
        </div>

        <div class="task-overview-body">
          <div>
            <graph-circle [data]="reportData?.tasks"></graph-circle>
          </div>
        </div>

      </div>
    </section>

    <!-- category` overview section -->

    <section *ngIf="reportData?.categories">
      <div class="overview-container">
        <div class="overview-heading">
          <div>
            <h5 class="clr-primary">{{ 'FRMELEMNTS_LBL_CATEGORY_OVERVIEW' | translate }}</h5>
          </div>

          <div class="filter-download-container">
            <div *ngIf="filterType">
              <ion-select
                [(ngModel)]="filter.type"
                [interfaceOptions]="{
                  cssClass: 'select-box',
                  animated: false
                }"
              >
                <ion-select-option [value]="t.value" *ngFor="let t of filterType">{{ t.label | translate }}</ion-select-option>
              </ion-select>
            </div>
            <download-share
              [name]="fileName()"
              [extension]="'.pdf'"
              [config]="config()"
              [interface]="'simple'"
            ></download-share>
          </div>
        </div>
        <div class="task-overview-body">
          <div>
            <graph-circle [data]="reportData?.categories"></graph-circle>
          </div>
        </div>

      </div>
    </section>

    <section>
    </section>
  </div>
</ion-content>

./project-report.component.scss

.filter-container {
  display: flex;
  align-items: center;
  .filter-icon {
    font-size: 1rem;
    padding: 0 5px;
    display: flex;
  }
}

.overview-container {
  .overview-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    .filter-download-container {
      display: flex;
      flex-direction: row;
      align-items: center;
    }
  }
}

.project-overview-body {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .card {
    width: 49%;
    background-color: #8080801c;
    display: flex;
    padding: 12px 0px;
    margin: 2px 0;
    .card-image {
      display: flex;
      align-items: center;
      padding: 6px;
      img {
        height: 1.25rem;
        width: 1.25rem;
      }
    }
    .card-content {
      flex: 1;
      margin-left: 22px;
      .content-heading {
        font-size: 0.75rem;
      }
    }
  }
}

.task-overview-body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.overview-footer {
  .view-option {
    display: flex;
    justify-content: center;
    ion-button {
      --border-color: white;
      color: blue;
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""