diff --git a/src/app/client-profile/client-profile.component.html b/src/app/client-profile/client-profile.component.html index a97295c..dee7506 100644 --- a/src/app/client-profile/client-profile.component.html +++ b/src/app/client-profile/client-profile.component.html @@ -1 +1,76 @@ -

client-profile works!

+ + +
+
+
+
+
Edit : {{User.First + ' ' + User.Last}}
+ +
+
+
+
+
+ + + + only jpg and png are allowed + +
+
+
+ +
+ +
+ + + + First name is required + +
+ + + + + Last Name is required + +
+ + + + + Display name cannot empty + +
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+ + +

{{ Message }}

+ + + +
diff --git a/src/app/client-profile/client-profile.component.scss b/src/app/client-profile/client-profile.component.scss index e69de29..7d990e4 100644 --- a/src/app/client-profile/client-profile.component.scss +++ b/src/app/client-profile/client-profile.component.scss @@ -0,0 +1,33 @@ +div.container { + max-width: 500px; +} + +div.vertical-spacer { + height:1px; + margin-bottom: 30px; +} + + +.dropzoneInvisible{ + opacity:0.1; +} + +.avatar { + width: 100%; +} + +.broker-photo { + display: inline-block; + width: 256px; + height: 256px; + border-radius: 50%; + background-size: 256px 256px; + background-position: center center; + vertical-align: middle; + line-height: 132px; + box-shadow: inset 0 0 1px #999, inset 0 0 10px rgba(0,0,0,.2); + margin-left: 5px; + margin-bottom: 10px; + background-repeat: no-repeat; + box-shadow: 1px 1px 10px black; +} diff --git a/src/app/client-profile/client-profile.component.ts b/src/app/client-profile/client-profile.component.ts index a322030..b0cf67d 100644 --- a/src/app/client-profile/client-profile.component.ts +++ b/src/app/client-profile/client-profile.component.ts @@ -1,4 +1,10 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {PeopleModel} from '../models/people.model'; +import {NgForm} from '@angular/forms'; +import {AuthService} from '../service/auth.service'; +import {PeopleService} from '../service/people.service'; +import {FileInfo, FileRestrictions, FileSelectComponent, SelectEvent} from '@progress/kendo-angular-upload'; +import {BrokerModel} from '../models/broker.model'; @Component({ selector: 'app-client-profile', @@ -6,10 +12,69 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./client-profile.component.scss'] }) export class ClientProfileComponent implements OnInit { + @Input() User: PeopleModel = PeopleModel.EmptyNew(); + @ViewChild('fileSelect', {static: true}) fs: FileSelectComponent; + public avatarUrl = 'url(https://svr2021.lawipac.com:8080/api/v1/avatar/1000)' ; + public myRestrictions: FileRestrictions = { + allowedExtensions: ['.jpg', '.png', '.jpeg'], + maxFileSize: 2194304 + }; + + public opened = false; // dialog box + public Message = ''; // dialog message + + constructor(private auth: AuthService, private ps: PeopleService) { } - constructor() { } ngOnInit(): void { + this.User = this.auth.loggedIn.user; + this.avatarUrl = 'url(' + this.auth.getUrl('avatar/' + this.User.Id) + ')'; + } + + + public save(brokerForm: NgForm): void{ + if (! brokerForm.touched || brokerForm.form.pristine) { + return; + } + this.ps.saveUser(this.User).subscribe( () => { + this.showDialog('updated successfully '); + brokerForm.form.markAsPristine(); + }, err => { + this.showDialog('Failed to Update: ' + err.toString()); + }); } + public onSelect(ev: SelectEvent): void { + if (ev.files) { + ev.files.every((file: FileInfo) => { + if (file.rawFile && !file.validationErrors) { + const reader = new FileReader(); + + reader.onloadend = () => { + const str = reader.result as string; + this.ps.updateAvatar(str, this.User.Id).subscribe( resp => { + this.avatarUrl = 'url(' + str + ' )'; + }, err => { + this.showDialog('Failed to Update Avatar: ' + err.toString()); + }); + this.fs.clearFiles(); + }; + reader.readAsDataURL(file.rawFile); + }else{ + this.showDialog('Only jpg, and png are supported (max 2MB)'); + setTimeout(() => { this.fs.clearFiles(); }, 10); + } + return false; // we only take first file + }); + } + } + + public showDialog(msg: string): void { + this.Message = msg; + this.opened = true; // open dialog + } + + public close(status): void { + this.opened = false; + } } diff --git a/src/app/service/people.service.ts b/src/app/service/people.service.ts index 5884c16..5ab2372 100644 --- a/src/app/service/people.service.ts +++ b/src/app/service/people.service.ts @@ -41,4 +41,7 @@ export class PeopleService { return this.http.post(this.auth.getUrl('broker/' + broker.Id), broker); } + public saveUser(people: PeopleModel): Observable{ + return this.http.post(this.auth.getUrl('people/' + people.Id), people); + } }