Skip to content

Commit

Permalink
Issue214 (#215)
Browse files Browse the repository at this point in the history
* Fixes #214

* Deleted unused file

*  Immediate loading of available worlds optimized when adding or removing a world of the currently logged in user

* Fix SonarCloud Bug
  • Loading branch information
aiakide authored and Christoph-Meyer committed Apr 18, 2019
1 parent 72d8003 commit c54ae80
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ public void updateLastLogin(final String username) {
}

public Boolean updateUserToWorld(List<UserToWorldDto> userToWorlds) {

userToWorlds.forEach(userToWorld -> {
User user = userRepository.findOne(userToWorld.getUserId());
if (userToWorld.getJoined()) {
user.addWorld(worldRepository.findOne(userToWorld.getWorldId()));
} else {
if(user.getCurrentWorld() != null && user.getCurrentWorld().getId().equals(userToWorld.getWorldId())) {
user.setCurrentWorld(null);
}
user.removeWorld(worldRepository.findOne(userToWorld.getWorldId()));
}

Expand Down
83 changes: 44 additions & 39 deletions sonarQuest-frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {UiDesignService} from './services/ui-design.service';
import {MatDialog} from '@angular/material';
import {AfterViewInit, Component, OnInit} from '@angular/core';
import {TdMediaService} from '@covalent/core';
import {Router} from '@angular/router';
import {WorldService} from './services/world.service';
import {World} from './Interfaces/World';
import {TranslateService} from '@ngx-translate/core';
import {UiDesign} from './Interfaces/UiDesign';
import {AuthenticationService} from './login/authentication.service';
import {LoginComponent} from './login/login.component';
import {UserService} from './services/user.service';
import {User} from './Interfaces/User';
import {PermissionService} from './services/permission.service';
import {RoutingUrls} from './app-routing/routing-urls';
import { UiDesignService } from './services/ui-design.service';
import { MatDialog } from '@angular/material';
import { AfterViewInit, Component, OnInit } from '@angular/core';
import { TdMediaService } from '@covalent/core';
import { Router } from '@angular/router';
import { WorldService } from './services/world.service';
import { World } from './Interfaces/World';
import { TranslateService } from '@ngx-translate/core';
import { UiDesign } from './Interfaces/UiDesign';
import { AuthenticationService } from './login/authentication.service';
import { LoginComponent } from './login/login.component';
import { UserService } from './services/user.service';
import { User } from './Interfaces/User';
import { PermissionService } from './services/permission.service';
import { RoutingUrls } from './app-routing/routing-urls';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -58,15 +58,15 @@ export class AppComponent implements OnInit, AfterViewInit {
private authService: AuthenticationService,
private permissionService: PermissionService,
private userService: UserService) {


translate.setDefaultLang('en'); // Fallback language when a translation isn't found in the current language.
translate.use(translate.getBrowserLang()); // The lang to use. If the lang isn't available, it will use the current loader to get them.
}

protected login(): void {
this.dialog.open(LoginComponent, {panelClass: 'dialog-sexy', width: '500px'}).afterClosed()
.subscribe(() => this.setDesign());
this.dialog.open(LoginComponent, { panelClass: 'dialog-sexy', width: '500px' }).afterClosed()
.subscribe(() => this.setDesign());
}

protected logout(): void {
Expand All @@ -88,7 +88,8 @@ export class AppComponent implements OnInit, AfterViewInit {
this.user = this.userService.getUser();
this.updateMenu();
this.susbcribeWorlds();
this.setDesign()
this.setDesign();
this.updateWorldsFromCurrentUser();
}
});
this.setPreDesign();
Expand Down Expand Up @@ -118,21 +119,25 @@ export class AppComponent implements OnInit, AfterViewInit {
}


private susbcribeWorlds(){
this.worldService.currentWorld$.subscribe(world =>{
this.currentWorld = world;
private susbcribeWorlds() {
this.worldService.currentWorld$.subscribe(world => {
this.currentWorld = world;
this.setBackground();
})
this.worldService.worlds$ .subscribe(worlds=>{
this.worlds = worlds;
this.worldService.worlds$.subscribe(worlds => {
this.worlds = worlds;
})
}

private setBackground(){
if (this.currentWorld && this.user ) {
this.changebackground( this.currentWorld.image);
protected updateWorldsFromCurrentUser(): void {
this.worldService.getWorlds();
}

private setBackground() {
if (this.currentWorld && this.user) {
this.changebackground(this.currentWorld.image);
} else if (!this.currentWorld && this.user) {
this.changebackground("");
this.changebackground("");
} else if (!this.currentWorld && !this.user) {
this.changebackground("bg13");
}
Expand Down Expand Up @@ -177,7 +182,7 @@ export class AppComponent implements OnInit, AfterViewInit {
}

changebackground(image: string) {
if (image != ""){
if (image != "") {
this.body.style.backgroundImage = 'url("/assets/images/background/' + image + '.jpg")';
} else {
this.body.style.backgroundImage = 'url("")';
Expand All @@ -186,23 +191,23 @@ export class AppComponent implements OnInit, AfterViewInit {
}

setDesign() {
if (this.user){
if (this.user) {
this.uiDesignService.getUiDesign().subscribe(ui => {
this.ui = ui;
console.log(ui)
this.body.className = '';
this.ui = ui;
console.log(ui)
this.body.className = '';
this.addClass(this.body, this.ui.name);
this.addClass(this.body, "background-image");
});
});
}
}

setPreDesign(){
setPreDesign() {
this.toggleDesign();
}

toggleDesign() {
const dark = 'dark';
const dark = 'dark';
const light = 'light';

if (this.hasClass(this.body, light)) { // If light is choosen, toggle to dark
Expand All @@ -219,7 +224,7 @@ export class AppComponent implements OnInit, AfterViewInit {
this.addClass(this.body, "background-image");
}

hasClass(element: HTMLScriptElement, cssClass: string): Boolean{
hasClass(element: HTMLScriptElement, cssClass: string): Boolean {
return element.classList.contains(cssClass);
}

Expand All @@ -228,8 +233,8 @@ export class AppComponent implements OnInit, AfterViewInit {
return newString.replace(' ', ' ');
}

addClass(element, cssClass){
if (!this.hasClass(element, cssClass)){
addClass(element, cssClass) {
if (!this.hasClass(element, cssClass)) {
element.className += ' ' + cssClass + ' ';
}
element.className.replace(' ', ' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UserToWorldService } from '../../../../../../services/user-to-world.ser
import { Role } from 'app/Interfaces/Role';
import { RoleService } from 'app/services/role.service';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { WorldService } from 'app/services/world.service';

@Component({
selector: 'app-admin-developer-edit',
Expand Down Expand Up @@ -46,18 +47,17 @@ export class AdminDeveloperEditComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) public data: {user: User, users: User[]},
private imageService: ImageService,
private roleService: RoleService,
private userToWorldService: UserToWorldService
private userToWorldService: UserToWorldService,
private worldService: WorldService
) {
}

ngOnInit() {

this.translateTable();
this.loadImages();
this.userToWorldService.getUserToWorlds(this.data.user).then(userToWorlds => {
this.userToWorlds = userToWorlds
});

});
this.roleService.getRoles().then(roles => this.roles = roles);
this.nameTaken = false;
this.mailTaken = false;
Expand All @@ -75,6 +75,9 @@ export class AdminDeveloperEditComponent implements OnInit {
this.userService.updateUser(this.data.user).then(() => {
this.userToWorldService.updateUserToWorld(this.userToWorlds);
this.dialogRef.close(true);
if(this.data.user.id === this.userService.getUser().id){
this.worldService.getWorlds()
}
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {TranslateService} from '@ngx-translate/core';
import {Component, OnInit} from '@angular/core';
import {WorldService} from '../../../../services/world.service';
import {World} from '../../../../Interfaces/World';
import { TranslateService } from '@ngx-translate/core';
import { Component, OnInit } from '@angular/core';
import { WorldService } from '../../../../services/world.service';
import { World } from '../../../../Interfaces/World';
import {
IPageChangeEvent, ITdDataTableColumn, ITdDataTableSortChangeEvent, TdDataTableService,
TdDataTableSortingOrder
} from '@covalent/core';
import {MatDialog} from '@angular/material';
import {EditWorldComponent} from './components/edit-world/edit-world.component';
import {TaskService} from '../../../../services/task.service';
import {QuestService} from '../../../../services/quest.service';
import {AdventureService} from '../../../../services/adventure.service';
import {LoadingService} from '../../../../services/loading.service';
import { MatDialog } from '@angular/material';
import { EditWorldComponent } from './components/edit-world/edit-world.component';
import { TaskService } from '../../../../services/task.service';
import { QuestService } from '../../../../services/quest.service';
import { AdventureService } from '../../../../services/adventure.service';
import { LoadingService } from '../../../../services/loading.service';
import { UserService } from 'app/services/user.service';
import { RoleService } from 'app/services/role.service';

@Component({
selector: 'app-admin-world',
Expand All @@ -23,12 +25,12 @@ export class AdminWorldComponent implements OnInit {
currentWorld: World;
worlds: World[];
columns: ITdDataTableColumn[] = [
{name: 'id', label: 'Id'},
{name: 'name', label: 'Name'},
{name: 'project', label: 'Project', width: { min: 400 } },
{name: 'active', label: 'Active'},
{name: 'usequestcards', label: 'Questcards'},
{name: 'edit', label: ''}
{ name: 'id', label: 'Id' },
{ name: 'name', label: 'Name' },
{ name: 'project', label: 'Project', width: { min: 400 } },
{ name: 'active', label: 'Active' },
{ name: 'usequestcards', label: 'Questcards' },
{ name: 'edit', label: '' }
];

// Sort / Filter / Paginate variables
Expand All @@ -43,13 +45,14 @@ export class AdminWorldComponent implements OnInit {
sortOrder: TdDataTableSortingOrder = TdDataTableSortingOrder.Ascending;

constructor(private worldService: WorldService,
private questService: QuestService,
private adventureService: AdventureService,
private taskService: TaskService,
private _dataTableService: TdDataTableService,
private translateService: TranslateService,
private dialog: MatDialog,
private loadingService: LoadingService) {
private questService: QuestService,
private adventureService: AdventureService,
private taskService: TaskService,
private _dataTableService: TdDataTableService,
private translateService: TranslateService,
private dialog: MatDialog,
private loadingService: LoadingService,
private userService: UserService) {
}

ngOnInit() {
Expand All @@ -62,18 +65,21 @@ export class AdminWorldComponent implements OnInit {
if (this.worldService.getCurrentWorld()) {
this.currentWorld = this.worldService.getCurrentWorld();
}
this.loadWorlds();
if (this.userService.getUser().role.name.toLocaleUpperCase() === 'ADMIN') {
this.loadWorlds();
}

}

translateTable() {
this.translateService.get('TABLE.COLUMNS').subscribe((col_names) => {
this.columns = [
{name: 'id', label: col_names.ID, width: 35},
{name: 'name', label: col_names.NAME},
{name: 'project', label: col_names.PROJECT, width: { min: 400 }},
{name: 'active', label: col_names.ACTIVE},
{name: 'usequestcards', label: col_names.USE_QUEST_CARDS},
{name: 'edit', label: ''}]
{ name: 'id', label: col_names.ID, width: 35 },
{ name: 'name', label: col_names.NAME },
{ name: 'project', label: col_names.PROJECT, width: { min: 400 } },
{ name: 'active', label: col_names.ACTIVE },
{ name: 'usequestcards', label: col_names.USE_QUEST_CARDS },
{ name: 'edit', label: '' }]
});
}

Expand All @@ -85,7 +91,7 @@ export class AdminWorldComponent implements OnInit {
}

protected editWorld(world: World) {
this.dialog.open(EditWorldComponent, {data: world}).afterClosed().subscribe(() => {
this.dialog.open(EditWorldComponent, { data: world }).afterClosed().subscribe(() => {
this.loadWorlds();
this.worldService.loadWorld();
})
Expand Down

0 comments on commit c54ae80

Please sign in to comment.