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 { 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-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';
|
2022-02-09 15:06:54 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2022-03-30 16:32:56 +01:00
|
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
2023-02-27 17:39:10 +01:00
|
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
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;
|
|
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
publicationList: {[key: string]: Publication[] } = {};
|
|
|
|
|
publicationItem: {[key: string]: PublicationFolder } = {};
|
2022-02-09 15:06:54 +01:00
|
|
|
getpublication = [];
|
2021-04-08 09:14:28 +01:00
|
|
|
error: any;
|
|
|
|
|
|
2023-02-02 12:01:18 +01:00
|
|
|
@Input() folderId: any;
|
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>();
|
2022-06-07 12:01:12 +01:00
|
|
|
@Output() getActions= new EventEmitter<any>();
|
2021-07-21 20:26:41 +01:00
|
|
|
|
2021-08-23 11:48:44 +01:00
|
|
|
publicationPipe = new PublicationPipe()
|
|
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
constructor(
|
|
|
|
|
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,
|
2022-03-30 16:32:56 +01:00
|
|
|
private storage: Storage,
|
|
|
|
|
public p:PermissionService,
|
2023-02-27 17:39:10 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle
|
2021-07-30 11:45:18 +01:00
|
|
|
) {
|
2023-02-27 21:24:34 +01:00
|
|
|
if(!this.publicationList[this.folderId]) {
|
|
|
|
|
this.publicationList[this.folderId] = []
|
|
|
|
|
this.publicationItem[this.folderId] = 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
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
if(!this.publicationList[this.folderId]) {
|
|
|
|
|
this.publicationList[this.folderId] = []
|
|
|
|
|
this.publicationItem[this.folderId] = new PublicationFolder();
|
|
|
|
|
}
|
2021-08-25 15:23:30 +01:00
|
|
|
|
|
|
|
|
window['app-view-publications-page-doRefresh'] = this.doRefresh
|
2023-02-27 20:17:03 +01:00
|
|
|
|
|
|
|
|
this.getFromDB();
|
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']
|
|
|
|
|
}
|
2023-02-27 21:24:34 +01:00
|
|
|
|
|
|
|
|
if(!this.publicationList[this.folderId]) {
|
|
|
|
|
this.publicationList[this.folderId] = []
|
|
|
|
|
this.publicationItem[this.folderId] = new PublicationFolder();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 20:17:03 +01:00
|
|
|
this.getFromDB();
|
2022-03-30 16:32:56 +01:00
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
this.getPublicationDetail();
|
|
|
|
|
this.getPublicationsIds();
|
2021-07-21 20:26:41 +01:00
|
|
|
|
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
|
|
|
|
2023-02-27 20:04:22 +01:00
|
|
|
this.getPublicationDetail();
|
|
|
|
|
this.getPublicationsIds();
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
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() {
|
2023-02-27 20:04:22 +01:00
|
|
|
this.showLoader = true;
|
2023-02-27 21:24:34 +01:00
|
|
|
const folderId = this.folderId
|
|
|
|
|
this.publications.GetPresidentialAction(folderId).subscribe(res=>{
|
2023-02-27 20:04:22 +01:00
|
|
|
this.showLoader = false;
|
2023-02-27 21:24:34 +01:00
|
|
|
this.publicationItem[folderId] = res
|
|
|
|
|
this.storage.set(folderId+"name", res)
|
2023-02-27 20:04:22 +01:00
|
|
|
}, (error) => {
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
// this.httpErroHandle.httpStatusHandle(error)
|
2021-12-14 23:13:21 +01:00
|
|
|
});
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
2021-06-29 14:16:49 +01:00
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
async getPublicationsIds() {
|
2022-02-09 15:06:54 +01:00
|
|
|
|
|
|
|
|
this.showLoader = true;
|
|
|
|
|
const folderId = this.folderId
|
|
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
try {
|
|
|
|
|
const res = await this.publications.GetPublicationsImages(folderId).toPromise();
|
|
|
|
|
let publicationList = []
|
|
|
|
|
|
|
|
|
|
for (let element of res) {
|
|
|
|
|
let ress = await this.publications.GetPublicationById(element).toPromise();
|
|
|
|
|
let item: Publication = this.publicationPipe.itemList(ress)
|
|
|
|
|
publicationList.push(item);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 15:06:54 +01:00
|
|
|
this.showLoader = false;
|
2023-02-27 21:24:34 +01:00
|
|
|
|
|
|
|
|
this.publicationList[folderId] = publicationList
|
|
|
|
|
this.storage.set(folderId, publicationList);
|
|
|
|
|
this.getpublication = publicationList;
|
|
|
|
|
} catch(error) {
|
2023-02-27 20:04:22 +01:00
|
|
|
this.showLoader = false;
|
2023-02-27 21:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-02-09 15:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFromDB() {
|
2023-02-27 21:24:34 +01:00
|
|
|
const folderId = this.folderId
|
|
|
|
|
this.storage.get(folderId).then((viewPublications) => {
|
|
|
|
|
this.publicationList[folderId] = viewPublications
|
|
|
|
|
})
|
|
|
|
|
this.storage.get(folderId+"name").then((viewPublications) => {
|
|
|
|
|
this.publicationItem[folderId] = viewPublications
|
2022-02-09 15:06:54 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 20:17:03 +01:00
|
|
|
// getPublications() {
|
|
|
|
|
// this.showLoader = true;
|
|
|
|
|
// const folderId = this.folderId
|
|
|
|
|
// this.publicationList = new Array();
|
|
|
|
|
// this.publications.GetPublications(folderId).subscribe(async res=> {
|
|
|
|
|
|
|
|
|
|
// res.forEach(element => {
|
|
|
|
|
// let item: Publication = this.publicationPipe.itemList(element)
|
|
|
|
|
// this.publicationList.push(item);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// this.showLoader = false;
|
|
|
|
|
// await this.storage.remove(folderId);
|
|
|
|
|
// await this.storage.set(folderId, this.publicationList);
|
|
|
|
|
// //this.getFromDB();
|
|
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
// (error)=>{
|
|
|
|
|
// if(error.status == '404') {
|
|
|
|
|
// this.error = 'Sem publicações disponíveis!';
|
|
|
|
|
// this.publicationList= [];
|
|
|
|
|
// }
|
2021-07-15 11:53:16 +01:00
|
|
|
|
2023-02-27 20:17:03 +01:00
|
|
|
// this.showLoader = false;
|
2021-07-30 11:45:18 +01:00
|
|
|
|
2023-02-27 20:17:03 +01:00
|
|
|
// })
|
2021-07-21 19:08:31 +01:00
|
|
|
|
2023-02-27 20:17:03 +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
|
|
|
|
2022-02-09 16:05:06 +01:00
|
|
|
if( window.innerWidth < 701) {
|
2021-03-15 12:06:06 +01:00
|
|
|
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){
|
2022-06-09 10:24:50 +01:00
|
|
|
|
2021-12-15 15:07:26 +01:00
|
|
|
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(() => {
|
2022-06-06 15:28:27 +01:00
|
|
|
// Do nothing
|
2021-12-15 15:07:26 +01:00
|
|
|
});
|
|
|
|
|
}
|
2022-06-06 15:28:27 +01:00
|
|
|
else {
|
2021-12-15 15:07:26 +01:00
|
|
|
this.editPublication.emit(folderId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 15:28:27 +01:00
|
|
|
async deletePublication(folderId?:any) {
|
2021-12-15 15:07:26 +01:00
|
|
|
const loader = this.toastService.loading();
|
|
|
|
|
try {
|
|
|
|
|
await this.publications.DeletePresidentialAction(folderId).toPromise();
|
2023-02-27 17:39:10 +01:00
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Eliminar Acção')
|
2023-02-02 12:01:18 +01:00
|
|
|
} catch (error) {
|
2023-02-27 17:39:10 +01:00
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
2021-12-15 15:07:26 +01:00
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
loader.remove()
|
|
|
|
|
}
|
2022-06-07 12:01:12 +01:00
|
|
|
this.close();
|
|
|
|
|
this.getActions.emit();
|
2021-12-15 15:07:26 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|