RLH-12 | Implement username changing

This commit is contained in:
Bea 2024-11-04 11:25:19 +01:00
parent c4e8e7483a
commit 1bb4d1d134
19 changed files with 1318 additions and 37 deletions

48
.eslintrc.json Normal file
View File

@ -0,0 +1,48 @@
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended",
"plugin:@angular-eslint/template/accessibility"
],
"rules": {}
}
]
}

View File

@ -102,8 +102,22 @@
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js" "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
] ]
} }
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
} }
} }
} }
},
"cli": {
"schematicCollections": [
"@angular-eslint/schematics"
]
} }
} }

1159
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,8 @@
"start": "ng serve", "start": "ng serve",
"build": "ng build", "build": "ng build",
"watch": "ng build --watch --configuration development", "watch": "ng build --watch --configuration development",
"test": "ng test" "test": "ng test",
"lint": "ng lint"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
@ -31,10 +32,18 @@
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "^17.3.11", "@angular-devkit/build-angular": "^17.3.11",
"@angular-eslint/builder": "17.5.3",
"@angular-eslint/eslint-plugin": "17.5.3",
"@angular-eslint/eslint-plugin-template": "17.5.3",
"@angular-eslint/schematics": "17.5.3",
"@angular-eslint/template-parser": "17.5.3",
"@angular/cli": "^17.3.11", "@angular/cli": "^17.3.11",
"@angular/compiler-cli": "^17.3.0", "@angular/compiler-cli": "^17.3.0",
"@angular/localize": "^17.3.0", "@angular/localize": "^17.3.0",
"@types/jasmine": "~5.1.0", "@types/jasmine": "~5.1.0",
"@typescript-eslint/eslint-plugin": "7.11.0",
"@typescript-eslint/parser": "7.11.0",
"eslint": "^8.57.0",
"jasmine-core": "~5.1.0", "jasmine-core": "~5.1.0",
"karma": "~6.4.0", "karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0", "karma-chrome-launcher": "~3.2.0",

View File

@ -1,6 +1,6 @@
import {HTTP_INTERCEPTORS} from "@angular/common/http"; import {HTTP_INTERCEPTORS} from "@angular/common/http";
import {AuthInterceptorService} from "./services/auth-interceptor.service"; import {AuthInterceptorService} from "./services/auth-interceptor.service";
import {AfterViewChecked, AfterViewInit, Component, OnInit} from "@angular/core"; import {Component} from "@angular/core";
import {RouterOutlet} from "@angular/router"; import {RouterOutlet} from "@angular/router";
import {LoginComponent} from "./views/login/login.component"; import {LoginComponent} from "./views/login/login.component";
import {ApiService} from "./services/api.service"; import {ApiService} from "./services/api.service";

View File

@ -1,8 +1,8 @@
import {ApplicationConfig} from '@angular/core'; import {ApplicationConfig} from '@angular/core';
import {provideRouter, provideRoutes, withComponentInputBinding} from '@angular/router'; import {provideRouter} from '@angular/router';
import {routes} from './app.routes'; import {routes} from './app.routes';
import {provideHttpClient, withInterceptors, withInterceptorsFromDi} from "@angular/common/http"; import {provideHttpClient, withInterceptorsFromDi} from "@angular/common/http";
import {httpInterceptorProviders} from "./app.component"; import {httpInterceptorProviders} from "./app.component";
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {

View File

@ -1,7 +1,10 @@
<button <ng-container *ngIf="!!button.visible && button.visible()">
type="button" <button
class="m-1 {{classes}}" type="button"
[disabled]="isDisabled()" class="m-1 {{classes}}"
(click)="button.click()"> [disabled]="isDisabled()"
{{ button.text }} (click)="button.click()">
</button> {{ button.text }}
</button>
</ng-container>

View File

@ -1,10 +1,13 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {ButtonModel, ButtonType} from "./models/button.model"; import {ButtonModel, ButtonType} from "./models/button.model";
import {NgIf} from "@angular/common";
@Component({ @Component({
selector: 'rlh-button', selector: 'rlh-button',
standalone: true, standalone: true,
imports: [], imports: [
NgIf
],
templateUrl: './button.component.html', templateUrl: './button.component.html',
styleUrl: './button.component.scss' styleUrl: './button.component.scss'
}) })
@ -14,6 +17,7 @@ export class ButtonComponent implements OnInit
@Input() button: ButtonModel = { @Input() button: ButtonModel = {
text: 'text', text: 'text',
disabled: () => false, disabled: () => false,
visible: () => true,
click: () => {}, click: () => {},
type: ButtonType.PRIMARY type: ButtonType.PRIMARY
}; };
@ -26,12 +30,16 @@ export class ButtonComponent implements OnInit
this.button.disabled = this.button.disabled this.button.disabled = this.button.disabled
? this.button.disabled ? this.button.disabled
: () => false; : () => false;
//
setTimeout(() => { setTimeout(() => {
this.isDisabled = () => { this.isDisabled = () => {
return this.button.disabled(); return this.button.disabled();
}; };
}); });
this.button.visible =
this.button.visible ?
this.button.visible : () => true;
} }
get classes(): string { get classes(): string {

View File

@ -3,9 +3,17 @@ export class ButtonModel {
type: ButtonType; type: ButtonType;
disabled: () => boolean; disabled: () => boolean;
click: () => void; click: () => void;
visible?: () => boolean;
} }
export enum ButtonType { export enum ButtonType {
LINK = "btn-link", LINK = "btn-link",
PRIMARY = "btn-primary", PRIMARY = "btn-primary",
SECONDARY = "btn-secondary",
SUCCESS = "btn-success",
DANGER = "btn-danger",
WARNING = "btn-warning",
INFO = "btn-info",
LIGHT = "btn-light",
DARK = "btn-dark"
} }

View File

@ -11,9 +11,7 @@ export class ApiService {
constructor( constructor(
private http: HttpClient private http: HttpClient
) { ) {}
}
// v1 USERS // v1 USERS

View File

@ -11,7 +11,7 @@ export class AuthInterceptorService implements HttpInterceptor {
const tokenId = localStorage.getItem('tokenId'); const tokenId = localStorage.getItem('tokenId');
if (!!tokenId) { if (tokenId) {
const cloned = req.clone({ const cloned = req.clone({
headers: req.headers.set("Authorization", headers: req.headers.set("Authorization",
"Bearer " + tokenId) "Bearer " + tokenId)

View File

@ -13,7 +13,7 @@ import {ButtonModel, ButtonType} from "../../../libraries/components/button/mode
}) })
export class AccountNavigationComponent { export class AccountNavigationComponent {
@Output() onNavChange = new EventEmitter<string>(); @Output() navChange = new EventEmitter<string>();
selectedMenu = "ACC"; selectedMenu = "ACC";
@ -22,7 +22,7 @@ export class AccountNavigationComponent {
click: () => click: () =>
{ {
this.selectedMenu = 'ACC'; this.selectedMenu = 'ACC';
this.onNavChange.emit(this.selectedMenu); this.navChange.emit(this.selectedMenu);
}, },
text: 'Account Management', text: 'Account Management',
type: ButtonType.LINK type: ButtonType.LINK
@ -32,7 +32,7 @@ export class AccountNavigationComponent {
disabled: () => this.selectedMenu === 'PPF', disabled: () => this.selectedMenu === 'PPF',
click: () => { click: () => {
this.selectedMenu = 'PPF'; this.selectedMenu = 'PPF';
this.onNavChange.emit(this.selectedMenu); this.navChange.emit(this.selectedMenu);
}, },
text: 'Public Profile', text: 'Public Profile',
type: ButtonType.LINK type: ButtonType.LINK

View File

@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="col-3"> <div class="col-3">
<app-account-navigation <app-account-navigation
(onNavChange)="navChanged($event)" (navChange)="navChanged($event)"
> >
</app-account-navigation> </app-account-navigation>
</div> </div>

View File

@ -1,6 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import {ButtonComponent} from "../../libraries/components/button/button.component"; import {ButtonComponent} from "../../libraries/components/button/button.component";
import {ButtonModel} from "../../libraries/components/button/models/button.model";
import {DashboardComponent} from "../dashboard/dashboard.component"; import {DashboardComponent} from "../dashboard/dashboard.component";
import {NgIf} from "@angular/common"; import {NgIf} from "@angular/common";
import {LoginComponent} from "../login/login.component"; import {LoginComponent} from "../login/login.component";

View File

@ -1,4 +1,4 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {LoginComponent} from "../../login/login.component"; import {LoginComponent} from "../../login/login.component";
import {NgIf} from "@angular/common"; import {NgIf} from "@angular/common";
import {RegisterComponent} from "../../register/register.component"; import {RegisterComponent} from "../../register/register.component";
@ -15,7 +15,7 @@ import {AuthService} from "../../../services/auth.service";
templateUrl: './auth-form.component.html', templateUrl: './auth-form.component.html',
styleUrl: './auth-form.component.scss' styleUrl: './auth-form.component.scss'
}) })
export class AuthFormComponent { export class AuthFormComponent implements OnInit {
constructor(private authService: AuthService) { constructor(private authService: AuthService) {
} }

View File

@ -12,10 +12,13 @@
</div> </div>
</div> </div>
<div class="col-2"> <div class="col-2">
<i>Modify</i> Actions
<div> <div>
<rlh-button <rlh-button *ngIf="!isEditingUsername"
[button]="editUserNameButton"> [button]="editUsernameButton">
</rlh-button>
<rlh-button *ngIf="isEditingUsername"
[button]="saveUsernameButton">
</rlh-button> </rlh-button>
</div> </div>
</div> </div>

View File

@ -10,6 +10,7 @@ import {InputComponent} from "../../libraries/components/input/input.component";
import {InputModel, InputType} from "../../libraries/components/input/input.model"; import {InputModel, InputType} from "../../libraries/components/input/input.model";
import {ButtonComponent} from "../../libraries/components/button/button.component"; import {ButtonComponent} from "../../libraries/components/button/button.component";
import {ButtonModel, ButtonType} from "../../libraries/components/button/models/button.model"; import {ButtonModel, ButtonType} from "../../libraries/components/button/models/button.model";
import {AccountService} from "../../services/account.service";
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
@ -30,7 +31,7 @@ export class DashboardComponent implements OnInit {
usernameInput: InputModel = { usernameInput: InputModel = {
type: InputType.TEXT, type: InputType.TEXT,
disabled: () => true, disabled: () => !this.isEditingUsername,
modelChange: () => {} modelChange: () => {}
} }
@ -52,12 +53,23 @@ export class DashboardComponent implements OnInit {
modelChange: () => {} modelChange: () => {}
} }
editUserNameButton: ButtonModel = { editUsernameButton: ButtonModel = {
disabled: () => false, disabled: () => this.isEditingUsername,
visible: () => !this.isEditingUsername,
click: () => { click: () => {
console.log(this.userData.username); this.isEditingUsername = true;
}, },
text: 'Edit', text: 'Edit',
type: ButtonType.SECONDARY
}
saveUsernameButton: ButtonModel = {
disabled: () => !this.isEditingUsername,
visible: () => this.isEditingUsername,
click: () => {
this.saveUsername();
},
text: 'Save',
type: ButtonType.PRIMARY type: ButtonType.PRIMARY
} }
@ -68,7 +80,12 @@ export class DashboardComponent implements OnInit {
createdAt: null createdAt: null
} }
constructor(private authService: AuthService, private apiService: ApiService, private router: Router) { isEditingUsername = false;
constructor(private authService: AuthService,
private apiService: ApiService,
private accountService: AccountService,
private router: Router) {
} }
ngOnInit(): void { ngOnInit(): void {
@ -82,4 +99,19 @@ export class DashboardComponent implements OnInit {
} }
} }
saveUsername(): void {
this.isEditingUsername = false;
this.apiService.getCurrentUser().subscribe(res => {
if(!res) return;
let uuid = res.uuid;
if(!!uuid) {
this.accountService.changeUsername(uuid, this.userData.username)
.subscribe(res => {
this.userData.username = res;
});
}
});
}
} }

View File

@ -10,7 +10,7 @@
*ngIf="!!loggedUser && !!loggedUser.username"> *ngIf="!!loggedUser && !!loggedUser.username">
<div class="col-4"> <div class="col-4">
<div class="form-group" data-mdb-input-init> <div class="form-group" data-mdb-input-init>
<label class="form-label">Username</label> <p class="form-label">Username</p>
<input type="text" <input type="text"
class="form-control" class="form-control"
name="loggedUser.username" name="loggedUser.username"
@ -22,7 +22,7 @@
<div class="row justify-content-center mb-2"> <div class="row justify-content-center mb-2">
<div class="col-4"> <div class="col-4">
<div class="form-group" data-mdb-input-init> <div class="form-group" data-mdb-input-init>
<label class="form-label">Email address</label> <p class="form-label">Email address</p>
<input type="text" <input type="text"
name="email" name="email"
[disabled]="isLoggedIn" [disabled]="isLoggedIn"
@ -34,7 +34,7 @@
<div class="row justify-content-center mb-4"> <div class="row justify-content-center mb-4">
<div class="col-4"> <div class="col-4">
<div class="form-group" data-mdb-input-init> <div class="form-group" data-mdb-input-init>
<label class="form-label">Password</label> <p class="form-label">Password</p>
<input type="password" <input type="password"
name="password" name="password"
[disabled]="isLoggedIn" [disabled]="isLoggedIn"

View File

@ -36,7 +36,7 @@ export class LoginComponent implements OnInit {
public attemptLogin() { public attemptLogin() {
this.authService.authenticate(this.email, this.password) this.authService.authenticate(this.email, this.password)
.subscribe(token => { .subscribe(() => {
this.router.navigate(['/']).then(); this.router.navigate(['/']).then();
}); });
} }