Blacked and isorted the python files

Prettied and eslinted the typescript/html files
This commit is contained in:
2020-10-11 10:56:29 +05:30
parent b31db593c2
commit d677cfb1ea
505 changed files with 7560 additions and 5650 deletions

View File

@ -1,10 +1,9 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable } from 'rxjs';
import { SectionPrinter } from '../core/section-printer';
export class SectionPrinterDataSource extends DataSource<SectionPrinter> {
constructor(private data: Observable<SectionPrinter[]>) {
super();
}
@ -13,6 +12,5 @@ export class SectionPrinterDataSource extends DataSource<SectionPrinter> {
return this.data;
}
disconnect() {
}
disconnect() {}
}

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {SectionPrinterResolver} from './section-printer-resolver.service';
import { SectionPrinterResolver } from './section-printer-resolver.service';
describe('SectionPrinterResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [SectionPrinterResolver]
providers: [SectionPrinterResolver],
});
});

View File

@ -1,18 +1,18 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
import { SectionPrinter } from '../core/section-printer';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs';
import { SectionPrinter } from '../core/section-printer';
import { SectionPrinterService } from './section-printer.service';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class SectionPrinterResolver implements Resolve<SectionPrinter[]> {
constructor(private ser: SectionPrinterService) {}
constructor(private ser: SectionPrinterService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<SectionPrinter[]> {
resolve(route: ActivatedRouteSnapshot): Observable<SectionPrinter[]> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}

View File

@ -5,11 +5,20 @@
</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">
<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" (selectionChange)="show($event)">
<mat-select
placeholder="Section"
formControlName="section"
(selectionChange)="show($event)"
>
<mat-option *ngFor="let s of sections" [value]="s.id">
{{ s.name }}
</mat-option>
@ -17,49 +26,50 @@
</mat-form-field>
</div>
<mat-divider></mat-divider>
<mat-table #table [dataSource]="dataSource" formArrayName="menuCategories">
<mat-table #table [dataSource]="dataSource" formArrayName="menuCategories">
<!-- Menu Category Column -->
<ng-container matColumnDef="menuCategory">
<mat-header-cell *matHeaderCellDef>Menu Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.menuCategory?.name || 'Default' }}</mat-cell>
</ng-container>
<!-- Menu Category Column -->
<ng-container matColumnDef="menuCategory">
<mat-header-cell *matHeaderCellDef>Menu Category</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.menuCategory?.name || 'Default'}}</mat-cell>
</ng-container>
<!-- Printer Column -->
<ng-container matColumnDef="printer">
<mat-header-cell *matHeaderCellDef>Printer</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
<mat-form-field>
<mat-label>Printer</mat-label>
<mat-select formControlName="printer" name="printer">
<mat-option>-- Default --</mat-option>
<mat-option *ngFor="let p of printers" [value]="p.id">
{{ p.name }}
</mat-option>
</mat-select>
</mat-form-field>
</mat-cell>
</ng-container>
<!-- Printer Column -->
<ng-container matColumnDef="printer">
<mat-header-cell *matHeaderCellDef>Printer</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
<mat-form-field>
<mat-label>Printer</mat-label>
<mat-select formControlName="printer" name="printer">
<mat-option>-- Default --</mat-option>
<mat-option *ngFor="let p of printers" [value]="p.id">
{{ p.name }}
</mat-option>
</mat-select>
</mat-form-field>
</mat-cell>
</ng-container>
<!-- Copies Column -->
<ng-container matColumnDef="copies">
<mat-header-cell *matHeaderCellDef>Copies</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
<mat-form-field *ngIf="!!$any(form.get('menuCategories')).at(i).value.printer">
<mat-label>Copies</mat-label>
<input matInput type="number" placeholder="Copies" formControlName="copies" />
</mat-form-field>
</mat-cell>
</ng-container>
<!-- Copies Column -->
<ng-container matColumnDef="copies">
<mat-header-cell *matHeaderCellDef>Copies</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
<mat-form-field *ngIf="!!$any(form.get('menuCategories')).at(i).value.printer">
<mat-label>Copies</mat-label>
<input matInput type="number" placeholder="Copies" formControlName="copies">
</mat-form-field>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; let i = index; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; let i = index; columns: displayedColumns"></mat-row>
</mat-table>
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click)="save()">Save</button>
<button mat-raised-button color="warn" *ngIf="sectionId" (click)="confirmDelete()">Delete</button>
<button mat-raised-button color="warn" *ngIf="sectionId" (click)="confirmDelete()">
Delete
</button>
</mat-card-actions>
</mat-card>
</div>

View File

@ -1,6 +1,6 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {SectionPrinterComponent} from './section-printer.component';
import { SectionPrinterComponent } from './section-printer.component';
describe('SectionPrinterComponent', () => {
let component: SectionPrinterComponent;
@ -8,9 +8,8 @@ describe('SectionPrinterComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SectionPrinterComponent]
})
.compileComponents();
declarations: [SectionPrinterComponent],
}).compileComponents();
}));
beforeEach(() => {

View File

@ -1,24 +1,26 @@
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { Printer } from '../core/printer';
import { Section } from '../core/section';
import { SectionPrinter } from '../core/section-printer';
import { ToasterService } from '../core/toaster.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { Section } from '../core/section';
import { Printer } from '../core/printer';
import { SectionPrinterService } from './section-printer.service';
import { SectionPrinterDataSource } from './section-printer-datasource';
import { SectionPrinterService } from './section-printer.service';
@Component({
selector: 'app-section-printer',
templateUrl: './section-printer.component.html',
styleUrls: ['./section-printer.component.css']
styleUrls: ['./section-printer.component.css'],
})
export class SectionPrinterComponent implements OnInit {
@ViewChild('section', {static: true}) sectionElement: ElementRef;
@ViewChild('section', { static: true }) sectionElement: ElementRef;
form: FormGroup;
dataSource: SectionPrinterDataSource;
public listObservable = new BehaviorSubject<SectionPrinter[]>([]);
@ -34,74 +36,80 @@ export class SectionPrinterComponent implements OnInit {
private fb: FormBuilder,
private toaster: ToasterService,
private dialog: MatDialog,
private ser: SectionPrinterService
private ser: SectionPrinterService,
) {
this.createForm();
route.params.pipe(map(p => p.id)).subscribe(x => this.sectionId = x);
route.params.pipe(map((p) => p.id)).subscribe((x) => {
this.sectionId = x;
});
}
createForm() {
this.form = this.fb.group({
section: '',
menuCategories: this.fb.array([])
menuCategories: this.fb.array([]),
});
}
ngOnInit() {
this.route.data
.subscribe((data: { list: SectionPrinter[], sections: Section[], printers: Printer[] }) => {
this.route.data.subscribe(
(data: { list: SectionPrinter[]; sections: Section[]; printers: Printer[] }) => {
this.sections = data.sections;
this.printers = data.printers;
this.showItem(data.list);
this.dataSource = new SectionPrinterDataSource(this.listObservable);
this.listObservable.next(this.list);
});
},
);
}
showItem(list: SectionPrinter[]) {
this.list = list;
this.form.get('section').setValue(this.sectionId);
this.form.setControl('menuCategories', this.fb.array(
this.list.map(
x => this.fb.group({
menuCategory: (x.menuCategory?.name || 'Default'),
printer: x.printer?.id,
copies: '' + x.copies
})
)
));
this.form.setControl(
'menuCategories',
this.fb.array(
this.list.map((x) =>
this.fb.group({
menuCategory: x.menuCategory?.name || 'Default',
printer: x.printer?.id,
copies: `${x.copies}`,
}),
),
),
);
}
save() {
this.ser.save(this.sectionId, this.getItem())
.subscribe(
(result: SectionPrinter[]) => {
this.toaster.show('Success', '');
this.showItem(result);
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
this.ser.save(this.sectionId, this.getItem()).subscribe(
(result: SectionPrinter[]) => {
this.toaster.show('Success', '');
this.showItem(result);
},
(error) => {
this.toaster.show('Danger', error.error);
},
);
}
delete() {
this.ser.delete(this.sectionId)
.subscribe(
(result) => {
this.toaster.show('Success', '');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
this.ser.delete(this.sectionId).subscribe(
() => {
this.toaster.show('Success', '');
},
(error) => {
this.toaster.show('Danger', error.error);
},
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete all printers for this section?', content: 'Are you sure? This cannot be undone.'}
data: {
title: 'Delete all printers for this section?',
content: 'Are you sure? This cannot be undone.',
},
});
dialogRef.afterClosed().subscribe((result: boolean) => {
@ -117,7 +125,7 @@ export class SectionPrinterComponent implements OnInit {
const array = this.form.get('menuCategories') as FormArray;
this.list.forEach((item, index) => {
const cont = array.controls[index].value;
item.printer = {id: cont.printer};
item.printer = { id: cont.printer };
item.copies = +cont.copies;
});
return this.list;

View File

@ -1,11 +1,11 @@
import {inject, TestBed} from '@angular/core/testing';
import { inject, TestBed } from '@angular/core/testing';
import {SectionPrinterService} from './section-printer.service';
import { SectionPrinterService } from './section-printer.service';
describe('SectionPrinterService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [SectionPrinterService]
providers: [SectionPrinterService],
});
});

View File

@ -1,29 +1,30 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ErrorLoggerService } from '../core/error-logger.service';
import { catchError } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { SectionPrinter } from '../core/section-printer';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/section-printers';
const serviceName = 'SectionPrinterService';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class SectionPrinterService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string): Observable<SectionPrinter[]> {
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
return <Observable<SectionPrinter[]>>this.http.get<SectionPrinter[]>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<SectionPrinter[]>>(
this.http
.get<SectionPrinter[]>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
}
// item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
@ -35,16 +36,18 @@ export class SectionPrinterService {
// }
save(sectionId: string, list: SectionPrinter[]): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>this.http.post<SectionPrinter[]>(`${url}/${sectionId}`, list, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
return <Observable<SectionPrinter[]>>(
this.http
.post<SectionPrinter[]>(`${url}/${sectionId}`, list, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
}
delete(id: string): Observable<SectionPrinter[]> {
return <Observable<SectionPrinter[]>>this.http.delete<SectionPrinter[]>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);
return <Observable<SectionPrinter[]>>(
this.http
.delete<SectionPrinter[]>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
);
}
}

View File

@ -1,11 +1,13 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {SectionPrinterResolver} from './section-printer-resolver.service';
import {SectionPrinterComponent} from './section-printer.component';
import {AuthGuard} from '../auth/auth-guard.service';
import {SectionListResolver} from '../sections/section-list-resolver.service';
import {PrinterListResolver} from '../printers/printer-list-resolver.service';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from '../auth/auth-guard.service';
import { PrinterListResolver } from '../printers/printer-list-resolver.service';
import { SectionListResolver } from '../sections/section-list-resolver.service';
import { SectionPrinterResolver } from './section-printer-resolver.service';
import { SectionPrinterComponent } from './section-printer.component';
const sectionPrinterRoutes: Routes = [
{
@ -13,41 +15,32 @@ const sectionPrinterRoutes: Routes = [
component: SectionPrinterComponent,
canActivate: [AuthGuard],
data: {
permission: 'Section Printers'
permission: 'Section Printers',
},
resolve: {
list: SectionPrinterResolver,
sections: SectionListResolver,
printers: PrinterListResolver
}
printers: PrinterListResolver,
},
},
{
path: ':id',
component: SectionPrinterComponent,
canActivate: [AuthGuard],
data: {
permission: 'Section Printers'
permission: 'Section Printers',
},
resolve: {
list: SectionPrinterResolver,
sections: SectionListResolver,
printers: PrinterListResolver
}
}
printers: PrinterListResolver,
},
},
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(sectionPrinterRoutes)
],
exports: [
RouterModule
],
providers: [
SectionPrinterResolver
]
imports: [CommonModule, RouterModule.forChild(sectionPrinterRoutes)],
exports: [RouterModule],
providers: [SectionPrinterResolver],
})
export class SectionPrintersRoutingModule {
}
export class SectionPrintersRoutingModule {}

View File

@ -1,8 +1,8 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import { SectionPrinterComponent } from './section-printer.component';
import { SectionPrintersRoutingModule } from './section-printers-routing.module';
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 { MatCheckboxModule } from '@angular/material/checkbox';
@ -12,10 +12,11 @@ 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 { CdkTableModule } from '@angular/cdk/table';
import { ReactiveFormsModule } from '@angular/forms';
import { SharedModule } from '../shared/shared.module';
import { FlexLayoutModule } from '@angular/flex-layout';
import { SectionPrinterComponent } from './section-printer.component';
import { SectionPrintersRoutingModule } from './section-printers-routing.module';
@NgModule({
imports: [
@ -33,11 +34,8 @@ import { FlexLayoutModule } from '@angular/flex-layout';
MatTableModule,
ReactiveFormsModule,
SharedModule,
SectionPrintersRoutingModule
SectionPrintersRoutingModule,
],
declarations: [
SectionPrinterComponent
]
declarations: [SectionPrinterComponent],
})
export class SectionPrintersModule {
}
export class SectionPrintersModule {}