diff --git a/src/app/components/about/about.component.html b/src/app/components/about/about.component.html index 5bf352e..6f2cb3e 100644 --- a/src/app/components/about/about.component.html +++ b/src/app/components/about/about.component.html @@ -20,7 +20,7 @@
level | -{{level.level}} | +{{level.levelNumber}} | level name | diff --git a/src/app/components/about/about.component.ts b/src/app/components/about/about.component.ts index 3983dc3..2fdf072 100644 --- a/src/app/components/about/about.component.ts +++ b/src/app/components/about/about.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {Activitylist} from 'src/app/models/activity'; -import {Levellist} from 'src/app/models/levellist'; +import {LevelList} from 'src/app/models/levellist'; import {MatSort} from '@angular/material/sort'; import {MatTableDataSource} from '@angular/material/table'; import {ActivityService} from 'src/app/services/activity/activity.service'; @@ -12,12 +12,12 @@ import {ActivityService} from 'src/app/services/activity/activity.service'; }) export class AboutComponent implements OnInit { actionlist: Activitylist = new Activitylist(); - levellist: Levellist = new Levellist(); + levellist: LevelList = new LevelList(); displayedColumns = ['points', 'name', 'description']; dataSource = new MatTableDataSource(this.actionlist.Actions); displayedLevelColumns = ['level', 'name']; - levelSource = this.levellist.levels; + levelSource = new MatTableDataSource(this.levellist.levels); constructor(private activityService: ActivityService) { } @@ -31,6 +31,12 @@ export class AboutComponent implements OnInit { this.dataSource = new MatTableDataSource(this.actionlist.Actions); this.dataSource.sort = this.sort; }); + this.activityService.getLevels(); + this.activityService.levelList.subscribe(response => { + this.levellist = response; + this.levelSource = new MatTableDataSource(this.levellist.levels); + this.levelSource.sort = this.sort; + }); } } diff --git a/src/app/components/main-navigation/main-navigation.component.ts b/src/app/components/main-navigation/main-navigation.component.ts index a9bcdc2..3898ce2 100644 --- a/src/app/components/main-navigation/main-navigation.component.ts +++ b/src/app/components/main-navigation/main-navigation.component.ts @@ -4,7 +4,6 @@ import {DatasharingService} from '../../services/datasharing.service'; import {RequestService} from '../../services/request/request.service'; import {SettingsService} from '../../services/settings/settings.service'; import {environment} from 'src/environments/environment'; -import {Levellist} from 'src/app/models/levellist'; import {Router} from '@angular/router'; import {User} from 'src/app/models/user'; import {OverlayContainer} from '@angular/cdk/overlay'; @@ -33,7 +32,6 @@ export class MainNavigationComponent implements OnInit { userId: number; username: string; user: User; - levellist: Levellist = new Levellist(); level: string; points: number; profileUrl = '/profile/1'; diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 200f2d9..22232a7 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit} from '@angular/core'; import {NavigationEnd, Router} from '@angular/router'; import {User} from 'src/app/models/user'; -import {Levellist} from 'src/app/models/levellist'; +import {LevelList} from 'src/app/models/levellist'; import {RequestService} from 'src/app/services/request/request.service'; import {DatasharingService} from '../../services/datasharing.service'; import {ProfileService} from 'src/app/services/profile/profile.service'; @@ -18,7 +18,7 @@ import {Lightbox} from 'ngx-lightbox'; styleUrls: ['./profile.component.sass'] }) export class ProfileComponent implements OnInit { - levellist: Levellist = new Levellist(); + levellist: LevelList = new LevelList(); ownProfile = false; userProfile: User = new User(); self: User; diff --git a/src/app/models/friendinfo.ts b/src/app/models/friendinfo.ts index 887737b..637d000 100644 --- a/src/app/models/friendinfo.ts +++ b/src/app/models/friendinfo.ts @@ -1,5 +1,3 @@ -import {Levellist} from 'src/app/models/levellist'; - export class FriendInfo { id: number; name: string; diff --git a/src/app/models/levellist.ts b/src/app/models/levellist.ts index 09be30c..b510103 100644 --- a/src/app/models/levellist.ts +++ b/src/app/models/levellist.ts @@ -1,23 +1,27 @@ -export class Levellist { - levels: { level: number, name: string, points: number }[] = [ - {level: 0, name: 'Green Horn', points: 0}, - {level: 1, name: 'Good Willed', points: 100}, - {level: 2, name: 'Helper', points: 200}, - {level: 3, name: 'World Saver', points: 300}, - {level: 4, name: 'Hero of the Green Country', points: 400}, - {level: 5, name: 'Champion of the Earth', points: 500}, - {level: 6, name: 'Intergallactic Superhero', points: 600}, - ]; +export class Level { + id: number; + name: string; + levelNumber: number; + points: number; - getLevelName(level: number): any { - let name = 'not defined'; + constructor(id: number, name: string, levelNumber: number, points: number) { + this.id = id; + this.name = name; + this.levelNumber = levelNumber; + this.points = points; + } +} +export class LevelList { + levels: Level[] = []; + + getLevelName(level: number): string { + let name = 'not defined'; for (const rank of this.levels) { - if (level === rank.level) { + if (level === rank.levelNumber) { name = rank.name; } } return name; } - } diff --git a/src/app/services/activity/activity.service.ts b/src/app/services/activity/activity.service.ts index df2246d..8056a9c 100644 --- a/src/app/services/activity/activity.service.ts +++ b/src/app/services/activity/activity.service.ts @@ -1,18 +1,40 @@ import {Injectable} from '@angular/core'; import {BehaviorSubject} from 'rxjs'; import {Activity, Activitylist} from 'src/app/models/activity'; +import {Level, LevelList} from 'src/app/models/levellist'; import {environment} from 'src/environments/environment'; -import {Http} from '@angular/http'; +import {HttpClient, HttpErrorResponse} from '@angular/common/http'; +import {BaseService} from '../base.service'; @Injectable({ providedIn: 'root' }) -export class ActivityService { +export class ActivityService extends BaseService { public activitylist = new BehaviorSubject
---|