Files
doneit-web/src/app/shared/publication/view-publications/view-publications.page.ts
T
2026-03-18 14:37:45 +01:00

347 lines
9.8 KiB
TypeScript

import { Component, OnInit, Input, Output, EventEmitter, ViewChild, ViewChildren, QueryList, ElementRef } from '@angular/core';
import { IonicSlides, ModalController } from '@ionic/angular';
import { PublicationFolder } from 'src/app/models/publicationfolder';
import { PublicationsService } from 'src/app/services/publications.service';
import { NewPublicationPage } from 'src/app/pages/publications/new-publication/new-publication.page';
import { PublicationPipe } from 'src/app/pipes/publication.pipe';
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';
import { PermissionService } from 'src/app/services/permission.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
import { AskModalPage } from 'src/app/modals/ask-modal/ask-modal.page';
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { StopvideoService } from "src/app/services/stopvideo.service";
import { PublicationHolderService } from 'src/app/services/publication/publication-holder.service'
import { HttpService } from 'src/app/infra/http/http.service';
import { environment } from 'src/environments/environment';
import { PublicationRemoteRepositoryService } from 'src/app/module/actions/data/repository/publication-remote-repository.service';
@Component({
selector: 'app-view-publications',
templateUrl: './view-publications.page.html',
styleUrls: ['./view-publications.page.scss'],
})
export class ViewPublicationsPage implements OnInit {
showLoader: boolean;
loading: any;
error: any;
oldpublicationIds = []
swiperConfig = {
spaceBetween: 10,
navigation: true,
}
swiperThumbsConfig = {
spaceBetween: 10,
slidesPerView: 4,
freeMode: true,
watchSlidesProgress: true,
}
@Input() folderId: any;
@Output() addNewPublication = new EventEmitter<any>();
@Output() editPublication = new EventEmitter<any>();
@Output() openPublicationDetails = new EventEmitter<any>();
@Output() goBackToViewPublications = new EventEmitter();
@Output() closeDesktopComponent = new EventEmitter<any>();
@Output() goBacktoPublicationDetails = new EventEmitter<any>();
@Output() getActions = new EventEmitter<any>();
publicationPipe = new PublicationPipe()
swiperModules = [IonicSlides];
@ViewChild('myVideo') myVideo: any;
@ViewChild('VideoManager') VideoManager;
@ViewChildren('videoElement') videoElements: QueryList<ElementRef>;
public lastScrollTop = 0;
public isHidden = false;
constructor(
private modalController: ModalController,
private publications: PublicationsService,
public ThemeService: ThemeService,
private toastService: ToastService,
private storage: Storage,
public p: PermissionService,
private httpErrorHandle: HttpErrorHandle,
public publicationFolderService: PublicationFolderService,
public checkFileType: checkFileTypeService,
public StopvideoService: StopvideoService,
public PublicationHolderService: PublicationHolderService,
private http: HttpService,
private publicationRemoteRepository: PublicationRemoteRepositoryService
) {
this.createPublicationList()
}
isUploadingPublicationById(publicationId: string) {
return this.publicationRemoteRepository.isUpdatingPublication(publicationId, this.folderId);
}
isFechingFilesPublicationById(publicationId: string) {
return this.publicationRemoteRepository.isFechingFilesPublication(publicationId);
}
onVisibilityChange = (e: boolean) => {
if(!e) {
/* this.stopVideo() */
}
}
ngOnInit() {
if (typeof (this.folderId) == 'object') {
this.folderId = this.folderId['ProcessId']
}
this.createPublicationList()
window['app-view-publications-page-doRefresh'] = this.doRefresh
window['_deletePublication'] = (a, b) => {
this._deletePublication(a, b)
}
this.getFromDB();
}
ngOnChanges(changes: any): void {
if (typeof (this.folderId) == 'object') {
this.folderId = this.folderId['ProcessId']
}
if (!this.publicationFolderService.publicationList[this.folderId]) {
this.publicationFolderService.FolderDetails[this.folderId] = new PublicationFolder();
}
this.publicationFolderService.loadPublications(this.folderId);
this.createPublicationList()
this.getFromDB();
this.getPublicationDetail();
this.getPublicationsIds();
this.stopVideo();
}
createPublicationList(folderId = this.folderId) {
if (!this.publicationFolderService.publicationList[this.folderId]) {
this.publicationFolderService.publicationList[this.folderId] = []
}
if (!this.publicationFolderService.FolderDetails[this.folderId]) {
this.publicationFolderService.FolderDetails[this.folderId] = new PublicationFolder();
}
}
doRefresh = (event) => {
this.publicationFolderService.loadPublications(this.folderId);
this.getPublicationDetail();
this.getPublicationsIds();
}
close() {
this.closeDesktopComponent.emit();
}
getPublicationDetail() {
const folderId = this.folderId
this.publications.GetPresidentialAction(folderId).subscribe(res => {
// PublicationDetailsModel.create(res)
this.publicationFolderService.FolderDetails[folderId] = res
this.storage.set(folderId + "name", res)
}, (error) => {
this.showLoader = false;
// this.httpErroHandle.httpStatusHandle(error)
});
}
async getPublicationsIds() {
this.showLoader = true;
const folderId = this.folderId
this.showLoader = false;
}
_deletePublication = (folderId, publicationId) => {
this.publicationFolderService.publicationList[folderId] = this.publicationFolderService.publicationList[folderId].filter(e => e.DocumentId != publicationId)
}
getFromDB() {
const folderId = this.folderId
this.publicationFolderService.getFromDB(folderId)
}
async AddPublication(publicationType: any, folderId: any) {
if(this.PublicationHolderService.PublicationFormMV.length == 0) {
if (window.innerWidth < 701) {
const modal = await this.modalController.create({
component: NewPublicationPage,
componentProps: {
publicationType: publicationType,
folderId: folderId,
},
cssClass: 'new-publication modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
this.doRefresh(event);
});
await modal.present();
} else {
this.addNewPublication.emit({
publicationType: publicationType,
folderId: folderId
})
}
} else {
this.toastService._successMessage('já existe uma publicação a ser processado');
}
}
async openEditPublication(folderId?: any) {
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(() => {
// Do nothing
});
await modal.present();
}
else {
this.editPublication.emit(folderId);
}
}
async deletePublication(folderId?: any) {
const modal = await this.modalController.create({
component: AskModalPage,
cssClass: 'discart-expedient-modal',
backdropDismiss: true,
componentProps: {
title: 'Deseja eliminar 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(async (res) => {
if (res.data == 'Yes') {
const loader = this.toastService.loading();
try {
await this.publications.DeletePresidentialAction(folderId).toPromise();
this.httpErrorHandle.httpsSucessMessagge('Eliminar Acção')
window['updateAction']()
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
this.close();
this.getActions.emit();
}
// Do nothing
});
await modal.present();
}
async viewPublicationDetail(DocumentId: string, ProcessId: string) {
this.stopVideo();
setTimeout(()=> {
this.openPublicationDetails.emit({ DocumentId, ProcessId });
}, 200)
}
preventVideoPlay(event: Event): void {
// Prevent the default behavior of the click event (which is to play the video)
event.preventDefault();
// You may also want to stop the propagation of the event to prevent any parent click handlers
// event.stopPropagation();
// Optionally, you can add additional logic here
const videoElement: HTMLVideoElement = event.target as HTMLVideoElement;
videoElement.pause()
}
stopVideo() {
try {
var videos = document.querySelectorAll('video');
// Pause each video
videos.forEach(function (video) {
video.pause();
})
try {
this.videoElements.forEach(videoElement => {
// You can access the native HTML video element using videoElement.nativeElement
const video: HTMLVideoElement = videoElement.nativeElement;
video.pause()
// Do something with each video element
// console.log(video);
});
} catch (e) {
}
} catch (error) {
}
}
public onScroll(event): void {
if(this.lastScrollTop < event.detail.scrollTop) {
// console.log("scrolling down")
} else {
// console.log("scrolling up")
}
this.lastScrollTop = event.detail.scrollTop;
}
}