upload profile picture

This commit is contained in:
Eudes Inácio
2023-09-09 14:40:08 +01:00
parent fb1bd07ad0
commit 42c2fc92ff
5 changed files with 94 additions and 47 deletions
@@ -188,5 +188,6 @@
<button class="btn-cancel" shape="round" (click)="cancelTask()">Cancelar</button>
<button *ngIf="taskType == '0'" class="btn-ok" shape="round" (click)="saveTask()">Concluir</button>
<button *ngIf="taskType == '1'" class="btn-ok" shape="round" (click)="saveTask()">Solicitar</button>
<button *ngIf="taskType == '2'" class="btn-ok" shape="round" (click)="saveTask()">Solicitar</button>
</div>
</ion-footer>
@@ -10,6 +10,7 @@ import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera
import { Filesystem, Directory } from '@capacitor/filesystem';
import { File } from '@awesome-cordova-plugins/file/ngx';
import { StorageService } from 'src/app/services/storage.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Component({
@@ -33,20 +34,42 @@ export class EditProfilePage implements OnInit {
public ThemeService: ThemeService,
private file: File,
private storageService: StorageService,
private attachmentService: AttachmentsService
) { }
ngOnInit() {
this.getProfilpicture()
ngOnInit() {
this.getProfilpictureFromStorage()
}
getProfilpicture() {
getProfilpictureFromStorage() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture)
this.profilePicture = picture
}).catch((error ) => {
}).catch((error) => {
this.profilePicture = "";
})
}
getProfilpicture(guid) {
console.log('Get picture ', guid.path)
this.attachmentService.downloadFile(guid.path).subscribe(async (picture: any) => {
let downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(picture.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
console.log('Get picture ', downloadFile)
this.storageService.store(this.SessionStore.user.RoleID.toString()+"guid", guid.path)
this.storageService.store(this.SessionStore.user.RoleID.toString(), downloadFile).then((value) => {
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
});
}, ((error) => {
console.log('Error get profile picture: ', error)
}))
}
close() {
this.modalController.dismiss();
@@ -146,50 +169,32 @@ export class EditProfilePage implements OnInit {
async takePicture() {
const capturedImage = await Camera.getPhoto({
width: 188,
height: 188,
width: 250,
height: 250,
quality: 100,
// allowEditing: true,
resultType: CameraResultType.Base64,
source: CameraSource.Camera
});
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
console.log(this.SessionStore.user.RoleID.toString())
this.storageService.store(this.SessionStore.user.RoleID.toString(),this.capturedImage).then((value) => {
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
})
this.getProfilpicture()
this.capturedImageTitle = SessionStore.user.Profile;
/* this.saveFile(this.capturedImage,this.capturedImageTitle,'application/img'); */
this.capturedImage = 'data:image/jpeg;base64,' + capturedImage.base64String;
const blob = this.dataURItoBlob(this.capturedImage)
const formData = new FormData();
formData.append("blobFile", blob);
this.attachmentService.uploadFile(formData).subscribe((guid) => {
console.log('GUID ', guid)
console.log(this.SessionStore.user.RoleID.toString())
this.getProfilpicture(guid);
}, ((error) => {
console.log('Erro Upload profile picture ',error)
}))
}
/* async saveFile(pdfString, filename, type) {
const blob = this.b64toBlob(pdfString, type)
console.log(blob)
let pathFile = ''
const fileName = filename
const contentFile = blob
if (this.platform.is('ios')) {
pathFile = this.file.documentsDirectory
} else {
pathFile = this.file.externalRootDirectory
}
console.log(pathFile)
await Filesystem.writeFile({
path: fileName,
data: pdfString,
directory: Directory.Documents,
}).then((dir) => {
console.log('DIR ', dir)
});
} */
b64toBlob(b64Data, contentType) {
contentType = contentType || '';
@@ -216,5 +221,30 @@ export class EditProfilePage implements OnInit {
return blob;
}
dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer
var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], { type: mimeString });
return blob;
}
}
+13
View File
@@ -253,6 +253,19 @@ export class ProfilePage implements OnInit {
else if (Service === "gabinete-digital" && Object === "despachos-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', IdObject, 'gabinete-digital']));
}else if (Service === "gabinete-digital" && Object === "diplomas") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "diplomas-assinar") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "diploma-revisao") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', IdObject, 'gabinete-digital']));
}
else if (Service === "gabinete-digital" && Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', IdObject, 'gabinete-digital']));
}
this.deleteNotification(index);
+6 -3
View File
@@ -95,7 +95,7 @@ export class HeaderPage implements OnInit {
this.eventTriger.getObservable().subscribe((event) => {
if (event.notification == "recive") {
console.log('header', event.notification)
this.notificationLength++
this.notificationLengthData()
}
});
@@ -105,21 +105,24 @@ export class HeaderPage implements OnInit {
this.eventTriger.getObservable().subscribe((event) => {
if (event.notification == "deleted") {
console.log('header', event.notification)
this.notificationLength--
this.notificationLengthData()
}
});
}
async notificationLengthData() {
console.log('Call notification data')
await this.storageservice.get("Notifications").then((value) => {
console.log('Get notification data', )
this.notificationLength = value.length;
console.log('Call notification data',this.notificationLength)
}).catch((error) => {
if (!error) {
console.error('header storage get notification', error)
this.notificationLength = 0;
} else {
console.error('header storage get notification', error)
+6 -6
View File
@@ -1,12 +1,12 @@
export let versionData = {
"shortSHA": "9de301944",
"SHA": "9de30194464b9511a9aa14a85b5b60894aeb860b",
"shortSHA": "fb1bd07ad",
"SHA": "fb1bd07ad0a5ba460b84408f87a08f72604cb41f",
"branch": "developer-prod",
"lastCommitAuthor": "'Eudes Inácio'",
"lastCommitTime": "'Thu Aug 31 17:35:39 2023 +0100'",
"lastCommitMessage": "new erro hendle",
"lastCommitNumber": "5256",
"lastCommitTime": "'Wed Sep 6 21:23:21 2023 +0100'",
"lastCommitMessage": "a lot of changes",
"lastCommitNumber": "5257",
"change": "",
"changeStatus": "On branch developer-prod\nYour branch is ahead of 'origin/developer-prod' by 2 commits.\n (use \"git push\" to publish your local commits)\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: src/app/Rules/despacho.service.ts\n\tmodified: src/app/modals/create-process/create-process.page.html\n\tmodified: src/app/modals/create-process/create-process.page.ts\n\tnew file: src/app/models/eventToAprove.model.ts\n\tmodified: src/app/models/user.model.ts\n\tmodified: src/app/pages/agenda/edit-event/edit-event.page.ts\n\tmodified: src/app/pages/agenda/new-event/new-event.page.ts\n\tmodified: src/app/pages/events/events.page.html\n\tmodified: src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.html\n\tmodified: src/app/pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page.html\n\tmodified: src/app/pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page.ts\n\tmodified: src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page.ts\n\tmodified: src/app/services/auth.service.ts\n\tmodified: src/app/services/http-error-handle.service.ts\n\tmodified: src/app/services/processes.service.ts\n\tmodified: src/app/shared/agenda/approve-event/approve-event.page.ts\n\tmodified: src/app/shared/agenda/edit-event/edit-event.page.ts\n\tmodified: src/app/shared/agenda/new-event/new-event.page.ts\n\tmodified: src/app/shared/chat/group-messages/group-messages.page.ts\n\tmodified: src/app/shared/chat/messages/messages.page.ts\n\tmodified: src/app/shared/header/header.page.html\n\tmodified: src/app/shared/header/header.page.scss\n\tmodified: src/app/shared/popover/deploma-options/deploma-options.page.html\n\tmodified: src/app/shared/popover/deploma-options/deploma-options.page.ts",
"changeStatus": "On branch developer-prod\nYour branch is up to date with 'origin/developer-prod'.\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n\tmodified: src/app/modals/create-process/create-process.page.html\n\tmodified: src/app/modals/profile/edit-profile/edit-profile.page.ts\n\tmodified: src/app/modals/profile/profile.page.ts\n\tmodified: src/app/shared/header/header.page.ts",
"changeAuthor": "eudes.inacio"
}