Initial Commit
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Office Status</mat-card-title>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Name</mat-label>
|
||||
<input
|
||||
matInput
|
||||
#nameElement
|
||||
placeholder="Name"
|
||||
formControlName="name"
|
||||
(keyup.enter)="save()"
|
||||
/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">
|
||||
Delete
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
@ -0,0 +1,26 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { OfficeStatusDetailComponent } from './office-status-detail.component';
|
||||
|
||||
describe('OfficeStatusDetailComponent', () => {
|
||||
let component: OfficeStatusDetailComponent;
|
||||
let fixture: ComponentFixture<OfficeStatusDetailComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [OfficeStatusDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(OfficeStatusDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,99 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { OfficeStatus } from '../../core/office-status';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { OfficeStatusService } from '../office-status.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-office-status-detail',
|
||||
templateUrl: './office-status-detail.component.html',
|
||||
styleUrls: ['./office-status-detail.component.css'],
|
||||
})
|
||||
export class OfficeStatusDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: OfficeStatus = new OfficeStatus();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: OfficeStatusService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: OfficeStatus };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: OfficeStatus) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/office-statuses');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/office-statuses');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: 'Delete Office Status?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): OfficeStatus {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfficeStatusListResolver } from './office-status-list-resolver.service';
|
||||
|
||||
describe('OfficeStatusListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [OfficeStatusListResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject(
|
||||
[OfficeStatusListResolver],
|
||||
(service: OfficeStatusListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { OfficeStatus } from '../core/office-status';
|
||||
|
||||
import { OfficeStatusService } from './office-status.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OfficeStatusListResolver implements Resolve<OfficeStatus[]> {
|
||||
constructor(private ser: OfficeStatusService) {}
|
||||
|
||||
resolve(): Observable<OfficeStatus[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { OfficeStatus } from '../../core/office-status';
|
||||
|
||||
export class OfficeStatusListDataSource extends DataSource<OfficeStatus> {
|
||||
constructor(public data: OfficeStatus[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<OfficeStatus[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Office Statuses</mat-card-title>
|
||||
<a mat-button [routerLink]="['/office-statuses', 'new']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/office-statuses', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,22 @@
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfficeStatusListComponent } from './office-status-list.component';
|
||||
|
||||
describe('OfficeStatusListComponent', () => {
|
||||
let component: OfficeStatusListComponent;
|
||||
let fixture: ComponentFixture<OfficeStatusListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [OfficeStatusListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(OfficeStatusListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,28 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { OfficeStatus } from '../../core/office-status';
|
||||
|
||||
import { OfficeStatusListDataSource } from './office-status-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-office-status-list',
|
||||
templateUrl: './office-status-list.component.html',
|
||||
styleUrls: ['./office-status-list.component.css'],
|
||||
})
|
||||
export class OfficeStatusListComponent implements OnInit {
|
||||
list: OfficeStatus[] = [];
|
||||
dataSource: OfficeStatusListDataSource = new OfficeStatusListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: OfficeStatus[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new OfficeStatusListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfficeStatusResolver } from './office-status-resolver.service';
|
||||
|
||||
describe('OfficeStatusResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [OfficeStatusResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([OfficeStatusResolver], (service: OfficeStatusResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { OfficeStatus } from '../core/office-status';
|
||||
|
||||
import { OfficeStatusService } from './office-status.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OfficeStatusResolver implements Resolve<OfficeStatus> {
|
||||
constructor(private ser: OfficeStatusService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<OfficeStatus> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
15
otis/src/app/office-statuses/office-status.service.spec.ts
Normal file
15
otis/src/app/office-statuses/office-status.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfficeStatusService } from './office-status.service';
|
||||
|
||||
describe('OfficeStatusService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [OfficeStatusService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([OfficeStatusService], (service: OfficeStatusService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
60
otis/src/app/office-statuses/office-status.service.ts
Normal file
60
otis/src/app/office-statuses/office-status.service.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import { OfficeStatus } from '../core/office-status';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/office-statuses';
|
||||
const serviceName = 'OfficeStatusService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class OfficeStatusService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string | null): Observable<OfficeStatus> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<OfficeStatus>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`)),
|
||||
) as Observable<OfficeStatus>;
|
||||
}
|
||||
|
||||
list(): Observable<OfficeStatus[]> {
|
||||
return this.http
|
||||
.get<OfficeStatus[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<OfficeStatus[]>;
|
||||
}
|
||||
|
||||
save(officeStatus: OfficeStatus): Observable<OfficeStatus> {
|
||||
return this.http
|
||||
.post<OfficeStatus>(url, officeStatus, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<OfficeStatus>;
|
||||
}
|
||||
|
||||
update(officeStatus: OfficeStatus): Observable<OfficeStatus> {
|
||||
return this.http
|
||||
.put<OfficeStatus>(`${url}/${officeStatus.id}`, officeStatus, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<OfficeStatus>;
|
||||
}
|
||||
|
||||
saveOrUpdate(officeStatus: OfficeStatus): Observable<OfficeStatus> {
|
||||
if (!officeStatus.id) {
|
||||
return this.save(officeStatus);
|
||||
}
|
||||
return this.update(officeStatus);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<OfficeStatus> {
|
||||
return this.http
|
||||
.delete<OfficeStatus>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<OfficeStatus>;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { OfficeStatusesRoutingModule } from './office-statuses-routing.module';
|
||||
|
||||
describe('OfficesRoutingModule', () => {
|
||||
let officeStatusesRoutingModule: OfficeStatusesRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
officeStatusesRoutingModule = new OfficeStatusesRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(officeStatusesRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,53 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { OfficeStatusDetailComponent } from './office-status-detail/office-status-detail.component';
|
||||
import { OfficeStatusListResolver } from './office-status-list-resolver.service';
|
||||
import { OfficeStatusListComponent } from './office-status-list/office-status-list.component';
|
||||
import { OfficeStatusResolver } from './office-status-resolver.service';
|
||||
|
||||
const officeStatusesRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: OfficeStatusListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Office Statuses',
|
||||
},
|
||||
resolve: {
|
||||
list: OfficeStatusListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: OfficeStatusDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Office Statuses',
|
||||
},
|
||||
resolve: {
|
||||
item: OfficeStatusResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: OfficeStatusDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Office Statuses',
|
||||
},
|
||||
resolve: {
|
||||
item: OfficeStatusResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(officeStatusesRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [OfficeStatusListResolver, OfficeStatusResolver],
|
||||
})
|
||||
export class OfficeStatusesRoutingModule {}
|
||||
13
otis/src/app/office-statuses/office-statuses.module.spec.ts
Normal file
13
otis/src/app/office-statuses/office-statuses.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { OfficeStatusesModule } from './office-statuses.module';
|
||||
|
||||
describe('OfficeStatusesModule', () => {
|
||||
let officeStatusesModule: OfficeStatusesModule;
|
||||
|
||||
beforeEach(() => {
|
||||
officeStatusesModule = new OfficeStatusesModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(officeStatusesModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
33
otis/src/app/office-statuses/office-statuses.module.ts
Normal file
33
otis/src/app/office-statuses/office-statuses.module.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
import { OfficeStatusDetailComponent } from './office-status-detail/office-status-detail.component';
|
||||
import { OfficeStatusListComponent } from './office-status-list/office-status-list.component';
|
||||
import { OfficeStatusesRoutingModule } from './office-statuses-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
OfficeStatusesRoutingModule,
|
||||
],
|
||||
declarations: [OfficeStatusListComponent, OfficeStatusDetailComponent],
|
||||
})
|
||||
export class OfficeStatusesModule {}
|
||||
Reference in New Issue
Block a user