diff --git a/package-lock.json b/package-lock.json index 1cc583623..b6f9964e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -91,6 +91,7 @@ "@logisticinfotech/ionic4-datepicker": "^1.4.4", "@ng-bootstrap/ng-bootstrap": "^9.1.2", "@ngx-translate/core": "^13.0.0", + "@ngxs/store": "^3.8.2", "@pdftron/pdfjs-express": "^8.0.1", "@sentry/angular": "7.73.0", "@sentry/capacitor": "^0.14.0", @@ -7464,6 +7465,22 @@ "rxjs": ">=6.5.3" } }, + "node_modules/@ngxs/store": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/@ngxs/store/-/store-3.8.2.tgz", + "integrity": "sha512-IovxuGQDEpB9VefmbTaV1k4hms4iZ4aS9gPVZOC+qzyfvpi7zrUEsjo+yT6FfVBmBg/RLUmPCtqArzbKU5XrLQ==", + "dependencies": { + "tslib": "^2.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/ngxs" + }, + "peerDependencies": { + "@angular/core": ">=12.0.0 <18.0.0", + "rxjs": ">=6.5.5" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -49120,6 +49137,14 @@ "tslib": "^2.0.0" } }, + "@ngxs/store": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/@ngxs/store/-/store-3.8.2.tgz", + "integrity": "sha512-IovxuGQDEpB9VefmbTaV1k4hms4iZ4aS9gPVZOC+qzyfvpi7zrUEsjo+yT6FfVBmBg/RLUmPCtqArzbKU5XrLQ==", + "requires": { + "tslib": "^2.2.0" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 005d29067..c7da3bcc2 100644 --- a/package.json +++ b/package.json @@ -105,6 +105,7 @@ "@logisticinfotech/ionic4-datepicker": "^1.4.4", "@ng-bootstrap/ng-bootstrap": "^9.1.2", "@ngx-translate/core": "^13.0.0", + "@ngxs/store": "^3.8.2", "@pdftron/pdfjs-express": "^8.0.1", "@sentry/angular": "7.73.0", "@sentry/capacitor": "^0.14.0", diff --git a/src/app/pages/publications/new-publication/new-publication.page.html b/src/app/pages/publications/new-publication/new-publication.page.html index 00b3395be..e6379fc96 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -40,7 +40,7 @@ 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 c33182032..302b4a61c 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.ts +++ b/src/app/pages/publications/new-publication/new-publication.page.ts @@ -25,12 +25,13 @@ import { FileService } from 'src/app/services/functions/file.service'; import { readAndCompressImage } from 'browser-image-resizer'; import { FilePicker } from '@capawesome/capacitor-file-picker'; import { CapacitorVideoPlayer } from 'capacitor-video-player'; -import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx'; +import { CaptureError, CaptureImageOptions, CaptureVideoOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx'; import { Capacitor } from '@capacitor/core'; 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 { CameraService } from "src/app/services/camera.service" const config = { quality: 0.5, maxWidth: 800, @@ -133,7 +134,9 @@ export class NewPublicationPage implements OnInit { public FileService: FileService, private mediaCapture: MediaCapture, public checkFileType: checkFileTypeService, - private FileValidatorService: FileValidatorService + private FileValidatorService: FileValidatorService, + private file: File, + private cameraService: CameraService ) { this.publicationType = this.navParams.get('publicationType'); @@ -161,12 +164,17 @@ export class NewPublicationPage implements OnInit { recursive: true }); - document.addEventListener("click", clickOutside, false); - function clickOutside(e) { - const inside = document.getElementById('container-multiselect').contains(e.target); - this.photoOrVideo = false; - console.log(this.photoOrVideo) - } + + try { + + document.addEventListener("click", clickOutside, false); + function clickOutside(e) { + const inside = document.getElementById('container-multiselect').contains(e.target); + this.photoOrVideo = false; + console.log(this.photoOrVideo) + } + } catch (error) {} + } // in use @@ -195,7 +203,8 @@ export class NewPublicationPage implements OnInit { this.photoOrVideo = false; let fileObject = { FileBase64: this.removeTextBeforeSlash(picture, ','), - FileExtension: capturedImage.format + FileExtension: capturedImage.format, + OriginalFileName: 'foto' } this.seletedContent.push(fileObject) @@ -232,6 +241,7 @@ export class NewPublicationPage implements OnInit { } async startVideoRecording() { + try { let options: CaptureImageOptions = { limit: 1 } const data: any = await this.mediaCapture.captureVideo(options) @@ -268,6 +278,7 @@ export class NewPublicationPage implements OnInit { } catch (error) { console.log('record video error: ', error) } + } async loadVideo() { @@ -290,7 +301,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: 'foto' } this.seletedContent.push(fileObject) }) @@ -334,24 +346,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' - + } - + } */ @@ -390,47 +402,19 @@ export class NewPublicationPage implements OnInit { if (this.publicationType == '3') { const loader = this.toastService.loading() - // has file - 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 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, - } + 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 { + /* else { this.publication = { DateIndex: this.publication.DateIndex, DocumentId: this.publication.DocumentId, diff --git a/src/app/pages/publications/view-publications/view-publications.page.html b/src/app/pages/publications/view-publications/view-publications.page.html index b120e6d89..fec91d0e3 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.html +++ b/src/app/pages/publications/view-publications/view-publications.page.html @@ -65,7 +65,7 @@ --> -
+
{{publication.Title}} 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 7a089f2c8..860492442 100644 --- a/src/app/pages/publications/view-publications/view-publications.page.ts +++ b/src/app/pages/publications/view-publications/view-publications.page.ts @@ -18,6 +18,7 @@ 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 { StopvideoService } from "src/app/services/stopvideo.service" +import { Result } from 'neverthrow'; @Component({ selector: 'app-view-publications', templateUrl: './view-publications.page.html', diff --git a/src/app/services/camera.service.ts b/src/app/services/camera.service.ts index 6ccc91648..1411691fc 100644 --- a/src/app/services/camera.service.ts +++ b/src/app/services/camera.service.ts @@ -1,19 +1,22 @@ import { Injectable } from '@angular/core'; +import { CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx'; import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera'; - +import { File } from "@awesome-cordova-plugins/file/ngx" @Injectable({ providedIn: 'root' }) export class CameraService { - constructor() { } + constructor( + private mediaCapture: MediaCapture, + private file: File) { } - async takePicture(){ + async takePicture() { return new Promise(async (resolve, reject)=>{ - + const image = await Camera.getPhoto({ quality: 50, @@ -21,16 +24,38 @@ export class CameraService { resultType: CameraResultType.Uri, source: CameraSource.Camera // Camera, Photos or Prompt! }); - + if (image) { resolve(image) - + } else { reject('Error saving image') } - + //this.capturedImage = this.capturedImage; }) } + + async startRecording() { + try { + let options: CaptureImageOptions = { limit: 1} + + const data: MediaFile[] = (await this.mediaCapture.captureVideo(options) as any ) + const video = data[0] + + let dir = video.fullPath.split("/") + dir.pop() + let fromDir = dir.join("/") + let toDir = this.file.dataDirectory + + const response = await this.file.copyFile(fromDir, video.name, toDir, video.name ) + console.log({response}) + + } catch(e) { + console.log(e) + } + } + + nice() {} } diff --git a/src/app/services/camera/camera.service.spec.ts b/src/app/services/camera/camera.service.spec.ts new file mode 100644 index 000000000..73b57d3a5 --- /dev/null +++ b/src/app/services/camera/camera.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { CameraService } from './camera.service'; + +describe('CameraService', () => { + let service: CameraService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(CameraService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/camera/camera.service.ts b/src/app/services/camera/camera.service.ts new file mode 100644 index 000000000..73fa4b515 --- /dev/null +++ b/src/app/services/camera/camera.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class CameraService { + + constructor() { } +} 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 63ca8ff55..dd1bf0ef9 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -51,12 +51,12 @@ - + @@ -102,8 +102,6 @@
--> - -
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 f2a7f8f06..d941b1dc5 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -130,7 +130,16 @@ export class NewPublicationPage implements OnInit { } console.log('edit',this.publication) this.pub = this.publication; - this.seletedContent = this.publication.Files; + this.seletedContent = this.publication.Files.map( e => { + return new PublicationAttachmentEntity( + { + base64: e.FileBase64, + extension: e.FileExtension, + OriginalFileName: e.OriginalFileName, + FileType: this.checkFileType.checkFileType(e.FileExtension) + } + ) + }) this.showLoader = false; }, (error) => { console.log(error) @@ -322,52 +331,47 @@ export class NewPublicationPage implements OnInit { if (this.publicationType == ActionType.edit) { - if (!this.publication?.OriginalFileName || !this.pub.OriginalFileName) { - - if (this.pub?.OriginalFileName) { - console.log('this.pub', this.pub) - } - throw ('no this.publication.OriginalFileName') - - } const loader = this.toastService.loading() - if (this.seletedContent.length > 0) { - 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 || 'foto', - Files: this.seletedContent, - } + 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, + Files: this.seletedContent, + } - try { - const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() + this.publication.Files = this.publication.Files.map( e => ({ + FileBase64: e.FileBase64, + FileExtension: e.FileExtension, + OriginalFileName: 'foto' + })) - this.httpErroHandle.httpsSucessMessagge('Editar publicação') - console.log({ response }) + try { + const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise() + + this.httpErroHandle.httpsSucessMessagge('Editar publicação') + console.log({ response }) + + this.goBack(); + + } catch (error) { + this.httpErroHandle.httpStatusHandle(error) + if (error.status == 404) { + this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId) this.goBack(); - - } catch (error) { - this.httpErroHandle.httpStatusHandle(error) - if (error.status == 404) { - this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId) - this.goBack(); - } - } finally { - loader.remove() } - - } else { - }/* - else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { // + } finally { + loader.remove() + } +/* + else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { // this.publication = { DateIndex: this.publication.DateIndex, @@ -412,6 +416,16 @@ export class NewPublicationPage implements OnInit { } + // this.publicationFormMV.setDataToFrom(this.publication) + + // this.publicationFormMV.uploadVideosFiles() + + this.publication.Files = this.publication.Files.map( e => ({ + FileBase64: e.FileBase64, + FileExtension: e.FileExtension, + OriginalFileName: 'foto' + })) + const loader = this.toastService.loading() try { @@ -1043,7 +1057,7 @@ class PublicationAttachmentEntity { this.FileBase64 = 'data:image/jpg;base64,' + this.FileBase64 } } else if (this.FileType == 'video' ) { - if(!this.FileBase64.startsWith('data:')) { + if(!this.FileBase64.startsWith('data:') && !this.FileBase64.startsWith('http')) { this.FileBase64 = 'data:video/mp4;base64,' + this.FileBase64 } diff --git a/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts b/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts index b2657bb6f..9b489d57a 100644 --- a/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts +++ b/src/app/shared/publication/view-publications/publication-detail/publication-detail.page.ts @@ -73,17 +73,17 @@ export class PublicationDetailPage implements OnInit { if(localPublication?.ProcessId) { console.log('console.log local storage') - + this.publication = localPublication console.log('Local publication',this.publication) } else { console.log('API res') - + this.showLoader = true; this.publications.GetPublicationWithArrayOfFilesById(this.publicationId).subscribe(res => { - + this.publication = this.publicationPipe.itemList(res) console.log('API pub', this.publication) @@ -96,12 +96,12 @@ export class PublicationDetailPage implements OnInit { if(error.status == 404) { this.publicationFolderService.deletePost(this.folderId, this.publicationId) } - + this.goBack(); this.httpErrorHandle.httpStatusHandle(error) }); } - + } close() { @@ -121,7 +121,7 @@ export class PublicationDetailPage implements OnInit { if(window['app-view-publications-page-doRefresh']) { window['app-view-publications-page-doRefresh']() } - + this.goBackToViewPublications.emit(); } catch (error) { @@ -138,7 +138,7 @@ export class PublicationDetailPage implements OnInit { } async editPost(publicationType:any) { - + if(window.innerWidth < 701){ const modal = await this.modalController.create({ @@ -186,10 +186,4 @@ export class PublicationDetailPage implements OnInit { modal.present(); } - - - - - - } diff --git a/src/app/shared/publication/view-publications/view-publications.page.html b/src/app/shared/publication/view-publications/view-publications.page.html index 88e03720e..29de9e485 100644 --- a/src/app/shared/publication/view-publications/view-publications.page.html +++ b/src/app/shared/publication/view-publications/view-publications.page.html @@ -79,7 +79,7 @@
s --> -
+
{{publication.Title}} 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 ad5e68ac6..ec82302c1 100644 --- a/src/app/shared/publication/view-publications/view-publications.page.ts +++ b/src/app/shared/publication/view-publications/view-publications.page.ts @@ -227,8 +227,6 @@ export class ViewPublicationsPage implements OnInit { this.publicationFolderService.publicationList[folderId].push(publicationDetails) } else { - // console.log("names"); - let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex]) let b: any = Object.assign({}, publicationDetails) diff --git a/src/app/store/publication-folder.service.ts b/src/app/store/publication-folder.service.ts index 7221ea60e..b30a1dbe8 100644 --- a/src/app/store/publication-folder.service.ts +++ b/src/app/store/publication-folder.service.ts @@ -217,11 +217,11 @@ export class PublicationFolderService { PublicationHasImage(Publication: Publication) { - return Publication.Files[0].FileBase64 != '' && Publication.Files[0].FileBase64 != "data:image/jpg;base64,null" + return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null" } hasCapturedImage(Publication: Publication) { - return Publication.Files[0].FileBase64 != '' && Publication.Files[0].FileBase64 != "data:image/jpg;base64,null" + return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null" } }