Case Sources added primarily to filter the kind of cases in case list.
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Case Source</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"
|
||||
/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Prefix</mat-label>
|
||||
<input
|
||||
matInput
|
||||
placeholder="Prefix"
|
||||
formControlName="prefix"
|
||||
/>
|
||||
</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 { CaseSourceDetailComponent } from './case-source-detail.component';
|
||||
|
||||
describe('CaseSourceDetailComponent', () => {
|
||||
let component: CaseSourceDetailComponent;
|
||||
let fixture: ComponentFixture<CaseSourceDetailComponent>;
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CaseSourceDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CaseSourceDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,102 @@
|
||||
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 { CaseSource } from '../../core/case-source';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { CaseSourceService } from '../case-source.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-case-source-detail',
|
||||
templateUrl: './case-source-detail.component.html',
|
||||
styleUrls: ['./case-source-detail.component.css'],
|
||||
})
|
||||
export class CaseSourceDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: CaseSource = new CaseSource();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: CaseSourceService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
prefix: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: CaseSource };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: CaseSource) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
prefix: this.item.prefix,
|
||||
});
|
||||
}
|
||||
|
||||
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('/case-sources');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id as string).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/case-sources');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: 'Delete Case Source?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): CaseSource {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.prefix = formModel.prefix;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CaseSourceListResolver } from './case-source-list-resolver.service';
|
||||
|
||||
describe('CaseSourceListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CaseSourceListResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CaseSourceListResolver], (service: CaseSourceListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { CaseSource } from '../core/case-source';
|
||||
|
||||
import { CaseSourceService } from './case-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CaseSourceListResolver implements Resolve<CaseSource[]> {
|
||||
constructor(private ser: CaseSourceService) {}
|
||||
|
||||
resolve(): Observable<CaseSource[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { CaseSource } from '../../core/case-source';
|
||||
|
||||
export class CaseSourceListDataSource extends DataSource<CaseSource> {
|
||||
constructor(public data: CaseSource[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<CaseSource[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Case Sources</mat-card-title>
|
||||
<a mat-button [routerLink]="['/case-sources', '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]="['/case-sources', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Prefix Column -->
|
||||
<ng-container matColumnDef="prefix">
|
||||
<mat-header-cell *matHeaderCellDef>Prefix</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.prefix }}</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 { CaseSourceListComponent } from './case-source-list.component';
|
||||
|
||||
describe('CaseSourceListComponent', () => {
|
||||
let component: CaseSourceListComponent;
|
||||
let fixture: ComponentFixture<CaseSourceListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CaseSourceListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CaseSourceListComponent);
|
||||
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 { CaseSource } from '../../core/case-source';
|
||||
|
||||
import { CaseSourceListDataSource } from './case-source-list-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-case-source-list',
|
||||
templateUrl: './case-source-list.component.html',
|
||||
styleUrls: ['./case-source-list.component.css'],
|
||||
})
|
||||
export class CaseSourceListComponent implements OnInit {
|
||||
list: CaseSource[] = [];
|
||||
dataSource: CaseSourceListDataSource = new CaseSourceListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'prefix'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: CaseSource[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new CaseSourceListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CaseSourceResolver } from './case-source-resolver.service';
|
||||
|
||||
describe('CaseSourceResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CaseSourceResolver],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CaseSourceResolver], (service: CaseSourceResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
19
otis/src/app/case-sources/case-source-resolver.service.ts
Normal file
19
otis/src/app/case-sources/case-source-resolver.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { CaseSource } from '../core/case-source';
|
||||
|
||||
import { CaseSourceService } from './case-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CaseSourceResolver implements Resolve<CaseSource> {
|
||||
constructor(private ser: CaseSourceService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<CaseSource> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
15
otis/src/app/case-sources/case-source.service.spec.ts
Normal file
15
otis/src/app/case-sources/case-source.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CaseSourceService } from './case-source.service';
|
||||
|
||||
describe('CaseSourceService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CaseSourceService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CaseSourceService], (service: CaseSourceService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
58
otis/src/app/case-sources/case-source.service.ts
Normal file
58
otis/src/app/case-sources/case-source.service.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { CaseSource } from '../core/case-source';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/case-sources';
|
||||
const serviceName = 'CaseSourceService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CaseSourceService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string | null): Observable<CaseSource> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
return this.http
|
||||
.get<CaseSource>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<CaseSource>;
|
||||
}
|
||||
|
||||
list(): Observable<CaseSource[]> {
|
||||
return this.http
|
||||
.get<CaseSource[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<CaseSource[]>;
|
||||
}
|
||||
|
||||
save(caseSource: CaseSource): Observable<CaseSource> {
|
||||
return this.http
|
||||
.post<CaseSource>(url, caseSource, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<CaseSource>;
|
||||
}
|
||||
|
||||
update(caseSource: CaseSource): Observable<CaseSource> {
|
||||
return this.http
|
||||
.put<CaseSource>(`${url}/${caseSource.id}`, caseSource, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<CaseSource>;
|
||||
}
|
||||
|
||||
saveOrUpdate(caseSource: CaseSource): Observable<CaseSource> {
|
||||
if (!caseSource.id) {
|
||||
return this.save(caseSource);
|
||||
}
|
||||
return this.update(caseSource);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<CaseSource> {
|
||||
return this.http
|
||||
.delete<CaseSource>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<CaseSource>;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { CaseSourcesRoutingModule } from './case-sources-routing.module';
|
||||
|
||||
describe('CasesRoutingModule', () => {
|
||||
let caseSourcesRoutingModule: CaseSourcesRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
caseSourcesRoutingModule = new CaseSourcesRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(caseSourcesRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
53
otis/src/app/case-sources/case-sources-routing.module.ts
Normal file
53
otis/src/app/case-sources/case-sources-routing.module.ts
Normal file
@ -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 { CaseSourceDetailComponent } from './case-source-detail/case-source-detail.component';
|
||||
import { CaseSourceListResolver } from './case-source-list-resolver.service';
|
||||
import { CaseSourceListComponent } from './case-source-list/case-source-list.component';
|
||||
import { CaseSourceResolver } from './case-source-resolver.service';
|
||||
|
||||
const caseSourcesRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: CaseSourceListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Case Sources',
|
||||
},
|
||||
resolve: {
|
||||
list: CaseSourceListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: CaseSourceDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Case Sources',
|
||||
},
|
||||
resolve: {
|
||||
item: CaseSourceResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: CaseSourceDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Case Sources',
|
||||
},
|
||||
resolve: {
|
||||
item: CaseSourceResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(caseSourcesRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [CaseSourceListResolver, CaseSourceResolver],
|
||||
})
|
||||
export class CaseSourcesRoutingModule {}
|
||||
13
otis/src/app/case-sources/case-sources.module.spec.ts
Normal file
13
otis/src/app/case-sources/case-sources.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { CaseSourcesModule } from './case-sources.module';
|
||||
|
||||
describe('CaseSourcesModule', () => {
|
||||
let caseSourcesModule: CaseSourcesModule;
|
||||
|
||||
beforeEach(() => {
|
||||
caseSourcesModule = new CaseSourcesModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(caseSourcesModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
33
otis/src/app/case-sources/case-sources.module.ts
Normal file
33
otis/src/app/case-sources/case-sources.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 { CaseSourceDetailComponent } from './case-source-detail/case-source-detail.component';
|
||||
import { CaseSourceListComponent } from './case-source-list/case-source-list.component';
|
||||
import { CaseSourcesRoutingModule } from './case-sources-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
CaseSourcesRoutingModule,
|
||||
],
|
||||
declarations: [CaseSourceListComponent, CaseSourceDetailComponent],
|
||||
})
|
||||
export class CaseSourcesModule {}
|
||||
Reference in New Issue
Block a user