From 6983a09b486d09b4968b9e89b98170a76008694a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Mon, 11 Feb 2019 17:52:43 +0100
Subject: [PATCH] Fix statistics-landing-tab

---
 .../statistics-page/statistics-page.component.ts    | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/app/components/shared/statistics-page/statistics-page.component.ts b/src/app/components/shared/statistics-page/statistics-page.component.ts
index 4211c2de9..ae3b5bc18 100644
--- a/src/app/components/shared/statistics-page/statistics-page.component.ts
+++ b/src/app/components/shared/statistics-page/statistics-page.component.ts
@@ -1,10 +1,11 @@
-import { Component, OnInit } from '@angular/core';
+import { Component, OnInit, ViewChild } from '@angular/core';
 import { ActivatedRoute } from '@angular/router';
 import { RoomService } from '../../../services/http/room.service';
 import { ContentGroup } from '../../../models/content-group';
 import { Room } from '../../../models/room';
 import { TranslateService } from '@ngx-translate/core';
 import { LanguageService } from '../../../services/util/language.service';
+import { MatTabGroup } from '@angular/material';
 
 @Component({
   selector: 'app-statistics',
@@ -17,6 +18,9 @@ export class StatisticsPageComponent implements OnInit {
   room: Room;
   contentGroups: ContentGroup[];
   isLoading = true;
+  currentCG: string;
+
+  @ViewChild(MatTabGroup) tabGroup: MatTabGroup;
 
   constructor(
     private route: ActivatedRoute,
@@ -27,7 +31,9 @@ export class StatisticsPageComponent implements OnInit {
   }
 
   ngOnInit(): void {
+    this.currentCG = sessionStorage.getItem('contentGroup');
     this.getRoom(localStorage.getItem('roomId'));
+    this.tabGroup.selectedIndex = 1;
   }
 
   getRoom(id: string): void {
@@ -35,6 +41,11 @@ export class StatisticsPageComponent implements OnInit {
     this.roomService.getRoom(id).subscribe(room => {
       this.contentGroups = room.contentGroups;
       this.isLoading = false;
+      for (let i = 0; i < this.contentGroups.length; i++) {
+        if (this.currentCG.includes(this.contentGroups[i].name)) {
+          this.tabGroup.selectedIndex = i;
+        }
+      }
     });
   }
 
-- 
GitLab