File

src/app/modules/public/module/offline/components/telemetry-import/telemetry-import.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(resourceService: ResourceService, telemetryActionsService: TelemetryActionsService, telemetryService: TelemetryService, toasterService: ToasterService, activatedRoute: ActivatedRoute, electronDialogService: ElectronDialogService)
Parameters :
Name Type Optional
resourceService ResourceService No
telemetryActionsService TelemetryActionsService No
telemetryService TelemetryService No
toasterService ToasterService No
activatedRoute ActivatedRoute No
electronDialogService ElectronDialogService No

Methods

getList
getList()
Returns : void
getTotalSizeImportedFiles
getTotalSizeImportedFiles()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
openImportTelemetryDialog
openImportTelemetryDialog()
Returns : void
reTryImport
reTryImport(fileDetails)
Parameters :
Name Optional
fileDetails No
Returns : void
setImportTelemetry
setImportTelemetry()
Returns : void
setRetryImportTelemetry
setRetryImportTelemetry(fileDetails)
Parameters :
Name Optional
fileDetails No
Returns : void

Properties

apiCallSubject
Default value : new Subject()
apiCallTimer
Default value : timer(1000, 3000).pipe(filter(data => !data || (this.callImportList)))
callImportList
Default value : false
contentStatusObject
Type : object
Default value : {}
importedFilesSize
Type : number
Default value : 0
importFilesList
Type : []
Default value : []
localStatusArr
Type : []
Default value : ['inProgress', 'inQueue']
Public resourceService
Type : ResourceService
Public telemetryActionsService
Type : TelemetryActionsService
Public toasterService
Type : ToasterService
Public unsubscribe$
Default value : new Subject<void>()
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ResourceService, ToasterService } from '@sunbird/shared';
import { ElectronDialogService } from '../../../offline/services';
import { TelemetryActionsService } from './../../../offline/services';
import * as _ from 'lodash-es';
import { ActivatedRoute } from '@angular/router';
import { TelemetryService } from '@sunbird/telemetry';
import { timer, Subject, combineLatest } from 'rxjs';
import { switchMap, filter, takeUntil, tap} from 'rxjs/operators';
@Component({
  selector: 'app-telemetry-import',
  templateUrl: './telemetry-import.component.html',
  styleUrls: ['./telemetry-import.component.scss']
})
export class TelemetryImportComponent implements OnInit, OnDestroy {
  importFilesList = [];
  public unsubscribe$ = new Subject<void>();
  importedFilesSize = 0;
  callImportList = false;
  apiCallSubject = new Subject();
  contentStatusObject = {};
  localStatusArr = ['inProgress', 'inQueue'];
  apiCallTimer = timer(1000, 3000).pipe(filter(data => !data || (this.callImportList)));
  constructor(public resourceService: ResourceService,
    public telemetryActionsService: TelemetryActionsService,
    private telemetryService: TelemetryService,
    public toasterService: ToasterService,
    private activatedRoute: ActivatedRoute,
    private electronDialogService: ElectronDialogService) {
      this.getList();
      document.addEventListener('telemetry:import', (event) => {
        this.apiCallSubject.next();
      });
     }

     ngOnInit() {
    this.apiCallSubject.next();
  }
  openImportTelemetryDialog() {
    this.setImportTelemetry();
    this.electronDialogService.showTelemetryImportDialog();
  }
  getList() {
    // tslint:disable-next-line: deprecation
    combineLatest(this.apiCallTimer, this.apiCallSubject, (data1, data2) => true)
      .pipe(takeUntil(this.unsubscribe$),  switchMap(() => this.telemetryActionsService.telemetryImportList()),
        tap((resp: any) => {
          const itemToComplete = _.find(_.get(resp, 'result.response.items'), (item) => {
            return _.includes(this.localStatusArr, item.status); });
          this. callImportList = itemToComplete ? true : false;
        })).subscribe((responseList: any) => {
          this.importFilesList = _.get(responseList, 'result.response.items');
          this.getTotalSizeImportedFiles();
        });
  }
  getTotalSizeImportedFiles() {
    this.importedFilesSize = 0;
    this.importedFilesSize =  _.reduce(this.importFilesList, (sum, data) => {
      return data.status === 'completed' ? sum + data.totalSize : sum + 0; }, 0);
  }
  setImportTelemetry() {
    const interactData = {
      context: {
        env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry',
        cdata: []
      },
      edata: {
        id: 'import_telemetry_file',
        type: 'click',
        pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
        extra: {}
      }
    };
    this.telemetryService.interact(interactData);
  }
  reTryImport(fileDetails) {
    fileDetails['disable'] = true;
    this.setRetryImportTelemetry(fileDetails);
    this.telemetryActionsService.reTryTelemetryImport(fileDetails.id).pipe(takeUntil(this.unsubscribe$)).subscribe(data => {
    this.apiCallSubject.next();
    }, error => {
    this.apiCallSubject.next();
      this.toasterService.error(this.resourceService.messages.etmsg.desktop.telemetryImportError);
    });
  }
  setRetryImportTelemetry(fileDetails) {
    const interactData = {
      context: {
        env: _.get(this.activatedRoute.snapshot.data.telemetry, 'env') || 'telemetry',
        cdata: []
      },
      edata: {
        id: fileDetails.id,
        type: 'click',
        pageid: _.get(this.activatedRoute.snapshot.data.telemetry, 'pageid'),
        extra: {
          size: fileDetails['totalSize'],
        }
      }
    };
    this.telemetryService.interact(interactData);
  }
  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }
}
<ul class="sb-bordered-list my-16">
    <li class="sb-bordered-list-item m-0 relative9">
      <div class="d-flex flex-ai-center flex-jc-space-between flex-w-wrap">
        <div class="sb-bordered-list-item-title">{{resourceService?.frmelmnts?.lbl?.desktop?.filesImported}}
          ({{importFilesList?.length}})&lrm;
          <span class="sb-bordered-list-item-title-extra ml-16">{{resourceService?.frmelmnts?.lbl?.desktop?.TotalSize}}
            {{importedFilesSize | filesize }}</span></div>
  
        <button class="sb-btn sb-btn-normal sb-bulk-upload-btn sb-btn-outline-primary" tabindex="0" (click)="openImportTelemetryDialog()">
          <img src="assets/images/plus-icon.svg" width="12px" height="12px" class="mr-8">
          {{resourceService?.frmelmnts?.lbl?.desktop?.importNewFile}}
        </button>
  
      </div>
    </li>
    <li class="sb-bordered-list-item m-0 relative9" *ngFor="let items of importFilesList">
      <div class="d-flex flex-ai-center flex-jc-space-between">
        <div class="sb-bordered-list-item-heading file-import-text" title="{{items.name}}">{{items.name}}
        </div>
        <div class="sb-bordered-list-item-subheading ml-16 file-import-text">{{items.createdOn | dateFormat: 'DD MMMM YYYY'}}
          at {{items.createdOn | date:'h:mm a'}}, {{items?.totalSize | filesize}}</div>
        <div class="sb-bordered-list-item-subheading ml-16 ">
          <span *ngIf="items.status === 'inProgress'" class="sb-label sb-label-table sb-label-success-0">{{items.status}} </span>
          <span *ngIf="items.status === 'completed'" class="sb-label sb-label-table sb-label-success-0">{{items.status}} </span>
          <span *ngIf="items.status === 'inQueue'"
            class="sb-label sb-label-table sb-label-error-0">{{resourceService?.frmelmnts?.lbl?.desktop?.waitingForImport}} </span>
          <span *ngIf="items.status === 'failed' && items.failedCode === 'MANIFEST_MISSING'" >
            <span class="sb-label sb-label-table sb-label-error-0">
              <span> {{items.status}}  </span>
              <span class="ml-8"> 
                {{resourceService?.frmelmnts?.emsg?.desktop?.importValidZipFile}} </span>
             </span>
            </span>
          <span *ngIf="items.status === 'failed' && items.failedCode !== 'MANIFEST_MISSING'" class="sb-color-error">
            {{items.status}}
            <button type="button" class="sb-btn sb-btn-xs sb-btn-outline-warning ml-8" [disabled]="items.disable"
              tabindex="0" (click)="reTryImport(items)">
              {{resourceService?.frmelmnts?.btn?.retry}}
            </button>
          </span>
        </div>
      </div>
    </li>
  </ul>

./telemetry-import.component.scss

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

.sb-bulk-upload-btn{
    position: relative;
    overflow: hidden;
    cursor: pointer;
      .sb-btn-upload{
        position: absolute;
        opacity: 0;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        height: 100%;
        cursor: pointer;
      }
  }
  
.sb-upload-file {
          height: 3.5rem;
          width:  3.5rem;
          background: var(--gray-400);
          margin-top: auto;
          margin-bottom: auto;
      }

      .file-import-text{
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: inline;
      }
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""