Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
FE-#103: Code-QA
Browse files Browse the repository at this point in the history
- Moved logic for updating theme preference to user.service
- Created types for user settings and color modes
- Updated list style
  • Loading branch information
Drumber committed May 12, 2024
1 parent f7520aa commit 85a1855
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public enum ColorMode {
GRASSLAND,
SUNSET,
DEVELOPER,
DARK_BV,
AUTUMN
}
8 changes: 4 additions & 4 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ import {EventpageComponent} from "./eventpage/eventpage.component";
import {MatRippleModule} from "@angular/material/core";
import {EventSearchComponent} from './dashboard/side-menu/event-search/event-search.component';
import {FormsModule} from "@angular/forms";
import { UserSettingsComponent } from './dashboard/user-settings/user-settings.component';
import { UserSettingsItemComponent } from './dashboard/user-settings/user-settings-item/user-settings-item.component';
import {UserSettingsComponent} from './dashboard/user-settings/user-settings.component';
import {UserSettingsItemComponent} from './dashboard/user-settings/user-settings-item/user-settings-item.component';
import {EventBannerComponent} from './eventpage/event-banner/event-banner.component';
import {EventDescriptionComponent} from './eventpage/event-description/event-description.component';
import {WidgetsSectionComponent} from './eventpage/widgets-section/widgets-section.component';
import {WidgetContainerComponent} from './eventpage/widgets-section/widget-container/widget-container.component';
import {ScrollingModule} from "@angular/cdk/scrolling";
import {WidgetsBarComponent} from './eventpage/widgets-section/widgets-bar/widgets-bar.component';
import {MatTabsModule} from "@angular/material/tabs";
import { ParticipantsSidenavComponent } from './eventpage/participants-sidenav/participants-sidenav.component';
import { ParticipantCardComponent } from './eventpage/participants-sidenav/participant-card/participant-card.component';
import {ParticipantsSidenavComponent} from './eventpage/participants-sidenav/participants-sidenav.component';
import {ParticipantCardComponent} from './eventpage/participants-sidenav/participant-card/participant-card.component';

registerLocaleData(localeDe);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[routerLink]="'./' + event.id"
routerLinkActive="selected"
class="event-card"
tabindex="0"
>
<div class="ripple-container" mat-ripple [matRippleTrigger]="wrapper"></div>
<mat-card-header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
width="30"
height="30"
[ngSrc]="user.profilePictureUrl"
referrerpolicy="no-referrer"
alt="Profilbild">

<mat-menu #menu="matMenu">
Expand All @@ -33,7 +34,7 @@
color="accent"
matTooltip="Event erstellen"
class="event-add-button"
(click)="openDialog()"
(click)="openCreateEventDialog()"
[disabled]="user.guest"
>
<mat-icon>add</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export class ProfileMenuComponent {
return [user.firstName, user.lastName].filter(x => x).join(" ");
}

openDialog() {
openCreateEventDialog() {
this.dialog.open(EventCreationComponent);
}

openUserSettings(){
this.dialog.open(UserSettingsComponent);
this.dialog.open(UserSettingsComponent, {
width: "600px"
});
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<div class="wrapper" #wrapper>
<mat-card
appearance="outlined"
routerLinkActive="selected"
(click)="switchColor()"
class="settingscard"

(click)="onSelect.emit()"
(keyup.enter)="onSelect.emit()"
[class.selected]="isSelected"
tabindex="0"
class="settings-card"
>
<div class="ripple-container" mat-ripple [matRippleTrigger]="wrapper"></div>

<mat-card-content>
<div class="cardcontent-container">
<p class="colorcard" [style.background]="'var(--'+color+'-primary)'"></p>
{{color}}
</div>
<div class="cardcontent-container">
<div class="colorcard" [style.background-color]="'var(--' + colorMode.toLowerCase() + '-primary-preview)'"></div>
{{ colorMode | titlecase }}
</div>
</mat-card-content>
</mat-card>
</div>

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.settingscard {
.settings-card {
cursor: pointer;
overflow: hidden;
--mdc-outlined-card-outline-color: transparent;

&.selected {
--mdc-outlined-card-outline-color: var(--primary-color);
Expand All @@ -19,24 +20,26 @@
height: 100%;
z-index: 0;
}
mat-card-content{
padding: 5% 0 5% 5%;

mat-card-content {
padding: 8px !important;
}
.cardcontent-container{
display: grid;
grid-template-columns: 1fr 3fr;
grid-gap: 2%;
align-items: center;
//align-items: center;
//padding: 10% 0 10% 0;
.colorcard{
position: relative;
aspect-ratio: 1 / 1;
height: 70%;
padding: 0;
margin: 0;

border-radius: 12px;
}
.cardcontent-container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
gap: var(--size-12);
align-items: center;
font-weight: var(--font-weight-subtitle);

.colorcard {
position: relative;
aspect-ratio: 1 / 1;
height: 50px;
padding: 0;
margin: 0;
border-radius: 12px;
}
}

Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
import {Component, Input, ViewChild} from '@angular/core';
import {EventOverview} from "../../../../model/event";
import {User} from "../../../../model/user";
import {HttpClient} from "@angular/common/http";
import {UserService} from "../../../../services/user.service";
import {iconButton} from "material-components-web/index";
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {ColorMode} from "../../../../model/user";

@Component({
selector: 'app-user-settings-item',
templateUrl: './user-settings-item.component.html',
styleUrl: './user-settings-item.component.scss'
})
export class UserSettingsItemComponent {
constructor(
public userService: UserService,
private http: HttpClient
) {}

@Input()
color!: string;
colorMode!: ColorMode;

@Input()
isSelected = false;

@Output()
onSelect = new EventEmitter();

//switch color on change
switchColor() {
document.documentElement.setAttribute("theme", this.color);
console.log("curr ColorMode: "+document.documentElement.getAttribute("theme"))
let colormode:string=this.color.replace("-","_").toUpperCase();
this.http.put("http://localhost:8080/user/self", {
"settings": {
"colorMode" : colormode
}
},{withCredentials: true}).subscribe(result =>{
console.log(result);
})
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
<h1 mat-dialog-title class="prim-color">Einstellungen</h1>
<p class="subTitle" mat-dialog-title>Wähle ein Farbschema aus.</p>
<h2 mat-dialog-title class="prim-color">
Einstellungen
<button mat-icon-button class="close-button" matDialogClose tabindex="-1">
<mat-icon>close</mat-icon>
</button>
</h2>
<mat-dialog-content>
<p class="subTitle">Day Theme</p>
<mat-divider></mat-divider>
<ul class="color-list">
<p>Wähle ein Farbschema aus</p>

@if (userService.user | async; as user) {
<h4 class="section-title">Day Theme</h4>
<ul class="color-list">
@for (color of lightColors; track color) {
<li>
<app-user-settings-item [color]="color"></app-user-settings-item>
<app-user-settings-item
[colorMode]="color"
[isSelected]="user.settings.colorMode === color"
(onSelect)="selectColorMode(color)"
></app-user-settings-item>
</li>
}
</ul>
<p class="subTitle">Night Theme</p>
<mat-divider></mat-divider>
<ul class="color-list">
</ul>

<h4 class="section-title">Night Theme</h4>
<ul class="color-list">
@for (color of darkColors; track color) {
<li>
<app-user-settings-item [color]="color"></app-user-settings-item>
<app-user-settings-item
[colorMode]="color"
[isSelected]="user.settings.colorMode === color"
(onSelect)="selectColorMode(color)"
></app-user-settings-item>
</li>
}
</ul>
} @else {
<div class="loading-container">
<mat-spinner></mat-spinner>
<p>Profil wird geladen...</p>
</div>
}
</mat-dialog-content>
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
.close-button {
float: right;
margin-top: 8px;
}

.container {
overflow-y: auto;
height: 100%;
}

.color-list {
list-style: none;
padding: 0;
margin: 0;


li:not(:last-child) {
margin-bottom: var(--size-12);
margin-bottom: 2px;
}
}
.prim-color{

.prim-color {
color: var(--primary-color);
}
.subTitle{

.section-title {
color: var(--secondary-color);
margin-top: var(--size-24);
}

.loading-container {
text-align: center;
padding: var(--size-12);

mat-spinner {
margin-left: auto;
margin-right: auto;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { Component } from '@angular/core';
import {MatDialogModule} from "@angular/material/dialog";
import {Component} from '@angular/core';
import {UserService} from "../../../services/user.service";
import {ColorMode} from "../../../model/user";

@Component({
selector: 'app-user-settings',
templateUrl: './user-settings.component.html',
styleUrl: './user-settings.component.scss'
})
export class UserSettingsComponent {
lightColors:string[]=["light", "water", "sunset", "grassland"]
darkColors :string[] = ["dark", "developer","autumn"];
lightColors = [ColorMode.LIGHT, ColorMode.WATER, ColorMode.SUNSET, ColorMode.GRASSLAND];
darkColors = [ColorMode.DARK, ColorMode.DEVELOPER, ColorMode.AUTUMN];

}
isLoading = false;

constructor(public userService: UserService) {
}

selectColorMode(colorMode: ColorMode) {
this.isLoading = true;
this.userService.applyThemeAttribute(colorMode);
this.userService.updateTheme(colorMode).subscribe(() => {
this.isLoading = false;
});
}
}
29 changes: 22 additions & 7 deletions frontend/src/model/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export type User = {
id: string
creationDate: string
email: string
firstName: string
lastName: string
profilePictureUrl: string
guest: true | undefined
id: string;
creationDate: string;
email: string;
firstName: string;
lastName: string;
profilePictureUrl: string;
settings: UserSettings;
guest: true | undefined;
}

export type SimpleUser = {
Expand All @@ -14,3 +15,17 @@ export type SimpleUser = {
lastName: string;
profilePictureUrl: string;
}

export type UserSettings = {
colorMode: ColorMode;
}

export enum ColorMode {
LIGHT = "LIGHT",
DARK = "DARK",
WATER = "WATER",
GRASSLAND = "GRASSLAND",
SUNSET = "SUNSET",
DEVELOPER = "DEVELOPER",
AUTUMN = "AUTUMN"
}
Loading

0 comments on commit 85a1855

Please sign in to comment.