Compare commits
3 Commits
a2de24fd93
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f33b55b1c8 | |||
| e2fd4fb29a | |||
| 0cce8b2982 |
@@ -1,4 +1,4 @@
|
|||||||
FROM node:24-alpine AS builder
|
FROM node:25-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY frontend /app
|
COPY frontend /app
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"fr": {
|
"fr": {
|
||||||
"translation": "src/locale/messages-fr.json"
|
"translation": "src/locale/messages-fr.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"architect": {
|
"architect": {
|
||||||
@@ -30,7 +30,6 @@
|
|||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"browser": "src/main.ts",
|
"browser": "src/main.ts",
|
||||||
"polyfills": [
|
"polyfills": [
|
||||||
"zone.js",
|
|
||||||
"@angular/localize/init"
|
"@angular/localize/init"
|
||||||
],
|
],
|
||||||
"tsConfig": "tsconfig.app.json",
|
"tsConfig": "tsconfig.app.json",
|
||||||
@@ -133,8 +132,6 @@
|
|||||||
"builder": "@angular/build:karma",
|
"builder": "@angular/build:karma",
|
||||||
"options": {
|
"options": {
|
||||||
"polyfills": [
|
"polyfills": [
|
||||||
"zone.js",
|
|
||||||
"zone.js/testing"
|
|
||||||
],
|
],
|
||||||
"tsConfig": "tsconfig.spec.json",
|
"tsConfig": "tsconfig.spec.json",
|
||||||
"inlineStyleLanguage": "scss",
|
"inlineStyleLanguage": "scss",
|
||||||
|
|||||||
4149
frontend/package-lock.json
generated
4149
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -17,32 +17,26 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "^21.0.6",
|
"@angular/animations": "^21.1.2",
|
||||||
"@angular/cdk": "^21.0.5",
|
"@angular/cdk": "^21.1.2",
|
||||||
"@angular/common": "^21.0.6",
|
"@angular/common": "^21.1.2",
|
||||||
"@angular/compiler": "^21.0.6",
|
"@angular/compiler": "^21.1.2",
|
||||||
"@angular/core": "^21.0.6",
|
"@angular/core": "^21.1.2",
|
||||||
"@angular/forms": "^21.0.6",
|
"@angular/forms": "^21.1.2",
|
||||||
"@angular/material": "^21.0.5",
|
"@angular/material": "^21.1.2",
|
||||||
"@angular/platform-browser": "^21.0.6",
|
"@angular/platform-browser": "^21.1.2",
|
||||||
"@angular/platform-browser-dynamic": "^21.0.6",
|
"@angular/platform-browser-dynamic": "^21.1.2",
|
||||||
"@angular/router": "^21.0.6",
|
"@angular/router": "^21.1.2",
|
||||||
"rxjs": "~7.8.0",
|
"rxjs": "~7.8.2",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.8.1"
|
||||||
"zone.js": "~0.15.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular/build": "^21.0.4",
|
"@angular/build": "^21.1.2",
|
||||||
"@angular/cli": "^21.0.4",
|
"@angular/cli": "^21.1.2",
|
||||||
"@angular/compiler-cli": "^21.0.6",
|
"@angular/compiler-cli": "^21.1.2",
|
||||||
"@angular/localize": "^21.0.6",
|
"@angular/localize": "^21.1.2",
|
||||||
"@types/jasmine": "~5.1.0",
|
"@types/jasmine": "~5.1.15",
|
||||||
"jasmine-core": "~5.1.0",
|
"jasmine-core": "~5.13.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",
|
|
||||||
"typescript": "~5.9.3"
|
"typescript": "~5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
<main>
|
<main>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</main>
|
</main>
|
||||||
<app-footer></app-footer>
|
<app-footer></app-footer>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
app-header {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
padding: 1em 0;
|
||||||
app-header {
|
}
|
||||||
width: 100%;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
flex: 1;
|
|
||||||
padding: 1em 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import { AppComponent } from './app.component';
|
import {AppComponent} from './app.component';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
|
import {Component} from '@angular/core';
|
||||||
import { Component } from '@angular/core';
|
import {RouterOutlet} from '@angular/router';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import {HeaderComponent} from './components/header/header.component';
|
||||||
import { HeaderComponent } from './components/header/header.component';
|
import {FooterComponent} from './components/footer/footer.component';
|
||||||
import { FooterComponent } from './components/footer/footer.component';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
imports: [
|
imports: [
|
||||||
RouterOutlet,
|
RouterOutlet,
|
||||||
HeaderComponent,
|
HeaderComponent,
|
||||||
FooterComponent
|
FooterComponent
|
||||||
],
|
],
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrl: './app.component.scss'
|
styleUrl: './app.component.scss'
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
title = 'codiki-ng';
|
title = 'codiki-ng';
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
import {ApplicationConfig, inject, provideAppInitializer} from '@angular/core';
|
||||||
import { provideRouter, withRouterConfig } from '@angular/router';
|
import {provideRouter, withRouterConfig} from '@angular/router';
|
||||||
|
|
||||||
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
|
import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from '@angular/common/http';
|
||||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
import {provideAnimationsAsync} from '@angular/platform-browser/animations/async';
|
||||||
import { routes } from './app.routes';
|
import {routes} from './app.routes';
|
||||||
import { JwtInterceptor } from './core/interceptor/jwt.interceptor';
|
import {JwtInterceptor} from './core/interceptor/jwt.interceptor';
|
||||||
import { AuthenticationService } from './core/service/authentication.service';
|
import {AuthenticationService} from './core/service/authentication.service';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
@@ -15,13 +15,13 @@ export const appConfig: ApplicationConfig = {
|
|||||||
paramsInheritanceStrategy: 'always',
|
paramsInheritanceStrategy: 'always',
|
||||||
onSameUrlNavigation: 'reload'
|
onSameUrlNavigation: 'reload'
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
provideAnimationsAsync(),
|
provideAnimationsAsync(),
|
||||||
provideHttpClient(withInterceptorsFromDi()),
|
provideHttpClient(withInterceptorsFromDi()),
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
|
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
|
||||||
provideAppInitializer(() => {
|
provideAppInitializer(() => {
|
||||||
const initializerFn = ((authenticationService: AuthenticationService) => () => authenticationService.startAuthenticationCheckingProcess())(inject(AuthenticationService));
|
const initializerFn = ((authenticationService: AuthenticationService) => () => authenticationService.startAuthenticationCheckingProcess())(inject(AuthenticationService));
|
||||||
return initializerFn();
|
return initializerFn();
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
import { Routes } from '@angular/router';
|
import {Routes} from '@angular/router';
|
||||||
import { alreadyAuthenticatedGuard } from './core/guard/already-authenticated.guard';
|
import {alreadyAuthenticatedGuard} from './core/guard/already-authenticated.guard';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: 'login',
|
||||||
loadComponent: () => import('./pages/login/login.component').then(module => module.LoginComponent),
|
loadComponent: () => import('./pages/login/login.component').then(module => module.LoginComponent),
|
||||||
canActivate: [alreadyAuthenticatedGuard]
|
canActivate: [alreadyAuthenticatedGuard]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'signin',
|
path: 'signin',
|
||||||
loadComponent: () => import('./pages/signin/signin.component').then(module => module.SigninComponent),
|
loadComponent: () => import('./pages/signin/signin.component').then(module => module.SigninComponent),
|
||||||
canActivate: [alreadyAuthenticatedGuard]
|
canActivate: [alreadyAuthenticatedGuard]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'disconnect',
|
path: 'disconnect',
|
||||||
loadComponent: () => import('./pages/disconnection/disconnection.component').then(module => module.DisconnectionComponent)
|
loadComponent: () => import('./pages/disconnection/disconnection.component').then(module => module.DisconnectionComponent)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'publications/new',
|
path: 'publications/new',
|
||||||
loadChildren: () => import('./pages/publication-creation/publication-creation.routes').then(module => module.ROUTES)
|
loadChildren: () => import('./pages/publication-creation/publication-creation.routes').then(module => module.ROUTES)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'publications/:publicationId',
|
path: 'publications/:publicationId',
|
||||||
loadComponent: () => import('./pages/publication/publication.component').then(module => module.PublicationComponent)
|
loadComponent: () => import('./pages/publication/publication.component').then(module => module.PublicationComponent)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'publications/:publicationId/edit',
|
path: 'publications/:publicationId/edit',
|
||||||
loadChildren: () => import('./pages/publication-update/publication-update.routes').then(module => module.ROUTES)
|
loadChildren: () => import('./pages/publication-update/publication-update.routes').then(module => module.ROUTES)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'publications',
|
path: 'publications',
|
||||||
loadComponent: () => import('./pages/search-publications/search-publications.component').then(module => module.SearchPublicationsComponent)
|
loadComponent: () => import('./pages/search-publications/search-publications.component').then(module => module.SearchPublicationsComponent)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'my-publications',
|
path: 'my-publications',
|
||||||
loadChildren: () => import('./pages/my-publications/my-publications.routes').then(module => module.ROUTES)
|
loadChildren: () => import('./pages/my-publications/my-publications.routes').then(module => module.ROUTES)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '**',
|
path: '**',
|
||||||
loadComponent: () => import('./pages/home/home.component').then(module => module.HomeComponent)
|
loadComponent: () => import('./pages/home/home.component').then(module => module.HomeComponent)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1>{{title}}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<h2>{{description}}</h2>
|
<h2>{{ description }}</h2>
|
||||||
<footer>
|
<footer>
|
||||||
<button type="button" class="cod-button secondary" (click)="closeDialog()" matRipple i18n>
|
<button type="button" class="cod-button secondary" (click)="closeDialog()" matRipple i18n>
|
||||||
No
|
No
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="cod-button" (click)="closeAndValidate()" matRipple i18n>
|
<button type="button" class="cod-button" (click)="closeAndValidate()" matRipple i18n>
|
||||||
Yes
|
Yes
|
||||||
</button>
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
import { Component, inject, Input } from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
|
|
||||||
export interface ConfirmationDialogData {
|
export interface ConfirmationDialogData {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-confirmation-dialog',
|
selector: 'app-confirmation-dialog',
|
||||||
templateUrl: './confirmation-dialog.component.html',
|
templateUrl: './confirmation-dialog.component.html',
|
||||||
styleUrl: './confirmation-dialog.component.scss',
|
styleUrl: './confirmation-dialog.component.scss',
|
||||||
imports: [MatRippleModule]
|
imports: [MatRippleModule]
|
||||||
})
|
})
|
||||||
export class ConfirmationDialog {
|
export class ConfirmationDialog {
|
||||||
private readonly dialogRef = inject(MatDialogRef<ConfirmationDialog>);
|
private readonly dialogRef = inject(MatDialogRef<ConfirmationDialog>);
|
||||||
data: ConfirmationDialogData = inject(MAT_DIALOG_DATA);
|
data: ConfirmationDialogData = inject(MAT_DIALOG_DATA);
|
||||||
|
|
||||||
get title(): string {
|
get title(): string {
|
||||||
return this.data.title;
|
return this.data.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
get description(): string {
|
get description(): string {
|
||||||
return this.data.description;
|
return this.data.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeAndValidate(): void {
|
closeAndValidate(): void {
|
||||||
this.dialogRef.close(true);
|
this.dialogRef.close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDialog(): void {
|
closeDialog(): void {
|
||||||
this.dialogRef.close(false);
|
this.dialogRef.close(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<div i18n>
|
<div i18n>
|
||||||
<span class="copy-left">©</span>
|
<span class="copy-left">©</span>
|
||||||
2016 - 2024 All rights reserved
|
2016 - 2026 All rights reserved
|
||||||
-
|
-
|
||||||
2.1
|
2.2
|
||||||
<a [routerLink]="['./']" matTooltip="Health checking will be available in future..." i18n-matTooltip>
|
<a [routerLink]="['./']" matTooltip="Health checking will be available in future..." i18n-matTooltip>
|
||||||
<mat-icon>favorite</mat-icon>
|
<mat-icon>favorite</mat-icon>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<mat-icon matTooltip="Documentation will be available in future..." i18n-matTooltip>menu_book</mat-icon>
|
<mat-icon matTooltip="Documentation will be available in future..." i18n-matTooltip>menu_book</mat-icon>
|
||||||
-
|
-
|
||||||
<span i18n>Development realised by</span> Florian THIERRY
|
<span i18n>Development realised by</span> Florian THIERRY
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
:host {
|
:host {
|
||||||
background-color: #3f51b5;
|
background-color: #3f51b5;
|
||||||
color: rgba(255,255,255,.6);
|
color: rgba(255, 255, 255, .6);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-around;
|
||||||
|
align-items: center;
|
||||||
|
padding: .5em;
|
||||||
|
font-size: 1.1em;
|
||||||
|
|
||||||
|
div {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-around;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: .5em;
|
gap: .2em;
|
||||||
font-size: 1.1em;
|
|
||||||
|
|
||||||
div {
|
.copy-left {
|
||||||
display: flex;
|
transform: rotate(180deg);
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
.copy-left {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: rgba(255,255,255,.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
mat-icon {
|
|
||||||
font-size: 1em;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: rgba(255, 255, 255, .6);
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-icon {
|
||||||
|
font-size: 1em;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import { RouterModule } from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-footer',
|
selector: 'app-footer',
|
||||||
imports: [MatIconModule, MatTooltipModule, RouterModule],
|
imports: [MatIconModule, MatTooltipModule, RouterModule],
|
||||||
templateUrl: './footer.component.html',
|
templateUrl: './footer.component.html',
|
||||||
styleUrl: './footer.component.scss'
|
styleUrl: './footer.component.scss'
|
||||||
})
|
})
|
||||||
export class FooterComponent {
|
export class FooterComponent {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<button type="button"
|
<button type="button"
|
||||||
(click)="sideMenu.open()"
|
(click)="sideMenu.open()"
|
||||||
class="cod-button icon"
|
class="cod-button icon"
|
||||||
matTooltip="Click to show side menu"
|
matTooltip="Click to show side menu"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>menu</mat-icon>
|
<mat-icon>menu</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<a [routerLink]="['/home']">
|
<a [routerLink]="['/home']">
|
||||||
<img src="assets/images/codiki.png" alt="logo"/>
|
<img src="assets/images/codiki.png" alt="logo"/>
|
||||||
<span class="title">Codiki</span>
|
<span class="title">Codiki</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="middle">
|
<div class="middle">
|
||||||
<app-publications-search-bar></app-publications-search-bar>
|
<app-publications-search-bar></app-publications-search-bar>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="right">
|
<div class="right">
|
||||||
@if (isAuthenticated) {
|
@if (isAuthenticated) {
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="cod-button icon"
|
class="cod-button icon"
|
||||||
[matMenuTriggerFor]="authenticatedUserMenu"
|
[matMenuTriggerFor]="authenticatedUserMenu"
|
||||||
matRipple>
|
matRipple>
|
||||||
<mat-icon>more_vert</mat-icon>
|
<mat-icon>more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<mat-menu #authenticatedUserMenu="matMenu">
|
<mat-menu #authenticatedUserMenu="matMenu">
|
||||||
<div class="authenticated-user-menu">
|
<div class="authenticated-user-menu">
|
||||||
<a [routerLink]="['/my-publications']" matRipple i18n>
|
<a [routerLink]="['/my-publications']" matRipple i18n>
|
||||||
<mat-icon>description</mat-icon>
|
<mat-icon>description</mat-icon>
|
||||||
My publications
|
My publications
|
||||||
</a>
|
</a>
|
||||||
<a [routerLink]="['/disconnect']" matRipple class="disconnection" i18n>
|
<a [routerLink]="['/disconnect']" matRipple class="disconnection" i18n>
|
||||||
<mat-icon>logout</mat-icon>
|
<mat-icon>logout</mat-icon>
|
||||||
Disconnect
|
Disconnect
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
} @else {
|
} @else {
|
||||||
<a [routerLink]="['/login']" class="cod-button" matRipple i18n>Login</a>
|
<a [routerLink]="['/login']" class="cod-button" matRipple i18n>Login</a>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<app-side-menu #sideMenu></app-side-menu>
|
<app-side-menu #sideMenu></app-side-menu>
|
||||||
|
|||||||
@@ -1,148 +1,148 @@
|
|||||||
$headerHeight: 3.5em;
|
$headerHeight: 3.5em;
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
position: relative;
|
||||||
|
height: $headerHeight;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
|
||||||
|
div {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: center;
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
height: $headerHeight;
|
height: $headerHeight;
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
|
|
||||||
div {
|
&.left {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1em;
|
||||||
|
padding: 0 1em;
|
||||||
|
z-index: 2;
|
||||||
|
|
||||||
|
a {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
position: relative;
|
align-items: center;
|
||||||
height: $headerHeight;
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
gap: .5em;
|
||||||
|
|
||||||
&.left {
|
img {
|
||||||
position: absolute;
|
$imageSize: 2em;
|
||||||
top: 0;
|
width: $imageSize;
|
||||||
left: 0;
|
height: $imageSize;
|
||||||
align-items: center;
|
|
||||||
gap: 1em;
|
|
||||||
padding: 0 1em;
|
|
||||||
z-index: 2;
|
|
||||||
|
|
||||||
a {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
gap: .5em;
|
|
||||||
|
|
||||||
img {
|
|
||||||
$imageSize: 2em;
|
|
||||||
width: $imageSize;
|
|
||||||
height: $imageSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title {
|
|
||||||
font-size: 1.5em;
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
@media screen and (min-width: 600px) {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.middle {
|
.title {
|
||||||
flex: 1;
|
font-size: 1.5em;
|
||||||
$borderRadiusValue: 10em;
|
display: none;
|
||||||
position: relative;
|
|
||||||
transition: max-width .2s ease-in-out;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
z-index: 1;
|
|
||||||
|
|
||||||
app-publications-search-bar {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 12em;
|
|
||||||
|
|
||||||
@media screen and (min-width: 435px) {
|
@media screen and (min-width: 600px) {
|
||||||
max-width: 16em;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 500px) {
|
|
||||||
max-width: 20em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 700px) {
|
|
||||||
max-width: 24em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 800px) {
|
|
||||||
max-width: 32em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 900px) {
|
|
||||||
max-width: 38em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 1000px) {
|
|
||||||
max-width: 45em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 1100px) {
|
|
||||||
max-width: 50em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.right {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
z-index: 2;
|
|
||||||
margin-right: .5em;
|
|
||||||
|
|
||||||
a, button {
|
|
||||||
margin: .5em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.middle {
|
||||||
|
flex: 1;
|
||||||
|
$borderRadiusValue: 10em;
|
||||||
|
position: relative;
|
||||||
|
transition: max-width .2s ease-in-out;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
app-publications-search-bar {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 12em;
|
||||||
|
|
||||||
|
@media screen and (min-width: 435px) {
|
||||||
|
max-width: 16em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 500px) {
|
||||||
|
max-width: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 700px) {
|
||||||
|
max-width: 24em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 800px) {
|
||||||
|
max-width: 32em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 900px) {
|
||||||
|
max-width: 38em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1000px) {
|
||||||
|
max-width: 45em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 1100px) {
|
||||||
|
max-width: 50em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.right {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 2;
|
||||||
|
margin-right: .5em;
|
||||||
|
|
||||||
|
a, button {
|
||||||
|
margin: .5em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app-side-menu {
|
app-side-menu {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.authenticated-user-menu {
|
.authenticated-user-menu {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 0.2em 0;
|
||||||
|
|
||||||
|
a {
|
||||||
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
padding: 0.2em 0;
|
align-items: center;
|
||||||
|
text-decoration: none;
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
padding: 1em;
|
||||||
|
gap: .5em;
|
||||||
|
transition: background-color .2s ease-in-out, color .2s ease-in-out;
|
||||||
|
|
||||||
a {
|
&:hover {
|
||||||
flex: 1;
|
background-color: #5c6bc0;
|
||||||
display: flex;
|
color: white;
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
text-decoration: none;
|
|
||||||
background-color: white;
|
|
||||||
color: black;
|
|
||||||
padding: 1em;
|
|
||||||
gap: .5em;
|
|
||||||
transition: background-color .2s ease-in-out, color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.disconnection {
|
|
||||||
color: #D50000;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #E53935;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
&.disconnection {
|
||||||
|
color: #D50000;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #E53935;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
|
import {Component, inject} from '@angular/core';
|
||||||
import { Component, inject } from '@angular/core';
|
import {FormControl, ReactiveFormsModule} from '@angular/forms';
|
||||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
import {MatButtonModule} from '@angular/material/button';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
import { MatRippleModule } from '@angular/material/core';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatMenuModule} from '@angular/material/menu';
|
||||||
import { MatMenuModule } from '@angular/material/menu';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import {RouterModule} from '@angular/router';
|
||||||
import { RouterModule } from '@angular/router';
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
import { AuthenticationService } from '../../core/service/authentication.service';
|
import {PublicationsSearchBarComponent} from '../publications-search-bar/publications-search-bar.component';
|
||||||
import { PublicationsSearchBarComponent } from '../publications-search-bar/publications-search-bar.component';
|
import {SideMenuComponent} from '../side-menu/side-menu.component';
|
||||||
import { SideMenuComponent } from '../side-menu/side-menu.component';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-header',
|
selector: 'app-header',
|
||||||
imports: [
|
imports: [
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
@@ -23,9 +22,9 @@ import { SideMenuComponent } from '../side-menu/side-menu.component';
|
|||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
SideMenuComponent
|
SideMenuComponent
|
||||||
],
|
],
|
||||||
templateUrl: './header.component.html',
|
templateUrl: './header.component.html',
|
||||||
styleUrl: './header.component.scss'
|
styleUrl: './header.component.scss'
|
||||||
})
|
})
|
||||||
export class HeaderComponent {
|
export class HeaderComponent {
|
||||||
private authenticationService = inject(AuthenticationService);
|
private authenticationService = inject(AuthenticationService);
|
||||||
|
|||||||
@@ -4,34 +4,34 @@
|
|||||||
matTooltip="Close"
|
matTooltip="Close"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<header>
|
<header>
|
||||||
<h1 i18n>Add a code block</h1>
|
<h1 i18n>Add a code block</h1>
|
||||||
</header>
|
</header>
|
||||||
<form [formGroup]="formGroup" (submit)="closeAndValidate()" class="cod-form" ngNativeValidate>
|
<form [formGroup]="formGroup" (submit)="closeAndValidate()" class="cod-form" ngNativeValidate>
|
||||||
<div class="form-content">
|
<div class="form-content">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Programming language</mat-label>
|
<mat-label i18n>Programming language</mat-label>
|
||||||
<mat-select #programmingLanguageSelect formControlName="programmingLanguage">
|
<mat-select #programmingLanguageSelect formControlName="programmingLanguage">
|
||||||
@for(programmingLanguage of programmingLanguages; track programmingLanguage) {
|
@for (programmingLanguage of programmingLanguages; track programmingLanguage) {
|
||||||
<mat-option [value]="programmingLanguage.code">
|
<mat-option [value]="programmingLanguage.code">
|
||||||
{{programmingLanguage.label}}
|
{{ programmingLanguage.label }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
}
|
}
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Code block</mat-label>
|
<mat-label i18n>Code block</mat-label>
|
||||||
<textarea matInput formControlName="codeBlock"></textarea>
|
<textarea matInput formControlName="codeBlock"></textarea>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions reversed">
|
<div class="actions reversed">
|
||||||
<button type="submit" class="cod-button" matRipple i18n>
|
<button type="submit" class="cod-button" matRipple i18n>
|
||||||
Validate
|
Validate
|
||||||
</button>
|
</button>
|
||||||
<button type="button" (click)="closeDialog()" class="cod-button secondary" matRipple i18n>
|
<button type="button" (click)="closeDialog()" class="cod-button secondary" matRipple i18n>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
:host {
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1em;
|
||||||
|
gap: 1em;
|
||||||
|
position: relative;
|
||||||
|
max-height: 90vh;
|
||||||
|
|
||||||
|
header {
|
||||||
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
padding: 1em;
|
justify-content: center;
|
||||||
gap: 1em;
|
align-items: center;
|
||||||
position: relative;
|
}
|
||||||
max-height: 90vh;
|
|
||||||
|
|
||||||
header {
|
form {
|
||||||
flex: 1;
|
div {
|
||||||
display: flex;
|
&.form-content {
|
||||||
flex-direction: row;
|
mat-form-field {
|
||||||
justify-content: center;
|
width: 100%;
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
form {
|
textarea {
|
||||||
div {
|
height: 30vh;
|
||||||
&.form-content {
|
}
|
||||||
mat-form-field {
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
textarea {
|
|
||||||
height: 30vh;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,119 +1,119 @@
|
|||||||
import { Component, inject } from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
|
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MatDialogRef } from "@angular/material/dialog";
|
import {MatDialogRef} from "@angular/material/dialog";
|
||||||
import { MatFormFieldModule } from "@angular/material/form-field";
|
import {MatFormFieldModule} from "@angular/material/form-field";
|
||||||
import { MatIcon } from "@angular/material/icon";
|
import {MatIcon} from "@angular/material/icon";
|
||||||
import { MatInputModule } from "@angular/material/input";
|
import {MatInputModule} from "@angular/material/input";
|
||||||
import { MatSelectModule } from '@angular/material/select';
|
import {MatSelectModule} from '@angular/material/select';
|
||||||
import { MatTooltip } from "@angular/material/tooltip";
|
import {MatTooltip} from "@angular/material/tooltip";
|
||||||
|
|
||||||
export interface ProgramingLanguage {
|
export interface ProgramingLanguage {
|
||||||
code: string;
|
code: string;
|
||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PROGRAMMING_LANGUAGES: ProgramingLanguage[] = [
|
export const PROGRAMMING_LANGUAGES: ProgramingLanguage[] = [
|
||||||
{
|
{
|
||||||
code: 'bash',
|
code: 'bash',
|
||||||
label: 'Bash'
|
label: 'Bash'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'c',
|
code: 'c',
|
||||||
label: 'C'
|
label: 'C'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'cpp',
|
code: 'cpp',
|
||||||
label: 'C++'
|
label: 'C++'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'cs',
|
code: 'cs',
|
||||||
label: 'C#'
|
label: 'C#'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'lua',
|
code: 'lua',
|
||||||
label: 'Lua'
|
label: 'Lua'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'java',
|
code: 'java',
|
||||||
label: 'Java'
|
label: 'Java'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'json5',
|
code: 'json5',
|
||||||
label: 'JSON'
|
label: 'JSON'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'kt',
|
code: 'kt',
|
||||||
label: 'Kotlin'
|
label: 'Kotlin'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'markup',
|
code: 'markup',
|
||||||
label: 'html/xml'
|
label: 'html/xml'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'php',
|
code: 'php',
|
||||||
label: 'PHP'
|
label: 'PHP'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'plsql',
|
code: 'plsql',
|
||||||
label: 'PL/SQL'
|
label: 'PL/SQL'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'python',
|
code: 'python',
|
||||||
label: 'Python'
|
label: 'Python'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'powershell',
|
code: 'powershell',
|
||||||
label: 'PowerShell'
|
label: 'PowerShell'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'rust',
|
code: 'rust',
|
||||||
label: 'Rust'
|
label: 'Rust'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'sql',
|
code: 'sql',
|
||||||
label: 'SQL'
|
label: 'SQL'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'ts',
|
code: 'ts',
|
||||||
label: 'Typescript'
|
label: 'Typescript'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: 'yml',
|
code: 'yml',
|
||||||
label: 'YAML'
|
label: 'YAML'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-code-block-dialog',
|
selector: 'app-code-block-dialog',
|
||||||
templateUrl: './code-block-dialog.component.html',
|
templateUrl: './code-block-dialog.component.html',
|
||||||
styleUrl: './code-block-dialog.component.scss',
|
styleUrl: './code-block-dialog.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
MatIcon,
|
MatIcon,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
MatTooltip,
|
MatTooltip,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class CodeBlockDialog {
|
export class CodeBlockDialog {
|
||||||
private readonly dialogRef = inject(MatDialogRef<CodeBlockDialog>);
|
private readonly dialogRef = inject(MatDialogRef<CodeBlockDialog>);
|
||||||
private formBuilder = inject(FormBuilder);
|
private formBuilder = inject(FormBuilder);
|
||||||
programmingLanguages = PROGRAMMING_LANGUAGES;
|
programmingLanguages = PROGRAMMING_LANGUAGES;
|
||||||
formGroup = this.formBuilder.group({
|
formGroup = this.formBuilder.group({
|
||||||
programmingLanguage: new FormControl('', Validators.required),
|
programmingLanguage: new FormControl('', Validators.required),
|
||||||
codeBlock: new FormControl('', Validators.required)
|
codeBlock: new FormControl('', Validators.required)
|
||||||
});
|
});
|
||||||
|
|
||||||
closeAndValidate(): void {
|
closeAndValidate(): void {
|
||||||
if (this.formGroup.valid) {
|
if (this.formGroup.valid) {
|
||||||
this.dialogRef.close(this.formGroup.value);
|
this.dialogRef.close(this.formGroup.value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
closeDialog(): void {
|
closeDialog(): void {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,40 +4,41 @@
|
|||||||
matTooltip="Close"
|
matTooltip="Close"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<header>
|
<header>
|
||||||
<h1 i18n>Select an illustration</h1>
|
<h1 i18n>Select an illustration</h1>
|
||||||
</header>
|
</header>
|
||||||
<div class="picture-container">
|
<div class="picture-container">
|
||||||
@if (isLoading) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Pictures loading...</h2>
|
<h2 i18n>Pictures loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
|
} @else {
|
||||||
|
@if (pictures.length) {
|
||||||
|
@for (picture of pictures; track picture) {
|
||||||
|
<img src="/api/pictures/{{picture.id}}" (click)="selectPicture(picture)" matTooltip="Choose this illustration"
|
||||||
|
i18n-matTooltip/>
|
||||||
|
}
|
||||||
} @else {
|
} @else {
|
||||||
@if (pictures.length) {
|
<h2 i18n>There is no any picture.</h2>
|
||||||
@for(picture of pictures; track picture) {
|
|
||||||
<img src="/api/pictures/{{picture.id}}" (click)="selectPicture(picture)" matTooltip="Choose this illustration" i18n-matTooltip/>
|
|
||||||
}
|
|
||||||
} @else {
|
|
||||||
<h2 i18n>There is no any picture.</h2>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
(click)="closeDialog()"
|
(click)="closeDialog()"
|
||||||
class="cod-button secondary"
|
class="cod-button secondary"
|
||||||
matRipple
|
matRipple
|
||||||
i18n>
|
i18n>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
(click)="fileUpload.click()"
|
(click)="fileUpload.click()"
|
||||||
class="cod-button"
|
class="cod-button"
|
||||||
matRipple
|
matRipple
|
||||||
i18n>
|
i18n>
|
||||||
<mat-icon>upload_file</mat-icon>
|
<mat-icon>upload_file</mat-icon>
|
||||||
Add new picture
|
Add new picture
|
||||||
</button>
|
</button>
|
||||||
<input type="file" (change)="uploadPicture($event)" #fileUpload/>
|
<input type="file" (change)="uploadPicture($event)" #fileUpload/>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -1,83 +1,83 @@
|
|||||||
:host {
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1em;
|
||||||
|
gap: 1em;
|
||||||
|
position: relative;
|
||||||
|
max-height: 90vh;
|
||||||
|
|
||||||
|
header {
|
||||||
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
padding: 1em;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.picture-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
position: relative;
|
max-height: 30em;
|
||||||
max-height: 90vh;
|
overflow-y: auto;
|
||||||
|
min-height: 10em;
|
||||||
|
padding: .5em 0;
|
||||||
|
|
||||||
header {
|
img {
|
||||||
flex: 1;
|
width: 15em;
|
||||||
display: flex;
|
height: 10em;
|
||||||
flex-direction: row;
|
object-fit: cover;
|
||||||
justify-content: center;
|
border-radius: 1em;
|
||||||
align-items: center;
|
opacity: .9;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
transition: opacity .2s ease-in-out, box-shadow .2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 1;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .32), 0 2px 10px 0 rgba(0, 0, 0, .24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: .8em 1.2em;
|
||||||
|
border-radius: 10em;
|
||||||
|
border: none;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #5b6ed8;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.secondary {
|
||||||
|
color: #3f51b5;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #f2f4ff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.picture-container {
|
input[type=file] {
|
||||||
display: flex;
|
display: none;
|
||||||
flex-direction: row;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1em;
|
|
||||||
max-height: 30em;
|
|
||||||
overflow-y: auto;
|
|
||||||
min-height: 10em;
|
|
||||||
padding: .5em 0;
|
|
||||||
|
|
||||||
img {
|
|
||||||
width: 15em;
|
|
||||||
height: 10em;
|
|
||||||
object-fit: cover;
|
|
||||||
border-radius: 1em;
|
|
||||||
opacity: .9;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
transition: opacity .2s ease-in-out, box-shadow .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
opacity: 1;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.32),0 2px 10px 0 rgba(0,0,0,.24);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
footer {
|
}
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.secondary {
|
|
||||||
color: #3f51b5;
|
|
||||||
background-color: white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #f2f4ff;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type=file] {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,74 +1,74 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import {Component, inject, OnInit, signal} from "@angular/core";
|
||||||
import { Picture } from "../../../core/rest-services/picture/model/picture";
|
import {Picture} from "../../../core/rest-services/picture/model/picture";
|
||||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { PictureRestService } from "../../../core/rest-services/picture/picture.rest-service";
|
import {PictureRestService} from "../../../core/rest-services/picture/picture.rest-service";
|
||||||
import { MatIcon } from "@angular/material/icon";
|
import {MatIcon} from "@angular/material/icon";
|
||||||
import { MatDialogRef } from "@angular/material/dialog";
|
import {MatDialogRef} from "@angular/material/dialog";
|
||||||
import {MatRippleModule} from '@angular/material/core';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
import { MatTooltip } from "@angular/material/tooltip";
|
import {MatTooltip} from "@angular/material/tooltip";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-picture-selection',
|
selector: 'app-picture-selection',
|
||||||
templateUrl: './picture-selection-dialog.component.html',
|
templateUrl: './picture-selection-dialog.component.html',
|
||||||
styleUrl: './picture-selection-dialog.component.scss',
|
styleUrl: './picture-selection-dialog.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatIcon,
|
MatIcon,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatTooltip
|
MatTooltip
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class PictureSelectionDialog implements OnInit {
|
export class PictureSelectionDialog implements OnInit {
|
||||||
private readonly pictureRestService = inject(PictureRestService);
|
private readonly pictureRestService = inject(PictureRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
||||||
|
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
isLoaded: boolean = false;
|
isLoaded = signal(false);
|
||||||
pictures: Picture[] = [];
|
pictures: Picture[] = [];
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
this.pictureRestService.getAllOfCurrentUser()
|
this.pictureRestService.getAllOfCurrentUser()
|
||||||
.then(pictures => {
|
.then(pictures => {
|
||||||
this.pictures = pictures;
|
this.pictures = pictures;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.status === 401) {
|
if (error.status === 401) {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = $localize`An error occured while loading pictures.`;
|
const errorMessage = $localize`An error occurred while loading pictures.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.isLoading = false;
|
|
||||||
this.isLoaded = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
selectPicture(picture: Picture): void {
|
|
||||||
this.dialogRef.close(picture.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
closeDialog(): void {
|
|
||||||
this.dialogRef.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadPicture(fileSelectionEvent: any): void {
|
|
||||||
const pictureFile = fileSelectionEvent.target.files[0];
|
|
||||||
if (pictureFile) {
|
|
||||||
this.pictureRestService.uploadPicture(pictureFile)
|
|
||||||
.then(pictureId => {
|
|
||||||
this.dialogRef.close(pictureId);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
const errorMessage = $localize`A technical error occured while uploading your picture.`;
|
|
||||||
console.error(errorMessage, error);
|
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.isLoading.set(false);
|
||||||
|
this.isLoaded.set(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectPicture(picture: Picture): void {
|
||||||
|
this.dialogRef.close(picture.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
closeDialog(): void {
|
||||||
|
this.dialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadPicture(fileSelectionEvent: any): void {
|
||||||
|
const pictureFile = fileSelectionEvent.target.files[0];
|
||||||
|
if (pictureFile) {
|
||||||
|
this.pictureRestService.uploadPicture(pictureFile)
|
||||||
|
.then(pictureId => {
|
||||||
|
this.dialogRef.close(pictureId);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const errorMessage = $localize`A technical error occurred while uploading your picture.`;
|
||||||
|
console.error(errorMessage, error);
|
||||||
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import { PictureRestService } from "../../../core/rest-services/picture/picture.rest-service";
|
import {PictureRestService} from "../../../core/rest-services/picture/picture.rest-service";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { MatDialogRef } from "@angular/material/dialog";
|
import {MatDialogRef} from "@angular/material/dialog";
|
||||||
import { PictureSelectionDialog } from "./picture-selection-dialog.component";
|
import {PictureSelectionDialog} from "./picture-selection-dialog.component";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PictureSelectionDialogService {
|
export class PictureSelectionDialogService {
|
||||||
private pictureRestService = inject(PictureRestService);
|
private pictureRestService = inject(PictureRestService);
|
||||||
private snackBar = inject(MatSnackBar);
|
private snackBar = inject(MatSnackBar);
|
||||||
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
private readonly dialogRef = inject(MatDialogRef<PictureSelectionDialog>);
|
||||||
|
|
||||||
uploadPicture(pictureFile: File): void {
|
uploadPicture(pictureFile: File): void {
|
||||||
this.pictureRestService.uploadPicture(pictureFile)
|
this.pictureRestService.uploadPicture(pictureFile)
|
||||||
.then(pictureId => {
|
.then(pictureId => {
|
||||||
this.dialogRef.close(pictureId);
|
this.dialogRef.close(pictureId);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while uploading a picture...`;
|
const errorMessage = $localize`An error occured while uploading a picture...`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,132 +1,133 @@
|
|||||||
<form [formGroup]="publicationEditionForm" (submit)="save()" ngNativeValidate>
|
<form [formGroup]="publicationEditionForm" (submit)="save()" ngNativeValidate>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{title}}</h1>
|
<h1>{{ title() }}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<mat-tab-group dynamicHeight (selectedIndexChange)="onTabChange($event)">
|
<mat-tab-group dynamicHeight (selectedIndexChange)="onTabChange($event)">
|
||||||
<mat-tab label="Edition" i18n-label>
|
<mat-tab label="Edition" i18n-label>
|
||||||
<div class="form-content">
|
<div class="form-content">
|
||||||
<div class="first-part">
|
<div class="first-part">
|
||||||
<div>
|
<div>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Title</mat-label>
|
<mat-label i18n>Title</mat-label>
|
||||||
<input matInput type="text" formControlName="title" />
|
<input matInput type="text" formControlName="title"/>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Description</mat-label>
|
<mat-label i18n>Description</mat-label>
|
||||||
<input matInput type="text" formControlName="description" />
|
<input matInput type="text" formControlName="description"/>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label i18n>Category</mat-label>
|
<mat-label i18n>Category</mat-label>
|
||||||
<mat-select formControlName="categoryId">
|
<mat-select formControlName="categoryId">
|
||||||
@for (category of categories$ | async; track category) {
|
@for (category of categories$ | async; track category) {
|
||||||
<mat-option [value]="category.id">
|
<mat-option [value]="category.id">
|
||||||
{{ category.name }}
|
{{ category.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
}
|
|
||||||
</mat-select>
|
|
||||||
</mat-form-field>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="picture-container">
|
|
||||||
<img [src]="publication.illustrationId.length ? '/api/pictures/' + publication.illustrationId : '/assets/images/default-picture.png'"
|
|
||||||
(click)="displayPictureSectionDialog()"
|
|
||||||
matTooltip="Click to change illustration"
|
|
||||||
i18n-matTooltip/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="actions">
|
|
||||||
<button type="button"
|
|
||||||
(click)="insertTitle(1)"
|
|
||||||
matTooltip="Click to insert a title 1 section"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
H1
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
(click)="insertTitle(2)"
|
|
||||||
matTooltip="Click to insert a title 2 section"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
H2
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
(click)="insertTitle(3)"
|
|
||||||
matTooltip="Click to insert a title 3 section"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
H3
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
(click)="insertLink()"
|
|
||||||
matTooltip="Click to insert a link"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
<mat-icon>link</mat-icon>
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
(click)="selectAPicture()"
|
|
||||||
matTooltip="Click to insert a picture"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
<mat-icon>image</mat-icon>
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
(click)="displayCodeBlockDialog()"
|
|
||||||
matTooltip="Click to insert a code block"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
<mat-icon>code</mat-icon>
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
matTooltip="Click to display editor help"
|
|
||||||
disabled
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
<mat-icon>help</mat-icon>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<mat-form-field>
|
|
||||||
<mat-label i18n>Content</mat-label>
|
|
||||||
<textarea
|
|
||||||
#textArea
|
|
||||||
matInput
|
|
||||||
formControlName="text"
|
|
||||||
class="text-input"
|
|
||||||
(keyup)="updateCursorPosition($event)"
|
|
||||||
(click)="updateCursorPosition($event)">
|
|
||||||
</textarea>
|
|
||||||
</mat-form-field>
|
|
||||||
</div>
|
|
||||||
</mat-tab>
|
|
||||||
|
|
||||||
<mat-tab label="Previewing" i18n-label>
|
|
||||||
<div class="preview">
|
|
||||||
@if ((isPreviewing$ | async) === true) {
|
|
||||||
<div class="preview-loading">
|
|
||||||
<h2 i18n>Preview is loading...</h2>
|
|
||||||
<mat-spinner></mat-spinner>
|
|
||||||
</div>
|
|
||||||
} @else {
|
|
||||||
<img class="illustration" src="/api/pictures/{{ publication.illustrationId }}" />
|
|
||||||
<header>
|
|
||||||
<h1>{{ publication.title }}</h1>
|
|
||||||
<h2>{{ publication.description }}</h2>
|
|
||||||
</header>
|
|
||||||
<main [innerHTML]="publicationInEdition.parsedText"></main>
|
|
||||||
}
|
}
|
||||||
</div>
|
</mat-select>
|
||||||
</mat-tab>
|
</mat-form-field>
|
||||||
</mat-tab-group>
|
</div>
|
||||||
<footer>
|
|
||||||
<app-submit-button [requestPending]="!!(isSaving$ | async)" i18n>Save</app-submit-button>
|
<div class="picture-container">
|
||||||
<button type="button"
|
<img
|
||||||
class="cod-button secondary"
|
[src]="publication().illustrationId.length ? '/api/pictures/' + publication().illustrationId : '/assets/images/default-picture.png'"
|
||||||
(click)="goPreviousLocation()"
|
(click)="displayPictureSectionDialog()"
|
||||||
matRipple
|
matTooltip="Click to change illustration"
|
||||||
i18n>
|
i18n-matTooltip/>
|
||||||
Cancel
|
</div>
|
||||||
</button>
|
</div>
|
||||||
</footer>
|
|
||||||
</form>
|
<div class="actions">
|
||||||
|
<button type="button"
|
||||||
|
(click)="insertTitle(1)"
|
||||||
|
matTooltip="Click to insert a title 1 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
H1
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="insertTitle(2)"
|
||||||
|
matTooltip="Click to insert a title 2 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
H2
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="insertTitle(3)"
|
||||||
|
matTooltip="Click to insert a title 3 section"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
H3
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="insertLink()"
|
||||||
|
matTooltip="Click to insert a link"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>link</mat-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="selectAPicture()"
|
||||||
|
matTooltip="Click to insert a picture"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>image</mat-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
(click)="displayCodeBlockDialog()"
|
||||||
|
matTooltip="Click to insert a code block"
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>code</mat-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
matTooltip="Click to display editor help"
|
||||||
|
disabled
|
||||||
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>help</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label i18n>Content</mat-label>
|
||||||
|
<textarea
|
||||||
|
#textArea
|
||||||
|
matInput
|
||||||
|
formControlName="text"
|
||||||
|
class="text-input"
|
||||||
|
(keyup)="updateCursorPosition($event)"
|
||||||
|
(click)="updateCursorPosition($event)">
|
||||||
|
</textarea>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</mat-tab>
|
||||||
|
|
||||||
|
<mat-tab label="Previewing" i18n-label>
|
||||||
|
<div class="preview">
|
||||||
|
@if (isPreviewing()) {
|
||||||
|
<div class="preview-loading">
|
||||||
|
<h2 i18n>Preview is loading...</h2>
|
||||||
|
<mat-spinner></mat-spinner>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<img class="illustration" src="/api/pictures/{{ publication().illustrationId }}"/>
|
||||||
|
<header>
|
||||||
|
<h1>{{ publication().title }}</h1>
|
||||||
|
<h2>{{ publication().description }}</h2>
|
||||||
|
</header>
|
||||||
|
<main [innerHTML]="publicationInEdition().parsedText"></main>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</mat-tab>
|
||||||
|
</mat-tab-group>
|
||||||
|
<footer>
|
||||||
|
<app-submit-button [requestPending]="isSaving()" i18n>Save</app-submit-button>
|
||||||
|
<button type="button"
|
||||||
|
class="cod-button secondary"
|
||||||
|
(click)="goPreviousLocation()"
|
||||||
|
matRipple
|
||||||
|
i18n>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
|||||||
@@ -1,170 +1,170 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
form {
|
form {
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
max-width: 80em;
|
max-width: 80em;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
border-radius: .5em;
|
border-radius: .5em;
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
|
||||||
& > header {
|
& > header {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
background-color: #3f51b5;
|
background-color: #3f51b5;
|
||||||
color: white;
|
color: white;
|
||||||
border-radius: .5em .5em 0 0;
|
border-radius: .5em .5em 0 0;
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
margin-bottom: .5em;
|
margin-bottom: .5em;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
padding: 2em;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row-reverse;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
padding: 2em;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-content {
|
.form-content {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: .5em;
|
||||||
|
|
||||||
|
mat-form-field {
|
||||||
|
textarea {
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.first-part {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column-reverse;
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
|
@media screen and (min-width: 600px) {
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
div {
|
||||||
|
flex: 1 0;
|
||||||
|
|
||||||
|
&.picture-container {
|
||||||
|
max-width: 20em;
|
||||||
|
|
||||||
|
img {
|
||||||
|
max-height: 15em;
|
||||||
|
max-width: 20em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
flex: 1 0 50%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
&.picture-container {
|
||||||
|
img {
|
||||||
|
flex: 1;
|
||||||
|
object-fit: cover;
|
||||||
|
width: 100%;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 1em;
|
||||||
|
opacity: .9;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
transition: opacity .2s ease-in-out, box-shadow .2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 1;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .32), 0 2px 10px 0 rgba(0, 0, 0, .24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
gap: .5em;
|
gap: .5em;
|
||||||
|
|
||||||
mat-form-field {
|
button {
|
||||||
textarea {
|
padding: 0;
|
||||||
height: 20em;
|
border-radius: 10em;
|
||||||
}
|
border: none;
|
||||||
}
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
.first-part {
|
transition: background-color .2s ease-in-out;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column-reverse;
|
justify-content: center;
|
||||||
gap: 1em;
|
align-items: center;
|
||||||
|
width: 3em;
|
||||||
@media screen and (min-width: 600px) {
|
height: 3em;
|
||||||
flex-direction: row;
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
font-weight: bold;
|
||||||
div {
|
|
||||||
flex: 1 0;
|
&:hover {
|
||||||
|
background-color: #5b6ed8;
|
||||||
&.picture-container {
|
cursor: pointer;
|
||||||
max-width: 20em;
|
}
|
||||||
|
|
||||||
img {
|
&:disabled {
|
||||||
max-height: 15em;
|
background-color: #5f6aa6;
|
||||||
max-width: 20em;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
div {
|
|
||||||
flex: 1 0 50%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
&.picture-container {
|
|
||||||
img {
|
|
||||||
flex: 1;
|
|
||||||
object-fit: cover;
|
|
||||||
width: 100%;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 1em;
|
|
||||||
opacity: .9;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
transition: opacity .2s ease-in-out, box-shadow .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
opacity: 1;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.32),0 2px 10px 0 rgba(0,0,0,.24);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: .5em;
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: 0;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
width: 3em;
|
|
||||||
height: 3em;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
font-weight: bold;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:disabled {
|
|
||||||
background-color: #5f6aa6;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview {
|
.preview {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-height: 80vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
|
.preview-loading {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
max-height: 80vh;
|
align-items: center;
|
||||||
overflow-y: auto;
|
}
|
||||||
|
|
||||||
.preview-loading {
|
.illustration {
|
||||||
display: flex;
|
flex: 1;
|
||||||
flex-direction: column;
|
height: 12em;
|
||||||
align-items: center;
|
object-fit: cover;
|
||||||
|
transition: height .2s ease-in-out;
|
||||||
|
|
||||||
|
@media screen and (min-width: 450px) {
|
||||||
|
height: 15em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.illustration {
|
@media screen and (min-width: 600px) {
|
||||||
flex: 1;
|
height: 20em;
|
||||||
height: 12em;
|
|
||||||
object-fit: cover;
|
|
||||||
transition: height .2s ease-in-out;
|
|
||||||
|
|
||||||
@media screen and (min-width: 450px) {
|
|
||||||
height: 15em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 600px) {
|
|
||||||
height: 20em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 750px) {
|
|
||||||
height: 25em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
@media screen and (min-width: 750px) {
|
||||||
padding: 2em;
|
height: 25em;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
main {
|
header {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
text-align: justify;
|
}
|
||||||
}
|
|
||||||
}
|
main {
|
||||||
|
padding: 2em;
|
||||||
|
text-align: justify;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,148 +1,135 @@
|
|||||||
import { CommonModule, Location } from "@angular/common";
|
import {CommonModule, Location} from "@angular/common";
|
||||||
import { Component, EventEmitter, inject, Input, OnChanges, OnDestroy, Output } from "@angular/core";
|
import {Component, effect, inject, input, output, signal} from "@angular/core";
|
||||||
import { FormGroup, ReactiveFormsModule } from "@angular/forms";
|
import {FormGroup, ReactiveFormsModule} from "@angular/forms";
|
||||||
import { MatDialogModule } from "@angular/material/dialog";
|
import {MatDialogModule} from "@angular/material/dialog";
|
||||||
import { MatIconModule } from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import { MatInputModule } from "@angular/material/input";
|
import {MatInputModule} from "@angular/material/input";
|
||||||
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||||
import { MatSelectModule } from "@angular/material/select";
|
import {MatSelectModule} from "@angular/material/select";
|
||||||
import { MatTabsModule } from "@angular/material/tabs";
|
import {MatTabsModule} from "@angular/material/tabs";
|
||||||
import { MatTooltipModule } from "@angular/material/tooltip";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
import { map, Observable, of, Subscription } from "rxjs";
|
import {map, Observable} from "rxjs";
|
||||||
import { Category } from "../../core/rest-services/category/model/category";
|
import {Category} from "../../core/rest-services/category/model/category";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { CategoryService } from "../../core/service/category.service";
|
import {CategoryService} from "../../core/service/category.service";
|
||||||
import { SubmitButtonComponent } from "../submit-button/submit-button.component";
|
import {SubmitButtonComponent} from "../submit-button/submit-button.component";
|
||||||
import { PictureSelectionDialog } from "./picture-selection-dialog/picture-selection-dialog.component";
|
import {PublicationEditionService} from "./publication-edition.service";
|
||||||
import { PublicationEditionService } from "./publication-edition.service";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-edition',
|
selector: 'app-publication-edition',
|
||||||
templateUrl: './publication-edition.component.html',
|
templateUrl: './publication-edition.component.html',
|
||||||
styleUrl: './publication-edition.component.scss',
|
styleUrl: './publication-edition.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
MatTabsModule,
|
MatTabsModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
SubmitButtonComponent
|
SubmitButtonComponent
|
||||||
],
|
],
|
||||||
providers: [PublicationEditionService]
|
providers: [PublicationEditionService]
|
||||||
})
|
})
|
||||||
export class PublicationEditionComponent implements OnChanges, OnDestroy {
|
export class PublicationEditionComponent {
|
||||||
@Input()
|
readonly #categoryService = inject(CategoryService);
|
||||||
publication!: Publication;
|
readonly #location = inject(Location);
|
||||||
@Input()
|
readonly #publicationEditionService = inject(PublicationEditionService);
|
||||||
title!: string;
|
|
||||||
@Input()
|
|
||||||
isSaving$: Observable<boolean> = of(false);
|
|
||||||
@Output()
|
|
||||||
publicationSave = new EventEmitter<Publication>();
|
|
||||||
|
|
||||||
publicationInEdition!: Publication;
|
publication = input.required<Publication>();
|
||||||
private readonly categoryService = inject(CategoryService);
|
title = input.required<string>();
|
||||||
private readonly location = inject(Location);
|
isSaving = input.required<boolean>();
|
||||||
private readonly publicationEditionService = inject(PublicationEditionService);
|
publicationSave = output<Publication>();
|
||||||
private subscriptions: Subscription[] = [];
|
|
||||||
|
|
||||||
get publicationEditionForm(): FormGroup {
|
isLoading = this.#publicationEditionService.isLoading;
|
||||||
return this.publicationEditionService.publicationEditionForm;
|
isPreviewing = this.#publicationEditionService.isPreviewing;
|
||||||
|
publicationInEdition = signal<Publication>(DEFAULT_PUBLICATION);
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
effect(() => {
|
||||||
|
let publication = this.publication();
|
||||||
|
const publicationInEdition = this.publicationInEdition();
|
||||||
|
if (!publicationInEdition || publicationInEdition !== publication) {
|
||||||
|
this.publicationInEdition.set(publication);
|
||||||
|
this.#publicationEditionService.init(publication);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get publicationEditionForm(): FormGroup {
|
||||||
|
return this.#publicationEditionService.publicationEditionForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
get categories$(): Observable<Category[]> {
|
||||||
|
return this.#categoryService.categories$
|
||||||
|
.pipe(
|
||||||
|
map(categories =>
|
||||||
|
categories.filter(category => category.subCategories.length == 0)
|
||||||
|
.sort(this.byNameAscComparator())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byNameAscComparator(): (categoryA: Category, categoryB: Category) => number {
|
||||||
|
return (categoryA, categoryB) => this.compareStrings(categoryA.name, categoryB.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private compareStrings(stringA: string, stringB: string): number {
|
||||||
|
if (stringA < stringB) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (stringA > stringB) {
|
||||||
get isLoading$(): Observable<boolean> {
|
return 1;
|
||||||
return this.publicationEditionService.isLoading$;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
get isPreviewing$(): Observable<boolean> {
|
goPreviousLocation(): void {
|
||||||
return this.publicationEditionService.isPreviewing$;
|
this.#location.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
insertTitle(titleNumber: number): void {
|
||||||
|
this.#publicationEditionService.insertTitle(titleNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectAPicture(): void {
|
||||||
|
this.#publicationEditionService.selectAPicture();
|
||||||
|
}
|
||||||
|
|
||||||
|
insertLink(): void {
|
||||||
|
this.#publicationEditionService.insertLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
displayCodeBlockDialog(): void {
|
||||||
|
this.#publicationEditionService.displayCodeBlockDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
displayPictureSectionDialog(): void {
|
||||||
|
this.#publicationEditionService.displayPictureSectionDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCursorPosition(event: KeyboardEvent | MouseEvent): void {
|
||||||
|
if (event.target) {
|
||||||
|
const textarea = event.target as HTMLTextAreaElement;
|
||||||
|
|
||||||
|
const positionStart = textarea.selectionStart;
|
||||||
|
const positionEnd = textarea.selectionEnd;
|
||||||
|
|
||||||
|
this.#publicationEditionService.editCursorPosition(positionStart, positionEnd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get categories$(): Observable<Category[]> {
|
save(): void {
|
||||||
return this.categoryService.categories$
|
this.publicationSave.emit(this.#publicationEditionService.editedPublication);
|
||||||
.pipe(
|
}
|
||||||
map(categories =>
|
|
||||||
categories.filter(category => category.subCategories.length == 0)
|
onTabChange(tabSelectedIndex: number): void {
|
||||||
.sort(this.byNameAscComparator())
|
if (tabSelectedIndex === 1) {
|
||||||
)
|
this.#publicationEditionService.loadPreview();
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byNameAscComparator(): (categoryA: Category, categoryB: Category) => number {
|
|
||||||
return (categoryA, categoryB) => this.compareStrings(categoryA.name, categoryB.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private compareStrings(stringA: string, stringB: string): number {
|
|
||||||
if (stringA < stringB) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (stringA > stringB) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnChanges(): void {
|
|
||||||
this.ngOnDestroy();
|
|
||||||
|
|
||||||
if (!this.publicationInEdition || this.publicationInEdition !== this.publication) {
|
|
||||||
this.publicationInEdition = this.publication;
|
|
||||||
this.publicationEditionService.init(this.publicationInEdition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
goPreviousLocation(): void {
|
|
||||||
this.location.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
insertTitle(titleNumber: number): void {
|
|
||||||
this.publicationEditionService.insertTitle(titleNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
selectAPicture(): void {
|
|
||||||
this.publicationEditionService.selectAPicture();
|
|
||||||
}
|
|
||||||
|
|
||||||
insertLink(): void {
|
|
||||||
this.publicationEditionService.insertLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
displayCodeBlockDialog(): void {
|
|
||||||
this.publicationEditionService.displayCodeBlockDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
displayPictureSectionDialog(): void {
|
|
||||||
this.publicationEditionService.displayPictureSectionDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCursorPosition(event: KeyboardEvent | MouseEvent): void {
|
|
||||||
if (event.target) {
|
|
||||||
const textarea = event.target as HTMLTextAreaElement;
|
|
||||||
|
|
||||||
const positionStart = textarea.selectionStart;
|
|
||||||
const positionEnd = textarea.selectionEnd;
|
|
||||||
|
|
||||||
this.publicationEditionService.editCursorPosition(positionStart, positionEnd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
save(): void {
|
|
||||||
this.publicationSave.emit(this.publicationEditionService.editedPublication);
|
|
||||||
}
|
|
||||||
|
|
||||||
onTabChange(tabSelectedIndex: number): void {
|
|
||||||
if (tabSelectedIndex === 1) {
|
|
||||||
this.publicationEditionService.loadPreview();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,312 +1,287 @@
|
|||||||
import { Location } from "@angular/common";
|
import {Location} from "@angular/common";
|
||||||
import { inject, Injectable, OnDestroy } from "@angular/core";
|
import {inject, Injectable, OnDestroy, Signal, signal} from "@angular/core";
|
||||||
import { MatDialog } from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { ActivatedRoute } from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import { BehaviorSubject, debounceTime, distinctUntilChanged, Observable, Subscription } from "rxjs";
|
import {debounceTime, distinctUntilChanged, Subscription} from "rxjs";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { copy } from "../../core/utils/ObjectUtils";
|
import {copy} from "../../core/utils/ObjectUtils";
|
||||||
import { CodeBlockDialog } from "./code-block-dialog/code-block-dialog.component";
|
import {CodeBlockDialog} from "./code-block-dialog/code-block-dialog.component";
|
||||||
import { PictureSelectionDialog } from "./picture-selection-dialog/picture-selection-dialog.component";
|
import {PictureSelectionDialog} from "./picture-selection-dialog/picture-selection-dialog.component";
|
||||||
import { PreviewContentRequest } from "../../core/rest-services/publications/model/preview";
|
import {PreviewContentRequest} from "../../core/rest-services/publications/model/preview";
|
||||||
import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";
|
import {FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
|
||||||
|
|
||||||
declare let Prism: any;
|
declare let Prism: any;
|
||||||
|
|
||||||
export class CursorPosition {
|
export class CursorPosition {
|
||||||
start: number;
|
start: number;
|
||||||
end: number;
|
end: number;
|
||||||
selectedCharacters: number;
|
selectedCharacters: number;
|
||||||
|
|
||||||
constructor(start: number, end: number) {
|
constructor(start: number, end: number) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.selectedCharacters = end - start;
|
this.selectedCharacters = end - start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PublicationEditionState {
|
export interface PublicationEditionState {
|
||||||
publication: Publication;
|
publication: Publication;
|
||||||
cursorPosition: CursorPosition;
|
cursorPosition: CursorPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_PUBLICATION: Publication = {
|
|
||||||
id: '',
|
|
||||||
key: '',
|
|
||||||
title: '',
|
|
||||||
text: '',
|
|
||||||
parsedText: '',
|
|
||||||
description: '',
|
|
||||||
creationDate: new Date(),
|
|
||||||
illustrationId: '',
|
|
||||||
categoryId: '',
|
|
||||||
author: {
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
image: ''
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEFAULT_CURSOR_POSITION = new CursorPosition(0, 0);
|
const DEFAULT_CURSOR_POSITION = new CursorPosition(0, 0);
|
||||||
|
|
||||||
const DEFAULT_STATE: PublicationEditionState = {
|
const DEFAULT_STATE: PublicationEditionState = {
|
||||||
publication: DEFAULT_PUBLICATION,
|
publication: DEFAULT_PUBLICATION,
|
||||||
cursorPosition: DEFAULT_CURSOR_POSITION
|
cursorPosition: DEFAULT_CURSOR_POSITION
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PublicationEditionService implements OnDestroy {
|
export class PublicationEditionService implements OnDestroy {
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
readonly #activatedRoute = inject(ActivatedRoute);
|
||||||
private readonly dialog = inject(MatDialog);
|
readonly #dialog = inject(MatDialog);
|
||||||
private readonly formBuilder = inject(FormBuilder);
|
readonly #formBuilder = inject(FormBuilder);
|
||||||
private readonly location = inject(Location);
|
readonly #location = inject(Location);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private stateSubject = new BehaviorSubject<PublicationEditionState>(copy(DEFAULT_STATE));
|
#state = signal<PublicationEditionState>(copy(DEFAULT_STATE));
|
||||||
private subscriptions: Subscription[] = [];
|
#isSaving = signal<boolean>(false);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
#isPreviewing = signal<boolean>(false);
|
||||||
private isPreviewingSubject = new BehaviorSubject<boolean>(false);
|
#subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
publicationEditionForm: FormGroup = this.formBuilder.group({
|
publicationEditionForm: FormGroup = this.#formBuilder.group({
|
||||||
title: new FormControl<string | undefined>('', [Validators.required]),
|
title: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
description: new FormControl<string | undefined>('', [Validators.required]),
|
description: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
text: new FormControl<string | undefined>('', [Validators.required]),
|
text: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
illustrationId: new FormControl<string | undefined>('', [Validators.required]),
|
illustrationId: new FormControl<string | undefined>('', [Validators.required]),
|
||||||
categoryId: new FormControl<string | undefined>('', [Validators.required])
|
categoryId: new FormControl<string | undefined>('', [Validators.required])
|
||||||
|
});
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.#subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||||
|
}
|
||||||
|
|
||||||
|
#updateForm(): void {
|
||||||
|
const state = this.#state();
|
||||||
|
const publication = state.publication;
|
||||||
|
|
||||||
|
this.publicationEditionForm.controls['title'].setValue(publication.title);
|
||||||
|
this.publicationEditionForm.controls['description'].setValue(publication.description);
|
||||||
|
this.publicationEditionForm.controls['text'].setValue(publication.text);
|
||||||
|
this.publicationEditionForm.controls['illustrationId'].setValue(publication.illustrationId);
|
||||||
|
this.publicationEditionForm.controls['categoryId'].setValue(publication.categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLoading(): Signal<boolean> {
|
||||||
|
return this.#isLoading.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get isSaving(): Signal<boolean> {
|
||||||
|
return this.#isSaving.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get isPreviewing(): Signal<boolean> {
|
||||||
|
return this.#isPreviewing.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get state(): Signal<PublicationEditionState> {
|
||||||
|
return this.#state.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get editedPublication(): Publication {
|
||||||
|
return this.#state().publication;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPublication(): void {
|
||||||
|
this.#isLoading.set(true);
|
||||||
|
|
||||||
|
this.#activatedRoute.paramMap.subscribe(params => {
|
||||||
|
const publicationId = params.get('publicationId');
|
||||||
|
if (publicationId == undefined) {
|
||||||
|
this.#snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, {duration: 5000});
|
||||||
|
this.#location.back();
|
||||||
|
} else {
|
||||||
|
this.#publicationRestService.getById(publicationId)
|
||||||
|
.then(publication => {
|
||||||
|
const state = this.#state();
|
||||||
|
state.publication = publication;
|
||||||
|
this.#state.set(state);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
||||||
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
|
console.error(errorMessage, error)
|
||||||
|
})
|
||||||
|
.finally(() => this.#isLoading.set(false));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
init(publication: Publication): void {
|
||||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
const state = this.#state();
|
||||||
}
|
state.publication = publication;
|
||||||
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
|
|
||||||
private get _state(): PublicationEditionState {
|
const formValueChangesSubscription = this.publicationEditionForm.valueChanges
|
||||||
return this.stateSubject.value;
|
.pipe(
|
||||||
}
|
debounceTime(200),
|
||||||
|
distinctUntilChanged()
|
||||||
private _save(state: PublicationEditionState): void {
|
)
|
||||||
this.stateSubject.next(state);
|
.subscribe(formValue => {
|
||||||
}
|
const state = this.#state();
|
||||||
|
|
||||||
private _updateForm(): void {
|
|
||||||
const state = this._state;
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
this.publicationEditionForm.controls['title'].setValue(publication.title);
|
publication.title = formValue.title;
|
||||||
this.publicationEditionForm.controls['description'].setValue(publication.description);
|
publication.description = formValue.description;
|
||||||
this.publicationEditionForm.controls['text'].setValue(publication.text);
|
publication.categoryId = formValue.categoryId;
|
||||||
this.publicationEditionForm.controls['illustrationId'].setValue(publication.illustrationId);
|
publication.text = formValue.text;
|
||||||
this.publicationEditionForm.controls['categoryId'].setValue(publication.categoryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
this.#state.set(state);
|
||||||
return this.isLoadingSubject.asObservable();
|
});
|
||||||
}
|
this.#subscriptions.push(formValueChangesSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
private editIllustrationId(pictureId: string): void {
|
||||||
return this.isSavingSubject.asObservable();
|
const state = this.#state();
|
||||||
}
|
state.publication.illustrationId = pictureId
|
||||||
|
this.#state.set(state);
|
||||||
|
}
|
||||||
|
|
||||||
get isPreviewing$(): Observable<boolean> {
|
displayPictureSectionDialog(): void {
|
||||||
return this.isPreviewingSubject.asObservable();
|
const dialogRef = this.#dialog.open(PictureSelectionDialog);
|
||||||
}
|
|
||||||
|
|
||||||
get state$(): Observable<PublicationEditionState> {
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
return this.stateSubject.asObservable();
|
.subscribe(newPictureId => {
|
||||||
}
|
if (newPictureId) {
|
||||||
|
this.editIllustrationId(newPictureId);
|
||||||
get editedPublication(): Publication {
|
|
||||||
return this._state.publication;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPublication(): void {
|
|
||||||
this.isLoadingSubject.next(true);
|
|
||||||
|
|
||||||
this.activatedRoute.paramMap.subscribe(params => {
|
|
||||||
const publicationId = params.get('publicationId');
|
|
||||||
if (publicationId == undefined) {
|
|
||||||
this.snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, { duration: 5000 });
|
|
||||||
this.location.back();
|
|
||||||
} else {
|
|
||||||
this.publicationRestService.getById(publicationId)
|
|
||||||
.then(publication => {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication = publication;
|
|
||||||
this.stateSubject.next(state);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
|
||||||
console.error(errorMessage, error)
|
|
||||||
})
|
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
init(publication: Publication): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication = publication;
|
|
||||||
this.stateSubject.next(state);
|
|
||||||
this._updateForm();
|
|
||||||
|
|
||||||
const formValueChangesSubscription = this.publicationEditionForm.valueChanges
|
|
||||||
.pipe(
|
|
||||||
debounceTime(200),
|
|
||||||
distinctUntilChanged()
|
|
||||||
)
|
|
||||||
.subscribe(formValue => {
|
|
||||||
const state = this._state;
|
|
||||||
const publication = state.publication;
|
|
||||||
|
|
||||||
publication.title = formValue.title;
|
|
||||||
publication.description = formValue.description;
|
|
||||||
publication.categoryId = formValue.categoryId;
|
|
||||||
publication.text = formValue.text;
|
|
||||||
|
|
||||||
this._save(state);
|
|
||||||
})
|
|
||||||
this.subscriptions.push(formValueChangesSubscription);
|
|
||||||
}
|
|
||||||
|
|
||||||
private editIllustrationId(pictureId: string): void {
|
|
||||||
const state = this._state;
|
|
||||||
state.publication.illustrationId = pictureId
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
displayPictureSectionDialog(): void {
|
|
||||||
const dialogRef = this.dialog.open(PictureSelectionDialog);
|
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
|
||||||
.subscribe(newPictureId => {
|
|
||||||
if (newPictureId) {
|
|
||||||
this.editIllustrationId(newPictureId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
|
||||||
}
|
|
||||||
|
|
||||||
displayCodeBlockDialog(): void {
|
|
||||||
const dialogRef = this.dialog.open(CodeBlockDialog, { width: '60em' });
|
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
|
||||||
.subscribe(codeBlockWithLanguage => {
|
|
||||||
if (codeBlockWithLanguage) {
|
|
||||||
this.insertCodeBlock(codeBlockWithLanguage.programmingLanguage, codeBlockWithLanguage.codeBlock);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
|
||||||
}
|
|
||||||
|
|
||||||
editCursorPosition(positionStart: number, positionEnd: number): void {
|
|
||||||
const state = this._state;
|
|
||||||
|
|
||||||
state.cursorPosition.start = positionStart;
|
|
||||||
state.cursorPosition.end = positionEnd;
|
|
||||||
|
|
||||||
this._save(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
insertTitle(titleNumber: number): void {
|
|
||||||
if (titleNumber >= 1 && titleNumber <= 3) {
|
|
||||||
const state = this._state;
|
|
||||||
|
|
||||||
const publication = state.publication;
|
|
||||||
|
|
||||||
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
|
||||||
const publicationTextMiddlePart = publication.text.substring(state.cursorPosition.start, state.cursorPosition.end);
|
|
||||||
const publicationTextRightPart = publication.text.substring(state.cursorPosition.end);
|
|
||||||
const textWithTags = `${publicationTextLeftPart}[h${titleNumber}]${publicationTextMiddlePart}[/h${titleNumber}]${publicationTextRightPart}`;
|
|
||||||
|
|
||||||
publication.text = textWithTags;
|
|
||||||
|
|
||||||
this._save(state);
|
|
||||||
this._updateForm();
|
|
||||||
} else {
|
|
||||||
console.error(`Bad value for parameter of function 'insertTitle': '${titleNumber}'.`);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
|
displayCodeBlockDialog(): void {
|
||||||
|
const dialogRef = this.#dialog.open(CodeBlockDialog, {width: '60em'});
|
||||||
|
|
||||||
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
|
.subscribe(codeBlockWithLanguage => {
|
||||||
|
if (codeBlockWithLanguage) {
|
||||||
|
this.insertCodeBlock(codeBlockWithLanguage.programmingLanguage, codeBlockWithLanguage.codeBlock);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
|
}
|
||||||
|
|
||||||
|
editCursorPosition(positionStart: number, positionEnd: number): void {
|
||||||
|
const state = this.#state();
|
||||||
|
|
||||||
|
state.cursorPosition.start = positionStart;
|
||||||
|
state.cursorPosition.end = positionEnd;
|
||||||
|
|
||||||
|
this.#state.set(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
insertTitle(titleNumber: number): void {
|
||||||
|
if (titleNumber >= 1 && titleNumber <= 3) {
|
||||||
|
const state = this.#state();
|
||||||
|
|
||||||
|
const publication = state.publication;
|
||||||
|
|
||||||
|
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
||||||
|
const publicationTextMiddlePart = publication.text.substring(state.cursorPosition.start, state.cursorPosition.end);
|
||||||
|
const publicationTextRightPart = publication.text.substring(state.cursorPosition.end);
|
||||||
|
const textWithTags = `${publicationTextLeftPart}[h${titleNumber}]${publicationTextMiddlePart}[/h${titleNumber}]${publicationTextRightPart}`;
|
||||||
|
|
||||||
|
publication.text = textWithTags;
|
||||||
|
|
||||||
|
this.#state.set(state);
|
||||||
|
this.#updateForm();
|
||||||
|
} else {
|
||||||
|
console.error(`Bad value for parameter of function 'insertTitle': '${titleNumber}'.`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
selectAPicture(): void {
|
selectAPicture(): void {
|
||||||
const dialogRef = this.dialog.open(PictureSelectionDialog);
|
const dialogRef = this.#dialog.open(PictureSelectionDialog);
|
||||||
|
|
||||||
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
const afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(newPictureId => {
|
.subscribe(newPictureId => {
|
||||||
if (newPictureId) {
|
if (newPictureId) {
|
||||||
this.insertPicture(newPictureId);
|
this.insertPicture(newPictureId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.subscriptions.push(afterDialogCloseSubscription);
|
this.#subscriptions.push(afterDialogCloseSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertPicture(pictureId: string): void {
|
insertPicture(pictureId: string): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
||||||
const publicationTextRightPart = publication.text.substring(state.cursorPosition.start);
|
const publicationTextRightPart = publication.text.substring(state.cursorPosition.start);
|
||||||
const textWithTags = `${publicationTextLeftPart}[img src="/api/pictures/${pictureId}" /]${publicationTextRightPart}`;
|
const textWithTags = `${publicationTextLeftPart}[img src="/api/pictures/${pictureId}" /]${publicationTextRightPart}`;
|
||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
this._updateForm();
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertLink(): void {
|
insertLink(): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
||||||
const publicationTextMiddlePart = publication.text.substring(state.cursorPosition.start, state.cursorPosition.end);
|
const publicationTextMiddlePart = publication.text.substring(state.cursorPosition.start, state.cursorPosition.end);
|
||||||
const publicationTextRightPart = publication.text.substring(state.cursorPosition.end);
|
const publicationTextRightPart = publication.text.substring(state.cursorPosition.end);
|
||||||
const textWithTags = `${publicationTextLeftPart}[link href="" txt="${publicationTextMiddlePart}" /]${publicationTextRightPart}`;
|
const textWithTags = `${publicationTextLeftPart}[link href="" txt="${publicationTextMiddlePart}" /]${publicationTextRightPart}`;
|
||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
this._updateForm();
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
private insertCodeBlock(programmingLanguage: string, codeBlock: string): void {
|
private insertCodeBlock(programmingLanguage: string, codeBlock: string): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
const publication = state.publication;
|
const publication = state.publication;
|
||||||
|
|
||||||
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
const publicationTextLeftPart = publication.text.substring(0, state.cursorPosition.start);
|
||||||
const publicationTextRightPart = publication.text.substring(state.cursorPosition.start);
|
const publicationTextRightPart = publication.text.substring(state.cursorPosition.start);
|
||||||
const codeBlockInstruction = `\n[code lg="${programmingLanguage}"]\n${codeBlock}\n[/code]\n\n`;
|
const codeBlockInstruction = `\n[code lg="${programmingLanguage}"]\n${codeBlock}\n[/code]\n\n`;
|
||||||
const textWithTags = `${publicationTextLeftPart}${codeBlockInstruction}${publicationTextRightPart}`;
|
const textWithTags = `${publicationTextLeftPart}${codeBlockInstruction}${publicationTextRightPart}`;
|
||||||
|
|
||||||
publication.text = textWithTags;
|
publication.text = textWithTags;
|
||||||
|
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
this._updateForm();
|
this.#updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPreview(): void {
|
loadPreview(): void {
|
||||||
const state = this._state;
|
const state = this.#state();
|
||||||
|
|
||||||
this.isPreviewingSubject.next(true);
|
this.#isPreviewing.set(true);
|
||||||
const request: PreviewContentRequest = {
|
const request: PreviewContentRequest = {
|
||||||
text: state.publication.text
|
text: state.publication.text
|
||||||
};
|
};
|
||||||
this.publicationRestService.preview(request)
|
this.#publicationRestService.preview(request)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
state.publication.parsedText = response.text;
|
state.publication.parsedText = response.text;
|
||||||
this._save(state);
|
this.#state.set(state);
|
||||||
setTimeout(() => Prism.highlightAll(), 1000);
|
setTimeout(() => Prism.highlightAll(), 1000);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isPreviewingSubject.next(false);
|
this.#isPreviewing.set(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
@for(publication of publications$ | async; track publication) {
|
@for (publication of publications(); track publication.id) {
|
||||||
<a [routerLink]="['/publications/' + publication.id]" class="publication">
|
<a [routerLink]="['/publications/' + publication.id]" class="publication">
|
||||||
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<h1>{{publication.title}}</h1>
|
<h1>{{ publication.title }}</h1>
|
||||||
<h2>{{publication.description}}</h2>
|
<h2>{{ publication.description }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<img src="/api/pictures/{{ publication.author.image }}" [matTooltip]="publication.author.name"/>
|
<img src="/api/pictures/{{ publication.author.image }}" [matTooltip]="publication.author.name"/>
|
||||||
<span i18n>Publication posted by {{publication.author.name}}</span>
|
<span i18n>Publication posted by {{ publication.author.name }}</span>
|
||||||
<span class="publication-date">
|
<span class="publication-date">
|
||||||
({{ publication.creationDate | date: 'short' }})
|
({{ publication.creationDate | date: 'short' }})
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +1,87 @@
|
|||||||
$cardBorderRadius: .5em;
|
$cardBorderRadius: .5em;
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2em;
|
||||||
|
max-width: 50em;
|
||||||
|
width: 90%;
|
||||||
|
margin: auto;
|
||||||
|
|
||||||
|
.publication {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 2em;
|
border-radius: $cardBorderRadius;
|
||||||
max-width: 50em;
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
width: 90%;
|
transition: box-shadow .2s ease-in-out;
|
||||||
margin: auto;
|
text-decoration: none;
|
||||||
|
color: black;
|
||||||
|
background-color: #ffffff;
|
||||||
|
|
||||||
.publication {
|
&:hover {
|
||||||
display: flex;
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, .24), 0 4px 14px 0 rgba(0, 0, 0, .16);
|
||||||
flex-direction: column;
|
|
||||||
border-radius: $cardBorderRadius;
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
|
||||||
transition: box-shadow .2s ease-in-out;
|
|
||||||
text-decoration: none;
|
|
||||||
color: black;
|
|
||||||
background-color: #ffffff;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
box-shadow: 0 4px 8px 0 rgba(0,0,0,.24),0 4px 14px 0 rgba(0,0,0,.16);
|
|
||||||
}
|
|
||||||
|
|
||||||
img {
|
|
||||||
object-fit: cover;
|
|
||||||
height: 15em;
|
|
||||||
border-radius: $cardBorderRadius $cardBorderRadius 0 0;
|
|
||||||
transition: height .2s ease-in-out;
|
|
||||||
|
|
||||||
@media screen and (min-width: 450px) {
|
|
||||||
height: 20em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 600px) {
|
|
||||||
height: 25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 750px) {
|
|
||||||
height: 32em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.body {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 1.5em 2em;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 1.8em;
|
|
||||||
margin-bottom: .5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1em;
|
|
||||||
line-height: 1.4em;
|
|
||||||
margin: 0;
|
|
||||||
color: #747373;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
background-color: #f0f0f0;
|
|
||||||
border-radius: 0 0 $cardBorderRadius $cardBorderRadius;
|
|
||||||
padding: 1em 2em;
|
|
||||||
gap: 1em;
|
|
||||||
color: #6c757d;
|
|
||||||
|
|
||||||
img {
|
|
||||||
$imageSize: 4em;
|
|
||||||
border-radius: 10em;
|
|
||||||
width: $imageSize;
|
|
||||||
height: $imageSize;
|
|
||||||
object-fit: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.publication-date {
|
|
||||||
font-style: italic;
|
|
||||||
color: #bdbdbd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
img {
|
||||||
|
object-fit: cover;
|
||||||
|
height: 15em;
|
||||||
|
border-radius: $cardBorderRadius $cardBorderRadius 0 0;
|
||||||
|
transition: height .2s ease-in-out;
|
||||||
|
|
||||||
|
@media screen and (min-width: 450px) {
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 600px) {
|
||||||
|
height: 25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 750px) {
|
||||||
|
height: 32em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1.5em 2em;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.8em;
|
||||||
|
margin-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1em;
|
||||||
|
line-height: 1.4em;
|
||||||
|
margin: 0;
|
||||||
|
color: #747373;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
border-radius: 0 0 $cardBorderRadius $cardBorderRadius;
|
||||||
|
padding: 1em 2em;
|
||||||
|
gap: 1em;
|
||||||
|
color: #6c757d;
|
||||||
|
|
||||||
|
img {
|
||||||
|
$imageSize: 4em;
|
||||||
|
border-radius: 10em;
|
||||||
|
width: $imageSize;
|
||||||
|
height: $imageSize;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.publication-date {
|
||||||
|
font-style: italic;
|
||||||
|
color: #bdbdbd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import { Component, Input } from "@angular/core";
|
import {Component, input} from "@angular/core";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Observable } from "rxjs";
|
import {CommonModule} from "@angular/common";
|
||||||
import { CommonModule } from "@angular/common";
|
import {RouterModule} from "@angular/router";
|
||||||
import { RouterModule } from "@angular/router";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
import { MatTooltipModule } from "@angular/material/tooltip";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-list',
|
selector: 'app-publication-list',
|
||||||
templateUrl: './publication-list.component.html',
|
templateUrl: './publication-list.component.html',
|
||||||
styleUrl: './publication-list.component.scss',
|
styleUrl: './publication-list.component.scss',
|
||||||
imports: [CommonModule, RouterModule, MatTooltipModule]
|
imports: [CommonModule, RouterModule, MatTooltipModule]
|
||||||
})
|
})
|
||||||
export class PublicationListComponent {
|
export class PublicationListComponent {
|
||||||
@Input()
|
publications = input.required<Publication[]>();
|
||||||
publications$!: Observable<Publication[]>;
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<form [formGroup]="formGroup">
|
<form [formGroup]="formGroup">
|
||||||
<input name="search-query" placeholder="Search something..." formControlName="criteria" i18n-placeholder/>
|
<input name="search-query" placeholder="Search something..." formControlName="criteria" i18n-placeholder/>
|
||||||
<button type="submit" (click)="searchPublications()" matRipple>
|
<button type="submit" (click)="searchPublications()" matRipple>
|
||||||
<mat-icon>search</mat-icon>
|
<mat-icon>search</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
:host {
|
:host {
|
||||||
$borderRadiusValue: 10em;
|
$borderRadiusValue: 10em;
|
||||||
position: relative;
|
position: relative;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
form {
|
form {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
input {
|
input {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
border-radius: $borderRadiusValue;
|
border-radius: $borderRadiusValue;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: solid 1px #ddd;
|
border: solid 1px #ddd;
|
||||||
padding: .2em 2.7em .2em 1em;
|
padding: .2em 2.7em .2em 1em;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
position: absolute;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
border-radius: $borderRadiusValue;
|
|
||||||
background-color: white;
|
|
||||||
border: none;
|
|
||||||
top: 0;
|
|
||||||
right: 0;
|
|
||||||
color: #aaaaaa;
|
|
||||||
padding: .3em;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #eee;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
button {
|
||||||
|
position: absolute;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: $borderRadiusValue;
|
||||||
|
background-color: white;
|
||||||
|
border: none;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
color: #aaaaaa;
|
||||||
|
padding: .3em;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #eee;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
import { Component, inject } from "@angular/core";
|
import {Component, inject} from "@angular/core";
|
||||||
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
|
import {FormBuilder, FormControl, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MatIconModule } from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import { Router } from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publications-search-bar',
|
selector: 'app-publications-search-bar',
|
||||||
templateUrl: './publications-search-bar.component.html',
|
templateUrl: './publications-search-bar.component.html',
|
||||||
styleUrl: './publications-search-bar.component.scss',
|
styleUrl: './publications-search-bar.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
ReactiveFormsModule
|
ReactiveFormsModule
|
||||||
],
|
],
|
||||||
providers: []
|
providers: []
|
||||||
})
|
})
|
||||||
export class PublicationsSearchBarComponent {
|
export class PublicationsSearchBarComponent {
|
||||||
private formBuilder = inject(FormBuilder);
|
private formBuilder = inject(FormBuilder);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
formGroup = this.formBuilder.group({
|
formGroup = this.formBuilder.group({
|
||||||
criteria: new FormControl<string | undefined>('', [Validators.required])
|
criteria: new FormControl<string | undefined>('', [Validators.required])
|
||||||
});
|
});
|
||||||
|
|
||||||
searchPublications(): void {
|
searchPublications(): void {
|
||||||
const query = this.formGroup.controls.criteria.value
|
const query = this.formGroup.controls.criteria.value
|
||||||
|
|
||||||
if (query?.trim()) {
|
if (query?.trim()) {
|
||||||
const queryParams = { 'query' : this.formGroup.controls.criteria.value ?? '' }
|
const queryParams = {'query': this.formGroup.controls.criteria.value ?? ''}
|
||||||
this.router.navigate(['/publications'], { queryParams });
|
this.router.navigate(['/publications'], {queryParams});
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
@for(category of categories$ | async; track category) {
|
@for (category of categories(); track category.id) {
|
||||||
<div class="category {{category.isOpenned ? 'openned' : ''}}">
|
<div class="category {{category.isOpenned ? 'openned' : ''}}">
|
||||||
<div id="category-{{category.id}}" class="category-header" (click)="setOpenned(category)">
|
<div id="category-{{category.id}}" class="category-header" (click)="setOpened(category)">
|
||||||
{{category.name}}
|
{{ category.name }}
|
||||||
<mat-icon>chevron_right</mat-icon>
|
<mat-icon>chevron_right</mat-icon>
|
||||||
</div>
|
|
||||||
<div class="sub-category-container {{category.isOpenned ? 'displayed' : ''}}">
|
|
||||||
@for(subCategory of category.subCategories; track subCategory) {
|
|
||||||
<a [routerLink]="['/publications']"
|
|
||||||
[queryParams]="{'category-id': subCategory.id}"
|
|
||||||
(click)="categoryClicked.emit()"
|
|
||||||
class="sub-category">
|
|
||||||
{{subCategory.name}}
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
<div class="sub-category-container {{category.isOpenned ? 'displayed' : ''}}">
|
||||||
|
@for (subCategory of category.subCategories; track subCategory) {
|
||||||
|
<a [routerLink]="['/publications']"
|
||||||
|
[queryParams]="{'category-id': subCategory.id}"
|
||||||
|
(click)="categoryClicked.emit()"
|
||||||
|
class="sub-category">
|
||||||
|
{{ subCategory.name }}
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,57 +1,57 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
.category {
|
.category {
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #5c6bc0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category-header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: .5em 1em;
|
||||||
|
|
||||||
|
mat-icon {
|
||||||
|
transition: transform .2s ease-in-out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.openned {
|
||||||
|
.category-header {
|
||||||
|
mat-icon {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub-category-container {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sub-category-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
max-height: 0;
|
||||||
|
transition: max-height .2s ease-in-out;
|
||||||
|
background-color: #303f9f;
|
||||||
|
|
||||||
|
.sub-category {
|
||||||
|
padding: .5em 1em .5em 2em;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
transition: background-color .2s ease-in-out;
|
transition: background-color .2s ease-in-out;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
cursor: pointer;
|
background-color: #5c6bc0;
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.category-header {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: .5em 1em;
|
|
||||||
|
|
||||||
mat-icon {
|
|
||||||
transition: transform .2s ease-in-out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.openned {
|
|
||||||
.category-header {
|
|
||||||
mat-icon {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sub-category-container {
|
|
||||||
max-height: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.sub-category-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
overflow: hidden;
|
|
||||||
max-height: 0;
|
|
||||||
transition: max-height .2s ease-in-out;
|
|
||||||
background-color: #303f9f;
|
|
||||||
|
|
||||||
.sub-category {
|
|
||||||
padding: .5em 1em .5em 2em;
|
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5c6bc0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +1,59 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import { Component, EventEmitter, inject, OnInit, Output } from "@angular/core";
|
import {Component, inject, OnInit, output, Signal} from "@angular/core";
|
||||||
import { MatIconModule } from "@angular/material/icon";
|
import {MatIconModule} from "@angular/material/icon";
|
||||||
import { DisplayableCategory, SideMenuService } from "../side-menu.service";
|
import {DisplayableCategory, SideMenuService} from "../side-menu.service";
|
||||||
import { Observable } from "rxjs";
|
import {RouterModule} from "@angular/router";
|
||||||
import { RouterModule } from "@angular/router";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-categories-menu',
|
selector: 'app-categories-menu',
|
||||||
templateUrl: './categories-menu.component.html',
|
templateUrl: './categories-menu.component.html',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
MatIconModule
|
MatIconModule
|
||||||
],
|
],
|
||||||
styleUrl: './categories-menu.component.scss'
|
styleUrl: './categories-menu.component.scss'
|
||||||
})
|
})
|
||||||
export class CategoriesMenuComponent implements OnInit {
|
export class CategoriesMenuComponent implements OnInit {
|
||||||
private sideMenuService = inject(SideMenuService);
|
readonly #sideMenuService = inject(SideMenuService);
|
||||||
@Output()
|
categoryClicked = output<void>();
|
||||||
categoryClicked = new EventEmitter<void>();
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.sideMenuService.loadCategories();
|
this.#sideMenuService.loadCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
get categories$(): Observable<DisplayableCategory[]> {
|
get categories(): Signal<DisplayableCategory[]> {
|
||||||
return this.sideMenuService.categories$;
|
return this.#sideMenuService.categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenned(category: DisplayableCategory): void {
|
setOpened(category: DisplayableCategory): void {
|
||||||
if (category.isOpenned) {
|
if (category.isOpenned) {
|
||||||
const categoryDiv = document.getElementById(`category-${category.id}`);
|
const categoryDiv = document.getElementById(`category-${category.id}`);
|
||||||
if (categoryDiv) {
|
if (categoryDiv) {
|
||||||
this.closeAccordion(categoryDiv);
|
this.#closeAccordion(categoryDiv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const categoriesDivs = document.getElementsByClassName('category-header');
|
const categoriesDivs = document.getElementsByClassName('category-header');
|
||||||
Array.from(categoriesDivs)
|
Array.from(categoriesDivs)
|
||||||
.map(category => category as HTMLElement)
|
.map(category => category as HTMLElement)
|
||||||
.forEach(categoryDiv => this.closeAccordion(categoryDiv));
|
.forEach(categoryDiv => this.#closeAccordion(categoryDiv));
|
||||||
|
|
||||||
const categoryDiv = document.getElementById(`category-${category.id}`);
|
const categoryDiv = document.getElementById(`category-${category.id}`);
|
||||||
if (categoryDiv) {
|
if (categoryDiv) {
|
||||||
this.openAccordion(categoryDiv);
|
this.#openAccordion(categoryDiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sideMenuService.setOpenned(category);
|
this.#sideMenuService.setOpened(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
private closeAccordion(categoryDiv: HTMLElement): void {
|
#closeAccordion(categoryDiv: HTMLElement): void {
|
||||||
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
||||||
divContent.style.maxHeight = '0';
|
divContent.style.maxHeight = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
private openAccordion(categoryDiv: HTMLElement): void {
|
#openAccordion(categoryDiv: HTMLElement): void {
|
||||||
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
const divContent = categoryDiv?.nextElementSibling as HTMLElement;
|
||||||
divContent.style.maxHeight = `${divContent.scrollHeight}px`;
|
divContent.style.maxHeight = `${divContent.scrollHeight}px`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
<div class="menu {{ isOpenned ? 'displayed' : '' }}">
|
<div class="menu {{ isOpened() ? 'displayed' : '' }}">
|
||||||
<h1>
|
<h1>
|
||||||
<a [routerLink]="['/home']">
|
<a [routerLink]="['/home']">
|
||||||
<img src="assets/images/codiki.png" alt="logo"/>
|
<img src="assets/images/codiki.png" alt="logo"/>
|
||||||
Codiki
|
Codiki
|
||||||
</a>
|
</a>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
(click)="close()"
|
(click)="close()"
|
||||||
class="cod-button icon"
|
class="cod-button icon"
|
||||||
matTooltip="Close the menu"
|
matTooltip="Close the menu"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>close</mat-icon>
|
<mat-icon>close</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</h1>
|
</h1>
|
||||||
<h2 i18n>Categories</h2>
|
<h2 i18n>Categories</h2>
|
||||||
<app-categories-menu (categoryClicked)="close()"></app-categories-menu>
|
<app-categories-menu (categoryClicked)="close()"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="overlay {{ isOpenned ? 'displayed' : ''}}" (click)="close()"></div>
|
<div class="overlay {{ isOpened() ? 'displayed' : ''}}" (click)="close()"></div>
|
||||||
|
|||||||
@@ -1,68 +1,68 @@
|
|||||||
:host {
|
:host {
|
||||||
.menu {
|
.menu {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
$categoriesMenuWidth: 20em;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: -$categoriesMenuWidth - 1em - 1;
|
||||||
|
bottom: 0;
|
||||||
|
transition: left .2s ease-in-out;
|
||||||
|
width: $categoriesMenuWidth;
|
||||||
|
z-index: 3;
|
||||||
|
padding: 1em 0;
|
||||||
|
|
||||||
|
&.displayed {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 1em;
|
||||||
|
|
||||||
|
a {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
background-color: #3f51b5;
|
justify-content: start;
|
||||||
|
align-items: center;
|
||||||
|
gap: .5em;
|
||||||
color: white;
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
|
||||||
$categoriesMenuWidth: 20em;
|
img {
|
||||||
position: fixed;
|
$imageSize: 1.2em;
|
||||||
top: 0;
|
width: $imageSize;
|
||||||
left: -$categoriesMenuWidth - 1em - 1;
|
height: $imageSize;
|
||||||
bottom: 0;
|
|
||||||
transition: left .2s ease-in-out;
|
|
||||||
width: $categoriesMenuWidth;
|
|
||||||
z-index: 3;
|
|
||||||
padding: 1em 0;
|
|
||||||
|
|
||||||
&.displayed {
|
|
||||||
left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 1em;
|
|
||||||
|
|
||||||
a {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: start;
|
|
||||||
align-items: center;
|
|
||||||
gap: .5em;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
img {
|
|
||||||
$imageSize: 1.2em;
|
|
||||||
width: $imageSize;
|
|
||||||
height: $imageSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
padding: 0 1em;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.overlay {
|
h2 {
|
||||||
display: none;
|
padding: 0 1em;
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-color: #000;
|
|
||||||
opacity: .2;
|
|
||||||
z-index: 2;
|
|
||||||
|
|
||||||
&.displayed {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.overlay {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: #000;
|
||||||
|
opacity: .2;
|
||||||
|
z-index: 2;
|
||||||
|
|
||||||
|
&.displayed {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import { Component } from '@angular/core';
|
import {Component, signal} from '@angular/core';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import { RouterModule } from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import { CategoriesMenuComponent } from './categories-menu/categories-menu.component';
|
import {CategoriesMenuComponent} from './categories-menu/categories-menu.component';
|
||||||
import { MatRippleModule } from '@angular/material/core';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-side-menu',
|
selector: 'app-side-menu',
|
||||||
templateUrl: './side-menu.component.html',
|
templateUrl: './side-menu.component.html',
|
||||||
styleUrl: './side-menu.component.scss',
|
styleUrl: './side-menu.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CategoriesMenuComponent,
|
CategoriesMenuComponent,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
RouterModule
|
RouterModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SideMenuComponent {
|
export class SideMenuComponent {
|
||||||
isOpenned: boolean = false;
|
isOpened = signal(false);
|
||||||
|
|
||||||
open(): void {
|
open(): void {
|
||||||
this.isOpenned = true;
|
this.isOpened.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(): void {
|
close(): void {
|
||||||
this.isOpenned = false;
|
this.isOpened.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable, Signal, signal} from '@angular/core';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import {CategoryRestService} from '../../core/rest-services/category/category.rest-service';
|
||||||
import { CategoryRestService } from '../../core/rest-services/category/category.rest-service';
|
import {Category} from '../../core/rest-services/category/model/category';
|
||||||
import { Category } from '../../core/rest-services/category/model/category';
|
|
||||||
|
|
||||||
export interface DisplayableCategory {
|
export interface DisplayableCategory {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -20,68 +19,60 @@ export interface DisplayableSubCategory {
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class SideMenuService {
|
export class SideMenuService {
|
||||||
private categoryRestService = inject(CategoryRestService);
|
readonly #categoryRestService = inject(CategoryRestService);
|
||||||
private snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private categoriesSubject = new BehaviorSubject<DisplayableCategory[]>([]);
|
#categories = signal<DisplayableCategory[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
isLoaded = signal(false);
|
||||||
|
|
||||||
private mapToDisplayableCategory(category: Category): DisplayableCategory {
|
#mapToDisplayableCategory(category: Category): DisplayableCategory {
|
||||||
return {
|
return {
|
||||||
id: category.id,
|
id: category.id,
|
||||||
name: category.name,
|
name: category.name,
|
||||||
subCategories: category.subCategories.map(subCategory => this.mapToDisplayableSubCategory(subCategory)),
|
subCategories: category.subCategories.map(subCategory => this.#mapToDisplayableSubCategory(subCategory)),
|
||||||
isOpenned: false
|
isOpenned: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory {
|
#mapToDisplayableSubCategory(subCategory: Category): DisplayableSubCategory {
|
||||||
return {
|
return {
|
||||||
id: subCategory.id,
|
id: subCategory.id,
|
||||||
name: subCategory.name
|
name: subCategory.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private get categories(): DisplayableCategory[] {
|
get categories(): Signal<DisplayableCategory[]> {
|
||||||
return this.categoriesSubject.value;
|
return this.#categories.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
private save(categories: DisplayableCategory[]): void {
|
get isLoading(): Signal<boolean> {
|
||||||
this.categoriesSubject.next(categories);
|
return this.#isLoading.asReadonly();
|
||||||
}
|
|
||||||
|
|
||||||
get categories$(): Observable<DisplayableCategory[]> {
|
|
||||||
return this.categoriesSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.isLoadingSubject.asObservable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadCategories(): void {
|
loadCategories(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoading.set(true);
|
||||||
this.isLoadedSubject.next(false);
|
this.isLoaded.set(false);
|
||||||
|
|
||||||
this.categoryRestService.getCategories()
|
this.#categoryRestService.getCategories()
|
||||||
.then(categories => {
|
.then(categories => {
|
||||||
const displayableCategories = categories
|
const displayableCategories = categories
|
||||||
.filter(category => category.subCategories?.length)
|
.filter(category => category.subCategories?.length)
|
||||||
.map(category => this.mapToDisplayableCategory(category));
|
.map(category => this.#mapToDisplayableCategory(category));
|
||||||
this.categoriesSubject.next(displayableCategories);
|
this.#categories.set(displayableCategories);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while loading categories.`;
|
const errorMessage = $localize`An error occured while loading categories.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoadingSubject.next(false);
|
this.#isLoading.set(false);
|
||||||
this.isLoadedSubject.next(true);
|
this.isLoaded.set(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenned(category: DisplayableCategory): void {
|
setOpened(category: DisplayableCategory): void {
|
||||||
const categories = this.categories;
|
const categories = this.#categories();
|
||||||
const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id);
|
const matchingCategory = categories.find(categoryTemp => categoryTemp.id === category.id);
|
||||||
if (matchingCategory) {
|
if (matchingCategory) {
|
||||||
const actualOpennedCategory = categories.find(category => category.isOpenned);
|
const actualOpennedCategory = categories.find(category => category.isOpenned);
|
||||||
@@ -91,7 +82,7 @@ export class SideMenuService {
|
|||||||
categories.forEach(categoryTemp => categoryTemp.isOpenned = false);
|
categories.forEach(categoryTemp => categoryTemp.isOpenned = false);
|
||||||
matchingCategory.isOpenned = true;
|
matchingCategory.isOpenned = true;
|
||||||
}
|
}
|
||||||
this.save(categories);
|
this.#categories.set(categories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<button type="submit"
|
<button type="submit"
|
||||||
class="cod-button {{color}}"
|
class="cod-button {{color()}}"
|
||||||
[disabled]="disabled || requestPending"
|
[disabled]="disabled() || requestPending()"
|
||||||
(click)="click.emit()"
|
(click)="click.emit()"
|
||||||
matRipple>
|
matRipple>
|
||||||
@if (requestPending) {
|
@if (requestPending()) {
|
||||||
<mat-spinner class="spinner {{color}}" [diameter]="25"></mat-spinner>
|
<mat-spinner class="spinner {{color()}}" [diameter]="25"></mat-spinner>
|
||||||
}
|
}
|
||||||
<span>
|
<span>
|
||||||
<ng-content/>
|
<ng-content/>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
button {
|
button {
|
||||||
padding: .8em 1.2em;
|
padding: .8em 1.2em;
|
||||||
border-radius: 10em;
|
border-radius: 10em;
|
||||||
border: none;
|
border: none;
|
||||||
background-color: #3f51b5;
|
background-color: #3f51b5;
|
||||||
color: white;
|
color: white;
|
||||||
transition: background-color .2s ease-in-out;
|
transition: background-color .2s ease-in-out;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #5b6ed8;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.secondary {
|
||||||
|
color: #3f51b5;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #5b6ed8;
|
background-color: #f2f4ff;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.secondary {
|
&:disabled {
|
||||||
color: #3f51b5;
|
background-color: #6d7ac5;
|
||||||
background-color: white;
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
mat-spinner {
|
||||||
background-color: #f2f4ff;
|
position: absolute;
|
||||||
cursor: pointer;
|
top: calc(50% - 12px);
|
||||||
}
|
left: calc(50% - 12px);
|
||||||
}
|
}
|
||||||
|
|
||||||
&:disabled {
|
|
||||||
background-color: #6d7ac5;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
mat-spinner {
|
|
||||||
position: absolute;
|
|
||||||
top: calc(50% - 12px);
|
|
||||||
left: calc(50% - 12px);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::ng-deep .spinner circle {
|
:host ::ng-deep .spinner circle {
|
||||||
stroke: white;
|
stroke: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::ng-deep .spinner.secondary circle {
|
:host ::ng-deep .spinner.secondary circle {
|
||||||
stroke: #3f51b5;
|
stroke: #3f51b5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
|
import {Component, input, output} from "@angular/core";
|
||||||
import { Component, EventEmitter, Input, Output } from "@angular/core";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||||
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-submit-button',
|
selector: 'app-submit-button',
|
||||||
templateUrl: 'submit-button.component.html',
|
templateUrl: 'submit-button.component.html',
|
||||||
styleUrl: 'submit-button.component.scss',
|
styleUrl: 'submit-button.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatProgressSpinnerModule
|
MatProgressSpinnerModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SubmitButtonComponent {
|
export class SubmitButtonComponent {
|
||||||
@Input() requestPending: boolean = false;
|
requestPending = input.required<boolean>();
|
||||||
@Input() label: string = '';
|
label = input<string>();
|
||||||
@Input() disabled: boolean = false;
|
disabled = input<boolean>(false);
|
||||||
@Input() color?: 'secondary';
|
color = input<'secondary' | undefined>('secondary');
|
||||||
@Output() click = new EventEmitter<void>();
|
click = output<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { inject } from "@angular/core";
|
import {inject} from "@angular/core";
|
||||||
import { CanActivateFn, Router } from "@angular/router";
|
import {CanActivateFn, Router} from "@angular/router";
|
||||||
import { AuthenticationService } from "../service/authentication.service";
|
import {AuthenticationService} from "../service/authentication.service";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
export const alreadyAuthenticatedGuard: CanActivateFn = () => {
|
export const alreadyAuthenticatedGuard: CanActivateFn = () => {
|
||||||
const authenticationService = inject(AuthenticationService);
|
const authenticationService = inject(AuthenticationService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
const snackBar = inject(MatSnackBar);
|
const snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
if (authenticationService.isAuthenticated()) {
|
if (authenticationService.isAuthenticated()) {
|
||||||
router.navigate(['/home']);
|
router.navigate(['/home']);
|
||||||
snackBar.open($localize`You can't access to this page because you are already authenticated.`, $localize`Close`, { duration: 5000 });
|
snackBar.open($localize`You can't access to this page because you are already authenticated.`, $localize`Close`, {duration: 5000});
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import { inject } from "@angular/core";
|
import {inject} from "@angular/core";
|
||||||
import { CanActivateFn, Router } from "@angular/router";
|
import {CanActivateFn, Router} from "@angular/router";
|
||||||
import { AuthenticationService } from "../service/authentication.service";
|
import {AuthenticationService} from "../service/authentication.service";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
|
|
||||||
export const authenticationGuard: CanActivateFn = async () => {
|
export const authenticationGuard: CanActivateFn = async () => {
|
||||||
const authenticationService = inject(AuthenticationService);
|
const authenticationService = inject(AuthenticationService);
|
||||||
const router = inject(Router);
|
const router = inject(Router);
|
||||||
const snackBar = inject(MatSnackBar);
|
const snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
await authenticationService.checkIsAuthenticated();
|
await authenticationService.checkIsAuthenticated();
|
||||||
|
|
||||||
if (authenticationService.isAuthenticated()) {
|
if (authenticationService.isAuthenticated()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
router.navigate(['/login']);
|
router.navigate(['/login']);
|
||||||
snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, { duration: 5000 });
|
snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, {duration: 5000});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,78 +1,77 @@
|
|||||||
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
|
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
|
||||||
import { inject, Injectable } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { catchError, filter, Observable, Subject, switchMap, take, throwError } from 'rxjs';
|
import {catchError, filter, Observable, Subject, switchMap, take, throwError} from 'rxjs';
|
||||||
import { RefreshTokenRequest } from '../rest-services/user/model/refresh-token.model';
|
import {UserRestService} from '../rest-services/user/user.rest-service';
|
||||||
import { UserRestService } from '../rest-services/user/user.rest-service';
|
import {AuthenticationService} from '../service/authentication.service';
|
||||||
import { AuthenticationService } from '../service/authentication.service';
|
import {Router} from '@angular/router';
|
||||||
import { Router } from '@angular/router';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JwtInterceptor implements HttpInterceptor {
|
export class JwtInterceptor implements HttpInterceptor {
|
||||||
private readonly authenticationService = inject(AuthenticationService);
|
private readonly authenticationService = inject(AuthenticationService);
|
||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
private readonly userRestService = inject(UserRestService);
|
private readonly userRestService = inject(UserRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private isRefreshingToken = false;
|
private isRefreshingToken = false;
|
||||||
private refreshTokenSubject = new Subject<string | undefined>();
|
private refreshTokenSubject = new Subject<string | undefined>();
|
||||||
|
|
||||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
|
let requestWithAuthentication = request;
|
||||||
|
|
||||||
|
const jwt = this.authenticationService.getToken();
|
||||||
|
if (jwt) {
|
||||||
|
requestWithAuthentication = this.addTokenInHeaders(request, jwt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next.handle(requestWithAuthentication)
|
||||||
|
.pipe(
|
||||||
|
catchError(error => {
|
||||||
|
if (error instanceof HttpErrorResponse && error.status === 401) {
|
||||||
|
return this.handleAunauthorizedError(request, next, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return throwError(() => error);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleAunauthorizedError(request: HttpRequest<any>, next: HttpHandler, initialError: any): Observable<HttpEvent<any>> {
|
||||||
|
if (!this.isRefreshingToken) {
|
||||||
|
this.isRefreshingToken = true;
|
||||||
|
this.refreshTokenSubject.next(undefined);
|
||||||
|
|
||||||
|
this.authenticationService.refreshToken()
|
||||||
|
.then(refreshTokenResponse => {
|
||||||
|
this.refreshTokenSubject.next(refreshTokenResponse.accessToken);
|
||||||
|
})
|
||||||
|
.catch(() => this.handleNoRefreshToken(initialError))
|
||||||
|
.finally(() => this.isRefreshingToken = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.refreshTokenSubject.pipe(
|
||||||
|
filter(token => !!token),
|
||||||
|
take(1),
|
||||||
|
switchMap(token => {
|
||||||
let requestWithAuthentication = request;
|
let requestWithAuthentication = request;
|
||||||
|
if (token) {
|
||||||
const jwt = this.authenticationService.getToken();
|
requestWithAuthentication = this.addTokenInHeaders(request, token)
|
||||||
if (jwt) {
|
|
||||||
requestWithAuthentication = this.addTokenInHeaders(request, jwt);
|
|
||||||
}
|
}
|
||||||
|
return next.handle(requestWithAuthentication);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return next.handle(requestWithAuthentication)
|
private addTokenInHeaders(request: HttpRequest<any>, token: string): HttpRequest<any> {
|
||||||
.pipe(
|
return request.clone({
|
||||||
catchError(error => {
|
headers: request.headers.set('Authorization', `Bearer ${token}`)
|
||||||
if (error instanceof HttpErrorResponse && error.status === 401) {
|
});
|
||||||
return this.handleAunauthorizedError(request, next, error);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return throwError(() => error);
|
private handleNoRefreshToken(initialError: any): Observable<HttpEvent<any>> {
|
||||||
})
|
this.router.navigate(['/login']);
|
||||||
);
|
this.refreshTokenSubject.next(undefined);
|
||||||
}
|
this.authenticationService.unauthenticate();
|
||||||
|
this.snackBar.open($localize`You are unauthenticated. Please, re-authenticate before retrying your action.`, $localize`Close`, {duration: 5000});
|
||||||
private handleAunauthorizedError(request: HttpRequest<any>, next: HttpHandler, initialError: any): Observable<HttpEvent<any>> {
|
return throwError(() => initialError);
|
||||||
if (!this.isRefreshingToken) {
|
}
|
||||||
this.isRefreshingToken = true;
|
}
|
||||||
this.refreshTokenSubject.next(undefined);
|
|
||||||
|
|
||||||
this.authenticationService.refreshToken()
|
|
||||||
.then(refreshTokenResponse => {
|
|
||||||
this.refreshTokenSubject.next(refreshTokenResponse.accessToken);
|
|
||||||
})
|
|
||||||
.catch(() => this.handleNoRefreshToken(initialError))
|
|
||||||
.finally(() => this.isRefreshingToken = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.refreshTokenSubject.pipe(
|
|
||||||
filter(token => !!token),
|
|
||||||
take(1),
|
|
||||||
switchMap(token => {
|
|
||||||
let requestWithAuthentication = request;
|
|
||||||
if (token) {
|
|
||||||
requestWithAuthentication = this.addTokenInHeaders(request, token)
|
|
||||||
}
|
|
||||||
return next.handle(requestWithAuthentication);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private addTokenInHeaders(request: HttpRequest<any>, token: string): HttpRequest<any> {
|
|
||||||
return request.clone({
|
|
||||||
headers: request.headers.set('Authorization', `Bearer ${token}`)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private handleNoRefreshToken(initialError: any): Observable<HttpEvent<any>> {
|
|
||||||
this.router.navigate(['/login']);
|
|
||||||
this.refreshTokenSubject.next(undefined);
|
|
||||||
this.authenticationService.unauthenticate();
|
|
||||||
this.snackBar.open($localize`You are unauthenticated. Please, re-authenticate before retrying your action.`, $localize`Close`, { duration: 5000 });
|
|
||||||
return throwError(() => initialError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export interface FormError {
|
export interface FormError {
|
||||||
fieldName: string;
|
fieldName: string;
|
||||||
errorMessage: string;
|
errorMessage: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
pseudo: string;
|
pseudo: string;
|
||||||
photoId?: string;
|
photoId?: string;
|
||||||
roles: string[];
|
roles: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import {lastValueFrom} from 'rxjs';
|
||||||
import { Category } from './model/category';
|
import {Category} from './model/category';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface Category {
|
export interface Category {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
subCategories: Category[];
|
subCategories: Category[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export interface Picture {
|
export interface Picture {
|
||||||
id: string,
|
id: string,
|
||||||
publishedAt: Date
|
publishedAt: Date
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import { Picture } from "./model/picture";
|
import {Picture} from "./model/picture";
|
||||||
import { lastValueFrom } from "rxjs";
|
import {lastValueFrom} from "rxjs";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class PictureRestService {
|
export class PictureRestService {
|
||||||
private readonly httpClient = inject(HttpClient);
|
private readonly httpClient = inject(HttpClient);
|
||||||
|
|
||||||
getAllOfCurrentUser(): Promise<Picture[]> {
|
getAllOfCurrentUser(): Promise<Picture[]> {
|
||||||
return lastValueFrom(this.httpClient.get<Picture[]>('/api/pictures/current-user'));
|
return lastValueFrom(this.httpClient.get<Picture[]>('/api/pictures/current-user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadPicture(pictureFile: File): Promise<string> {
|
uploadPicture(pictureFile: File): Promise<string> {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", pictureFile);
|
formData.append("file", pictureFile);
|
||||||
return lastValueFrom(this.httpClient.post<string>('/api/pictures', formData));
|
return lastValueFrom(this.httpClient.post<string>('/api/pictures', formData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface Author {
|
export interface Author {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export interface PreviewContentRequest {
|
export interface PreviewContentRequest {
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreviewContentResponse {
|
export interface PreviewContentResponse {
|
||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
import { Author } from "./author";
|
import {Author} from "./author";
|
||||||
|
|
||||||
export interface Publication {
|
export interface Publication {
|
||||||
id: string;
|
id: string;
|
||||||
key: string;
|
key: string;
|
||||||
title: string;
|
title: string;
|
||||||
text: string;
|
text: string;
|
||||||
parsedText: string;
|
parsedText: string;
|
||||||
description: string;
|
description: string;
|
||||||
creationDate: Date;
|
creationDate: Date;
|
||||||
illustrationId: string;
|
illustrationId: string;
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
author: Author;
|
author: Author;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_PUBLICATION: Publication = {
|
||||||
|
id: '',
|
||||||
|
key: '',
|
||||||
|
title: '',
|
||||||
|
text: '',
|
||||||
|
parsedText: '',
|
||||||
|
description: '',
|
||||||
|
creationDate: new Date(),
|
||||||
|
illustrationId: '',
|
||||||
|
categoryId: '',
|
||||||
|
author: {
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
image: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { last, lastValueFrom } from 'rxjs';
|
import {lastValueFrom} from 'rxjs';
|
||||||
import { Publication } from './model/publication';
|
import {Publication} from './model/publication';
|
||||||
import { PreviewContentRequest, PreviewContentResponse } from './model/preview';
|
import {PreviewContentRequest, PreviewContentResponse} from './model/preview';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -29,7 +29,7 @@ export class PublicationRestService {
|
|||||||
search(searchCriteria: string): Promise<Publication[]> {
|
search(searchCriteria: string): Promise<Publication[]> {
|
||||||
let params = new HttpParams();
|
let params = new HttpParams();
|
||||||
params = params.set('query', searchCriteria);
|
params = params.set('query', searchCriteria);
|
||||||
return lastValueFrom(this.httpClient.get<Publication[]>('/api/publications', { params }));
|
return lastValueFrom(this.httpClient.get<Publication[]>('/api/publications', {params}));
|
||||||
}
|
}
|
||||||
|
|
||||||
preview(request: PreviewContentRequest): Promise<PreviewContentResponse> {
|
preview(request: PreviewContentRequest): Promise<PreviewContentResponse> {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
export interface LoginRequest {
|
export interface LoginRequest {
|
||||||
email?: string;
|
email?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginResponse {
|
export interface LoginResponse {
|
||||||
tokenType: string,
|
tokenType: string,
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
refreshToken: string
|
refreshToken: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export interface RefreshTokenRequest {
|
export interface RefreshTokenRequest {
|
||||||
refreshTokenValue: string;
|
refreshTokenValue: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export interface SigninRequest {
|
export interface SigninRequest {
|
||||||
pseudo?: string;
|
pseudo?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import {HttpClient} from "@angular/common/http";
|
||||||
import { Injectable, inject } from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import { LoginRequest, LoginResponse } from "./model/login.model";
|
import {LoginRequest, LoginResponse} from "./model/login.model";
|
||||||
import { lastValueFrom } from "rxjs";
|
import {lastValueFrom} from "rxjs";
|
||||||
import { SigninRequest } from "./model/signin.model";
|
import {SigninRequest} from "./model/signin.model";
|
||||||
import { RefreshTokenRequest } from "./model/refresh-token.model";
|
import {RefreshTokenRequest} from "./model/refresh-token.model";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class UserRestService {
|
export class UserRestService {
|
||||||
private httpClient = inject(HttpClient);
|
private httpClient = inject(HttpClient);
|
||||||
|
|
||||||
login(request: LoginRequest): Promise<LoginResponse> {
|
login(request: LoginRequest): Promise<LoginResponse> {
|
||||||
return lastValueFrom(this.httpClient.post<LoginResponse>('/api/users/login', request));
|
return lastValueFrom(this.httpClient.post<LoginResponse>('/api/users/login', request));
|
||||||
}
|
}
|
||||||
|
|
||||||
signin(request: SigninRequest): Promise<void> {
|
signin(request: SigninRequest): Promise<void> {
|
||||||
return lastValueFrom(this.httpClient.post<void>('/api/users', request));
|
return lastValueFrom(this.httpClient.post<void>('/api/users', request));
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshToken(request: RefreshTokenRequest): Promise<LoginResponse> {
|
refreshToken(request: RefreshTokenRequest): Promise<LoginResponse> {
|
||||||
return lastValueFrom(this.httpClient.post<LoginResponse>('/api/users/refresh-token', request));
|
return lastValueFrom(this.httpClient.post<LoginResponse>('/api/users/refresh-token', request));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,146 +1,146 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable} from "@angular/core";
|
||||||
import { BehaviorSubject, interval } from "rxjs";
|
import {BehaviorSubject, interval} from "rxjs";
|
||||||
import { User } from "../model/User";
|
import {User} from "../model/User";
|
||||||
import { UserRestService } from "../rest-services/user/user.rest-service";
|
import {UserRestService} from "../rest-services/user/user.rest-service";
|
||||||
import { RefreshTokenRequest } from "../rest-services/user/model/refresh-token.model";
|
import {RefreshTokenRequest} from "../rest-services/user/model/refresh-token.model";
|
||||||
import { LoginResponse } from "../rest-services/user/model/login.model";
|
import {LoginResponse} from "../rest-services/user/model/login.model";
|
||||||
|
|
||||||
const JWT_PARAM = 'jwt';
|
const JWT_PARAM = 'jwt';
|
||||||
const REFRESH_TOKEN_PARAM = 'refresh-token';
|
const REFRESH_TOKEN_PARAM = 'refresh-token';
|
||||||
|
|
||||||
interface UserDetails {
|
interface UserDetails {
|
||||||
sub: string;
|
sub: string;
|
||||||
exp: number;
|
exp: number;
|
||||||
email: string;
|
email: string;
|
||||||
pseudo: string;
|
pseudo: string;
|
||||||
roles: string;
|
roles: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthenticationService {
|
export class AuthenticationService {
|
||||||
private readonly AUTHENTICATION_CHECKING_PERIOD = 5 * 60 * 1000;
|
private readonly AUTHENTICATION_CHECKING_PERIOD = 5 * 60 * 1000;
|
||||||
private isAuthenticatedSubject = new BehaviorSubject<boolean>(false);
|
private isAuthenticatedSubject = new BehaviorSubject<boolean>(false);
|
||||||
private readonly userRestService = inject(UserRestService);
|
private readonly userRestService = inject(UserRestService);
|
||||||
|
|
||||||
startAuthenticationCheckingProcess(): void {
|
startAuthenticationCheckingProcess(): void {
|
||||||
this.checkIsAuthenticated();
|
this.checkIsAuthenticated();
|
||||||
interval(this.AUTHENTICATION_CHECKING_PERIOD)
|
interval(this.AUTHENTICATION_CHECKING_PERIOD)
|
||||||
.subscribe(() => this.checkIsAuthenticated());
|
.subscribe(() => this.checkIsAuthenticated());
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate(token: string, refreshToken: string): void {
|
||||||
|
localStorage.setItem(JWT_PARAM, token);
|
||||||
|
localStorage.setItem(REFRESH_TOKEN_PARAM, refreshToken);
|
||||||
|
this.isAuthenticatedSubject.next(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
unauthenticate(): void {
|
||||||
|
localStorage.removeItem(JWT_PARAM);
|
||||||
|
localStorage.removeItem(REFRESH_TOKEN_PARAM);
|
||||||
|
this.isAuthenticatedSubject.next(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
isAuthenticated(): boolean {
|
||||||
|
return this.isAuthenticatedSubject.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getAuthenticatedUser(): User | undefined {
|
||||||
|
return this.extractUserFromLocalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
getToken(): string | undefined {
|
||||||
|
return localStorage.getItem(JWT_PARAM) ?? undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRefreshToken(): string | undefined {
|
||||||
|
return localStorage.getItem(REFRESH_TOKEN_PARAM) ?? undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
isTokenExpired(): boolean {
|
||||||
|
let result = true;
|
||||||
|
|
||||||
|
const userDetails = this.extractUserDetails();
|
||||||
|
|
||||||
|
if (userDetails) {
|
||||||
|
const expirationDate = new Date(userDetails.exp * 1000);
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
result = expirationDate < now;
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticate(token: string, refreshToken: string): void {
|
return result;
|
||||||
localStorage.setItem(JWT_PARAM, token);
|
}
|
||||||
localStorage.setItem(REFRESH_TOKEN_PARAM, refreshToken);
|
|
||||||
this.isAuthenticatedSubject.next(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
unauthenticate(): void {
|
refreshToken(): Promise<LoginResponse> {
|
||||||
localStorage.removeItem(JWT_PARAM);
|
const refreshToken = this.getRefreshToken();
|
||||||
localStorage.removeItem(REFRESH_TOKEN_PARAM);
|
if (refreshToken) {
|
||||||
this.isAuthenticatedSubject.next(false);
|
const refreshTokenRequest: RefreshTokenRequest = {
|
||||||
}
|
refreshTokenValue: refreshToken
|
||||||
|
};
|
||||||
isAuthenticated(): boolean {
|
return this.userRestService.refreshToken(refreshTokenRequest)
|
||||||
return this.isAuthenticatedSubject.value;
|
.then(refreshTokenResponse => {
|
||||||
}
|
this.authenticate(refreshTokenResponse.accessToken, refreshTokenResponse.refreshToken);
|
||||||
|
return refreshTokenResponse;
|
||||||
getAuthenticatedUser(): User | undefined {
|
|
||||||
return this.extractUserFromLocalStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
getToken(): string | undefined {
|
|
||||||
return localStorage.getItem(JWT_PARAM) ?? undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
getRefreshToken(): string | undefined {
|
|
||||||
return localStorage.getItem(REFRESH_TOKEN_PARAM) ?? undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
isTokenExpired(): boolean {
|
|
||||||
let result = true;
|
|
||||||
|
|
||||||
const userDetails = this.extractUserDetails();
|
|
||||||
|
|
||||||
if (userDetails) {
|
|
||||||
const expirationDate = new Date(userDetails.exp * 1000);
|
|
||||||
const now = new Date();
|
|
||||||
|
|
||||||
result = expirationDate < now;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
refreshToken(): Promise<LoginResponse> {
|
|
||||||
const refreshToken = this.getRefreshToken();
|
|
||||||
if (refreshToken) {
|
|
||||||
const refreshTokenRequest: RefreshTokenRequest = {
|
|
||||||
refreshTokenValue: refreshToken
|
|
||||||
};
|
|
||||||
return this.userRestService.refreshToken(refreshTokenRequest)
|
|
||||||
.then(refreshTokenResponse => {
|
|
||||||
this.authenticate(refreshTokenResponse.accessToken, refreshTokenResponse.refreshToken);
|
|
||||||
return refreshTokenResponse;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.reject('No any refresh token found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIsAuthenticated(): Promise<void> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const isTokenExpired = this.isTokenExpired();
|
|
||||||
if (isTokenExpired) {
|
|
||||||
if (this.getRefreshToken()) {
|
|
||||||
this.refreshToken()
|
|
||||||
.then(() => resolve())
|
|
||||||
.catch(() => reject());
|
|
||||||
} else {
|
|
||||||
this.isAuthenticatedSubject.next(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.isAuthenticatedSubject.next(true);
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractUserFromLocalStorage(): User | undefined {
|
return Promise.reject('No any refresh token found.');
|
||||||
let result: User | undefined;
|
}
|
||||||
|
|
||||||
const userDetails = this.extractUserDetails();
|
checkIsAuthenticated(): Promise<void> {
|
||||||
if (userDetails) {
|
return new Promise((resolve, reject) => {
|
||||||
const user = this.convertToUser(userDetails);
|
const isTokenExpired = this.isTokenExpired();
|
||||||
result = user;
|
if (isTokenExpired) {
|
||||||
|
if (this.getRefreshToken()) {
|
||||||
|
this.refreshToken()
|
||||||
|
.then(() => resolve())
|
||||||
|
.catch(() => reject());
|
||||||
|
} else {
|
||||||
|
this.isAuthenticatedSubject.next(false);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.isAuthenticatedSubject.next(true);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
private extractUserFromLocalStorage(): User | undefined {
|
||||||
|
let result: User | undefined;
|
||||||
|
|
||||||
|
const userDetails = this.extractUserDetails();
|
||||||
|
if (userDetails) {
|
||||||
|
const user = this.convertToUser(userDetails);
|
||||||
|
result = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractUserDetails(): UserDetails | undefined {
|
return result;
|
||||||
let result: UserDetails | undefined = undefined;
|
}
|
||||||
|
|
||||||
const token = localStorage.getItem(JWT_PARAM);
|
private extractUserDetails(): UserDetails | undefined {
|
||||||
|
let result: UserDetails | undefined = undefined;
|
||||||
|
|
||||||
const tokenParts = token?.split('.');
|
const token = localStorage.getItem(JWT_PARAM);
|
||||||
if (tokenParts?.length === 3 && tokenParts[1].length) {
|
|
||||||
const decodedTokenPart = atob(tokenParts[1]);
|
|
||||||
const userDetails: UserDetails = JSON.parse(decodedTokenPart);
|
|
||||||
result = userDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
const tokenParts = token?.split('.');
|
||||||
|
if (tokenParts?.length === 3 && tokenParts[1].length) {
|
||||||
|
const decodedTokenPart = atob(tokenParts[1]);
|
||||||
|
const userDetails: UserDetails = JSON.parse(decodedTokenPart);
|
||||||
|
result = userDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertToUser(userDetails: UserDetails): User {
|
return result;
|
||||||
return {
|
}
|
||||||
id: userDetails.sub,
|
|
||||||
email: userDetails.email,
|
private convertToUser(userDetails: UserDetails): User {
|
||||||
pseudo: userDetails.pseudo,
|
return {
|
||||||
roles: userDetails.roles.split(',')
|
id: userDetails.sub,
|
||||||
};
|
email: userDetails.email,
|
||||||
}
|
pseudo: userDetails.pseudo,
|
||||||
}
|
roles: userDetails.roles.split(',')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { CategoryRestService } from '../rest-services/category/category.rest-service';
|
import {CategoryRestService} from '../rest-services/category/category.rest-service';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import { Category } from '../rest-services/category/model/category';
|
import {Category} from '../rest-services/category/model/category';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export function copy<T>(object: T): T {
|
export function copy<T>(object: T): T {
|
||||||
return JSON.parse(
|
return JSON.parse(
|
||||||
JSON.stringify(object)
|
JSON.stringify(object)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Component, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import { AuthenticationService } from '../../core/service/authentication.service';
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
import { Router } from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-disconnection',
|
selector: 'app-disconnection',
|
||||||
imports: [MatProgressSpinnerModule],
|
imports: [MatProgressSpinnerModule],
|
||||||
templateUrl: './disconnection.component.html',
|
templateUrl: './disconnection.component.html',
|
||||||
styleUrl: './disconnection.component.scss'
|
styleUrl: './disconnection.component.scss'
|
||||||
})
|
})
|
||||||
export class DisconnectionComponent implements OnInit {
|
export class DisconnectionComponent implements OnInit {
|
||||||
private authenticationService = inject(AuthenticationService);
|
private authenticationService = inject(AuthenticationService);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<h1 i18n>Last publications</h1>
|
<h1 i18n>Last publications</h1>
|
||||||
@if ((isLoading$ | async) === true) {
|
@if ((isLoading())) {
|
||||||
<h2 i18n>Publications loading...</h2>
|
<h2 i18n>Publications loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
} @else {
|
} @else {
|
||||||
@if ((publications$ | async) != []) {
|
@if (publications(); as publications) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications"/>
|
||||||
} @else {
|
} @else {
|
||||||
<h2 i18n>No any publication.</h2>
|
<h2 i18n>No any publication.</h2>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,26 @@
|
|||||||
import { Component, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnInit} from '@angular/core';
|
||||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import { Observable } from 'rxjs';
|
import {PublicationListComponent} from '../../components/publication-list/publication-list.component';
|
||||||
import { PublicationListComponent } from '../../components/publication-list/publication-list.component';
|
import {HomeService} from './home.service';
|
||||||
import { Publication } from '../../core/rest-services/publications/model/publication';
|
import {CommonModule} from '@angular/common';
|
||||||
import { HomeService } from './home.service';
|
|
||||||
import { CommonModule } from '@angular/common';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-home',
|
selector: 'app-home',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
PublicationListComponent
|
PublicationListComponent
|
||||||
],
|
],
|
||||||
templateUrl: './home.component.html',
|
templateUrl: './home.component.html',
|
||||||
styleUrl: './home.component.scss',
|
styleUrl: './home.component.scss',
|
||||||
providers: [HomeService]
|
providers: [HomeService]
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements OnInit {
|
||||||
private homeService = inject(HomeService);
|
readonly #homeService = inject(HomeService);
|
||||||
|
isLoading = this.#homeService.isLoading;
|
||||||
get isLoading$(): Observable<boolean> {
|
publications = this.#homeService.publications;
|
||||||
return this.homeService.isLoading$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
|
||||||
return this.homeService.publications$;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.homeService.startLatestPublicationsRetrieving();
|
this.#homeService.startLatestPublicationsRetrieving();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,34 @@
|
|||||||
import { Injectable, inject } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
import {MatSnackBar} from "@angular/material/snack-bar"
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar"
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class HomeService {
|
export class HomeService {
|
||||||
private publicationRestService = inject(PublicationRestService);
|
private publicationRestService = inject(PublicationRestService);
|
||||||
private snackBar = inject(MatSnackBar);
|
private snackBar = inject(MatSnackBar);
|
||||||
|
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoadingSubject = signal<boolean>(false);
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
get isLoading(): Signal<boolean> {
|
||||||
return this.isLoadingSubject.asObservable();
|
return this.#isLoadingSubject.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
startLatestPublicationsRetrieving(): void {
|
startLatestPublicationsRetrieving(): void {
|
||||||
this.isLoadingSubject.next(true);
|
this.#isLoadingSubject.set(true);
|
||||||
|
|
||||||
this.publicationRestService.getLatest()
|
this.publicationRestService.getLatest()
|
||||||
.then(publications => this.publicationsSubject.next(publications))
|
.then(publications => this.#publications.set(publications))
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occurred while retrieving latest publications...`;
|
const errorMessage = $localize`An error occurred while retrieving latest publications...`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
})
|
})
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
.finally(() => this.#isLoadingSubject.set(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
<form [formGroup]="loginForm" (submit)="performLogin()" class="cod-form card" ngNativeValidate>
|
<form [formGroup]="loginForm" (submit)="performLogin()" class="cod-form card" ngNativeValidate>
|
||||||
<h1 i18n>Login</h1>
|
<h1 i18n>Login</h1>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>mail</mat-icon>
|
<mat-icon>mail</mat-icon>
|
||||||
<label for="email" i18n>
|
<label for="email" i18n>
|
||||||
Email address
|
Email address
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="email" id="email" formControlName="email" autocomplete="email" required />
|
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="password" i18n>
|
<label for="password" i18n>
|
||||||
Password
|
Password
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="password" formControlName="password" required />
|
<input type="password" id="password" formControlName="password" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions reversed">
|
<div class="actions reversed">
|
||||||
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
||||||
<a [routerLink]="['/signin']" class="cod-button secondary" matRipple i18n>Create an account</a>
|
<a [routerLink]="['/signin']" class="cod-button secondary" matRipple i18n>Create an account</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
import {MatSnackBarModule} from '@angular/material/snack-bar';
|
||||||
import { Subscription, debounceTime, map } from 'rxjs';
|
import {debounceTime, map, Subscription} from 'rxjs';
|
||||||
import { LoginService } from './login.service';
|
import {LoginService} from './login.service';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { RouterModule } from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import { SubmitButtonComponent } from "../../components/submit-button/submit-button.component";
|
import {SubmitButtonComponent} from "../../components/submit-button/submit-button.component";
|
||||||
import { MatRippleModule } from '@angular/material/core';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: './login.component.scss',
|
styleUrl: './login.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
SubmitButtonComponent
|
SubmitButtonComponent
|
||||||
],
|
],
|
||||||
providers: [LoginService, MatSnackBarModule]
|
providers: [LoginService, MatSnackBarModule]
|
||||||
})
|
})
|
||||||
export class LoginComponent implements OnInit, OnDestroy {
|
export class LoginComponent implements OnInit, OnDestroy {
|
||||||
private loginService = inject(LoginService);
|
private loginService = inject(LoginService);
|
||||||
@@ -52,10 +52,10 @@ export class LoginComponent implements OnInit, OnDestroy {
|
|||||||
this.subscriptions.push(passwordSubscription)
|
this.subscriptions.push(passwordSubscription)
|
||||||
|
|
||||||
const stateSubscription = this.loginService.state$
|
const stateSubscription = this.loginService.state$
|
||||||
.subscribe(state => {
|
.subscribe(state => {
|
||||||
this.loginForm.controls['email'].setValue(state.request.email, { emitEvent: false });
|
this.loginForm.controls['email'].setValue(state.request.email, {emitEvent: false});
|
||||||
this.loginForm.controls['password'].setValue(state.request.password, { emitEvent: false });
|
this.loginForm.controls['password'].setValue(state.request.password, {emitEvent: false});
|
||||||
});
|
});
|
||||||
this.subscriptions.push(stateSubscription);
|
this.subscriptions.push(stateSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import { copy } from '../../core/utils/ObjectUtils';
|
import {copy} from '../../core/utils/ObjectUtils';
|
||||||
import { FormError } from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
import { UserRestService } from '../../core/rest-services/user/user.rest-service';
|
import {UserRestService} from '../../core/rest-services/user/user.rest-service';
|
||||||
import { LoginRequest } from '../../core/rest-services/user/model/login.model';
|
import {LoginRequest} from '../../core/rest-services/user/model/login.model';
|
||||||
import { AuthenticationService } from '../../core/service/authentication.service';
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { Router } from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
|
|
||||||
export interface LoginState {
|
export interface LoginState {
|
||||||
request: LoginRequest;
|
request: LoginRequest;
|
||||||
@@ -65,15 +65,15 @@ export class LoginService {
|
|||||||
.login(state.request)
|
.login(state.request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.authenticationService.authenticate(response.accessToken, response.refreshToken);
|
this.authenticationService.authenticate(response.accessToken, response.refreshToken);
|
||||||
this.snackBar.open($localize`Authentication succeeded!`, $localize`Close`, { duration: 5000 });
|
this.snackBar.open($localize`Authentication succeeded!`, $localize`Close`, {duration: 5000});
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.snackBar.open($localize`Authentication failed.`, $localize`Close`, { duration: 5000 });
|
this.snackBar.open($localize`Authentication failed.`, $localize`Close`, {duration: 5000});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.snackBar.open($localize`Please, fill the inputs before send.`, $localize`Close`, { duration: 5000 });
|
this.snackBar.open($localize`Please, fill the inputs before send.`, $localize`Close`, {duration: 5000});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
<h1 i18n>Your publications</h1>
|
<h1 i18n>Your publications</h1>
|
||||||
|
|
||||||
<a [routerLink]="['/publications/new']"
|
<a [routerLink]="['/publications/new']"
|
||||||
class="new-publication"
|
class="new-publication"
|
||||||
matTooltip="Add a new publication"
|
matTooltip="Add a new publication"
|
||||||
matTooltipPosition="left"
|
matTooltipPosition="left"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
+
|
+
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@if ((isLoading$ | async) === true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Publication loading...</h2>
|
<h2 i18n>Publication loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
} @else {
|
} @else {
|
||||||
@if ((isLoaded$ | async) === true) {
|
@if (isLoaded()) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications()"></app-publication-list>
|
||||||
} @else {
|
} @else {
|
||||||
<h2 i18n>There is no any publication...</h2>
|
<h2 i18n>There is no any publication...</h2>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
$newPublicationButtonSize: 1.7em;
|
$newPublicationButtonSize: 1.7em;
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
.new-publication {
|
.new-publication {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
border-radius: 10em;
|
border-radius: 10em;
|
||||||
background-color: #14A44D;
|
background-color: #14A44D;
|
||||||
color: white;
|
color: white;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
bottom: $newPublicationButtonSize;
|
bottom: $newPublicationButtonSize;
|
||||||
right: $newPublicationButtonSize;
|
right: $newPublicationButtonSize;
|
||||||
width: $newPublicationButtonSize;
|
width: $newPublicationButtonSize;
|
||||||
height: $newPublicationButtonSize;
|
height: $newPublicationButtonSize;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
transition: background-color .2s ease-in-out;
|
transition: background-color .2s ease-in-out;
|
||||||
font-size: 2.2em;
|
font-size: 2.2em;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #0e7a3a;
|
background-color: #0e7a3a;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,45 +1,35 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import {Component, inject, OnInit} from "@angular/core";
|
||||||
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
|
||||||
import { MyPublicationsService } from "./my-publications.service";
|
import {MyPublicationsService} from "./my-publications.service";
|
||||||
import { Observable } from "rxjs";
|
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
||||||
import { PublicationListComponent } from "../../components/publication-list/publication-list.component";
|
import {CommonModule} from "@angular/common";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {RouterModule} from "@angular/router";
|
||||||
import { CommonModule } from "@angular/common";
|
import {MatTooltipModule} from "@angular/material/tooltip";
|
||||||
import { RouterModule } from "@angular/router";
|
import {MatRippleModule} from "@angular/material/core";
|
||||||
import { MatTooltipModule } from "@angular/material/tooltip";
|
|
||||||
import { MatRippleModule } from "@angular/material/core";
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-my-component',
|
selector: 'app-my-component',
|
||||||
templateUrl: './my-publications.component.html',
|
templateUrl: './my-publications.component.html',
|
||||||
styleUrl: './my-publications.component.scss',
|
styleUrl: './my-publications.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
PublicationListComponent,
|
PublicationListComponent,
|
||||||
RouterModule
|
RouterModule
|
||||||
],
|
],
|
||||||
providers: [MyPublicationsService]
|
providers: [MyPublicationsService]
|
||||||
})
|
})
|
||||||
export class MyPublicationsComponent implements OnInit {
|
export class MyPublicationsComponent implements OnInit {
|
||||||
private readonly myPublicationsService = inject(MyPublicationsService);
|
private readonly myPublicationsService = inject(MyPublicationsService);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
publications = this.myPublicationsService.publications;
|
||||||
return this.myPublicationsService.publications$;
|
isLoading = this.myPublicationsService.isLoading;
|
||||||
}
|
isLoaded = this.myPublicationsService.isLoaded;
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
ngOnInit(): void {
|
||||||
return this.myPublicationsService.isLoading$;
|
this.myPublicationsService.loadAuthenticatedUserPublications();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
get isLoaded$(): Observable<boolean> {
|
|
||||||
return this.myPublicationsService.isLoaded$;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.myPublicationsService.loadAuthenticatedUserPublications();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Route } from "@angular/router";
|
import {Route} from "@angular/router";
|
||||||
import { authenticationGuard } from "../../core/guard/authentication.guard";
|
import {authenticationGuard} from "../../core/guard/authentication.guard";
|
||||||
import { MyPublicationsComponent } from "./my-publications.component";
|
import {MyPublicationsComponent} from "./my-publications.component";
|
||||||
|
|
||||||
export const ROUTES: Route[] = [
|
export const ROUTES: Route[] = [
|
||||||
{ path: '', component: MyPublicationsComponent, canActivate: [authenticationGuard] }
|
{path: '', component: MyPublicationsComponent, canActivate: [authenticationGuard]}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,57 +1,56 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { AuthenticationService } from "../../core/service/authentication.service";
|
import {AuthenticationService} from "../../core/service/authentication.service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {Router} from "@angular/router";
|
||||||
import { Router } from "@angular/router";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MyPublicationsService {
|
export class MyPublicationsService {
|
||||||
private readonly authenticationService = inject(AuthenticationService);
|
readonly #authenticationService = inject(AuthenticationService);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
#isLoaded = signal(false);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLoading(): Signal<boolean> {
|
||||||
|
return this.#isLoading.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLoaded(): Signal<boolean> {
|
||||||
|
return this.#isLoaded.asReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadAuthenticatedUserPublications(): void {
|
||||||
|
const authenticatedUser = this.#authenticationService.getAuthenticatedUser();
|
||||||
|
if (authenticatedUser) {
|
||||||
|
this.#isLoading.set(true);
|
||||||
|
this.#isLoaded.set(false);
|
||||||
|
|
||||||
|
const query = `author_id=${authenticatedUser.id}`;
|
||||||
|
this.#publicationRestService.search(query)
|
||||||
|
.then(publications => {
|
||||||
|
this.#publications.set(publications);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const errorMessage = $localize`An error occurred while retrieving your publications...`;
|
||||||
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
|
console.error(errorMessage, error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.#isLoading.set(false);
|
||||||
|
this.#isLoaded.set(true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.#authenticationService.unauthenticate();
|
||||||
|
this.#snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, {duration: 5000});
|
||||||
|
this.#router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
get isLoading$(): Observable<boolean> {
|
}
|
||||||
return this.isLoadingSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
|
||||||
return this.isLoadedSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
loadAuthenticatedUserPublications(): void {
|
|
||||||
const authenticatedUser = this.authenticationService.getAuthenticatedUser();
|
|
||||||
if (authenticatedUser) {
|
|
||||||
this.isLoadingSubject.next(true);
|
|
||||||
this.isLoadedSubject.next(false);
|
|
||||||
|
|
||||||
const query = `author_id=${authenticatedUser.id}`;
|
|
||||||
this.publicationRestService.search(query)
|
|
||||||
.then(publications => {
|
|
||||||
this.publicationsSubject.next(publications);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
const errorMessage = $localize`An error occurred while retrieving your publications...`;
|
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
|
||||||
console.error(errorMessage, error);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.isLoadingSubject.next(false);
|
|
||||||
this.isLoadedSubject.next(true);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.authenticationService.unauthenticate();
|
|
||||||
this.snackBar.open($localize`You are unauthenticated. Please, log-in first.`, $localize`Close`, { duration: 5000 });
|
|
||||||
this.router.navigate(['/login']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<app-publication-edition
|
<app-publication-edition
|
||||||
title="Creation of a new publication"
|
title="Creation of a new publication"
|
||||||
[publication]="publication"
|
[publication]="publication()"
|
||||||
[isSaving$]="isSaving$"
|
[isSaving]="isSaving()"
|
||||||
(publicationSave)="onPublicationSave($event)"
|
(publicationSave)="onPublicationSave($event)"
|
||||||
i18n-title>
|
i18n-title
|
||||||
</app-publication-edition>
|
/>
|
||||||
|
|||||||
@@ -1,74 +1,53 @@
|
|||||||
import { Component, inject, OnInit } from "@angular/core";
|
import {Component, inject, OnInit, signal} from "@angular/core";
|
||||||
import { PublicationEditionComponent } from "../../components/publication-edition/publication-edition.component";
|
import {PublicationEditionComponent} from "../../components/publication-edition/publication-edition.component";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { BehaviorSubject, Observable, Subscription } from "rxjs";
|
import {DEFAULT_PUBLICATION, Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {AuthenticationService} from "../../core/service/authentication.service";
|
||||||
import { AuthenticationService } from "../../core/service/authentication.service";
|
import {Author} from "../../core/rest-services/publications/model/author";
|
||||||
import { Author } from "../../core/rest-services/publications/model/author";
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-creation',
|
selector: 'app-publication-creation',
|
||||||
templateUrl: './publication-creation.component.html',
|
templateUrl: './publication-creation.component.html',
|
||||||
styleUrl: './publication-creation.component.scss',
|
styleUrl: './publication-creation.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
PublicationEditionComponent
|
PublicationEditionComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class PublicationCreationComponent implements OnInit {
|
export class PublicationCreationComponent implements OnInit {
|
||||||
private readonly authenticationService = inject(AuthenticationService);
|
readonly #authenticationService = inject(AuthenticationService);
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
isSaving = signal(false);
|
||||||
private subscriptions: Subscription[] = [];
|
publication = signal<Publication>(DEFAULT_PUBLICATION);
|
||||||
publication!: Publication;
|
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
ngOnInit(): void {
|
||||||
return this.isSavingSubject.asObservable();
|
const authenticatedUser = this.#authenticationService.getAuthenticatedUser();
|
||||||
|
if (authenticatedUser) {
|
||||||
|
const author: Author = {
|
||||||
|
id: authenticatedUser.id,
|
||||||
|
name: authenticatedUser.pseudo,
|
||||||
|
image: authenticatedUser.photoId ?? ''
|
||||||
|
};
|
||||||
|
const newPublication: Publication = {...DEFAULT_PUBLICATION, author};
|
||||||
|
this.publication.set(newPublication);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
onPublicationSave(publication: Publication): void {
|
||||||
const authenticatedUser = this.authenticationService.getAuthenticatedUser();
|
this.isSaving.set(true);
|
||||||
if (authenticatedUser) {
|
this.#publicationRestService.create(publication)
|
||||||
const author: Author = {
|
.then(() => {
|
||||||
id: authenticatedUser.id,
|
this.#snackBar.open($localize`Publication created succesfully!`, $localize`Close`, {duration: 5000});
|
||||||
name: authenticatedUser.pseudo,
|
this.#router.navigate(['/my-publications']);
|
||||||
image: authenticatedUser.photoId ?? ''
|
})
|
||||||
};
|
.catch(error => {
|
||||||
this.publication = {
|
const errorMessage = $localize`An error occured while saving new publication.`;
|
||||||
id: '',
|
console.error(errorMessage, error);
|
||||||
key: '',
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
title: '',
|
})
|
||||||
text: '',
|
.finally(() => this.isSaving.set(false));
|
||||||
parsedText: '',
|
}
|
||||||
description: '',
|
}
|
||||||
creationDate: new Date(),
|
|
||||||
illustrationId: '',
|
|
||||||
categoryId: '',
|
|
||||||
author
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
|
||||||
}
|
|
||||||
|
|
||||||
onPublicationSave(publication: Publication): void {
|
|
||||||
this.isSavingSubject.next(true);
|
|
||||||
this.publicationRestService.create(publication)
|
|
||||||
.then(() => {
|
|
||||||
this.snackBar.open($localize`Publication created succesfully!`, $localize`Close`, { duration: 5000 });
|
|
||||||
this.router.navigate(['/my-publications']);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
const errorMessage = $localize`An error occured while saving new publication.`;
|
|
||||||
console.error(errorMessage, error);
|
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
|
||||||
})
|
|
||||||
.finally(() => this.isSavingSubject.next(false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Route } from "@angular/router";
|
import {Route} from "@angular/router";
|
||||||
import { authenticationGuard } from "../../core/guard/authentication.guard";
|
import {authenticationGuard} from "../../core/guard/authentication.guard";
|
||||||
import { PublicationCreationComponent } from "./publication-creation.component";
|
import {PublicationCreationComponent} from "./publication-creation.component";
|
||||||
|
|
||||||
export const ROUTES: Route[] = [
|
export const ROUTES: Route[] = [
|
||||||
{ path: '', component: PublicationCreationComponent, canActivate: [authenticationGuard] }
|
{path: '', component: PublicationCreationComponent, canActivate: [authenticationGuard]}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
@if ((isLoading$ | async) == true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Loading publication to edit...</h2>
|
<h2 i18n>Loading publication to edit...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
}
|
} @else {
|
||||||
@else {
|
@if (publication(); as publication) {
|
||||||
@if (publication) {
|
<app-publication-edition
|
||||||
<app-publication-edition
|
title="Update publication {{ publication.title }}"
|
||||||
title="Update publication {{ publication.title }}"
|
[publication]="publication"
|
||||||
[publication]="publication"
|
[isSaving]="isSaving()"
|
||||||
[isSaving$]="isSaving$"
|
(publicationSave)="onPublicationSave($event)"
|
||||||
(publicationSave)="onPublicationSave($event)"
|
i18n-title
|
||||||
i18n-title>
|
/>
|
||||||
</app-publication-edition>
|
} @else {
|
||||||
}
|
<div class="loading-failed">
|
||||||
@else {
|
<h1 i18n>Publication failed to load...</h1>
|
||||||
<div class="loading-failed">
|
</div>
|
||||||
<h1 i18n>Publication failed to load...</h1>
|
}
|
||||||
</div>
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
app-publication-edition {
|
app-publication-edition {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
import { CommonModule, Location } from '@angular/common';
|
import {CommonModule, Location} from '@angular/common';
|
||||||
import { Component, inject, OnDestroy, OnInit } from '@angular/core';
|
import {Component, effect, inject, Signal, signal} from '@angular/core';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import {ReactiveFormsModule} from '@angular/forms';
|
||||||
import { MatDialogModule } from '@angular/material/dialog';
|
import {MatDialogModule} from '@angular/material/dialog';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import {MatInputModule} from '@angular/material/input';
|
||||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { MatTabsModule } from '@angular/material/tabs';
|
import {MatTabsModule} from '@angular/material/tabs';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
|
import {PublicationEditionComponent} from '../../components/publication-edition/publication-edition.component';
|
||||||
import { PublicationEditionComponent } from '../../components/publication-edition/publication-edition.component';
|
import {Publication} from '../../core/rest-services/publications/model/publication';
|
||||||
import { Publication } from '../../core/rest-services/publications/model/publication';
|
import {PublicationRestService} from '../../core/rest-services/publications/publication.rest-service';
|
||||||
import { PublicationRestService } from '../../core/rest-services/publications/publication.rest-service';
|
import {toSignal} from "@angular/core/rxjs-interop";
|
||||||
|
import {map} from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication-update',
|
selector: 'app-publication-update',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatTabsModule,
|
MatTabsModule,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
PublicationEditionComponent
|
PublicationEditionComponent
|
||||||
],
|
],
|
||||||
templateUrl: './publication-update.component.html',
|
templateUrl: './publication-update.component.html',
|
||||||
styleUrl: './publication-update.component.scss'
|
styleUrl: './publication-update.component.scss'
|
||||||
})
|
})
|
||||||
export class PublicationUpdateComponent implements OnInit, OnDestroy {
|
export class PublicationUpdateComponent {
|
||||||
private readonly publicationRestService = inject(PublicationRestService);
|
readonly #activatedRoute = inject(ActivatedRoute);
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
readonly #location = inject(Location);
|
||||||
private readonly location = inject(Location);
|
readonly #publicationRestService = inject(PublicationRestService);
|
||||||
private readonly router = inject(Router);
|
readonly #router = inject(Router);
|
||||||
private readonly snackBar = inject(MatSnackBar);
|
readonly #snackBar = inject(MatSnackBar);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private isSavingSubject = new BehaviorSubject<boolean>(false);
|
#isSavingSubject = signal(false);
|
||||||
private subscriptions: Subscription[] = [];
|
publication = signal<Publication | undefined>(undefined);
|
||||||
publication: Publication | undefined;
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
#publicationId$ = this.#activatedRoute.params
|
||||||
return this.isLoadingSubject.asObservable();
|
.pipe(map(queryParams => queryParams['publicationId']));
|
||||||
|
#publicationId = toSignal(this.#publicationId$, {initialValue: undefined});
|
||||||
|
|
||||||
|
get isLoading(): Signal<boolean> {
|
||||||
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isSaving$(): Observable<boolean> {
|
get isSaving(): Signal<boolean> {
|
||||||
return this.isSavingSubject.asObservable();
|
return this.#isSavingSubject.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
constructor() {
|
||||||
this.isLoadingSubject.next(true);
|
effect(() => {
|
||||||
const activatedRouteSubscription = this.activatedRoute.paramMap.subscribe(params => {
|
this.#isLoading.set(true);
|
||||||
const publicationId = params.get('publicationId');
|
|
||||||
if (publicationId == undefined) {
|
|
||||||
this.snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, { duration: 5000 });
|
|
||||||
this.location.back();
|
|
||||||
} else {
|
|
||||||
this.publicationRestService.getById(publicationId)
|
|
||||||
.then(publication => {
|
|
||||||
this.publication = publication;
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
|
||||||
console.error(errorMessage, error)
|
|
||||||
})
|
|
||||||
.finally(() => this.isLoadingSubject.next(false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.subscriptions.push(activatedRouteSubscription);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
const publicationId = this.#publicationId();
|
||||||
this.subscriptions.forEach(subscription => subscription?.unsubscribe());
|
if (publicationId) {
|
||||||
|
this.#publicationRestService.getById(publicationId)
|
||||||
|
.then(publication => {
|
||||||
|
this.publication.set(publication);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const errorMessage = $localize`A technical error occurred while loading publication data.`;
|
||||||
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
|
console.error(errorMessage, error)
|
||||||
|
})
|
||||||
|
.finally(() => this.#isLoading.set(false));
|
||||||
|
} else {
|
||||||
|
this.#snackBar.open($localize`A technical error occurred while loading publication data.`, $localize`Close`, {duration: 5000});
|
||||||
|
this.#location.back();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onPublicationSave(publication: Publication): void {
|
onPublicationSave(publication: Publication): void {
|
||||||
this.isSavingSubject.next(true);
|
this.#isSavingSubject.set(true);
|
||||||
this.publicationRestService.update(publication)
|
this.#publicationRestService.update(publication)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.snackBar.open($localize`Publication updated succesfully!`, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open($localize`Publication updated succesfully!`, $localize`Close`, {duration: 5000});
|
||||||
this.router.navigate(['/home']);
|
this.#router.navigate(['/home']);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occured while saving publication modifications.`;
|
const errorMessage = $localize`An error occured while saving publication modifications.`;
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
})
|
})
|
||||||
.finally(() => this.isSavingSubject.next(false));
|
.finally(() => this.#isSavingSubject.set(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Route } from "@angular/router";
|
import {Route} from "@angular/router";
|
||||||
import { PublicationUpdateComponent } from "./publication-update.component";
|
import {PublicationUpdateComponent} from "./publication-update.component";
|
||||||
import { authenticationGuard } from "../../core/guard/authentication.guard";
|
import {authenticationGuard} from "../../core/guard/authentication.guard";
|
||||||
|
|
||||||
export const ROUTES: Route[] = [
|
export const ROUTES: Route[] = [
|
||||||
{ path: '', component: PublicationUpdateComponent, canActivate: [authenticationGuard] }
|
{path: '', component: PublicationUpdateComponent, canActivate: [authenticationGuard]}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,50 +1,50 @@
|
|||||||
@if (isLoading) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Publication content loading...</h2>
|
<h2 i18n>Publication content loading...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner></mat-spinner>
|
||||||
} @else {
|
} @else {
|
||||||
@if (publication) {
|
@if (publication(); as publication) {
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<img src="/api/pictures/{{ publication.illustrationId }}" />
|
<img src="/api/pictures/{{ publication.illustrationId }}"/>
|
||||||
<header>
|
<header>
|
||||||
<h1>{{ publication.title }}</h1>
|
<h1>{{ publication.title }}</h1>
|
||||||
<h2>{{ publication.description }}</h2>
|
<h2>{{ publication.description }}</h2>
|
||||||
@if (isAuthorAndUserEquals) {
|
@if (isAuthorAndUserEquals()) {
|
||||||
<a [routerLink]="['edit']"
|
<a [routerLink]="['edit']"
|
||||||
class="button action"
|
class="button action"
|
||||||
matTooltip="Click to edit the publication"
|
matTooltip="Click to edit the publication"
|
||||||
matRipple
|
matRipple
|
||||||
i18n-matTooltip>
|
i18n-matTooltip>
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
</header>
|
</header>
|
||||||
<main [innerHTML]="publication.parsedText"></main>
|
<main [innerHTML]="publication.parsedText"></main>
|
||||||
<footer>
|
<footer>
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
<img src="/api/pictures/{{ publication.author.image }}" [matTooltip]="publication.author.name" />
|
<img src="/api/pictures/{{ publication.author.image }}" [matTooltip]="publication.author.name"/>
|
||||||
<div class="posting-data">
|
<div class="posting-data">
|
||||||
<span i18n>Publication posted by {{ publication.author.name }}</span>
|
<span i18n>Publication posted by {{ publication.author.name }}</span>
|
||||||
<span class="publication-date">
|
<span class="publication-date">
|
||||||
({{ publication.creationDate | date: 'short' }})
|
({{ publication.creationDate | date: 'short' }})
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
@if (isAuthorAndUserEquals) {
|
|
||||||
<button type="button"
|
|
||||||
(click)="deletePublication()"
|
|
||||||
matTooltip="Click to delete the publication"
|
|
||||||
matTooltipPosition="left"
|
|
||||||
matRipple
|
|
||||||
i18n-matTooltip>
|
|
||||||
<mat-icon>delete</mat-icon>
|
|
||||||
Delete
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</footer>
|
|
||||||
</div>
|
</div>
|
||||||
} @else {
|
@if (isAuthorAndUserEquals()) {
|
||||||
<div class="loading-failed">
|
<button type="button"
|
||||||
<h1 i18n>Publication failed to load...</h1>
|
(click)="deletePublication()"
|
||||||
</div>
|
matTooltip="Click to delete the publication"
|
||||||
}
|
matTooltipPosition="left"
|
||||||
}
|
matRipple
|
||||||
|
i18n-matTooltip>
|
||||||
|
<mat-icon>delete</mat-icon>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
} @else {
|
||||||
|
<div class="loading-failed">
|
||||||
|
<h1 i18n>Publication failed to load...</h1>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,140 +1,140 @@
|
|||||||
$cardBorderRadius: .5em;
|
$cardBorderRadius: .5em;
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin: 1em;
|
||||||
|
max-width: 80em;
|
||||||
|
width: 90%;
|
||||||
|
border-radius: .5em;
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, .16), 0 2px 10px 0 rgba(0, 0, 0, .12);
|
||||||
|
|
||||||
|
img {
|
||||||
|
height: 12em;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: $cardBorderRadius $cardBorderRadius 0 0;
|
||||||
|
transition: height .2s ease-in-out;
|
||||||
|
|
||||||
|
@media screen and (min-width: 450px) {
|
||||||
|
height: 15em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 600px) {
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 750px) {
|
||||||
|
height: 25em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
padding: 2em;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2em;
|
||||||
|
margin-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.2em;
|
||||||
|
line-height: 1.6em;
|
||||||
|
margin: 0;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
padding: .8em .8em;
|
||||||
|
border-radius: 10em;
|
||||||
|
border: none;
|
||||||
|
background-color: #3f51b5;
|
||||||
|
color: white;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
|
position: absolute;
|
||||||
|
top: -1.5em;
|
||||||
|
right: 3em;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
justify-content: center;
|
||||||
margin: 1em;
|
align-items: center;
|
||||||
max-width: 80em;
|
|
||||||
width: 90%;
|
&:hover {
|
||||||
border-radius: .5em;
|
background-color: #5b6ed8;
|
||||||
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16),0 2px 10px 0 rgba(0,0,0,.12);
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
border-top: 1px solid #dddddd;
|
||||||
|
margin: 0 2em 2em 2em;
|
||||||
|
padding-top: 2em;
|
||||||
|
text-align: justify;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
border-radius: 0 0 $cardBorderRadius $cardBorderRadius;
|
||||||
|
padding: 1em 2em;
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
|
@media screen and (min-width: 500px) {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metadata {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
height: 12em;
|
$imageSize: 4em;
|
||||||
object-fit: cover;
|
border-radius: 10em;
|
||||||
border-radius: $cardBorderRadius $cardBorderRadius 0 0;
|
width: $imageSize;
|
||||||
transition: height .2s ease-in-out;
|
height: $imageSize;
|
||||||
|
object-fit: cover;
|
||||||
@media screen and (min-width: 450px) {
|
|
||||||
height: 15em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 600px) {
|
|
||||||
height: 20em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 750px) {
|
|
||||||
height: 25em;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
.posting-data {
|
||||||
padding: 2em;
|
display: flex;
|
||||||
position: relative;
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: start;
|
||||||
|
|
||||||
h1 {
|
.publication-date {
|
||||||
font-size: 2em;
|
font-style: italic;
|
||||||
margin-bottom: .5em;
|
color: #bdbdbd;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.2em;
|
|
||||||
line-height: 1.6em;
|
|
||||||
margin: 0;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
padding: .8em .8em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #3f51b5;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
position: absolute;
|
|
||||||
top: -1.5em;
|
|
||||||
right: 3em;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #5b6ed8;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
main {
|
button {
|
||||||
border-top: 1px solid #dddddd;
|
padding: .8em 1.2em;
|
||||||
margin: 0 2em 2em 2em;
|
border-radius: 10em;
|
||||||
padding-top: 2em;
|
border: none;
|
||||||
text-align: justify;
|
background-color: #D50000;
|
||||||
}
|
color: white;
|
||||||
|
transition: background-color .2s ease-in-out;
|
||||||
footer {
|
display: flex;
|
||||||
display: flex;
|
flex-direction: row;
|
||||||
flex-direction: column;
|
justify-content: center;
|
||||||
justify-content: space-between;
|
align-items: center;
|
||||||
align-items: center;
|
gap: .5em;
|
||||||
background-color: #f0f0f0;
|
|
||||||
border-radius: 0 0 $cardBorderRadius $cardBorderRadius;
|
&:hover {
|
||||||
padding: 1em 2em;
|
background-color: #E53935;
|
||||||
gap: 1em;
|
cursor: pointer;
|
||||||
|
|
||||||
@media screen and (min-width: 500px) {
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metadata {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1em;
|
|
||||||
|
|
||||||
img {
|
|
||||||
$imageSize: 4em;
|
|
||||||
border-radius: 10em;
|
|
||||||
width: $imageSize;
|
|
||||||
height: $imageSize;
|
|
||||||
object-fit: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.posting-data {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: start;
|
|
||||||
|
|
||||||
.publication-date {
|
|
||||||
font-style: italic;
|
|
||||||
color: #bdbdbd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
padding: .8em 1.2em;
|
|
||||||
border-radius: 10em;
|
|
||||||
border: none;
|
|
||||||
background-color: #D50000;
|
|
||||||
color: white;
|
|
||||||
transition: background-color .2s ease-in-out;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
gap: .5em;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: #E53935;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
import { CommonModule, Location } from '@angular/common';
|
import {CommonModule, Location} from '@angular/common';
|
||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit, signal} from '@angular/core';
|
||||||
import { MatRippleModule } from '@angular/material/core';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import {MatDialog} from '@angular/material/dialog';
|
||||||
import { MatIcon } from '@angular/material/icon';
|
import {MatIcon} from '@angular/material/icon';
|
||||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
import {MatProgressSpinner} from '@angular/material/progress-spinner';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||||
import { ActivatedRoute, RouterModule } from '@angular/router';
|
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||||
import { Subscription } from 'rxjs';
|
import {Subscription} from 'rxjs';
|
||||||
import { ConfirmationDialog } from '../../components/confirmation-dialog/confirmation-dialog.component';
|
import {ConfirmationDialog} from '../../components/confirmation-dialog/confirmation-dialog.component';
|
||||||
import { Publication } from '../../core/rest-services/publications/model/publication';
|
import {Publication} from '../../core/rest-services/publications/model/publication';
|
||||||
import { PublicationRestService } from '../../core/rest-services/publications/publication.rest-service';
|
import {PublicationRestService} from '../../core/rest-services/publications/publication.rest-service';
|
||||||
import { AuthenticationService } from '../../core/service/authentication.service';
|
import {AuthenticationService} from '../../core/service/authentication.service';
|
||||||
|
|
||||||
declare let Prism: any;
|
declare let Prism: any;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-publication',
|
selector: 'app-publication',
|
||||||
templateUrl: './publication.component.html',
|
templateUrl: './publication.component.html',
|
||||||
styleUrl: './publication.component.scss',
|
styleUrl: './publication.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
MatIcon,
|
MatIcon,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatProgressSpinner,
|
MatProgressSpinner,
|
||||||
MatTooltipModule,
|
MatTooltipModule,
|
||||||
RouterModule
|
RouterModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class PublicationComponent implements OnInit, OnDestroy {
|
export class PublicationComponent implements OnInit, OnDestroy {
|
||||||
private readonly activatedRoute = inject(ActivatedRoute);
|
private readonly activatedRoute = inject(ActivatedRoute);
|
||||||
@@ -37,35 +37,35 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
private readonly snackBar = inject(MatSnackBar);
|
private readonly snackBar = inject(MatSnackBar);
|
||||||
private paramMapSubscription?: Subscription;
|
private paramMapSubscription?: Subscription;
|
||||||
private afterDialogCloseSubscription?: Subscription;
|
private afterDialogCloseSubscription?: Subscription;
|
||||||
isLoading: boolean = false;
|
isLoading = signal(false);
|
||||||
isAuthorAndUserEquals: boolean = false;
|
isAuthorAndUserEquals = signal(false);
|
||||||
publication?: Publication;
|
publication = signal<Publication | null>(null);
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.paramMapSubscription = this.activatedRoute
|
this.paramMapSubscription = this.activatedRoute
|
||||||
.paramMap
|
.paramMap
|
||||||
.subscribe(params => {
|
.subscribe(params => {
|
||||||
const publicationId = params.get('publicationId');
|
const publicationId = params.get('publicationId');
|
||||||
|
|
||||||
if (publicationId) {
|
if (publicationId) {
|
||||||
this.isLoading = true;
|
this.isLoading.set(true);
|
||||||
|
|
||||||
this.publicationRestService.getById(publicationId)
|
this.publicationRestService.getById(publicationId)
|
||||||
.then(publication => {
|
.then(publication => {
|
||||||
this.publication = publication;
|
this.publication.set(publication);
|
||||||
this.isAuthorAndUserEquals = this.authenticationService.getAuthenticatedUser()?.id === this.publication.author.id;
|
this.isAuthorAndUserEquals.set(this.authenticationService.getAuthenticatedUser()?.id === this.publication()?.author.id);
|
||||||
setTimeout(() => Prism.highlightAll(), 100);
|
setTimeout(() => Prism.highlightAll(), 100);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const errorMessage = $localize`An error occurred while loading publication...`;
|
const errorMessage = $localize`An error occurred while loading publication...`;
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
this.snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
console.error(errorMessage, error);
|
console.error(errorMessage, error);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoading = false;
|
this.isLoading.set(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
@@ -86,9 +86,10 @@ export class PublicationComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.afterDialogCloseSubscription = dialogRef.afterClosed()
|
this.afterDialogCloseSubscription = dialogRef.afterClosed()
|
||||||
.subscribe(response => {
|
.subscribe(response => {
|
||||||
if (response && this.publication?.id) {
|
const publication = this.publication();
|
||||||
this.publicationRestService.delete(this.publication.id);
|
if (response && publication?.id) {
|
||||||
this.snackBar.open($localize`Publication deleted`, $localize`Close`, { duration: 5000 });
|
this.publicationRestService.delete(publication.id);
|
||||||
|
this.snackBar.open($localize`Publication deleted`, $localize`Close`, {duration: 5000});
|
||||||
this.location.back();
|
this.location.back();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<h1 i18n>Search results</h1>
|
<h1 i18n>Search results</h1>
|
||||||
@if((isLoading$ | async) === true) {
|
@if (isLoading()) {
|
||||||
<h2 i18n>Search in progress...</h2>
|
<h2 i18n>Search in progress...</h2>
|
||||||
<mat-spinner></mat-spinner>
|
<mat-spinner/>
|
||||||
} @else if((isLoaded$ | async) === true) {
|
} @else if (isLoaded()) {
|
||||||
@if((publications$ | async)?.length) {
|
@if (publications().length) {
|
||||||
<app-publication-list [publications$]="publications$"></app-publication-list>
|
<app-publication-list [publications]="publications()"/>
|
||||||
} @else {
|
} @else {
|
||||||
<span i18n>No any result.</span>
|
|
||||||
}
|
|
||||||
} @else {
|
|
||||||
<span i18n>No any result.</span>
|
<span i18n>No any result.</span>
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
<span i18n>No any result.</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,39 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import {CommonModule} from "@angular/common";
|
||||||
import { Component, inject, OnDestroy, OnInit } from "@angular/core";
|
import {Component, effect, inject} from "@angular/core";
|
||||||
import { MatProgressSpinner } from "@angular/material/progress-spinner";
|
import {MatProgressSpinner} from "@angular/material/progress-spinner";
|
||||||
import { ActivatedRoute } from "@angular/router";
|
import {ActivatedRoute} from "@angular/router";
|
||||||
import { Observable, Subscription } from "rxjs";
|
import {PublicationListComponent} from "../../components/publication-list/publication-list.component";
|
||||||
import { PublicationListComponent } from "../../components/publication-list/publication-list.component";
|
import {SearchPublicationsService} from "./search-publications.service";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {toSignal} from "@angular/core/rxjs-interop";
|
||||||
import { SearchPublicationsService } from "./search-publications.service";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search-publications',
|
selector: 'app-search-publications',
|
||||||
templateUrl: './search-publications.component.html',
|
templateUrl: './search-publications.component.html',
|
||||||
styleUrl: './search-publications.component.scss',
|
styleUrl: './search-publications.component.scss',
|
||||||
imports: [CommonModule, MatProgressSpinner, PublicationListComponent],
|
imports: [CommonModule, MatProgressSpinner, PublicationListComponent],
|
||||||
providers: [SearchPublicationsService]
|
providers: [SearchPublicationsService]
|
||||||
})
|
})
|
||||||
export class SearchPublicationsComponent implements OnInit, OnDestroy {
|
export class SearchPublicationsComponent {
|
||||||
private searchPublicationsService = inject(SearchPublicationsService);
|
private searchPublicationsService = inject(SearchPublicationsService);
|
||||||
private activatedRoute = inject(ActivatedRoute);
|
private activatedRoute = inject(ActivatedRoute);
|
||||||
private queryParamsSubscription?: Subscription;
|
publications = this.searchPublicationsService.publications;
|
||||||
|
isLoading = this.searchPublicationsService.isLoading;
|
||||||
|
isLoaded = this.searchPublicationsService.isLoaded;
|
||||||
|
|
||||||
ngOnInit(): void {
|
constructor() {
|
||||||
this.queryParamsSubscription = this.activatedRoute.queryParamMap
|
const queryParams = toSignal(this.activatedRoute.queryParamMap);
|
||||||
.subscribe(params => {
|
effect(() => {
|
||||||
const categoryId = params.get('category-id');
|
let params = queryParams();
|
||||||
if (categoryId) {
|
if (params) {
|
||||||
this.searchPublicationsService.loadPublications(`category_id=${categoryId}`);
|
const categoryId = params.get('category-id');
|
||||||
}
|
if (categoryId) {
|
||||||
const query = params.get('query')
|
this.searchPublicationsService.loadPublications(`category_id=${categoryId}`);
|
||||||
if (query) {
|
}
|
||||||
this.searchPublicationsService.loadPublications(query);
|
const query = params.get('query')
|
||||||
}
|
if (query) {
|
||||||
});
|
this.searchPublicationsService.loadPublications(query);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ngOnDestroy(): void {
|
});
|
||||||
this.queryParamsSubscription?.unsubscribe();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
|
||||||
return this.searchPublicationsService.publications$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.searchPublicationsService.isLoading$;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
|
||||||
return this.searchPublicationsService.isLoaded$;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,49 +1,47 @@
|
|||||||
import { inject, Injectable } from "@angular/core";
|
import {inject, Injectable, Signal, signal} from "@angular/core";
|
||||||
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
|
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
|
||||||
import { BehaviorSubject, Observable } from "rxjs";
|
import {Publication} from "../../core/rest-services/publications/model/publication";
|
||||||
import { Publication } from "../../core/rest-services/publications/model/publication";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import { MatSnackBar } from "@angular/material/snack-bar";
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SearchPublicationsService {
|
export class SearchPublicationsService {
|
||||||
private publicationRestService = inject(PublicationRestService);
|
#snackBar = inject(MatSnackBar);
|
||||||
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
|
#publicationRestService = inject(PublicationRestService);
|
||||||
private isLoadingSubject = new BehaviorSubject<boolean>(false);
|
#publications = signal<Publication[]>([]);
|
||||||
private isLoadedSubject = new BehaviorSubject<boolean>(false);
|
#isLoading = signal(false);
|
||||||
private snackBar = inject(MatSnackBar);
|
#isLoaded = signal(false);
|
||||||
|
|
||||||
get publications$(): Observable<Publication[]> {
|
get publications(): Signal<Publication[]> {
|
||||||
return this.publicationsSubject.asObservable();
|
return this.#publications.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
get isLoading$(): Observable<boolean> {
|
|
||||||
return this.isLoadingSubject.asObservable();
|
|
||||||
}
|
|
||||||
|
|
||||||
get isLoaded$(): Observable<boolean> {
|
get isLoading(): Signal<boolean> {
|
||||||
return this.isLoadedSubject.asObservable();
|
return this.#isLoading.asReadonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPublications(searchCriteria: string): void {
|
get isLoaded(): Signal<boolean> {
|
||||||
this.isLoadingSubject.next(true);
|
return this.#isLoaded.asReadonly();
|
||||||
this.isLoadedSubject.next(false);
|
}
|
||||||
this.publicationsSubject.next([]);
|
|
||||||
|
|
||||||
this.publicationRestService.search(searchCriteria)
|
loadPublications(searchCriteria: string): void {
|
||||||
.then(publications => {
|
this.#isLoading.set(true);
|
||||||
this.publicationsSubject.next(publications);
|
this.#isLoaded.set(false);
|
||||||
})
|
this.#publications.set([]);
|
||||||
.catch(error => {
|
|
||||||
if (error.status !== 404) {
|
this.#publicationRestService.search(searchCriteria)
|
||||||
const errorMessage = $localize`An error occured while retrieving publications.`;
|
.then(publications => {
|
||||||
console.error(errorMessage, error);
|
this.#publications.set(publications);
|
||||||
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
|
})
|
||||||
}
|
.catch(error => {
|
||||||
})
|
if (error.status !== 404) {
|
||||||
.finally(() => {
|
const errorMessage = $localize`An error occured while retrieving publications.`;
|
||||||
this.isLoadingSubject.next(false);
|
console.error(errorMessage, error);
|
||||||
this.isLoadedSubject.next(true);
|
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
|
||||||
});
|
}
|
||||||
}
|
})
|
||||||
}
|
.finally(() => {
|
||||||
|
this.#isLoading.set(false);
|
||||||
|
this.#isLoaded.set(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
<form [formGroup]="signinForm" (submit)="performSignin()" class="cod-form card" ngNativeValidate>
|
<form [formGroup]="signinForm" (submit)="performSignin()" class="cod-form card" ngNativeValidate>
|
||||||
<h1 i18n>Signin</h1>
|
<h1 i18n>Signin</h1>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>person</mat-icon>
|
<mat-icon>person</mat-icon>
|
||||||
<label for="pseudo" i18n>
|
<label for="pseudo" i18n>
|
||||||
Pseudo
|
Pseudo
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" id="pseudo" formControlName="pseudo" autocomplete="pseudo" required />
|
<input type="text" id="pseudo" formControlName="pseudo" autocomplete="pseudo" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>mail</mat-icon>
|
<mat-icon>mail</mat-icon>
|
||||||
<label for="email" i18n>
|
<label for="email" i18n>
|
||||||
Email address
|
Email address
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="email" id="email" formControlName="email" autocomplete="email" required />
|
<input type="email" id="email" formControlName="email" autocomplete="email" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="password" i18n>
|
<label for="password" i18n>
|
||||||
Password
|
Password
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="password" formControlName="password" required />
|
<input type="password" id="password" formControlName="password" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<mat-icon>lock</mat-icon>
|
<mat-icon>lock</mat-icon>
|
||||||
<label for="confirm-password" i18n>
|
<label for="confirm-password" i18n>
|
||||||
Confirm password
|
Confirm password
|
||||||
<span class="required">*</span>
|
<span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="password" id="confirm-password" formControlName="confirmPassword" required />
|
<input type="password" id="confirm-password" formControlName="confirmPassword" required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions reversed">
|
<div class="actions reversed">
|
||||||
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
<app-submit-button [requestPending]="false" [disabled]="false" i18n>Send</app-submit-button>
|
||||||
<a [routerLink]="['/login']" class="cod-button secondary" matRipple i18n>I already have an account</a>
|
<a [routerLink]="['/login']" class="cod-button secondary" matRipple i18n>I already have an account</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
import {FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import {MatIconModule} from '@angular/material/icon';
|
||||||
import { RouterModule } from '@angular/router';
|
import {RouterModule} from '@angular/router';
|
||||||
import { Subscription, debounceTime, distinctUntilChanged, map } from 'rxjs';
|
import {debounceTime, distinctUntilChanged, map, Subscription} from 'rxjs';
|
||||||
import { SigninService } from './signin.service';
|
import {SigninService} from './signin.service';
|
||||||
import { LoginService } from '../login/login.service';
|
import {LoginService} from '../login/login.service';
|
||||||
import { FormError } from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
import { SubmitButtonComponent } from "../../components/submit-button/submit-button.component";
|
import {SubmitButtonComponent} from "../../components/submit-button/submit-button.component";
|
||||||
import { MatRippleModule } from '@angular/material/core';
|
import {MatRippleModule} from '@angular/material/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-signin',
|
selector: 'app-signin',
|
||||||
templateUrl: './signin.component.html',
|
templateUrl: './signin.component.html',
|
||||||
styleUrl: './signin.component.scss',
|
styleUrl: './signin.component.scss',
|
||||||
imports: [
|
imports: [
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
RouterModule,
|
RouterModule,
|
||||||
SubmitButtonComponent
|
SubmitButtonComponent
|
||||||
],
|
],
|
||||||
providers: [SigninService, LoginService]
|
providers: [SigninService, LoginService]
|
||||||
})
|
})
|
||||||
export class SigninComponent implements OnInit, OnDestroy {
|
export class SigninComponent implements OnInit, OnDestroy {
|
||||||
private signinService = inject(SigninService);
|
private signinService = inject(SigninService);
|
||||||
@@ -38,63 +38,63 @@ export class SigninComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const pseudoSubscription = this.signinForm.controls['pseudo'].valueChanges
|
const pseudoSubscription = this.signinForm.controls['pseudo'].valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
debounceTime(300),
|
debounceTime(300),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map(value => value?.length ? value as string : '')
|
map(value => value?.length ? value as string : '')
|
||||||
)
|
)
|
||||||
.subscribe(pseudo => {
|
.subscribe(pseudo => {
|
||||||
this.signinService.editPseudo(pseudo);
|
this.signinService.editPseudo(pseudo);
|
||||||
});
|
});
|
||||||
this.subscriptions.push(pseudoSubscription);
|
this.subscriptions.push(pseudoSubscription);
|
||||||
|
|
||||||
const emailSubscription = this.signinForm.controls['email'].valueChanges
|
const emailSubscription = this.signinForm.controls['email'].valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
debounceTime(300),
|
debounceTime(300),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map(value => value?.length ? value as string : '')
|
map(value => value?.length ? value as string : '')
|
||||||
)
|
)
|
||||||
.subscribe(email => {
|
.subscribe(email => {
|
||||||
this.signinService.editEmail(email);
|
this.signinService.editEmail(email);
|
||||||
});
|
});
|
||||||
this.subscriptions.push(emailSubscription);
|
this.subscriptions.push(emailSubscription);
|
||||||
|
|
||||||
const passwordSubscription = this.signinForm.controls['password'].valueChanges
|
const passwordSubscription = this.signinForm.controls['password'].valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
debounceTime(300),
|
debounceTime(300),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map(value => value?.length ? value as string : '')
|
map(value => value?.length ? value as string : '')
|
||||||
)
|
)
|
||||||
.subscribe(password => {
|
.subscribe(password => {
|
||||||
this.signinService.editPassword(password);
|
this.signinService.editPassword(password);
|
||||||
});
|
});
|
||||||
this.subscriptions.push(passwordSubscription);
|
this.subscriptions.push(passwordSubscription);
|
||||||
|
|
||||||
const confirmPasswordSubscription = this.signinForm.controls['confirmPassword'].valueChanges
|
const confirmPasswordSubscription = this.signinForm.controls['confirmPassword'].valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
debounceTime(300),
|
debounceTime(300),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
map(value => value?.length ? value as string : '')
|
map(value => value?.length ? value as string : '')
|
||||||
)
|
)
|
||||||
.subscribe(confirmPassword => {
|
.subscribe(confirmPassword => {
|
||||||
this.signinService.editConfirmPassword(confirmPassword);
|
this.signinService.editConfirmPassword(confirmPassword);
|
||||||
});
|
});
|
||||||
this.subscriptions.push(confirmPasswordSubscription);
|
this.subscriptions.push(confirmPasswordSubscription);
|
||||||
|
|
||||||
const stateSubscription = this.signinService.state$
|
const stateSubscription = this.signinService.state$
|
||||||
.subscribe(state => {
|
.subscribe(state => {
|
||||||
this.signinForm.controls['pseudo'].setValue(state.request.pseudo, { emitEvent: false });
|
this.signinForm.controls['pseudo'].setValue(state.request.pseudo, {emitEvent: false});
|
||||||
this.signinForm.controls['email'].setValue(state.request.email, { emitEvent: false });
|
this.signinForm.controls['email'].setValue(state.request.email, {emitEvent: false});
|
||||||
this.signinForm.controls['password'].setValue(state.request.password, { emitEvent: false });
|
this.signinForm.controls['password'].setValue(state.request.password, {emitEvent: false});
|
||||||
this.signinForm.controls['confirmPassword'].setValue(state.confirmPassword, { emitEvent: false });
|
this.signinForm.controls['confirmPassword'].setValue(state.confirmPassword, {emitEvent: false});
|
||||||
});
|
});
|
||||||
this.subscriptions.push(stateSubscription);
|
this.subscriptions.push(stateSubscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
performSignin(): void {
|
performSignin(): void {
|
||||||
if (this.signinForm.valid) {
|
if (this.signinForm.valid) {
|
||||||
this.signinService.performSignin();
|
this.signinService.performSignin();
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import { SigninRequest } from '../../core/rest-services/user/model/signin.model';
|
import {SigninRequest} from '../../core/rest-services/user/model/signin.model';
|
||||||
import { FormError } from '../../core/model/FormError';
|
import {FormError} from '../../core/model/FormError';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import { copy } from '../../core/utils/ObjectUtils';
|
import {copy} from '../../core/utils/ObjectUtils';
|
||||||
import { UserRestService } from '../../core/rest-services/user/user.rest-service';
|
import {UserRestService} from '../../core/rest-services/user/user.rest-service';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||||
import { Router } from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import { LoginService } from '../login/login.service';
|
import {LoginService} from '../login/login.service';
|
||||||
|
|
||||||
export interface SigninState {
|
export interface SigninState {
|
||||||
request: SigninRequest;
|
request: SigninRequest;
|
||||||
@@ -74,12 +74,12 @@ export class SigninService {
|
|||||||
state.confirmPassword = newConfirmPassword;
|
state.confirmPassword = newConfirmPassword;
|
||||||
|
|
||||||
if (state.request.password !== state.confirmPassword) {
|
if (state.request.password !== state.confirmPassword) {
|
||||||
const confirmPasswordError: FormError = {
|
const confirmPasswordError: FormError = {
|
||||||
fieldName: 'confirmPassword',
|
fieldName: 'confirmPassword',
|
||||||
errorMessage: $localize`Typed passwords are different.`
|
errorMessage: $localize`Typed passwords are different.`
|
||||||
}
|
}
|
||||||
state.errors.filter(error => error.fieldName !== 'confirmPassword');
|
state.errors.filter(error => error.fieldName !== 'confirmPassword');
|
||||||
state.errors.push(confirmPasswordError)
|
state.errors.push(confirmPasswordError)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.save(state);
|
this.save(state);
|
||||||
@@ -91,12 +91,12 @@ export class SigninService {
|
|||||||
// Check state is valid
|
// Check state is valid
|
||||||
|
|
||||||
this.userRestService
|
this.userRestService
|
||||||
.signin(state.request)
|
.signin(state.request)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.loginService.editEmail(state.request.email!!);
|
this.loginService.editEmail(state.request.email!!);
|
||||||
this.loginService.editPassword(state.request.password!!);
|
this.loginService.editPassword(state.request.password!!);
|
||||||
|
|
||||||
this.loginService.performLogin();
|
this.loginService.performLogin();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
button.cod-button, a.cod-button {
|
button.cod-button, a.cod-button {
|
||||||
padding: .8em 1.2em;
|
padding: .8em 1.2em;
|
||||||
border-radius: 10em;
|
border-radius: 10em;
|
||||||
border: none;
|
border: none;
|
||||||
background-color: #3f51b5;
|
background-color: #3f51b5;
|
||||||
color: white;
|
color: white;
|
||||||
transition: background-color .2s ease-in-out;
|
transition: background-color .2s ease-in-out;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #5b6ed8;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.secondary {
|
||||||
|
color: #3f51b5;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #5b6ed8;
|
background-color: #f2f4ff;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.secondary {
|
&.icon {
|
||||||
color: #3f51b5;
|
$buttonSize: 2.5em;
|
||||||
background-color: white;
|
width: $buttonSize;
|
||||||
|
height: $buttonSize;
|
||||||
&:hover {
|
padding: 0;
|
||||||
background-color: #f2f4ff;
|
|
||||||
}
|
&.close {
|
||||||
}
|
position: absolute;
|
||||||
|
top: 1em;
|
||||||
&.icon {
|
right: 1em;
|
||||||
$buttonSize: 2.5em;
|
color: black;
|
||||||
width: $buttonSize;
|
|
||||||
height: $buttonSize;
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
&.close {
|
|
||||||
position: absolute;
|
|
||||||
top: 1em;
|
|
||||||
right: 1em;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.cod-button {
|
a.cod-button {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user