From 89965169789de7b5dea7c13346571b3643e6e695 Mon Sep 17 00:00:00 2001 From: tanshu Date: Sun, 10 Jun 2018 13:58:01 +0530 Subject: [PATCH] Added loading bar Fixed product, account and employee details for add new. --- brewman/views/__init__.py | 16 +++++----- brewman/views/product.py | 2 +- overlord/package.json | 2 ++ .../account-detail.component.ts | 2 +- overlord/src/app/app.component.html | 1 + overlord/src/app/core/core.module.ts | 19 ++++++++++-- .../src/app/core/http-auth-interceptor.ts | 31 +++++++++++++++++++ .../employee-detail.component.ts | 4 +-- .../product-detail.component.ts | 17 +++++----- overlord/src/app/shared/tokenizer.service.ts | 6 ++-- 10 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 overlord/src/app/core/http-auth-interceptor.ts diff --git a/brewman/views/__init__.py b/brewman/views/__init__.py index 61ac6be1..b5d8df13 100644 --- a/brewman/views/__init__.py +++ b/brewman/views/__init__.py @@ -1,8 +1,8 @@ -from decimal import Decimal -from datetime import date, datetime, timedelta, time -from io import BytesIO -import uuid import re +import uuid +from datetime import date, datetime, timedelta, time +from decimal import Decimal +from io import BytesIO import pkg_resources from pyramid.httpexceptions import HTTPForbidden, HTTPFound @@ -20,14 +20,16 @@ def home(request): file = pkg_resources.resource_filename(package, resource) return FileResponse(file, request=request) + @view_config(context=HTTPForbidden) -def forbidden(request): - if 'X-Requested-With' in request.headers and request.headers['X-Requested-With'] == 'XMLHttpRequest': +def forbidden_json(request): + if request.accept.quality('application/json') == 1: response = Response("Forbidden") response.status_int = 401 return response else: - return HTTPFound(location=request.route_url('login', _query={'returnUrl': request.path_qs})) + ret = HTTPFound(location=request.route_url('login', _query={'returnUrl': request.path_qs})) + return ret @view_config(route_name='db_image') diff --git a/brewman/views/product.py b/brewman/views/product.py index ad546469..8615561f 100644 --- a/brewman/views/product.py +++ b/brewman/views/product.py @@ -204,7 +204,7 @@ def show_term(request): def product_info(id, dbsession): if id is None: - product = {'code': '(Auto)', 'isActive': True, 'isPurchased': True, 'isSold': False} + product = {'code': '(Auto)', 'productGroup': {}, 'isActive': True, 'isPurchased': True, 'isSold': False} else: product = dbsession.query(Product).filter(Product.id == id).first() product = {'id': product.id, 'code': product.code, 'name': product.name, 'units': product.units, diff --git a/overlord/package.json b/overlord/package.json index 5a455efa..ceb33f6d 100644 --- a/overlord/package.json +++ b/overlord/package.json @@ -24,6 +24,8 @@ "@angular/platform-browser": "^6.0.3", "@angular/platform-browser-dynamic": "^6.0.3", "@angular/router": "^6.0.3", + "@ngx-loading-bar/http-client": "^2.1.0", + "@ngx-loading-bar/router": "^2.1.0", "core-js": "^2.5.4", "moment": "^2.22.1", "rxjs": "^6.2.0", diff --git a/overlord/src/app/account/account-detail/account-detail.component.ts b/overlord/src/app/account/account-detail/account-detail.component.ts index 68514a7a..53b72c4c 100644 --- a/overlord/src/app/account/account-detail/account-detail.component.ts +++ b/overlord/src/app/account/account-detail/account-detail.component.ts @@ -56,7 +56,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit { this.item = item; this.form.setValue({ code: this.item.code || '(Auto)', - name: this.item.name, + name: this.item.name || '', type: this.item.type, isActive: this.item.isActive, isReconcilable: this.item.isReconcilable, diff --git a/overlord/src/app/app.component.html b/overlord/src/app/app.component.html index 69c51fcb..3ed55bb2 100644 --- a/overlord/src/app/app.component.html +++ b/overlord/src/app/app.component.html @@ -1,3 +1,4 @@ +
diff --git a/overlord/src/app/core/core.module.ts b/overlord/src/app/core/core.module.ts index 63c318a7..64bd2d92 100644 --- a/overlord/src/app/core/core.module.ts +++ b/overlord/src/app/core/core.module.ts @@ -3,10 +3,16 @@ import {CommonModule} from '@angular/common'; import {NavBarComponent} from './nav-bar/nav-bar.component'; import {MatButtonModule, MatIconModule, MatMenuModule, MatToolbarModule} from '@angular/material'; import {RouterModule} from '@angular/router'; +import {HTTP_INTERCEPTORS} from '@angular/common/http'; +import {HttpAuthInterceptor} from './http-auth-interceptor'; +import {LoadingBarHttpClientModule} from '@ngx-loading-bar/http-client'; +import {LoadingBarRouterModule} from '@ngx-loading-bar/router'; @NgModule({ imports: [ CommonModule, + LoadingBarHttpClientModule, + LoadingBarRouterModule, MatButtonModule, MatIconModule, MatMenuModule, @@ -14,11 +20,18 @@ import {RouterModule} from '@angular/router'; RouterModule ], declarations: [ - NavBarComponent + NavBarComponent, ], exports: [ - NavBarComponent - ] + NavBarComponent, + LoadingBarHttpClientModule, + LoadingBarRouterModule + ], + providers: [[{ + provide: HTTP_INTERCEPTORS, + useClass: HttpAuthInterceptor, + multi: true + }]] }) export class CoreModule { } diff --git a/overlord/src/app/core/http-auth-interceptor.ts b/overlord/src/app/core/http-auth-interceptor.ts new file mode 100644 index 00000000..173dab87 --- /dev/null +++ b/overlord/src/app/core/http-auth-interceptor.ts @@ -0,0 +1,31 @@ +import {Injectable} from '@angular/core'; +import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; + +import {Observable, ObservableInput, of as observableOf} from 'rxjs'; +import {catchError} from 'rxjs/operators'; +import {ToasterService} from './toaster.service'; +import {Router} from '@angular/router'; +import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component'; +import {MatDialog} from '@angular/material'; + +@Injectable() +export class HttpAuthInterceptor implements HttpInterceptor { + + constructor(private router: Router, private dialog: MatDialog, private toaster: ToasterService) { + } + + intercept(req: HttpRequest, next: HttpHandler): + Observable> { + return next.handle(req) + .pipe( + catchError((err: any, caught: Observable): ObservableInput<{}> => { + if (err.status === 401) { + this.router.navigate(['login']); + this.toaster.show('Danger', 'User has been logged out'); + } + return observableOf(caught); + } + ) + ); + } +} diff --git a/overlord/src/app/employee/employee-detail/employee-detail.component.ts b/overlord/src/app/employee/employee-detail/employee-detail.component.ts index f3d172b1..ee3209a8 100644 --- a/overlord/src/app/employee/employee-detail/employee-detail.component.ts +++ b/overlord/src/app/employee/employee-detail/employee-detail.component.ts @@ -64,9 +64,9 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit { designation: this.item.designation || '', salary: this.item.salary || '', points: this.item.points || '', - isActive: this.item.isActive || true, + isActive: this.item.isActive, costCentre: this.item.costCentre.id, - joiningDate: moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate(), + joiningDate: this.item.joiningDate ? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate() : '', leavingDate: this.item.isActive ? null : moment(this.item.leavingDate, 'DD-MMM-YYYY').toDate() }); } diff --git a/overlord/src/app/product/product-detail/product-detail.component.ts b/overlord/src/app/product/product-detail/product-detail.component.ts index 25e69162..b0dd28a4 100644 --- a/overlord/src/app/product/product-detail/product-detail.component.ts +++ b/overlord/src/app/product/product-detail/product-detail.component.ts @@ -57,19 +57,20 @@ export class ProductDetailComponent implements OnInit, AfterViewInit { showItem(item: Product) { this.item = item; + console.log(item); this.form.setValue({ code: this.item.code || '(Auto)', - name: this.item.name, - units: this.item.units, - fraction: this.item.fraction, - fractionUnits: this.item.fractionUnits, - productYield: this.item.productYield, - price: this.item.price, - salePrice: this.item.salePrice, + name: this.item.name || '', + units: this.item.units || '', + fraction: this.item.fraction || '', + fractionUnits: this.item.fractionUnits || '', + productYield: this.item.productYield || '', + price: this.item.price || '', + salePrice: this.item.salePrice || '', isPurchased: this.item.isPurchased, isSold: this.item.isSold, isActive: this.item.isActive, - productGroup: this.item.productGroup.id + productGroup: this.item.productGroup.id ? this.item.productGroup.id : '' }); } diff --git a/overlord/src/app/shared/tokenizer.service.ts b/overlord/src/app/shared/tokenizer.service.ts index 1b72d5c0..8396bc85 100644 --- a/overlord/src/app/shared/tokenizer.service.ts +++ b/overlord/src/app/shared/tokenizer.service.ts @@ -44,7 +44,7 @@ export class TokenizerService { const isSort = (key === '' && value.length > 1 && '+-'.indexOf(value.charAt(0)) !== -1); return sorter !== null ? (isSort && value.substr(1) in sorter) : isSort; } - // getFilters(input: string[]) { - // input. - // } + getFilters(input: string[]) { + // input. + } }