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';
|
2021-11-19 14:56:29 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
import { NewPublicationPage } from 'src/app/pages/publications/new-publication/new-publication.page';
|
2021-07-21 20:26:41 +01:00
|
|
|
import { PublicationListStorage } from 'src/app/store/publication-list.service'
|
|
|
|
|
import { PublicationEventFolderStorage } from 'src/app/store/publication-event-folder.service';
|
|
|
|
|
import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-folder.service';
|
2021-08-23 11:30:42 +01:00
|
|
|
import { PublicationPipe } from 'src/app/pipes/publication.pipe';
|
2021-10-25 13:21:48 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
2021-12-15 15:07:26 +01:00
|
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
|
|
|
import { EditActionPage } from 'src/app/pages/publications/edit-action/edit-action.page';
|
2021-10-25 13:21:48 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
@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-12-15 15:07:26 +01:00
|
|
|
@Output() editPublication = 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
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
|
|
|
|
|
publicationListStorage = PublicationListStorage
|
|
|
|
|
//
|
|
|
|
|
publicationEventFolderStorage = PublicationEventFolderStorage
|
|
|
|
|
publicationTravelFolderService = PublicationTravelFolderStore
|
|
|
|
|
|
2021-08-23 11:48:44 +01:00
|
|
|
publicationPipe = new PublicationPipe()
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
constructor(
|
|
|
|
|
private loadingController: LoadingService,
|
|
|
|
|
private modalController: ModalController,
|
2021-10-25 13:21:48 +01:00
|
|
|
private publications: PublicationsService,
|
2021-12-15 15:07:26 +01:00
|
|
|
public ThemeService: ThemeService,
|
|
|
|
|
private toastService: ToastService,
|
2021-07-30 11:45:18 +01:00
|
|
|
) {
|
2021-03-12 14:38:55 +01:00
|
|
|
this.item = new PublicationFolder();
|
2021-03-15 16:47:16 +01:00
|
|
|
}
|
2021-03-12 14:38:55 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-07-15 17:39:19 +01:00
|
|
|
if(typeof(this.folderId) == 'object') {
|
|
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
this.getPublications();
|
|
|
|
|
this.getPublicationDetail();
|
2021-08-25 15:23:30 +01:00
|
|
|
|
|
|
|
|
window['app-view-publications-page-doRefresh'] = this.doRefresh
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnChanges(changes: any): void {
|
|
|
|
|
|
2021-07-15 17:42:12 +01:00
|
|
|
if(typeof(this.folderId) == 'object') {
|
|
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
2021-08-09 13:56:17 +01:00
|
|
|
console.log('change view to ',this.folderId)
|
2021-07-15 17:42:12 +01:00
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
setTimeout(()=>{
|
|
|
|
|
this.getPublications();
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}, 100)
|
|
|
|
|
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-25 15:23:30 +01:00
|
|
|
doRefresh =(event) => {
|
2021-03-12 14:38:55 +01:00
|
|
|
this.getPublications();
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.getPublicationDetail();
|
|
|
|
|
}, 3000);
|
|
|
|
|
}
|
2021-07-21 19:08:31 +01:00
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
close() {
|
2021-03-17 09:01:24 +01:00
|
|
|
this.closeDesktopComponent.emit();
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2021-06-29 14:16:49 +01:00
|
|
|
getPublicationDetail() {
|
2021-12-14 23:13:21 +01:00
|
|
|
this.publications.GetPresidentialAction(this.folderId).subscribe(res=>{
|
|
|
|
|
console.log(res);
|
|
|
|
|
this.item = res;
|
|
|
|
|
});
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
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;
|
2021-07-21 20:26:41 +01:00
|
|
|
const folderId = this.folderId
|
2022-01-19 16:32:06 +01:00
|
|
|
this.publicationList = new Array();
|
2021-07-21 20:26:41 +01:00
|
|
|
this.publications.GetPublications(folderId).subscribe(res=> {
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
res.forEach(element => {
|
2021-08-23 11:30:42 +01:00
|
|
|
let item: Publication = this.publicationPipe.itemList(element)
|
2021-03-12 14:38:55 +01:00
|
|
|
this.publicationList.push(item);
|
|
|
|
|
});
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
this.showLoader = false;
|
2021-04-08 09:14:28 +01:00
|
|
|
},
|
|
|
|
|
(error)=>{
|
2021-07-21 20:26:41 +01:00
|
|
|
if(error.status == '404') {
|
2021-04-08 09:14:28 +01:00
|
|
|
this.error = 'Sem publicações disponíveis!';
|
2021-09-03 17:01:01 +01:00
|
|
|
this.publicationList= [];
|
|
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
2021-04-08 09:14:28 +01:00
|
|
|
}
|
2021-07-15 11:53:16 +01:00
|
|
|
|
|
|
|
|
this.showLoader = false;
|
2021-07-30 11:45:18 +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
|
|
|
}
|
|
|
|
|
|
2021-12-15 15:07:26 +01:00
|
|
|
async openEditPublication(folderId?:any){
|
|
|
|
|
if( window.innerWidth < 701) {
|
|
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: EditActionPage,
|
|
|
|
|
componentProps: {
|
|
|
|
|
folderId: folderId,
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'new-action modal modal-desktop',
|
|
|
|
|
backdropDismiss: true
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
|
|
|
|
modal.onDidDismiss().then(() => {
|
|
|
|
|
//Do nothing
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.editPublication.emit(folderId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deletePublication(folderId?:any){
|
|
|
|
|
const loader = this.toastService.loading();
|
|
|
|
|
try {
|
|
|
|
|
await this.publications.DeletePresidentialAction(folderId).toPromise();
|
|
|
|
|
this.toastService._successMessage()
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.toastService._badRequest()
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
loader.remove()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
async viewPublicationDetail(publicationId:string) {
|
2021-03-15 16:47:16 +01:00
|
|
|
|
|
|
|
|
|
2021-08-24 11:15:13 +01:00
|
|
|
// if( window.innerWidth <= 1024) {
|
|
|
|
|
// const modal = await this.modalController.create({
|
|
|
|
|
// component: PublicationDetailPage,
|
|
|
|
|
// componentProps:{
|
|
|
|
|
// publicationId: publicationId,
|
|
|
|
|
// },
|
|
|
|
|
// cssClass: 'publication-detail modal modal-desktop',
|
|
|
|
|
// //backdropDismiss: false
|
|
|
|
|
// });
|
|
|
|
|
// await modal.present();
|
|
|
|
|
// modal.onDidDismiss().then(()=>{
|
|
|
|
|
// this.doRefresh(event);
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// // open publication details
|
|
|
|
|
// this.openPublicationDetails.emit(publicationId);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
this.openPublicationDetails.emit(publicationId);
|
2021-03-15 16:47:16 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|