From d7980908dd3f64bc5490ebbf05299379683a8d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 5 Feb 2024 10:29:42 +0100 Subject: [PATCH] add try catch to video.foreach and video.pause --- .../new-publication/new-publication.page.ts | 23 ++++++-- .../pages/publications/publications.page.html | 6 +- .../pages/publications/publications.page.ts | 6 +- .../view-publications.page.ts | 57 +++++++++++-------- src/app/services/chunkService.ts | 53 +++++++++++++++++ .../view-publications.page.ts | 47 ++++++++------- src/assets/images/not-allowed.svg | 1 + 7 files changed, 137 insertions(+), 56 deletions(-) create mode 100644 src/app/services/chunkService.ts create mode 100644 src/assets/images/not-allowed.svg diff --git a/src/app/pages/publications/new-publication/new-publication.page.ts b/src/app/pages/publications/new-publication/new-publication.page.ts index 4b100fc7f..0e3e7a611 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -31,6 +31,9 @@ import { File } from '@ionic-native/file/ngx'; import { Media } from '@ionic-native/media/ngx'; import { checkFileTypeService } from 'src/app/services/checkFileType.service'; import { FileValidatorService } from "src/app/services/file/file-validator.service" +import { App } from '@capacitor/app'; +import { Router } from '@angular/router'; + const config = { quality: 0.5, maxWidth: 800, @@ -133,7 +136,8 @@ export class NewPublicationPage implements OnInit { public FileService: FileService, private mediaCapture: MediaCapture, public checkFileType: checkFileTypeService, - private FileValidatorService: FileValidatorService + private FileValidatorService: FileValidatorService, + private router: Router, ) { this.publicationType = this.navParams.get('publicationType'); @@ -536,11 +540,12 @@ export class NewPublicationPage implements OnInit { await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); - this.close(); this.httpErrorHandle.httpsSucessMessagge('Criar publicação') - window["sharedContent"] = null; - window["endSharedContent"] = null; - + if(window["sharedContent"]) { + this.router.navigate(['/home/publications', this.folderId]); + return + } + this.close(); } catch (error) { this.httpErrorHandle.httpStatusHandle(error) @@ -562,6 +567,10 @@ export class NewPublicationPage implements OnInit { this.modalController.dismiss(this.publication).then(() => { this.showLoader = true; }); + + if(window["sharedContent"]) { + this.closeApp(); + } } clear() { @@ -782,5 +791,9 @@ export class NewPublicationPage implements OnInit { this.seletedContent.splice(index, 1) } + closeApp() { + App.exitApp() + } + } diff --git a/src/app/pages/publications/publications.page.html b/src/app/pages/publications/publications.page.html index 60591173b..391c47e29 100644 --- a/src/app/pages/publications/publications.page.html +++ b/src/app/pages/publications/publications.page.html @@ -24,7 +24,7 @@ --> -
+
-
+
diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index f81d448cc..2287fc8bf 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -349,7 +349,7 @@ export class PublicationsPage implements OnInit { componentProps: { publicationType: publicationType, folderId: folderId, - intent: intent + intent: window["sharedContent"] }, cssClass: 'new-publication modal modal-desktop', backdropDismiss: false @@ -362,8 +362,8 @@ export class PublicationsPage implements OnInit { } goToPublicationsList(folderId: string) { - if(this.intent){ - this.AddPublication('2',folderId,this.intent) + if(window["sharedContent"]){ + this.AddPublication('2',folderId,window["sharedContent"]) return } if (window.innerWidth < 701) { diff --git a/src/app/pages/publications/view-publications/view-publications.page.ts b/src/app/pages/publications/view-publications/view-publications.page.ts index 247a1ca9f..cc12b5a37 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.ts +++ b/src/app/pages/publications/view-publications/view-publications.page.ts @@ -1,6 +1,6 @@ import { Component, ElementRef, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { ModalController,IonicSlides } from '@ionic/angular'; +import { ModalController, IonicSlides } 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'; @@ -16,9 +16,10 @@ import { Storage } from '@ionic/storage'; import { PublicationFolderService } from 'src/app/store/publication-folder.service'; // import { CapacitorVideoPlayer } from 'capacitor-video-player'; import { checkFileTypeService } from 'src/app/services/checkFileType.service'; -import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service" +import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service" import { StopvideoService } from "src/app/services/stopvideo.service" import { Result } from 'neverthrow'; +import { App } from '@capacitor/app'; @Component({ selector: 'app-view-publications', templateUrl: './view-publications.page.html', @@ -43,7 +44,7 @@ export class ViewPublicationsPage implements OnInit { initialSlide: 0, speed: 400, loop: true, - pagination : { + pagination: { el: '.swiper-pagination', clickable: true } @@ -70,13 +71,13 @@ export class ViewPublicationsPage implements OnInit { public stopvideoService: StopvideoService) { - /* this.publicationVideoManagerService.setContainer(this.VideoManager.nativeElement) */ + /* this.publicationVideoManagerService.setContainer(this.VideoManager.nativeElement) */ - setTimeout(() => { + setTimeout(() => { - console.log(this.VideoManager.nativeElement) - }, 2000) + console.log(this.VideoManager.nativeElement) + }, 2000) this.createPublicationList() @@ -122,7 +123,7 @@ export class ViewPublicationsPage implements OnInit { onVisibilityChange = (e: boolean) => { console.log("nice to have", e) - if(!e) { + if (!e) { this.stopVideo() } } @@ -131,26 +132,30 @@ export class ViewPublicationsPage implements OnInit { stopVideo() { var videos = document.querySelectorAll('video'); - // Pause each video - videos.forEach(function (video) { - video.pause(); - }) + try { + // Pause each video + videos.forEach(function (video) { + video.pause(); + }) - this.videoElements.forEach(videoElement => { - // You can access the native HTML video element using videoElement.nativeElement - const video: HTMLVideoElement = videoElement.nativeElement; + 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); - }); + video.pause() + // Do something with each video element + // console.log(video); + }); + } catch (error) { + console.log(error) + } } ngOnChanges() { if (typeof (this.folderId) == 'object') { - this.folderId = (this.folderId as any )['ProcessId'] + this.folderId = (this.folderId as any)['ProcessId'] } this.createPublicationList() @@ -186,6 +191,10 @@ export class ViewPublicationsPage implements OnInit { } goBack() { + if (window["sharedContent"]) { + App.exitApp(); + return + } this.router.navigate(['/home/publications']); } @@ -274,13 +283,13 @@ export class ViewPublicationsPage implements OnInit { } else { - let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex]) + let a: any = Object.assign({}, this.publicationFolderService.publicationList[folderId][findIndex]) let b: any = Object.assign({}, publicationDetails) a.Files = a.Files.length b.Files = b.Files.length - if(JSON.stringify(a) != JSON.stringify(b)) { + if (JSON.stringify(a) != JSON.stringify(b)) { // console.log({a, b}) this.publicationFolderService.publicationList[folderId][findIndex] = publicationDetails @@ -350,9 +359,9 @@ export class ViewPublicationsPage implements OnInit { } - getSortedPublications(): Publication[] { + getSortedPublications(): Publication[] { const unsortedPublications = this.publicationFolderService.publicationList[this.folderId]; - + if (unsortedPublications) { // Copiar a lista original para evitar alterações indesejadas const publicationsCopy = [...unsortedPublications]; diff --git a/src/app/services/chunkService.ts b/src/app/services/chunkService.ts new file mode 100644 index 000000000..6f8bc75f9 --- /dev/null +++ b/src/app/services/chunkService.ts @@ -0,0 +1,53 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) + +export class ChunksService { + + chunkSize: number + private file: File + + constructor() { + + } + + get totalChunks () { + return Math.ceil(this.file.size / this.chunkSize); + } + + // Function to read a chunk of the file + readChunk(start: number, end: number): Promise { + const file = this.file + + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => { + if (reader.result instanceof ArrayBuffer) { + resolve(reader.result); + } else { + reject(new Error("Failed to read chunk")); + } + }; + + reader.readAsArrayBuffer(file.slice(start, end)); + }); + } + + setFile(file) { + this.file = file + } + + async getChunks(i: number,chunkSize: number) { + i-- + if(i < this.totalChunks) { + const start = i * chunkSize; + const end = Math.min(start + chunkSize, this.file.size); + const chunk = await this.readChunk(start, end); + + return chunk + } + } + +} \ No newline at end of file diff --git a/src/app/shared/publication/view-publications/view-publications.page.ts b/src/app/shared/publication/view-publications/view-publications.page.ts index 3024c0b82..b5fb30c71 100644 --- a/src/app/shared/publication/view-publications/view-publications.page.ts +++ b/src/app/shared/publication/view-publications/view-publications.page.ts @@ -15,7 +15,7 @@ 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 { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"; +import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"; import { StopvideoService } from "src/app/services/stopvideo.service"; @Component({ selector: 'app-view-publications', @@ -80,7 +80,7 @@ export class ViewPublicationsPage implements OnInit { onVisibilityChange = (e: boolean) => { console.log("nice to have", e) - if(!e) { + if (!e) { /* this.stopVideo() */ } } @@ -228,13 +228,13 @@ export class ViewPublicationsPage implements OnInit { this.publicationFolderService.revertPublicationOrder(folderId) } else { - let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex]) + let a: any = Object.assign({}, this.publicationFolderService.publicationList[folderId][findIndex]) let b: any = Object.assign({}, publicationDetails) a.Files = a.Files.length b.Files = b.Files.length - if(JSON.stringify(a) != JSON.stringify(b)) { + if (JSON.stringify(a) != JSON.stringify(b)) { // console.log({a, b}) this.publicationFolderService.publicationList[folderId][findIndex] = publicationDetails @@ -329,7 +329,7 @@ export class ViewPublicationsPage implements OnInit { } this.close(); this.getActions.emit(); - + } // Do nothing @@ -343,7 +343,7 @@ export class ViewPublicationsPage implements OnInit { this.stopVideo(); - setTimeout(()=> { + setTimeout(() => { this.openPublicationDetails.emit({ DocumentId, ProcessId }); }, 200) @@ -370,30 +370,35 @@ export class ViewPublicationsPage implements OnInit { stopVideo() { var videos = document.querySelectorAll('video'); - // Pause each video - videos.forEach(function (video) { - video.pause(); - }) + try { + // Pause each video + videos.forEach(function (video) { + video.pause(); + }) - this.videoElements.forEach(videoElement => { - // You can access the native HTML video element using videoElement.nativeElement - const video: HTMLVideoElement = videoElement.nativeElement; + 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); - }); + video.pause() + // Do something with each video element + // console.log(video); + }); + + } catch (error) { + console.log(error) + } } public onScroll(event): void { - if(this.lastScrollTop < event.detail.scrollTop) { + if (this.lastScrollTop < event.detail.scrollTop) { // console.log("scrolling down") - } else { + } else { // console.log("scrolling up") - } + } - this.lastScrollTop = event.detail.scrollTop; + this.lastScrollTop = event.detail.scrollTop; } } diff --git a/src/assets/images/not-allowed.svg b/src/assets/images/not-allowed.svg new file mode 100644 index 000000000..ba95d9c23 --- /dev/null +++ b/src/assets/images/not-allowed.svg @@ -0,0 +1 @@ + \ No newline at end of file