From 5b720b79c4d08d90e52780b5df27ad8fb637aa99 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 27 Jun 2019 16:26:31 -0400 Subject: [PATCH] update org timezone --- src/app/core/api.service.ts | 5 +++++ src/app/core/org.service.ts | 8 +++++++ src/app/org/org.html | 45 +++++++++++++++++++++++++++++++++++++ src/app/org/org.ts | 42 ++++++++++++++++++++++++++++++++++ src/app/shared/util.ts | 9 ++++++++ 5 files changed, 109 insertions(+) diff --git a/src/app/core/api.service.ts b/src/app/core/api.service.ts index e61996f..fd0650f 100644 --- a/src/app/core/api.service.ts +++ b/src/app/core/api.service.ts @@ -231,6 +231,11 @@ export class ApiService { .pipe(catchError(this.handleError)); } + putOrg(org: Org): Observable { + return this.http.put(this.url + '/orgs/' + this.orgId, org, this.httpOptions) + .pipe(catchError(this.handleError)); + } + getPricesNearestInTime(date: Date): Observable { let query = '/orgs/' + this.orgId + '/prices?nearestDate=' + date.getTime(); return this.http.get(this.url + query, this.httpOptions) diff --git a/src/app/core/org.service.ts b/src/app/core/org.service.ts index 007ec77..b54478d 100644 --- a/src/app/core/org.service.ts +++ b/src/app/core/org.service.ts @@ -59,6 +59,14 @@ export class OrgService { }); } + updateOrg(org: Org): Observable { + return this.apiService.putOrg(org) + .do(org => { + this.org = org; + this.sessionService.switchOrg(this.org); + }) + } + getInvites(): Observable { return this.apiService.getInvites(); } diff --git a/src/app/org/org.html b/src/app/org/org.html index a376751..cd60567 100644 --- a/src/app/org/org.html +++ b/src/app/org/org.html @@ -1,6 +1,41 @@

Organization

+

Current Organization

+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+

{{updateOrgError.message}}

+ +
+

Choose Organization

@@ -103,6 +138,16 @@
+
+ +
+ +
+
diff --git a/src/app/org/org.ts b/src/app/org/org.ts index e5e570c..4c67aea 100644 --- a/src/app/org/org.ts +++ b/src/app/org/org.ts @@ -30,7 +30,11 @@ export class OrgPage { public inviteFormError: AppError; public newOrgForm: FormGroup; public newOrgError: AppError; + public updateOrgForm: FormGroup; + public updateOrgError: AppError; public invites: Invite[]; + public timezones: string[]; + public defaultTz: string; constructor( private log: Logger, @@ -38,8 +42,19 @@ export class OrgPage { private fb: FormBuilder ) { + this.timezones = Util.getTimezones(); + this.defaultTz = Util.getDefaultTimezone(); + + console.log('defaultTz', this.defaultTz); this.invites = null; + this.updateOrgForm = fb.group({ + 'name': ['', Validators.required], + 'currency': [{value: '', disabled: true}, Validators.required], + 'precision': [{value: null, disabled: true}, Validators.required], + 'timezone': ['', Validators.required] + }); + this.chooseOrgForm = fb.group({ 'id': [null, Validators.required] }); @@ -56,6 +71,7 @@ export class OrgPage { 'name': ['', Validators.required], 'currency': ['', Validators.required], 'precision': [null, Validators.required], + 'timezone': [this.defaultTz, Validators.required], 'createDefaultAccounts': [true, Validators.required] }); } @@ -63,12 +79,22 @@ export class OrgPage { ngOnInit() { this.currentOrg = this.orgService.getCurrentOrg(); + this.updateOrgForm.setValue( + { + name: this.currentOrg.name, + currency: this.currentOrg.currency, + precision: this.currentOrg.precision, + timezone: this.currentOrg.timezone + } + ); + this.chooseOrgForm.setValue({id: this.currentOrg.id}); this.newOrgForm.setValue( { name: '', currency: this.currentOrg.currency, precision: this.currentOrg.precision, + timezone: this.defaultTz, createDefaultAccounts: true } ); @@ -139,6 +165,22 @@ export class OrgPage { ); } + updateOrgSubmit() { + let org = this.currentOrg; + org.name = this.updateOrgForm.get('name').value; + org.timezone = this.updateOrgForm.get('timezone').value; + + this.orgService.updateOrg(org) + .subscribe( + org => { + this.log.debug(org); + }, + error => { + this.updateOrgError = error; + } + ); + } + deleteInvite(invite: Invite) { this.orgService.deleteInvite(invite.id).subscribe(() => { this.invites = this.invites.filter(inv => { diff --git a/src/app/shared/util.ts b/src/app/shared/util.ts index a190f1a..e670eae 100644 --- a/src/app/shared/util.ts +++ b/src/app/shared/util.ts @@ -164,6 +164,15 @@ export class Util { return m.toDate(); } + static getTimezones(): string[] { + let timezones = ['']; + return timezones.concat(moment.tz.names()); + } + + static getDefaultTimezone(): string { + return defaultTz; + } + static newGuid() { let arr = new Uint8Array(16); window.crypto.getRandomValues(arr);