Big Chunk of updates on way to making the sales portion working
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Device</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>Section</mat-label>
|
||||
<mat-select placeholder="Section" formControlName="section">
|
||||
<mat-option *ngFor="let s of sections" [value]="s.id">
|
||||
{{ s.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>
|
||||
@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DeviceDetailComponent} from './device-detail.component';
|
||||
|
||||
describe('DeviceDetailComponent', () => {
|
||||
let component: DeviceDetailComponent;
|
||||
let fixture: ComponentFixture<DeviceDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [DeviceDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DeviceDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
108
bookie/src/app/devices/device-detail/device-detail.component.ts
Normal file
108
bookie/src/app/devices/device-detail/device-detail.component.ts
Normal file
@ -0,0 +1,108 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog} from "@angular/material/dialog";
|
||||
|
||||
import { DeviceService } from '../device.service';
|
||||
import { Device } from '../../core/device';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
|
||||
import { Section } from "../../core/section";
|
||||
|
||||
@Component({
|
||||
selector: 'app-device-detail',
|
||||
templateUrl: './device-detail.component.html',
|
||||
styleUrls: ['./device-detail.component.css']
|
||||
})
|
||||
export class DeviceDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
sections: Section[];
|
||||
item: Device;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: DeviceService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
section: ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Device, sections: Section[] }) => {
|
||||
this.showItem(data.item);
|
||||
this.sections = data.sections;
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Device) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
section: this.item.section.id ? this.item.section.id : ''
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/devices');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/devices');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Device?', content: 'Are you sure? This cannot be undone.'}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): Device {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.section.id = formModel.section;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/devices/device-list-resolver.service.spec.ts
Normal file
15
bookie/src/app/devices/device-list-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DeviceListResolver} from './device-list-resolver.service';
|
||||
|
||||
describe('DeviceListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DeviceListResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([DeviceListResolver], (service: DeviceListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
18
bookie/src/app/devices/device-list-resolver.service.ts
Normal file
18
bookie/src/app/devices/device-list-resolver.service.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Device} from '../core/device';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {DeviceService} from './device.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DeviceListResolver implements Resolve<Device[]> {
|
||||
|
||||
constructor(private ser: DeviceService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Device[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
17
bookie/src/app/devices/device-list/device-list-datasource.ts
Normal file
17
bookie/src/app/devices/device-list/device-list-datasource.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { DataSource} from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf} from 'rxjs';
|
||||
import { Device} from '../../core/device';
|
||||
|
||||
export class DeviceListDataSource extends DataSource<Device> {
|
||||
|
||||
constructor(public data: Device[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Device[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Devices</mat-card-title>
|
||||
<a mat-button [routerLink]="['/devices', '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]="['/devices', row.id]">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Section Column -->
|
||||
<ng-container matColumnDef="tax">
|
||||
<mat-header-cell *matHeaderCellDef>Section</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.section.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>
|
||||
@ -0,0 +1,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DeviceListComponent} from './device-list.component';
|
||||
|
||||
describe('DeviceListComponent', () => {
|
||||
let component: DeviceListComponent;
|
||||
let fixture: ComponentFixture<DeviceListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [DeviceListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(DeviceListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
27
bookie/src/app/devices/device-list/device-list.component.ts
Normal file
27
bookie/src/app/devices/device-list/device-list.component.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { DeviceListDataSource } from './device-list-datasource';
|
||||
import { Device } from '../../core/device';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-device-list',
|
||||
templateUrl: './device-list.component.html',
|
||||
styleUrls: ['./device-list.component.css']
|
||||
})
|
||||
export class DeviceListComponent implements OnInit {
|
||||
dataSource: DeviceListDataSource;
|
||||
list: Device[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Device[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new DeviceListDataSource(this.list);
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/devices/device-resolver.service.spec.ts
Normal file
15
bookie/src/app/devices/device-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DeviceResolver} from './device-resolver.service';
|
||||
|
||||
describe('DeviceResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DeviceResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([DeviceResolver], (service: DeviceResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
19
bookie/src/app/devices/device-resolver.service.ts
Normal file
19
bookie/src/app/devices/device-resolver.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {DeviceService} from './device.service';
|
||||
import {Device} from '../core/device';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DeviceResolver implements Resolve<Device> {
|
||||
|
||||
constructor(private ser: DeviceService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Device> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/devices/device.service.spec.ts
Normal file
15
bookie/src/app/devices/device.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {DeviceService} from './device.service';
|
||||
|
||||
describe('DeviceService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DeviceService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([DeviceService], (service: DeviceService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
65
bookie/src/app/devices/device.service.ts
Normal file
65
bookie/src/app/devices/device.service.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {Device} from '../core/device';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/v1/devices';
|
||||
const serviceName = 'DeviceService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DeviceService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Device> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
return <Observable<Device>>this.http.get<Device>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Device[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Device[]>>this.http.get<Device[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(device: Device): Observable<Device> {
|
||||
return <Observable<Device>>this.http.post<Device>(`${url}/new`, device, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(device: Device): Observable<Device> {
|
||||
return <Observable<Device>>this.http.put<Device>(`${url}/${device.id}`, device, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(device: Device): Observable<Device> {
|
||||
if (!device.id) {
|
||||
return this.save(device);
|
||||
} else {
|
||||
return this.update(device);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Device> {
|
||||
return <Observable<Device>>this.http.delete<Device>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
13
bookie/src/app/devices/devices-routing.module.spec.ts
Normal file
13
bookie/src/app/devices/devices-routing.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {DevicesRoutingModule} from './devices-routing.module';
|
||||
|
||||
describe('DevicesRoutingModule', () => {
|
||||
let devicesRoutingModule: DevicesRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
devicesRoutingModule = new DevicesRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(devicesRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
64
bookie/src/app/devices/devices-routing.module.ts
Normal file
64
bookie/src/app/devices/devices-routing.module.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {DeviceListResolver} from './device-list-resolver.service';
|
||||
import {DeviceResolver} from './device-resolver.service';
|
||||
import {DeviceListComponent} from './device-list/device-list.component';
|
||||
import {DeviceDetailComponent} from './device-detail/device-detail.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import {SectionListResolver} from "../sections/section-list-resolver.service";
|
||||
|
||||
const devicesRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: DeviceListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Devices'
|
||||
},
|
||||
resolve: {
|
||||
list: DeviceListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: DeviceDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Devices'
|
||||
},
|
||||
resolve: {
|
||||
item: DeviceResolver,
|
||||
sections: SectionListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: DeviceDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Devices'
|
||||
},
|
||||
resolve: {
|
||||
item: DeviceResolver,
|
||||
sections: SectionListResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(devicesRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
DeviceListResolver,
|
||||
DeviceResolver
|
||||
]
|
||||
})
|
||||
export class DevicesRoutingModule {
|
||||
}
|
||||
13
bookie/src/app/devices/devices.module.spec.ts
Normal file
13
bookie/src/app/devices/devices.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {DevicesModule} from './devices.module';
|
||||
|
||||
describe('DevicesModule', () => {
|
||||
let devicesModule: DevicesModule;
|
||||
|
||||
beforeEach(() => {
|
||||
devicesModule = new DevicesModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(devicesModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
41
bookie/src/app/devices/devices.module.ts
Normal file
41
bookie/src/app/devices/devices.module.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { DeviceListComponent } from './device-list/device-list.component';
|
||||
import { DeviceDetailComponent } from './device-detail/device-detail.component';
|
||||
import { DevicesRoutingModule } from './devices-routing.module';
|
||||
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 { MatOptionModule } from '@angular/material/core';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatOptionModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
DevicesRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
DeviceListComponent,
|
||||
DeviceDetailComponent
|
||||
]
|
||||
})
|
||||
export class DevicesModule {
|
||||
}
|
||||
Reference in New Issue
Block a user