mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Disabled capacitor and add camera integration
This commit is contained in:
@@ -17,7 +17,6 @@ import { File } from '@ionic-native/File/ngx';
|
||||
import { WebView } from '@ionic-native/ionic-webview/ngx';
|
||||
import { FilePath } from '@ionic-native/file-path/ngx';
|
||||
import { Camera } from '@ionic-native/camera/ngx';
|
||||
|
||||
import { IonicStorageModule } from '@ionic/storage';
|
||||
|
||||
@NgModule({
|
||||
|
||||
@@ -15,7 +15,7 @@ export class HomeGuard implements CanActivate {
|
||||
|
||||
canActivate(): Promise<boolean>{
|
||||
return new Promise(resolve => {
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res => {
|
||||
/* this.storageService.get(AuthConnstants.AUTH).then(res => {
|
||||
if(res){
|
||||
resolve(true);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export class HomeGuard implements CanActivate {
|
||||
}
|
||||
}).catch(err =>{
|
||||
resolve(false);
|
||||
})
|
||||
}) */
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ export class IndexGuard implements CanActivate {
|
||||
){}
|
||||
canActivate(): Promise<boolean>{
|
||||
return new Promise(resolve => {
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res => {
|
||||
/* this.storageService.get(AuthConnstants.AUTH).then(res => {
|
||||
if(res){
|
||||
this.router.navigate(['home']);
|
||||
resolve(false);
|
||||
@@ -24,7 +24,7 @@ export class IndexGuard implements CanActivate {
|
||||
}
|
||||
}).catch(err =>{
|
||||
resolve(false);
|
||||
})
|
||||
}) */
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,3 +17,4 @@
|
||||
</form>
|
||||
</div>
|
||||
</ion-content>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { environment } from 'src/environments/environment';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { PhotoService } from 'src/app/services/photo.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -29,6 +30,7 @@ export class LoginPage implements OnInit {
|
||||
private authService: AuthService,
|
||||
private storageService: StorageService,
|
||||
private toastService: ToastService,
|
||||
private photoService: PhotoService,
|
||||
public alertController: AlertController) { }
|
||||
|
||||
ngOnInit() {
|
||||
@@ -56,7 +58,7 @@ export class LoginPage implements OnInit {
|
||||
loginAction(){
|
||||
|
||||
if(this.validateInput()){
|
||||
this.authService.loginChat2(this.postData).subscribe((res: any) =>{
|
||||
/* this.authService.loginChat2(this.postData).subscribe((res: any) =>{
|
||||
if(res.data){
|
||||
this.storageService.store(AuthConnstants.AUTH, res.data);
|
||||
console.log('Log RockectChat OK');
|
||||
@@ -69,13 +71,13 @@ export class LoginPage implements OnInit {
|
||||
},
|
||||
(error:any) =>{
|
||||
console.log('Network error');
|
||||
})
|
||||
}) */
|
||||
}
|
||||
else{
|
||||
this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async Login(){
|
||||
try {
|
||||
//Go to our home in home/feed.
|
||||
@@ -106,4 +108,7 @@ export class LoginPage implements OnInit {
|
||||
this.presentAlert('Ocorreu um erro ao fazer login. Contacte o administrador de sistema.');
|
||||
}
|
||||
}
|
||||
openCamera(){
|
||||
this.photoService.takePicture();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="photoService.photos.length > 0" class="ion-item-container-no-border">
|
||||
<div *ngIf="capturedImage != ''" class="ion-item-container-no-border">
|
||||
<ion-label class="attached-title">Fotografia Anexada</ion-label>
|
||||
<ion-item lines="none">
|
||||
<ion-thumbnail slot="start">
|
||||
<ion-img [(ngModel)]="pub.FileBase64" name="image" ngDefaultControl [src]="'data:image/png;base64,'+this.photoService.photos[0].webviewPath"></ion-img>
|
||||
<ion-img [(ngModel)]="pub.FileBase64" name="image" ngDefaultControl [src]="'data:image/png;base64,'+capturedImage"></ion-img>
|
||||
</ion-thumbnail>
|
||||
<!-- <ion-thumbnail *ngIf="!publication" slot="start">
|
||||
<ion-img [(ngModel)]="publication.imageUrl" [src]="guestPicture"></ion-img>
|
||||
</ion-thumbnail> -->
|
||||
<ion-label>
|
||||
<p>{{photoService.photos[0].fileName}}</p>
|
||||
<p>size</p>
|
||||
<p>{{capturedImageTitle}}</p>
|
||||
<p hidden>size</p>
|
||||
</ion-label>
|
||||
<ion-icon (click)="clear()" name="close"></ion-icon>
|
||||
</ion-item>
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ModalController, NavParams } from '@ionic/angular';
|
||||
import { AlertController, ModalController, NavParams } from '@ionic/angular';
|
||||
import { GalleryPage } from '../gallery/gallery.page';
|
||||
|
||||
import {Plugins, CameraResultType, CameraSource} from '@capacitor/core';
|
||||
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
|
||||
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
||||
import { PublicationsService } from 'src/app/services/publications.service';
|
||||
import { Publication } from 'src/app/models/publication';
|
||||
import { Image } from 'src/app/models/image';
|
||||
import { ThrowStmt } from '@angular/compiler';
|
||||
import { PhotoService } from 'src/app/services/photo.service';
|
||||
import { AlertService } from 'src/app/services/alert.service';
|
||||
|
||||
const { Camera } = Plugins;
|
||||
/* const { Camera } = Plugins; */
|
||||
|
||||
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
||||
|
||||
@Component({
|
||||
selector: 'app-new-publication',
|
||||
@@ -35,14 +38,18 @@ export class NewPublicationPage implements OnInit {
|
||||
guestPicture:any;
|
||||
|
||||
capturedImage:any;
|
||||
capturedImageTitle:any;
|
||||
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
public photoService: PhotoService,
|
||||
private navParams: NavParams,
|
||||
private alertService: AlertService,
|
||||
/* private camera: Camera, */
|
||||
private sanitizer: DomSanitizer,
|
||||
private publications: PublicationsService,
|
||||
private camera: Camera,
|
||||
) {
|
||||
this.publicationType = this.navParams.get('publicationType');
|
||||
this.folderId = this.navParams.get('folderId');
|
||||
@@ -55,7 +62,23 @@ export class NewPublicationPage implements OnInit {
|
||||
|
||||
}
|
||||
takePictureCodova(){
|
||||
this.photoService.takePicture();
|
||||
const options: CameraOptions = {
|
||||
quality: 100,
|
||||
destinationType: this.camera.DestinationType.DATA_URL,
|
||||
encodingType: this.camera.EncodingType.JPEG,
|
||||
mediaType: this.camera.MediaType.PICTURE
|
||||
}
|
||||
|
||||
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();
|
||||
}, (err) => {
|
||||
// Handle error
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* takePictureCapacitor() {
|
||||
@@ -88,21 +111,31 @@ export class NewPublicationPage implements OnInit {
|
||||
async save(){
|
||||
console.log(this.pub.FileBase64);
|
||||
if(this.publicationType == '3'){
|
||||
this.image = {
|
||||
title: this.image.title,
|
||||
url: this.image.url,
|
||||
format: 'png'
|
||||
if(this.capturedImage != ''){
|
||||
this.publication = {
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
OriginalFileName: this.capturedImageTitle,
|
||||
FileBase64: this.capturedImage,
|
||||
FileExtension: 'jpg',
|
||||
}
|
||||
}
|
||||
this.publication = {
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
OriginalFileName: '',
|
||||
FileBase64: this.publication.FileBase64,
|
||||
FileExtension: 'jpg',
|
||||
else{
|
||||
this.publication = {
|
||||
DocumentId:this.publication.DocumentId,
|
||||
ProcessId:this.publication.ProcessId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: this.publication.DatePublication,
|
||||
OriginalFileName: '',
|
||||
FileBase64: this.publication.FileBase64,
|
||||
FileExtension: 'jpg',
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Edit');
|
||||
console.log(this.publication);
|
||||
this.publications.UpdatePublication(this.publication.ProcessId, this.publication);
|
||||
@@ -110,19 +143,14 @@ export class NewPublicationPage implements OnInit {
|
||||
}
|
||||
else{
|
||||
|
||||
this.image = {
|
||||
title: this.image.title,
|
||||
url: this.image.url,
|
||||
format: 'png'
|
||||
}
|
||||
this.publication = {
|
||||
DocumentId:null,
|
||||
ProcessId:this.folderId,
|
||||
Title: this.pub.Title,
|
||||
Message: this.pub.Message,
|
||||
DatePublication: new Date(),
|
||||
OriginalFileName: 'foto',
|
||||
FileBase64: this.photoService.photos[0].webviewPath,
|
||||
OriginalFileName: this.capturedImageTitle,
|
||||
FileBase64: this.capturedImage,
|
||||
FileExtension: 'jpg',
|
||||
}
|
||||
|
||||
@@ -138,7 +166,7 @@ export class NewPublicationPage implements OnInit {
|
||||
this.modalController.dismiss();
|
||||
}
|
||||
clear(){
|
||||
this.photoService.photos = [];
|
||||
this.capturedImage = '';
|
||||
}
|
||||
setTitle(){
|
||||
if(this.publicationType == '1'){
|
||||
@@ -165,7 +193,7 @@ export class NewPublicationPage implements OnInit {
|
||||
modal.onDidDismiss();
|
||||
} */
|
||||
|
||||
async takePicture(){
|
||||
/* async takePicture(){
|
||||
const image = await Plugins.Camera.getPhoto({
|
||||
quality: 100,
|
||||
allowEditing: false,
|
||||
@@ -175,7 +203,7 @@ export class NewPublicationPage implements OnInit {
|
||||
console.log(image);
|
||||
|
||||
this.photo = this.sanitizer.bypassSecurityTrustResourceUrl(image && (image.dataUrl));
|
||||
}
|
||||
} */
|
||||
openCamera(){
|
||||
/* this.camera.getPicture({
|
||||
sourceType: this.camera.PictureSourceType.CAMERA,
|
||||
|
||||
@@ -8,6 +8,6 @@ export class UserDataResolver{
|
||||
constructor(private authService: AuthService){}
|
||||
|
||||
resolve(){
|
||||
return this.authService.getUserData();
|
||||
/* return this.authService.getUserData(); */
|
||||
}
|
||||
}
|
||||
@@ -56,24 +56,24 @@ export class AuthService {
|
||||
}
|
||||
|
||||
//Get user data from RocketChat
|
||||
getUserData(){
|
||||
/* getUserData(){
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res=>{
|
||||
this.userData$.next(res);
|
||||
})
|
||||
}
|
||||
} */
|
||||
|
||||
getProfile(){
|
||||
/* getProfile(){
|
||||
this.storageService.get(AuthConnstants.PROFILE).then(res=>{
|
||||
return res;
|
||||
});
|
||||
}
|
||||
} */
|
||||
|
||||
logoutChat(){
|
||||
//this.storageService.clear();
|
||||
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
/* this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.userData$.next('');
|
||||
this.router.navigate(['']);
|
||||
})
|
||||
}) */
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
/* import {
|
||||
Plugins,
|
||||
PushNotification,
|
||||
PushNotificationToken,
|
||||
PushNotificationActionPerformed,
|
||||
Capacitor
|
||||
} from '@capacitor/core';
|
||||
} from '@capacitor/core'; */
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
const { PushNotifications } = Plugins;
|
||||
/* const { PushNotifications } = Plugins; */
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -17,7 +17,7 @@ export class FcmService {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
|
||||
initPush() {
|
||||
/* initPush() {
|
||||
if (Capacitor.platform !== 'web') {
|
||||
this.registerPush();
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export class FcmService {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Plugins, CameraResultType, Capacitor, FilesystemDirectory, CameraPhoto, CameraSource } from '@capacitor/core';
|
||||
/* import { Plugins, CameraResultType, Capacitor, FilesystemDirectory, CameraPhoto, CameraSource } from '@capacitor/core'; */
|
||||
import { Photo } from '../models/photo';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
||||
@@ -27,6 +27,8 @@ export class PhotoService {
|
||||
encodingType: this.camera.EncodingType.JPEG,
|
||||
mediaType: this.camera.MediaType.PICTURE
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.camera.getPicture(options).then((imageData) => {
|
||||
// imageData is either a base64 encoded string or a file URI
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
const { Storage } = Plugins;
|
||||
/* import { Plugins } from '@capacitor/core';
|
||||
const { Storage } = Plugins; */
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StorageService {
|
||||
constructor() {}
|
||||
|
||||
// Store the value
|
||||
/* // Store the value
|
||||
async store(storageKey: string, value: any) {
|
||||
const encryptedValue = btoa(escape(JSON.stringify(value)));
|
||||
await Storage.set({
|
||||
@@ -29,5 +29,5 @@ const { Storage } = Plugins;
|
||||
// Clear storage
|
||||
async clear() {
|
||||
await Storage.clear();
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user