From f652829c6b50d02a2f6e49aea7314968b7d608ba Mon Sep 17 00:00:00 2001
From: Ron Lucke <lucke@elan-ev.de>
Date: Fri, 5 Nov 2021 15:03:40 +0000
Subject: [PATCH] Biest #254

---
 app/controllers/my_courses.php         | 42 +++++++-------------------
 resources/vue/components/MyCourses.vue |  5 ++-
 resources/vue/mixins/MyCoursesMixin.js |  2 --
 resources/vue/store/MyCoursesStore.js  |  5 +++
 4 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/app/controllers/my_courses.php b/app/controllers/my_courses.php
index 96d6a675d45..8a4f4727c2f 100644
--- a/app/controllers/my_courses.php
+++ b/app/controllers/my_courses.php
@@ -189,6 +189,7 @@ class MyCoursesController extends AuthenticatedController
                 'allow_dozent_visibility'  => Config::get()->ALLOW_DOZENT_VISIBILITY,
                 'open_groups'              => $GLOBALS['user']->cfg->MY_COURSES_OPEN_GROUPS,
                 'sem_number'               => Config::get()->IMPORTANT_SEMNUMBER,
+                'allow_tiled_display'      => Config::get()->MY_COURSES_ALLOW_TILED_DISPLAY,
                 'display_type'             => Config::get()->MY_COURSES_ALLOW_TILED_DISPLAY && $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY ? 'tiles' : 'tables',
                 'responsive_type'          => Config::get()->MY_COURSES_ALLOW_TILED_DISPLAY && $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY_RESPONSIVE ? 'tiles' : 'tables',
                 'navigation_show_only_new' => $GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY,
@@ -763,28 +764,6 @@ class MyCoursesController extends AuthenticatedController
         $this->redirect($this->url_for('my_courses'));
     }
 
-    /**
-     * Changes a config setting for the current use
-     * @param string $config Config setting
-     * @param bool   $state  State of setting
-     */
-    public function config_action($config, $state = null)
-    {
-        if ($config === 'tiled') {
-            if ($state === null) {
-                $state = !$GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY;
-            }
-            $GLOBALS['user']->cfg->store('MY_COURSES_TILED_DISPLAY', (bool) $state);
-        } elseif ($config === 'new') {
-            if ($state === null) {
-                $state = !$GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY;
-            }
-            $GLOBALS['user']->cfg->store('MY_COURSES_SHOW_NEW_ICONS_ONLY', (bool) $state);
-        }
-
-        $this->redirect('my_courses');
-    }
-
     /**
      * Get widget for grouping selected courses (e.g. by colors, ...)
      * @param      $action
@@ -927,22 +906,23 @@ class MyCoursesController extends AuthenticatedController
             $views->id = 'tiled-courses-sidebar-switch';
             $views->addLink(
                 _('Tabellarische Ansicht'),
-                $this->config('tiled', 0)
+                '#'
             )->setActive(!$GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY);
             $views->addLink(
                 _('Kachelansicht'),
-                $this->config('tiled', 1)
+                '#'
             )->setActive($GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY);
 
-            $options = $sidebar->addWidget(new OptionsWidget());
-            $options->id = 'tiled-courses-new-contents-toggle';
-            $options->addCheckbox(
-                _('Nur neue Inhalte anzeigen'),
-                $GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY,
-                $this->config('new')
-            );
         }
 
+        $options = $sidebar->addWidget(new OptionsWidget());
+        $options->id = 'tiled-courses-new-contents-toggle';
+        $options->addCheckbox(
+            _('Nur neue Inhalte anzeigen'),
+            $GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY,
+            '#'
+        );
+
         $export_widget = $sidebar->addWidget(new ExportWidget());
         $export_widget->addLink(
             _('Veranstaltungsübersicht exportieren'),
diff --git a/resources/vue/components/MyCourses.vue b/resources/vue/components/MyCourses.vue
index 3e99ad79f79..c458f220b0a 100644
--- a/resources/vue/components/MyCourses.vue
+++ b/resources/vue/components/MyCourses.vue
@@ -21,7 +21,7 @@
         </studip-message-box>
         <component v-else :is="displayComponent" :icon-size="iconSize"></component>
 
-        <MountingPortal mount-to="#tiled-courses-sidebar-switch .sidebar-widget-content .widget-list" name="sidebar-switch">
+        <MountingPortal v-if="allowTiled" mount-to="#tiled-courses-sidebar-switch .sidebar-widget-content .widget-list" name="sidebar-switch">
             <my-courses-sidebar-switch></my-courses-sidebar-switch>
         </MountingPortal>
 
@@ -49,6 +49,9 @@ export default {
         MyCoursesNewContentToggle,
     },
     computed: {
+        allowTiled () {
+            return this.getConfig('allow_tiled_display');
+        },
         displayComponent () {
             return this.displayedType === 'tiles'
                  ? MyCoursesTiles
diff --git a/resources/vue/mixins/MyCoursesMixin.js b/resources/vue/mixins/MyCoursesMixin.js
index 99db7de3c6d..81d85ab5e7b 100644
--- a/resources/vue/mixins/MyCoursesMixin.js
+++ b/resources/vue/mixins/MyCoursesMixin.js
@@ -166,9 +166,7 @@ export default {
     created () {
         this.responsiveDisplay = Responsive.media_query.matches;
         Responsive.media_query.addListener(() => {
-            console.log('changing responsive display', Responsive.media_query.matches);
             this.responsiveDisplay = Responsive.media_query.matches;
-            console.log('changed responsive display', this.responsiveDisplay);
         })
     }
 }
diff --git a/resources/vue/store/MyCoursesStore.js b/resources/vue/store/MyCoursesStore.js
index a0900404e44..a2aa2cd6ce2 100644
--- a/resources/vue/store/MyCoursesStore.js
+++ b/resources/vue/store/MyCoursesStore.js
@@ -1,4 +1,9 @@
 const configMapping = {
+    allow_tiled_display: value => {
+        return {
+            MY_COURSES_ALLOW_TILED_DISPLAY: value,
+        }
+    },
     display_type: value => {
         return {
             MY_COURSES_TILED_DISPLAY: value === 'tiles',
-- 
GitLab