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

343 lines
10 KiB
TypeScript
Raw Normal View History

2023-11-29 12:17:52 +01:00
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { IonicSlides, 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';
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';
2023-11-29 12:17:52 +01:00
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
2023-12-01 12:16:34 +01:00
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.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;
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;
2023-11-29 12:17:52 +01:00
@Output() addNewPublication = new EventEmitter<any>();
@Output() editPublication = new EventEmitter<any>();
@Output() openPublicationDetails = new EventEmitter<any>();
@Output() goBackToViewPublications = new EventEmitter();
2023-11-29 12:17:52 +01:00
@Output() closeDesktopComponent = new EventEmitter<any>();
@Output() goBacktoPublicationDetails = new EventEmitter<any>();
2023-11-29 12:17:52 +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()
2023-11-29 12:17:52 +01:00
swiperModules = [IonicSlides];
@ViewChild('myVideo') myVideo: any;
2023-12-01 12:16:34 +01:00
@ViewChild('VideoManager') VideoManager;
2023-11-29 12:17:52 +01:00
public lastScrollTop = 0;
public isHidden = false;
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,
2023-11-29 12:17:52 +01:00
public p: PermissionService,
2023-08-11 16:38:23 +01:00
private httpErrorHandle: HttpErrorHandle,
2023-11-29 12:17:52 +01:00
public publicationFolderService: PublicationFolderService,
2023-12-01 12:16:34 +01:00
public checkFileType: checkFileTypeService,
private publicationVideoManagerService: PublicationVideoManagerService
2023-11-29 12:17:52 +01:00
) {
2023-12-01 12:16:34 +01:00
setTimeout(()=> {
// console.log("this.VideoManager", this.VideoManager, document.querySelector('.VideoManager'))
this.publicationVideoManagerService.setContainer(this.VideoManager.nativeElement)
}, 2000)
// this.publicationVideoManagerService.setContainer(this.VideoManager.nativeElement)
2023-11-29 12:17:52 +01:00
this.createPublicationList()
2023-12-01 12:16:34 +01:00
2023-11-29 12:17:52 +01:00
}
2021-03-12 14:38:55 +01:00
2023-12-01 12:16:34 +01:00
onVisibilityChange = (e: boolean) => {
console.log("nice to have", e)
if(!e) {
this.stopVideo()
}
}
2021-03-12 14:38:55 +01:00
ngOnInit() {
2023-11-29 12:17:52 +01:00
if (typeof (this.folderId) == 'object') {
2021-07-15 17:39:19 +01:00
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 {
2023-11-29 12:17:52 +01:00
if (typeof (this.folderId) == 'object') {
2021-07-15 17:42:12 +01:00
this.folderId = this.folderId['ProcessId']
}
2023-02-27 21:24:34 +01:00
2023-11-29 12:17:52 +01:00
if (!this.publicationFolderService.publicationList[this.folderId]) {
2023-08-11 16:38:23 +01:00
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
2023-12-01 12:16:34 +01:00
this.stopVideo();
2021-03-12 14:38:55 +01:00
}
2023-03-10 14:30:50 +01:00
createPublicationList(folderId = this.folderId) {
2023-11-29 12:17:52 +01:00
if (!this.publicationFolderService.publicationList[this.folderId]) {
2023-08-11 16:38:23 +01:00
this.publicationFolderService.publicationList[this.folderId] = []
2023-03-10 14:30:50 +01:00
}
2023-11-29 12:17:52 +01:00
if (!this.publicationFolderService.FolderDetails[this.folderId]) {
2023-08-11 16:38:23 +01:00
this.publicationFolderService.FolderDetails[this.folderId] = new PublicationFolder();
2023-03-10 14:30:50 +01:00
}
}
2023-11-29 12:17:52 +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() {
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
2023-11-29 12:17:52 +01:00
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-11-29 12:17:52 +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() {
this.showLoader = true;
const folderId = this.folderId
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
2023-11-29 12:17:52 +01:00
if (!this.publicationIsPresent(publicationId, folderId)) {
2023-03-10 14:30:50 +01:00
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
2023-11-29 12:17:52 +01:00
for (let publicationId of loadLater) {
2023-03-10 14:30:50 +01:00
await this.loadPublication(publicationId, folderId)
}
2023-08-21 17:36:32 +01:00
2023-11-29 12:17:52 +01:00
for (let localPublication of this.publicationFolderService.publicationList[folderId]) {
2023-08-21 17:36:32 +01:00
const apiPublication = publicationIds.includes(localPublication.DocumentId)
2023-11-29 12:17:52 +01:00
if (!apiPublication) {
2023-08-21 17:36:32 +01:00
this.publicationFolderService.deletePost(folderId, localPublication.DocumentId)
}
}
this.showLoader = false;
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-11-29 12:17:52 +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-11-29 12:17:52 +01:00
this.publicationFolderService.publicationList[folderId] = this.publicationFolderService.publicationList[folderId].filter(e => e.DocumentId != publicationId)
2023-08-10 16:46:55 +01:00
}
2023-03-10 14:30:50 +01:00
publicationIsPresent(publicationId, folderId) {
2023-11-29 12:17:52 +01:00
return this.publicationFolderService.publicationList[folderId].find(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
publicationFind(publicationId, folderId) {
2023-11-29 12:17:52 +01:00
return this.publicationFolderService.publicationList[folderId].find(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
publicationFindIndex(publicationId, folderId) {
2023-11-29 12:17:52 +01:00
return this.publicationFolderService.publicationList[folderId].findIndex(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
async loadPublication(publicationId, folderId) {
2023-11-29 12:17:52 +01:00
let Publication = await this.publications.GetPublicationWithArrayOfFilesById(publicationId).toPromise();
2023-03-10 14:30:50 +01:00
let publicationDetails: Publication = this.publicationPipe.itemList(Publication)
2023-03-10 14:30:50 +01:00
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
2023-11-29 12:17:52 +01:00
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
}
}
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
2023-11-29 12:17:52 +01:00
async AddPublication(publicationType: any, folderId: any) {
2021-03-15 12:06:06 +01:00
2023-11-29 12:17:52 +01:00
if (window.innerWidth < 701) {
2021-03-15 12:06:06 +01:00
const modal = await this.modalController.create({
component: NewPublicationPage,
2023-11-29 12:17:52 +01:00
componentProps: {
2021-03-15 12:06:06 +01:00
publicationType: publicationType,
folderId: folderId,
},
cssClass: 'new-publication modal modal-desktop',
2021-03-15 12:06:06 +01:00
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2023-11-29 12:17:52 +01:00
modal.onDidDismiss().then(() => {
2021-03-15 12:06:06 +01:00
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
}
2023-11-29 12:17:52 +01:00
async openEditPublication(folderId?: any) {
2022-06-09 10:24:50 +01:00
2023-11-29 12:17:52 +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
});
modal.onDidDismiss().then(() => {
2022-06-06 15:28:27 +01:00
// Do nothing
});
2023-07-15 11:01:09 +01:00
await modal.present();
}
2022-06-06 15:28:27 +01:00
else {
this.editPublication.emit(folderId);
}
}
2023-11-29 12:17:52 +01:00
async deletePublication(folderId?: any) {
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?',
2023-10-19 16:51:12 +01:00
/* description: 'Nota: Ao Efetuar esta operação, o tratamento deste acção não poderá ser realizado a partir da lista de acções' */
2023-08-11 16:38:23 +01:00
},
});
modal.onDidDismiss().then((res) => {
2023-11-29 12:17:52 +01:00
if (res.data == 'Yes') {
2023-08-11 16:38:23 +01:00
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-11-29 12:17:52 +01:00
async viewPublicationDetail(DocumentId: string, ProcessId: string) {
2021-08-24 11:15:13 +01:00
2023-11-29 12:17:52 +01:00
this.openPublicationDetails.emit({ DocumentId, ProcessId });
}
stopVideo() {
2023-12-01 12:16:34 +01:00
var videos = document.querySelectorAll('video');
// Pause each video
videos.forEach(function (video) {
video.pause();
})
2023-11-29 12:17:52 +01:00
}
public onScroll(event): void {
if(this.lastScrollTop < event.detail.scrollTop) {
2023-12-01 12:16:34 +01:00
// console.log("scrolling down")
2023-11-29 12:17:52 +01:00
} else {
2023-12-01 12:16:34 +01:00
// console.log("scrolling up")
2023-11-29 12:17:52 +01:00
}
2021-03-15 16:47:16 +01:00
2023-11-29 12:17:52 +01:00
this.lastScrollTop = event.detail.scrollTop;
2021-03-12 14:38:55 +01:00
}
}