Files
doneit-web/src/app/shared/publication/view-publications/view-publications.page.ts
T

260 lines
6.8 KiB
TypeScript
Raw Normal View History

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'
import { ToastService } from 'src/app/services/toast.service';
import { EditActionPage } from 'src/app/pages/publications/edit-action/edit-action.page';
import { Storage } from '@ionic/storage';
2022-03-30 16:32:56 +01:00
import { PermissionService } from 'src/app/services/permission.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;
publicationList: Publication[];
item: PublicationFolder;
getpublication = [];
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>();
@Output() editPublication = new EventEmitter<any>();
2021-03-15 16:47:16 +01:00
@Output() openPublicationDetails= new EventEmitter<any>();
@Output() goBackToViewPublications = new EventEmitter();
@Output() closeDesktopComponent = new EventEmitter<any>();
@Output() goBacktoPublicationDetails = new EventEmitter<any>();
@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,
public ThemeService: ThemeService,
private toastService: ToastService,
2022-03-30 16:32:56 +01:00
private storage: Storage,
public p:PermissionService,
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
2022-06-08 13:02:43 +01:00
//this.getPublicationsIds();
2021-08-25 15:23:30 +01:00
window['app-view-publications-page-doRefresh'] = this.doRefresh
2022-06-08 13:02:43 +01:00
this.getPublicationDetail();
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']
}
2022-04-28 09:32:27 +01:00
2021-07-15 17:42:12 +01:00
//setTimeout(()=>{
2021-07-21 20:26:41 +01:00
this.getPublicationDetail();
2022-02-16 10:59:45 +01:00
this.getPublicationsIds();
2022-03-30 16:32:56 +01:00
//}, 100)
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) => {
2022-02-16 10:59:45 +01:00
this.getPublicationsIds();
2021-03-12 14:38:55 +01:00
setTimeout(() => {
this.getPublicationDetail();
}, 3000);
}
2021-07-21 19:08:31 +01:00
2021-07-21 20:26:41 +01:00
close() {
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=>{
2022-04-28 09:32:27 +01:00
2021-12-14 23:13:21 +01:00
this.item = res;
});
2021-03-12 14:38:55 +01:00
}
2021-06-29 14:16:49 +01:00
getPublicationsIds() {
this.showLoader = true;
const folderId = this.folderId
2022-02-16 10:59:45 +01:00
//this.getFromDB()
this.publications.GetPublicationsImages(this.folderId).subscribe(res => {
2022-04-28 09:32:27 +01:00
this.publicationList = new Array();
2022-02-16 10:59:45 +01:00
/* for(let i = 0; i < res.length; i++) {
this.publications.GetPublicationById(res[i]).subscribe(ress => {
2022-04-28 09:32:27 +01:00
let item: Publication = this.publicationPipe.itemList(ress)
2022-04-28 09:32:27 +01:00
this.publicationList.push(item);
})
2022-02-16 10:59:45 +01:00
} */
2022-02-16 10:59:45 +01:00
res.forEach(element => {
2022-04-28 09:32:27 +01:00
this.publications.GetPublicationById(element).subscribe(ress => {
2022-04-28 09:32:27 +01:00
let item: Publication = this.publicationPipe.itemList(ress)
2022-04-28 09:32:27 +01:00
this.publicationList.push(item);
})
2022-02-16 10:59:45 +01:00
});
2022-04-28 09:32:27 +01:00
this.storage.remove('view_publications');
this.storage.set('view_publications', this.publicationList);
2022-04-28 09:32:27 +01:00
this.getpublication = this.publicationList;
this.showLoader = false;
2022-02-16 10:59:45 +01:00
},() => {
this.getFromDB();
});
}
getFromDB() {
this.storage.get('view_publications').then((viewPublications) => {
2022-02-18 15:28:30 +01:00
this.publicationList = viewPublications;
})
}
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();
2022-02-16 10:59:45 +01:00
//this.getFromDB();
this.publications.GetPublications(folderId).subscribe(async 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
await this.storage.remove('view_publications');
await this.storage.set('view_publications', this.publicationList);
//this.getFromDB();
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!';
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
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,
},
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 openEditPublication(folderId?:any){
2022-06-09 10:24:50 +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
});
}
2022-06-06 15:28:27 +01:00
else {
this.editPublication.emit(folderId);
}
}
2022-06-06 15:28:27 +01:00
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()
}
this.close();
this.getActions.emit();
}
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
}
}