Bladeren bron

Back to admin - auto-redir to where the user was

Vijayakrishnan 3 jaren geleden
bovenliggende
commit
4fb4664120
3 gewijzigde bestanden met toevoegingen van 15 en 2 verwijderingen
  1. 1 1
      app/Http/Controllers/HomeController.php
  2. 13 0
      js-dev/mc.js
  3. 1 1
      resources/views/layouts/template.blade.php

+ 1 - 1
app/Http/Controllers/HomeController.php

@@ -2098,7 +2098,7 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
 
             Cookie::queue('sessionKey', $data->data->sessionKey);
 
-            return redirect(route('dashboard'));
+            return redirect($request->input('redir') ?: route('dashboard'));
 
         } catch (\Exception $e) {
             return redirect(route('dashboard'));

+ 13 - 0
js-dev/mc.js

@@ -207,6 +207,7 @@ function onFastLoaded(_data, _href, _history, _target = null) {
             hideMask();
             hideMoeFormMask();
         }
+        appendRedirectUrl();
     } else {
         // fallback
         let msg = 'Unable to open page: ';
@@ -228,10 +229,22 @@ function onFastLoaded(_data, _href, _history, _target = null) {
         $('.stag-content').first().html('<p class="text-danger p-3 small"><b>' + _data + '</b> - ' + msg + '<b>' + _href + '</b></p>');
         hideMask();
         hideMoeFormMask();
+        appendRedirectUrl();
     }
     $('html, body').removeClass('no-scroll');
 }
 
+function appendRedirectUrl(_url) {
+    let targetLocation = window.top.location.pathname + window.top.location.search;
+    if(targetLocation.indexOf('/mc') === 0) {
+        targetLocation = targetLocation.substr(3);
+    }
+    let form = $('.frm-back-to-admin');
+    if(form.length) {
+        form.attr('action', form.attr('data-action') + '?redir=' + targetLocation);
+    }
+}
+
 var fastReload = function(_target = null) {
     var targetLocation = window.top.location.pathname + window.top.location.search;
     if(targetLocation.indexOf('/mc') === 0) {

+ 1 - 1
resources/views/layouts/template.blade.php

@@ -248,7 +248,7 @@
                     @endif
                     <div class="dropdown-menu dropdown-menu-right mcp-theme-1 pt-0 pb-1" aria-labelledby="account-menu">
                         @if($performer->logged_in_as_pro_from_admin_pro_app_session_id)
-                            <form action="{{route('back-to-admin-pro')}}" method="post" target="_top" class="d-block pt-1">
+                            <form action="{{route('back-to-admin-pro')}}" data-action="{{route('back-to-admin-pro')}}" method="post" target="_top" class="d-block pt-1 frm-back-to-admin">
                                 @csrf
                                 <button class="d-block ml-2 back-to-admin-button">
                                     Back to Admin