Added angular website, with login, registration & searching.
This commit is contained in:
16
frontend/angular-seshat/.editorconfig
Normal file
16
frontend/angular-seshat/.editorconfig
Normal file
@ -0,0 +1,16 @@
|
||||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
42
frontend/angular-seshat/.gitignore
vendored
Normal file
42
frontend/angular-seshat/.gitignore
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
|
||||
|
||||
# Compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
/bazel-out
|
||||
|
||||
# Node
|
||||
/node_modules
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# IDEs and editors
|
||||
.idea/
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history/*
|
||||
|
||||
# Miscellaneous
|
||||
/.angular/cache
|
||||
.sass-cache/
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
testem.log
|
||||
/typings
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
4
frontend/angular-seshat/.vscode/extensions.json
vendored
Normal file
4
frontend/angular-seshat/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
|
||||
"recommendations": ["angular.ng-template"]
|
||||
}
|
20
frontend/angular-seshat/.vscode/launch.json
vendored
Normal file
20
frontend/angular-seshat/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ng serve",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "npm: start",
|
||||
"url": "http://localhost:4200/"
|
||||
},
|
||||
{
|
||||
"name": "ng test",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "npm: test",
|
||||
"url": "http://localhost:9876/debug.html"
|
||||
}
|
||||
]
|
||||
}
|
42
frontend/angular-seshat/.vscode/tasks.json
vendored
Normal file
42
frontend/angular-seshat/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "start",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"owner": "typescript",
|
||||
"pattern": "$tsc",
|
||||
"background": {
|
||||
"activeOnStart": true,
|
||||
"beginsPattern": {
|
||||
"regexp": "(.*?)"
|
||||
},
|
||||
"endsPattern": {
|
||||
"regexp": "bundle generation complete"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "test",
|
||||
"isBackground": true,
|
||||
"problemMatcher": {
|
||||
"owner": "typescript",
|
||||
"pattern": "$tsc",
|
||||
"background": {
|
||||
"activeOnStart": true,
|
||||
"beginsPattern": {
|
||||
"regexp": "(.*?)"
|
||||
},
|
||||
"endsPattern": {
|
||||
"regexp": "bundle generation complete"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
27
frontend/angular-seshat/README.md
Normal file
27
frontend/angular-seshat/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# AngularSeshat
|
||||
|
||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.0.5.
|
||||
|
||||
## Development server
|
||||
|
||||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||
|
||||
## Running end-to-end tests
|
||||
|
||||
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
|
||||
|
||||
## Further help
|
||||
|
||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
134
frontend/angular-seshat/angular.json
Normal file
134
frontend/angular-seshat/angular.json
Normal file
@ -0,0 +1,134 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"angular-seshat": {
|
||||
"projectType": "application",
|
||||
"schematics": {},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:application",
|
||||
"options": {
|
||||
"outputPath": "dist/angular-seshat",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": [
|
||||
"zone.js"
|
||||
],
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
],
|
||||
"scripts": [],
|
||||
"server": "src/main.server.ts",
|
||||
"prerender": true,
|
||||
"ssr": {
|
||||
"entry": "server.ts"
|
||||
}
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kB",
|
||||
"maximumError": "1MB"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kB",
|
||||
"maximumError": "4kB"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"optimization": false,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"buildTarget": "angular-seshat:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "angular-seshat:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n"
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"polyfills": [
|
||||
"zone.js",
|
||||
"zone.js/testing"
|
||||
],
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"assets": [
|
||||
{
|
||||
"glob": "**/*",
|
||||
"input": "public"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
],
|
||||
"scripts": []
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"library": {
|
||||
"projectType": "library",
|
||||
"root": "projects/library",
|
||||
"sourceRoot": "projects/library/src",
|
||||
"prefix": "lib",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:ng-packagr",
|
||||
"options": {
|
||||
"project": "projects/library/ng-package.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"tsConfig": "projects/library/tsconfig.lib.prod.json"
|
||||
},
|
||||
"development": {
|
||||
"tsConfig": "projects/library/tsconfig.lib.json"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"tsConfig": "projects/library/tsconfig.spec.json",
|
||||
"polyfills": [
|
||||
"zone.js",
|
||||
"zone.js/testing"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
14418
frontend/angular-seshat/package-lock.json
generated
Normal file
14418
frontend/angular-seshat/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
frontend/angular-seshat/package.json
Normal file
47
frontend/angular-seshat/package.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "angular-seshat",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test",
|
||||
"serve:ssr:angular-seshat": "node dist/angular-seshat/server/server.mjs"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^18.0.0",
|
||||
"@angular/common": "^18.0.0",
|
||||
"@angular/compiler": "^18.0.0",
|
||||
"@angular/core": "^18.0.0",
|
||||
"@angular/forms": "^18.0.0",
|
||||
"@angular/material": "^18.2.14",
|
||||
"@angular/platform-browser": "^18.0.0",
|
||||
"@angular/platform-browser-dynamic": "^18.0.0",
|
||||
"@angular/platform-server": "^18.0.0",
|
||||
"@angular/router": "^18.0.0",
|
||||
"@angular/ssr": "^18.0.5",
|
||||
"express": "^4.18.2",
|
||||
"ngx-cookie-service": "^18.0.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zone.js": "~0.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^18.0.5",
|
||||
"@angular/cli": "^18.0.5",
|
||||
"@angular/compiler-cli": "^18.0.0",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"@types/node": "^18.18.0",
|
||||
"jasmine-core": "~5.1.0",
|
||||
"karma": "~6.4.0",
|
||||
"karma-chrome-launcher": "~3.2.0",
|
||||
"karma-coverage": "~2.2.0",
|
||||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"ng-packagr": "^18.2.0",
|
||||
"typescript": "~5.4.2"
|
||||
}
|
||||
}
|
BIN
frontend/angular-seshat/public/favicon.ico
Normal file
BIN
frontend/angular-seshat/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M80-140v-320h320v320H80Zm80-80h160v-160H160v160Zm60-340 220-360 220 360H220Zm142-80h156l-78-126-78 126ZM863-42 757-148q-21 14-45.5 21t-51.5 7q-75 0-127.5-52.5T480-300q0-75 52.5-127.5T660-480q75 0 127.5 52.5T840-300q0 26-7 50.5T813-204L919-98l-56 56ZM660-200q42 0 71-29t29-71q0-42-29-71t-71-29q-42 0-71 29t-29 71q0 42 29 71t71 29ZM320-380Zm120-260Z"/></svg>
|
After Width: | Height: | Size: 472 B |
1
frontend/angular-seshat/public/icons/close_icon.svg
Normal file
1
frontend/angular-seshat/public/icons/close_icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"/></svg>
|
After Width: | Height: | Size: 222 B |
1
frontend/angular-seshat/public/icons/error_icon.svg
Normal file
1
frontend/angular-seshat/public/icons/error_icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm-40-160h80v-240h-80v240Zm40 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
After Width: | Height: | Size: 537 B |
1
frontend/angular-seshat/public/icons/search_icon.svg
Normal file
1
frontend/angular-seshat/public/icons/search_icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>
|
After Width: | Height: | Size: 376 B |
1
frontend/angular-seshat/public/icons/warning_icon.svg
Normal file
1
frontend/angular-seshat/public/icons/warning_icon.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z"/></svg>
|
After Width: | Height: | Size: 314 B |
57
frontend/angular-seshat/server.ts
Normal file
57
frontend/angular-seshat/server.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { APP_BASE_HREF } from '@angular/common';
|
||||
import { CommonEngine } from '@angular/ssr';
|
||||
import express from 'express';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import bootstrap from './src/main.server';
|
||||
|
||||
// The Express app is exported so that it can be used by serverless Functions.
|
||||
export function app(): express.Express {
|
||||
const server = express();
|
||||
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
||||
const browserDistFolder = resolve(serverDistFolder, '../browser');
|
||||
const indexHtml = join(serverDistFolder, 'index.server.html');
|
||||
|
||||
const commonEngine = new CommonEngine();
|
||||
|
||||
server.set('view engine', 'html');
|
||||
server.set('views', browserDistFolder);
|
||||
|
||||
// Example Express Rest API endpoints
|
||||
// server.get('/api/**', (req, res) => { });
|
||||
// Serve static files from /browser
|
||||
server.get('**', express.static(browserDistFolder, {
|
||||
maxAge: '1y',
|
||||
index: 'index.html',
|
||||
}));
|
||||
|
||||
// All regular routes use the Angular engine
|
||||
server.get('**', (req, res, next) => {
|
||||
const { protocol, originalUrl, baseUrl, headers } = req;
|
||||
|
||||
commonEngine
|
||||
.render({
|
||||
bootstrap,
|
||||
documentFilePath: indexHtml,
|
||||
url: `${protocol}://${headers.host}${originalUrl}`,
|
||||
publicPath: browserDistFolder,
|
||||
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
||||
})
|
||||
.then((html) => res.send(html))
|
||||
.catch((err) => next(err));
|
||||
});
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
function run(): void {
|
||||
const port = process.env['PORT'] || 4000;
|
||||
|
||||
// Start up the Node server
|
||||
const server = app();
|
||||
server.listen(port, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
run();
|
10
frontend/angular-seshat/src/app/app.component.css
Normal file
10
frontend/angular-seshat/src/app/app.component.css
Normal file
@ -0,0 +1,10 @@
|
||||
.loading-container {
|
||||
display: flex;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
z-index: 1000;
|
||||
}
|
6
frontend/angular-seshat/src/app/app.component.html
Normal file
6
frontend/angular-seshat/src/app/app.component.html
Normal file
@ -0,0 +1,6 @@
|
||||
@if (loading) {
|
||||
<div class="loading-container flex-content-center">
|
||||
<div>hello, loading world.</div>
|
||||
</div>
|
||||
}
|
||||
<router-outlet />
|
29
frontend/angular-seshat/src/app/app.component.spec.ts
Normal file
29
frontend/angular-seshat/src/app/app.component.spec.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [AppComponent],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should have the 'angular-seshat' title`, () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.componentInstance;
|
||||
expect(app.title).toEqual('angular-seshat');
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, angular-seshat');
|
||||
});
|
||||
});
|
53
frontend/angular-seshat/src/app/app.component.ts
Normal file
53
frontend/angular-seshat/src/app/app.component.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { Component, inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { AuthService } from './services/auth/auth.service';
|
||||
import { ConfigService } from './services/config.service';
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { LoadingService } from './services/loading.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { RedirectionService } from './services/redirection.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
standalone: true,
|
||||
imports: [RouterOutlet],
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.css'
|
||||
})
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _config = inject(ConfigService);
|
||||
private readonly _loading = inject(LoadingService);
|
||||
private readonly _platformId = inject(PLATFORM_ID);
|
||||
private readonly _redirect = inject(RedirectionService);
|
||||
private readonly _subscriptions: Subscription[] = [];
|
||||
|
||||
loading: boolean = false;
|
||||
|
||||
ngOnInit() {
|
||||
if (!isPlatformBrowser(this._platformId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.listenToLoading();
|
||||
|
||||
this._config.fetch();
|
||||
this._auth.update();
|
||||
|
||||
this._loading.listenUntilReady()
|
||||
.subscribe(async () => {
|
||||
this._redirect.redirect(null);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._subscriptions.forEach(s => s.unsubscribe());
|
||||
}
|
||||
|
||||
listenToLoading(): void {
|
||||
this._subscriptions.push(
|
||||
this._loading.listen()
|
||||
.subscribe((loading) => this.loading = loading)
|
||||
);
|
||||
}
|
||||
}
|
11
frontend/angular-seshat/src/app/app.config.server.ts
Normal file
11
frontend/angular-seshat/src/app/app.config.server.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
|
||||
import { provideServerRendering } from '@angular/platform-server';
|
||||
import { appConfig } from './app.config';
|
||||
|
||||
const serverConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideServerRendering()
|
||||
],
|
||||
};
|
||||
|
||||
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
21
frontend/angular-seshat/src/app/app.config.ts
Normal file
21
frontend/angular-seshat/src/app/app.config.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { routes } from './app.routes';
|
||||
import { provideClientHydration } from '@angular/platform-browser';
|
||||
import { provideHttpClient, withInterceptorsFromDi, withFetch, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { LoadingInterceptor } from './shared/interceptors/loading.interceptor';
|
||||
import { TokenValidationInterceptor } from './shared/interceptors/token-validation.interceptor';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideZoneChangeDetection({ eventCoalescing: true }),
|
||||
provideRouter(routes),
|
||||
provideClientHydration(),
|
||||
provideHttpClient(
|
||||
withInterceptorsFromDi(),
|
||||
withFetch()
|
||||
),
|
||||
LoadingInterceptor,
|
||||
TokenValidationInterceptor,
|
||||
]
|
||||
};
|
22
frontend/angular-seshat/src/app/app.routes.ts
Normal file
22
frontend/angular-seshat/src/app/app.routes.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { LoginFormComponent } from './login/login-form/login-form.component';
|
||||
import { RegisterFormComponent } from './register/register-form/register-form.component';
|
||||
import { AddNewPageComponent } from './library/add-new-page/add-new-page.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: 'login',
|
||||
component: LoginFormComponent,
|
||||
canActivate: [],
|
||||
},
|
||||
{
|
||||
path: 'register',
|
||||
component: RegisterFormComponent,
|
||||
canActivate: [],
|
||||
},
|
||||
{
|
||||
path: 'add/new',
|
||||
component: AddNewPageComponent,
|
||||
canActivate: [],
|
||||
},
|
||||
];
|
@ -0,0 +1,37 @@
|
||||
.results-box {
|
||||
background: #5757576c;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.results-error {
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
color: red;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.results-end {
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
color: #ff8c00;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.results-error img, .results-end img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.filter-error {
|
||||
filter: brightness(0) saturate(100%) invert(25%) sepia(67%) saturate(2736%) hue-rotate(340deg) brightness(110%) contrast(100%);
|
||||
}
|
||||
|
||||
.filter-warning {
|
||||
filter: brightness(0) saturate(100%) invert(52%) sepia(95%) saturate(2039%) hue-rotate(3deg) brightness(106%) contrast(102%);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<div class="search-content">
|
||||
<search-box
|
||||
(searchOutput)="search.next($event)"
|
||||
(filtersOutput)="filters.next($event)" />
|
||||
<div class="results-box"
|
||||
(scroll)="onResultsScroll($event)">
|
||||
@for (result of results; track $index) {
|
||||
<media-search-item class="result-item"
|
||||
[media]="result" />
|
||||
}
|
||||
@if (searchError() != null) {
|
||||
<p class="results-error">
|
||||
<img src="/icons/error_icon.svg"
|
||||
alt="error icon"
|
||||
class="filter-error" />
|
||||
{{searchError()}}
|
||||
</p>
|
||||
}
|
||||
@if (endOfResults()) {
|
||||
<div class="results-end">
|
||||
<img src="/icons/warning_icon.svg"
|
||||
alt="warning icon"
|
||||
class="filter-warning" />
|
||||
No more results returned from the provider.
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AddNewPageComponent } from './add-new-page.component';
|
||||
|
||||
describe('AddNewPageComponent', () => {
|
||||
let component: AddNewPageComponent;
|
||||
let fixture: ComponentFixture<AddNewPageComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [AddNewPageComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(AddNewPageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,126 @@
|
||||
import { Component, inject, NgZone, OnDestroy, signal } from '@angular/core';
|
||||
import { AuthService } from '../../services/auth/auth.service';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { BehaviorSubject, combineLatest, distinctUntilChanged, filter, scan, Subscription, tap, throttleTime } from 'rxjs';
|
||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { RedirectionService } from '../../services/redirection.service';
|
||||
import { BookSearchResultDto } from '../../shared/dto/book-search-result.dto';
|
||||
import { MediaSearchItemComponent } from '../media-search-item/media-search-item.component';
|
||||
import { SearchBoxComponent } from "../search-box/search-box.component";
|
||||
import { SearchContextDto } from '../../shared/dto/search-context.dto';
|
||||
|
||||
@Component({
|
||||
selector: 'add-new-page',
|
||||
standalone: true,
|
||||
imports: [
|
||||
MediaSearchItemComponent,
|
||||
ReactiveFormsModule,
|
||||
SearchBoxComponent
|
||||
],
|
||||
templateUrl: './add-new-page.component.html',
|
||||
styleUrl: './add-new-page.component.css'
|
||||
})
|
||||
export class AddNewPageComponent implements OnDestroy {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _http = inject(HttpClient);
|
||||
private readonly _redirect = inject(RedirectionService);
|
||||
private readonly _subscriptions: Subscription[] = [];
|
||||
private readonly _zone = inject(NgZone);
|
||||
|
||||
search = new BehaviorSubject<string>('');
|
||||
filters = new BehaviorSubject<SearchContextDto>(new SearchContextDto());
|
||||
page = new BehaviorSubject<number>(0);
|
||||
results: BookSearchResultDto[] = [];
|
||||
resultsPerPage = signal<number>(10);
|
||||
endOfResults = signal<boolean>(false);
|
||||
searchError = signal<string | null>(null);
|
||||
|
||||
constructor() {
|
||||
this._zone.runOutsideAngular(() =>
|
||||
// Subscription for the search bar.
|
||||
this._subscriptions.push(
|
||||
combineLatest({
|
||||
search: this.search.pipe(
|
||||
filter(value => value != null),
|
||||
),
|
||||
filters: this.filters,
|
||||
page: this.page.pipe(
|
||||
throttleTime(3000, undefined, { leading: true, trailing: true }),
|
||||
),
|
||||
}).pipe(
|
||||
filter(entry => !this.endOfResults() && entry.search!.length > 1),
|
||||
throttleTime(1000, undefined, { leading: false, trailing: true }),
|
||||
scan((acc, next) => {
|
||||
if (acc.search != next.search) {
|
||||
this.results = [];
|
||||
return {
|
||||
...next,
|
||||
page: 0
|
||||
};
|
||||
}
|
||||
if (this.searchError() != null) {
|
||||
return acc;
|
||||
}
|
||||
return {
|
||||
...next,
|
||||
page: Math.min(acc.page + 1, next.page),
|
||||
};
|
||||
}),
|
||||
distinctUntilChanged(),
|
||||
filter(entry => entry.page >= 0),
|
||||
tap(_ => this.endOfResults.set(false)),
|
||||
).subscribe((entry) => {
|
||||
this._http.get('/api/providers/search',
|
||||
{
|
||||
params: {
|
||||
...this.filters.value.values,
|
||||
provider: 'google',
|
||||
search: entry.search!,
|
||||
startIndex: entry.page * this.resultsPerPage(),
|
||||
}
|
||||
}
|
||||
).subscribe({
|
||||
next: (results: any) => {
|
||||
[].push.apply(this.results, results);
|
||||
|
||||
if (results.length < this.resultsPerPage()) {
|
||||
this.endOfResults.set(true);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
if (err instanceof HttpErrorResponse) {
|
||||
if (err.status == 400) {
|
||||
this.searchError.set('Something went wrong when Google received the request.');
|
||||
} else if (err.status == 401) {
|
||||
this.searchError.set('Unauthorized. Refresh the page to login again.');
|
||||
} else if (err.status == 429) {
|
||||
this.searchError.set('Too many requests. Try again in a minute.');
|
||||
} else {
|
||||
this.searchError.set(err.name + ': ' + err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._subscriptions.forEach(s => s.unsubscribe());
|
||||
}
|
||||
|
||||
onResultsScroll(event: any): void {
|
||||
const scroll = event.target;
|
||||
const limit = scroll.scrollHeight - scroll.clientHeight;
|
||||
|
||||
// Prevent page changes when:
|
||||
// - new search is happening (emptying results);
|
||||
// - still scrolling through current content.
|
||||
if (scroll.scrollTop == 0 || scroll.scrollTop < limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.page.next(this.page.getValue() + 1);
|
||||
}
|
||||
}
|
12
frontend/angular-seshat/src/app/library/library.module.ts
Normal file
12
frontend/angular-seshat/src/app/library/library.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule
|
||||
]
|
||||
})
|
||||
export class LibraryModule { }
|
@ -0,0 +1,43 @@
|
||||
.result-item {
|
||||
background-color: #EEE;
|
||||
padding: 10px;
|
||||
border-radius: 15px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.result-info {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.title {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.volume {
|
||||
background-color: hsl(0, 0%, 84%);
|
||||
display: inline;
|
||||
margin-left: 10px;
|
||||
padding: 3px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: inline-flex;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 0 5px;
|
||||
margin: 0 3px;
|
||||
background-color: rgb(199, 199, 199);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.body {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: right;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<div class="result-item">
|
||||
<img class="result-image" [src]="media().thumbnail" />
|
||||
<div class="result-info">
|
||||
<div class="header">
|
||||
<h2 class="title">{{media().title}}</h2>
|
||||
@if (media().volume != null) {
|
||||
<label class="volume">volume {{media().volume}}</label>
|
||||
}
|
||||
</div>
|
||||
<div class="subheader tags">
|
||||
@for (tag of tags(); track $index) {
|
||||
<label class="tag">{{tag}}</label>
|
||||
}
|
||||
</div>
|
||||
<p class="body description">{{media().desc}}</p>
|
||||
<p class="footer">Metadata provided by {{provider()}}</p>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MediaSearchItemComponent } from './media-search-item.component';
|
||||
|
||||
describe('MediaSearchItemComponent', () => {
|
||||
let component: MediaSearchItemComponent;
|
||||
let fixture: ComponentFixture<MediaSearchItemComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MediaSearchItemComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(MediaSearchItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,39 @@
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
import { BookSearchResultDto } from '../../shared/dto/book-search-result.dto';
|
||||
|
||||
@Component({
|
||||
selector: 'media-search-item',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './media-search-item.component.html',
|
||||
styleUrl: './media-search-item.component.css'
|
||||
})
|
||||
export class MediaSearchItemComponent {
|
||||
media = input.required<BookSearchResultDto>();
|
||||
|
||||
tags = computed(() => {
|
||||
const tags = [];
|
||||
if (this.media().language)
|
||||
tags.push(this.media().language);
|
||||
if (this.media().publisher)
|
||||
tags.push(this.media().publisher);
|
||||
if (this.media().categories)
|
||||
tags.push.apply(tags, this.media().categories);
|
||||
if (this.media().maturityRating.replaceAll('_', ' '))
|
||||
tags.push(this.media().maturityRating);
|
||||
if (this.media().publishedAt) {
|
||||
tags.push(new Date(this.media().publishedAt).getFullYear());
|
||||
}
|
||||
return tags;
|
||||
});
|
||||
|
||||
provider = computed(() => {
|
||||
const value = this.media().provider;
|
||||
return value.split(' ')
|
||||
.map(s => s[0].toUpperCase() + s.substring(1))
|
||||
.join(' ')
|
||||
.split('-')
|
||||
.map(s => s[0].toUpperCase() + s.substring(1))
|
||||
.join('-');
|
||||
});
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
.search-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
padding: 20px;
|
||||
flex-direction: row;
|
||||
width: calc(100% - 40px);
|
||||
}
|
||||
|
||||
.left-side,
|
||||
.center-side,
|
||||
.right-side {
|
||||
align-content: center;
|
||||
height: 40px;
|
||||
border-top: 1px;
|
||||
border-bottom: 1px;
|
||||
border: 1px gray solid;
|
||||
}
|
||||
|
||||
.icon-wrapper {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.left-side {
|
||||
border: 1px gray solid;
|
||||
border-right: 0;
|
||||
border-radius: 3px 0 0 3px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.center-side {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.right-side {
|
||||
border: 1px gray solid;
|
||||
border-left: 0;
|
||||
border-radius: 0 3px 3px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
input {
|
||||
flex-grow: 1;
|
||||
outline: none;
|
||||
font-size: 20px;
|
||||
border: 0;
|
||||
padding: 0 15px;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 0 4px 3px rgba(31, 128, 255, 0.5);
|
||||
}
|
||||
|
||||
.icon-button:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.icon-enabled {
|
||||
background-color: rgb(185, 185, 185);
|
||||
}
|
||||
|
||||
.collapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.filters-box {
|
||||
margin: 0 60px 10px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.checkbox-wrapper, .select-wrapper, .text-wrapper {
|
||||
display: inline-flex;
|
||||
height: 20px;
|
||||
align-items: center;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.checkbox-wrapper input, .select-wrapper select, .text-wrapper input {
|
||||
display: inline;
|
||||
height: 20px;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.text-wrapper input {
|
||||
font-size: 13px;
|
||||
outline: 1px solid;
|
||||
}
|
||||
|
||||
.checkbox-wrapper label, .select-wrapper label, .text-wrapper label {
|
||||
display: inline;
|
||||
white-space: nowrap;
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<div class="search-bar">
|
||||
<div class="icon-wrapper left-side">
|
||||
<img src="/icons/search_icon.svg"
|
||||
alt="search icon" />
|
||||
</div>
|
||||
<div class="icon-wrapper icon-button left-side"
|
||||
[class.icon-enabled]="filtersEnabled.value">
|
||||
<img src="/icons/category_search_icon.svg"
|
||||
alt="advanced search icon"
|
||||
(click)="filtersEnabled.setValue(!filtersEnabled.value)" />
|
||||
</div>
|
||||
<div class="search-box center-side">
|
||||
<input type="text"
|
||||
placeholder="eg. Lord of the Rings"
|
||||
[formControl]="search" />
|
||||
</div>
|
||||
<div class="icon-wrapper icon-button right-side">
|
||||
<img src="/icons/close_icon.svg"
|
||||
alt="clear text button"
|
||||
(click)="search.setValue('')" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="filters-box"
|
||||
[class.collapsed]="!filtersEnabled.value">
|
||||
<div class="select-wrapper">
|
||||
<label for="languageSelect">Language</label>
|
||||
<select name="languageSelect"
|
||||
(change)="updateFilters('langRestrict', $event.target)">
|
||||
<option value="">All</option>
|
||||
@for (language of provider.languages | keyvalue; track language.key) {
|
||||
<option [value]="language.key">{{language.value}}</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="select-wrapper">
|
||||
<label for="orderBySelect">Order By</label>
|
||||
<select name="orderBySelect"
|
||||
(change)="updateFilters('orderBy', $event.target)">
|
||||
<option value="relevance">Relevance</option>
|
||||
<option value="newest">Newest</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="select-wrapper">
|
||||
<label for="resultsSizeSelect">Results Size</label>
|
||||
<select name="resultsSizeSelect"
|
||||
(change)="updateFilters('maxResults', $event.target)">
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="40">40</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="text-wrapper">
|
||||
<label for="resultsSizeSelect">ISBN</label>
|
||||
<input type="text"
|
||||
placeholder="ISBN-10 or ISBN-13"
|
||||
[formControl]="isbn" />
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SearchBoxComponent } from './search-box.component';
|
||||
|
||||
describe('SearchBoxComponent', () => {
|
||||
let component: SearchBoxComponent;
|
||||
let fixture: ComponentFixture<SearchBoxComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SearchBoxComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SearchBoxComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,65 @@
|
||||
import { Component, inject, NgZone, OnDestroy, output } from '@angular/core';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { SearchContextDto } from '../../shared/dto/search-context.dto';
|
||||
import { filter, Subscription } from 'rxjs';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'search-box',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
templateUrl: './search-box.component.html',
|
||||
styleUrl: './search-box.component.css'
|
||||
})
|
||||
export class SearchBoxComponent implements OnDestroy {
|
||||
private readonly _subscriptions: Subscription[] = [];
|
||||
private readonly _zone = inject(NgZone);
|
||||
|
||||
config = inject(ConfigService).config;
|
||||
filtersEnabled = new FormControl<boolean>(false);
|
||||
search = new FormControl<string>('');
|
||||
searchOutput = output<string>();
|
||||
filters = new SearchContextDto();
|
||||
filtersOutput = output<SearchContextDto>();
|
||||
isbn = new FormControl<string>('');
|
||||
|
||||
constructor() {
|
||||
this._zone.runOutsideAngular(() => {
|
||||
this._subscriptions.push(
|
||||
this.search.valueChanges.pipe(
|
||||
filter(value => value != null),
|
||||
).subscribe((value) => this.searchOutput.emit(value!))
|
||||
);
|
||||
|
||||
this._subscriptions.push(
|
||||
this.isbn.valueChanges.pipe(
|
||||
filter(value => value != null),
|
||||
).subscribe((value) => this.updateFilters('isbn', { value: value }))
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
get provider() {
|
||||
switch (this.config.providers.default) {
|
||||
case 'google': return this.config.providers.google;
|
||||
default: return this.config.providers.google;
|
||||
}
|
||||
}
|
||||
|
||||
updateFilters(key: string, value: any) {
|
||||
if (key == 'langRestrict' && value == '') {
|
||||
delete this.filters.values[key];
|
||||
} else {
|
||||
this.filters.values[key] = value.value;
|
||||
}
|
||||
this.filtersOutput.emit(this.filters);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this._subscriptions.forEach(s => s.unsubscribe());
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form {
|
||||
width: 500px;
|
||||
height: 100%;
|
||||
border: black solid 2px;
|
||||
border-radius: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.messages {
|
||||
width: 100%;
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
input {
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
margin: 20px;
|
||||
padding: 5px;
|
||||
border: gray solid 1px;
|
||||
border-radius: 15px;
|
||||
background-color: white;
|
||||
display: block;
|
||||
width: 400px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.input-wrapper:focus {
|
||||
outline: 5px solid blue;
|
||||
}
|
||||
|
||||
.checkbox-wrapper {
|
||||
display: inline-flex;
|
||||
height: 20px;
|
||||
align-items: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.checkbox-wrapper input {
|
||||
display: inline;
|
||||
height: 20px;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.checkbox-wrapper label {
|
||||
display: inline;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.actions {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
width: calc(100% - 30px);
|
||||
height: 50px;
|
||||
margin: 10px auto;
|
||||
border: 1px gray solid;
|
||||
border-radius: 15px;
|
||||
display: block;
|
||||
background-color: white;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #FAFAFA;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: white;
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
.register-link {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.register-link a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.register-link a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<div class="form">
|
||||
<h1>Login</h1>
|
||||
<div class="messages">
|
||||
<notice [message]="errorMessage"
|
||||
[level]="'error'"
|
||||
[visible]="errorMessage.length > 0" />
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="input-wrapper">
|
||||
<input type="text"
|
||||
placeholder="Username"
|
||||
[formControl]="username" />
|
||||
</div>
|
||||
<div class="input-wrapper">
|
||||
<input type="password"
|
||||
placeholder="Password"
|
||||
[formControl]="password" />
|
||||
</div>
|
||||
<div class="checkbox-wrapper">
|
||||
<input type="checkbox"
|
||||
id="rememberme"
|
||||
[formControl]="rememberMe">
|
||||
<label for="rememberme">Remember me?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button type="submit"
|
||||
(click)="login()"
|
||||
[disabled]="!forms.valid || waitForResponse">Login</button>
|
||||
</div>
|
||||
@if (config.features.registration) {
|
||||
<div class="register-link">
|
||||
Don't have an account?
|
||||
<a href="/register"
|
||||
(click)="register($event)">Register here.</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LoginFormComponent } from './login-form.component';
|
||||
|
||||
describe('LoginFormComponent', () => {
|
||||
let component: LoginFormComponent;
|
||||
let fixture: ComponentFixture<LoginFormComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [LoginFormComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(LoginFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,81 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { NoticeComponent } from "../../shared/notice/notice.component";
|
||||
import { Router } from '@angular/router';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { AuthService } from '../../services/auth/auth.service';
|
||||
import { LoadingService } from '../../services/loading.service';
|
||||
import { RedirectionService } from '../../services/redirection.service';
|
||||
|
||||
@Component({
|
||||
selector: 'login-form',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
NoticeComponent
|
||||
],
|
||||
templateUrl: './login-form.component.html',
|
||||
styleUrl: './login-form.component.css'
|
||||
})
|
||||
export class LoginFormComponent {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _loading = inject(LoadingService);
|
||||
private readonly _http = inject(HttpClient);
|
||||
private readonly _redirect = inject(RedirectionService);
|
||||
private readonly _router = inject(Router);
|
||||
readonly config = inject(ConfigService).config;
|
||||
|
||||
readonly username = new FormControl('', [Validators.required]);
|
||||
readonly password = new FormControl('', [Validators.required]);
|
||||
readonly rememberMe = new FormControl(false);
|
||||
readonly forms = new FormGroup({
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
});
|
||||
|
||||
waitForResponse: boolean = false;
|
||||
errorMessage: string = '';
|
||||
|
||||
login() {
|
||||
if (this.waitForResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.waitForResponse = true;
|
||||
this.errorMessage = '';
|
||||
if (!this.forms.valid) {
|
||||
this.waitForResponse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._http.post('/api/auth/login', {
|
||||
user_login: this.username.value,
|
||||
password: this.password.value,
|
||||
remember_me: this.rememberMe.value,
|
||||
}).subscribe({
|
||||
next: async (response: any) => {
|
||||
this._auth.update(true)
|
||||
.subscribe(async () => await this._redirect.redirect(null));
|
||||
},
|
||||
error: (err) => this.handleLoginErrors(err),
|
||||
complete: () => this.waitForResponse = false
|
||||
});
|
||||
}
|
||||
|
||||
handleLoginErrors(err: any) {
|
||||
if (err.status == 400 || err.status == 401) {
|
||||
this.errorMessage = 'Invalid credentials.';
|
||||
} else if (err.status == 403) {
|
||||
this.errorMessage = 'Something went wrong.';
|
||||
} else {
|
||||
this.errorMessage = 'Something went wrong: ' + err.error.statusCode + ' ' + err.error.message;
|
||||
}
|
||||
this.waitForResponse = false;
|
||||
}
|
||||
|
||||
async register(event: any) {
|
||||
event.preventDefault();
|
||||
await this._router.navigate(['register']);
|
||||
}
|
||||
}
|
10
frontend/angular-seshat/src/app/login/login.module.ts
Normal file
10
frontend/angular-seshat/src/app/login/login.module.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
],
|
||||
providers: []
|
||||
})
|
||||
export class LoginModule { }
|
@ -0,0 +1,101 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form {
|
||||
width: 500px;
|
||||
height: 100%;
|
||||
border: black solid 2px;
|
||||
border-radius: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
h1 {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.messages {
|
||||
width: 100%;
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
input {
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
margin: 20px;
|
||||
padding: 5px;
|
||||
border: gray solid 1px;
|
||||
border-radius: 15px;
|
||||
background-color: white;
|
||||
display: block;
|
||||
width: 400px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.input-wrapper:focus {
|
||||
outline: 5px solid blue;
|
||||
}
|
||||
|
||||
.actions {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
width: calc(100% - 30px);
|
||||
height: 50px;
|
||||
margin: 10px auto;
|
||||
border: 1px gray solid;
|
||||
border-radius: 15px;
|
||||
display: block;
|
||||
background-color: white;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #FAFAFA;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: white;
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
.register-link {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.register-link a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.register-link a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.center {
|
||||
font-size: 16;
|
||||
text-align: center;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
@if (config.features.registration) {
|
||||
<div class="form">
|
||||
<h1>Register</h1>
|
||||
<div class="messages">
|
||||
<notice [message]="errorMessage"
|
||||
[level]="'error'"
|
||||
[visible]="errorMessage.length > 0" />
|
||||
</div>
|
||||
<div class="fields">
|
||||
<div class="input-wrapper">
|
||||
<input type="text"
|
||||
placeholder="Name"
|
||||
[formControl]="name" />
|
||||
</div>
|
||||
<div class="input-wrapper">
|
||||
<input type="text"
|
||||
placeholder="Username"
|
||||
[formControl]="username" />
|
||||
</div>
|
||||
<div class="input-wrapper">
|
||||
<input type="password"
|
||||
placeholder="Password"
|
||||
[formControl]="password" />
|
||||
</div>
|
||||
<div class="input-wrapper">
|
||||
<input type="password"
|
||||
placeholder="Password Confirm"
|
||||
[formControl]="passwordConfirmation" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button type="submit"
|
||||
(click)="register()"
|
||||
[disabled]="!forms.valid || waitForResponse">Register</button>
|
||||
</div>
|
||||
<div class="register-link">
|
||||
Already have an account?
|
||||
<a href="/login"
|
||||
(click)="login($event)">Login here.</a>
|
||||
</div>
|
||||
</div>
|
||||
} @else {
|
||||
<p class="center disabled">Registrations have been disabled.</p>
|
||||
<p class="center">You will be redirected to login in 3 seconds.</p>
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RegisterFormComponent } from './register-form.component';
|
||||
|
||||
describe('RegisterFormComponent', () => {
|
||||
let component: RegisterFormComponent;
|
||||
let fixture: ComponentFixture<RegisterFormComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [RegisterFormComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(RegisterFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,92 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { NoticeComponent } from "../../shared/notice/notice.component";
|
||||
import { Router } from '@angular/router';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { AuthService } from '../../services/auth/auth.service';
|
||||
import { LoadingService } from '../../services/loading.service';
|
||||
import { RedirectionService } from '../../services/redirection.service';
|
||||
|
||||
@Component({
|
||||
selector: 'register-form',
|
||||
standalone: true,
|
||||
imports: [
|
||||
NoticeComponent,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
templateUrl: './register-form.component.html',
|
||||
styleUrl: './register-form.component.css'
|
||||
})
|
||||
export class RegisterFormComponent implements OnInit {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _loading = inject(LoadingService);
|
||||
private readonly _http = inject(HttpClient);
|
||||
private readonly _redirect = inject(RedirectionService);
|
||||
private readonly _router = inject(Router);
|
||||
readonly config = inject(ConfigService).config;
|
||||
|
||||
readonly name = new FormControl('', [Validators.required]);
|
||||
readonly username = new FormControl('', [Validators.required]);
|
||||
readonly password = new FormControl('', [Validators.required]);
|
||||
readonly passwordConfirmation = new FormControl('', [Validators.required]);
|
||||
readonly forms = new FormGroup({
|
||||
name: this.name,
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
passwordConfirmation: this.passwordConfirmation
|
||||
});
|
||||
|
||||
waitForResponse: boolean = false;
|
||||
errorMessage: string = '';
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
register() {
|
||||
if (this.waitForResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.waitForResponse = true;
|
||||
this.errorMessage = '';
|
||||
if (!this.forms.valid) {
|
||||
this.waitForResponse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.password.value != this.passwordConfirmation.value) {
|
||||
this.errorMessage = 'Password confirmation does not match original password.';
|
||||
return;
|
||||
}
|
||||
|
||||
this._http.post('/api/auth/register', {
|
||||
user_login: this.name.value,
|
||||
user_name: this.username.value,
|
||||
password: this.password.value,
|
||||
}).subscribe({
|
||||
next: async (response: any) => {
|
||||
this._auth.update(true)
|
||||
.subscribe(async () => await this._redirect.redirect(null));
|
||||
},
|
||||
error: (err) => this.handleRegistrationErrors(err),
|
||||
complete: () => this.waitForResponse = false
|
||||
});
|
||||
}
|
||||
|
||||
handleRegistrationErrors(err: any) {
|
||||
if (err.status == 401) {
|
||||
this.errorMessage = 'Invalid credentials.';
|
||||
} else if (err.status == 400 || err.status == 403) {
|
||||
this.errorMessage = 'Something went wrong.';
|
||||
} else {
|
||||
this.errorMessage = 'Something went wrong: ' + err.error.statusCode + ' ' + err.error.message;
|
||||
}
|
||||
this.waitForResponse = false;
|
||||
}
|
||||
|
||||
async login(event: any) {
|
||||
event.preventDefault();
|
||||
await this._router.navigate(['login']);
|
||||
}
|
||||
}
|
12
frontend/angular-seshat/src/app/register/register.module.ts
Normal file
12
frontend/angular-seshat/src/app/register/register.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule
|
||||
]
|
||||
})
|
||||
export class RegisterModule { }
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AuthService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,70 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private readonly _http = inject(HttpClient);
|
||||
|
||||
private authenticated = false;
|
||||
private userId: string | null = null;
|
||||
private username: string | null = null;
|
||||
private lastValidationCheck: number = 0;
|
||||
|
||||
|
||||
getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
isLoggedIn() {
|
||||
return this.authenticated;
|
||||
}
|
||||
|
||||
renew() {
|
||||
return this._http.patch('/api/auth/login', {});
|
||||
}
|
||||
|
||||
update(force: boolean = false) {
|
||||
if (!force && this.lastValidationCheck && this.lastValidationCheck + 90000 < Date.now()) {
|
||||
return of(this.authenticated);
|
||||
}
|
||||
|
||||
this.lastValidationCheck = Date.now();
|
||||
const observable = this._http.post('/api/auth/validate', {})
|
||||
observable.subscribe({
|
||||
next: (response: any) => {
|
||||
if (response.validation === null) {
|
||||
this.renew().subscribe({
|
||||
next: (res: any) => {
|
||||
this.authenticated = true;
|
||||
this.userId = res.userId;
|
||||
this.username = res.username;
|
||||
},
|
||||
error: (err) => {
|
||||
this.authenticated = false;
|
||||
this.userId = null;
|
||||
this.username = null;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.authenticated = response.validation;
|
||||
this.userId = response.userId;
|
||||
this.username = response.username;
|
||||
},
|
||||
error: (err) => {
|
||||
this.authenticated = false;
|
||||
this.userId = null;
|
||||
this.username = null;
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ConfigService } from './config.service';
|
||||
|
||||
describe('ConfigService', () => {
|
||||
let service: ConfigService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ConfigService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
36
frontend/angular-seshat/src/app/services/config.service.ts
Normal file
36
frontend/angular-seshat/src/app/services/config.service.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { AppConfig } from '../shared/dto/config.dto';
|
||||
import { map, Observable, of } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ConfigService {
|
||||
private readonly _http = inject(HttpClient);
|
||||
|
||||
config: AppConfig = new AppConfig();
|
||||
loaded = false;
|
||||
|
||||
constructor() { }
|
||||
|
||||
fetch(): Observable<any> {
|
||||
if (this.loaded) {
|
||||
return of(this.config);
|
||||
}
|
||||
|
||||
const $ = this._http.get('/api/asset/config').pipe(map((response: any) => response.config));
|
||||
$.subscribe({
|
||||
next: (config: any) => {
|
||||
if (!config) {
|
||||
console.log('Something went wrong with fetching app configuration. Using defaults.');
|
||||
return;
|
||||
}
|
||||
this.config = config;
|
||||
this.loaded = true;
|
||||
},
|
||||
error: (err) => { this.loaded = true; console.log('Something went wrong with fetching app configuration. Using defaults.', err); }
|
||||
});
|
||||
return $;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LoadingService } from './loading.service';
|
||||
|
||||
describe('LoadingService', () => {
|
||||
let service: LoadingService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(LoadingService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
47
frontend/angular-seshat/src/app/services/loading.service.ts
Normal file
47
frontend/angular-seshat/src/app/services/loading.service.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, delay, filter, first } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LoadingService {
|
||||
private readonly _subject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
private readonly _status = this._subject.asObservable().pipe(delay(0));
|
||||
private readonly _set: Set<string> = new Set<string>();
|
||||
|
||||
|
||||
listen() {
|
||||
return this._status;
|
||||
}
|
||||
|
||||
listenUntilReady() {
|
||||
return this._status.pipe(
|
||||
filter(status => !status),
|
||||
first(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the subject based on the following:
|
||||
* - If loading is true, add url to the set & update subject value to true.
|
||||
* - If loading is false, remove url entry and update subject to false if set is empty.
|
||||
* This supports multiple requests awaiting completion.
|
||||
*
|
||||
* @param loading {boolean}
|
||||
* @param url {string}
|
||||
*/
|
||||
set(loading: boolean, url: string): void {
|
||||
if (!url) {
|
||||
throw new Error('URL must be provided.');
|
||||
}
|
||||
if (loading) {
|
||||
this._set.add(url);
|
||||
this._subject.next(true);
|
||||
} else if (this._set.has(url)) {
|
||||
this._set.delete(url);
|
||||
if (this._set.size === 0) {
|
||||
this._subject.next(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RedirectionService } from './redirection.service';
|
||||
|
||||
describe('RedirectionService', () => {
|
||||
let service: RedirectionService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RedirectionService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,55 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RedirectionService {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _router = inject(Router);
|
||||
|
||||
constructor() { }
|
||||
|
||||
async redirect(destination: string | string[] | null) {
|
||||
let uri = this._router.url;
|
||||
if (!this._router.url.startsWith('/') && !this._router.url.startsWith('http')) {
|
||||
uri = '/' + this._router.url;
|
||||
}
|
||||
|
||||
if (await this.handleSpecialCases(uri)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const queryParams = this._router.parseUrl(uri).queryParams;
|
||||
const redirect = queryParams['rd'];
|
||||
if (redirect) {
|
||||
if (!(await this.handleSpecialCases(redirect))) {
|
||||
await this._router.navigateByUrl(redirect);
|
||||
}
|
||||
} else if (typeof destination === 'string') {
|
||||
await this._router.navigateByUrl(destination);
|
||||
} else if (destination !== null) {
|
||||
await this._router.navigate(destination);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleSpecialCases(uri: string): Promise<boolean> {
|
||||
if (this._auth.isLoggedIn()) {
|
||||
if (uri.startsWith('/login') || uri.startsWith('/register')) {
|
||||
await this._router.navigate(['add', 'new']);
|
||||
return true;
|
||||
}
|
||||
} else if (!uri.startsWith('/login') && !uri.startsWith('/register')) {
|
||||
await this._router.navigate(['login'],
|
||||
{
|
||||
queryParams: {
|
||||
rd: uri,
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
export class BookSearchResultDto {
|
||||
providerBookId: string = '';
|
||||
providerSeriesId: string = '';
|
||||
title: string = '';
|
||||
desc: string = '';
|
||||
volume: number|null = null;
|
||||
publisher: string = '';
|
||||
authors: string[] = [];
|
||||
industryIdentifiers: { [key: string]: string } = {};
|
||||
provider: string = '';
|
||||
publishedAt: string = '';
|
||||
language: string = '';
|
||||
mediaType: string | null = null;
|
||||
categories: string[] = [];
|
||||
maturityRating: string = '';
|
||||
thumbnail: string = '';
|
||||
url: string = '';
|
||||
}
|
35
frontend/angular-seshat/src/app/shared/dto/config.dto.ts
Normal file
35
frontend/angular-seshat/src/app/shared/dto/config.dto.ts
Normal file
@ -0,0 +1,35 @@
|
||||
export class AppConfig {
|
||||
features = new FeaturesConfig();
|
||||
providers = new ProvidersConfig();
|
||||
}
|
||||
|
||||
class FeaturesConfig {
|
||||
registration: boolean = false;
|
||||
}
|
||||
|
||||
class ProvidersConfig {
|
||||
default: string = 'google';
|
||||
|
||||
google: GoogleProviderConfig = new GoogleProviderConfig();
|
||||
}
|
||||
|
||||
class GenericProviderConfig {
|
||||
name: string = '';
|
||||
filters: { [key: string]: any } = {};
|
||||
}
|
||||
|
||||
class GoogleProviderConfig extends GenericProviderConfig {
|
||||
override name: string = 'Google';
|
||||
|
||||
// Key represents the language's ISO-639-1 code.
|
||||
// Value is the name of the language.
|
||||
languages: { [key: string]: any } = {
|
||||
'zh': 'Chinese',
|
||||
'nl': 'Dutch',
|
||||
'en': 'English',
|
||||
'fr': 'Francais',
|
||||
'ko': 'Korean',
|
||||
'ja': 'Japanese',
|
||||
'es': 'Spanish',
|
||||
};
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export class SearchContextDto {
|
||||
values: { [key: string]: string } = {};
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
import { HTTP_INTERCEPTORS, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from "@angular/common/http";
|
||||
import { inject, Injectable } from "@angular/core";
|
||||
import { catchError, map, Observable } from "rxjs";
|
||||
import { LoadingService } from "../../services/loading.service";
|
||||
|
||||
@Injectable()
|
||||
class LoadingHttpInterceptor implements HttpInterceptor {
|
||||
private readonly _loading = inject(LoadingService);
|
||||
private readonly _filters = [
|
||||
{
|
||||
url: '/api/auth/validate',
|
||||
methods: null,
|
||||
},
|
||||
{
|
||||
url: '/api/asset/config',
|
||||
methods: null,
|
||||
},
|
||||
{
|
||||
url: '/api/auth/login',
|
||||
methods: ['PATCH'],
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
let uri = request.url;
|
||||
if (!request.url.startsWith('/') && !request.url.startsWith('http')) {
|
||||
uri = '/' + request.url;
|
||||
}
|
||||
|
||||
const method = request.method.toUpperCase();
|
||||
if (!this._filters.some(item => uri.startsWith(item.url) && (!item.methods || item.methods.includes(method)))) {
|
||||
return next.handle(request);
|
||||
}
|
||||
|
||||
this._loading.set(true, request.url);
|
||||
return next.handle(request)
|
||||
.pipe(
|
||||
catchError((err) => {
|
||||
this._loading.set(false, request.url);
|
||||
return err;
|
||||
}),
|
||||
map((evt: any) => {
|
||||
if (evt instanceof HttpResponse) {
|
||||
this._loading.set(false, request.url);
|
||||
}
|
||||
return evt;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const LoadingInterceptor = [
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: LoadingHttpInterceptor,
|
||||
multi: true,
|
||||
}
|
||||
];
|
@ -0,0 +1,86 @@
|
||||
import { HTTP_INTERCEPTORS, HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http";
|
||||
import { inject, Injectable } from "@angular/core";
|
||||
import { BehaviorSubject, catchError, filter, Observable, switchMap, take, throwError } from "rxjs";
|
||||
import { AuthService } from "../../services/auth/auth.service";
|
||||
|
||||
@Injectable()
|
||||
class TokenValidationHttpInterceptor implements HttpInterceptor {
|
||||
private readonly _auth = inject(AuthService);
|
||||
private readonly _filters: { url: string, methods: string[] | null }[] = [
|
||||
{
|
||||
url: '/api/auth/validate',
|
||||
methods: null,
|
||||
},
|
||||
{
|
||||
url: '/api/asset/config',
|
||||
methods: null,
|
||||
},
|
||||
{
|
||||
url: '/api/auth/login',
|
||||
methods: null,
|
||||
},
|
||||
{
|
||||
url: '/api/auth/register',
|
||||
methods: null,
|
||||
},
|
||||
];
|
||||
|
||||
private _isRefreshing = false;
|
||||
private _refreshSubject = new BehaviorSubject<boolean>(false);
|
||||
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
let uri = request.url;
|
||||
if (!request.url.startsWith('/') && !request.url.startsWith('http')) {
|
||||
uri = '/' + request.url;
|
||||
}
|
||||
|
||||
const method = request.method.toUpperCase();
|
||||
if (this._filters.some(item => uri.startsWith(item.url) && (!item.methods || item.methods.includes(method)))) {
|
||||
return next.handle(request);
|
||||
}
|
||||
|
||||
return next.handle(request)
|
||||
.pipe(
|
||||
catchError((err) => {
|
||||
if (err instanceof HttpErrorResponse && err.status == 401) {
|
||||
return this.handleTokenRenewal(request, next);
|
||||
}
|
||||
return throwError(() => err);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private handleTokenRenewal(request: HttpRequest<any>, next: HttpHandler) {
|
||||
if (!this._isRefreshing) {
|
||||
this._isRefreshing = true;
|
||||
this._refreshSubject.next(false);
|
||||
|
||||
return this._auth.renew()
|
||||
.pipe(
|
||||
take(1),
|
||||
switchMap((token: any) => {
|
||||
this._isRefreshing = false;
|
||||
this._refreshSubject.next(true);
|
||||
return next.handle(request.clone())
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return this._refreshSubject.pipe(
|
||||
filter(token => token != null),
|
||||
take(1),
|
||||
switchMap(_ => {
|
||||
return next.handle(request.clone());
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const TokenValidationInterceptor = [
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: TokenValidationHttpInterceptor,
|
||||
multi: true,
|
||||
}
|
||||
];
|
@ -0,0 +1,18 @@
|
||||
.info {
|
||||
background-color: #ADD8E6;
|
||||
}
|
||||
|
||||
.warning {
|
||||
background-color: #FFD580;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color: #FF474C;
|
||||
}
|
||||
|
||||
p {
|
||||
width: 80%;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 10px auto;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
@if (this.visible()) {
|
||||
<p [class.info]="level() == 'info'"
|
||||
[class.warning]="level() == 'warning'"
|
||||
[class.error]="level() == 'error'">{{this.message()}}</p>
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NoticeComponent } from './notice.component';
|
||||
|
||||
describe('NoticeComponent', () => {
|
||||
let component: NoticeComponent;
|
||||
let fixture: ComponentFixture<NoticeComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [NoticeComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(NoticeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
import { Component, input } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'notice',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './notice.component.html',
|
||||
styleUrl: './notice.component.css'
|
||||
})
|
||||
export class NoticeComponent {
|
||||
message = input<string>('');
|
||||
level = input<'info' | 'warning' | 'error'>('info');
|
||||
visible = input<boolean>(this.message.length > 0);
|
||||
}
|
13
frontend/angular-seshat/src/index.html
Normal file
13
frontend/angular-seshat/src/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Seshat</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
7
frontend/angular-seshat/src/main.server.ts
Normal file
7
frontend/angular-seshat/src/main.server.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { config } from './app/app.config.server';
|
||||
|
||||
const bootstrap = () => bootstrapApplication(AppComponent, config);
|
||||
|
||||
export default bootstrap;
|
6
frontend/angular-seshat/src/main.ts
Normal file
6
frontend/angular-seshat/src/main.ts
Normal file
@ -0,0 +1,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));
|
8
frontend/angular-seshat/src/proxy.conf.json
Normal file
8
frontend/angular-seshat/src/proxy.conf.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"/api/**": {
|
||||
"target": "http://192.168.2.63:3001",
|
||||
"protocol": "http",
|
||||
"secure": false,
|
||||
"changeOrigin": true
|
||||
}
|
||||
}
|
5
frontend/angular-seshat/src/styles.css
Normal file
5
frontend/angular-seshat/src/styles.css
Normal file
@ -0,0 +1,5 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
19
frontend/angular-seshat/tsconfig.app.json
Normal file
19
frontend/angular-seshat/tsconfig.app.json
Normal file
@ -0,0 +1,19 @@
|
||||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts",
|
||||
"src/main.server.ts",
|
||||
"server.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
38
frontend/angular-seshat/tsconfig.json
Normal file
38
frontend/angular-seshat/tsconfig.json
Normal file
@ -0,0 +1,38 @@
|
||||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/out-tsc",
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"paths": {
|
||||
"library": [
|
||||
"./dist/library"
|
||||
]
|
||||
},
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "bundler",
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"useDefineForClassFields": false,
|
||||
"lib": [
|
||||
"ES2022",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
15
frontend/angular-seshat/tsconfig.spec.json
Normal file
15
frontend/angular-seshat/tsconfig.spec.json
Normal file
@ -0,0 +1,15 @@
|
||||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
||||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user