2020-12-01 14:03:15 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-06-18 11:01:02 +01:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
|
import { ModalController } from '@ionic/angular';
|
2020-12-09 12:10:19 +01:00
|
|
|
import { Publication } from 'src/app/models/publication';
|
|
|
|
|
import { PublicationFolder } from 'src/app/models/publicationfolder';
|
2021-08-23 11:30:42 +01:00
|
|
|
import { PublicationPipe } from 'src/app/pipes/publication.pipe';
|
2020-12-09 12:10:19 +01:00
|
|
|
import { PublicationsService } from 'src/app/services/publications.service';
|
2021-07-21 20:26:41 +01:00
|
|
|
import { PublicationEventFolderStorage } from 'src/app/store/publication-event-folder.service';
|
|
|
|
|
import { PublicationListStorage } from 'src/app/store/publication-list.service';
|
2021-07-21 19:08:31 +01:00
|
|
|
import { PublicationTravelFolderStore } from 'src/app/store/publication-travel-folder.service';
|
2020-12-01 17:22:45 +01:00
|
|
|
import { NewPublicationPage } from '../new-publication/new-publication.page';
|
2020-12-09 12:10:19 +01:00
|
|
|
import { PublicationDetailPage } from './publication-detail/publication-detail.page';
|
2021-10-09 09:15:22 +01:00
|
|
|
import { SqliteService } from 'src/app/services/sqlite.service';
|
2021-10-19 09:41:06 +01:00
|
|
|
import { BackgroundService } from 'src/app/services/background.service';
|
2021-10-25 13:54:34 +01:00
|
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
2021-11-29 15:48:35 +01:00
|
|
|
import { forkJoin } from 'rxjs';
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-view-publications',
|
|
|
|
|
templateUrl: './view-publications.page.html',
|
|
|
|
|
styleUrls: ['./view-publications.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class ViewPublicationsPage implements OnInit {
|
2021-07-15 16:07:55 +01:00
|
|
|
showLoader = true;
|
2020-12-15 19:37:42 +01:00
|
|
|
loading: any;
|
2020-12-11 15:09:53 +01:00
|
|
|
|
2021-07-22 16:18:49 +01:00
|
|
|
publicationList: Publication[] = new Array();
|
2020-12-09 12:10:19 +01:00
|
|
|
item: PublicationFolder;
|
2021-11-29 15:48:35 +01:00
|
|
|
defaultImage = "https://governo.gov.ao/ao/noticias/presidente-joao-lourenco-ouviu-a-voz-da-igreja/"
|
2021-10-11 17:22:01 +01:00
|
|
|
folderId: string;
|
2021-11-29 15:48:35 +01:00
|
|
|
id: string;
|
2021-07-15 11:53:16 +01:00
|
|
|
error: any;
|
2020-12-01 14:03:15 +01:00
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
publicationListStorage = PublicationListStorage
|
|
|
|
|
//
|
|
|
|
|
publicationEventFolderStorage = PublicationEventFolderStorage
|
|
|
|
|
publicationTravelFolderService = PublicationTravelFolderStore
|
2021-07-22 14:36:29 +01:00
|
|
|
|
2021-08-23 11:48:44 +01:00
|
|
|
publicationPipe = new PublicationPipe()
|
2021-10-11 17:22:01 +01:00
|
|
|
publicationDitails: any;
|
|
|
|
|
getpublication = [];
|
|
|
|
|
|
2021-08-23 11:48:44 +01:00
|
|
|
|
2021-07-22 11:12:55 +01:00
|
|
|
constructor(
|
2020-12-09 12:10:19 +01:00
|
|
|
private modalController: ModalController,
|
|
|
|
|
private publications: PublicationsService,
|
2021-06-18 11:01:02 +01:00
|
|
|
private activatedRoute: ActivatedRoute,
|
2021-10-09 09:15:22 +01:00
|
|
|
private router: Router,
|
2021-10-19 09:41:06 +01:00
|
|
|
private sqliteservice: SqliteService,
|
2021-10-25 13:54:34 +01:00
|
|
|
private backgroundservice: BackgroundService,
|
|
|
|
|
public ThemeService: ThemeService) {
|
2021-07-15 17:15:04 +01:00
|
|
|
|
2021-07-21 19:08:31 +01:00
|
|
|
this.item = new PublicationFolder();
|
|
|
|
|
this.activatedRoute.paramMap.subscribe(params => {
|
|
|
|
|
console.log(params);
|
2021-07-22 14:36:29 +01:00
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
if (params["params"]) {
|
2021-07-21 19:08:31 +01:00
|
|
|
this.folderId = params["params"].folderId;
|
2021-08-31 16:32:16 +01:00
|
|
|
// console.log(params["params"]);
|
2021-07-21 19:08:31 +01:00
|
|
|
}
|
2021-07-22 11:12:55 +01:00
|
|
|
|
2021-08-25 15:23:30 +01:00
|
|
|
window['app-view-publications-page-doRefresh'] = this.doRefresh
|
2021-07-21 19:08:31 +01:00
|
|
|
});
|
|
|
|
|
}
|
2020-12-01 14:03:15 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-07-15 17:15:04 +01:00
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
if (typeof (this.folderId) == 'object') {
|
2021-07-15 17:15:04 +01:00
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
2022-01-28 19:02:44 +01:00
|
|
|
//this.testForkJoin()
|
2021-10-19 09:41:06 +01:00
|
|
|
this.getPublicationDetail();
|
2022-01-30 10:45:27 +01:00
|
|
|
this.getPublicationsIds();
|
|
|
|
|
/* setTimeout(() => {
|
2021-11-29 17:15:15 +01:00
|
|
|
this.getPublicationsIds();
|
2022-01-30 10:45:27 +01:00
|
|
|
}, 1000); */
|
2021-10-19 09:41:06 +01:00
|
|
|
|
2021-11-29 17:15:15 +01:00
|
|
|
this.backgroundservice.registerBackService('Online', () => {
|
2021-10-19 09:41:06 +01:00
|
|
|
this.getPublicationDetail();
|
2022-01-28 19:02:44 +01:00
|
|
|
//this.testForkJoin()
|
2021-10-19 09:41:06 +01:00
|
|
|
|
|
|
|
|
})
|
2021-08-23 11:30:42 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
2021-06-21 08:27:57 +01:00
|
|
|
|
2021-07-15 17:42:12 +01:00
|
|
|
ngOnChanges() {
|
|
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
if (typeof (this.folderId) == 'object') {
|
2021-07-15 17:42:12 +01:00
|
|
|
this.folderId = this.folderId['ProcessId']
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 15:48:35 +01:00
|
|
|
// if (typeof (this.id == 'object') {
|
|
|
|
|
// this.id = this.id['ProcessId']
|
|
|
|
|
// }
|
2022-01-28 19:02:44 +01:00
|
|
|
//this.testForkJoin()
|
2022-01-30 10:45:27 +01:00
|
|
|
//this.getPublicationDetail();
|
2021-11-30 17:56:56 +01:00
|
|
|
// this.getPublicationsIds();
|
2021-07-15 17:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
doRefresh = (event) => {
|
2022-02-07 12:56:35 +01:00
|
|
|
//setTimeout(() => {
|
2022-01-28 19:02:44 +01:00
|
|
|
//this.testForkJoin()
|
2021-02-03 15:13:23 +01:00
|
|
|
this.getPublicationDetail();
|
2022-01-28 19:02:44 +01:00
|
|
|
this.getPublicationsIds();
|
2020-12-17 10:59:11 +01:00
|
|
|
event.target.complete();
|
2022-02-07 12:56:35 +01:00
|
|
|
//}, 3000);
|
2021-07-15 16:07:55 +01:00
|
|
|
|
2020-12-11 15:09:53 +01:00
|
|
|
}
|
2021-06-21 08:27:57 +01:00
|
|
|
|
|
|
|
|
close() {
|
2020-12-09 12:10:19 +01:00
|
|
|
this.modalController.dismiss();
|
2021-07-15 16:08:05 +01:00
|
|
|
this.router.navigate(['/home/publications']);
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
2021-06-21 08:27:57 +01:00
|
|
|
|
|
|
|
|
goBack() {
|
2021-06-18 11:01:02 +01:00
|
|
|
this.router.navigate(['/home/publications']);
|
|
|
|
|
}
|
2021-06-21 08:27:57 +01:00
|
|
|
|
2021-07-15 16:07:55 +01:00
|
|
|
getPublicationDetail() {
|
2022-01-28 19:02:44 +01:00
|
|
|
this.publications.GetPresidentialAction(this.folderId).subscribe(res => {
|
2021-12-07 17:25:09 +01:00
|
|
|
console.log(res);
|
|
|
|
|
this.item = res;
|
2022-01-30 10:45:27 +01:00
|
|
|
this.sqliteservice.updatePublicationsDetails(this.folderId, JSON.stringify(res));
|
2021-12-07 17:25:09 +01:00
|
|
|
});
|
2021-02-03 15:13:23 +01:00
|
|
|
}
|
2021-12-07 17:25:09 +01:00
|
|
|
|
2022-01-28 19:02:44 +01:00
|
|
|
// goes to fork
|
2021-11-30 17:56:56 +01:00
|
|
|
// getPublicationsIds() {
|
2021-11-29 15:48:35 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
// this.showLoader = true;
|
|
|
|
|
// const folderId = this.folderId
|
2021-11-29 15:48:35 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
// this.publications.GetIdsPublicationsImages(this.id).subscribe(res => {
|
2021-11-29 15:48:35 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
// console.log(this.id)
|
2021-11-29 15:48:35 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
// this.publicationList = new Array();
|
2021-07-22 14:36:29 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
getPublicationsIds() {
|
2021-11-29 17:15:15 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
this.showLoader = true;
|
|
|
|
|
const folderId = this.folderId
|
2022-01-28 19:02:44 +01:00
|
|
|
this.getFromDB()
|
2021-11-30 17:56:56 +01:00
|
|
|
this.publications.GetPublicationsImages(this.folderId).subscribe(res => {
|
2021-11-29 17:15:15 +01:00
|
|
|
|
2021-11-30 17:56:56 +01:00
|
|
|
console.log('publications ids', res)
|
|
|
|
|
this.publicationList = new Array();
|
2021-11-29 17:15:15 +01:00
|
|
|
|
2022-01-30 10:45:27 +01:00
|
|
|
for(let i = 0; i < res.length; i++) {
|
|
|
|
|
this.publications.GetPublicationById(res[i]).subscribe(ress => {
|
2022-01-28 19:02:44 +01:00
|
|
|
console.log('publications by ids', ress)
|
|
|
|
|
let item: Publication = this.publicationPipe.itemList(ress)
|
|
|
|
|
console.log('publications by ids 2', item)
|
|
|
|
|
this.publicationList.push(item);
|
|
|
|
|
})
|
2022-01-30 10:45:27 +01:00
|
|
|
}
|
2021-11-29 17:15:15 +01:00
|
|
|
|
2022-01-30 10:45:27 +01:00
|
|
|
/* res.forEach(element => {
|
2021-11-29 17:15:15 +01:00
|
|
|
console.log('publications elements', element)
|
|
|
|
|
this.publications.GetPublicationById(element).subscribe(ress => {
|
|
|
|
|
console.log('publications by ids', ress)
|
|
|
|
|
let item: Publication = this.publicationPipe.itemList(ress)
|
|
|
|
|
console.log('publications by ids 2', item)
|
|
|
|
|
this.publicationList.push(ress);
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-30 10:45:27 +01:00
|
|
|
}); */
|
|
|
|
|
console.log('PUBLICATIONS IMAGEs',this.publicationList)
|
2021-11-29 17:15:15 +01:00
|
|
|
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
2022-01-30 10:45:27 +01:00
|
|
|
console.log('PUBLICATIONS IMAGEs',this.publicationList)
|
2021-11-29 17:15:15 +01:00
|
|
|
|
|
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
|
|
|
|
this.getpublication = this.publicationList;
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
|
|
|
|
|
/* this.publicationList = new Array();
|
2021-12-07 17:25:09 +01:00
|
|
|
|
2021-11-29 17:15:15 +01:00
|
|
|
res.forEach(element => {
|
|
|
|
|
console.log('getPublications', element)
|
|
|
|
|
let item: Publication = this.publicationPipe.itemList(element)
|
|
|
|
|
this.publicationList.push(item);
|
|
|
|
|
});
|
|
|
|
|
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
2021-12-07 17:25:09 +01:00
|
|
|
|
2021-11-29 17:15:15 +01:00
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
|
|
|
|
this.getpublication = this.publicationList; */
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 16:07:55 +01:00
|
|
|
getPublications() {
|
2021-11-19 14:56:29 +01:00
|
|
|
|
2020-12-15 19:37:42 +01:00
|
|
|
this.showLoader = true;
|
2021-07-21 20:26:41 +01:00
|
|
|
const folderId = this.folderId
|
2022-01-28 19:02:44 +01:00
|
|
|
this.getFromDB();
|
2021-10-11 17:22:01 +01:00
|
|
|
this.publications.GetPublications(this.folderId).subscribe(res => {
|
2021-11-19 14:58:17 +01:00
|
|
|
|
2021-10-09 09:15:22 +01:00
|
|
|
console.log(this.folderId)
|
2021-07-22 14:36:29 +01:00
|
|
|
|
2021-08-23 11:30:42 +01:00
|
|
|
this.publicationList = new Array();
|
2021-08-24 16:48:33 +01:00
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
res.forEach(element => {
|
2021-10-11 17:22:01 +01:00
|
|
|
console.log('getPublications', element)
|
2021-08-23 11:30:42 +01:00
|
|
|
let item: Publication = this.publicationPipe.itemList(element)
|
2021-07-22 16:18:49 +01:00
|
|
|
this.publicationList.push(item);
|
2021-11-29 17:15:15 +01:00
|
|
|
console.log('getPublications 222', item)
|
|
|
|
|
|
2020-12-09 12:10:19 +01:00
|
|
|
});
|
2021-10-11 17:22:01 +01:00
|
|
|
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
|
|
|
|
|
2021-07-21 20:26:41 +01:00
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
2021-10-11 17:22:01 +01:00
|
|
|
this.getpublication = this.publicationList;
|
2021-07-21 19:08:31 +01:00
|
|
|
|
2020-12-15 19:37:42 +01:00
|
|
|
this.showLoader = false;
|
2021-11-19 14:56:29 +01:00
|
|
|
}, (error) => {
|
2021-07-22 14:36:29 +01:00
|
|
|
|
2021-11-29 17:15:15 +01:00
|
|
|
if (error.status == '0') {
|
2021-11-19 14:56:29 +01:00
|
|
|
this.getFromDB();
|
|
|
|
|
}
|
|
|
|
|
if (error.status == '404') {
|
|
|
|
|
this.error = 'Sem publicações disponíveis!';
|
|
|
|
|
this.publicationList = [];
|
|
|
|
|
this.publicationListStorage.add(folderId, this.publicationList)
|
|
|
|
|
}
|
|
|
|
|
this.showLoader = false;
|
|
|
|
|
});
|
2020-12-01 14:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-28 19:02:44 +01:00
|
|
|
testForkJoin() {
|
2021-11-29 15:48:35 +01:00
|
|
|
forkJoin([
|
2021-11-29 16:50:56 +01:00
|
|
|
this.getPublicationsIds(),
|
2021-11-29 15:48:35 +01:00
|
|
|
this.getPublications(),
|
2021-12-07 17:25:09 +01:00
|
|
|
|
|
|
|
|
|
2022-01-28 19:02:44 +01:00
|
|
|
]).subscribe(allResults => {
|
2021-11-29 15:48:35 +01:00
|
|
|
this.publicationList = allResults[2]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 09:15:22 +01:00
|
|
|
getFromDB() {
|
2021-10-19 09:41:06 +01:00
|
|
|
|
|
|
|
|
this.sqliteservice.getActionById(this.folderId).then((publications) => {
|
|
|
|
|
console.log('publications', publications)
|
2022-01-30 10:45:27 +01:00
|
|
|
/* let item = {
|
2021-10-19 09:41:06 +01:00
|
|
|
ActionType: publications[0].ActionType,
|
|
|
|
|
DateBegin: publications[0].DateBegin,
|
|
|
|
|
DateEnd: publications[0].DateEnd,
|
|
|
|
|
Description: publications[0].Description,
|
|
|
|
|
Detail: publications[0].Detail,
|
|
|
|
|
ProcessId: publications[0].ProcessId
|
|
|
|
|
}
|
2022-01-30 10:45:27 +01:00
|
|
|
this.publicationDitails = item; */
|
2022-02-07 12:56:35 +01:00
|
|
|
this.item = this.isJson(publications[0].publicationsDetails);
|
2021-10-19 09:41:06 +01:00
|
|
|
|
|
|
|
|
let publicationArray = [];
|
2022-02-07 12:56:35 +01:00
|
|
|
this.isJson(publications[0].publications).forEach(element => {
|
2021-10-19 09:41:06 +01:00
|
|
|
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
|
2021-10-11 17:22:01 +01:00
|
|
|
}
|
2021-10-19 09:41:06 +01:00
|
|
|
publicationArray.push(publicationlis);
|
2021-10-11 17:22:01 +01:00
|
|
|
|
2021-10-19 09:41:06 +01:00
|
|
|
});
|
2022-01-30 10:45:27 +01:00
|
|
|
|
2021-10-19 09:41:06 +01:00
|
|
|
this.getpublication = publicationArray;
|
|
|
|
|
})
|
2021-10-09 09:15:22 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-07 12:56:35 +01:00
|
|
|
isJson(str) {
|
|
|
|
|
try {
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse(str);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
async AddPublication(publicationType: any, folderId: any) {
|
2020-12-01 17:22:45 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: NewPublicationPage,
|
2021-10-11 17:22:01 +01:00
|
|
|
componentProps: {
|
2020-12-01 17:22:45 +01:00
|
|
|
publicationType: publicationType,
|
2021-11-09 12:21:23 +01:00
|
|
|
folderId: this.folderId,
|
2020-12-01 17:22:45 +01:00
|
|
|
},
|
2021-04-14 15:27:50 +01:00
|
|
|
cssClass: 'new-publication modal modal-desktop',
|
2020-12-01 17:22:45 +01:00
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
await modal.present();
|
2021-10-11 17:22:01 +01:00
|
|
|
modal.onDidDismiss().then(() => {
|
2020-12-15 19:37:42 +01:00
|
|
|
this.doRefresh(event);
|
|
|
|
|
});
|
2020-12-01 17:22:45 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
goToPublicationDetail(publicationId: string) {
|
2021-06-18 11:59:06 +01:00
|
|
|
this.router.navigate(['/home/publications/view-publications', this.folderId, publicationId]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:22:01 +01:00
|
|
|
async viewPublicationDetail(publicationId: string) {
|
2020-12-09 12:10:19 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: PublicationDetailPage,
|
2021-10-11 17:22:01 +01:00
|
|
|
componentProps: {
|
2020-12-09 12:10:19 +01:00
|
|
|
publicationId: publicationId,
|
2021-04-07 10:20:01 +01:00
|
|
|
folderId: this.folderId,
|
2020-12-09 12:10:19 +01:00
|
|
|
},
|
2021-04-14 15:27:50 +01:00
|
|
|
cssClass: 'publication-detail modal modal-desktop',
|
2021-04-29 19:46:40 +01:00
|
|
|
// backdropDismiss: false
|
2020-12-09 12:10:19 +01:00
|
|
|
});
|
|
|
|
|
await modal.present();
|
2021-10-11 17:22:01 +01:00
|
|
|
modal.onDidDismiss().then(() => {
|
2021-11-29 17:15:15 +01:00
|
|
|
this.getPublicationsIds();
|
2020-12-15 19:37:42 +01:00
|
|
|
});
|
2020-12-09 12:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-01 14:03:15 +01:00
|
|
|
}
|