Files
doneit-web/src/app/pages/publications/view-publications/publication-detail/publication-detail.page.ts
T
ivan gomes dc84401716 save
2021-12-03 17:27:10 +01:00

164 lines
4.2 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AnimationController, ModalController } from '@ionic/angular';
import { Publication } from 'src/app/models/publication';
import { PublicationsService } from 'src/app/services/publications.service';
import { ToastService } from 'src/app/services/toast.service';
import { ImageModalPage } from '../../gallery/image-modal/image-modal.page';
import { NewPublicationPage } from '../../new-publication/new-publication.page';
import { Location } from '@angular/common';
import { ThemeService } from 'src/app/services/theme.service'
@Component({
selector: 'app-publication-detail',
templateUrl: './publication-detail.page.html',
styleUrls: ['./publication-detail.page.scss'],
})
export class PublicationDetailPage implements OnInit {
showLoader: boolean;
publicationId: string;
folderId: string;
publication: Publication;
isModal = false
constructor(
private modalController: ModalController,
private publications:PublicationsService,
private animationController: AnimationController,
private toastService: ToastService,
private activatedRoute: ActivatedRoute,
private router: Router,
private location: Location,
public ThemeService: ThemeService
) {
this.activatedRoute.paramMap.subscribe(params => {
console.log(params);
if(params["params"]) {
this.folderId = params["params"].folderId;
this.publicationId = params["params"].publicationId;
// console.log(params["params"]);
}
});
this.publication = {
DateIndex: null,
DocumentId: '',
ProcessId:'',
Title:'',
Message: '',
/* image: null, */
DatePublication: null,
FileBase64: '',
OriginalFileName: '',
FileExtension: '',
};
}
ngOnInit() {
/* console.log(this.publication.FileBase64); */
this.getPublicationDetail();
}
doRefresh(event) {
this.getPublicationDetail();
setTimeout(() => {
event.target.complete();
}, 2000);
}
getPublicationDetail(){
this.showLoader = true;
console.log(this.publicationId);
/* console.log(this.folderId); */
this.publications.GetPublicationById(this.publicationId).subscribe(res=>{
console.log(res);
/* this.publication = res; */
this.publication = {
DateIndex: res.DateIndex,
DocumentId: res.DocumentId,
ProcessId:res.ProcessId,
Title:res.Title,
Message: res.Message,
DatePublication: res.DatePublication,
FileBase64: "data:image/jpg;base64," + res.FileBase64,
OriginalFileName: res.OriginalFileName,
FileExtension: 'jpeg',
}
this.showLoader = false;
});
}
close() {
this.modalController.dismiss();
}
goBack() {
if(this.isModal) {
this.close()
} else {
// alert('go back')
this.location.back();
}
}
async deletePost() {
const loader = this.toastService.loading()
try {
await this.publications.DeletePublication(this.folderId, this.publicationId).toPromise();
this.toastService.successMessage('Publicação eliminada')
if(window['app-view-publications-page-doRefresh']) {
window['app-view-publications-page-doRefresh']()
}
this.goBack();
} catch (error) {
this.toastService.badRequest('Publicaçao não eliminada')
} finally {
loader.remove()
}
}
async editPost(publicationType:any) {
console.log(this.publication);
const modal = await this.modalController.create({
component: NewPublicationPage,
componentProps:{
publicationType: publicationType,
publication: this.publication,
folderId: this.folderId
},
cssClass: 'new-publication modal modal-desktop',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(()=>{
setTimeout(() => {
this.getPublicationDetail();
}, 5000);
});
}
openPreview(imageUrl:string){
this.modalController.create({
component: ImageModalPage,
componentProps: {
imageUrl:imageUrl,
}
}).then(modal => modal.present());
}
}