Skip to content

Commit

Permalink
Fixes final lint issues + prettier format
Browse files Browse the repository at this point in the history
  • Loading branch information
ComputasAlex committed Jul 2, 2024
1 parent 3fa5568 commit d618f4d
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 129 deletions.
11 changes: 6 additions & 5 deletions src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { LoginService } from './login.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { AuthStatus } from '../shared/models/backend-interfaces';

@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss'],
standalone: true,
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss'],
standalone: true,
})
export class AdminComponent {
constructor(private router: Router, private loginService: LoginService, private _snackBar: MatSnackBar) {}

login(username: string, password: string) {
// Call on login service to authorize user
this.loginService.login(username, password).subscribe(
(res: any) => {
(res: AuthStatus) => {
if (res.success === 'OK') {
this.loginService.setLoggedIn();
this.router.navigate(['admin/info']);
Expand Down
15 changes: 8 additions & 7 deletions src/app/admin/info/info.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { InfoDialogComponent } from './../info-dialog/info-dialog.component';
import { PairingService } from '../../game/game-multiplayer/services/pairing.service';
import { MatButton } from '@angular/material/button';
import { StatusData } from '@/app/shared/models/backend-interfaces';

@Component({
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.scss'],
standalone: true,
imports: [MatButton],
selector: 'app-info',
templateUrl: './info.component.html',
styleUrls: ['./info.component.scss'],
standalone: true,
imports: [MatButton],
})
export class InfoComponent {
datasetString = 'Nullstill treningssett til originalen';
Expand Down Expand Up @@ -147,11 +148,11 @@ export class InfoComponent {
getInformation() {
this.resetAll();
this.loginService.getStatus().subscribe(
(res: any) => {
(res: StatusData) => {
const name = res.CV_iteration_name;
const time = res.CV_time_created;
const count = res.BLOB_image_count;
this._dialog.openDialog(name, time, count);
this._dialog.openDialog(name, time, count.toString());
},
() => {
this.openSnackBar(this.errorMsg);
Expand Down
8 changes: 5 additions & 3 deletions src/app/admin/login.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { endpoints } from '../shared/models/endpoints';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthStatus, StatusData } from '../shared/models/backend-interfaces';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -46,8 +48,8 @@ export class LoginService {
);
}

attemptLogin(formData: FormData) {
return this.http.post(`${endpoints.TEKNISKBACKEND}/${endpoints.AUTH}`, formData, {
attemptLogin(formData: FormData): Observable<AuthStatus> {
return this.http.post<AuthStatus>(`${endpoints.TEKNISKBACKEND}/${endpoints.AUTH}`, formData, {
withCredentials: true,
});
}
Expand Down Expand Up @@ -83,7 +85,7 @@ export class LoginService {
}

getStatus() {
return this.http.post(
return this.http.post<StatusData>(
`${endpoints.TEKNISKBACKEND}/${endpoints.ADMIN}/${endpoints.GETSTATUS}`,
{},
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AppComponent implements OnInit {
title = 'Teknisk Museum';

userActivity = 0;
userInactive = new Subject<any>();
userInactive = new Subject<boolean | undefined>();

isDialogOpen = false;
inactivityTime = environment.inactivityTime;
Expand Down
51 changes: 24 additions & 27 deletions src/app/game/game-config.service.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';

export interface GameConfig {
difficultyId: number,
difficultyId: number;
rounds: number;
secondsPerRound: number;
timeToStartClassify: number;
}

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class GameConfigService {
private _configValues: GameConfig = {
difficultyId: 1,
rounds: 3,
secondsPerRound: 30,
timeToStartClassify: 23
};

constructor() {}
timeToStartClassify: 23,
};

private readonly _config = new BehaviorSubject<GameConfig>(this._configValues); // Easy mode as default
config$ = this._config.asObservable();



setDifficultyLevel(level: string): void {
switch (level) {
case 'easy':
this.setConfig = {
difficultyId: 1,
rounds: 3,
secondsPerRound: 30,
timeToStartClassify: 25
this.setConfig = {
difficultyId: 1,
rounds: 3,
secondsPerRound: 30,
timeToStartClassify: 25,
};
break;
case 'medium':
this.setConfig = {
difficultyId: 2,
rounds: 3,
secondsPerRound: 20,
timeToStartClassify: 15
this.setConfig = {
difficultyId: 2,
rounds: 3,
secondsPerRound: 20,
timeToStartClassify: 15,
};
break;
case 'hard':
this.setConfig = {
difficultyId: 3,
rounds: 3,
secondsPerRound: 20,
timeToStartClassify: 15
};
this.setConfig = {
difficultyId: 3,
rounds: 3,
secondsPerRound: 20,
timeToStartClassify: 15,
};
break;
}
}

set setConfig(newConfigValues: GameConfig) {
this._configValues = { ...this._configValues, ...newConfigValues };
this._config.next(newConfigValues);
this._config.next(newConfigValues);
}

get getConfig(): GameConfig {
return this._configValues;
}
}
}
8 changes: 4 additions & 4 deletions src/app/game/game-draw/game-draw.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ export class GameDrawComponent implements OnInit, OnDestroy {
});
}

sortOnCertainty(res: any) {
const arr: any = [];
sortOnCertainty(res: PredictionData) {
const arr: Certainty[] = [];
Object.entries(res.certainty).map((keyValue) => {
const [label, certainty] = keyValue;
arr.push({ label, certainty });
const [, certainty] = keyValue;
arr.push(certainty);
});
arr.sort((a: Certainty, b: Certainty) => {
return b.certainty - a.certainty;
Expand Down
5 changes: 1 addition & 4 deletions src/app/game/game.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { GameIntermediateResultComponent } from './game-intermediate-result/game
import { GameDrawComponent } from './game-draw/game-draw.component';
import { GameInfoComponent } from './game-info/game-info.component';
import { GamePickDifficultyComponent } from './game-pick-difficulty/game-pick-difficulty.component';
import { GameConfigService } from './game-config.service';


@Component({
selector: 'app-game',
Expand Down Expand Up @@ -78,7 +76,7 @@ export class GameComponent implements OnInit, OnDestroy {
this.showDifficultyPicker = true;
this.showHowToPlay = false;
}

getDrawWord() {
this.showWordToDraw = true;
this.showDifficultyPicker = false;
Expand Down Expand Up @@ -106,4 +104,3 @@ export class GameComponent implements OnInit, OnDestroy {
this.guessDone = false;
}
}

52 changes: 26 additions & 26 deletions src/app/services/translation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ import { Observable, BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class TranslationService {
private translations: any = {};
private langSubject = new BehaviorSubject<string>('NO');
lang$ = this.langSubject.asObservable();
private translations: Record<string, string> = {};
private langSubject = new BehaviorSubject<string>('NO');
lang$ = this.langSubject.asObservable();

constructor(private http: HttpClient) { }

loadTranslations(lang: string): Observable<any> {
return this.http.get(`/assets/translation/${lang}.json`).pipe(
map(translations => {
this.translations = translations;
this.langSubject.next(lang);
return translations;
})
);
}
constructor(private http: HttpClient) {}

getTranslation(key: string): string {
return this.translations[key] || key;
}
loadTranslations(lang: string): Observable<Record<string, string>> {
return this.http.get<Record<string, string>>(`/assets/translation/${lang}.json`).pipe(
map((translations) => {
this.translations = translations;
this.langSubject.next(lang);
return translations;
})
);
}

getCurrentLang(): string {
return this.langSubject.getValue();
}
getTranslation(key: string): string {
return this.translations[key] || key;
}

changeLanguage(lang:string) {
this.loadTranslations(lang).subscribe();
localStorage.setItem('language', lang);
this.langSubject.next(lang);
}
getCurrentLang(): string {
return this.langSubject.getValue();
}

changeLanguage(lang: string) {
this.loadTranslations(lang).subscribe();
localStorage.setItem('language', lang);
this.langSubject.next(lang);
}
}
10 changes: 10 additions & 0 deletions src/app/shared/models/backend-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ export interface JoinGameData {
export interface JoinGameReady {
ready: boolean;
}

export interface AuthStatus {
success: string;
}

export interface StatusData {
CV_iteration_name: string;
CV_time_created: string;
BLOB_image_count: number;
}
24 changes: 8 additions & 16 deletions src/app/welcome/welcome.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,29 @@ import { Observable } from 'rxjs';
import { CommonModule } from '@angular/common';

@Component({
selector: 'app-welcome',
templateUrl: './welcome.component.html',
styleUrls: ['./welcome.component.scss'],
standalone: true,
imports: [
RouterLink,
RouterLinkActive,
MatButton,
MatIcon,
TranslatePipe,
CommonModule
],
providers: [TranslationService, HttpClient]
selector: 'app-welcome',
templateUrl: './welcome.component.html',
styleUrls: ['./welcome.component.scss'],
standalone: true,
imports: [RouterLink, RouterLinkActive, MatButton, MatIcon, TranslatePipe, CommonModule],
providers: [TranslationService, HttpClient],
})
export class WelcomeComponent implements OnInit {
private headerClicks = 0;
currentLang$: Observable<string>;

constructor(
private multiplayerService: MultiplayerService,
private drawingService: DrawingService,
private router: Router,
private translationService: TranslationService
) {
this.currentLang$ = this.translationService.lang$
this.currentLang$ = this.translationService.lang$;
}

ngOnInit() {
this.multiplayerService.clearState();
this.drawingService.clearState();
const savedLanguage = localStorage.getItem('language') || 'NO';
this.translationService.loadTranslations(this.translationService.getCurrentLang()).subscribe();
//this.translationService.loadTranslations(savedLanguage).subscribe();
}
Expand Down
Loading

0 comments on commit d618f4d

Please sign in to comment.