This commit is contained in:
Peter Maquiran
2021-08-23 16:00:58 +01:00
parent 3251144704
commit df8876f436
6 changed files with 71 additions and 73 deletions
@@ -63,7 +63,7 @@
</div> </div>
</ion-label> </ion-label>
</div> </div>
</div> </div>
</ion-content> </ion-content>
+1 -1
View File
@@ -8,7 +8,7 @@ export class FileLoaderService {
constructor() { } constructor() { }
loadeFile({ type = 'file'}): HTMLInputElement { createInput({ type = 'file'}): HTMLInputElement {
let input = document.createElement('input'); let input = document.createElement('input');
input.type = type; input.type = type;
@@ -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();
});
});
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class PublicationService {
constructor() { }
}
@@ -16,7 +16,7 @@
<ion-input [(ngModel)]="pub.Title" name="title" placeholder="Título" ></ion-input> <ion-input [(ngModel)]="pub.Title" name="title" placeholder="Título" ></ion-input>
</div> </div>
<div *ngIf="publicationType!='1'" class="container-div pb-20"> <div *ngIf="publicationType!='1' " class="container-div pb-20">
<div class="ion-item-class-2 d-flex"> <div class="ion-item-class-2 d-flex">
<div class="ion-icon-class" > <div class="ion-icon-class" >
<ion-icon slot="start" src="assets/images/icons-description.svg"></ion-icon> <ion-icon slot="start" src="assets/images/icons-description.svg"></ion-icon>
@@ -29,7 +29,7 @@
<div class="container-title py-10 hide-desktop">Fotografia Anexada</div> <div class="container-title py-10 hide-desktop">Fotografia Anexada</div>
<div class="picture d-flex pb-5 hide-desktop" *ngIf="publication.FileBase64"> <div class="picture d-flex pb-5 hide-desktop" *ngIf="publication.FileBase64 && capturedImage ==''">
<div class="post-img"> <div class="post-img">
<img src="{{publication.FileBase64}}" alt="image" > <img src="{{publication.FileBase64}}" alt="image" >
</div> </div>
@@ -43,26 +43,32 @@
</div> </div>
<!-- <div *ngIf="capturedImage != ''" class="ion-item-container-no-border hide-desktop"> <div class="ion-item-container-no-border">
<ion-label (click)="laodPicture()">
<div class="attach-icon">
<ion-icon src="assets/images/icons-add-photos.svg"></ion-icon>
</div>
<div class="attach-document">
<ion-label>Anexar Fotografia</ion-label>
</div>
</ion-label>
</div>
<div *ngIf="capturedImage != ''" class="ion-item-container-no-border">
<ion-label class="attached-title">Fotografia Anexada</ion-label> <ion-label class="attached-title">Fotografia Anexada</ion-label>
<ion-item lines="none"> <ion-item lines="none">
<ion-thumbnail slot="start"> <ion-thumbnail slot="start">
<ion-img [(ngModel)]="capturedImage" name="image" ngDefaultControl [src]="'data:image/png;base64,'+capturedImage"></ion-img> <ion-img [(ngModel)]="capturedImage" name="image" ngDefaultControl [src]="capturedImage"></ion-img>
</ion-thumbnail> --> </ion-thumbnail>
<!-- <ion-thumbnail *ngIf="!publication" slot="start">
<ion-img [(ngModel)]="publication.imageUrl" [src]="guestPicture"></ion-img> <ion-label>
</ion-thumbnail> -->
<!-- <ion-label>
<p>{{capturedImageTitle}}</p> <p>{{capturedImageTitle}}</p>
<p hidden>size</p> <p hidden>size</p>
</ion-label> </ion-label>
<ion-icon (click)="clear()" name="close"></ion-icon> <ion-icon (click)="clear()" name="close"></ion-icon>
</ion-item> --> </ion-item>
<!-- <ion-thumbnail> </div>
<ion-img src="{{imgUrl}}"></ion-img>
</ion-thumbnail> -->
<!-- </div> -->
<div class="ion-item-container-no-border hide-desktop"> <div class="ion-item-container-no-border hide-desktop">
<ion-label (click)="takePicture()"> <ion-label (click)="takePicture()">
@@ -8,7 +8,8 @@ import { PhotoService } from 'src/app/services/photo.service';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx'; import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
import { FormControl, FormGroup, Validators } from '@angular/forms'; 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({ @Component({
selector: 'app-new-publication', selector: 'app-new-publication',
templateUrl: './new-publication.page.html', templateUrl: './new-publication.page.html',
@@ -51,6 +52,8 @@ export class NewPublicationPage implements OnInit {
private camera: Camera, private camera: Camera,
private animationController: AnimationController, private animationController: AnimationController,
private toastService: ToastService, private toastService: ToastService,
private fileLoaderService: FileLoaderService,
private fileToBase64Service: FileToBase64Service
) { ) {
this.publicationTitle = 'Nova Publicação'; this.publicationTitle = 'Nova Publicação';
} }
@@ -88,7 +91,7 @@ export class NewPublicationPage implements OnInit {
} }
takePicture(){ takePicture() {
const options: CameraOptions = { const options: CameraOptions = {
quality: 90, quality: 90,
destinationType: this.camera.DestinationType.DATA_URL, destinationType: this.camera.DestinationType.DATA_URL,
@@ -99,9 +102,7 @@ export class NewPublicationPage implements OnInit {
} }
this.camera.getPicture(options).then((imageData) => { 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.capturedImage = imageData;
this.capturedImageTitle = new Date().getTime() + '.jpeg'; this.capturedImageTitle = new Date().getTime() + '.jpeg';
}, (err) => { }, (err) => {
@@ -109,27 +110,21 @@ export class NewPublicationPage implements OnInit {
}); });
} }
getPicture(){ laodPicture() {
const options: CameraOptions = { const input = this.fileLoaderService.createInput({})
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);
});
}
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() { runValidation() {
@@ -190,7 +185,7 @@ export class NewPublicationPage implements OnInit {
} }
} }
else if (!this.publication.OriginalFileName) { else if (!this.publication.OriginalFileName) { //
this.publication = { this.publication = {
DateIndex: this.publication.DateIndex, DateIndex: this.publication.DateIndex,
DocumentId:this.publication.DocumentId, DocumentId:this.publication.DocumentId,
@@ -198,6 +193,7 @@ export class NewPublicationPage implements OnInit {
Title: this.pub.Title, Title: this.pub.Title,
Message: this.pub.Message, Message: this.pub.Message,
DatePublication: this.publication.DatePublication, DatePublication: this.publication.DatePublication,
OriginalFileName: this.capturedImageTitle,
// OriginalFileName: this.publication.OriginalFileName, // OriginalFileName: this.publication.OriginalFileName,
// FileBase64: this.publication.FileBase64, // FileBase64: this.publication.FileBase64,
// FileExtension: 'jpeg', // FileExtension: 'jpeg',
@@ -286,10 +282,10 @@ export class NewPublicationPage implements OnInit {
this.capturedImage = ''; this.capturedImage = '';
} }
setTitle(){ setTitle(){
if(this.publicationType == '1'){ if(this.publicationType == '1') {
this.publicationTitle = 'Nova Publicação Rápida'; this.publicationTitle = 'Nova Publicação Rápida';
} }
else if(this.publicationType == '2'){ else if(this.publicationType == '2') {
this.publicationTitle = 'Nova Publicação'; this.publicationTitle = 'Nova Publicação';
} }
else if(this.publicationType == '3') { 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));
} */
} }