You've already forked openaccounting-web
mirror of
https://github.com/openaccounting/oa-web.git
synced 2025-12-09 09:01:24 +13:00
update org timezone
This commit is contained in:
@@ -231,6 +231,11 @@ export class ApiService {
|
|||||||
.pipe(catchError(this.handleError));
|
.pipe(catchError(this.handleError));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putOrg(org: Org): Observable<Org> {
|
||||||
|
return this.http.put<Org>(this.url + '/orgs/' + this.orgId, org, this.httpOptions)
|
||||||
|
.pipe(catchError(this.handleError));
|
||||||
|
}
|
||||||
|
|
||||||
getPricesNearestInTime(date: Date): Observable<Price[]> {
|
getPricesNearestInTime(date: Date): Observable<Price[]> {
|
||||||
let query = '/orgs/' + this.orgId + '/prices?nearestDate=' + date.getTime();
|
let query = '/orgs/' + this.orgId + '/prices?nearestDate=' + date.getTime();
|
||||||
return this.http.get<Price[]>(this.url + query, this.httpOptions)
|
return this.http.get<Price[]>(this.url + query, this.httpOptions)
|
||||||
|
|||||||
@@ -59,6 +59,14 @@ export class OrgService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateOrg(org: Org): Observable<Org> {
|
||||||
|
return this.apiService.putOrg(org)
|
||||||
|
.do(org => {
|
||||||
|
this.org = org;
|
||||||
|
this.sessionService.switchOrg(this.org);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
getInvites(): Observable<Invite[]> {
|
getInvites(): Observable<Invite[]> {
|
||||||
return this.apiService.getInvites();
|
return this.apiService.getInvites();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,41 @@
|
|||||||
<h1>Organization</h1>
|
<h1>Organization</h1>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
|
<h2>Current Organization</h2>
|
||||||
|
|
||||||
|
<form [formGroup]="updateOrgForm" (ngSubmit)="updateOrgSubmit()">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="name" class="col-sm-3 col-form-label">Name</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<input formControlName="name" type="text" class="form-control" id="name" placeholder="Organization name">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="currency" class="col-sm-3 col-form-label">Currency</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<input formControlName="currency" type="text" class="form-control" id="currency" placeholder="Currency">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="precision" class="col-sm-3 col-form-label">Decimal Places</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<input formControlName="precision" type="text" class="form-control" id="precision" placeholder="Decimal Places">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="timezone" class="col-sm-3 col-form-label">Timezone</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<select class="form-control" id="timezone" formControlName="timezone">
|
||||||
|
<option *ngFor="let tz of timezones" [value]="tz">
|
||||||
|
{{tz}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p *ngIf="updateOrgError" class="error">{{updateOrgError.message}}</p>
|
||||||
|
<button class="btn btn-primary" type="submit" [disabled]="!updateOrgForm.valid">Save Changes</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
<h2>Choose Organization</h2>
|
<h2>Choose Organization</h2>
|
||||||
|
|
||||||
<form [formGroup]="chooseOrgForm" (ngSubmit)="chooseOrgSubmit()">
|
<form [formGroup]="chooseOrgForm" (ngSubmit)="chooseOrgSubmit()">
|
||||||
@@ -103,6 +138,16 @@
|
|||||||
<input formControlName="precision" type="text" class="form-control" id="precision" placeholder="Decimal Places">
|
<input formControlName="precision" type="text" class="form-control" id="precision" placeholder="Decimal Places">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="timezone" class="col-sm-3 col-form-label">Timezone</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<select class="form-control" id="timezone" formControlName="timezone">
|
||||||
|
<option *ngFor="let tz of timezones" [value]="tz">
|
||||||
|
{{tz}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="createDefaultAccounts" class="col-sm-3 col-form-label">Create default accounts<br>(can be customized later)</label>
|
<label for="createDefaultAccounts" class="col-sm-3 col-form-label">Create default accounts<br>(can be customized later)</label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
|
|||||||
@@ -30,7 +30,11 @@ export class OrgPage {
|
|||||||
public inviteFormError: AppError;
|
public inviteFormError: AppError;
|
||||||
public newOrgForm: FormGroup;
|
public newOrgForm: FormGroup;
|
||||||
public newOrgError: AppError;
|
public newOrgError: AppError;
|
||||||
|
public updateOrgForm: FormGroup;
|
||||||
|
public updateOrgError: AppError;
|
||||||
public invites: Invite[];
|
public invites: Invite[];
|
||||||
|
public timezones: string[];
|
||||||
|
public defaultTz: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private log: Logger,
|
private log: Logger,
|
||||||
@@ -38,8 +42,19 @@ export class OrgPage {
|
|||||||
private fb: FormBuilder
|
private fb: FormBuilder
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
this.timezones = Util.getTimezones();
|
||||||
|
this.defaultTz = Util.getDefaultTimezone();
|
||||||
|
|
||||||
|
console.log('defaultTz', this.defaultTz);
|
||||||
this.invites = null;
|
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({
|
this.chooseOrgForm = fb.group({
|
||||||
'id': [null, Validators.required]
|
'id': [null, Validators.required]
|
||||||
});
|
});
|
||||||
@@ -56,6 +71,7 @@ export class OrgPage {
|
|||||||
'name': ['', Validators.required],
|
'name': ['', Validators.required],
|
||||||
'currency': ['', Validators.required],
|
'currency': ['', Validators.required],
|
||||||
'precision': [null, Validators.required],
|
'precision': [null, Validators.required],
|
||||||
|
'timezone': [this.defaultTz, Validators.required],
|
||||||
'createDefaultAccounts': [true, Validators.required]
|
'createDefaultAccounts': [true, Validators.required]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -63,12 +79,22 @@ export class OrgPage {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.currentOrg = this.orgService.getCurrentOrg();
|
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.chooseOrgForm.setValue({id: this.currentOrg.id});
|
||||||
this.newOrgForm.setValue(
|
this.newOrgForm.setValue(
|
||||||
{
|
{
|
||||||
name: '',
|
name: '',
|
||||||
currency: this.currentOrg.currency,
|
currency: this.currentOrg.currency,
|
||||||
precision: this.currentOrg.precision,
|
precision: this.currentOrg.precision,
|
||||||
|
timezone: this.defaultTz,
|
||||||
createDefaultAccounts: true
|
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) {
|
deleteInvite(invite: Invite) {
|
||||||
this.orgService.deleteInvite(invite.id).subscribe(() => {
|
this.orgService.deleteInvite(invite.id).subscribe(() => {
|
||||||
this.invites = this.invites.filter(inv => {
|
this.invites = this.invites.filter(inv => {
|
||||||
|
|||||||
@@ -164,6 +164,15 @@ export class Util {
|
|||||||
return m.toDate();
|
return m.toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getTimezones(): string[] {
|
||||||
|
let timezones = [''];
|
||||||
|
return timezones.concat(moment.tz.names());
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDefaultTimezone(): string {
|
||||||
|
return defaultTz;
|
||||||
|
}
|
||||||
|
|
||||||
static newGuid() {
|
static newGuid() {
|
||||||
let arr = new Uint8Array(16);
|
let arr = new Uint8Array(16);
|
||||||
window.crypto.getRandomValues(arr);
|
window.crypto.getRandomValues(arr);
|
||||||
|
|||||||
Reference in New Issue
Block a user