From 38300f247aff543262a6fccbf64f8cf1338f277e Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Thu, 31 Oct 2024 23:55:34 -0400 Subject: [PATCH] Prettier --- client/admin/.prettierignore | 3 ++ client/admin/.prettierrc | 1 + client/admin/angular.json | 17 ++----- client/admin/package-lock.json | 17 +++++++ client/admin/package.json | 1 + client/admin/src/app/api.service.ts | 37 ++++++++------ client/admin/src/app/app.component.ts | 2 +- client/admin/src/app/app.config.ts | 26 ++++++---- client/admin/src/app/app.routes.ts | 10 ++-- client/admin/src/app/auth.guard.spec.ts | 4 +- client/admin/src/app/auth.guard.ts | 4 +- .../admin/src/app/home/home.component.spec.ts | 5 +- client/admin/src/app/home/home.component.ts | 6 +-- .../admin/src/app/login/login.component.html | 48 ++++++++++++------- .../src/app/login/login.component.spec.ts | 5 +- client/admin/src/app/login/login.component.ts | 33 +++++++------ client/admin/src/index.html | 20 ++++---- client/admin/src/main.ts | 5 +- client/admin/tailwind.config.js | 6 +-- client/admin/tsconfig.app.json | 8 +--- client/admin/tsconfig.json | 5 +- client/admin/tsconfig.spec.json | 9 +--- 22 files changed, 150 insertions(+), 122 deletions(-) create mode 100644 client/admin/.prettierignore create mode 100644 client/admin/.prettierrc diff --git a/client/admin/.prettierignore b/client/admin/.prettierignore new file mode 100644 index 0000000..1b8ac88 --- /dev/null +++ b/client/admin/.prettierignore @@ -0,0 +1,3 @@ +# Ignore artifacts: +build +coverage diff --git a/client/admin/.prettierrc b/client/admin/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/client/admin/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/client/admin/angular.json b/client/admin/angular.json index b6ed706..6b18863 100644 --- a/client/admin/angular.json +++ b/client/admin/angular.json @@ -16,9 +16,7 @@ "outputPath": "dist/admin", "index": "src/index.html", "browser": "src/main.ts", - "polyfills": [ - "zone.js" - ], + "polyfills": ["zone.js"], "tsConfig": "tsconfig.app.json", "assets": [ { @@ -26,9 +24,7 @@ "input": "public" } ], - "styles": [ - "src/styles.css" - ], + "styles": ["src/styles.css"], "scripts": [] }, "configurations": { @@ -73,10 +69,7 @@ "test": { "builder": "@angular-devkit/build-angular:karma", "options": { - "polyfills": [ - "zone.js", - "zone.js/testing" - ], + "polyfills": ["zone.js", "zone.js/testing"], "tsConfig": "tsconfig.spec.json", "assets": [ { @@ -84,9 +77,7 @@ "input": "public" } ], - "styles": [ - "src/styles.css" - ], + "styles": ["src/styles.css"], "scripts": [] } } diff --git a/client/admin/package-lock.json b/client/admin/package-lock.json index 1a4570a..6bc06a5 100644 --- a/client/admin/package-lock.json +++ b/client/admin/package-lock.json @@ -32,6 +32,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "prettier": "3.3.3", "tailwindcss": "^3.4.14", "typescript": "~5.5.2" } @@ -11137,6 +11138,22 @@ "dev": true, "license": "MIT" }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/proc-log": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-4.2.0.tgz", diff --git a/client/admin/package.json b/client/admin/package.json index dcc7abd..ed8a8c3 100644 --- a/client/admin/package.json +++ b/client/admin/package.json @@ -34,6 +34,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "prettier": "3.3.3", "tailwindcss": "^3.4.14", "typescript": "~5.5.2" } diff --git a/client/admin/src/app/api.service.ts b/client/admin/src/app/api.service.ts index 5d95a9f..0249ef7 100644 --- a/client/admin/src/app/api.service.ts +++ b/client/admin/src/app/api.service.ts @@ -1,29 +1,36 @@ import { Injectable } from '@angular/core'; -import {HttpClient, HttpResponse } from '@angular/common/http'; +import { HttpClient, HttpResponse } from '@angular/common/http'; import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; export class Jwt { - constructor( - public jwt: string, - ) {} + constructor(public jwt: string) {} } @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class APIService { - constructor(private http: HttpClient, private _router: Router) { + constructor( + private http: HttpClient, + private _router: Router, + ) {} - } - - login(username: string, password: string): Observable> { - return this.http.post('/login', {username: username, password: password}, {observe: 'response'}).pipe(tap((event) => { - if (event.status == 200) { - sessionStorage.setItem('jwt', event.body?.jwt.toString() ?? ''); - this._router.navigateByUrl('/home'); - } - })); + login(username: string, password: string): Observable> { + return this.http + .post( + '/login', + { username: username, password: password }, + { observe: 'response' }, + ) + .pipe( + tap((event) => { + if (event.status == 200) { + sessionStorage.setItem('jwt', event.body?.jwt.toString() ?? ''); + this._router.navigateByUrl('/home'); + } + }), + ); } } diff --git a/client/admin/src/app/app.component.ts b/client/admin/src/app/app.component.ts index 0e89945..039c2b7 100644 --- a/client/admin/src/app/app.component.ts +++ b/client/admin/src/app/app.component.ts @@ -6,7 +6,7 @@ import { RouterOutlet } from '@angular/router'; standalone: true, imports: [RouterOutlet], templateUrl: './app.component.html', - styleUrl: './app.component.css' + styleUrl: './app.component.css', }) export class AppComponent { title = 'admin'; diff --git a/client/admin/src/app/app.config.ts b/client/admin/src/app/app.config.ts index c1a30f5..511abb3 100644 --- a/client/admin/src/app/app.config.ts +++ b/client/admin/src/app/app.config.ts @@ -1,25 +1,35 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; import { provideRouter } from '@angular/router'; -import {HttpRequest, HttpHandlerFn, HttpEvent, withInterceptors} from '@angular/common/http'; +import { + HttpRequest, + HttpHandlerFn, + HttpEvent, + withInterceptors, +} from '@angular/common/http'; import { Observable } from 'rxjs'; import { isDevMode } from '@angular/core'; - - import { routes } from './app.routes'; -import {provideHttpClient} from '@angular/common/http'; +import { provideHttpClient } from '@angular/common/http'; -export function apiBaseInterceptor(req: HttpRequest, next: HttpHandlerFn): Observable> { +export function apiBaseInterceptor( + req: HttpRequest, + next: HttpHandlerFn, +): Observable> { let baseUrl: string; if (isDevMode()) { - baseUrl = "http://xenon:3050"; + baseUrl = 'http://xenon:3050'; } else { - baseUrl = ""; + baseUrl = ''; } const apiReq = req.clone({ url: `${baseUrl}${req.url}` }); return next(apiReq); } export const appConfig: ApplicationConfig = { - providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideHttpClient(withInterceptors([apiBaseInterceptor]))] + providers: [ + provideZoneChangeDetection({ eventCoalescing: true }), + provideRouter(routes), + provideHttpClient(withInterceptors([apiBaseInterceptor])), + ], }; diff --git a/client/admin/src/app/app.routes.ts b/client/admin/src/app/app.routes.ts index 2aa7ae7..a94f40b 100644 --- a/client/admin/src/app/app.routes.ts +++ b/client/admin/src/app/app.routes.ts @@ -1,13 +1,11 @@ import { Routes } from '@angular/router'; - -import {HomeComponent} from './home/home.component'; -import {LoginComponent} from './login/login.component'; -import {AuthGuard} from './auth.guard'; - +import { HomeComponent } from './home/home.component'; +import { LoginComponent } from './login/login.component'; +import { AuthGuard } from './auth.guard'; export const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, - { path: 'home', component: HomeComponent, canActivate:[AuthGuard]}, + { path: 'home', component: HomeComponent, canActivate: [AuthGuard] }, { path: 'login', component: LoginComponent }, ]; diff --git a/client/admin/src/app/auth.guard.spec.ts b/client/admin/src/app/auth.guard.spec.ts index 4ae275e..f1ada9d 100644 --- a/client/admin/src/app/auth.guard.spec.ts +++ b/client/admin/src/app/auth.guard.spec.ts @@ -4,8 +4,8 @@ import { CanActivateFn } from '@angular/router'; import { authGuard } from './auth.guard'; describe('authGuard', () => { - const executeGuard: CanActivateFn = (...guardParameters) => - TestBed.runInInjectionContext(() => authGuard(...guardParameters)); + const executeGuard: CanActivateFn = (...guardParameters) => + TestBed.runInInjectionContext(() => authGuard(...guardParameters)); beforeEach(() => { TestBed.configureTestingModule({}); diff --git a/client/admin/src/app/auth.guard.ts b/client/admin/src/app/auth.guard.ts index 0307737..f5065e2 100644 --- a/client/admin/src/app/auth.guard.ts +++ b/client/admin/src/app/auth.guard.ts @@ -1,9 +1,9 @@ import { CanActivateFn } from '@angular/router'; export const AuthGuard: CanActivateFn = (route, state) => { - if (sessionStorage.getItem("jwt") == null) { + if (sessionStorage.getItem('jwt') == null) { return false; } else { return true; } -} +}; diff --git a/client/admin/src/app/home/home.component.spec.ts b/client/admin/src/app/home/home.component.spec.ts index 1191557..7737f1c 100644 --- a/client/admin/src/app/home/home.component.spec.ts +++ b/client/admin/src/app/home/home.component.spec.ts @@ -8,9 +8,8 @@ describe('HomeComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [HomeComponent] - }) - .compileComponents(); + imports: [HomeComponent], + }).compileComponents(); fixture = TestBed.createComponent(HomeComponent); component = fixture.componentInstance; diff --git a/client/admin/src/app/home/home.component.ts b/client/admin/src/app/home/home.component.ts index deaec52..14c5108 100644 --- a/client/admin/src/app/home/home.component.ts +++ b/client/admin/src/app/home/home.component.ts @@ -5,8 +5,6 @@ import { Component } from '@angular/core'; standalone: true, imports: [], templateUrl: './home.component.html', - styleUrl: './home.component.css' + styleUrl: './home.component.css', }) -export class HomeComponent { - -} +export class HomeComponent {} diff --git a/client/admin/src/app/login/login.component.html b/client/admin/src/app/login/login.component.html index 6049e84..511ceae 100644 --- a/client/admin/src/app/login/login.component.html +++ b/client/admin/src/app/login/login.component.html @@ -1,22 +1,34 @@
-
-
- - -
-
- -
-
- @if (failed) { - - } +
+
+ + +
+
+ +
+
+ @if (failed) { + + }
diff --git a/client/admin/src/app/login/login.component.spec.ts b/client/admin/src/app/login/login.component.spec.ts index 18f3685..251a67f 100644 --- a/client/admin/src/app/login/login.component.spec.ts +++ b/client/admin/src/app/login/login.component.spec.ts @@ -8,9 +8,8 @@ describe('LoginComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [LoginComponent] - }) - .compileComponents(); + imports: [LoginComponent], + }).compileComponents(); fixture = TestBed.createComponent(LoginComponent); component = fixture.componentInstance; diff --git a/client/admin/src/app/login/login.component.ts b/client/admin/src/app/login/login.component.ts index 1204bf6..9446408 100644 --- a/client/admin/src/app/login/login.component.ts +++ b/client/admin/src/app/login/login.component.ts @@ -1,7 +1,7 @@ import { Component, inject } from '@angular/core'; -import {FormsModule} from '@angular/forms'; -import {APIService} from '../api.service'; -import {catchError, of } from 'rxjs'; +import { FormsModule } from '@angular/forms'; +import { APIService } from '../api.service'; +import { catchError, of } from 'rxjs'; import { Router } from '@angular/router'; @Component({ @@ -9,7 +9,7 @@ import { Router } from '@angular/router'; standalone: true, imports: [FormsModule], templateUrl: './login.component.html', - styleUrl: './login.component.css' + styleUrl: './login.component.css', }) export class LoginComponent { apiService: APIService = inject(APIService); @@ -20,15 +20,20 @@ export class LoginComponent { onSubmit() { this.failed = false; - this.apiService.login(this.username, this.password).pipe(catchError(() => { - this.failed = true; - return of(null); - })).subscribe((event) => { - if (event?.status == 200) { - this.router.navigateByUrl('/home') - } else { - this.failed = true; - } - }); + this.apiService + .login(this.username, this.password) + .pipe( + catchError(() => { + this.failed = true; + return of(null); + }), + ) + .subscribe((event) => { + if (event?.status == 200) { + this.router.navigateByUrl('/home'); + } else { + this.failed = true; + } + }); } } diff --git a/client/admin/src/index.html b/client/admin/src/index.html index 0a8c6c3..cfc0cc1 100644 --- a/client/admin/src/index.html +++ b/client/admin/src/index.html @@ -1,13 +1,13 @@ - - - Admin - - - - - - - + + + Admin + + + + + + + diff --git a/client/admin/src/main.ts b/client/admin/src/main.ts index 35b00f3..8882c45 100644 --- a/client/admin/src/main.ts +++ b/client/admin/src/main.ts @@ -2,5 +2,6 @@ import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; -bootstrapApplication(AppComponent, appConfig) - .catch((err) => console.error(err)); +bootstrapApplication(AppComponent, appConfig).catch((err) => + console.error(err), +); diff --git a/client/admin/tailwind.config.js b/client/admin/tailwind.config.js index 35ca417..b3a72d5 100644 --- a/client/admin/tailwind.config.js +++ b/client/admin/tailwind.config.js @@ -1,9 +1,7 @@ /** @type {import('tailwindcss').Config} */ module.exports = { - content: [ - "./src/**/*.{html,ts}", - ], + content: ["./src/**/*.{html,ts}"], theme: { extend: {}, }, @@ -17,4 +15,4 @@ module.exports = { logs: true, rtl: false, }, -} +}; diff --git a/client/admin/tsconfig.app.json b/client/admin/tsconfig.app.json index 3775b37..8886e90 100644 --- a/client/admin/tsconfig.app.json +++ b/client/admin/tsconfig.app.json @@ -6,10 +6,6 @@ "outDir": "./out-tsc/app", "types": [] }, - "files": [ - "src/main.ts" - ], - "include": [ - "src/**/*.d.ts" - ] + "files": ["src/main.ts"], + "include": ["src/**/*.d.ts"] } diff --git a/client/admin/tsconfig.json b/client/admin/tsconfig.json index a8bb65b..25afa53 100644 --- a/client/admin/tsconfig.json +++ b/client/admin/tsconfig.json @@ -19,10 +19,7 @@ "importHelpers": true, "target": "ES2022", "module": "ES2022", - "lib": [ - "ES2022", - "dom" - ] + "lib": ["ES2022", "dom"] }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false, diff --git a/client/admin/tsconfig.spec.json b/client/admin/tsconfig.spec.json index 5fb748d..e00e30e 100644 --- a/client/admin/tsconfig.spec.json +++ b/client/admin/tsconfig.spec.json @@ -4,12 +4,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", - "types": [ - "jasmine" - ] + "types": ["jasmine"] }, - "include": [ - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] + "include": ["src/**/*.spec.ts", "src/**/*.d.ts"] }