Browse Source

server update detection

tags/v0.1.0
Robin Thoni 8 years ago
parent
commit
e0af828a9c
2 changed files with 42 additions and 2 deletions
  1. 36
    1
      app/app.js
  2. 6
    1
      app/translations/en.json

+ 36
- 1
app/app.js View File

@@ -150,7 +150,41 @@ angular.module('app', [
150 150
 
151 151
             $urlRouterProvider.otherwise('/');
152 152
     }])
153
-    .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate) {
153
+    .run(['$rootScope', '$transitions', 'AppUtilsBusiness', 'ssSideNav', '$translate', 'luRequest', '$mdDialog',
154
+        function ($rootScope, $transitions, AppUtilsBusiness, ssSideNav, $translate, luRequest, $mdDialog) {
155
+
156
+        var apiVersion = null;
157
+
158
+        function apiVersionChanged(oldVersion, newVersion) {
159
+            $mdDialog.show(
160
+                $mdDialog.alert()
161
+                    .title(AppUtilsBusiness.tr('common.updateDetected.title'))
162
+                    .textContent(AppUtilsBusiness.tr('common.updateDetected.text', {oldVersion: oldVersion, newVersion: newVersion}))
163
+                    .ok(AppUtilsBusiness.tr('common.ok')));
164
+        }
165
+
166
+        luRequest.addHook('resolve', function(url, method, dataGet, dataPost, luBusyGroups, data)
167
+        {
168
+            if (apiVersion == null) {
169
+                apiVersion = data.version;
170
+            }
171
+            else if (data.version != null && data.version != apiVersion) {
172
+                apiVersionChanged(apiVersion, data.version);
173
+                apiVersion = data.version;
174
+            }
175
+        });
176
+
177
+        luRequest.addHook('reject', function(url, method, dataGet, dataPost, luBusyGroups, error)
178
+        {
179
+            if (apiVersion == null) {
180
+                apiVersion = error.data.version;
181
+            }
182
+            else if (error.data.version != null && error.data.version != apiVersion) {
183
+                apiVersionChanged(apiVersion, error.data.version);
184
+                apiVersion = error.data.version;
185
+            }
186
+        });
187
+
154 188
         $translate('common.appName').then(function() {
155 189
             for (var i = 0; i < ssSideNav.sections.length; ++i) {
156 190
                 var a = ssSideNav.sections[i];
@@ -171,6 +205,7 @@ angular.module('app', [
171 205
         }, function (error) {
172 206
             console.error(error);
173 207
         });
208
+
174 209
         $transitions.onEnter({}, function($transitions)
175 210
         {
176 211
             var toState = $transitions.$to();

+ 6
- 1
app/translations/en.json View File

@@ -13,6 +13,7 @@
13 13
     "submit": "Submit",
14 14
     "menu": "Menu",
15 15
     "cancel": "Cancel",
16
+    "ok": "OK",
16 17
     "confirmDelete": "Confirm deletion",
17 18
     "pagination": {
18 19
       "of": "of",
@@ -20,7 +21,11 @@
20 21
       "rowsPerPage": "Items per page:"
21 22
     },
22 23
     "createdBy": "Created with ❤ by",
23
-    "busyLoading": "Loading..."
24
+    "busyLoading": "Loading...",
25
+    "updateDetected": {
26
+      "title": "Update detected",
27
+      "text": "The server has been updated from version {oldVersion} to {newVersion}.\nPlease perform a full refresh by pressing Ctrl+F5 to load the new version.\nNot doing it may leads to undefined behaviors."
28
+    }
24 29
   },
25 30
   "home": {
26 31
     "name": "Home",

Loading…
Cancel
Save