From 300b48817407c2c0090cf32c2b2c140d0e843f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Fri, 26 Jan 2024 05:59:14 +0100 Subject: [PATCH 1/4] record video on diferente divice solved --- android/app/src/main/AndroidManifest.xml | 3 +- .../new-publication/new-publication.page.ts | 258 ++++---- .../new-publication/new-publication.page.html | 43 +- .../new-publication/new-publication.page.scss | 4 + .../new-publication/new-publication.page.ts | 582 ++++++++++-------- src/environments/environment.prod.ts | 2 +- 6 files changed, 487 insertions(+), 405 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 13e2aa973..e30b92953 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -19,7 +19,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" - android:usesCleartextTraffic="true"> + android:usesCleartextTraffic="true" + android:requestLegacyExternalStorage="true"> { this.filesSizeSum = this.filesSizeSum + element.size if (this.fileSizeToMB(this.filesSizeSum) <= 20) { if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') { let resultUrl = decodeURIComponent(element.path); - Filesystem.readFile({ path: resultUrl }) + try { + Filesystem.readFile({ path: resultUrl }) + + .then(async (content) => { + console.log(result) + console.log(content) + this.filecontent = true; + let fileObject = { + FileBase64: content.data, + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/') + } + this.seletedContent.push(fileObject) + }) + .catch((err) => console.error(err)); + } catch (error) { + console.log('upload video error: ', error) + } - .then(async (content) => { - console.log(result) - console.log(content) - this.filecontent = true; - let fileObject = { - FileBase64: content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'foto' - } - this.seletedContent.push(fileObject) - }) - .catch((err) => console.error(err)); } } else { if (this.seletedContent.length === 0) - this.filesSizeSum = 0 + this.filesSizeSum = 0 - this.httpErrorHandle.validationMessagge('filessize') + this.httpErrorHandle.validationMessagge('filessize') } }); }; @@ -346,24 +341,24 @@ export class NewPublicationPage implements OnInit { /* // in use async laodPicture() { - + const capturedImage = await Camera.getPhoto({ quality: 90, // allowEditing: true, resultType: CameraResultType.Uri, source: CameraSource.Photos }); - + const response = await fetch(capturedImage.webPath!); const blob = await response.blob(); - + this.convertBlobToBase64Worker.postMessage(blob); this.convertBlobToBase64Worker.onmessage = async (oEvent)=> { this.capturedImage = oEvent.data this.capturedImageTitle = 'foto' - + } - + } */ @@ -398,28 +393,12 @@ export class NewPublicationPage implements OnInit { if (this.Form.invalid) return false - if(this.seletedContent.length == 0) { - - const newAttachment = { - FileBase64: "iVBORw0KGgoAAAANSUhEUgAAAgMAAAIJCAIAAAC3IqlmAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAABSKSURBVHhe7d1ncuNGo4bRu/8lfh5F5qToBdyWNJbHDYgAmETqPVXnh4PAhKp+iMDu/3v9+28AkikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEA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afSRQAo5OCS5LtftIoAQcnRJclmr3kUAJODoluCzV7iOBEnB0SnBZqt1HAiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQDSKQFAOiUASKcEAOmUACCdEgCkUwKAdEoAkE4JANIpAUA6JQBIpwQA6ZQAIJ0SAKRTAoB0SgCQTgkA0ikBQDolAEinBADplAAgnRIApFMCgHRKAJBOCQCy/f33/wPavQjXs/ARnQAAAABJRU5ErkJggg==", - FileExtension: "png", - OriginalFileName: "foto", - } - - - this.seletedContent.push(newAttachment) - } - if (this.publicationType == '3') { + const loader = this.toastService.loading() - - - if (this.seletedContent.length >= 1) { - - - const loader = this.toastService.loading() - + // has file + if (this.PublicationFolderService.PublicationHasImage(this.publication)) { this.publication = { DateIndex: this.publication.DateIndex, DocumentId: this.publication.DocumentId, @@ -431,74 +410,115 @@ export class NewPublicationPage implements OnInit { Files: this.seletedContent, } - try { - - const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() - - this.httpErrorHandle.httpsSucessMessagge('Editar publicação') - console.log({ response }) - - - this.close(); - } catch (error) { - if (error.status == 404) { - this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId) - this.close(); - } - this.httpErrorHandle.httpStatusHandle(error) - } finally { - loader.remove() + /* } else if (this.capturedVideo != '' && this.capturedImage == '') { + this.publication = { + DateIndex: this.publication.DateIndex, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, + Title: this.pub.Title, + Message: this.pub.Message, + DatePublication: this.publication.DatePublication, + OriginalFileName: this.publication.OriginalFileName || 'video', + Files: this.seletedContent, + FileExtension: 'mp4', + } + } */ + // no names + } else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { + this.publication = { + DateIndex: this.publication.DateIndex, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, + Title: this.pub.Title, + Message: this.pub.Message, + DatePublication: this.publication.DatePublication, + OriginalFileName: this.publication.OriginalFileName, + Files: this.seletedContent, } - } else { - this.toastService._badRequest("É necessário adicionar uma imagem ou vídeo") + } /* else { + this.publication = { + DateIndex: this.publication.DateIndex, + DocumentId: this.publication.DocumentId, + ProcessId: this.publication.ProcessId, + Title: this.pub.Title, + Message: this.pub.Message, + DatePublication: this.publication.DatePublication, + OriginalFileName: this.publication.OriginalFileName, + FileBase64: this.publication.FileBase64, + FileExtension: this.publication.FileExtension || 'jpeg', + } + + } */ + + + try { + + const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() + + this.httpErrorHandle.httpsSucessMessagge('Editar publicação') + console.log({ response }) + + + this.close(); + } catch (error) { + if (error.status == 404) { + this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId) + this.close(); + } + this.httpErrorHandle.httpStatusHandle(error) + } finally { + loader.remove() } - - } else { + const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') - if (this.seletedContent.length >= 1) { + /* if (this.capturedImage != '') { */ + this.publication = { + DateIndex: date, + DocumentId: null, + ProcessId: this.folderId, + Title: this.pub.Title, + Message: this.pub.Message, + DatePublication: date, + OriginalFileName: this.capturedImageTitle, + Files: this.seletedContent, + /* FileExtension: 'jpeg', */ + } - const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') - - /* if (this.capturedImage != '') { */ - this.publication = { - DateIndex: date, - DocumentId: null, - ProcessId: this.folderId, - Title: this.pub.Title, - Message: this.pub.Message, - DatePublication: date, - OriginalFileName: this.capturedImageTitle, - Files: this.seletedContent, - /* FileExtension: 'jpeg', */ - } - - const loader = this.toastService.loading() + /* } else if (this.capturedVideo != '') { + this.publication = { + DateIndex: date, + DocumentId: null, + ProcessId: this.folderId, + Title: this.pub.Title, + Message: this.pub.Message, + DatePublication: date, + OriginalFileName: this.capturedImageTitle || 'video', + Files: this.seletedContent, + FileExtension: 'mp4', + } + } */ - try { + const loader = this.toastService.loading() - await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); - this.close(); - this.httpErrorHandle.httpsSucessMessagge('Criar publicação') - window["sharedContent"] = null; + try { - this.close(); - } catch (error) { - this.httpErrorHandle.httpStatusHandle(error) - } finally { - loader.remove() - } + await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); + this.close(); + this.httpErrorHandle.httpsSucessMessagge('Criar publicação') + window["sharedContent"] = null; - - - } else { - this.toastService._badRequest("É necessário adicionar uma imagem ou vídeo") + this.close(); + } catch (error) { + this.httpErrorHandle.httpStatusHandle(error) + } finally { + loader.remove() } } @@ -684,7 +704,7 @@ export class NewPublicationPage implements OnInit { type: this.intent.type, url: this.intent.url } - if(this.intent?.additionalItems) { + if (this.intent?.additionalItems) { filesArray = this.intent?.additionalItems; } filesArray.push(fistFile) @@ -696,7 +716,8 @@ export class NewPublicationPage implements OnInit { console.log('shared base', content.data) let fileObject = { FileBase64: this.removeTextBeforeSlash(content.data, ','), - FileExtension: FileExtension + FileExtension: FileExtension, + OriginalFileName: 'shared', } this.seletedContent.push(fileObject) }) @@ -714,8 +735,9 @@ export class NewPublicationPage implements OnInit { return parseInt(sizeInMB) } - deleteFromSeletedContent(index){ - this.seletedContent.splice(index,1) + deleteFromSeletedContent(index) { + this.seletedContent.splice(index, 1) } } + diff --git a/src/app/shared/publication/new-publication/new-publication.page.html b/src/app/shared/publication/new-publication/new-publication.page.html index 47516404b..c82a02b8e 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -100,41 +100,26 @@ - - -
- +
+
- + +
-
- Tirar Fotografia +
+ Câmera
- +
+
+ +
+ +
@@ -145,7 +130,7 @@ src="assets/images/theme/gov/icons-add-photos.svg">
- Anexar Fotografia + Galeria
diff --git a/src/app/shared/publication/new-publication/new-publication.page.scss b/src/app/shared/publication/new-publication/new-publication.page.scss index d6bbd0b09..efb482701 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.scss +++ b/src/app/shared/publication/new-publication/new-publication.page.scss @@ -156,6 +156,10 @@ font-size: rem(25); display: block; } +.container-multiselect { + display: grid; +} + diff --git a/src/app/shared/publication/new-publication/new-publication.page.ts b/src/app/shared/publication/new-publication/new-publication.page.ts index 652b5ccfd..c89b2f9f6 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -16,8 +16,11 @@ import { LakefsRepositoryService } from '../../repository/lakefs/lakefs-reposito import { ok, err, Result } from 'neverthrow'; import { SocketConnectionMCRService } from "src/app/services/socket-connection-mcr.service" import { CMAPIService } from "src/app/shared/repository/CMAPI/cmapi.service"; +import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx'; +import { Filesystem, Directory, Encoding, FilesystemDirectory } from '@capacitor/filesystem'; +import { Platform } from '@ionic/angular'; -enum ActionType { +enum ActionType { newRapid = "1", new = "2", edit = "3" @@ -60,6 +63,8 @@ export class NewPublicationPage implements OnInit { seletedContent: PublicationAttachmentEntity[] = [] displayLimit = 4; filesSizeSum = 0; + photoOrVideo: boolean = false; + video: any; publicationFormMV = new PublicationFormMV() @@ -76,7 +81,10 @@ export class NewPublicationPage implements OnInit { private MiddlewareServiceService: MiddlewareServiceService, private LakefsRepositoryService: LakefsRepositoryService, private SocketConnectionMCRService: SocketConnectionMCRService, - private CMAPIService: CMAPIService + private CMAPIService: CMAPIService, + private mediaCapture: MediaCapture, + private httpErrorHandle: HttpErrorHandle, + private platform: Platform, ) { this.publicationTitle = 'Nova Publicação'; @@ -134,9 +142,9 @@ export class NewPublicationPage implements OnInit { OriginalFileName: res.OriginalFileName, FileExtension: res.FileExtension, } - console.log('edit',this.publication) + console.log('edit', this.publication) this.pub = this.publication; - this.seletedContent = this.publication.Files.map( e => { + this.seletedContent = this.publication.Files.map(e => { return new PublicationAttachmentEntity( { base64: e.FileBase64, @@ -173,12 +181,13 @@ export class NewPublicationPage implements OnInit { 800, // maxHeight 0.9 // quality ).then((picture) => { + this.photoOrVideo = false; let fileObject = { FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg','/') + FileExtension: this.removeTextBeforeSlash('jpeg', '/') } - const FileExtension = this.removeTextBeforeSlash('jpeg','/') + const FileExtension = this.removeTextBeforeSlash('jpeg', '/') const newAttachment = new PublicationAttachmentEntity( { @@ -194,9 +203,9 @@ export class NewPublicationPage implements OnInit { this.seletedContent.push(newAttachment) }); - /* } else { - this.toastService._badRequest("Imagem inválida") - } */ + /* } else { + this.toastService._badRequest("Imagem inválida") + } */ } async laodPicture() { @@ -219,10 +228,10 @@ export class NewPublicationPage implements OnInit { ).then((picture) => { let fileObject = { FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg','/') + FileExtension: this.removeTextBeforeSlash('jpeg', '/') } - const FileExtension = this.removeTextBeforeSlash('jpeg','/') + const FileExtension = this.removeTextBeforeSlash('jpeg', '/') const newAttachment = new PublicationAttachmentEntity( { @@ -246,36 +255,41 @@ export class NewPublicationPage implements OnInit { multiple: true, }); + console.log(result) result.files.forEach(async blobFile => { - if(this.checkFileType.checkFileType(blobFile.mimeType) == 'image' || this.checkFileType.checkFileType(blobFile.mimeType) == 'video') { + console.log(blobFile) + if (this.checkFileType.checkFileType(blobFile.mimeType) == 'image' || this.checkFileType.checkFileType(blobFile.mimeType) == 'video') { + console.log() this.convertBlobToBase64(blobFile.blob).then((value) => { + this.filesSizeSum = this.filesSizeSum + blobFile.size - if(this.fileSizeToMB(this.filesSizeSum) <= 20) { + if (this.fileSizeToMB(this.filesSizeSum) <= 20) { - const FileExtension = this.removeTextBeforeSlash(blobFile.mimeType,'/') + const FileExtension = this.removeTextBeforeSlash(blobFile.mimeType, '/') - const file = new File([blobFile.blob], blobFile.name); + const file = new File([blobFile.blob], blobFile.name); - const newAttachment = new PublicationAttachmentEntity( - { - base64: value, - extension: FileExtension, - blobFile: file, - FileType: this.checkFileType.checkFileType(FileExtension) - } - ) + const newAttachment = new PublicationAttachmentEntity( + { + base64: value, + extension: FileExtension, + blobFile: file, + FileType: this.checkFileType.checkFileType(FileExtension) + } + ) - newAttachment.needUpload() + newAttachment.needUpload() - this.seletedContent.push(newAttachment) - this.filecontent = true; - } else { - if(this.seletedContent.length === 0) - this.filesSizeSum = 0 + this.seletedContent.push(newAttachment) + console.log(this.seletedContent) + this.filecontent = true; + } else { + if (this.seletedContent.length === 0) + this.filesSizeSum = 0 - this.httpErroHandle.validationMessagge('filessize'); - } + this.httpErroHandle.validationMessagge('filessize'); + } }) } else { this.httpErroHandle.validationMessagge('filetype'); @@ -338,7 +352,7 @@ export class NewPublicationPage implements OnInit { } - if(this.seletedContent.length == 0) { + if (this.seletedContent.length == 0) { const newAttachment = new PublicationAttachmentEntity( { @@ -370,7 +384,7 @@ export class NewPublicationPage implements OnInit { } - this.publication.Files = this.publication.Files.map( e => ({ + this.publication.Files = this.publication.Files.map(e => ({ FileBase64: e.FileBase64, FileExtension: e.FileExtension, OriginalFileName: 'foto' @@ -417,7 +431,7 @@ export class NewPublicationPage implements OnInit { - this.publication.Files = this.publication.Files.map( e => ({ + this.publication.Files = this.publication.Files.map(e => ({ FileBase64: e.FileBase64, FileExtension: e.FileExtension, OriginalFileName: 'foto' @@ -529,6 +543,7 @@ export class NewPublicationPage implements OnInit { } convertBlobToBase64(blob: Blob) { + console.log('Convert blob ',blob) return new Promise((resolve, reject) => { const reader = new FileReader; reader.onerror = reject; @@ -539,7 +554,7 @@ export class NewPublicationPage implements OnInit { }) } - removeTextBeforeSlash(inputString,mark) { + removeTextBeforeSlash(inputString, mark) { if (inputString.includes(mark)) { const parts = inputString.split(mark); return parts.length > 1 ? parts[1] : inputString; @@ -618,216 +633,216 @@ export class NewPublicationPage implements OnInit { -/* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { - return new Promise(async (resolve, reject) => { - try { - // Decode the base64 video string to an ArrayBuffer - const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(base64String,',')); + /* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { + return new Promise(async (resolve, reject) => { + try { + // Decode the base64 video string to an ArrayBuffer + const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(base64String,',')); + + // Create a Blob from the ArrayBuffer + const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); + + // Create an object URL from the Blob + const videoObjectUrl = URL.createObjectURL(videoBlob); + + // Create a video element + const video = document.createElement('video'); + + // Create a source element and set its type attribute + const source = document.createElement('source'); + source.type = 'video/mp4'; + + // Set the source URL + source.src = videoObjectUrl; + + // Append the source element to the video element + video.appendChild(source); + + // Wait for the video to load + video.addEventListener('loadedmetadata', async () => { + const canvas = document.createElement('canvas'); + let newWidth = video.videoWidth; + let newHeight = video.videoHeight; + + if (newWidth > maxWidth) { + newHeight *= maxWidth / newWidth; + newWidth = maxWidth; + } + + if (newHeight > maxHeight) { + newWidth *= maxHeight / newHeight; + newHeight = maxHeight; + } + + canvas.width = newWidth; + canvas.height = newHeight; + + const context = canvas.getContext('2d'); + + // Create a function to draw each video frame onto the canvas + const drawFrame = () => { + context?.drawImage(video, 0, 0, newWidth, newHeight); + + // Convert the canvas to a Blob with the correct MIME type + canvas.toBlob(async (blob) => { + if (blob) { + // Read the Blob as an ArrayBuffer + const compressedVideoBuffer = await this.readBlobAsArrayBuffer(blob); + + // Convert the ArrayBuffer back to base64 + const compressedBase64 = this.arrayBufferToBase64(compressedVideoBuffer); + + resolve(compressedBase64); + } else { + reject('Error creating compressed video blob.'); + } + }, 'video/mp4', quality); + + // Request the next video frame + requestAnimationFrame(drawFrame); + }; + + // Start drawing frames + drawFrame(); + + // Start playing the video + video.play(); + }); + + } catch (error) { + reject(error); + } + }); + } */ - // Create a Blob from the ArrayBuffer - const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); - // Create an object URL from the Blob - const videoObjectUrl = URL.createObjectURL(videoBlob); - // Create a video element - const video = document.createElement('video'); - // Create a source element and set its type attribute - const source = document.createElement('source'); - source.type = 'video/mp4'; + /* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { + return new Promise(async (resolve, reject) => { + try { + // Decode the base64 video string to an ArrayBuffer + const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(base64String,',')); + + // Create a Blob from the ArrayBuffer + const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); + + // Create an object URL from the Blob + const videoObjectUrl = URL.createObjectURL(videoBlob); + + // Create a video element + const video = document.createElement('video'); + video.src = videoObjectUrl; + + // Wait for the video to load metadata + video.addEventListener('loadedmetadata', async () => { + const canvas = document.createElement('canvas'); + let newWidth = video.videoWidth; + let newHeight = video.videoHeight; + + if (newWidth > maxWidth) { + newHeight *= maxWidth / newWidth; + newWidth = maxWidth; + } + + if (newHeight > maxHeight) { + newWidth *= maxHeight / newHeight; + newHeight = maxHeight; + } + + canvas.width = newWidth; + canvas.height = newHeight; + + const context = canvas.getContext('2d'); + context?.drawImage(video, 0, 0, newWidth, newHeight); + + // Convert the canvas to a Blob with the correct MIME type + canvas.toBlob(async (blob) => { + if (blob) { + // Read the Blob as an ArrayBuffer + const compressedVideoBuffer = await this.readBlobAsArrayBuffer(blob); + + // Convert the ArrayBuffer back to base64 + const compressedBase64 = this.arrayBufferToBase64(compressedVideoBuffer); + + resolve(compressedBase64); + } else { + reject('Error creating compressed video blob.'); + } + }, 'video/mp4', quality); + + }); + + } catch (error) { + reject(error); + } + }); + } */ - // Set the source URL - source.src = videoObjectUrl; - // Append the source element to the video element - video.appendChild(source); - - // Wait for the video to load - video.addEventListener('loadedmetadata', async () => { - const canvas = document.createElement('canvas'); - let newWidth = video.videoWidth; - let newHeight = video.videoHeight; - - if (newWidth > maxWidth) { - newHeight *= maxWidth / newWidth; - newWidth = maxWidth; - } - - if (newHeight > maxHeight) { - newWidth *= maxHeight / newHeight; - newHeight = maxHeight; - } - - canvas.width = newWidth; - canvas.height = newHeight; - - const context = canvas.getContext('2d'); - - // Create a function to draw each video frame onto the canvas - const drawFrame = () => { + /* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { + return new Promise(async (resolve, reject) => { + try { + // Decode the base64 video string to an ArrayBuffer + + const trimmedBase64 = base64String.trim(); + console.log(this.removeTextBeforeSlash(trimmedBase64,',')) + const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(trimmedBase64,',')); + + // Create a Blob from the ArrayBuffer + const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); + + // Create an object URL from the Blob + const videoObjectUrl = URL.createObjectURL(videoBlob); + + // Create a video element + const video = document.createElement('video'); + video.src = videoObjectUrl; + + // Wait for the video to load metadata + video.addEventListener('loadedmetadata', async () => { + const canvas = document.createElement('canvas'); + let newWidth = video.videoWidth; + let newHeight = video.videoHeight; + + if (newWidth > maxWidth) { + newHeight *= maxWidth / newWidth; + newWidth = maxWidth; + } + + if (newHeight > maxHeight) { + newWidth *= maxHeight / newHeight; + newHeight = maxHeight; + } + + canvas.width = newWidth; + canvas.height = newHeight; + + const context = canvas.getContext('2d'); context?.drawImage(video, 0, 0, newWidth, newHeight); - - // Convert the canvas to a Blob with the correct MIME type + + // Convert the canvas to a Blob canvas.toBlob(async (blob) => { if (blob) { // Read the Blob as an ArrayBuffer const compressedVideoBuffer = await this.readBlobAsArrayBuffer(blob); - + // Convert the ArrayBuffer back to base64 const compressedBase64 = this.arrayBufferToBase64(compressedVideoBuffer); - + resolve(compressedBase64); } else { reject('Error creating compressed video blob.'); } }, 'video/mp4', quality); - - // Request the next video frame - requestAnimationFrame(drawFrame); - }; - - // Start drawing frames - drawFrame(); - - // Start playing the video - video.play(); - }); - - } catch (error) { - reject(error); - } - }); - } */ - - - - - /* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { - return new Promise(async (resolve, reject) => { - try { - // Decode the base64 video string to an ArrayBuffer - const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(base64String,',')); - - // Create a Blob from the ArrayBuffer - const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); - - // Create an object URL from the Blob - const videoObjectUrl = URL.createObjectURL(videoBlob); - - // Create a video element - const video = document.createElement('video'); - video.src = videoObjectUrl; - - // Wait for the video to load metadata - video.addEventListener('loadedmetadata', async () => { - const canvas = document.createElement('canvas'); - let newWidth = video.videoWidth; - let newHeight = video.videoHeight; - - if (newWidth > maxWidth) { - newHeight *= maxWidth / newWidth; - newWidth = maxWidth; - } - - if (newHeight > maxHeight) { - newWidth *= maxHeight / newHeight; - newHeight = maxHeight; - } - - canvas.width = newWidth; - canvas.height = newHeight; - - const context = canvas.getContext('2d'); - context?.drawImage(video, 0, 0, newWidth, newHeight); - - // Convert the canvas to a Blob with the correct MIME type - canvas.toBlob(async (blob) => { - if (blob) { - // Read the Blob as an ArrayBuffer - const compressedVideoBuffer = await this.readBlobAsArrayBuffer(blob); - - // Convert the ArrayBuffer back to base64 - const compressedBase64 = this.arrayBufferToBase64(compressedVideoBuffer); - - resolve(compressedBase64); - } else { - reject('Error creating compressed video blob.'); - } - }, 'video/mp4', quality); - - }); - - } catch (error) { - reject(error); - } - }); - } */ - - -/* async compressVideoBase64(base64String: string, maxWidth: number, maxHeight: number, quality: number): Promise { - return new Promise(async (resolve, reject) => { - try { - // Decode the base64 video string to an ArrayBuffer - - const trimmedBase64 = base64String.trim(); - console.log(this.removeTextBeforeSlash(trimmedBase64,',')) - const videoBuffer = this.base64ToArrayBuffer(this.removeTextBeforeSlash(trimmedBase64,',')); - - // Create a Blob from the ArrayBuffer - const videoBlob = new Blob([videoBuffer], { type: 'video/mp4' }); - - // Create an object URL from the Blob - const videoObjectUrl = URL.createObjectURL(videoBlob); - - // Create a video element - const video = document.createElement('video'); - video.src = videoObjectUrl; - - // Wait for the video to load metadata - video.addEventListener('loadedmetadata', async () => { - const canvas = document.createElement('canvas'); - let newWidth = video.videoWidth; - let newHeight = video.videoHeight; - - if (newWidth > maxWidth) { - newHeight *= maxWidth / newWidth; - newWidth = maxWidth; - } - - if (newHeight > maxHeight) { - newWidth *= maxHeight / newHeight; - newHeight = maxHeight; - } - - canvas.width = newWidth; - canvas.height = newHeight; - - const context = canvas.getContext('2d'); - context?.drawImage(video, 0, 0, newWidth, newHeight); - - // Convert the canvas to a Blob - canvas.toBlob(async (blob) => { - if (blob) { - // Read the Blob as an ArrayBuffer - const compressedVideoBuffer = await this.readBlobAsArrayBuffer(blob); - - // Convert the ArrayBuffer back to base64 - const compressedBase64 = this.arrayBufferToBase64(compressedVideoBuffer); - - resolve(compressedBase64); - } else { - reject('Error creating compressed video blob.'); - } - }, 'video/mp4', quality); - - }); - - } catch (error) { - reject(error); - } - }); - } */ + + }); + + } catch (error) { + reject(error); + } + }); + } */ private base64ToArrayBuffer(base64: string): ArrayBuffer { const binaryString = window.atob(base64); @@ -890,6 +905,58 @@ export class NewPublicationPage implements OnInit { this.publicationFormMV.uploadVideosFiles() } + + chossePhotoOrVideo() { + this.photoOrVideo = !this.photoOrVideo + } + + async startVideoRecording() { + try { + let options: CaptureImageOptions = { limit: 1 } + const data: any = await this.mediaCapture.captureVideo(options) + this.video = data[0]; + console.log(data) + data.forEach(async element => { + this.filesSizeSum = this.filesSizeSum + element.size + if (this.fileSizeToMB(this.filesSizeSum) <= 20) { + const savedFile = await Filesystem.copy({ + from: element.fullPath, // directory prop removed, Capacitor parses filename for us + to: "video.mp4", + toDirectory: FilesystemDirectory.Data + }); + console.log(savedFile.uri) + Filesystem.readFile({ path: savedFile.uri }) + + .then(async (content) => { + this.filecontent = true; + let fileObject = new PublicationAttachmentEntity({ + base64: content.data, + extension: 'mp4', + OriginalFileName: 'record', + FileType: 'video' + + } + ) + this.seletedContent.push(fileObject) + }) + .catch((err) => console.error(err)); + } else { + if (this.seletedContent.length === 0) + this.filesSizeSum = 0 + + this.httpErrorHandle.validationMessagge('filessize') + } + + }); + } catch (error) { + console.log('record video error: ', error) + } + } + + checkTableDivice() { + if (!this.platform.is('desktop')) + return true; + } } // class UploadFileUseCase { @@ -994,32 +1061,32 @@ export class NewPublicationPage implements OnInit { class UploadFileUseCase { - CMAPIService: CMAPIService = window["CMAPIService"] - constructor() {} + CMAPIService: CMAPIService = window["CMAPIService"] + constructor() { } async execute(ChucksManager: ChucksManager): Promise> { let path: string; const length = ChucksManager.chunks.totalChunks.toString() - const readAndUploadChunk = async(index: number) => { + const readAndUploadChunk = async (index: number) => { const chunk = await ChucksManager.chunks.getChunks(index) const blob = new Blob([chunk]); const blobFile = new File([blob], "test.mp4", { type: blob.type }); - return await this.CMAPIService.FileContent({length, path: ChucksManager.path, index, blobFile}) + return await this.CMAPIService.FileContent({ length, path: ChucksManager.path, index, blobFile }) } - if(!ChucksManager.hasPath()) { + if (!ChucksManager.hasPath()) { const initIndex = ChucksManager.uploadsCount + 1 const chuck = await ChucksManager.chunks.getChunks(initIndex) const blob = new Blob([chuck]); const blobFile = new File([blob], "test.mp4", { type: blob.type }); - const uploadRequest = await this.CMAPIService.FileContent({length, path:ChucksManager.path, index: initIndex, blobFile}) + const uploadRequest = await this.CMAPIService.FileContent({ length, path: ChucksManager.path, index: initIndex, blobFile }) - if(uploadRequest.isOk()) { + if (uploadRequest.isOk()) { path = uploadRequest.value.data @@ -1034,7 +1101,7 @@ class UploadFileUseCase { for (let index = indexContinuation; index <= ChucksManager.chunks.totalChunks; index++) { const uploadRequest = await readAndUploadChunk(index) - if(uploadRequest.isErr()) { + if (uploadRequest.isErr()) { return err(ChucksManager) } else { ChucksManager.setResponse(index, uploadRequest.value as any) @@ -1052,9 +1119,9 @@ class PublicationAttachmentEntity { OriginalFileName: string blobFile: File toUpload = false; - chucksManager : ChucksManager + chucksManager: ChucksManager - constructor({base64, extension, blobFile = null, OriginalFileName = null, FileType}) { + constructor({ base64, extension, blobFile = null, OriginalFileName = null, FileType }) { this.FileBase64 = base64; this.FileExtension = extension; this.blobFile = blobFile @@ -1065,12 +1132,12 @@ class PublicationAttachmentEntity { } fixFileBase64() { - if(this.FileType == 'image' ) { - if(!this.FileBase64.startsWith('data:')) { + if (this.FileType == 'image') { + if (!this.FileBase64.startsWith('data:')) { this.FileBase64 = 'data:image/jpg;base64,' + this.FileBase64 } - } else if (this.FileType == 'video' ) { - if(!this.FileBase64.startsWith('data:') && !this.FileBase64.startsWith('http')) { + } else if (this.FileType == 'video') { + if (!this.FileBase64.startsWith('data:') && !this.FileBase64.startsWith('http')) { this.FileBase64 = 'data:video/mp4;base64,' + this.FileBase64 } @@ -1081,8 +1148,8 @@ class PublicationAttachmentEntity { this.toUpload = true } - setChunkManger (chunks: Chunks) { - this.chucksManager = new ChucksManager({chunks}) + setChunkManger(chunks: Chunks) { + this.chucksManager = new ChucksManager({ chunks }) } get hasChunkManager() { @@ -1090,7 +1157,7 @@ class PublicationAttachmentEntity { } } -interface IPublicationFormModelEntity { +interface IPublicationFormModelEntity { DateIndex: any DocumentId: any ProcessId: any @@ -1101,7 +1168,7 @@ interface IPublicationFormModelEntity { } class PublicationFormModel implements IPublicationFormModelEntity { - constructor() {} + constructor() { } DateIndex: any; DocumentId: any; ProcessId: any; @@ -1126,18 +1193,18 @@ class PublicationFormMV { } private getVideoFiles() { - return this.form.Files.filter( x => x.FileType == 'video') + return this.form.Files.filter(x => x.FileType == 'video') } private async upload(PublicationAttachmentEntity: PublicationAttachmentEntity) { const fileBlob = PublicationAttachmentEntity.blobFile; - const fileChunks = new Chunks({chunkSize: 100 }) + const fileChunks = new Chunks({ chunkSize: 100 }) fileChunks.setFile(fileBlob) PublicationAttachmentEntity.setChunkManger(fileChunks) - const ChucksManagers = new ChucksManager({chunks: fileChunks}) + const ChucksManagers = new ChucksManager({ chunks: fileChunks }) this.UploadFileUseCase.execute(ChucksManagers) } @@ -1146,9 +1213,9 @@ class PublicationFormMV { const videosFiles = this.getVideoFiles() - const videosFilesToUploads = videosFiles.filter( e => e.toUpload == true) + const videosFilesToUploads = videosFiles.filter(e => e.toUpload == true) - for(const file of videosFilesToUploads) { + for (const file of videosFilesToUploads) { this.upload(file) } } @@ -1161,17 +1228,17 @@ class Chunks { chunkSize: number private file: File - constructor({chunkSize}) { + constructor({ chunkSize }) { this.chunkSize = chunkSize * 1024 } - get totalChunks () { + 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 + const file = this.file return new Promise((resolve, reject) => { const reader = new FileReader(); @@ -1193,7 +1260,7 @@ class Chunks { async getChunks(i: number) { i-- - if(i < this.totalChunks) { + if (i < this.totalChunks) { const start = i * this.chunkSize; const end = Math.min(start + this.chunkSize, this.file.size); const chunk = await this.readChunk(start, end); @@ -1211,7 +1278,7 @@ interface IUploadResponse { class ChucksManager { chunks: Chunks - uploads: {[key: string]: IUploadResponse } = {} + uploads: { [key: string]: IUploadResponse } = {} path: string = undefined get uploadsCount() { @@ -1219,7 +1286,7 @@ class ChucksManager { } uploadFunc: Function - constructor({chunks}) { + constructor({ chunks }) { this.chunks = chunks } @@ -1234,4 +1301,7 @@ class ChucksManager { setResponse(index, UploadResponse) { this.uploads[index] = UploadResponse } + } + + diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index a9256d5a8..726ebb13e 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -4,4 +4,4 @@ import { doneITProd } from './suport/doneIt' import { DevDev } from './suport/dev' -export const environment: Environment = DevDev; +export const environment: Environment = oaprProd; From ba464a4f7377f45f076f10fb9fef804359abc8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 29 Jan 2024 08:25:27 +0100 Subject: [PATCH 2/4] solved --- package.json | 2 +- .../diploma-assinar/diploma-assinar.page.ts | 2 + .../diplomas/diploma/diploma.page.ts | 1 + .../new-publication/new-publication.page.ts | 11 ++- .../pages/publications/publications.page.ts | 2 +- src/app/services/publications.service.ts | 13 +++ .../new-publication/new-publication.page.html | 25 +++++- .../new-publication/new-publication.page.ts | 86 ++++++++++++++++++- 8 files changed, 129 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index fb200c89b..713d488b3 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@capacitor/push-notifications": "^5.1.0", "@capacitor/share": "^4.1.0", "@capacitor/storage": "^1.2.5", - "@capawesome/capacitor-file-picker": "^5.1.1", + "@capawesome/capacitor-file-picker": "^5.3.0", "@fortawesome/angular-fontawesome": "^0.9.0", "@fortawesome/fontawesome-free": "^5.15.3", "@fortawesome/fontawesome-svg-core": "^1.2.35", diff --git a/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts b/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts index 8132d5590..0064d51aa 100644 --- a/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts +++ b/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts @@ -479,6 +479,8 @@ export class DiplomaAssinarPage implements OnInit { try { const resd = await this.processes.GetDraftByID(strg).toPromise(); + console.log('DRAFT FFF',resd) + let object = { "ApplicationId": "", "Assunto": resd.data.description, diff --git a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts index b4e127dbf..549dcf098 100644 --- a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts +++ b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts @@ -537,6 +537,7 @@ export class DiplomaPage implements OnInit { console.log('List of ids', strg) const resd = await this.processes.GetDraftByID(strg).toPromise() + console.log('DRAFT FFF',resd) let object = { "ApplicationId": "", "Assunto": resd.data.description, 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 7ea1fe1d3..4fa09463c 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -195,7 +195,8 @@ export class NewPublicationPage implements OnInit { this.photoOrVideo = false; let fileObject = { FileBase64: this.removeTextBeforeSlash(picture, ','), - FileExtension: capturedImage.format + FileExtension: capturedImage.format, + OriginalFileName: 'image' } this.seletedContent.push(fileObject) @@ -253,7 +254,7 @@ export class NewPublicationPage implements OnInit { let fileObject = { FileBase64: content.data, FileExtension: 'mp4', - OriginalFileName: 'record' + OriginalFileName: 'video' } this.seletedContent.push(fileObject) }) @@ -293,7 +294,8 @@ export class NewPublicationPage implements OnInit { this.filecontent = true; let fileObject = { FileBase64: content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/') + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'video' } this.seletedContent.push(fileObject) }) @@ -485,7 +487,7 @@ export class NewPublicationPage implements OnInit { Title: this.pub.Title, Message: this.pub.Message, DatePublication: date, - OriginalFileName: this.capturedImageTitle, + OriginalFileName: this.capturedImageTitle || 'foto', Files: this.seletedContent, /* FileExtension: 'jpeg', */ } @@ -513,6 +515,7 @@ export class NewPublicationPage implements OnInit { this.close(); this.httpErrorHandle.httpsSucessMessagge('Criar publicação') window["sharedContent"] = null; + window["endSharedContent"] = null; this.close(); } catch (error) { diff --git a/src/app/pages/publications/publications.page.ts b/src/app/pages/publications/publications.page.ts index 019edb3b9..5ffd706d5 100644 --- a/src/app/pages/publications/publications.page.ts +++ b/src/app/pages/publications/publications.page.ts @@ -81,7 +81,7 @@ export class PublicationsPage implements OnInit { ) { this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]; this.days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"]; - + this.intent = window["sharedContent"] } diff --git a/src/app/services/publications.service.ts b/src/app/services/publications.service.ts index 143defd21..674409284 100644 --- a/src/app/services/publications.service.ts +++ b/src/app/services/publications.service.ts @@ -218,6 +218,8 @@ GetIdsPublicationNext(id:any){ //my last tries CreatePublication(folderId:any,body:any){ + + console.log('body publi', body) const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/v2/posts'; let params = new HttpParams(); @@ -226,6 +228,17 @@ GetIdsPublicationNext(id:any){ headers: this.headers, /* params: params */ }; + +/* this.http.post(`${geturl}`, body, options).subscribe( + (resposta) => { + console.log('Resposta da solicitação POST:', resposta); + }, + (erro) => { + console.error('Erro na solicitação POST:', erro); + }); + */ + + return this.http.post(`${geturl}`, body, options) } diff --git a/src/app/shared/publication/new-publication/new-publication.page.html b/src/app/shared/publication/new-publication/new-publication.page.html index c82a02b8e..c44017053 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -70,11 +70,16 @@ >
--> - + + @@ -102,7 +107,7 @@ -
+
Video
-
+ +
+ +
+ + +
+
+ Galeria +
+
+
+ +
diff --git a/src/app/shared/publication/new-publication/new-publication.page.ts b/src/app/shared/publication/new-publication/new-publication.page.ts index c89b2f9f6..06eacfc04 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -19,6 +19,7 @@ import { CMAPIService } from "src/app/shared/repository/CMAPI/cmapi.service"; import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx'; import { Filesystem, Directory, Encoding, FilesystemDirectory } from '@capacitor/filesystem'; import { Platform } from '@ionic/angular'; +import { Capacitor } from '@capacitor/core'; enum ActionType { newRapid = "1", @@ -184,7 +185,8 @@ export class NewPublicationPage implements OnInit { this.photoOrVideo = false; let fileObject = { FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg', '/') + FileExtension: this.removeTextBeforeSlash('jpeg', '/'), + OriginalFileName: 'imagem' } const FileExtension = this.removeTextBeforeSlash('jpeg', '/') @@ -228,7 +230,8 @@ export class NewPublicationPage implements OnInit { ).then((picture) => { let fileObject = { FileBase64: picture, - FileExtension: this.removeTextBeforeSlash('jpeg', '/') + FileExtension: this.removeTextBeforeSlash('jpeg', '/'), + OriginalFileName: 'image' } const FileExtension = this.removeTextBeforeSlash('jpeg', '/') @@ -260,9 +263,22 @@ export class NewPublicationPage implements OnInit { result.files.forEach(async blobFile => { console.log(blobFile) if (this.checkFileType.checkFileType(blobFile.mimeType) == 'image' || this.checkFileType.checkFileType(blobFile.mimeType) == 'video') { - console.log() + /* console.log('converte new way',this.getBase64(blobFile)) */ + + /* const blob = await fetch( + Capacitor.convertFileSrc(blobFile.path) + ).then(r => r.blob()); */ + + /* console.log(await blob.arrayBuffer()); + + + + console.log("base64 :data:video/mp4;base64,",this.arrayBufferToBase64(await blob.arrayBuffer())) */ + this.convertBlobToBase64(blobFile.blob).then((value) => { + console.log(value) + this.filesSizeSum = this.filesSizeSum + blobFile.size if (this.fileSizeToMB(this.filesSizeSum) <= 20) { @@ -290,6 +306,8 @@ export class NewPublicationPage implements OnInit { this.httpErroHandle.validationMessagge('filessize'); } + }).catch((erro) => { + console.log(erro) }) } else { this.httpErroHandle.validationMessagge('filetype'); @@ -297,6 +315,9 @@ export class NewPublicationPage implements OnInit { }); + + + /* this.capturedImage = 'data:image/jpeg;base64,' +capturedImage.base64String; this.capturedImageTitle = 'foto'; @@ -320,6 +341,49 @@ export class NewPublicationPage implements OnInit { }; + async loadVideoTablet() { + + const result = await FilePicker.pickMedia + ({ + multiple: true, + }); + console.log(result.files) + result.files.forEach(element => { + + this.filesSizeSum = this.filesSizeSum + element.size + if (this.fileSizeToMB(this.filesSizeSum) <= 20) { + if (this.checkFileType.checkFileType(element.mimeType) == 'image' || this.checkFileType.checkFileType(element.mimeType) == 'video') { + let resultUrl = decodeURIComponent(element.path); + try { + Filesystem.readFile({ path: resultUrl }) + + .then(async (content) => { + console.log(result) + console.log(content) + this.filecontent = true; + let fileObject = new PublicationAttachmentEntity ({ + base64: content.data, + extension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'video', + FileType: this.checkFileType.checkFileType( this.removeTextBeforeSlash(element.mimeType, '/')) + }) + this.seletedContent.push(fileObject) + }) + .catch((err) => console.error(err)); + } catch (error) { + console.log('upload video error: ', error) + } + + } + } else { + if (this.seletedContent.length === 0) + this.filesSizeSum = 0 + + this.httpErrorHandle.validationMessagge('filessize') + } + }); + }; + runValidation() { this.validateFrom = true @@ -551,9 +615,18 @@ export class NewPublicationPage implements OnInit { resolve(reader.result) } reader.readAsDataURL(blob) - }) + },) } + getBase64(file) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = () => resolve(reader.result); + reader.onerror = error => reject(error); + }); + } + removeTextBeforeSlash(inputString, mark) { if (inputString.includes(mark)) { const parts = inputString.split(mark); @@ -957,6 +1030,11 @@ export class NewPublicationPage implements OnInit { if (!this.platform.is('desktop')) return true; } + + checkDesktop() { + if (this.platform.is('desktop')) + return true; + } } // class UploadFileUseCase { From 78c6ac2f36c0f45a45f84de70f0b8ee4cbf17ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 29 Jan 2024 13:43:49 +0100 Subject: [PATCH 3/4] diplmas signaure solved --- src/app/models/dailyworktask.model.ts | 3 +- .../diploma-assinar/diploma-assinar.page.ts | 10 +++--- .../diplomas/diploma/diploma.page.ts | 1 + .../expediente-detail.page.ts | 3 +- .../expediente-pr/expediente-pr.page.ts | 3 +- .../new-publication/new-publication.page.ts | 34 ++++++++++++++++--- .../deploma-options/deploma-options.page.ts | 8 +++-- .../event-details-documents-options.page.ts | 2 ++ .../new-publication/new-publication.page.ts | 3 +- 9 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/app/models/dailyworktask.model.ts b/src/app/models/dailyworktask.model.ts index 452b50758..26884ad0b 100644 --- a/src/app/models/dailyworktask.model.ts +++ b/src/app/models/dailyworktask.model.ts @@ -170,7 +170,8 @@ export interface expedienteTask { Status : string DispatchNumber: any AttachmentsProcessLastInstanceID: any - InstanceID: any + InstanceID: any, + DraftIds: string } export interface ExpedienteTask { diff --git a/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts b/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts index 0064d51aa..5cadb1f40 100644 --- a/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts +++ b/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts @@ -129,11 +129,14 @@ export class DiplomaAssinarPage implements OnInit { "TaskStartDate": res.taskStartDate, "InstanceID": res.workflowInstanceDataFields.InstanceID, "FolderID": res.workflowInstanceDataFields.FolderID, + "DraftIds": res.workflowInstanceDataFields?.DraftIds } + console.log('draftidsss',res.workflowInstanceDataFields.DraftIds); this.fulltask = res; let stringDraft = res.workflowInstanceDataFields.DraftIds; - this.DraftIds = stringDraft + this.DraftIds = res.workflowInstanceDataFields.DraftIds + console.log('draftidsss 111',this.DraftIds); let split_stringDraft = stringDraft?.split(";").filter(Boolean); @@ -233,11 +236,9 @@ export class DiplomaAssinarPage implements OnInit { "dataFields": { "ReviewUserComment": '', "InstanceIDNew": this.task.InstanceID, - "DraftIds": "", }, "AttachmentList": { "ProcessInstanceID": this.task.InstanceID, - "DraftIds": null, "Attachments": [] }, } @@ -269,10 +270,11 @@ export class DiplomaAssinarPage implements OnInit { modal.onDidDismiss().then(async (res) => { const data = res.data if (data == "Yes") { + console.log(' diploma Draft draft',this.task.DraftIds) let body = { "InstanceId": this.task.InstanceID, "FolderId": this.task.FolderID, - "DraftIds": this.DraftIds, + "DraftIds": this.task.DraftIds, "OriginalFileName": this.DraftNames } diff --git a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts index 549dcf098..acf778492 100644 --- a/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts +++ b/src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.ts @@ -137,6 +137,7 @@ export class DiplomaPage implements OnInit { "WorkflowName": res.workflowDisplayName, "DeadlineType": res.workflowInstanceDataFields.DeadlineType, "activityInstanceName": res.activityInstanceName, + "DraftIds": res.workflowInstanceDataFields?.DraftIds } this.fulltask = res; console.log('Diploma anexo',this.fulltask.Documents ) diff --git a/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts b/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts index e457802f2..09d367c4d 100644 --- a/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts +++ b/src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts @@ -370,7 +370,8 @@ export class ExpedienteDetailPage implements OnInit { "Status": res.workflowInstanceDataFields.Status, "DispatchNumber": res.workflowInstanceDataFields.DispatchNumber, "AttachmentsProcessLastInstanceID": res.workflowInstanceDataFields.AttachmentsProcessLastInstanceID, - "InstanceID": res.workflowInstanceDataFields.InstanceID + "InstanceID": res.workflowInstanceDataFields.InstanceID, + "DraftIds": res.workflowInstanceDataFields?.DraftIds } this.fulltask = res; diff --git a/src/app/pages/gabinete-digital/expedientes-pr/expediente-pr/expediente-pr.page.ts b/src/app/pages/gabinete-digital/expedientes-pr/expediente-pr/expediente-pr.page.ts index 6859b51f8..44eab1ef5 100644 --- a/src/app/pages/gabinete-digital/expedientes-pr/expediente-pr/expediente-pr.page.ts +++ b/src/app/pages/gabinete-digital/expedientes-pr/expediente-pr/expediente-pr.page.ts @@ -132,7 +132,8 @@ export class ExpedientePrPage implements OnInit { "activityInstanceName": res.activityInstanceName, "Status": res.workflowInstanceDataFields.Status, "Deadline": res.deadline, - "TaskStartDate": res.taskStartDate + "TaskStartDate": res.taskStartDate, + "DraftIds": res.workflowInstanceDataFields?.DraftIds } this.fulltask = res; 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 4fa09463c..620b320ca 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -252,7 +252,7 @@ export class NewPublicationPage implements OnInit { .then(async (content) => { this.filecontent = true; let fileObject = { - FileBase64: content.data, + FileBase64: 'data:video/mp4;base64,'+content.data, FileExtension: 'mp4', OriginalFileName: 'video' } @@ -292,11 +292,21 @@ export class NewPublicationPage implements OnInit { console.log(result) console.log(content) this.filecontent = true; - let fileObject = { - FileBase64: content.data, - FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), - OriginalFileName: 'video' + let fileObject; + if(this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") { + fileObject = { + FileBase64: 'data:video/mp4;base64,'+ content.data, + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'video' + } + } else { + fileObject = { + FileBase64: content.data, + FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'), + OriginalFileName: 'image' + } } + this.seletedContent.push(fileObject) }) .catch((err) => console.error(err)); @@ -479,6 +489,18 @@ export class NewPublicationPage implements OnInit { const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss') + /* this.seletedContent = this.seletedContent.map((e) => { + if(e.FileExtension == "mp4") { + return { + FileBase64: e.FileBase64, + FileExtension: 'data:video/mp4;base64,'+e.FileExtension, + OriginalFileName: "video", + } + } + + return e + }) */ + /* if (this.capturedImage != '') { */ this.publication = { DateIndex: date, @@ -511,6 +533,8 @@ export class NewPublicationPage implements OnInit { try { + + await this.publications.CreatePublication(this.folderId, this.publication).toPromise(); this.close(); this.httpErrorHandle.httpsSucessMessagge('Criar publicação') diff --git a/src/app/shared/popover/deploma-options/deploma-options.page.ts b/src/app/shared/popover/deploma-options/deploma-options.page.ts index ee7309384..e7dfd6241 100644 --- a/src/app/shared/popover/deploma-options/deploma-options.page.ts +++ b/src/app/shared/popover/deploma-options/deploma-options.page.ts @@ -217,11 +217,11 @@ export class DiplomaOptionsPage implements OnInit { "dataFields": { "ReviewUserComment": note, "InstanceIDNew": this.task.InstanceID, - "DraftIds": "", + /* "DraftIds": "", */ }, "AttachmentList": { "ProcessInstanceID": this.task.InstanceID, - "DraftIds": null, + /* "DraftIds": null, */ "Attachments": [] }, } @@ -256,10 +256,12 @@ export class DiplomaOptionsPage implements OnInit { modal.onDidDismiss().then(async (res) => { const data = res.data if (data == "Yes") { + + console.log(' diploma options Draft draft',this.DraftIds) let body = { "InstanceId": this.task.InstanceID, "FolderId": this.task.FolderID, - "DraftIds": this.DraftIds, + "DraftIds": this.task.DraftIds, "OriginalFileName": this.DraftNames } const loader = this.toastService.loading() diff --git a/src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.ts b/src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.ts index 878a2e572..f847f7f78 100644 --- a/src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.ts +++ b/src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.ts @@ -148,6 +148,8 @@ export class EventDetailsDocumentsOptionsPage implements OnInit { modal.onDidDismiss().then(async (res) => { const data = res.data if(data == "Yes") { + + console.log(' event detais Draft draft',this.DraftIds) let body = { "InstanceId": this.InstanceID, "FolderId": this.FolderID, diff --git a/src/app/shared/publication/new-publication/new-publication.page.ts b/src/app/shared/publication/new-publication/new-publication.page.ts index 06eacfc04..4f6f9b84c 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -359,7 +359,7 @@ export class NewPublicationPage implements OnInit { .then(async (content) => { console.log(result) - console.log(content) + console.log('load video tablet base64',content) this.filecontent = true; let fileObject = new PublicationAttachmentEntity ({ base64: content.data, @@ -1002,6 +1002,7 @@ export class NewPublicationPage implements OnInit { .then(async (content) => { this.filecontent = true; + console.log('',content) let fileObject = new PublicationAttachmentEntity({ base64: content.data, extension: 'mp4', From 07939149eed87069afeba1f5dbd4658c380fe1a4 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 29 Jan 2024 15:50:32 +0100 Subject: [PATCH 4/4] add defualt calendar --- src/app/pages/agenda/agenda.page.html | 2 +- src/app/pages/agenda/agenda.page.ts | 22 +++- src/app/services/events.service.ts | 142 +++++++++++++++----------- 3 files changed, 99 insertions(+), 67 deletions(-) diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index 68412c638..f4ceae277 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -140,7 +140,7 @@ -
+
{ + this.setCalendarByDefault(true) + const selectedCalendarIds = this.getSelectedAgendaCalendars(); + this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds) + + this.tigerUpdate() + }) } tigerUpdate() { @@ -257,7 +265,7 @@ export class AgendaPage implements OnInit { ngOnInit() { - this.setCalendarByDefault() + this.setCalendarByDefault(false) const selectedCalendarIds = this.getSelectedAgendaCalendars(); this.listToPresent = this.CalendarStore.getEventsByCalendarIds(selectedCalendarIds) @@ -338,14 +346,20 @@ export class AgendaPage implements OnInit { }, 250) } - setCalendarByDefault() { - if (!this.CalendarName) { - if (this.eventService.calendarNamesAry.includes('Meu calendario')) { + setCalendarByDefault(force) { + if (!this.CalendarName || force) { + const prObject = this.eventService.calendarNamesAry.find(e => e?.RoleId == 100000014) + + if(prObject) { + console.log({prObject}) + this.CalendarName = prObject.Fullname + } else if (this.eventService.calendarNamesAry.includes('Meu calendario')) { this.CalendarName = 'Meu calendario'; } else { this.CalendarName = this.eventService.calendarNamesAry[0] } } + } //Go to the next view of the calendar month/week/day diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index ccd4d9f4e..9a2db9bc3 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -35,10 +35,10 @@ export class EventsService { headersSharedOficial: HttpHeaders; headersSharedPessoal: HttpHeaders; - + calendarIds = [] usersCalendarIds = [] - + hasSharedCalendar = false; hasSharedOficial: boolean = false; hasSharedPessoal: boolean = false; @@ -48,7 +48,7 @@ export class EventsService { hasOwnCalendar = false calendarNames = {} - + calendarNamesAry = [] calendarNamesAryNoPr = [] calendarNamesAryNoPrNMD = [] @@ -62,9 +62,13 @@ export class EventsService { myCalendarNames = {} hasAnyCalendar = false - + HasMdGPR = false + onLoadCalendars: Function[] =[] + loadCalendars = false + + onCalendarFinishLoad = new Subscribe({execute : false, deleteOnExecute: true}) constructor( @@ -81,7 +85,7 @@ export class EventsService { } async setHeader () { - + this.headers = new HttpHeaders();; this.headersMdOficial = new HttpHeaders();; this.headersMdPessoal = new HttpHeaders();; @@ -95,7 +99,7 @@ export class EventsService { this.headerOwnOficial= new HttpHeaders();; this.headerOwnPessoal= new HttpHeaders();; - + this.headerSharedOficial= new HttpHeaders();; this.headerSharedPessoal= new HttpHeaders();; @@ -106,7 +110,7 @@ export class EventsService { this.calendarRole = [] this.calendrFullName = []; this.calendarIds = [] - + this.calendarNamesAry = [] this.calendarNamesType = {} this.calendarNamesAryNoPr = [] @@ -151,10 +155,10 @@ export class EventsService { } } - + for (let sharedCalendar of SessionStore.user.SharedCalendars) { this.hasAnyCalendar = true - + if (sharedCalendar.CalendarName == 'Oficial') { this.hasSharedOficial = true @@ -288,17 +292,17 @@ export class EventsService { this.calendarNames[sharedCalendar.CalendarId] = e.FullName this.myCalendarNames[sharedCalendar.CalendarId] = e.FullName - + if(!this.calendarNamesAry.find(x => x.Role == e.Role)) { - - + + let objectShared = { "Fullname": e.FullName, "Role": e.Role, "OwnerUserId": sharedCalendar.OwnerUserId, "RoleId": sharedCalendar.CalendarRoleId } - + this.calendarNamesAry.push(objectShared) if(e.Role == 'Presidente da República') { @@ -306,7 +310,7 @@ export class EventsService { } else { this.calendarNamesAryNoPr.push(objectShared) } - + this.calendarNamesType[e.FullName] = {} } @@ -315,7 +319,7 @@ export class EventsService { this.calendarNamesType[e.FullName]['RoleId'] = sharedCalendar.CalendarRoleId this.calendarNamesType[e.FullName]['OwnerId'] = sharedCalendar.OwnerUserId } - + } this.calendarNamesAryNoPrNMD = this.calendarNamesAryNoPr.filter((e)=> { @@ -329,7 +333,7 @@ export class EventsService { this.HasMdGPR = this.calendarNamesAryNoPr.find( (e)=> { if(e.Role == 'Ministro e Director do Gabinete do PR') { - return true + return true } return false }) @@ -341,7 +345,7 @@ export class EventsService { this.hasAnyCalendar = true } - + this.calendarNamesAryReverse = this.calendarNamesAry.reverse(); this.onCalendarFinishLoad.executor(); @@ -366,8 +370,22 @@ export class EventsService { } })(); - + } + + + this.onLoadCalendars.forEach(e=> e()); + this.loadCalendars = true + } + + + registerOnLoadCalendars(e: Function) { + if( this.loadCalendars) { + e() + } else { + this.onLoadCalendars.push(e) + } + } @@ -397,7 +415,7 @@ export class EventsService { isMyEvent(event: any) { - + for (let calendar of SessionStore.user.OwnerCalendars) { if(event.CalendarId == calendar.CalendarId) { return true @@ -409,14 +427,14 @@ export class EventsService { return false } } - + return false } - + detectCalendarNameByCalendarId(calendarId) { - + for ( const property in this.calendarNamesType) { if(this.calendarNamesType[property]?.['Oficial']) { if(this.calendarNamesType[property]['OficialId'] == calendarId) { @@ -429,7 +447,7 @@ export class EventsService { } } } - + } @@ -542,7 +560,7 @@ export class EventsService { } } } - + const resFinal = prO.concat(prP); return new Promise(resolve => { return resolve(resFinal) @@ -621,14 +639,14 @@ export class EventsService { header = header.set('CalendarRoleId', agendasCalendar.CalendarRoleId); header = header.set('CalendarName', agendasCalendar.CalendarName); - + let geturl = environment.apiURL + 'calendar/GetEvents'; - + let params = new HttpParams(); - + params = params.set("StartDate", startdate); params = params.set("EndDate", enddate); - + let options = { headers: header, params: params @@ -655,12 +673,12 @@ export class EventsService { header = header.set('CalendarName', sharedCalendar.CalendarName); let geturl = environment.apiURL + 'calendar/GetEvents'; - + let params = new HttpParams(); - + params = params.set("StartDate", startdate); params = params.set("EndDate", enddate); - + let options = { headers: header, params: params @@ -686,7 +704,7 @@ export class EventsService { params = params.set("StartDate", startdate); params = params.set("EndDate", enddate); - + let options = { headers: this.headerSharedOficial, @@ -725,7 +743,7 @@ export class EventsService { } } - + const resFinal = prO.concat(prP); return new Promise(resolve => { @@ -746,7 +764,7 @@ export class EventsService { headers: this.headersSharedOficial, params: params }; - + return this.http.get(`${geturl}`, options); } @@ -814,13 +832,13 @@ export class EventsService { const calendar = this.DetectCalendars(calendarId) const header = this.makeHeader(calendar) - + if(header) { let options = { headers: header, params: params } - + return this.http.get(`${geturl}`, options); } else { @@ -875,18 +893,18 @@ export class EventsService { else if (SessionStore.user.Profile == 'PR') { this.headers = this.headersPrOficial; } else { - + const headers = [ this.headerSharedOficial, this.headerSharedPessoal, this.headerOwnPessoal, this.headerOwnOficial - ] - + ] + const header = headers.find((header)=> { return header?.get('CalendarId')?.includes(CalendarId) }) - + this.headers = header } } @@ -903,12 +921,12 @@ export class EventsService { this.headerSharedPessoal, this.headerOwnPessoal, this.headerOwnOficial - ] - + ] + const header = headers.find((header)=> { return header?.get('CalendarId')?.includes(CalendarId) }) - + this.headers = header } } @@ -920,13 +938,13 @@ export class EventsService { return this.http.put(`${puturl}`, event, options).pipe( catchError(err => { - + this.offlinemanager.storeRequestData('eventEdit', arrayReq); throw new Error(err); }) ) } - + changeAgenda(body: any) { const puturl = environment.apiURL + 'Calendar/MoveEvent'; @@ -948,7 +966,7 @@ export class EventsService { let options: any; switch (calendarName) { case 'Oficial': - + options = { headers: this.headersMdOficial, params: params @@ -956,14 +974,14 @@ export class EventsService { break; case 'Pessoal': - + options = { headers: this.headersMdPessoal, params: params }; break; } - + return this.http.post(`${puturl}`, event, options) } @@ -980,7 +998,7 @@ export class EventsService { let options: any; switch (calendarName) { case 'Oficial': - + options = { headers: this.headersPrOficial, params: params @@ -988,7 +1006,7 @@ export class EventsService { break; case 'Pessoal': - + options = { headers: this.headersPrPessoal, params: params @@ -1006,7 +1024,7 @@ export class EventsService { let params = new HttpParams(); const now = new Date(); - + event.TimeZone = now.toString().match(/([A-Z]+[\+-][0-9]+.*)/)[1]; event.Organizer = { "Id": SessionStore.user.UserId, @@ -1028,11 +1046,11 @@ export class EventsService { headers: header, params: params }; - + return this.http.post(`${puturl}`, event, options) } - + deleteEvent(eventid: string, eventDeleteType: number, calendarName: string) { let arrayReq = []; @@ -1084,7 +1102,7 @@ export class EventsService { return this.http.delete(`${puturl}`, options).pipe( catchError(err => { - + this.offlinemanager.storeRequestData('eventDelete', arrayReq); throw new Error(err); }) @@ -1143,8 +1161,8 @@ export class EventsService { this.headerSharedPessoal, this.headerOwnPessoal, this.headerOwnOficial - ] - + ] + const header = headers.find((header)=> { return header?.get('CalendarId')?.includes(calendarId) }) @@ -1159,20 +1177,20 @@ export class EventsService { return this.http.delete(`${puturl}`, options).pipe( catchError(err => { - + this.offlinemanager.storeRequestData('eventDelete', arrayReq); throw new Error(err); }) ) } else { - + } throw('header not found') } - + } @@ -1230,7 +1248,7 @@ export class EventsService { const calendar = this.DetectCalendars(CalendarId) const header = this.makeHeader(calendar) - + options = { headers: header, params: params @@ -1277,7 +1295,7 @@ export class EventsService { } break; } - + return this.http.post(`${geturl}`, body, options) } @@ -1326,4 +1344,4 @@ const token = { } -// decryptept token 873845982739845723987459823ouhfouidskfdjasklhdjfkusdhfliasdhfkljashdfkjhaskfhaskjdhfkasjdfhkjasdf \ No newline at end of file +// decryptept token 873845982739845723987459823ouhfouidskfdjasklhdjfkusdhfliasdhfkljashdfkjhaskfhaskjdhfkasjdfhkjasdf