mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
286 lines
7.4 KiB
TypeScript
286 lines
7.4 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { Publication } from 'src/app/models/publication';
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
|
import { PublicationPipe } from 'src/app/pipes/publication.pipe';
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
|
import { NewPublicationPage } from '../new-publication/new-publication.page';
|
|
import { PublicationDetailPage } from './publication-detail/publication-detail.page';
|
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
|
import { BackgroundService } from 'src/app/services/background.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { forkJoin } from 'rxjs';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { PermissionService } from 'src/app/services/permission.service';
|
|
|
|
@Component({
|
|
selector: 'app-view-publications',
|
|
templateUrl: './view-publications.page.html',
|
|
styleUrls: ['./view-publications.page.scss'],
|
|
})
|
|
export class ViewPublicationsPage implements OnInit {
|
|
showLoader = true;
|
|
loading: any;
|
|
|
|
publicationList: Publication[] = new Array();
|
|
item: PublicationFolder;
|
|
defaultImage = "/assets/icon/icon-no-image.svg";
|
|
folderId: string;
|
|
id: string;
|
|
error: any;
|
|
|
|
publicationPipe = new PublicationPipe()
|
|
publicationDitails: any;
|
|
getpublication = [];
|
|
|
|
|
|
constructor(
|
|
private modalController: ModalController,
|
|
private publications: PublicationsService,
|
|
private activatedRoute: ActivatedRoute,
|
|
private router: Router,
|
|
private sqliteservice: SqliteService,
|
|
private backgroundservice: BackgroundService,
|
|
public ThemeService: ThemeService,
|
|
private toastService: ToastService,
|
|
public p: PermissionService,) {
|
|
|
|
this.item = new PublicationFolder();
|
|
this.activatedRoute.paramMap.subscribe(params => {
|
|
|
|
|
|
if (params["params"]) {
|
|
this.folderId = params["params"].folderId;
|
|
//
|
|
}
|
|
|
|
window['app-view-publications-page-doRefresh'] = this.doRefresh
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
if (typeof (this.folderId) == 'object') {
|
|
this.folderId = this.folderId['ProcessId']
|
|
}
|
|
//this.testForkJoin()
|
|
this.getPublicationDetail();
|
|
this.getPublicationsIds();
|
|
/* setTimeout(() => {
|
|
this.getPublications();
|
|
}, 1000); */
|
|
|
|
this.backgroundservice.registerBackService('Online', () => {
|
|
this.getPublicationDetail();
|
|
//this.testForkJoin()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ngOnChanges() {
|
|
|
|
if (typeof (this.folderId) == 'object') {
|
|
this.folderId = this.folderId['ProcessId']
|
|
}
|
|
|
|
// if (typeof (this.id == 'object') {
|
|
// this.id = this.id['ProcessId']
|
|
// }
|
|
//this.testForkJoin()
|
|
//this.getPublicationDetail();
|
|
// this.getPublications();
|
|
}
|
|
|
|
doRefresh = (event) => {
|
|
//setTimeout(() => {
|
|
//this.testForkJoin()
|
|
this.getPublicationDetail();
|
|
this.getPublicationsIds();
|
|
event.target.complete();
|
|
//}, 3000);
|
|
|
|
}
|
|
|
|
close() {
|
|
this.modalController.dismiss();
|
|
this.router.navigate(['/home/publications']);
|
|
}
|
|
|
|
goBack() {
|
|
this.router.navigate(['/home/publications']);
|
|
}
|
|
|
|
getPublicationDetail() {
|
|
this.publications.GetPresidentialAction(this.folderId).subscribe(res => {
|
|
|
|
this.item = res;
|
|
this.sqliteservice.updatePublicationsDetails(this.folderId, JSON.stringify(res));
|
|
});
|
|
}
|
|
|
|
// goes to fork
|
|
// getPublicationsIds() {
|
|
|
|
// this.showLoader = true;
|
|
// const folderId = this.folderId
|
|
|
|
// this.publications.GetIdsPublicationsImages(this.id).subscribe(res => {
|
|
|
|
//
|
|
|
|
// this.publicationList = new Array();
|
|
|
|
getPublicationsIds() {
|
|
|
|
this.showLoader = true;
|
|
const folderId = this.folderId
|
|
this.publications.GetPublicationsImages(this.folderId).subscribe(res => {
|
|
|
|
|
|
this.publicationList = new Array();
|
|
|
|
res.forEach(element => {
|
|
|
|
this.publications.GetPublicationById(element).subscribe(ress => {
|
|
|
|
let item: Publication = this.publicationPipe.itemList(ress)
|
|
|
|
this.publicationList.push(item);
|
|
})
|
|
|
|
});
|
|
|
|
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
|
|
|
|
|
this.getpublication = this.publicationList;
|
|
this.showLoader = false;
|
|
|
|
}, (error) => {
|
|
this.getFromDB()
|
|
});
|
|
}
|
|
|
|
getPublications() {
|
|
|
|
this.showLoader = true;
|
|
const folderId = this.folderId
|
|
this.getFromDB();
|
|
this.publications.GetPublications(this.folderId).subscribe(res => {
|
|
|
|
|
|
|
|
this.publicationList = new Array();
|
|
|
|
res.forEach(element => {
|
|
|
|
let item: Publication = this.publicationPipe.itemList(element)
|
|
this.publicationList.push(item);
|
|
|
|
|
|
});
|
|
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
|
|
|
this.getpublication = this.publicationList;
|
|
|
|
this.showLoader = false;
|
|
}, (error) => {
|
|
|
|
if (error.status == '0') {
|
|
this.getFromDB();
|
|
}
|
|
if (error.status == '404') {
|
|
this.error = 'Sem publicações disponíveis!';
|
|
this.publicationList = [];
|
|
}
|
|
this.showLoader = false;
|
|
});
|
|
}
|
|
|
|
testForkJoin() {
|
|
forkJoin([
|
|
this.getPublicationsIds(),
|
|
this.getPublications(),
|
|
|
|
|
|
]).subscribe(allResults => {
|
|
this.publicationList = allResults[2]
|
|
})
|
|
}
|
|
|
|
getFromDB() {
|
|
|
|
this.sqliteservice.getActionById(this.folderId).then((publications) => {
|
|
|
|
this.item = this.isJson(publications[0].publicationsDetails);
|
|
|
|
let publicationArray = [];
|
|
this.isJson(publications[0].publications).forEach(element => {
|
|
let publicationlis = {
|
|
DateIndex: element.DateIndex,
|
|
DatePublication: element.DatePublication,
|
|
DocumentId: element.DocumentId,
|
|
FileBase64: element.FileBase64,
|
|
FileExtension: element.FileExtension,
|
|
Message: element.Message,
|
|
OrganicEntityId: element.OrganicEntityId,
|
|
OriginalFileName: element.OriginalFileName,
|
|
ProcessId: element.ProcessId
|
|
}
|
|
publicationArray.push(publicationlis);
|
|
|
|
});
|
|
|
|
this.publicationList = publicationArray;
|
|
})
|
|
}
|
|
|
|
isJson(str) {
|
|
try {
|
|
JSON.parse(str);
|
|
} catch (e) {
|
|
return str;
|
|
}
|
|
return JSON.parse(str);
|
|
}
|
|
|
|
async AddPublication(publicationType: any, folderId: any) {
|
|
const modal = await this.modalController.create({
|
|
component: NewPublicationPage,
|
|
componentProps: {
|
|
publicationType: publicationType,
|
|
folderId: this.folderId,
|
|
},
|
|
cssClass: 'new-publication modal modal-desktop',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then(() => {
|
|
this.doRefresh(event);
|
|
});
|
|
}
|
|
|
|
goToPublicationDetail(publicationId: string) {
|
|
this.router.navigate(['/home/publications/view-publications', this.folderId, publicationId]);
|
|
}
|
|
|
|
async viewPublicationDetail(publicationId: string) {
|
|
const modal = await this.modalController.create({
|
|
component: PublicationDetailPage,
|
|
componentProps: {
|
|
publicationId: publicationId,
|
|
folderId: this.folderId,
|
|
},
|
|
cssClass: 'publication-detail modal modal-desktop',
|
|
// backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then(() => {
|
|
this.getPublicationsIds();
|
|
});
|
|
}
|
|
|
|
}
|