From df8876f436da0e20ceadd00516c9c48e4bcdc6cc Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 23 Aug 2021 16:00:58 +0100 Subject: [PATCH] fix --- .../new-publication/new-publication.page.html | 2 +- src/app/services/file/file-loader.service.ts | 2 +- .../rules/publication.service.spec.ts | 16 ++++ src/app/services/rules/publication.service.ts | 9 +++ .../new-publication/new-publication.page.html | 34 ++++---- .../new-publication/new-publication.page.ts | 81 ++++++------------- 6 files changed, 71 insertions(+), 73 deletions(-) create mode 100644 src/app/services/rules/publication.service.spec.ts create mode 100644 src/app/services/rules/publication.service.ts 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 74e54add6..e6bb1d2fb 100644 --- a/src/app/pages/publications/new-publication/new-publication.page.html +++ b/src/app/pages/publications/new-publication/new-publication.page.html @@ -63,7 +63,7 @@ - + diff --git a/src/app/services/file/file-loader.service.ts b/src/app/services/file/file-loader.service.ts index d1de9fc19..997c3439f 100644 --- a/src/app/services/file/file-loader.service.ts +++ b/src/app/services/file/file-loader.service.ts @@ -8,7 +8,7 @@ export class FileLoaderService { constructor() { } - loadeFile({ type = 'file'}): HTMLInputElement { + createInput({ type = 'file'}): HTMLInputElement { let input = document.createElement('input'); input.type = type; diff --git a/src/app/services/rules/publication.service.spec.ts b/src/app/services/rules/publication.service.spec.ts new file mode 100644 index 000000000..3d3effb95 --- /dev/null +++ b/src/app/services/rules/publication.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { PublicationService } from './publication.service'; + +describe('PublicationService', () => { + let service: PublicationService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(PublicationService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/rules/publication.service.ts b/src/app/services/rules/publication.service.ts new file mode 100644 index 000000000..0470a7dfa --- /dev/null +++ b/src/app/services/rules/publication.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class PublicationService { + + 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 783d56d80..10dd8c922 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.html +++ b/src/app/shared/publication/new-publication/new-publication.page.html @@ -16,7 +16,7 @@ -
+
@@ -29,7 +29,7 @@
Fotografia Anexada
-
+
image
@@ -43,26 +43,32 @@
- - - + - - +
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 db2e9b480..04c3f191b 100644 --- a/src/app/shared/publication/new-publication/new-publication.page.ts +++ b/src/app/shared/publication/new-publication/new-publication.page.ts @@ -8,7 +8,8 @@ import { PhotoService } from 'src/app/services/photo.service'; import { Camera, CameraOptions } from '@ionic-native/camera/ngx'; import { ToastService } from 'src/app/services/toast.service'; import { FormControl, FormGroup, Validators } from '@angular/forms'; - +import { FileLoaderService } from 'src/app/services/file/file-loader.service' +import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; @Component({ selector: 'app-new-publication', templateUrl: './new-publication.page.html', @@ -51,6 +52,8 @@ export class NewPublicationPage implements OnInit { private camera: Camera, private animationController: AnimationController, private toastService: ToastService, + private fileLoaderService: FileLoaderService, + private fileToBase64Service: FileToBase64Service ) { this.publicationTitle = 'Nova Publicação'; } @@ -88,7 +91,7 @@ export class NewPublicationPage implements OnInit { } - takePicture(){ + takePicture() { const options: CameraOptions = { quality: 90, destinationType: this.camera.DestinationType.DATA_URL, @@ -99,9 +102,7 @@ export class NewPublicationPage implements OnInit { } this.camera.getPicture(options).then((imageData) => { - // imageData is either a base64 encoded string or a file URI - // If it's base64 (DATA_URL): - let base64Image = 'data:image/jpeg;base64,' + imageData; + this.capturedImage = imageData; this.capturedImageTitle = new Date().getTime() + '.jpeg'; }, (err) => { @@ -109,27 +110,21 @@ export class NewPublicationPage implements OnInit { }); } - getPicture(){ - const options: CameraOptions = { - quality: 90, - sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, - destinationType: this.camera.DestinationType.DATA_URL, - encodingType: this.camera.EncodingType.JPEG, - mediaType: this.camera.MediaType.PICTURE, - targetWidth: 720, - targetHeight: 720, - } - this.camera.getPicture(options).then((imageData) => { - // imageData is either a base64 encoded string or a file URI - // If it's base64 (DATA_URL): - let base64Image = 'data:image/jpeg;base64,' + imageData; - this.capturedImage = imageData; - this.capturedImageTitle = new Date().getTime() + '.jpeg'; - }, (err) => { - console.log(err); - }); - } + laodPicture() { + const input = this.fileLoaderService.createInput({}) + + input.onchange = async () => { + // you can use this method to get file and perform respective operations + let files = Array.from(input.files); + const file1 = files[0] + const imageData = await this.fileToBase64Service.convert(file1) + + this.capturedImage = imageData; + this.capturedImageTitle = file1.name + }; + + } runValidation() { @@ -190,7 +185,7 @@ export class NewPublicationPage implements OnInit { } } - else if (!this.publication.OriginalFileName) { + else if (!this.publication.OriginalFileName) { // this.publication = { DateIndex: this.publication.DateIndex, DocumentId:this.publication.DocumentId, @@ -198,6 +193,7 @@ export class NewPublicationPage implements OnInit { Title: this.pub.Title, Message: this.pub.Message, DatePublication: this.publication.DatePublication, + OriginalFileName: this.capturedImageTitle, // OriginalFileName: this.publication.OriginalFileName, // FileBase64: this.publication.FileBase64, // FileExtension: 'jpeg', @@ -286,10 +282,10 @@ export class NewPublicationPage implements OnInit { this.capturedImage = ''; } setTitle(){ - if(this.publicationType == '1'){ + if(this.publicationType == '1') { this.publicationTitle = 'Nova Publicação Rápida'; } - else if(this.publicationType == '2'){ + else if(this.publicationType == '2') { this.publicationTitle = 'Nova Publicação'; } else if(this.publicationType == '3') { @@ -309,33 +305,4 @@ export class NewPublicationPage implements OnInit { } - /* async openGallery() { - const modal = await this.modalController.create({ - component: GalleryPage, - componentProps:{ - }, - cssClass: 'new-publication', - backdropDismiss: false - }); - await modal.present(); - modal.onDidDismiss(); - } */ - - /* async takePicture(){ - const image = await Plugins.Camera.getPhoto({ - quality: 100, - allowEditing: false, - resultType: CameraResultType.DataUrl, - source: CameraSource.Camera - }); - console.log(image); - - this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl)); - } */ - - - - - - }