Upgrade: Angular 18, Ionic 8, Capacitor 6
Modernizacion completa del frontend: - Angular 8 -> 18.2.14 - Ionic 4 -> 8.7.17 - Capacitor 6.x (migracion desde Cordova/@ionic-native) - TypeScript 5.4.5 - Swiper 11 con Web Components API Cambios principales: - Migrar NativeStorage a @capacitor/preferences - Migrar InAppBrowser a @capacitor/browser - Migrar Camera a @capacitor/camera - Migrar Geolocation a @capacitor/geolocation - Migrar StatusBar/SplashScreen a Capacitor - Migrar Facebook/Google login a plugins Capacitor - Actualizar lazy loading syntax (Angular 12+) - Configurar buildOptimizer: false para Ionic 8 - Limpiar package.json de dependencias obsoletas - Agregar README con guia de instalacion Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
146
src/app/pages/contracts/nohome/nohome.page.ts
Normal file → Executable file
146
src/app/pages/contracts/nohome/nohome.page.ts
Normal file → Executable file
@@ -1,12 +1,9 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { NavController, LoadingController } from '@ionic/angular';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { LocationAccuracy } from '@ionic-native/location-accuracy/ngx';
|
||||
import { Geolocation } from '@ionic-native/geolocation/ngx';
|
||||
import { Camera, CameraOptions, PictureSourceType } from '@ionic-native/Camera/ngx';
|
||||
import { File, FileEntry } from '@ionic-native/File/ngx';
|
||||
import { WebView } from '@ionic-native/ionic-webview/ngx';
|
||||
import { FilePath } from '@ionic-native/file-path/ngx';
|
||||
import { Geolocation } from '@capacitor/geolocation';
|
||||
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
import { IchambaService } from 'src/app/services/ichamba.service';
|
||||
import { AlertService } from 'src/app/services/alert.service';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
@@ -18,13 +15,13 @@ import { DomSanitizer } from '@angular/platform-browser';
|
||||
})
|
||||
export class NohomePage implements OnInit {
|
||||
|
||||
private loading;
|
||||
private loading: any;
|
||||
|
||||
storedPhoto;
|
||||
resolvedImage = null;
|
||||
safeImage = null;
|
||||
contract_id = null;
|
||||
description: string;
|
||||
storedPhoto: any;
|
||||
resolvedImage: any = null;
|
||||
safeImage: any = null;
|
||||
contract_id: any = null;
|
||||
description: string = '';
|
||||
myPosition: any = {};
|
||||
|
||||
constructor(
|
||||
@@ -33,12 +30,6 @@ export class NohomePage implements OnInit {
|
||||
private navCtrl: NavController,
|
||||
private loadingCtrl: LoadingController,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private locaccuracy: LocationAccuracy,
|
||||
private geolocation: Geolocation,
|
||||
private camera: Camera,
|
||||
private file: File,
|
||||
private webview: WebView,
|
||||
private filePath: FilePath,
|
||||
private sanitizer: DomSanitizer
|
||||
) { }
|
||||
|
||||
@@ -47,45 +38,45 @@ export class NohomePage implements OnInit {
|
||||
this.getCurrentLocation();
|
||||
}
|
||||
|
||||
getCurrentLocation() {
|
||||
this.locaccuracy.request(this.locaccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(() => {
|
||||
this.geolocation.getCurrentPosition({ maximumAge: 20000, timeout: 30000, enableHighAccuracy: true }).then((resp) => {
|
||||
console.log(resp);
|
||||
this.myPosition = {
|
||||
latitude: resp.coords.latitude,
|
||||
longitude: resp.coords.longitude
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log('Error al obtener localización: ' + error);
|
||||
});
|
||||
}, (error) => {
|
||||
console.log(error);
|
||||
});
|
||||
async getCurrentLocation() {
|
||||
try {
|
||||
// Request permissions first
|
||||
const permissionStatus = await Geolocation.checkPermissions();
|
||||
if (permissionStatus.location !== 'granted') {
|
||||
await Geolocation.requestPermissions();
|
||||
}
|
||||
|
||||
const position = await Geolocation.getCurrentPosition({
|
||||
enableHighAccuracy: true,
|
||||
timeout: 30000
|
||||
});
|
||||
|
||||
console.log(position);
|
||||
this.myPosition = {
|
||||
latitude: position.coords.latitude,
|
||||
longitude: position.coords.longitude
|
||||
};
|
||||
} catch (error) {
|
||||
console.log('Error al obtener localización: ' + error);
|
||||
}
|
||||
}
|
||||
|
||||
openCamera(){
|
||||
const options: CameraOptions = {
|
||||
quality: 100,
|
||||
destinationType: this.camera.DestinationType.FILE_URI,
|
||||
encodingType: this.camera.EncodingType.JPEG,
|
||||
}
|
||||
async openCamera() {
|
||||
try {
|
||||
const image = await Camera.getPhoto({
|
||||
quality: 100,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera
|
||||
});
|
||||
|
||||
this.camera.getPicture(options).then((tempImage) => {
|
||||
const tempFilename = tempImage.substr(tempImage.lastIndexOf('/') + 1);
|
||||
const tempBaseFilesystemPath = tempImage.substr(0, tempImage.lastIndexOf('/') + 1);
|
||||
const newBaseFilesystemPath = this.file.dataDirectory;
|
||||
|
||||
this.file.copyFile(tempBaseFilesystemPath, tempFilename, newBaseFilesystemPath, tempFilename);
|
||||
|
||||
this.storedPhoto = newBaseFilesystemPath + tempFilename;
|
||||
//this.resolvedImage = (this.webview.convertFileSrc(this.storedPhoto)).replace('http://localhost/_app_file_', '');
|
||||
this.resolvedImage = this.webview.convertFileSrc(this.storedPhoto);
|
||||
this.safeImage = this.sanitizer.bypassSecurityTrustUrl(this.resolvedImage);
|
||||
this.alertService.presentToast(this.resolvedImage);
|
||||
}, (err) => {
|
||||
// Handle error
|
||||
this.alertService.presentToast("error: " + err)
|
||||
});
|
||||
// image.webPath will contain a path that can be set as an image src
|
||||
this.resolvedImage = image.webPath;
|
||||
this.safeImage = this.sanitizer.bypassSecurityTrustUrl(this.resolvedImage || '');
|
||||
this.storedPhoto = image.path;
|
||||
this.alertService.presentToast(this.resolvedImage || 'Image captured');
|
||||
} catch (err) {
|
||||
this.alertService.presentToast("error: " + err);
|
||||
}
|
||||
}
|
||||
|
||||
send() {
|
||||
@@ -98,27 +89,34 @@ export class NohomePage implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
startUpload() {
|
||||
this.file.resolveLocalFilesystemUrl(this.storedPhoto)
|
||||
.then(entry => {
|
||||
( < FileEntry > entry).file(file => this.readFile(file))
|
||||
})
|
||||
.catch(err => {
|
||||
this.alertService.presentToast("error: " + err)
|
||||
});
|
||||
}
|
||||
async startUpload() {
|
||||
try {
|
||||
if (!this.storedPhoto) {
|
||||
this.alertService.presentToast("No hay foto para subir");
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the file as base64
|
||||
const contents = await Filesystem.readFile({
|
||||
path: this.storedPhoto
|
||||
});
|
||||
|
||||
// Convert base64 to Blob
|
||||
const byteCharacters = atob(contents.data as string);
|
||||
const byteNumbers = new Array(byteCharacters.length);
|
||||
for (let i = 0; i < byteCharacters.length; i++) {
|
||||
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
||||
}
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
const blob = new Blob([byteArray], { type: 'image/jpeg' });
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', blob, 'photo.jpg');
|
||||
// this.uploadImageData(formData);
|
||||
|
||||
readFile(file: any) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
const formData = new FormData();
|
||||
const imgBlob = new Blob([reader.result], {
|
||||
type: file.type
|
||||
});
|
||||
formData.append('file', imgBlob, file.name);
|
||||
//this.uploadImageData(formData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
this.alertService.presentToast("Todo bien hasta ahora");
|
||||
} catch (err) {
|
||||
this.alertService.presentToast("error: " + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user