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';
|
2023-08-11 16:38:23 +01:00
|
|
|
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
|
|
|
|
|
import { AskModalPage } from 'src/app/modals/ask-modal/ask-modal.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;
|
|
|
|
|
|
2021-04-08 09:14:28 +01:00
|
|
|
error: any;
|
2023-08-10 16:46:55 +01:00
|
|
|
oldpublicationIds = []
|
2021-04-08 09:14:28 +01:00
|
|
|
|
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-08-11 16:38:23 +01:00
|
|
|
private httpErrorHandle: HttpErrorHandle,
|
|
|
|
|
public publicationFolderService: PublicationFolderService
|
2021-07-30 11:45:18 +01:00
|
|
|
) {
|
2023-03-10 14:30:50 +01:00
|
|
|
this.createPublicationList()
|
2023-08-11 16:38:23 +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-03-10 14:30:50 +01:00
|
|
|
this.createPublicationList()
|
2021-08-25 15:23:30 +01:00
|
|
|
|
|
|
|
|
window['app-view-publications-page-doRefresh'] = this.doRefresh
|
2023-08-10 16:46:55 +01:00
|
|
|
window['_deletePublication'] = (a, b) => {
|
|
|
|
|
this._deletePublication(a, b)
|
|
|
|
|
}
|
2023-02-27 20:17:03 +01:00
|
|
|
|
|
|
|
|
this.getFromDB();
|
2023-08-11 16:38:23 +01:00
|
|
|
|
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
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
if(!this.publicationFolderService.publicationList[this.folderId]) {
|
|
|
|
|
this.publicationFolderService.FolderDetails[this.folderId] = new PublicationFolder();
|
2023-02-27 21:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:30:50 +01:00
|
|
|
this.createPublicationList()
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:30:50 +01:00
|
|
|
|
|
|
|
|
createPublicationList(folderId = this.folderId) {
|
2023-08-11 16:38:23 +01:00
|
|
|
if(!this.publicationFolderService.publicationList[this.folderId]) {
|
|
|
|
|
this.publicationFolderService.publicationList[this.folderId] = []
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
2023-08-11 16:38:23 +01:00
|
|
|
if(!this.publicationFolderService.FolderDetails[this.folderId]) {
|
|
|
|
|
this.publicationFolderService.FolderDetails[this.folderId] = new PublicationFolder();
|
2023-03-10 14:30:50 +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 21:24:34 +01:00
|
|
|
const folderId = this.folderId
|
|
|
|
|
this.publications.GetPresidentialAction(folderId).subscribe(res=>{
|
2023-07-11 10:25:16 +01:00
|
|
|
|
|
|
|
|
// PublicationDetailsModel.create(res)
|
2023-08-11 16:38:23 +01:00
|
|
|
this.publicationFolderService.FolderDetails[folderId] = res
|
2023-02-27 21:24:34 +01:00
|
|
|
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-08-10 16:46:55 +01:00
|
|
|
|
2023-02-27 21:24:34 +01:00
|
|
|
try {
|
2023-03-04 07:21:33 +01:00
|
|
|
const publicationIds = await this.publications.GetPublicationsList(folderId).toPromise();
|
2023-03-10 14:30:50 +01:00
|
|
|
|
|
|
|
|
this.createPublicationList(folderId)
|
|
|
|
|
let loadLater = []
|
2023-03-04 07:21:33 +01:00
|
|
|
for (let publicationId of publicationIds) {
|
2023-03-10 14:30:50 +01:00
|
|
|
|
|
|
|
|
if(!this.publicationIsPresent(publicationId, folderId)) {
|
|
|
|
|
await this.loadPublication(publicationId, folderId)
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
loadLater.push(publicationId)
|
2023-03-04 07:21:33 +01:00
|
|
|
}
|
2023-02-27 21:24:34 +01:00
|
|
|
}
|
2023-03-10 14:30:50 +01:00
|
|
|
|
|
|
|
|
for( let publicationId of loadLater) {
|
|
|
|
|
await this.loadPublication(publicationId, folderId)
|
|
|
|
|
}
|
2023-08-21 17:36:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
for(let localPublication of this.publicationFolderService.publicationList[folderId]) {
|
|
|
|
|
|
|
|
|
|
const apiPublication = publicationIds.includes(localPublication.DocumentId)
|
|
|
|
|
if(!apiPublication) {
|
|
|
|
|
this.publicationFolderService.deletePost(folderId, localPublication.DocumentId)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-27 21:24:34 +01:00
|
|
|
|
2022-02-09 15:06:54 +01:00
|
|
|
this.showLoader = false;
|
2023-02-27 21:24:34 +01:00
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
this.storage.set(folderId, this.publicationFolderService.publicationList[folderId]);
|
2023-08-10 16:46:55 +01:00
|
|
|
|
|
|
|
|
this.oldpublicationIds = publicationIds
|
2023-02-27 21:24:34 +01:00
|
|
|
} catch(error) {
|
2023-02-27 20:04:22 +01:00
|
|
|
this.showLoader = false;
|
2023-02-27 21:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
2023-02-27 21:24:34 +01:00
|
|
|
|
2023-08-10 16:46:55 +01:00
|
|
|
_deletePublication = (folderId, publicationId) => {
|
|
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
this.publicationFolderService.publicationList[folderId] = this.publicationFolderService.publicationList[folderId].filter( e => e.DocumentId != publicationId)
|
2023-08-10 16:46:55 +01:00
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
console.log('this.publicationFolderService.publicationList[folderId]', this.publicationFolderService.publicationList[folderId].length)
|
2023-08-10 16:46:55 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:30:50 +01:00
|
|
|
publicationIsPresent(publicationId, folderId) {
|
2023-08-11 16:38:23 +01:00
|
|
|
return this.publicationFolderService.publicationList[folderId].find( e => e.DocumentId == publicationId )
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
|
|
|
|
publicationFind(publicationId, folderId) {
|
2023-08-11 16:38:23 +01:00
|
|
|
return this.publicationFolderService.publicationList[folderId].find( e => e.DocumentId == publicationId )
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
|
|
|
|
publicationFindIndex(publicationId, folderId) {
|
2023-08-11 16:38:23 +01:00
|
|
|
return this.publicationFolderService.publicationList[folderId].findIndex( e => e.DocumentId == publicationId )
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async loadPublication(publicationId, folderId) {
|
|
|
|
|
let Publication = await this.publications.GetPublicationById(publicationId).toPromise();
|
|
|
|
|
let publicationDetails: Publication = this.publicationPipe.itemList(Publication)
|
|
|
|
|
|
|
|
|
|
const findIndex = this.publicationFindIndex(publicationId, folderId)
|
|
|
|
|
const found = this.publicationIsPresent(publicationId, folderId)
|
|
|
|
|
if(!found) {
|
2023-08-11 16:38:23 +01:00
|
|
|
this.publicationFolderService.publicationList[folderId].push(publicationDetails)
|
2023-03-10 14:30:50 +01:00
|
|
|
} else {
|
2023-08-11 16:38:23 +01:00
|
|
|
this.publicationFolderService.publicationList[folderId][findIndex] = publicationDetails
|
2023-03-10 14:30:50 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-09 15:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFromDB() {
|
2023-02-27 21:24:34 +01:00
|
|
|
const folderId = this.folderId
|
2021-07-15 11:53:16 +01:00
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
this.publicationFolderService.getFromDB(folderId)
|
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2021-03-15 12:06:06 +01:00
|
|
|
modal.onDidDismiss().then(()=>{
|
|
|
|
|
this.doRefresh(event);
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
|
|
|
|
await modal.present();
|
2021-03-15 12:06:06 +01:00
|
|
|
} 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
|
|
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
|
2021-12-15 15:07:26 +01:00
|
|
|
modal.onDidDismiss().then(() => {
|
2022-06-06 15:28:27 +01:00
|
|
|
// Do nothing
|
2021-12-15 15:07:26 +01:00
|
|
|
});
|
2023-07-15 11:01:09 +01:00
|
|
|
await modal.present();
|
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
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: AskModalPage,
|
|
|
|
|
cssClass: 'discart-expedient-modal',
|
|
|
|
|
backdropDismiss: true,
|
|
|
|
|
componentProps: {
|
|
|
|
|
title: 'Deseja arquivar este acção?',
|
|
|
|
|
description: 'Nota: Ao Efetuar esta operação, o tratamento deste acção não poderá ser realizado a partir da lista de acções'
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then((res) => {
|
|
|
|
|
if(res.data == 'Yes') {
|
|
|
|
|
const loader = this.toastService.loading();
|
|
|
|
|
try {
|
|
|
|
|
this.publications.DeletePresidentialAction(folderId).toPromise();
|
|
|
|
|
this.httpErrorHandle.httpsSucessMessagge('Eliminar Acção')
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
loader.remove()
|
|
|
|
|
}
|
|
|
|
|
this.close();
|
|
|
|
|
this.getActions.emit();
|
|
|
|
|
}
|
|
|
|
|
// Do nothing
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
2021-03-15 16:47:16 +01:00
|
|
|
|
2023-08-11 16:38:23 +01:00
|
|
|
}
|
2021-03-15 16:47:16 +01:00
|
|
|
|
2023-08-24 22:15:56 +01:00
|
|
|
async viewPublicationDetail(DocumentId:string, ProcessId: string) {
|
2021-08-24 11:15:13 +01:00
|
|
|
|
2023-08-24 22:15:56 +01:00
|
|
|
this.openPublicationDetails.emit({DocumentId, ProcessId});
|
2021-03-15 16:47:16 +01:00
|
|
|
|
2021-03-12 14:38:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|