File

src/app/modules/org-management/components/status/status.component.ts

Description

This component helps to display the success/failure response given by the api based on the process id entered

Implements

OnInit OnDestroy AfterViewInit

Metadata

Index

Properties
Methods

Constructor

constructor(orgManagementService: OrgManagementService, router: Router, formBuilder: UntypedFormBuilder, toasterService: ToasterService, resourceService: ResourceService, activatedRoute: ActivatedRoute, userService: UserService, navigationhelperService: NavigationHelperService)

Constructor to create injected service(s) object

Default method of DetailsComponent class

Parameters :
Name Type Optional Description
orgManagementService OrgManagementService No
router Router No
formBuilder UntypedFormBuilder No
toasterService ToasterService No
resourceService ResourceService No

To call resource service which helps to use language constant

activatedRoute ActivatedRoute No
userService UserService No
navigationhelperService NavigationHelperService No

Methods

getBulkUploadStatus
getBulkUploadStatus(processId)

This method helps to fetch bulk upload status based on the given process id

Parameters :
Name Optional
processId No
Returns : void
getStatusResult
getStatusResult(status)

This method helps to get the status result from the api

Parameters :
Name Optional
status No
Returns : any
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()

This method is used to initialize the formbuilder and to validate process id form field

Returns : void
Public redirect
redirect()

This method helps to redirect to the parent component page, i.e, bulk upload page

Returns : void
setInteractEventData
setInteractEventData()
Returns : void

Properties

Public activatedRoute
Type : ActivatedRoute

reference for ActivatedRoute

checkStatusInteractEdata
Type : IInteractEventEdata
isProcessCompleted
Type : boolean
modal
Decorators :
@ViewChild('modal')
Public navigationhelperService
Type : NavigationHelperService
Public orgManagementService
Type : OrgManagementService

To call admin service which helps to upload csv file

processId
Type : string

Contains process id

redirectUrl
Type : string

Contains redirect url

Public resourceService
Type : ResourceService

To call resource service which helps to use language constant

sbFormBuilder
Type : UntypedFormBuilder

Contains reference of FormBuilder

showLoader
Default value : false

To show/hide loader

statusForm
Type : UntypedFormGroup

status check form name

statusResponse
Type : IUserUploadStatusResponse | IOrgUploadStatusResponse

Contains status response

telemetryImpression
Type : IImpressionEventInput

telemetryImpression

telemetryInteractObject
Type : IInteractEventObject
Private toasterService
Type : ToasterService

To show toaster(error, success etc) after any API calls

Public unsubscribe$
Default value : new Subject<void>()
Public userService
Type : UserService
import { Component, OnInit, OnDestroy, ViewChild, AfterViewInit } from '@angular/core';
import { ResourceService, ToasterService, ServerResponse, NavigationHelperService } from '@sunbird/shared';
import { Router, ActivatedRoute } from '@angular/router';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { OrgManagementService } from '../../services';
import { IUserUploadStatusResponse, IOrgUploadStatusResponse } from '../../interfaces';
import { IImpressionEventInput, IInteractEventEdata, IInteractEventObject } from '@sunbird/telemetry';
import { UserService } from '@sunbird/core';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

/**
 * This component helps to display the success/failure response given by the api based on the process id entered
 *
 */
@Component({
  selector: 'app-status',
  templateUrl: './status.component.html'
})
export class StatusComponent implements OnInit, OnDestroy, AfterViewInit {
  @ViewChild('modal') modal;
  /**
* reference for ActivatedRoute
*/
  public activatedRoute: ActivatedRoute;
  /**
* Contains status response
*/
  statusResponse: IUserUploadStatusResponse | IOrgUploadStatusResponse;
  /**
* Contains process id
*/
  processId: string;

  isProcessCompleted: boolean;
  /**
* To show toaster(error, success etc) after any API calls
*/
  private toasterService: ToasterService;
  /**
* To call admin service which helps to upload csv file
*/
  public orgManagementService: OrgManagementService;
  /**
 * To show/hide loader
 */
  showLoader = false;
  /**
   * To call resource service which helps to use language constant
   */
  public resourceService: ResourceService;
  /**
 * status check form name
 */
  statusForm: UntypedFormGroup;
  /**
* Contains reference of FormBuilder
*/
  sbFormBuilder: UntypedFormBuilder;
  /**
* Contains redirect url
*/
  redirectUrl: string;
  /**
	 * telemetryImpression
	*/
  telemetryImpression: IImpressionEventInput;
  checkStatusInteractEdata: IInteractEventEdata;
  telemetryInteractObject: IInteractEventObject;
  public unsubscribe$ = new Subject<void>();

  /**
* Constructor to create injected service(s) object
*
* Default method of DetailsComponent class
*
* @param {ResourceService} resourceService To call resource service which helps to use language constant
*/
  constructor(orgManagementService: OrgManagementService, private router: Router, formBuilder: UntypedFormBuilder,
    toasterService: ToasterService, resourceService: ResourceService, activatedRoute: ActivatedRoute, public userService: UserService,
    public navigationhelperService: NavigationHelperService) {
    this.resourceService = resourceService;
    this.sbFormBuilder = formBuilder;
    this.orgManagementService = orgManagementService;
    this.toasterService = toasterService;
    this.activatedRoute = activatedRoute;
  }
  /**
 * This method is used to initialize the formbuilder and to validate process id form field
 */
  ngOnInit() {
    this.activatedRoute.data.subscribe(data => {
      if (data.redirectUrl) {
        this.redirectUrl = data.redirectUrl;
      } else {
        this.redirectUrl = '/home';
      }
    });
    this.statusForm = this.sbFormBuilder.group({
      processId: ['', null]
    });
    this.setInteractEventData();
  }
  /**
 * This method helps to redirect to the parent component
 * page, i.e, bulk upload page
 */
  public redirect() {
    this.processId = '';
    this.router.navigate([this.redirectUrl]);
  }
  /**
 * This method helps to fetch bulk upload status based on the given process id
 */
  getBulkUploadStatus(processId) {
    this.showLoader = true;
    if (!(/^\s+$/.test(this.statusForm.value.processId))) {
      this.orgManagementService.getBulkUploadStatus(this.statusForm.value.processId.trim()).pipe(
        takeUntil(this.unsubscribe$))
        .subscribe(
          (apiResponse: ServerResponse) => {
            this.showLoader = false;
            this.statusResponse = apiResponse.result.response[0];
            if (this.statusResponse.status && (this.statusResponse.status === 'COMPLETED')) {
              this.isProcessCompleted = true;
              this.processId = this.statusResponse.processId;
              this.toasterService.success(this.resourceService.messages.smsg.m0032);
            } else {
              this.isProcessCompleted = false;
              this.toasterService.info(this.resourceService.messages.imsg.m0040);
            }
          }, err => {
            this.showLoader = false;
            const errMsg = err.error.params.errmsg ? err.error.params.errmsg : this.resourceService.messages.fmsg.m0051;
            this.toasterService.error(errMsg);
          });
    } else {
      this.toasterService.error(this.resourceService.messages.stmsg.m0006);
      this.showLoader = false;
    }
  }
  /**
 * This method helps to get the status result from the api
 */
  getStatusResult(status) {
    return status;
  }
  ngOnDestroy() {
    this.modal.deny();
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }
  ngAfterViewInit () {
    setTimeout(() => {
        this.telemetryImpression = {
          context: {
            env: this.activatedRoute.snapshot.data.telemetry.env
          },
          edata: {
            type: this.activatedRoute.snapshot.data.telemetry.type,
            pageid: 'profile-bulk-upload-check-status',
            subtype: this.activatedRoute.snapshot.data.telemetry.subtype,
            uri: this.router.url,
            duration: this.navigationhelperService.getPageLoadTime()
          }
        };
    });
  }
  setInteractEventData() {
    this.checkStatusInteractEdata = {
      id: 'upload-status',
      type: 'click',
      pageid: 'profile-read'
    };
    this.telemetryInteractObject = {
      id: this.userService.userid,
      type: 'User',
      ver: '1.0'
    };
  }
}
<app-modal-wrapper [config]="{disableClose: false, size: 'large'}" (dismiss)="redirect();modal.deny()" #modal>
  <ng-template sbModalContent>
    <div class="sb-modal">
      <div class="transition ui dimmer page modals active visible">
        <div class="ui modal transition active visible large">
          <!--Header-->
          <div class="sb-modal-header" [appTelemetryImpression]="telemetryImpression">
            {{resourceService?.frmelmnts?.lbl?.chkuploadsts}}
          </div>
          <!--/Header-->

          <!--Content-->
          <div class="sb-modal-content">
            <div *ngIf="showLoader">
              <app-loader></app-loader>
            </div>
            <form *ngIf="!isProcessCompleted && !showLoader" class="ui form" id="statusForm" [formGroup]="statusForm">
              <h4>{{resourceService?.frmelmnts?.instn?.t0011}}</h4>
              <div class="ui grid">
                <div class="six wide column">
                  <div class="field">
                    <label>{{resourceService?.frmelmnts?.lbl?.processid}}</label>
                    <input type="text" formControlName="processId" placeholder="Process ID" autofocus>
                  </div>
                </div>
                <div class="three wide column">
                </div>
              </div>
            </form>
            <div *ngIf="isProcessCompleted">
              <div class="ui label">
                <h5>{{resourceService?.frmelmnts?.lbl?.processid}}: {{processId}}</h5>
              </div>
              <div *ngFor="let status of [statusResponse.successResult, statusResponse.failureResult]">
                <div class="mt-40 overflowContentHorizontal" *ngIf="getStatusResult(status).length">
                  <h5 *ngIf="status === statusResponse.successResult">{{resourceService?.frmelmnts?.lbl?.successres}}
                  </h5>
                  <h5 *ngIf="status === statusResponse.failureResult">{{resourceService?.frmelmnts?.lbl?.failres}}</h5>
                  <table class="ui celled padded table">
                    <thead *ngIf="statusResponse.objectType === 'user'">
                      <tr>
                        <th>{{resourceService?.frmelmnts?.lbl?.firstName}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.lastName}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.userID}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.rootOrg}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.countryCode}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.phone}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.email}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.password}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.provider}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.phoneVerfied}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.emailVerfied}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.roles}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.position}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.grade | transposeTerms: 'frmelmnts.lbl.grade': resourceService?.selectedLang}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.location}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.dob}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.lang}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.subject | transposeTerms: 'frmelmnts.lbl.subject': resourceService?.selectedLang}}</th>
                        <th *ngIf="status === statusResponse.failureResult">
                          {{resourceService?.frmelmnts?.lbl?.errorMessage}}</th>
                      </tr>
                    </thead>
                    <thead *ngIf="statusResponse.objectType === 'organisation'">
                      <tr>
                        <th>{{resourceService?.frmelmnts?.lbl?.orgId}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.orgName}}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.isRootOrg}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.channel}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.externalId}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.provider}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.description}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.homeUrl}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.orgCode}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.orgType}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.preferredLanguage}}</th>
                        <th>{{resourceService?.frmelmnts?.lbl?.theme}}</th>
                        <th *ngIf="status === statusResponse.failureResult">
                          {{resourceService?.frmelmnts?.lbl?.errorMessage}}</th>
                      </tr>
                    </thead>
                    <tbody *ngIf="statusResponse.objectType === 'user'">
                      <tr [ngClass]="status === statusResponse.successResult ? 'positive' : 'error'"
                        *ngFor="let row of getStatusResult(status)">
                        <td>{{ row.firstName || "empty"}}</td>
                        <td>{{ row.lastName || "empty"}}</td>
                        <td>{{ row.userId || ""}}</td>
                        <td>{{ row.rootOrgId || ""}}</td>
                        <td>{{ row.countryCode || ""}}</td>
                        <td>{{ row.phone || "empty"}}</td>
                        <td>{{ row.email || "empty"}}</td>
                        <td>{{ row.password || "empty"}}</td>
                        <td>{{ row.provider || "empty"}}</td>
                        <td>{{ row.phoneVerified || "empty"}}</td>
                        <td>{{ row.emailVerified || "empty"}}</td>
                        <td>{{ row.roles || "empty"}}</td>
                        <td>{{ row.position || "empty"}}</td>
                        <td>{{ row.grade || "empty"}}</td>
                        <td>{{ row.location || "empty"}}</td>
                        <td>{{ row.dob || "empty"}}</td>
                        <td>{{ row.language || "empty"}}</td>
                        <td>{{ row.subject || "empty"}}</td>
                        <td *ngIf="status === statusResponse.failureResult">{{ row.err_msg || "empty"}}</td>
                    </tbody>
                    <tbody *ngIf="statusResponse.objectType === 'organisation'">
                      <tr [ngClass]="status === statusResponse.successResult ? 'positive' : 'error'"
                        *ngFor="let row of getStatusResult(status)">
                        <td>{{ row.id || "empty"}}</td>
                        <td>{{ row.orgName || "empty"}}</td>
                        <td>{{ row.isRootOrg || "empty"}}</td>
                        <td>{{ row.channel || ""}}</td>
                        <td>{{ row.externalId || ""}}</td>
                        <td>{{ row.provider || ""}}</td>
                        <td>{{ row.description || ""}}</td>
                        <td>{{ row.homeUrl || "empty"}}</td>
                        <td>{{ row.orgCode || "empty"}}</td>
                        <td>{{ row.orgType || "empty"}}</td>
                        <td>{{ row.preferredLanguage || "empty"}}</td>
                        <td>{{ row.theme || "empty"}}</td>
                        <td *ngIf="status === statusResponse.failureResult">{{ row.err_msg || "empty"}}</td>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
          <!--/Content-->

          <!--Actions-->
          <div class="sb-modal-actions">
            <button *ngIf="!isProcessCompleted" appTelemetryInteract [telemetryInteractObject]="telemetryInteractObject"
              [telemetryInteractEdata]="checkStatusInteractEdata" [disabled]="!statusForm.value.processId"
              class="sb-btn sb-btn-normal sb-btn-primary" tabindex="0" (click)="getBulkUploadStatus(statusForm.value)">
              {{resourceService?.frmelmnts?.btn?.chksts}}
            </button>
          </div>
          <!--/Actions-->

        </div>
      </div>
    </div>
  </ng-template>
</app-modal-wrapper>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""