Updated to angular 10

Moved to eslint for linting
Added prettier for formatting
Fixed minor errors
This commit is contained in:
Amritanshu Agrawal 2020-10-11 09:34:35 +05:30
parent 066d43a373
commit b31db593c2
22 changed files with 235 additions and 291 deletions

View File

@ -1,7 +1,6 @@
from sqlalchemy import engine_from_config
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import configure_mappers
import zope.sqlalchemy
# import or define all models here to ensure they are attached to the
# Base.metadata prior to any initialization routines

View File

@ -19,6 +19,7 @@ itsdangerous = "^1.1.0"
python-dotenv = "^0.14.0"
pydantic = {extras = ["dotenv"], version = "^1.6.1"}
starlette = "^0.13.6"
celery = "^5.0.0"
[tool.poetry.dev-dependencies]
flake8 = "^3.8.4"

18
bookie/.browserslistrc Normal file
View File

@ -0,0 +1,18 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support
# You can see what browsers were selected by your queries by running:
# npx browserslist
last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line.
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

43
bookie/.eslintrc.js Normal file
View File

@ -0,0 +1,43 @@
/*
We recommend eventually switching this configuration to extend from
the recommended rulesets in typescript-eslint.
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
Happy linting! 💖
*/
module.exports = {
"extends": [
"plugin:@angular-eslint/recommended",
// AirBnB Styleguide rules
"airbnb-typescript/base",
// Settings for Prettier
"prettier",
"prettier/@typescript-eslint",
"prettier/react",
],
"env": {
"browser": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"@angular-eslint/eslint-plugin",
"@typescript-eslint",
],
"ignorePatterns": ["/src/**/*.spec.ts", "src/test.ts", "src/polyfills.ts"],
"rules": {
"import/prefer-default-export": "off",
"no-param-reassign": ["error", { "props": false }],
"@typescript-eslint/lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"class-methods-use-this": ["error", {"exceptMethods": ["disconnect", "displayFn", "transform"]}],
"import/order": ["error", {"alphabetize": {"order": "asc", "caseInsensitive": true}, "newlines-between": "always"}],
"@typescript-eslint/no-explicit-any": "off", // Disabled for now, but needed to transition to strict compiling
}
};

8
bookie/.prettierrc.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = {
trailingComma: "all",
tabWidth: 2,
semi: true,
singleQuote: true,
bracketSpacing: true,
printWidth: 100
};

View File

@ -4,21 +4,25 @@
"newProjectRoot": "projects",
"projects": {
"bookie": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"aot": true,
"outputPath": "../frontend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
@ -42,19 +46,19 @@
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
"maximumWarning": "1mb",
"maximumError": "2mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
}
@ -83,8 +87,8 @@
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.css"
@ -97,24 +101,19 @@
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"builder": "@angular-eslint/builder:lint",
"options": {
"eslintConfig": ".eslintrc.js",
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"bookie-e2e": {
"root": "e2e/",
"projectType": "application",
"prefix": "",
"architect": {
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
@ -126,15 +125,6 @@
"devServerTarget": "bookie:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}

View File

@ -1,11 +0,0 @@
# This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed
> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11

View File

@ -16,7 +16,7 @@ module.exports = function (config) {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
dir: require('path').join(__dirname, './coverage/bookie'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
@ -28,4 +28,4 @@ module.exports = function (config) {
browsers: ['Chrome'],
singleRun: false
});
};
};

View File

@ -8,51 +8,78 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ngcc"
"eslint": "eslint",
"prettier": "prettier",
"husky": "husky"
},
"private": true,
"dependencies": {
"@angular/animations": "^9.1.11",
"@angular/cdk": "^9.2.4",
"@angular/common": "^9.1.11",
"@angular/compiler": "^9.1.11",
"@angular/core": "^9.1.11",
"@angular/flex-layout": "^9.0.0-beta.31",
"@angular/forms": "^9.1.11",
"@angular/material": "^9.2.4",
"@angular/material-moment-adapter": "^9.2.4",
"@angular/platform-browser": "^9.1.11",
"@angular/platform-browser-dynamic": "^9.1.11",
"@angular/router": "^9.1.11",
"angular2-hotkeys": "^2.2.0",
"core-js": "^3.1.1",
"mathjs": "^5.10.3",
"moment": "^2.24.0",
"rxjs": "^6.5.5",
"rxjs-tslint": "^0.1.5",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
"@angular/animations": "^10.1.4",
"@angular/cdk": "^10.2.4",
"@angular/common": "^10.1.4",
"@angular/compiler": "^10.1.4",
"@angular/core": "^10.1.4",
"@angular/flex-layout": "^10.0.0-beta.32",
"@angular/forms": "^10.1.4",
"@angular/material": "^10.2.4",
"@angular/material-moment-adapter": "^10.2.4",
"@angular/platform-browser": "^10.1.4",
"@angular/platform-browser-dynamic": "^10.1.4",
"@angular/router": "^10.1.4",
"core-js": "^3.6.5",
"mathjs": "^7.4.0",
"moment": "^2.29.1",
"rxjs": "^6.6.3",
"tslib": "^2.0.2",
"zone.js": "^0.10.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.8",
"@angular/cli": "^9.1.8",
"@angular/compiler-cli": "^9.1.11",
"@angular/language-service": "^9.1.11",
"@types/jasmine": "^3.3.0",
"@angular-devkit/build-angular": "~0.1001.4",
"@angular-eslint/builder": "^0.5.0-beta.2",
"@angular-eslint/eslint-plugin": "^0.5.0-beta.2",
"@angular-eslint/eslint-plugin-template": "^0.5.0-beta.2",
"@angular-eslint/schematics": "^0.5.0-beta.2",
"@angular-eslint/template-parser": "^0.5.0-beta.2",
"@angular/cli": "^10.1.4",
"@angular/compiler-cli": "^10.1.4",
"@angular/language-service": "^10.1.4",
"@types/jasmine": "^3.5.14",
"@types/jasminewd2": "^2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "^3.1.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.1",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "^5.4.0",
"standard-version": "^6.0.1",
"ts-node": "^8.1.0",
"tslint": "^5.16.0",
"typescript": "3.8.3"
"@types/node": "^14.11.5",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.3.0",
"codelyzer": "^6.0.1",
"eslint": "^7.10.0",
"eslint-config-airbnb-typescript": "^11.0.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^30.6.3",
"husky": "^4.3.0",
"jasmine-core": "^3.6.0",
"jasmine-spec-reporter": "^6.0.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "^4.0.1",
"karma-jasmine-html-reporter": "^1.5.0",
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"protractor": "~7.0.0",
"standard-version": "^9.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./src/*.{js,jsx,ts,tsx}": [
"npx prettier --write"
],
"./src/*.{js,jsx,ts,tsx, css, html}": [
"npx eslint --cache --fix"
]
}
}

View File

@ -19,7 +19,7 @@
</mat-form-field>
</div>
<mat-divider></mat-divider>
<h2 *ngIf="showOtp">Client ID: {{clientID}}</h2>
<h2 *ngIf="showOtp">Client ID: {{clientId}}</h2>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px" *ngIf="showOtp">
<mat-form-field fxFlex>
<mat-label>Otp</mat-label>

View File

@ -1,51 +1,61 @@
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Router } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { AuthService } from '../auth/auth.service';
import { ToasterService } from './toaster.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { ToasterService } from './toaster.service';
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(private authService: AuthService, private router: Router, private dialog: MatDialog, private toaster: ToasterService) {
}
constructor(
private authService: AuthService,
private router: Router,
private dialog: MatDialog,
private toaster: ToasterService,
) {}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(err => {
// We don't want to refresh token for some requests like login or refresh token itself
// So we verify url and we throw an error if it's the case
if (request.url.includes('/refresh') || request.url.includes('/token')) {
// We do another check to see if refresh token failed
// In this case we want to logout user and to redirect it to login page
if (request.url.includes('/refresh')) {
this.authService.logout();
return next.handle(request).pipe(
catchError((err) => {
// We don't want to refresh token for some requests like login or refresh token itself
// So we verify url and we throw an error if it's the case
if (request.url.includes('/refresh') || request.url.includes('/token')) {
// We do another check to see if refresh token failed
// In this case we want to logout user and to redirect it to login page
if (request.url.includes('/refresh')) {
this.authService.logout();
}
return throwError(err);
}
// If error status is different than 401 we want to skip refresh token
// So we check that and throw the error if it's the case
if (err.status !== 401) {
const error = err.error.message || err.error.detail || err.statusText;
return throwError(error);
}
// auto logout if 401 response returned from api
this.authService.logout();
this.toaster.show('Danger', 'User has been logged out');
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {
title: 'Logged out!',
content:
'You have been logged out.\nYou can press Cancel to stay on page and login in another tab to resume here, or you can press Ok to navigate to the login page.',
},
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.router.navigate(['login']);
}
});
return throwError(err);
}
// If error status is different than 401 we want to skip refresh token
// So we check that and throw the error if it's the case
if (err.status !== 401) {
const error = err.error.message || err.error.detail || err.statusText;
return throwError(error);
}
// auto logout if 401 response returned from api
this.authService.logout();
this.toaster.show('Danger', 'User has been logged out');
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {
title: 'Logged out!',
content: 'You have been logged out.\nYou can press Cancel to stay on page and login in another tab to resume here, or you can press Ok to navigate to the login page.'
}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.router.navigate(['login']);
}
});
}));
}),
);
}
}

View File

@ -54,7 +54,7 @@ export class MenuCategoryListComponent implements OnInit {
);
}
dropTable(event: CdkDragDrop<MenuCategory[]>) {
dropTable(event: CdkDragDrop<MenuCategoryListDatasource>) {
const prevIndex = this.list.indexOf(event.item.data);
moveItemInArray(this.list, prevIndex, event.currentIndex);
this.data.next(this.list);

View File

@ -72,7 +72,7 @@ export class ProductListComponent implements OnInit {
);
}
dropTable(event: CdkDragDrop<Product[]>) {
dropTable(event: CdkDragDrop<ProductListDataSource>) {
const prevIndex = this.list.indexOf(event.item.data);
moveItemInArray(this.list, prevIndex, event.currentIndex);
this.data.next(this.list);

View File

@ -31,7 +31,7 @@ export class BillsComponent implements OnInit {
private dialog: MatDialog,
private toaster: ToasterService,
private auth: AuthService,
private bs: BillService,
public bs: BillService,
private tSer: TableService
) {
}

View File

@ -9,7 +9,7 @@
<mat-form-field fxFlex>
<mat-label>Reason</mat-label>
<input type="text" matInput #son placeholder="Reason" formControlName="son" autocomplete="off"
(focus)="select($event.target.value) && son.select()" (input)="select($event.target.value)">
(focus)="select(son.value) && son.select()" (input)="select(son.value)">
</mat-form-field>
</mat-footer-cell>
</ng-container>

View File

@ -45,7 +45,7 @@
<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="!!form.get('menuCategories').at(i).value.printer">
<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>

View File

@ -54,7 +54,7 @@ export class TableListComponent implements OnInit {
);
}
dropTable(event: CdkDragDrop<MenuCategory[]>) {
dropTable(event: CdkDragDrop<TableListDataSource>) {
const prevIndex = this.list.indexOf(event.item.data);
moveItemInArray(this.list, prevIndex, event.currentIndex);
this.data.next(this.list);

View File

@ -1,17 +0,0 @@
{
"extends": "../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
]
}
}

View File

@ -1,12 +1,12 @@
{
"extends": "../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"outDir": "../frontend",
"types": []
},
"files": [
"main.ts",
"polyfills.ts"
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"

View File

@ -2,20 +2,27 @@
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"outDir": "../frontend",
"forceConsistentCasingInFileNames": true,
// "strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

View File

@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"types": [
@ -8,8 +8,8 @@
]
},
"files": [
"test.ts",
"polyfills.ts"
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"**/*.spec.ts",

View File

@ -1,131 +0,0 @@
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"arrow-return-shorthand": true,
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"deprecation": {
"severity": "warn"
},
"eofline": true,
"forin": true,
"import-blacklist": [
true,
"rxjs/Rx"
],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
{
"order": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-misused-new": true,
"no-non-null-assertion": true,
"no-redundant-jsdoc": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
true,
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"no-output-on-prefix": true,
"no-inputs-metadata-property": true,
"no-outputs-metadata-property": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-output-rename": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
}