You've already forked openaccounting-web
mirror of
https://github.com/openaccounting/oa-web.git
synced 2025-12-09 09:01:24 +13:00
initial commit
This commit is contained in:
45
src/app/org/neworg.html
Normal file
45
src/app/org/neworg.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<h1>Organization</h1>
|
||||
|
||||
<div class="section">
|
||||
<h2>Join Organization</h2>
|
||||
|
||||
<p>If you have an invite code, enter it here to join an existing organization.</p>
|
||||
|
||||
<form [formGroup]="joinOrgForm" (ngSubmit)="joinOrgSubmit()">
|
||||
<div class="form-group row">
|
||||
<label for="inviteId" class="col-sm-3 col-form-label">Invite Code</label>
|
||||
<div class="col-sm-9">
|
||||
<input formControlName="inviteId" type="text" class="form-control" id="inviteId">
|
||||
</div>
|
||||
</div>
|
||||
<p *ngIf="joinOrgError" class="error">{{joinOrgError.message}}</p>
|
||||
<button class="btn btn-primary" type="submit" [disabled]="!joinOrgForm.valid">Join</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>New Organization</h2>
|
||||
|
||||
<form [formGroup]="form" (ngSubmit)="onSubmit()">
|
||||
<div class="form-group">
|
||||
<label for="name">Name</label>
|
||||
<input formControlName="name" type="text" class="form-control" id="name" placeholder="Organization name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="currency">Currency</label>
|
||||
<input formControlName="currency" type="text" class="form-control" id="currency" placeholder="Currency">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="precision">Decimal Places</label>
|
||||
<input formControlName="precision" type="text" class="form-control" id="precision" placeholder="Decimal Places">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="createDefaultAccounts">Create default accounts<br>(can be customized later)</label>
|
||||
<input formControlName="createDefaultAccounts" id="createDefaultAccounts" type="checkbox" class="form-control" />
|
||||
</div>
|
||||
<p *ngIf="error" class="error">
|
||||
{{error.message}}
|
||||
</p>
|
||||
<button type="submit" class="btn btn-primary" [disabled]="!form.valid">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
77
src/app/org/neworg.ts
Normal file
77
src/app/org/neworg.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Logger } from '../core/logger';
|
||||
import {
|
||||
FormGroup,
|
||||
FormControl,
|
||||
Validators,
|
||||
FormBuilder,
|
||||
AbstractControl,
|
||||
ValidationErrors
|
||||
} from '@angular/forms';
|
||||
import { OrgService } from '../core/org.service';
|
||||
import { Org } from '../shared/org';
|
||||
import { AppError } from '../shared/error';
|
||||
import { Util } from '../shared/util';
|
||||
|
||||
@Component({
|
||||
selector: 'app-neworg',
|
||||
templateUrl: 'neworg.html'
|
||||
})
|
||||
export class NewOrgPage {
|
||||
public form: FormGroup;
|
||||
public error: AppError;
|
||||
public joinOrgForm: FormGroup;
|
||||
public joinOrgError: AppError;
|
||||
|
||||
constructor(
|
||||
private log: Logger,
|
||||
private orgService: OrgService,
|
||||
private fb: FormBuilder
|
||||
) {
|
||||
this.form = fb.group({
|
||||
'name': ['', Validators.required],
|
||||
'currency': ['USD', Validators.required],
|
||||
'precision': [2, Validators.required],
|
||||
'createDefaultAccounts': [true, Validators.required]
|
||||
});
|
||||
|
||||
this.joinOrgForm = fb.group({
|
||||
'inviteId': [null, Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
//this.dataService.setLoading(true);
|
||||
let org = new Org(this.form.value);
|
||||
org.id = Util.newGuid();
|
||||
|
||||
this.log.debug(org);
|
||||
|
||||
this.orgService.newOrg(org, this.form.value['createDefaultAccounts'])
|
||||
.subscribe(
|
||||
org => {
|
||||
this.log.debug(org);
|
||||
},
|
||||
error => {
|
||||
//this.dataService.setLoading(false);
|
||||
this.log.debug('An error occurred!');
|
||||
this.log.debug(error);
|
||||
this.error = error;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
joinOrgSubmit() {
|
||||
this.log.debug('join org');
|
||||
this.log.debug(this.joinOrgForm.value.id);
|
||||
this.orgService.acceptInvite(this.joinOrgForm.value.inviteId)
|
||||
.switchMap(invite => {
|
||||
return this.orgService.selectOrg(invite.orgId)
|
||||
})
|
||||
.subscribe(org => {
|
||||
console.log('joined org ' + org.id);
|
||||
}, err => {
|
||||
this.joinOrgError = err;
|
||||
})
|
||||
}
|
||||
}
|
||||
117
src/app/org/org.html
Normal file
117
src/app/org/org.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<h1>Organization</h1>
|
||||
|
||||
<div class="section">
|
||||
<h2>Choose Organization</h2>
|
||||
|
||||
<form [formGroup]="chooseOrgForm" (ngSubmit)="chooseOrgSubmit()">
|
||||
<div class="form-group row">
|
||||
<label for="id" class="col-sm-3 col-form-label">Current Organization</label>
|
||||
<div class="col-sm-9">
|
||||
<select class="form-control" id="id" formControlName="id">
|
||||
<option *ngFor="let org of orgs" [value]="org.id">
|
||||
{{org.name}}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p *ngIf="chooseOrgError" class="error">{{chooseOrgError.message}}</p>
|
||||
<button class="btn btn-primary" type="submit" [disabled]="!chooseOrgForm.valid">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Join Organization</h2>
|
||||
|
||||
<form [formGroup]="joinOrgForm" (ngSubmit)="joinOrgSubmit()">
|
||||
<div class="form-group row">
|
||||
<label for="inviteId" class="col-sm-3 col-form-label">Invite Code</label>
|
||||
<div class="col-sm-9">
|
||||
<input formControlName="inviteId" type="text" class="form-control" id="inviteId">
|
||||
</div>
|
||||
</div>
|
||||
<p *ngIf="joinOrgError" class="error">{{joinOrgError.message}}</p>
|
||||
<button class="btn btn-primary" type="submit" [disabled]="!joinOrgForm.valid">Join</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div *ngIf="invites !== null"class="section">
|
||||
|
||||
<h2 >Invite to {{currentOrg.name}}</h2>
|
||||
|
||||
<form [formGroup]="inviteForm" (ngSubmit)="inviteSubmit()">
|
||||
<div class="form-group row">
|
||||
<label for="email" class="col-sm-3 col-form-label">Email</label>
|
||||
<div class="col-sm-9">
|
||||
<input formControlName="email" type="text" class="form-control" id="email">
|
||||
</div>
|
||||
</div>
|
||||
<p *ngIf="inviteFormError" class="error">{{inviteFormError.message}}</p>
|
||||
<button class="btn btn-primary" type="submit" [disabled]="!inviteForm.valid">Invite</button>
|
||||
</form>
|
||||
|
||||
<div class="container-fluid mt-3">
|
||||
<div class="row">
|
||||
<div class="col-3">
|
||||
<strong>Code</strong>
|
||||
</div>
|
||||
<div class="col-5">
|
||||
<strong>Email</strong>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<strong>Status</strong>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" *ngFor="let invite of invites">
|
||||
<div class="col-3">
|
||||
{{invite.id}}
|
||||
</div>
|
||||
<div class="col-5">
|
||||
{{invite.email}}
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<span *ngIf="invite.accepted">accepted</span>
|
||||
<span *ngIf="!invite.accepted">pending</span>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<a (click)="deleteInvite(invite)">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Create Organization</h2>
|
||||
<form [formGroup]="newOrgForm" (ngSubmit)="newOrgSubmit()">
|
||||
<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="createDefaultAccounts" class="col-sm-3 col-form-label">Create default accounts<br>(can be customized later)</label>
|
||||
<div class="col-sm-9">
|
||||
<input formControlName="createDefaultAccounts" id="createDefaultAccounts" type="checkbox" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<p *ngIf="newOrgError" class="error">{{newOrgError.message}}</p>
|
||||
<button class="btn btn-primary" type="submit" [disabled]="!newOrgForm.valid">Create New Organization</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
19
src/app/org/org.module.ts
Normal file
19
src/app/org/org.module.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NewOrgPage } from './neworg';
|
||||
import { OrgPage } from './org';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
NewOrgPage,
|
||||
OrgPage
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
ReactiveFormsModule
|
||||
],
|
||||
providers: []
|
||||
})
|
||||
export class OrgModule { }
|
||||
151
src/app/org/org.ts
Normal file
151
src/app/org/org.ts
Normal file
@@ -0,0 +1,151 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Logger } from '../core/logger';
|
||||
import {
|
||||
FormGroup,
|
||||
FormControl,
|
||||
Validators,
|
||||
FormBuilder,
|
||||
AbstractControl,
|
||||
ValidationErrors
|
||||
} from '@angular/forms';
|
||||
import { OrgService } from '../core/org.service';
|
||||
import { User } from '../shared/user';
|
||||
import { Org } from '../shared/org';
|
||||
import { Invite } from '../shared/invite';
|
||||
import { AppError } from '../shared/error';
|
||||
import { Util } from '../shared/util';
|
||||
|
||||
@Component({
|
||||
selector: 'app-org',
|
||||
templateUrl: 'org.html'
|
||||
})
|
||||
export class OrgPage {
|
||||
public currentOrg: Org;
|
||||
public orgs: Org[] = [];
|
||||
public chooseOrgForm: FormGroup;
|
||||
public chooseOrgError: AppError;
|
||||
public joinOrgForm: FormGroup;
|
||||
public joinOrgError: AppError;
|
||||
public inviteForm: FormGroup;
|
||||
public inviteFormError: AppError;
|
||||
public newOrgForm: FormGroup;
|
||||
public newOrgError: AppError;
|
||||
public invites: Invite[];
|
||||
|
||||
constructor(
|
||||
private log: Logger,
|
||||
private orgService: OrgService,
|
||||
private fb: FormBuilder
|
||||
) {
|
||||
|
||||
this.invites = null;
|
||||
|
||||
this.chooseOrgForm = fb.group({
|
||||
'id': [null, Validators.required]
|
||||
});
|
||||
|
||||
this.joinOrgForm = fb.group({
|
||||
'inviteId': [null, Validators.required]
|
||||
});
|
||||
|
||||
this.inviteForm = fb.group({
|
||||
'email': [null, Validators.required]
|
||||
});
|
||||
|
||||
this.newOrgForm = fb.group({
|
||||
'name': ['', Validators.required],
|
||||
'currency': ['', Validators.required],
|
||||
'precision': [null, Validators.required],
|
||||
'createDefaultAccounts': [true, Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.currentOrg = this.orgService.getCurrentOrg();
|
||||
|
||||
this.chooseOrgForm.setValue({id: this.currentOrg.id});
|
||||
this.newOrgForm.setValue(
|
||||
{
|
||||
name: '',
|
||||
currency: this.currentOrg.currency,
|
||||
precision: this.currentOrg.precision,
|
||||
createDefaultAccounts: true
|
||||
}
|
||||
);
|
||||
|
||||
this.orgService.getOrgs().subscribe(orgs => {
|
||||
this.orgs = orgs;
|
||||
});
|
||||
|
||||
this.orgService.getInvites().subscribe(invites => {
|
||||
this.invites = invites;
|
||||
});
|
||||
}
|
||||
|
||||
chooseOrgSubmit() {
|
||||
this.log.debug('choose new org');
|
||||
this.log.debug(this.chooseOrgForm.value.id);
|
||||
//this.dataService.setLoading(true);
|
||||
this.orgService.selectOrg(this.chooseOrgForm.value.id).subscribe(org => {
|
||||
this.log.debug('new org');
|
||||
this.log.debug(org);
|
||||
});
|
||||
}
|
||||
|
||||
joinOrgSubmit() {
|
||||
this.log.debug('join org');
|
||||
this.log.debug(this.joinOrgForm.value.id);
|
||||
this.orgService.acceptInvite(this.joinOrgForm.value.inviteId)
|
||||
.switchMap(invite => {
|
||||
return this.orgService.selectOrg(invite.orgId)
|
||||
})
|
||||
.subscribe(org => {
|
||||
console.log('joined org ' + org.id);
|
||||
}, err => {
|
||||
this.joinOrgError = err;
|
||||
})
|
||||
}
|
||||
|
||||
inviteSubmit() {
|
||||
this.log.debug('invite');
|
||||
this.log.debug(this.inviteForm.value);
|
||||
|
||||
let invite = new Invite({email: this.inviteForm.value.email});
|
||||
this.orgService.newInvite(invite).subscribe(invite => {
|
||||
this.invites.push(invite);
|
||||
this.inviteForm.reset();
|
||||
}, err => {
|
||||
this.inviteFormError = err;
|
||||
})
|
||||
}
|
||||
|
||||
newOrgSubmit() {
|
||||
//this.dataService.setLoading(true);
|
||||
let org = new Org(this.newOrgForm.value);
|
||||
org.id = Util.newGuid();
|
||||
this.log.debug(org);
|
||||
|
||||
this.orgService.newOrg(org, this.newOrgForm.value['createDefaultAccounts'])
|
||||
.subscribe(
|
||||
org => {
|
||||
this.log.debug(org);
|
||||
},
|
||||
error => {
|
||||
//this.dataService.setLoading(false);
|
||||
this.log.debug('An error occurred!');
|
||||
this.log.debug(error);
|
||||
this.newOrgError = error;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
deleteInvite(invite: Invite) {
|
||||
this.orgService.deleteInvite(invite.id).subscribe(() => {
|
||||
this.invites = this.invites.filter(inv => {
|
||||
return inv.id !== invite.id;
|
||||
});
|
||||
}, err => {
|
||||
this.inviteFormError = err;
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user