2021-03-15 12:06:06 +01:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
2021-03-12 14:38:55 +01:00
|
|
|
import { Publication } from 'src/app/models/publication';
|
|
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
|
|
|
|
import { LoadingService } from 'src/app/services/loading.service';
|
|
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
|
|
|
import { PublicationDetailPage } from 'src/app/pages/publications/publication-detail/publication-detail.page';
|
|
|
|
|
import { NewPublicationPage } from 'src/app/pages/publications/new-publication/new-publication.page';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-view-publications',
|
|
|
|
|
templateUrl: './view-publications.page.html',
|
|
|
|
|
styleUrls: ['./view-publications.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ViewPublicationsPage implements OnInit {
|
|
|
|
|
showLoader: boolean;
|
|
|
|
|
loading: any;
|
|
|
|
|
|
|
|
|
|
publicationList: Publication[];
|
|
|
|
|
item: PublicationFolder;
|
|
|
|
|
|
2021-04-08 09:14:28 +01:00
|
|
|
error: any;
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
@Input() folderId: string;
|
2021-03-15 12:06:06 +01:00
|
|
|
@Output() addNewPublication = new EventEmitter<any>();
|
2021-03-15 16:47:16 +01:00
|
|
|
@Output() openPublicationDetails= new EventEmitter<any>();
|
2021-03-17 09:01:24 +01:00
|
|
|
@Output() goBackToViewPublications = new EventEmitter();
|
|
|
|
|
@Output() closeDesktopComponent = new EventEmitter<any>();
|
|
|
|
|
@Output() goBacktoPublicationDetails = new EventEmitter<any>();
|
2021-03-12 14:38:55 +01:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private loadingController: LoadingService,
|
|
|
|
|
private modalController: ModalController,
|
|
|
|
|
private publications: PublicationsService,
|
|
|
|
|
) {
|
|
|
|
|
this.item = new PublicationFolder();
|
2021-03-15 16:47:16 +01:00
|
|
|
}
|
2021-03-12 14:38:55 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
console.log(this.folderId);
|
2021-07-15 17:39:19 +01:00
|
|
|
|
|
|
|
|
if(typeof(this.folderId) == 'object') {
|
|
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
2021-03-12 14:38:55 +01:00
|
|
|
|
|
|
|
|
this.getPublications();
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: any): void {
|
|
|
|
|
console.log(this.folderId)
|
|
|
|
|
|
2021-07-15 17:42:12 +01:00
|
|
|
if(typeof(this.folderId) == 'object') {
|
|
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
this.getPublications();
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doRefresh(event) {
|
|
|
|
|
this.getPublications();
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.getPublications();
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
event.target.complete();
|
|
|
|
|
}, 3000);
|
|
|
|
|
}
|
2021-07-21 19:08:31 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
close(){
|
2021-03-17 09:01:24 +01:00
|
|
|
this.closeDesktopComponent.emit();
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
|
|
|
|
getPublicationDetail() {
|
2021-07-01 09:36:17 +01:00
|
|
|
this.publications.GetPresidentialAction(this.folderId).subscribe(res=>{
|
2021-03-12 14:38:55 +01:00
|
|
|
console.log(res);
|
|
|
|
|
this.item = res;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2021-07-21 19:08:31 +01:00
|
|
|
getPublications() {
|
2021-03-12 14:38:55 +01:00
|
|
|
this.showLoader = true;
|
|
|
|
|
|
|
|
|
|
this.publications.GetPublications(this.folderId).subscribe(res=>{
|
|
|
|
|
this.publicationList = new Array();
|
|
|
|
|
console.log(res);
|
|
|
|
|
res.forEach(element => {
|
|
|
|
|
let itemImage = {
|
|
|
|
|
title: 'Title',
|
|
|
|
|
url: "data:image/jpg;base64," + element.FileBase64,
|
|
|
|
|
format: 'png'
|
|
|
|
|
}
|
|
|
|
|
let item: Publication = {
|
|
|
|
|
"DateIndex": element.DateIndex,
|
|
|
|
|
"DocumentId":element.DocumentId,
|
|
|
|
|
"ProcessId":element.ProcessId,
|
|
|
|
|
"Title":element.Title,
|
|
|
|
|
"Message": element.Message,
|
|
|
|
|
"DatePublication": element.DatePublication,
|
|
|
|
|
/* image:itemImage, */
|
|
|
|
|
"FileBase64": "data:image/jpg;base64," + element.FileBase64,
|
|
|
|
|
"OriginalFileName": '',
|
|
|
|
|
"FileExtension": '',
|
|
|
|
|
}
|
|
|
|
|
this.publicationList.push(item);
|
|
|
|
|
});
|
|
|
|
|
console.log(this.publicationList);
|
|
|
|
|
this.showLoader = false;
|
2021-04-08 09:14:28 +01:00
|
|
|
},
|
|
|
|
|
(error)=>{
|
|
|
|
|
if(error.status == '404'){
|
|
|
|
|
this.error = 'Sem publicações disponíveis!';
|
2021-04-08 10:27:35 +01:00
|
|
|
this.publicationList=null;
|
2021-04-08 09:14:28 +01:00
|
|
|
}
|
2021-07-15 11:53:16 +01:00
|
|
|
|
|
|
|
|
this.showLoader = false;
|
2021-04-08 09:14:28 +01:00
|
|
|
|
2021-07-21 19:08:31 +01:00
|
|
|
})
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-03 10:41:25 +01:00
|
|
|
async AddPublication(publicationType:any, folderId:any) {
|
2021-03-15 12:06:06 +01:00
|
|
|
|
|
|
|
|
if( window.innerWidth <= 1024) {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: NewPublicationPage,
|
|
|
|
|
componentProps:{
|
|
|
|
|
publicationType: publicationType,
|
|
|
|
|
folderId: folderId,
|
|
|
|
|
},
|
2021-07-15 08:53:54 +01:00
|
|
|
cssClass: 'new-publication modal modal-desktop',
|
2021-03-15 12:06:06 +01:00
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(()=>{
|
|
|
|
|
this.doRefresh(event);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.addNewPublication.emit({
|
2021-03-12 14:38:55 +01:00
|
|
|
publicationType: publicationType,
|
2021-03-15 12:06:06 +01:00
|
|
|
folderId: folderId
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async viewPublicationDetail(publicationId:string) {
|
2021-03-15 16:47:16 +01:00
|
|
|
|
|
|
|
|
console.log(publicationId);
|
|
|
|
|
|
|
|
|
|
if( window.innerWidth <= 1024) {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: PublicationDetailPage,
|
|
|
|
|
componentProps:{
|
|
|
|
|
publicationId: publicationId,
|
|
|
|
|
},
|
2021-04-29 19:46:40 +01:00
|
|
|
cssClass: 'publication-detail modal modal-desktop',
|
|
|
|
|
//backdropDismiss: false
|
2021-03-15 16:47:16 +01:00
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(()=>{
|
|
|
|
|
this.doRefresh(event);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// open publication details
|
|
|
|
|
this.openPublicationDetails.emit(publicationId);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|