Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
+14
-3
@@ -5,11 +5,22 @@
|
||||
</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>Name</mat-label>
|
||||
<input matInput #nameElement placeholder="Name" formControlName="name" (keyup.enter)="save()">
|
||||
<input
|
||||
matInput
|
||||
#nameElement
|
||||
placeholder="Name"
|
||||
formControlName="name"
|
||||
(keyup.enter)="save()"
|
||||
/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
+4
-5
@@ -1,6 +1,6 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupDetailComponent} from './product-group-detail.component';
|
||||
import { ProductGroupDetailComponent } from './product-group-detail.component';
|
||||
|
||||
describe('ProductGroupDetailComponent', () => {
|
||||
let component: ProductGroupDetailComponent;
|
||||
@@ -8,9 +8,8 @@ describe('ProductGroupDetailComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductGroupDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ProductGroupDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
+21
-23
@@ -1,15 +1,15 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
|
||||
import {ProductGroupService} from '../product-group.service';
|
||||
import {ProductGroup} from '../../core/product-group';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { ProductGroupService } from '../product-group.service';
|
||||
import { ProductGroup } from '../../core/product-group';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-group-detail',
|
||||
templateUrl: './product-group-detail.component.html',
|
||||
styleUrls: ['./product-group-detail.component.css']
|
||||
styleUrls: ['./product-group-detail.component.css'],
|
||||
})
|
||||
export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@@ -21,22 +21,21 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ProductGroupService
|
||||
private ser: ProductGroupService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: ''
|
||||
name: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: ProductGroup }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
this.route.data.subscribe((data: { item: ProductGroup }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: ProductGroup) {
|
||||
@@ -53,16 +52,15 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/product-groups');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/product-groups');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getItem(): ProductGroup {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupListResolverService} from './product-group-list-resolver.service';
|
||||
import { ProductGroupListResolverService } from './product-group-list-resolver.service';
|
||||
|
||||
describe('ProductGroupListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupListResolverService]
|
||||
providers: [ProductGroupListResolverService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductGroupListResolverService], (service: ProductGroupListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
it('should be created', inject(
|
||||
[ProductGroupListResolverService],
|
||||
(service: ProductGroupListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ProductGroup} from '../core/product-group';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { ProductGroup } from '../core/product-group';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { ProductGroupService } from './product-group.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProductGroupListResolver implements Resolve<ProductGroup[]> {
|
||||
|
||||
constructor(private ser: ProductGroupService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: ProductGroupService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProductGroup[]> {
|
||||
return this.ser.list();
|
||||
|
||||
+11
-15
@@ -1,33 +1,29 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
||||
import {ProductGroup} from '../../core/product-group';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||
import { ProductGroup } from '../../core/product-group';
|
||||
|
||||
export class ProductGroupListDataSource extends DataSource<ProductGroup> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: ProductGroup[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<ProductGroup[]> {
|
||||
const dataMutations = [
|
||||
observableOf(this.data),
|
||||
this.paginator.page,
|
||||
this.sort.sortChange
|
||||
];
|
||||
const dataMutations = [observableOf(this.data), this.paginator.page, this.sort.sortChange];
|
||||
|
||||
// Set the paginators length
|
||||
this.paginator.length = this.data.length;
|
||||
|
||||
return merge(...dataMutations).pipe(map(() => {
|
||||
return this.getPagedData(this.getSortedData([...this.data]));
|
||||
}));
|
||||
return merge(...dataMutations).pipe(
|
||||
map(() => {
|
||||
return this.getPagedData(this.getSortedData([...this.data]));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
|
||||
private getPagedData(data: ProductGroup[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
|
||||
+12
-9
@@ -8,28 +8,31 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/product-groups', row.id]">{{row.name}}</a></mat-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/product-groups', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Is Fixture Column -->
|
||||
<ng-container matColumnDef="isFixture">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Is Fixture?</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.isFixture}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.isFixture }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator #paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]">
|
||||
<mat-paginator
|
||||
#paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]"
|
||||
>
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
+4
-5
@@ -1,6 +1,6 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupListComponent} from './product-group-list.component';
|
||||
import { ProductGroupListComponent } from './product-group-list.component';
|
||||
|
||||
describe('ProductGroupListComponent', () => {
|
||||
let component: ProductGroupListComponent;
|
||||
@@ -8,9 +8,8 @@ describe('ProductGroupListComponent', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductGroupListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ProductGroupListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ProductGroupListComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {ProductGroupListDataSource} from './product-group-list-datasource';
|
||||
import {ProductGroup} from '../../core/product-group';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import { ProductGroupListDataSource } from './product-group-list-datasource';
|
||||
import { ProductGroup } from '../../core/product-group';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-group-list',
|
||||
templateUrl: './product-group-list.component.html',
|
||||
styleUrls: ['./product-group-list.component.css']
|
||||
styleUrls: ['./product-group-list.component.css'],
|
||||
})
|
||||
export class ProductGroupListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
@@ -18,14 +18,12 @@ export class ProductGroupListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'isFixture'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: ProductGroup[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.route.data.subscribe((data: { list: ProductGroup[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new ProductGroupListDataSource(this.paginator, this.sort, this.list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupResolverService} from './product-group-resolver.service';
|
||||
import { ProductGroupResolverService } from './product-group-resolver.service';
|
||||
|
||||
describe('ProductGroupResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupDetailResolverService]
|
||||
providers: [ProductGroupDetailResolverService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductGroupDetailResolverService], (service: ProductGroupDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
it('should be created', inject(
|
||||
[ProductGroupDetailResolverService],
|
||||
(service: ProductGroupDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
import {ProductGroup} from '../core/product-group';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { ProductGroupService } from './product-group.service';
|
||||
import { ProductGroup } from '../core/product-group';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProductGroupResolver implements Resolve<ProductGroup> {
|
||||
|
||||
constructor(private ser: ProductGroupService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: ProductGroupService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProductGroup> {
|
||||
const id = route.paramMap.get('id');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ProductGroupRoutingModule} from './product-group-routing.module';
|
||||
import { ProductGroupRoutingModule } from './product-group-routing.module';
|
||||
|
||||
describe('ProductGroupRoutingModule', () => {
|
||||
let productGroupRoutingModule: ProductGroupRoutingModule;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {ProductGroupListResolver} from './product-group-list-resolver.service';
|
||||
import {ProductGroupResolver} from './product-group-resolver.service';
|
||||
import {ProductGroupListComponent} from './product-group-list/product-group-list.component';
|
||||
import {ProductGroupDetailComponent} from './product-group-detail/product-group-detail.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { ProductGroupListResolver } from './product-group-list-resolver.service';
|
||||
import { ProductGroupResolver } from './product-group-resolver.service';
|
||||
import { ProductGroupListComponent } from './product-group-list/product-group-list.component';
|
||||
import { ProductGroupDetailComponent } from './product-group-detail/product-group-detail.component';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
const productGroupRoutes: Routes = [
|
||||
{
|
||||
@@ -13,49 +13,39 @@ const productGroupRoutes: Routes = [
|
||||
component: ProductGroupListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
list: ProductGroupListResolver
|
||||
}
|
||||
list: ProductGroupListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: ProductGroupDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
item: ProductGroupResolver
|
||||
}
|
||||
item: ProductGroupResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ProductGroupDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
permission: 'Cost Centres',
|
||||
},
|
||||
resolve: {
|
||||
item: ProductGroupResolver
|
||||
}
|
||||
}
|
||||
item: ProductGroupResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(productGroupRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
ProductGroupListResolver,
|
||||
ProductGroupResolver
|
||||
]
|
||||
imports: [CommonModule, RouterModule.forChild(productGroupRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [ProductGroupListResolver, ProductGroupResolver],
|
||||
})
|
||||
export class ProductGroupRoutingModule {
|
||||
}
|
||||
export class ProductGroupRoutingModule {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ProductGroupModule} from './product-group.module';
|
||||
import { ProductGroupModule } from './product-group.module';
|
||||
|
||||
describe('ProductGroupModule', () => {
|
||||
let productGroupModule: ProductGroupModule;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import {ProductGroupListComponent} from './product-group-list/product-group-list.component';
|
||||
import {ProductGroupDetailComponent} from './product-group-detail/product-group-detail.component';
|
||||
import {ProductGroupRoutingModule} from './product-group-routing.module';
|
||||
import { ProductGroupListComponent } from './product-group-list/product-group-list.component';
|
||||
import { ProductGroupDetailComponent } from './product-group-detail/product-group-detail.component';
|
||||
import { ProductGroupRoutingModule } from './product-group-routing.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
@@ -12,9 +12,9 @@ import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import {CdkTableModule} from '@angular/cdk/table';
|
||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -30,12 +30,8 @@ import {ReactiveFormsModule} from '@angular/forms';
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
ReactiveFormsModule,
|
||||
ProductGroupRoutingModule
|
||||
ProductGroupRoutingModule,
|
||||
],
|
||||
declarations: [
|
||||
ProductGroupListComponent,
|
||||
ProductGroupDetailComponent
|
||||
]
|
||||
declarations: [ProductGroupListComponent, ProductGroupDetailComponent],
|
||||
})
|
||||
export class ProductGroupModule {
|
||||
}
|
||||
export class ProductGroupModule {}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
import { ProductGroupService } from './product-group.service';
|
||||
|
||||
describe('ProductGroupService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupService]
|
||||
providers: [ProductGroupService],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,50 +1,53 @@
|
||||
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 {ProductGroup} from '../core/product-group';
|
||||
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 { ProductGroup } from '../core/product-group';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/product-groups';
|
||||
const serviceName = 'ProductGroupService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProductGroupService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<ProductGroup> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<ProductGroup>>this.http.get<ProductGroup>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<ProductGroup>>(
|
||||
this.http
|
||||
.get<ProductGroup>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<ProductGroup[]> {
|
||||
return <Observable<ProductGroup[]>>this.http.get<ProductGroup[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
return <Observable<ProductGroup[]>>(
|
||||
this.http
|
||||
.get<ProductGroup[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.post<ProductGroup>(`${url}`, productGroup, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<ProductGroup>>(
|
||||
this.http
|
||||
.post<ProductGroup>(`${url}`, productGroup, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.put<ProductGroup>(`${url}/${productGroup.id}`, productGroup, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<ProductGroup>>(
|
||||
this.http
|
||||
.put<ProductGroup>(`${url}/${productGroup.id}`, productGroup, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
@@ -56,9 +59,10 @@ export class ProductGroupService {
|
||||
}
|
||||
|
||||
delete(id: string): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.delete<ProductGroup>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<ProductGroup>>(
|
||||
this.http
|
||||
.delete<ProductGroup>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user