Kaynağa Gözat

Push state before traversal, catch fetch errors to maintain state

Vijayakrishnan Krishnan 4 yıl önce
ebeveyn
işleme
09d2d35ceb

+ 6 - 2
app/Http/Controllers/HomeController.php

@@ -67,7 +67,7 @@ class HomeController extends Controller
             $reimbursement["lastPaymentDate"] = '--';
         }
 
-         //if today is < 15th, next payment is 15th, else nextPayment is 
+         //if today is < 15th, next payment is 15th, else nextPayment is
          $today = strtotime(date('Y-m-d'));
          $todayDate = date('j', $today);
 
@@ -90,7 +90,7 @@ class HomeController extends Controller
         $expectedForRme = DB::select(DB::raw("SELECT coalesce(SUM(rme_expected_payment_amount),0) as expected_pay  FROM bill WHERE rme_pro_id = :performerProID  AND has_rme_been_paid = false AND is_cancelled = false"), ['performerProID'=>$performerProID])[0]->expected_pay;
         $expectedForRmm = DB::select(DB::raw("SELECT coalesce(SUM(rmm_expected_payment_amount),0) as expected_pay  FROM bill WHERE rmm_pro_id = :performerProID  AND has_rmm_been_paid = false AND is_cancelled = false"), ['performerProID'=>$performerProID])[0]->expected_pay;
         $expectedForNa = DB::select(DB::raw("SELECT coalesce(SUM(na_expected_payment_amount),0) as expected_pay  FROM bill WHERE na_pro_id = :performerProID  AND has_na_been_paid = false AND is_cancelled = false"), ['performerProID'=>$performerProID])[0]->expected_pay;
-       
+
         $totalExpectedAmount =  $expectedForHcp + $expectedForCm + $expectedForRme + $expectedForRmm + $expectedForNa;
         $reimbursement['nextPaymentAmount'] = $totalExpectedAmount;
 
@@ -139,4 +139,8 @@ class HomeController extends Controller
         }
         return view('app/mc', compact('page'));
     }
+
+    public function blank(Request $request) {
+        return view('app/blank');
+    }
 }

+ 1 - 1
public/css/style.css

@@ -188,7 +188,7 @@ body>nav.navbar {
 .cancelled-item {
     opacity: 0.5;
 }
-.cancelled-item * {
+.cancelled-item:not(.always-clickable) * {
     pointer-events: none;
 }
 .note-content:not([auto-edit]) {

+ 27 - 20
public/js/mc.js

@@ -75,6 +75,7 @@ window.top.addEventListener('popstate', function (event) {
     }, 0);
 });
 $(document).ready(function () {
+
     if(window.location.href === window.top.location.href) {
         window.location.href = '/mc' + window.location.pathname;
         return;
@@ -105,12 +106,14 @@ $(document).ready(function () {
         initIntakeEvents();
     }
 
-    // replace history on fresh load
+    // populate history on fresh load
     var target = window.top.location.pathname;
     if (target.indexOf('/mc') === 0) {
         target = target.split('/mc')[1];
     }
-    window.top.history.pushState(target, null, '/mc' + target);
+    // window.top.history.pushState(target, null, '/mc' + target);
+    fastLoad(target, true, false);
+
 });
 function enableTimeSpecificFields(_checked, _valueClass, _rangeClass) {
     if(_valueClass) $('.' + _valueClass).prop('disabled', _checked);
@@ -175,7 +178,6 @@ function initFastLoad(_parent = false) {
         $(_a)
             .off('click.fast-load')
             .on('click.fast-load', function () {
-                showMask();
                 fastLoad(this.href, true, true);
                 $('.dropdown-menu[aria-labelledby="practice-management"]')
                     .removeClass('show')
@@ -216,32 +218,37 @@ function onFastLoaded(_data, _href, _history) {
         if(typeof initIntakeEvents !== 'undefined') {
             initIntakeEvents();
         }
-
-        // push state
-        if (_history) {
-            var target = _href;
-            if (target.indexOf('//') !== -1) {
-                target = target.split('//')[1];
-                if (target.indexOf('/') !== -1) {
-                    target = target.substr(target.indexOf('/') + 1);
-                }
-            }
-            if(target[0] === '/') target = target.substr(1);
-            window.top.history.pushState(target, null, '/mc/' + target);
-        }
-
     } else {
-        console.warn('Target page not found: ' + _href);
-        window.location.href = _href; // fallback
+        // fallback
+        console.warn('MC: Target page failed: ' + _href);
+        targetParent.html('<p class="text-danger p-3 small">Target page not found or returned error: <b>' + _href + '</b></p>');
     }
-    // hideMask();
+    hideMask();
 }
 function fastLoad(_href, _history = true, _useCache = true) {
+
+    showMask();
+
+    // push state
+    if (_history) {
+        var target = _href;
+        if (target.indexOf('//') !== -1) {
+            target = target.split('//')[1];
+            if (target.indexOf('/') !== -1) {
+                target = target.substr(target.indexOf('/') + 1);
+            }
+        }
+        if(target[0] === '/') target = target.substr(1);
+        window.top.history.pushState(target, null, '/mc/' + target);
+    }
+
     if (_useCache && !!fastCache[_href]) {
         onFastLoaded(fastCache[_href], _href, _history);
     } else {
         $.get(_href, function(_data) {
             onFastLoaded(_data, _href, _history);
+        }).fail(function() {
+            onFastLoaded('error', _href, _history);
         });
     }
 }

+ 10 - 3
public/js/yemi.js

@@ -120,12 +120,19 @@ var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/RED
 var pageReload = function () {
     setTimeout(function () {
         hideMoeFormMask();
-        var targetLocation = window.top.location.href.split('/mc')[1];
-        if(targetLocation[0] !== '/') targetLocation = '/' + targetLocation;
-        fastLoad(targetLocation, false, false);
+        fastReload();
     }, 500);
 };
 
+var fastReload = function() {
+    var targetLocation = window.top.location.pathname;
+    if(targetLocation.indexOf('/mc/') === 0) {
+        targetLocation = targetLocation.substr(3);
+    }
+    if(targetLocation[0] !== '/') targetLocation = '/' + targetLocation;
+    fastLoad(targetLocation, false, false);
+}
+
 if (typeof String.prototype.startsWith != 'function') {
     // see below for better implementation!
     String.prototype.startsWith = function (str) {

+ 7 - 0
resources/views/app/blank.blade.php

@@ -0,0 +1,7 @@
+@extends ('layouts.template')
+
+@section('content')
+    <div class="mcp-theme-1">
+        <p class="p-3 text-secondary small">Please wait...</p>
+    </div>
+@endsection

+ 1 - 1
resources/views/app/mc.blade.php

@@ -15,7 +15,7 @@
 <body class="h-100">
     <div class="row mx-0 h-100">
         <div class="col-9 px-0 app-left-panel">
-            <iframe id="stag_mcp_lhs" src="{{ $page }}" frameborder="0" class="h-100 w-100"></iframe>
+            <iframe id="stag_mcp_lhs" src="/blank" frameborder="0" class="h-100 w-100"></iframe>
         </div>
         <div class="col-3 border-left app-right-panel pr-1">
             <iframe id="stag_mcp_rhs" src="/pro/meet" frameborder="0" class="h-100 w-100"></iframe>

+ 2 - 0
routes/web.php

@@ -27,6 +27,8 @@ Route::post('logout', 'LoginController@logout')->name('logout');
 
 Route::middleware('pro.auth')->group(function () {
 
+    Route::get('/blank', 'HomeController@blank')->name('blank');
+
     Route::get('/', 'HomeController@dashboard')->name('dashboard');
 
     Route::get('/new-patient', 'HomeController@newPatient')->name('new-patient');