File

src/app/download-manager/downloads-tab/downloads-tab.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(popoverCtrl: PopoverController, commonUtilService: CommonUtilService, events: Events, telemetryGeneratorService: TelemetryGeneratorService, navService: NavigationService, headerService: AppHeaderService, obsService: ObservationService, router: Router)
Parameters :
Name Type Optional
popoverCtrl PopoverController No
commonUtilService CommonUtilService No
events Events No
telemetryGeneratorService TelemetryGeneratorService No
navService NavigationService No
headerService AppHeaderService No
obsService ObservationService No
router Router No

Inputs

downloadedContents
Type : Content[]
Default value : []

Outputs

deleteContents
Type : EventEmitter
sortCriteriaChanged
Type : EventEmitter

Methods

Async deleteAllContents
deleteAllContents()
Returns : any
deleteContent
deleteContent()
Returns : void
navigateToDetailsPage
navigateToDetailsPage(content)
Parameters :
Name Optional
content No
Returns : void
navigateToObservationDetails
navigateToObservationDetails(solution)
Parameters :
Name Optional
solution No
Returns : void
navigateToProjectDetails
navigateToProjectDetails(project)
Parameters :
Name Optional
project No
Returns : void
ngOnInit
ngOnInit()
Returns : void
selectAllContents
selectAllContents()
Returns : void
Async showDeletePopup
showDeletePopup(identifier?, type?)
Parameters :
Name Optional
identifier Yes
type Yes
Returns : any
Async showObsDeletePopup
showObsDeletePopup(identifier)
Parameters :
Name Optional
identifier No
Returns : any
Async showSortOptions
showSortOptions(event)
Parameters :
Name Optional
event No
Returns : any
Async toggleContentSelect
toggleContentSelect(event, idx)
Parameters :
Name Optional
event No
idx No
Returns : any
Async unSelectAllContents
unSelectAllContents(event?)
Parameters :
Name Optional
event Yes
Returns : any

Properties

defaultImg
Default value : this.commonUtilService.convertFileSrc('assets/imgs/ic_launcher.png')
deleteAllConfirm
deleteAllPopupPresent
Default value : false
Public obsService
Type : ObservationService
selectedContents
Type : ContentDelete[]
Default value : []
selectedContentsInfo
Type : object
Default value : { totalSize: 0, count: 0 }
selectedFilter
Type : string
Default value : MenuOverflow.DOWNLOAD_FILTERS[0]
showDeleteButton
Default value : true
showLoader
Default value : false
showSelectAll
Default value : true
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MenuOverflow, RouterLinks } from '@app/app/app.constant';
import { SbPopoverComponent } from '@app/app/components/popups/sb-popover/sb-popover.component';
import { OverflowMenuComponent } from '@app/app/profile/overflow-menu/overflow-menu.component';
import { AppHeaderService } from '@app/services';
import { CommonUtilService } from '@app/services/common-util.service';
import { NavigationService } from '@app/services/navigation-handler.service';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { ContentUtil } from '@app/util/content-util';
import { PopoverController } from '@ionic/angular';
import { Events } from '@app/util/events';
import { Content, ContentDelete, CorrelationData, InteractType, TelemetryObject } from 'sunbird-sdk';
import { ActionButtonType, CorReleationDataType, Environment, InteractSubtype, PageId } from '../../../services/telemetry-constants';
import { SbGenericPopoverComponent } from '../../components/popups/sb-generic-popover/sb-generic-popover.component';
import { EmitedContents } from '../download-manager.interface';
import { Router } from '@angular/router';
import { ObservationService } from '@app/app/manage-learn/observation/observation.service';
@Component({
  selector: 'app-downloads-tab',
  templateUrl: './downloads-tab.component.html',
  styleUrls: ['./downloads-tab.component.scss'],
})
export class DownloadsTabComponent implements OnInit {

  @Input() downloadedContents: Content[] = [];
  @Output() deleteContents = new EventEmitter();
  @Output() sortCriteriaChanged = new EventEmitter();
  showLoader = false;
  selectedContents: ContentDelete[] = [];
  showDeleteButton = true;
  deleteAllPopupPresent = false;
  showSelectAll = true;
  selectedFilter: string = MenuOverflow.DOWNLOAD_FILTERS[0];
  deleteAllConfirm;
  selectedContentsInfo = {
    totalSize: 0,
    count: 0
  };
  defaultImg = this.commonUtilService.convertFileSrc('assets/imgs/ic_launcher.png');

  constructor(
    private popoverCtrl: PopoverController,
    private commonUtilService: CommonUtilService,
    private events: Events,
    private telemetryGeneratorService: TelemetryGeneratorService,
    private navService: NavigationService,
    private headerService: AppHeaderService,
    public obsService: ObservationService,
    private router:Router) {
  }

  ngOnInit(): void {
    this.headerService.headerEventEmitted$.subscribe(async () => {
      if (this.deleteAllPopupPresent) {
        await this.deleteAllConfirm.dismiss();
      }
    });
  }

  async showDeletePopup(identifier?,type?) {
    if (identifier) {
      this.telemetryGeneratorService.generateInteractTelemetry(InteractType.TOUCH,
        InteractSubtype.DELETE_CLICKED,
        Environment.DOWNLOADS,
        PageId.DOWNLOADS);
      const contentDelete: ContentDelete = {
        contentId: identifier,
        isChildContent: false
      };
      contentDelete['type'] = (type == 'project' || type == 'observation') ? type : null
      this.selectedContents = [contentDelete];
    }

    this.telemetryGeneratorService.generatePageViewTelemetry(
      identifier ? PageId.SINGLE_DELETE_CONFIRMATION_POPUP : PageId.BULK_DELETE_CONFIRMATION_POPUP, Environment.DOWNLOADS);
    const deleteConfirm = await this.popoverCtrl.create({
      component: SbPopoverComponent,
      componentProps: {
        sbPopoverHeading: this.commonUtilService.translateMessage('DELETE_CONTENT'),
        actionsButtons: [
          {
            btntext: this.commonUtilService.translateMessage('REMOVE'),
            btnClass: 'popover-color'
          },
        ],
        icon: null,
        sbPopoverContent: identifier ? this.commonUtilService.translateMessage('DELETE_CONTENT_WARNING')
          : this.commonUtilService.translateMessage('DELETE_ALL_CONTENT_WARNING')
      },
      cssClass: 'sb-popover danger',
    });
    await deleteConfirm.present();
    const { data } = await deleteConfirm.onDidDismiss();
    this.showDeleteButton=true

    if (data === undefined) { // Backdrop clicked
      if (!identifier) { this.unSelectAllContents(); }
      this.telemetryGeneratorService.generateInteractTelemetry(
        InteractType.TOUCH,
        InteractSubtype.OUTSIDE_POPUP_AREA_CLICKED,
        Environment.DOWNLOADS,
        PageId.SINGLE_DELETE_CONFIRMATION_POPUP);
    } else if (data.closeDeletePopOver) { // Close clicked
      if (!identifier) { this.unSelectAllContents(); }
      this.telemetryGeneratorService.generateInteractTelemetry(
        InteractType.TOUCH,
        InteractSubtype.CLOSE_CLICKED,
        Environment.DOWNLOADS,
        PageId.SINGLE_DELETE_CONFIRMATION_POPUP);
    } else if (data.canDelete) {
      const valuesMap = {};
      valuesMap['type'] = ActionButtonType.POSITIVE;
      let telemetryObject: TelemetryObject;
      if (identifier) {
        this.downloadedContents.forEach(element => {
          if (element.identifier === identifier) {
            telemetryObject = ContentUtil.getTelemetryObject(element);
          }
        });
      }
      this.telemetryGeneratorService.generateInteractTelemetry(
        InteractType.TOUCH,
        InteractSubtype.ACTION_BUTTON_CLICKED,
        Environment.DOWNLOADS,
        identifier ? PageId.SINGLE_DELETE_CONFIRMATION_POPUP : PageId.BULK_DELETE_CONFIRMATION_POPUP,
        telemetryObject,
        valuesMap);
      this.deleteContent();
    }
  }

  deleteContent() {
    const emitedContents: EmitedContents = {
      selectedContentsInfo: this.selectedContentsInfo,
      selectedContents: this.selectedContents
    };
    this.deleteContents.emit(emitedContents);
  }

  async showSortOptions(event) {
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      InteractSubtype.SORT_OPTION_CLICKED,
      Environment.DOWNLOADS,
      PageId.DOWNLOADS);
    const sortOptions = await this.popoverCtrl.create({
      component: OverflowMenuComponent,
      event,
      componentProps: {
        list: MenuOverflow.DOWNLOAD_FILTERS
      },
      cssClass: 'download-popover'
    });
    await sortOptions.present();
    const { data } = await sortOptions.onDidDismiss();
    if (data) {
      if (data.content !== this.selectedFilter) {
        this.selectedFilter = data.content;
        this.sortCriteriaChanged.emit(data);
      }
      if (this.deleteAllPopupPresent) {
        await this.deleteAllConfirm.dismiss({ isLeftButtonClicked: null });
      }
    }
  }

  selectAllContents() {
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      InteractSubtype.SELECT_ALL_CLICKED,
      Environment.DOWNLOADS,
      PageId.DOWNLOADS);
    this.downloadedContents.forEach(element => {
      element['isSelected'] = true;
    });
    this.showDeleteButton = false;
    this.showSelectAll = false;
    this.deleteAllContents();
  }

  async unSelectAllContents(event?) {
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      InteractSubtype.UNSELECT_ALL_CLICKED,
      Environment.DOWNLOADS,
      PageId.DOWNLOADS);
    this.downloadedContents.forEach(element => {
      element['isSelected'] = false;
    });
    this.showDeleteButton = true;
    this.showSelectAll = true;
    if (this.deleteAllPopupPresent) {
      await this.deleteAllConfirm.dismiss({ isLeftButtonClicked: null });
    }
    this.selectedContents = [];
  }

  async toggleContentSelect(event, idx) {
    this.downloadedContents[idx]['isSelected'] = event.detail.checked;
    const selectedContents = (this.downloadedContents.filter((element) => element['isSelected']));
    if (selectedContents.length) {
      if (selectedContents.length === this.downloadedContents.length) {
        this.showSelectAll = false;
      } else {
        this.showSelectAll = true;
      }
      this.showDeleteButton = false;
      this.deleteAllContents();
    } else {
      this.showDeleteButton = true;
      if (this.deleteAllPopupPresent) {
        await this.deleteAllConfirm.dismiss({ isLeftButtonClicked: null });
      }
    }
  }

  async deleteAllContents() {
    this.selectedContentsInfo = {
      totalSize: 0,
      count: 0
    };
    this.selectedContents = [];
    this.downloadedContents.forEach(element => {
      if (element['isSelected']) {
        const contentDelete: ContentDelete = {
          contentId: element.identifier,
          isChildContent: false
        };
        contentDelete['type'] = (element['type'] == 'project' || element['type'] == 'observation') ? element['type'] : null;
        this.selectedContentsInfo.totalSize += element.sizeOnDevice;
        this.selectedContents.push(contentDelete);
      }
    });
    this.selectedContentsInfo.count = this.selectedContents.length;
    this.events.publish('selectedContents:changed', {
      selectedContents: this.selectedContentsInfo
    });
    if (!this.deleteAllPopupPresent) {
      this.telemetryGeneratorService.generatePageViewTelemetry(PageId.BULK_DELETE_POPUP, Environment.DOWNLOADS);
      this.deleteAllPopupPresent = true;
      this.deleteAllConfirm = await this.popoverCtrl.create({
        component: SbGenericPopoverComponent,
        componentProps: {
          sbPopoverMainTitle: this.commonUtilService.translateMessage('ITEMS_SELECTED'),
          selectedContents: this.selectedContentsInfo,
          actionsButtons: [
            {
              btntext: this.commonUtilService.translateMessage('CANCEL'),
              btnClass: 'sb-btn sb-btn-sm  sb-btn-outline-info'
            }, {
              btntext: this.commonUtilService.translateMessage('DELETE'),
              btnClass: 'popover-color'
            }
          ],
          showHeader: false,
          icon: null
        },
        cssClass: 'sb-popover danger sb-dw-delete-popover',
        showBackdrop: false,
        backdropDismiss: false,
        animated: true
      });
      await this.deleteAllConfirm.present();
      const { data } = await this.deleteAllConfirm.onDidDismiss();
      this.deleteAllPopupPresent = false;
      const valuesMap = {};
      if (data && data.isLeftButtonClicked === null) {
        this.unSelectAllContents();
        this.telemetryGeneratorService.generateInteractTelemetry(
          InteractType.TOUCH,
          InteractSubtype.POPUP_DISMISSED,
          Environment.DOWNLOADS,
          PageId.BULK_DELETE_POPUP);
        this.deleteAllConfirm = undefined;
        return;
      } else if (data.isLeftButtonClicked) {
        valuesMap['type'] = ActionButtonType.NEGATIVE;
        this.unSelectAllContents();
      } else {
        valuesMap['type'] = ActionButtonType.POSITIVE;
        this.telemetryGeneratorService.generateInteractTelemetry(
          InteractType.TOUCH,
          InteractSubtype.ACTION_BUTTON_CLICKED,
          Environment.DOWNLOADS,
          PageId.BULK_DELETE_POPUP, undefined,
          valuesMap);
        this.showDeletePopup();
      }
      this.deleteAllConfirm = undefined;
      this.telemetryGeneratorService.generateInteractTelemetry(
        InteractType.TOUCH,
        InteractSubtype.ACTION_BUTTON_CLICKED,
        Environment.DOWNLOADS,
        PageId.BULK_DELETE_POPUP, undefined,
        valuesMap);
    }
  }

  navigateToDetailsPage(content) {
    if (content.type == 'project') {
      this.navigateToProjectDetails(content)
      return
    } else if(content.type == 'observation'){
      this.navigateToObservationDetails(content)
      return
    }
    const corRelationList: Array<CorrelationData> = [{
        id: CorReleationDataType.DOWNLOADS,
        type: CorReleationDataType.SECTION
      }];
    this.telemetryGeneratorService.generateInteractTelemetry(InteractType.TOUCH,
      InteractSubtype.CONTENT_CLICKED,
      Environment.DOWNLOADS,
      PageId.DOWNLOADS,
      ContentUtil.getTelemetryObject(content),
      undefined,
      ContentUtil.generateRollUp(undefined, content.identifier),
      corRelationList);
    this.navService.navigateToDetailPage(
      content, { content }
    );
  }

  navigateToProjectDetails(project) {
     const selectedFilter = project.isAPrivateProgram==false ? 'assignedToMe' : 'createdByMe';
     this.router.navigate([`${RouterLinks.PROJECT}/${RouterLinks.DETAILS}`], {
       queryParams: {
         projectId: project._id,
         programId: project.programId,
         solutionId: project.solutionId,
         type: selectedFilter,
       },
     });
  }

  navigateToObservationDetails(solution) {
    let { programId, solutionId, _id: observationId, name: solutionName } = solution;
    this.router.navigate([`/${RouterLinks.OBSERVATION}/${RouterLinks.OBSERVATION_DETAILS}`], {
      queryParams: {
        programId: programId,
        solutionId: solutionId,
        observationId: observationId,
        solutionName: solutionName,
      },
    }).then(success => {
      this.obsService.obsTraceObj.programId = programId;
      this.obsService.obsTraceObj.solutionId = solutionId;
      this.obsService.obsTraceObj.name = solutionName;
      this.obsService.obsTraceObj.programName = solution.programName;
      this.obsService.obsTraceObj.observationId = solution.observationId;
    });
 }

 async showObsDeletePopup(identifier){
  this.telemetryGeneratorService.generatePageViewTelemetry(
    identifier ? PageId.SINGLE_DELETE_CONFIRMATION_POPUP : PageId.BULK_DELETE_CONFIRMATION_POPUP, Environment.DOWNLOADS);
  const deleteConfirm = await this.popoverCtrl.create({
    component: SbPopoverComponent,
    componentProps: {
      sbPopoverHeading: this.commonUtilService.translateMessage('DELETE_CONTENT'),
      actionsButtons: [
        {
          btntext: this.commonUtilService.translateMessage('REMOVE'),
          btnClass: 'popover-color'
        },
      ],
      icon: null,
      // sbPopoverContent: identifier ? this.commonUtilService.translateMessage('DELETE_CONTENT_WARNING')
      //   : this.commonUtilService.translateMessage('DELETE_ALL_CONTENT_WARNING')
    },
    cssClass: 'sb-popover danger',
  });
  await deleteConfirm.present();
  const { data } = await deleteConfirm.onDidDismiss();

 }
}
<div class="sb-dw-manager d-flex p-4 width-100">
  <div class="pull-left p-4 flex-50">
    <span class="selector" *ngIf="showSelectAll" (click)="selectAllContents()">{{'SELECT_ALL' | translate}}</span>
    <span class="selector" *ngIf="!showSelectAll"
      (click)="unSelectAllContents($event)">{{'UNSELECT_ALL' | translate}}</span>
  </div>
  <div class="p-4 flex-50">
    <div class="pull-right" (click)="showSortOptions($event)" role="button" attr.aria-label="Sort By {{selectedFilter | translate}}">
      <span class="selector">{{selectedFilter | translate}}</span>
      <span><img aria-hidden="true" src="./assets/imgs/sort.png" alt="sorting"></span>
      <span role="button" aria-label="sorting"><ion-icon name="arrow-down" role="button" class="selector"></ion-icon></span>
    </div>
  </div>
</div>

<div class="sb-card-container sb-card-download-container" [ngClass]="{'extra-margin':!showDeleteButton}">
  <div class="sb-card" *ngFor="let content of downloadedContents; let i = index;"
    [ngClass]="{'sb-card-active': content.isSelected}">
    <div class="check-container">
      <ion-label>
        <ion-checkbox (ionChange)="toggleContentSelect($event, i)" [checked]="content.isSelected">
        </ion-checkbox>
      </ion-label>
    </div>
    <div class="img-container">
      <img alt="content-logo" aria-hidden="true"
        [src]="commonUtilService.convertFileSrc(content?.contentData?.courseLogoUrl) || commonUtilService.convertFileSrc(content?.contentData?.appIcon) || defaultImg" />
    </div>
    <div class="sb-card-details">
      <div class="sb-card-content" (click)="!content.isSelected && navigateToDetailsPage(content)">
        <div class="title">{{content.contentData?.name}}</div>
        <div class="info grade_ellipsis">
          <span class="class">{{content?.contentData?.subject}}</span>
          <span class="separator-dot"></span>
          <span class="subject">{{content?.contentData?.gradeLevel | csa}}</span>
        </div>
        <div class="info"> {{ content?.sizeOnDevice | fileSize }}</div>
      </div>
      <div class="sb-card-actions">
        <button *ngIf="showDeleteButton" attr.aria-label="Delete content {{content.contentData?.name}}" class="action-btn float-end delete mr-8"
          (click)="showDeletePopup(content.identifier,content.type)">
          {{'DELETE' | translate}}
        </button>
      </div>
    </div>
  </div>
</div>

./downloads-tab.component.scss

@import "src/assets/styles/base/_variables.scss";
@import "src/assets/styles/mixins/bourbon/library/_clearfix.scss";
@import "src/assets/styles/_variables.scss";

:host {
  .sb-card-active {
    background: #{$light-blue-bg} !important;
  }
  .sb-dw-manager {
    @include clearfix;
    .selector {
      color: $primary-600;
      font-size: $font-size-md;
      vertical-align: middle !important;
    }
  }

  ion-checkbox {
    --border-width: 0.063rem;
    --border-color: #{map-get($colors, bright_blue_a0)};
    --background-checked: #{$blue};
    --border-color-checked: #{$blue};
    --border-radius: 4px;
  }
}

.flex-50{
  flex: 0 0 50%;
}

.sb-card-content {
  width: 65%;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""