mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
On new publication add image from gallery added
This commit is contained in:
@@ -56,7 +56,7 @@
|
||||
</div>
|
||||
|
||||
<div class="ion-item-container-no-border">
|
||||
<ion-label (click)="selectImage()">
|
||||
<ion-label (click)="takePicture()">
|
||||
<div class="attach-icon">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/icons-add-photo.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-add-photo.svg"></ion-icon>
|
||||
@@ -69,7 +69,7 @@
|
||||
</div>
|
||||
|
||||
<div class="ion-item-container-no-border">
|
||||
<ion-label (click)="laodPicture()" class="cursor-pointer">
|
||||
<ion-label (click)="selectImage()" class="cursor-pointer">
|
||||
<div class="attach-icon">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/icons-add-photos.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-add-photos.svg"></ion-icon>
|
||||
|
||||
@@ -16,7 +16,7 @@ import { formatDate } from 'src/plugin/momentG.js'
|
||||
import { FileLoaderService } from 'src/app/services/file/file-loader.service';
|
||||
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
|
||||
import { ThemeService } from 'src/app/services/theme.service';
|
||||
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
|
||||
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
|
||||
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
|
||||
@@ -42,7 +42,7 @@ export class NewPublicationPage implements OnInit {
|
||||
public showSeconds = false;
|
||||
public touchUi = false;
|
||||
public enableMeridian = false;
|
||||
public minDate = new Date().toISOString().slice(0,10)
|
||||
public minDate = new Date().toISOString().slice(0, 10)
|
||||
public endMinDate = new Date(new Date().getTime() + 15 * 60000);
|
||||
public stepHour = 1;
|
||||
public stepMinute = 5;
|
||||
@@ -58,18 +58,18 @@ export class NewPublicationPage implements OnInit {
|
||||
folderId: string;
|
||||
image: Image = new Image();
|
||||
|
||||
publicationType:string;
|
||||
publicationTitle:string;
|
||||
imgUrl:any;
|
||||
publicationType: string;
|
||||
publicationTitle: string;
|
||||
imgUrl: any;
|
||||
|
||||
Defaultimage:any = '';
|
||||
Defaultimage: any = '';
|
||||
|
||||
photo: SafeResourceUrl;
|
||||
|
||||
guestPicture:any;
|
||||
guestPicture: any;
|
||||
|
||||
capturedImage:any = '';
|
||||
capturedImageTitle:any;
|
||||
capturedImage: any = '';
|
||||
capturedImageTitle: any;
|
||||
public photos: any[] = [];
|
||||
|
||||
constructor(
|
||||
@@ -102,26 +102,17 @@ export class NewPublicationPage implements OnInit {
|
||||
// this.takePicture();
|
||||
}
|
||||
|
||||
async takePicture() {
|
||||
const capturedImage = await Camera.getPhoto({
|
||||
async takePicture() {
|
||||
const image = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
// allowEditing: true,
|
||||
allowEditing: false,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera
|
||||
|
||||
});
|
||||
const response = await fetch(capturedImage.webPath!);
|
||||
const blob = await response.blob();
|
||||
|
||||
this.photos.unshift({
|
||||
filepath: "soon...",
|
||||
webviewPath: capturedImage.webPath
|
||||
source: CameraSource.Camera // Camera, Photos or Prompt!
|
||||
});
|
||||
|
||||
this.capturedImage = await this.convertBlobToBase64(blob);
|
||||
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
||||
|
||||
//console.log(this.capturedImage);
|
||||
if (image) {
|
||||
this.saveImage(image)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -202,18 +193,18 @@ async takePicture() {
|
||||
this.injectValidation()
|
||||
this.runValidation()
|
||||
|
||||
if(this.Form.invalid) return false
|
||||
if (this.Form.invalid) return false
|
||||
|
||||
|
||||
|
||||
if(this.publicationType == '3') {
|
||||
if (this.publicationType == '3') {
|
||||
console.log(this.navParams.get('publication'));
|
||||
|
||||
if(this.capturedImage != ''){
|
||||
if (this.capturedImage != '') {
|
||||
this.publication = {
|
||||
DateIndex: this.publication.DateIndex,
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
DocumentId: this.publication.DocumentId,
|
||||
ProcessId: this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
@@ -242,8 +233,8 @@ async takePicture() {
|
||||
|
||||
this.publication = {
|
||||
DateIndex: this.publication.DateIndex,
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
DocumentId: this.publication.DocumentId,
|
||||
ProcessId: this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
@@ -271,8 +262,8 @@ async takePicture() {
|
||||
} else {
|
||||
this.publication = {
|
||||
DateIndex: this.publication.DateIndex,
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
DocumentId: this.publication.DocumentId,
|
||||
ProcessId: this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
@@ -307,8 +298,8 @@ async takePicture() {
|
||||
|
||||
this.publication = {
|
||||
DateIndex: date,
|
||||
DocumentId:null,
|
||||
ProcessId:this.folderId,
|
||||
DocumentId: null,
|
||||
ProcessId: this.folderId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: date,
|
||||
@@ -338,8 +329,8 @@ async takePicture() {
|
||||
|
||||
|
||||
close() {
|
||||
this.modalController.dismiss().then(()=>{
|
||||
this.showLoader=true;
|
||||
this.modalController.dismiss().then(() => {
|
||||
this.showLoader = true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -348,13 +339,13 @@ async takePicture() {
|
||||
}
|
||||
|
||||
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') {
|
||||
else if (this.publicationType == '3') {
|
||||
this.publicationTitle = 'Editar Publicação';
|
||||
this.pub = this.navParams.get('publication');
|
||||
|
||||
@@ -389,21 +380,21 @@ async takePicture() {
|
||||
|
||||
|
||||
|
||||
async selectImage() {
|
||||
async selectImage() {
|
||||
const image = await Camera.getPhoto({
|
||||
quality: 90,
|
||||
allowEditing: false,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera // Camera, Photos or Prompt!
|
||||
source: CameraSource.Photos // Camera, Photos or Prompt!
|
||||
});
|
||||
|
||||
if (image) {
|
||||
this.saveImage(image)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new file from a capture image
|
||||
async saveImage(photo: Photo) {
|
||||
// Create a new file from a capture image
|
||||
async saveImage(photo: Photo) {
|
||||
const base64Data = await this.readAsBase64(photo);
|
||||
|
||||
const fileName = new Date().getTime() + '.jpeg';
|
||||
@@ -414,7 +405,7 @@ async saveImage(photo: Photo) {
|
||||
});
|
||||
|
||||
this.loadFiles();
|
||||
}
|
||||
}
|
||||
|
||||
private async readAsBase64(photo: Photo) {
|
||||
if (this.platform.is('hybrid')) {
|
||||
@@ -431,9 +422,9 @@ async saveImage(photo: Photo) {
|
||||
|
||||
return await this.convertBlobToBase64(blob) as string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async loadFiles() {
|
||||
async loadFiles() {
|
||||
this.images = [];
|
||||
|
||||
const loading = await this.loadingCtrl.create({
|
||||
@@ -446,11 +437,11 @@ async loadFiles() {
|
||||
directory: Directory.Data,
|
||||
}).then(result => {
|
||||
console.log('ALL RESULTS', result.files[0])
|
||||
let lastphoto = result.files[result.files.length -1]
|
||||
let lastphoto = result.files[result.files.length - 1]
|
||||
this.loadFileData(lastphoto);
|
||||
},
|
||||
async (err) => {
|
||||
console.log('ERROR FILE DOSENT EXIST',err)
|
||||
console.log('ERROR FILE DOSENT EXIST', err)
|
||||
// Folder does not yet exists!
|
||||
await Filesystem.mkdir({
|
||||
path: IMAGE_DIR,
|
||||
@@ -461,9 +452,9 @@ async loadFiles() {
|
||||
).then(_ => {
|
||||
loading.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async loadFileData(fileName: string) {
|
||||
async loadFileData(fileName: string) {
|
||||
console.log('ALL PHOTOT FILE', fileName)
|
||||
// for (let f of fileNames) {
|
||||
const filePath = `${IMAGE_DIR}/${fileName}`;
|
||||
@@ -479,9 +470,9 @@ async loadFileData(fileName: string) {
|
||||
data: `data:image/jpeg;base64,${readFile.data}`,
|
||||
});
|
||||
|
||||
console.log('ALL IMAGE',this.images)
|
||||
console.log('ALL IMAGE', this.images)
|
||||
|
||||
this.capturedImage = this.images[0].data
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user