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

352 lines
9.9 KiB
TypeScript
Raw Normal View History

2023-12-13 18:19:08 +01:00
import { Component, ElementRef, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
2021-06-18 11:01:02 +01:00
import { ActivatedRoute, Router } from '@angular/router';
2024-02-28 09:51:49 +01:00
import { ModalController, IonicSlides, Platform } from '@ionic/angular';
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';
import { PublicationsService } from 'src/app/services/publications.service';
import { NewPublicationPage } from '../new-publication/new-publication.page';
import { PublicationDetailPage } from './publication-detail/publication-detail.page';
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'
2022-02-18 15:28:30 +01:00
import { ToastService } from 'src/app/services/toast.service';
2022-03-30 16:32:56 +01:00
import { PermissionService } from 'src/app/services/permission.service';
2023-02-27 09:34:36 +01:00
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
2023-02-27 21:24:34 +01:00
import { Storage } from '@ionic/storage';
2023-08-11 16:38:23 +01:00
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
// import { CapacitorVideoPlayer } from 'capacitor-video-player';
2023-11-29 12:17:52 +01:00
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"
2023-12-13 18:19:08 +01:00
import { StopvideoService } from "src/app/services/stopvideo.service"
2024-01-12 12:13:51 +01:00
import { Result } from 'neverthrow';
import { App } from '@capacitor/app';
import { ActiveTabService } from 'src/app/services/active-tab.service';
2024-03-26 12:03:30 +01:00
import { PublicationHolderService } from 'src/app/services/publication/publication-holder.service'
@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
2023-02-27 21:24:34 +01:00
2022-02-18 15:28:30 +01:00
defaultImage = "/assets/icon/icon-no-image.svg";
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;
2023-11-29 12:17:52 +01:00
arrayOfFile: any = [];
2021-08-23 11:48:44 +01:00
publicationPipe = new PublicationPipe()
2021-10-11 17:22:01 +01:00
publicationDitails: any;
getpublication = [];
private videoUrl: any;
swiperIndex: number = 0;
2023-11-29 12:17:52 +01:00
slideOpts = {
initialSlide: 0,
speed: 400,
loop: true,
pagination: {
2023-11-29 12:17:52 +01:00
el: '.swiper-pagination',
clickable: true
}
};
swiperModules = [IonicSlides];
2021-08-23 11:48:44 +01:00
publicationList: any
2023-12-01 12:16:34 +01:00
@ViewChild('VideoManager') VideoManager;
2023-12-13 18:19:08 +01:00
@ViewChildren('videoElement') videoElements: QueryList<ElementRef>;
@ViewChild('swiper')
swiperRef: ElementRef | undefined;
2023-12-01 12:16:34 +01:00
2021-07-22 11:12:55 +01:00
constructor(
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-25 13:54:34 +01:00
private backgroundservice: BackgroundService,
2022-02-18 15:28:30 +01:00
public ThemeService: ThemeService,
2022-03-30 16:32:56 +01:00
private toastService: ToastService,
2023-02-27 09:34:36 +01:00
public p: PermissionService,
2023-02-27 21:24:34 +01:00
private httpErroHandle: HttpErrorHandle,
2023-08-11 16:38:23 +01:00
private storage: Storage,
2023-11-29 12:17:52 +01:00
public publicationFolderService: PublicationFolderService,
2023-12-01 12:16:34 +01:00
public checkFileType: checkFileTypeService,
2023-12-13 18:19:08 +01:00
private publicationVideoManagerService: PublicationVideoManagerService,
2024-02-28 09:51:49 +01:00
public stopvideoService: StopvideoService,
2024-04-11 17:05:28 +01:00
public platform: Platform,
2024-03-26 12:03:30 +01:00
public activeTabService: ActiveTabService,
public PublicationHolderService: PublicationHolderService) {
2023-12-01 12:16:34 +01:00
/* this.publicationVideoManagerService.setContainer(this.VideoManager.nativeElement) */
2023-02-27 21:24:34 +01:00
setTimeout(() => {
console.log(this.VideoManager.nativeElement)
}, 2000)
2023-03-10 14:30:50 +01:00
this.createPublicationList()
2023-02-27 21:24:34 +01:00
this.getFromDB();
2021-07-15 17:15:04 +01:00
2021-07-21 19:08:31 +01:00
this.activatedRoute.paramMap.subscribe(params => {
2021-10-11 17:22:01 +01:00
if (params["params"]) {
2021-07-21 19:08:31 +01:00
this.folderId = params["params"].folderId;
2023-12-01 12:16:34 +01:00
//
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
});
}
ngOnInit() {
2023-12-01 12:16:34 +01:00
2021-10-11 17:22:01 +01:00
if (typeof (this.folderId) == 'object') {
2023-12-01 12:16:34 +01:00
this.folderId = (this.folderId as any)['ProcessId']
2021-07-15 17:15:04 +01:00
}
2023-02-27 21:24:34 +01:00
2023-03-10 14:30:50 +01:00
this.createPublicationList()
2023-02-27 21:24:34 +01:00
this.getFromDB();
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(() => {
2022-02-18 15:28:30 +01:00
this.getPublications();
2022-01-30 10:45:27 +01:00
}, 1000); */
2021-10-19 09:41:06 +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
})
2023-11-06 09:07:04 +01:00
2023-12-13 18:19:08 +01:00
// console.log(this.publicationFolderService.publicationList[this.folderId])
setTimeout(()=> {
2024-04-12 11:49:39 +01:00
// this.doRefresh({})
}, 1500)
}
2021-06-21 08:27:57 +01:00
onVisibilityChange = (e: boolean) => {
if (!e) {
2023-12-13 18:19:08 +01:00
this.stopVideo()
}
}
2023-12-13 18:19:08 +01:00
stopVideo() {
var videos = document.querySelectorAll('video');
try {
// Pause each video
videos.forEach(function (video) {
video.pause();
})
2023-12-13 18:19:08 +01:00
this.videoElements.forEach(videoElement => {
// You can access the native HTML video element using videoElement.nativeElement
const video: HTMLVideoElement = videoElement.nativeElement;
2023-12-13 18:19:08 +01:00
video.pause()
// Do something with each video element
// console.log(video);
});
} catch (error) {
console.log(error)
}
2023-12-13 18:19:08 +01:00
}
2021-07-15 17:42:12 +01:00
ngOnChanges() {
2021-10-11 17:22:01 +01:00
if (typeof (this.folderId) == 'object') {
this.folderId = (this.folderId as any)['ProcessId']
2021-07-15 17:42:12 +01:00
}
2023-03-10 14:30:50 +01:00
this.createPublicationList()
2023-02-27 21:24:34 +01:00
this.getFromDB();
2021-07-15 17:42:12 +01:00
}
2023-03-10 14:30:50 +01:00
createPublicationList(folderId = this.folderId) {
2023-08-18 17:37:11 +01:00
console.log('create')
if (!this.publicationFolderService.publicationList[folderId]) {
2023-08-11 16:38:23 +01:00
this.publicationFolderService.publicationList[folderId] = []
2023-03-10 14:30:50 +01:00
}
if (!this.publicationFolderService.FolderDetails[folderId]) {
2023-08-11 16:38:23 +01:00
this.publicationFolderService.FolderDetails[folderId] = new PublicationFolder();
2023-03-10 14:30:50 +01:00
}
}
2021-10-11 17:22:01 +01:00
doRefresh = (event) => {
2022-02-07 12:56:35 +01:00
//setTimeout(() => {
2023-02-27 21:24:34 +01:00
//this.testForkJoin()
this.getPublicationDetail();
this.getPublicationsIds();
try {
event?.target?.complete();
} catch (error) { }
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() {
this.modalController.dismiss();
2021-07-15 16:08:05 +01:00
this.router.navigate(['/home/publications']);
}
2021-06-21 08:27:57 +01:00
goBack() {
if (window["sharedContent"]) {
2024-02-28 09:51:49 +01:00
if (this.platform.is('android'))
App.exitApp();
return
}
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() {
2021-11-30 17:56:56 +01:00
const folderId = this.folderId
this.publications.GetPresidentialAction(folderId).subscribe(res => {
2023-08-11 16:38:23 +01:00
this.publicationFolderService.FolderDetails[folderId] = res
this.storage.set(folderId + "name", res)
2022-02-16 10:59:45 +01:00
}, (error) => {
2023-02-27 20:04:22 +01:00
this.showLoader = false;
2023-02-27 21:24:34 +01:00
// this.httpErroHandle.httpStatusHandle(error)
});
}
2023-02-27 21:24:34 +01:00
getFromDB() {
2021-07-21 20:26:41 +01:00
const folderId = this.folderId
2023-08-11 16:38:23 +01:00
this.publicationFolderService.getFromDB(folderId)
2021-11-29 15:48:35 +01:00
}
2023-02-27 21:24:34 +01:00
async getPublicationsIds() {
2021-10-19 09:41:06 +01:00
2023-02-27 21:24:34 +01:00
this.showLoader = true;
const folderId = this.folderId
2021-10-09 09:15:22 +01:00
2024-04-09 09:20:49 +01:00
await this.publicationFolderService.getPublicationsIds(folderId)
2024-04-09 09:20:49 +01:00
this.showLoader = false;
2023-02-27 21:24:34 +01:00
2022-02-07 12:56:35 +01:00
}
2023-03-10 14:30:50 +01:00
publicationIsPresent(publicationId, folderId) {
return this.publicationFolderService.publicationList[folderId].find(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
publicationFind(publicationId, folderId) {
return this.publicationFolderService.publicationList[folderId].find(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
publicationFindIndex(publicationId, folderId) {
return this.publicationFolderService.publicationList[folderId].findIndex(e => e.DocumentId == publicationId)
2023-03-10 14:30:50 +01:00
}
2021-10-11 17:22:01 +01:00
async AddPublication(publicationType: any, folderId: any) {
2023-07-15 11:01:09 +01:00
2024-03-26 14:20:14 +01:00
if(this.PublicationHolderService.PublicationFormMV.length == 0) {
2024-03-26 12:03:30 +01:00
const modal = await this.modalController.create({
component: NewPublicationPage,
componentProps: {
publicationType: publicationType,
folderId: this.folderId,
},
cssClass: 'new-publication modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
this.doRefresh(event);
});
await modal.present();
2024-03-26 14:20:14 +01:00
} else {
this.toastService._successMessage('já existe uma publicação a ser processado');
}
2024-03-26 12:03:30 +01:00
}
goToPublicationDetail(DocumentId: string, ProcessId: string) {
2023-12-13 18:40:00 +01:00
this.stopVideo();
2023-12-13 18:19:08 +01:00
setTimeout(() => {
this.router.navigate(['/home/publications/view-publications', this.folderId, DocumentId]);
}, 500)
2021-06-18 11:59:06 +01:00
}
2023-12-13 19:08:44 +01:00
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
}
2023-08-24 22:15:56 +01:00
async viewPublicationDetail(DocumentId: string) {
// alert('nice');
const modal = await this.modalController.create({
component: PublicationDetailPage,
2021-10-11 17:22:01 +01:00
componentProps: {
2023-08-24 22:15:56 +01:00
DocumentId: DocumentId,
2021-04-07 10:20:01 +01:00
folderId: this.folderId,
2023-02-06 09:23:36 +01:00
isModal: true
},
2021-04-14 15:27:50 +01:00
cssClass: 'publication-detail modal modal-desktop',
2021-04-29 19:46:40 +01:00
// backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2021-10-11 17:22:01 +01:00
modal.onDidDismiss().then(() => {
this.getPublicationsIds();
2020-12-15 19:37:42 +01:00
});
2023-07-15 11:01:09 +01:00
await modal.present();
}
2024-01-31 17:13:07 +01:00
getSortedPublications(): Publication[] {
2024-01-31 17:13:07 +01:00
const unsortedPublications = this.publicationFolderService.publicationList[this.folderId];
2024-01-31 17:13:07 +01:00
if (unsortedPublications) {
// Copiar a lista original para evitar alterações indesejadas
const publicationsCopy = [...unsortedPublications];
// Ordenar as publicações pelo DatePublication
publicationsCopy.sort((a, b) => {
const dateA = new Date(a.DatePublication).getTime();
const dateB = new Date(b.DatePublication).getTime();
return dateA - dateB;
});
return publicationsCopy;
} else {
return [];
}
}
//click custom bullet go to slide
goToSlide(index: number) {
this.swiperIndex = this.swiperRef?.nativeElement.swiper.activeIndex;
this.swiperRef?.nativeElement.swiper.slideTo(index);
console.log('index slide', index)
}
onSlideChange() {
this.swiperIndex = this.swiperRef?.nativeElement.swiper.activeIndex;
}
}