src/app/components/popups/download-transcript-popup/download-transcript-popup.component.ts
OnInit
selector | app-download-transcript-popup |
styleUrls | ./download-transcript-popup.component.scss |
templateUrl | ./download-transcript-popup.component.html |
Properties |
Methods |
|
Inputs |
constructor(contentService: ContentService, popOverCtrl: PopoverController, commonUtilService: CommonUtilService, platform: Platform, telemetryGeneratorService: TelemetryGeneratorService, appGlobalService: AppGlobalService, permissionService: AndroidPermissionsService)
|
||||||||||||||||||||||||
Parameters :
|
contentData | |
Type : any
|
|
Private Async checkForPermissions |
checkForPermissions()
|
Returns :
Promise<boolean | undefined>
|
closePopover |
closePopover()
|
Returns :
void
|
Async download |
download()
|
Returns :
any
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
Private Async showStoragePermissionPopup |
showStoragePermissionPopup()
|
Returns :
Promise<boolean | undefined>
|
appName |
Type : string
|
Default value : ''
|
transcriptLanguage |
Type : string
|
import { Component, Inject, Input, OnInit } from '@angular/core';
import { AndroidPermission, AndroidPermissionsStatus } from '@app/services/android-permissions/android-permission';
import { CommonUtilService } from '@app/services/common-util.service';
import { Environment, InteractSubtype, PageId } from '@app/services/telemetry-constants';
import { PopoverController,Platform, } from '@ionic/angular';
import { ContentService, InteractType } from 'sunbird-sdk';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { AppGlobalService } from '@app/services/app-global-service.service';
import { AndroidPermissionsService } from '@app/services/android-permissions/android-permissions.service';
@Component({
selector: 'app-download-transcript-popup',
templateUrl: './download-transcript-popup.component.html',
styleUrls: ['./download-transcript-popup.component.scss'],
})
export class DownloadTranscriptPopupComponent implements OnInit {
transcriptLanguage: string;
appName = '';
@Input() contentData;
constructor(
@Inject('CONTENT_SERVICE') private contentService: ContentService,
private popOverCtrl: PopoverController,
private commonUtilService: CommonUtilService,
private platform: Platform,
private telemetryGeneratorService: TelemetryGeneratorService,
private appGlobalService: AppGlobalService,
private permissionService: AndroidPermissionsService,
) { }
ngOnInit(): void {
console.log('download-transcript-popup.component');
}
private async checkForPermissions(): Promise<boolean | undefined> {
if(this.platform.is('ios')) {
return new Promise<boolean | undefined>(async (resolve, reject) => {
resolve(true);
});
}
return new Promise<boolean | undefined>(async (resolve) => {
const permissionStatus = await this.commonUtilService.getGivenPermissionStatus(AndroidPermission.WRITE_EXTERNAL_STORAGE);
if (permissionStatus.hasPermission) {
resolve(true);
} else if (permissionStatus.isPermissionAlwaysDenied) {
await this.commonUtilService.showSettingsPageToast('FILE_MANAGER_PERMISSION_DESCRIPTION', this.appName, PageId.PROFILE, true);
resolve(false);
} else {
this.showStoragePermissionPopup().then((result) => {
if (result) {
resolve(true);
} else {
resolve(false);
}
});
}
});
}
private async showStoragePermissionPopup(): Promise<boolean | undefined> {
return new Promise<boolean | undefined>(async (resolve) => {
const confirm = await this.commonUtilService.buildPermissionPopover(
async (selectedButton: string) => {
if (selectedButton === this.commonUtilService.translateMessage('NOT_NOW')) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.NOT_NOW_CLICKED,
Environment.SETTINGS,
PageId.PERMISSION_POPUP);
await this.commonUtilService.showSettingsPageToast('FILE_MANAGER_PERMISSION_DESCRIPTION', this.appName, PageId.PROFILE, true);
} else if (selectedButton === this.commonUtilService.translateMessage('ALLOW')) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.ALLOW_CLICKED,
Environment.SETTINGS,
PageId.PERMISSION_POPUP);
this.appGlobalService.isNativePopupVisible = true;
this.permissionService.requestPermission(AndroidPermission.WRITE_EXTERNAL_STORAGE)
.subscribe(async (status: AndroidPermissionsStatus) => {
if (status.hasPermission) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.ALLOW_CLICKED,
Environment.SETTINGS,
PageId.APP_PERMISSION_POPUP
);
resolve(true);
} else if (status.isPermissionAlwaysDenied) {
await this.commonUtilService.showSettingsPageToast
('FILE_MANAGER_PERMISSION_DESCRIPTION', this.appName, PageId.PROFILE, true);
resolve(false);
} else {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.DENY_CLICKED,
Environment.SETTINGS,
PageId.APP_PERMISSION_POPUP
);
await this.commonUtilService.showSettingsPageToast
('FILE_MANAGER_PERMISSION_DESCRIPTION', this.appName, PageId.PROFILE, true);
}
this.appGlobalService.setNativePopupVisible(false);
resolve(undefined);
});
}
}, this.appName, this.commonUtilService.translateMessage
('FILE_MANAGER'), 'FILE_MANAGER_PERMISSION_DESCRIPTION', PageId.PROFILE, true
);
await confirm.present();
});
}
async download() {
const loader = await this.commonUtilService.getLoader();
this.popOverCtrl.dismiss();
await loader.present();
await this.checkForPermissions().then(async (result) => {
if (result) {
const transcriptsObj = this.contentData.transcripts;
if (transcriptsObj) {
let transcripts = [];
if (typeof transcriptsObj === 'string') {
console.log('....................')
transcripts = JSON.parse(transcriptsObj);
} else {
transcripts = transcriptsObj;
}
if (transcripts && transcripts.length > 0) {
transcripts.forEach(item => {
if (item.language === this.transcriptLanguage) {
const url = item.artifactUrl;
const request = {
identifier: item.identifier,
downloadUrl: url,
mimeType: '',
fileName: this.contentData.name
};
this.contentService.downloadTranscriptFile(request).then((data) => {
loader.dismiss();
}).catch((err) => {
console.log('err........', err);
loader.dismiss();
});
}
});
} else {
loader.dismiss();
}
}
} else {
this.commonUtilService.showSettingsPageToast('FILE_MANAGER_PERMISSION_DESCRIPTION', this.appName, PageId.PROFILE, true);
}
});
}
closePopover() {
this.popOverCtrl.dismiss();
}
}
<ion-content>
<div class="header-info">
<div class="close-icon-info">
<img src="assets/imgs/close.png" alt="close-icon" (click)="closePopover()">
</div>
<h4 class="theme-header-info sb-btn-footer-text">{{'DOWNLOAD_TRANSCRIPT' | translate}}</h4>
</div>
<div>
<div class="input-text">
<ion-select placeholder="Select language" interface="popover" class="select-language"
[(ngModel)]="transcriptLanguage" mode="ios">
<ion-select-option *ngFor="let transcript of contentData.transcripts"
value="{{transcript.language}}">
{{transcript.language}}</ion-select-option>
</ion-select>
</div>
<div class="download-icon">
<button type="submit" class="download-btn"(click)="download()" [disabled]="!transcriptLanguage" [ngClass]="!transcriptLanguage ? 'download-disibled' : null">{{'DOWNLOAD' | translate}}</button>
</div>
</div>
</ion-content>
./download-transcript-popup.component.scss
@import "src/assets/styles/base/_variables.scss";
@import "src/assets/styles/_variables.scss";
@import "src/assets/styles/_custom-mixins.scss";
.download-btn{
color: var(--app-white);
background-color: $blue;
font-size: 0.8rem;
padding: 0.625rem;
border: 0.125rem solid $blue;
width: 36%;
}
.input-text {
text-align: center;
font-size: 1.3rem;
margin-top: 10%;
width: 75%;
border-radius: 1.2em; margin-left: 13%; height: 2.5rem; background-color: var(--app-white);
}
.sb-color-red {
color: #952833 !important;
}
.submit-disibled{
opacity: 0.5 !important;
cursor: default;
}
.theme-header-info {
margin-top: 0;
padding: 1rem .5rem 0 1rem;
font-weight: bold;
}
.close-icon-info {
float: right;
border-radius: 50% !important;
box-shadow: var(--sbt-box-shadow-3px);
background-color: var(--white);
font-size: 0.875rem;
height: 2rem;
width: 2rem;
cursor: pointer;
outline: 0;
border: 0;
margin: 1rem;
padding: 0.313rem;
}
.download-icon{
text-align: center;
margin-top: 4%;
padding: 1rem;
border-bottom-left-radius: 1.5rem;
border-bottom-right-radius: 1.5rem;
}
.sb-btn-footer-text{
color: var(--app-medium-gray);
}
.download-disibled{
opacity: 0.5 !important;
cursor: default;
}
.select-language{
padding: 0.375rem 1.25rem;
color: var(--app-medium-gray)
}