Adds logout and login buttons to the footer in the home component

parent 7e4075ac
Pipeline #18239 passed with stages
in 10 minutes and 28 seconds
......@@ -27,7 +27,8 @@ import { SharedService } from '../../service/shared/shared.service';
import { StorageService } from '../../service/storage/storage.service';
import { ThemesService } from '../../service/themes/themes.service';
import { ITrackClickEvent, TrackingService } from '../../service/tracking/tracking.service';
import { DB_TABLE, LANGUAGE, STORAGE_KEY } from '../../shared/enums';
import { UserService } from '../../service/user/user.service';
import { DB_TABLE, LANGUAGE, STORAGE_KEY, USER_AUTHORIZATION } from '../../shared/enums';
@Component({
selector: 'app-home',
......@@ -101,20 +102,12 @@ export class HomeComponent implements OnInit, OnDestroy {
private quizApiService: QuizApiService,
private lobbyApiService: LobbyApiService,
private storageService: StorageService,
private userService: UserService,
public sharedService: SharedService,
) {
this.footerBarService.TYPE_REFERENCE = HomeComponent.TYPE;
footerBarService.replaceFooterElements([
this.footerBarService.footerElemAbout,
this.footerBarService.footerElemTranslation,
this.footerBarService.footerElemTheme,
this.footerBarService.footerElemFullscreen,
this.footerBarService.footerElemHashtagManagement,
this.footerBarService.footerElemImport,
]);
headerLabelService.headerLabel = 'default';
if (isPlatformBrowser(this.platformId)) {
......@@ -128,6 +121,11 @@ export class HomeComponent implements OnInit, OnDestroy {
this.cleanUpSessionStorage();
}
this.updateFooterElements(this.userService.isLoggedIn);
this.userService.loginNotifier.subscribe(isLoggedIn => {
this.updateFooterElements(isLoggedIn);
});
this.connectionService.initConnection().then(() => {
if (!this.connectionService.socket) {
return;
......@@ -156,11 +154,17 @@ export class HomeComponent implements OnInit, OnDestroy {
this._routerSubscription = this.route.params.subscribe(async params => {
if (!Object.keys(params).length || !params.themeId || !params.languageId) {
const theme = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME).toPromise();
if (theme) {
return;
}
await this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME, DefaultSettings.defaultQuizSettings.theme).toPromise();
this.themesService.updateCurrentlyUsedTheme();
return;
}
if (isPlatformBrowser(this.platformId)) {
await this.storageService.delete(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME).toPromise();
await this.storageService.create(DB_TABLE.CONFIG, STORAGE_KEY.DEFAULT_THEME, params.themeId).toPromise();
this.themesService.updateCurrentlyUsedTheme();
}
......@@ -303,6 +307,30 @@ export class HomeComponent implements OnInit, OnDestroy {
this.reserveQuiz(questionGroup, routingTarget);
}
private updateFooterElements(isLoggedIn: boolean): void {
const footerElements = [
this.footerBarService.footerElemAbout,
this.footerBarService.footerElemTranslation,
this.footerBarService.footerElemTheme,
this.footerBarService.footerElemFullscreen,
this.footerBarService.footerElemHashtagManagement,
this.footerBarService.footerElemImport,
];
if (isLoggedIn) {
if (this.userService.isAuthorizedFor(USER_AUTHORIZATION.EDIT_I18N)) {
footerElements.push(this.footerBarService.footerElemEditI18n);
}
footerElements.push(this.footerBarService.footerElemLogout);
} else {
footerElements.push(this.footerBarService.footerElemLogin);
}
this.footerBarService.replaceFooterElements(footerElements);
}
private async reserveQuiz(questionGroup: IQuestionGroup, routingTarget: Array<string>): Promise<void> {
this.quizApiService.postQuizReservation({
quizName: this.enteredSessionName,
......
......@@ -69,6 +69,7 @@ export class UserService {
public loadConfig(): Promise<boolean> {
return new Promise<boolean>(async resolve => {
if (isPlatformServer(this.platformId)) {
this.isLoggedIn = false;
resolve(true);
return;
}
......@@ -76,6 +77,7 @@ export class UserService {
const tokens = await this.storageService.read(DB_TABLE.CONFIG, STORAGE_KEY.TOKEN).toPromise();
if (!tokens) {
this.isLoggedIn = false;
resolve(true);
return;
}
......@@ -85,6 +87,7 @@ export class UserService {
this._username = tokens.username;
if (!this._staticLoginToken) {
this.isLoggedIn = false;
resolve(true);
return;
}
......
......@@ -57,7 +57,7 @@ export const DefaultSettings = {
restrictToCasLogin: false,
selectedNicks: [],
},
theme: 'theme-SchroedelAktuell',
theme: 'theme-Material',
readingConfirmationEnabled: true,
showResponseProgress: true,
confidenceSliderEnabled: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment