From 00ab55037a652f11dc4faa2125a34ea4a2395384 Mon Sep 17 00:00:00 2001 From: Jesse Parnell Date: Mon, 13 Jun 2022 18:19:01 -0700 Subject: [PATCH 1/2] Now alerts when token expired --- app/common/tmDetailFactory.js | 27 ++++++++++++++++++++++----- app/common/tmListFactory.js | 8 +++++++- app/common/widgets/lookups.js | 2 ++ dataNinja/cachedResource.js | 9 ++++++++- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/common/tmDetailFactory.js b/app/common/tmDetailFactory.js index 35b477c1..69ea9612 100644 --- a/app/common/tmDetailFactory.js +++ b/app/common/tmDetailFactory.js @@ -182,21 +182,38 @@ function BaseDetail( return deferred.promise; }; + this.stateCache = ""; + // $state.stateCache = ""; this.close = function () { - var self = this; + // var self = this; this.canILeave().then(function (canILeave) { + if (canILeave) { let backState = self.$state.back.fromState.name; self.docSvc.clearDocument(); + + let goListView = () => { + // we are going back to the list so clear out the $state.data for next circular issue + $state.data = null; + self.$state.go(self.constructorArgs.listView); + } + + let goBack = () => { + $state.stateCache = self.$state.current.name; + self.$state.go(backState, $state.back.fromParams); + } + // !($state.data === backState) handle circlular issue with back button // the back state and the to state are the same if (backState && backState != "" && !($state.data === backState)) { - self.$state.go(backState, $state.back.fromParams); + if(backState == $state.stateCache) { + goListView(); + } else { + goBack(); + } } else { - // we are going back to the list so clear out the $state.data for next circular issue - $state.data = null; - self.$state.go(self.constructorArgs.listView); + goListView(); } } }); diff --git a/app/common/tmListFactory.js b/app/common/tmListFactory.js index 1632c1a3..0ecb18c5 100644 --- a/app/common/tmListFactory.js +++ b/app/common/tmListFactory.js @@ -54,11 +54,17 @@ function BaseList( var self = this; let dfd = new Promise((resolve, reject) => { self.setLoading(true); - self.Model.query(queryString, flush).then(function (items) { + self.Model.query(queryString, flush).then((items) => { + console.log("items", items); self.setLoading(false); self.items = items; self.afterLoad(); resolve(items); + }, (e) => { + console.log("err: ", e); + if(!e.data.success) { + self.tmNotifier.error("Your session has expired. Please log in again."); + } }); }); return dfd; //returns a promise, so we can work with the data. diff --git a/app/common/widgets/lookups.js b/app/common/widgets/lookups.js index 24cd2c0d..12f0d0c7 100644 --- a/app/common/widgets/lookups.js +++ b/app/common/widgets/lookups.js @@ -53,6 +53,8 @@ var Controller = ['$dataSource', '$attrs', '$injector', '$scope', '$timeout', fu self.updateList(); }, 0); } + }, (msg) => { + console.log("err: ", msg); }); diff --git a/dataNinja/cachedResource.js b/dataNinja/cachedResource.js index 823b9cdf..8d299719 100644 --- a/dataNinja/cachedResource.js +++ b/dataNinja/cachedResource.js @@ -26,6 +26,7 @@ export default class CachedResource { } query(queryString, flush) { + // console.log("cachedResource query called") var deferred = this.$q.defer(); queryString = queryString || {}; var self = this; @@ -33,12 +34,17 @@ export default class CachedResource { self.List = null; } if (!self.List) { - self.Resource.query(queryString, function (data) { + + self.Resource.query(queryString, (data) => { var json = JSON.stringify(data.data); var jsonParsed = JSON.parse(json, jsonReviver); self.List = jsonParsed; deferred.resolve(self.List); + }, (err) => { + console.log("err: ", err); + deferred.reject(err); }); + } else { deferred.resolve(self.List); @@ -99,6 +105,7 @@ export default class CachedResource { if (response.noData) { deferred.reject(response.noData); } + console.log("cachedResource: ", response.data); var json = JSON.stringify(response.data); var parsedJson = JSON.parse(json, jsonReviver); var itemIndex = self.List.map(function (i) { From c8e7c88c88d8ed87a3a15ef79a74fcce14c7a7eb Mon Sep 17 00:00:00 2001 From: trillobite Date: Wed, 15 Jun 2022 23:10:05 -0700 Subject: [PATCH 2/2] didnt throw error now fixed --- app/common/tmListFactory.js | 10 +++++++--- app/common/widgets/lookups.js | 2 ++ dataNinja/cachedResource.js | 27 +++++++++++++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/common/tmListFactory.js b/app/common/tmListFactory.js index 0ecb18c5..b6175354 100644 --- a/app/common/tmListFactory.js +++ b/app/common/tmListFactory.js @@ -55,15 +55,19 @@ function BaseList( let dfd = new Promise((resolve, reject) => { self.setLoading(true); self.Model.query(queryString, flush).then((items) => { - console.log("items", items); + // console.log("items", items); self.setLoading(false); self.items = items; self.afterLoad(); resolve(items); }, (e) => { console.log("err: ", e); - if(!e.data.success) { - self.tmNotifier.error("Your session has expired. Please log in again."); + if(!e.success) { + if(e.hasOwnProperty("message")) { + self.tmNotifier.error(e.message); + } else { + self.tmNotifier.error("Failed to get data"); + } } }); }); diff --git a/app/common/widgets/lookups.js b/app/common/widgets/lookups.js index 12f0d0c7..cbdf4201 100644 --- a/app/common/widgets/lookups.js +++ b/app/common/widgets/lookups.js @@ -54,7 +54,9 @@ var Controller = ['$dataSource', '$attrs', '$injector', '$scope', '$timeout', fu }, 0); } }, (msg) => { + //i don't think this ever catches an error... console.log("err: ", msg); + // throw(msg); }); diff --git a/dataNinja/cachedResource.js b/dataNinja/cachedResource.js index 8d299719..05f14249 100644 --- a/dataNinja/cachedResource.js +++ b/dataNinja/cachedResource.js @@ -36,13 +36,24 @@ export default class CachedResource { if (!self.List) { self.Resource.query(queryString, (data) => { - var json = JSON.stringify(data.data); - var jsonParsed = JSON.parse(json, jsonReviver); - self.List = jsonParsed; - deferred.resolve(self.List); - }, (err) => { - console.log("err: ", err); - deferred.reject(err); + + let run = () => { + var json = JSON.stringify(data.data); + var jsonParsed = JSON.parse(json, jsonReviver); + self.List = jsonParsed; + deferred.resolve(self.List); + } + + // console.log("data: ", data); + if(data.hasOwnProperty("success")) { + if(!data.success) { + deferred.reject(data); + } else { + run(); + } + } else { + run(); + } }); } @@ -105,7 +116,7 @@ export default class CachedResource { if (response.noData) { deferred.reject(response.noData); } - console.log("cachedResource: ", response.data); + // console.log("cachedResource: ", response.data); var json = JSON.stringify(response.data); var parsedJson = JSON.parse(json, jsonReviver); var itemIndex = self.List.map(function (i) {