src/app/manage-learn/project/add-file/add-file.page.ts
OnInit
selector | app-add-file |
styleUrls | ./add-file.page.scss |
templateUrl | ./add-file.page.html |
Properties |
Methods |
constructor(routerParams: ActivatedRoute, router: Router, headerService: AppHeaderService, translate: TranslateService, alert: AlertController, db: DbService, attachmentService: AttachmentService, projectService: ProjectService, location: Location, network: NetworkService, projectServ: ProjectService, toast: ToastService, popupService: GenericPopUpService)
|
||||||||||||||||||||||||||||||||||||||||||
Parameters :
|
delete | ||||
delete(index)
|
||||
Parameters :
Returns :
void
|
Async deleteConfirm | ||||
deleteConfirm(index)
|
||||
Parameters :
Returns :
any
|
doSyncAction | ||||||||
doSyncAction(isSubmission: boolean)
|
||||||||
Parameters :
Returns :
void
|
getProject |
getProject()
|
Returns :
void
|
getTask |
getTask()
|
Returns :
void
|
handleHeaderEvents | ||||
handleHeaderEvents($event)
|
||||
Parameters :
Returns :
void
|
Async ionViewWillEnter |
ionViewWillEnter()
|
Returns :
any
|
ionViewWillLeave |
ionViewWillLeave()
|
Returns :
void
|
linkEvent | ||||
linkEvent(event)
|
||||
Parameters :
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onAction | ||||
onAction(event)
|
||||
Parameters :
Returns :
void
|
Async pageExitConfirm |
pageExitConfirm()
|
Returns :
any
|
setHeaderConfig |
setHeaderConfig()
|
Returns :
void
|
submit |
submit()
|
Returns :
void
|
submitProject |
submitProject()
|
Returns :
void
|
Async submitProjectConfirmation |
submitProjectConfirmation()
|
Returns :
any
|
toggleLinkModal |
toggleLinkModal()
|
Returns :
void
|
update | ||||
update(type?)
|
||||
Parameters :
Returns :
void
|
updateRemarks |
updateRemarks()
|
Returns :
void
|
_appHeaderSubscription |
Type : Subscription
|
actionItems |
Default value : actions.FILE_UPLOAD_OPTIONS
|
attachments |
Type : any
|
Default value : []
|
button |
Type : string
|
canExit |
Default value : false
|
description |
Type : string
|
headerConfig |
Type : object
|
Default value : {
showHeader: true,
showBurgerMenu: false,
actionButtons: [],
pageTitle: ''
}
|
headerObservable |
Type : any
|
isLinkModalOpen |
Type : boolean
|
Default value : false
|
parameters |
project |
projectCopy |
projectId |
remarks |
task |
taskId |
taskIndex |
unregisterBackButton |
Type : Subscription
|
viewOnlyMode |
Type : boolean
|
Default value : false
|
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AppHeaderService } from '@app/services';
import { AlertController } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { AttachmentService, DbService, NetworkService, ProjectService, statusType, ToastService, UtilsService } from '../../core';
import { actions } from '../../core/constants/actions.constants';
import * as _ from "underscore";
import { Location } from '@angular/common';
import { RouterLinks } from '@app/app/app.constant';
import { GenericPopUpService } from '../../shared';
@Component({
selector: 'app-add-file',
templateUrl: './add-file.page.html',
styleUrls: ['./add-file.page.scss'],
})
export class AddFilePage implements OnInit {
description: string;
parameters;
isLinkModalOpen: boolean = false;
actionItems = actions.FILE_UPLOAD_OPTIONS;
_appHeaderSubscription: Subscription;
headerObservable: any;
headerConfig = {
showHeader: true,
showBurgerMenu: false,
actionButtons: [],
pageTitle: ''
};
remarks: '';
button: string;
attachments: any = [];
projectId;
taskId;
project;
task;
viewOnlyMode: boolean = false;
projectCopy;
taskIndex;
unregisterBackButton: Subscription;
canExit = false;
constructor(
private routerParams: ActivatedRoute,
private router: Router,
private headerService: AppHeaderService,
private translate: TranslateService,
private alert: AlertController,
private db: DbService,
private attachmentService: AttachmentService,
private projectService: ProjectService,
private location: Location,
private network: NetworkService,
private projectServ: ProjectService,
private toast: ToastService,
private popupService: GenericPopUpService,
) {
routerParams.params.subscribe(urlParams => {
this.projectId = urlParams.id;
this.getProject();
})
routerParams.queryParams.subscribe(params => {
this.description = params.taskId ? actions.TASK_FILE_DESCRIPTION.label : actions.PROJECT_FILE_DESCRIPTION.label;
this.taskId = params.taskId;
})
}
ngOnInit() { }
async ionViewWillEnter() {
this._appHeaderSubscription = this.headerService.headerEventEmitted$.subscribe(eventName => {
this.handleHeaderEvents(eventName);
});
}
handleHeaderEvents($event) {
if ($event.name == 'back') {
if (JSON.stringify(this.projectCopy) !== JSON.stringify(this.project) ||
JSON.stringify(this.projectCopy.tasks[this.taskIndex]) !== JSON.stringify(this.task)) {
this.pageExitConfirm();
} else {
this.location.back()
}
}
}
getProject() {
this.db.query({ _id: this.projectId }).then(
(success) => {
if (success?.docs.length) {
this.project = success.docs[0];
}
this.taskId ? this.getTask() : this.setHeaderConfig();
},
(error) => { }
);
}
getTask() {
this.taskIndex = _.findIndex(this.project.tasks, (item) => {
return item._id == this.taskId;
});
this.task = this.project.tasks[this.taskIndex];
this.setHeaderConfig();
}
updateRemarks() {
if (this.taskId) {
this.task.remarks = this.remarks;
} else {
this.project.remarks = this.remarks
}
}
setHeaderConfig() {
this.headerConfig = this.headerService.getDefaultPageConfig();
this.headerConfig.actionButtons = [];
this.headerConfig.showHeader = true;
this.headerConfig.showBurgerMenu = false;
this.headerConfig.pageTitle = this.taskId ? this.task.name : this.project.title;
this.button = this.taskId ? 'FRMELEMNTS_LBL_ATTACH_FILES' : "FRMELEMNTS_LBL_SUBMIT_IMPROVEMENT";
if (this.taskId) {
this.task.attachments = this.task?.attachments ? this.task.attachments : [];
this.attachments = this.task?.attachments ? this.task.attachments : [];
} else {
this.project.attachments = this.project?.attachments ? this.project.attachments : [];
this.attachments = this.project?.attachments ? this.project?.attachments : [];
}
this.projectCopy = JSON.parse(JSON.stringify(this.project));
this.remarks = this.taskId ? this.task.remarks : this.project?.remarks;
this.headerService.updatePageConfig(this.headerConfig);
}
ionViewWillLeave() {
if (this._appHeaderSubscription) {
this._appHeaderSubscription.unsubscribe();
}
}
async deleteConfirm(index) {
let data;
this.translate.get(["FRMELEMNTS_MSG_DELETE_ATTACHMENT_CONFIRM", "NO", "FRMELEMNTS_LBL_YES"]).subscribe((text) => {
data = text;
});
const alert = await this.alert.create({
cssClass: 'attachment-delete-alert',
message: data['FRMELEMNTS_MSG_DELETE_ATTACHMENT_CONFIRM'],
buttons: [
{
text: data["FRMELEMNTS_LBL_YES"],
handler: () => {
this.delete(index);
},
}, {
text: data["NO"],
role: "cancel",
cssClass: "secondary",
handler: (blah) => { },
},
],
});
await alert.present();
}
delete(index) {
this.attachments.splice(index, 1);
this.task.isEdit = true;
this.update('delete');
}
onAction(event) {
if(!this.taskId){
this.popupService.showPPPForProjectPopUp('FRMELEMNTS_LBL_EVIDENCES_CONTENT_POLICY', 'FRMELEMNTS_LBL_EVIDENCES_CONTENT_POLICY_TEXT', 'FRMELEMNTS_LBL_EVIDENCES_CONTENT_POLICY_LABEL', 'FRMELEMNTS_LBL_UPLOAD_EVIDENCES', 'https://diksha.gov.in/term-of-use.html', 'contentPolicy').then((data: any) => {
if (data.isClicked) {
if(data.isChecked){
if (event == 'openLink') {
this.toggleLinkModal();
return;
}
this.attachmentService.openAttachmentSource(event, this.attachments);
}else{
this.toast.showMessage('FRMELEMNTS_MSG_EVIDENCES_CONTENT_POLICY_REJECT', 'danger');
}
}
})
}else{
if (event == 'openLink') {
this.toggleLinkModal();
return;
}
this.attachmentService.openAttachmentSource(event, this.attachments);
}
}
submit() {
this.canExit = true;
if (this.taskId) {
this.task.attachments = this.attachments;
this.task.remarks = this.remarks;
if (JSON.stringify(this.projectCopy.tasks[this.taskIndex]) !== JSON.stringify(this.task)) {
this.task.isEdit = true;
this.project.isEdit = true;
this.taskId ? this.update(): this.update('submit');
this.toast.showMessage('FRMELEMNTS_LBL_FILES_ATTACHED', 'success')
} else {
this.location.back();
}
} else {
if (this.network.isNetworkAvailable) {
this.submitProjectConfirmation();
} else {
this.toast.showMessage('FRMELEMNTS_MSG_YOU_ARE_WORKING_OFFLINE_TRY_AGAIN', 'danger')
}
}
}
linkEvent(event) {
if (event) {
this.attachments = this.attachments.concat(this.projectService.getLinks(event));
if (this.taskId) {
this.task.attachments = this.task?.attachments.concat(this.projectService.getLinks(event));
} else {
this.project.attachments = this.project?.attachments.concat(this.projectService.getLinks(event));
}
this.toast.showMessage('FRMELEMNTS_MSG_SUCCESSFULLY_ATTACHED', 'success');
}
this.toggleLinkModal();
}
toggleLinkModal() {
this.isLinkModalOpen = !this.isLinkModalOpen;
}
update(type?) {
this.project.isEdit = true;
this.db
.update(this.project)
.then((success) => {
this.project._rev = success.rev;
if (type == 'submit') {
this.attachments = [];
this.doSyncAction(type === 'submit');
}else{
this.location.back();
}
})
}
doSyncAction(isSubmission:boolean = false) {
if (this.network.isNetworkAvailable) {
this.project.isNew
? this.projectServ.createNewProject(this.project)
: this.router.navigate([`${RouterLinks.PROJECT}/${RouterLinks.SYNC}`], { queryParams: { projectId: this.projectId,isSubmission: isSubmission } });
} else {
this.toast.showMessage('FRMELEMNTS_MSG_PLEASE_GO_ONLINE', 'danger');
}
}
async pageExitConfirm() {
let data;
this.translate.get(["FRMELEMNTS_MSG_ATTACHMENT_PAGE_EXIT_CONFIRM", "FRMELEMNTS_BTN_EXIT_PAGE", "FRMELEMNTS_BTN_YES_PAGE", "FRMELEMNTS_LBL_YES", "NO"]).subscribe((text) => {
data = text;
});
const alert = await this.alert.create({
cssClass: 'central-alert',
header: data['FRMELEMNTS_BTN_EXIT_PAGE'],
message: data['FRMELEMNTS_MSG_ATTACHMENT_PAGE_EXIT_CONFIRM'],
buttons: [
{
text: this.taskId ? data["FRMELEMNTS_BTN_YES_PAGE"] : data["FRMELEMNTS_LBL_YES"],
handler: () => { },
}, {
text: data["NO"],
role: "cancel",
cssClass: "secondary",
handler: (blah) => {
},
},
],
});
await alert.present();
let resp = await alert.onDidDismiss();
if (resp.role !== 'cancel') {
this.location.back();
}
}
async submitProjectConfirmation() {
let data;
this.translate.get(["FRMELEMNTS_MSG_SUBMIT_PROJECT", "FRMELEMNTS_LBL_SUBMIT_IMPROVEMENT", "CANCEL", "FRMELEMNTS_BTN_SUBMIT"]).subscribe((text) => {
data = text;
});
const alert = await this.alert.create({
cssClass: 'central-alert',
header: data['FRMELEMNTS_LBL_SUBMIT_IMPROVEMENT'],
message: data["FRMELEMNTS_MSG_SUBMIT_PROJECT"],
buttons: [
{
text: data["CANCEL"],
role: "cancel",
cssClass: "secondary",
handler: (blah) => { },
},
{
text: data["FRMELEMNTS_BTN_SUBMIT"],
handler: () => {
this.submitProject();
},
},
],
});
await alert.present();
}
submitProject() {
setTimeout(() => {
this.project.attachments = this.attachments;
this.project.remarks = this.remarks;
// this.project.status = statusType.submitted;
this.update('submit');
}, 0)
this.location.back()
}
}
<ion-content>
<div class="warning-block" *ngIf="project?.certificate && !taskId">
<div class="icon-box"> <ion-icon name="information-circle-outline"></ion-icon> </div>
<div class="message">{{"FRMELEMNTS_MSG_CERTIFICATE_CRITERIA_BFR_SUBMITTING" | translate}} </div>
</div>
<h5 class="page-header-content">{{ description | translate }}
</h5>
<div class="ion-padding">
<app-item-list-header headerLabel="{{'FRMELEMNTS_LBL_ADD_REMARKS' | translate}}"></app-item-list-header>
<div class="text-area-container">
<ion-textarea rows="8" placeholder="{{'FRMELEMNTS_LBL_TYPE_REMARKS_HERE' | translate}}" [(ngModel)]="remarks" (ngModelChange)="updateRemarks()">
</ion-textarea>
</div>
<app-item-list-header headerLabel="{{'FRMELEMNTS_LBL_ADD_ATTACHMENTS' | translate}}"></app-item-list-header>
<div class="sb-dt-card-actions">
<div class="wrapper">
<app-metadata-actions (actionEvent)="onAction($event)" [actionItems]="actionItems"></app-metadata-actions>
</div>
</div>
<div *ngFor="let attachment of attachments; let i = index" class="attachments-list">
<div class="attachment-label" *ngIf="attachment?.type != 'link'">
<ion-icon name="image" slot="start" *ngIf="attachment?.type == 'image/jpeg'"></ion-icon>
<ion-icon name="document" slot="start" *ngIf="attachment?.type == 'application/pdf'"></ion-icon>
<ion-icon name="videocam" slot="start" *ngIf="attachment?.type == 'video/mp4'"></ion-icon>
<span>{{attachment?.name || attachment?.url}} </span>
</div>
<div class="attachment-label" *ngIf="attachment?.type == 'link'">
<ion-icon name="link-outline" slot="start"></ion-icon>
<span>{{attachment?.name || attachment?.url}} </span>
</div>
<div>
<button slot="icon-only" (click)="deleteConfirm(i)">
<ion-icon name="close-circle" slot="end"></ion-icon>
<p class="card-text">{{'REMOVE_ACTIVITY'| translate}}
</p>
</button>
</div>
</div>
<ion-button (click)="submit()" expand="block" class="text-transform-none">
{{button | translate}}
</ion-button>
</div>
</ion-content>
<app-add-link-modal *ngIf="isLinkModalOpen" (eventEmit)="linkEvent($event)"> </app-add-link-modal>
./add-file.page.scss
@import "src/assets/styles/_variables.scss";
.page-header-content{
color: var(--app-light-gray) !important;
font-weight: bold !important;
margin: 15px 15px 0px 15px;
}
.text-area-container{
border: 2px solid $gray-400;
border-radius: 8px;
margin: 0px 15px;
}
.attachments-list{
background-color: $white-color;
color: $black-color;
padding: 10px 10px 5px 10px;
justify-content: space-between;
display: flex;
border-radius: 8px;
margin: 10px 10px;
height: auto;
font-weight: 600;
.attachment-label{
ion-icon{
font-size: 1.25rem;
position: absolute;
}
span{
margin-left:25px;
word-break: break-all;
}
}
button{
background: transparent;
box-shadow: none !important;
margin-top: -7px;
p{
margin-bottom: 0px;
font-size: 0.75rem !important;
margin-top: -5px;
text-align: center;
font-weight: 600;
}
}
ion-icon{
font-size: 1.25rem;
color: $black-color !important;
}
}
.text-transform-none {
text-transform: none !important;
}
.warning-block{
display: flex;
background: #e8baad;
padding: 5px 10px;
margin: 10px 15px;
border-radius: 12px;
.icon-box{
font-size: 20px;
margin-right: 5px;
}
.message{
font-size: 12px;
}
}