Initial Commit

This commit is contained in:
2021-01-05 13:02:52 +05:30
commit ec992df1da
520 changed files with 38712 additions and 0 deletions

View File

@ -0,0 +1,3 @@
.right-align {
text-align: right;
}

View File

@ -0,0 +1,76 @@
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Office</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>
<div
fxLayout="row"
fxLayoutAlign="space-around start"
fxLayout.lt-md="column"
fxLayoutGap="20px"
fxLayoutGap.lt-md="0px"
>
<mat-form-field fxFlex>
<mat-label>Email</mat-label>
<input matInput placeholder="Email" formControlName="email" />
</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>Address</mat-label>
<input matInput placeholder="Address" formControlName="address" />
</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>Department</mat-label>
<mat-select placeholder="Department" formControlName="department">
<mat-option value=""> -- Not Applicable -- </mat-option>
<mat-option *ngFor="let d of departments" [value]="d.id">
{{ d.name }}
</mat-option>
</mat-select>
</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>

View File

@ -0,0 +1,26 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { OfficeDetailComponent } from './office-detail.component';
describe('OfficeDetailComponent', () => {
let component: OfficeDetailComponent;
let fixture: ComponentFixture<OfficeDetailComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [OfficeDetailComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(OfficeDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,119 @@
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 { Department } from '../../core/department';
import { Office } from '../../core/office';
import { ToasterService } from '../../core/toaster.service';
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
import { OfficeService } from '../office.service';
@Component({
selector: 'app-office-detail',
templateUrl: './office-detail.component.html',
styleUrls: ['./office-detail.component.css'],
})
export class OfficeDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup;
departments: Department[] = [];
item: Office = new Office();
constructor(
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: OfficeService,
) {
// Create form
this.form = this.fb.group({
name: '',
email: '',
address: '',
department: '',
});
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { item: Office; departments: Department[] };
this.departments = data.departments;
this.showItem(data.item);
});
}
showItem(item: Office) {
this.item = item;
this.form.setValue({
name: this.item.name,
email: this.item.email,
address: this.item.address,
department: this.item.department ? this.item.department.id : '',
});
}
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('/offices');
},
(error) => {
this.toaster.show('Error', error);
},
);
}
delete() {
this.ser.delete(this.item.id as string).subscribe(
() => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/offices');
},
(error) => {
this.toaster.show('Error', error);
},
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: { title: 'Delete Office?', content: 'Are you sure? This cannot be undone.' },
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.delete();
}
});
}
getItem(): Office {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.email = formModel.email;
this.item.address = formModel.address;
if (formModel.department === undefined || formModel.department === '') {
this.item.department = undefined;
} else {
if (this.item.department === null || this.item.department === undefined) {
this.item.department = new Department();
}
this.item.department.id = formModel.department;
}
return this.item;
}
}

View File

@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';
import { OfficeListResolver } from './office-list-resolver.service';
describe('OfficeListResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OfficeListResolver],
});
});
it('should be created', inject([OfficeListResolver], (service: OfficesListResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { Office } from '../core/office';
import { OfficeService } from './office.service';
@Injectable({
providedIn: 'root',
})
export class OfficeListResolver implements Resolve<Office[]> {
constructor(private ser: OfficeService) {}
resolve(): Observable<Office[]> {
return this.ser.list();
}
}

View File

@ -0,0 +1,16 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
import { Office } from '../../core/office';
export class OfficeListDataSource extends DataSource<Office> {
constructor(public data: Office[]) {
super();
}
connect(): Observable<Office[]> {
return observableOf(this.data);
}
disconnect() {}
}

View File

@ -0,0 +1,40 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Offices</mat-card-title>
<a mat-button [routerLink]="['/offices', '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]="['/offices', row.id]">{{ row.name }}</a></mat-cell
>
</ng-container>
<!-- Email Column -->
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef>Email</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.email }}</mat-cell>
</ng-container>
<!-- Address Column -->
<ng-container matColumnDef="address">
<mat-header-cell *matHeaderCellDef>Address</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.address }}</mat-cell>
</ng-container>
<!-- Department Column -->
<ng-container matColumnDef="department">
<mat-header-cell *matHeaderCellDef>Department</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.department?.name }}</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>

View File

@ -0,0 +1,22 @@
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { OfficeListComponent } from './office-list.component';
describe('OfficeListComponent', () => {
let component: OfficeListComponent;
let fixture: ComponentFixture<OfficeListComponent>;
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [OfficeListComponent],
}).compileComponents();
fixture = TestBed.createComponent(OfficeListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should compile', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,28 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Office } from '../../core/office';
import { OfficeListDataSource } from './office-list-datasource';
@Component({
selector: 'app-office-list',
templateUrl: './office-list.component.html',
styleUrls: ['./office-list.component.css'],
})
export class OfficeListComponent implements OnInit {
list: Office[] = [];
dataSource: OfficeListDataSource = new OfficeListDataSource(this.list);
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'email', 'address', 'department'];
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { list: Office[] };
this.list = data.list;
});
this.dataSource = new OfficeListDataSource(this.list);
}
}

View File

@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';
import { OfficeResolver } from './office-resolver.service';
describe('OfficeResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OfficeResolver],
});
});
it('should be created', inject([OfficeResolver], (service: OfficeResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { Office } from '../core/office';
import { OfficeService } from './office.service';
@Injectable({
providedIn: 'root',
})
export class OfficeResolver implements Resolve<Office> {
constructor(private ser: OfficeService) {}
resolve(route: ActivatedRouteSnapshot): Observable<Office> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}
}

View File

@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';
import { OfficeService } from './office.service';
describe('OfficeService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [OfficeService],
});
});
it('should be created', inject([OfficeService], (service: OfficeService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,66 @@
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 { Office } from '../core/office';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/offices';
const serviceName = 'OfficeService';
@Injectable({
providedIn: 'root',
})
export class OfficeService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string | null): Observable<Office> {
const getUrl: string = id === null ? url : `${url}/${id}`;
return this.http
.get<Office>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Office>;
}
list(): Observable<Office[]> {
return this.http
.get<Office[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Office[]>;
}
filteredList(departmentId: string): Observable<Office[]> {
return this.http
.get<Office[]>(`${url}/of-department/${departmentId}`)
.pipe(
catchError(this.log.handleError(serviceName, `filteredList departmentId=${departmentId}`)),
) as Observable<Office[]>;
}
save(office: Office): Observable<Office> {
return this.http
.post<Office>(url, office, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Office>;
}
update(office: Office): Observable<Office> {
return this.http
.put<Office>(`${url}/${office.id}`, office, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Office>;
}
saveOrUpdate(office: Office): Observable<Office> {
if (!office.id) {
return this.save(office);
}
return this.update(office);
}
delete(id: string): Observable<Office> {
return this.http
.delete<Office>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Office>;
}
}

View File

@ -0,0 +1,13 @@
import { OfficesRoutingModule } from './offices-routing.module';
describe('OfficesRoutingModule', () => {
let advocatesRoutingModule: OfficesRoutingModule;
beforeEach(() => {
advocatesRoutingModule = new OfficesRoutingModule();
});
it('should create an instance', () => {
expect(advocatesRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,56 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '../auth/auth-guard.service';
import { DepartmentListResolver } from '../departments/department-list-resolver.service';
import { OfficeDetailComponent } from './office-detail/office-detail.component';
import { OfficeListResolver } from './office-list-resolver.service';
import { OfficeListComponent } from './office-list/office-list.component';
import { OfficeResolver } from './office-resolver.service';
const advocatesRoutes: Routes = [
{
path: '',
component: OfficeListComponent,
canActivate: [AuthGuard],
data: {
permission: 'Offices',
},
resolve: {
list: OfficeListResolver,
},
},
{
path: 'new',
component: OfficeDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Offices',
},
resolve: {
item: OfficeResolver,
departments: DepartmentListResolver,
},
},
{
path: ':id',
component: OfficeDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Offices',
},
resolve: {
item: OfficeResolver,
departments: DepartmentListResolver,
},
},
];
@NgModule({
imports: [CommonModule, RouterModule.forChild(advocatesRoutes)],
exports: [RouterModule],
providers: [OfficeListResolver, OfficeResolver],
})
export class OfficesRoutingModule {}

View File

@ -0,0 +1,13 @@
import { OfficesModule } from './offices.module';
describe('OfficesModule', () => {
let advocatesModule: OfficesModule;
beforeEach(() => {
advocatesModule = new OfficesModule();
});
it('should create an instance', () => {
expect(advocatesModule).toBeTruthy();
});
});

View File

@ -0,0 +1,35 @@
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 { MatSelectModule } from '@angular/material/select';
import { MatTableModule } from '@angular/material/table';
import { OfficeDetailComponent } from './office-detail/office-detail.component';
import { OfficeListComponent } from './office-list/office-list.component';
import { OfficesRoutingModule } from './offices-routing.module';
@NgModule({
imports: [
CommonModule,
CdkTableModule,
FlexLayoutModule,
MatButtonModule,
MatCardModule,
MatIconModule,
MatInputModule,
MatProgressSpinnerModule,
MatTableModule,
ReactiveFormsModule,
OfficesRoutingModule,
MatSelectModule,
],
declarations: [OfficeListComponent, OfficeDetailComponent],
})
export class OfficesModule {}