From 95445b3eaf98f75b1afe74602b5f5d5b2ec6bfbc Mon Sep 17 00:00:00 2001 From: Ram Vibhakar Date: Mon, 27 Jul 2015 15:30:57 +0800 Subject: [PATCH] - Do not pull list of sketches from web after a sketch is deleted - Handle expired session tokens --- .../components/view/KSketch_HomeView.mxml | 19 +++++-- .../canvas/controls/KSketch_CacheControl.as | 55 +++++++++++-------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/components/view/KSketch_HomeView.mxml b/KSKInterface/src/sg/edu/smu/ksketch2/canvas/components/view/KSketch_HomeView.mxml index dbf43008..3cde0c62 100644 --- a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/components/view/KSketch_HomeView.mxml +++ b/KSKInterface/src/sg/edu/smu/ksketch2/canvas/components/view/KSketch_HomeView.mxml @@ -285,14 +285,14 @@ } - private function _setupSketchListView():void { + private function _setupSketchListView(fromWeb:Boolean = true):void { _startProgressBar(); listSketches_unavailable.visible = true; arrDG.removeAll(); - _cacheControl.retrieveWebSketchList(); + _cacheControl.retrieveWebSketchList(fromWeb); } public function displaySketchList(sortedArr:SortedList):void { @@ -353,8 +353,8 @@ } - public function refresh():void { - _setupSketchListView(); + public function refresh(fromWeb:Boolean = true):void { + _setupSketchListView(fromWeb); } public function logout():void { @@ -372,7 +372,10 @@ } public function navigateToScreen(screenName:String):void { - if (screenName.indexOf("CANVAS") == -1) //if screen name is Login + if (screenName.indexOf("RELOGIN") != -1) { + navigator.pushView(KSketch_LoginView); + } + else if (screenName.indexOf("CANVAS") == -1) //if screen name is Login { KSketch_LoginView.userData = new Object(); @@ -498,6 +501,12 @@ KSketchStyles.scale(2); } } + + public function handleExpiredSession(){ + _canvasNotice._parent = KSketch_CanvasNotice.CANVASNOTICE_EXPIRED_SESSION; + _canvasNotice.open(this, true); + PopUpManager.centerPopUp(_canvasNotice); + } ]]> diff --git a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KSketch_CacheControl.as b/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KSketch_CacheControl.as index 2fc0e4f8..2b8546f7 100644 --- a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KSketch_CacheControl.as +++ b/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KSketch_CacheControl.as @@ -157,11 +157,11 @@ import flash.net.SharedObject; _mySO.data.cachedDocuments = com.adobe.serialization.json.JSON.encode(list); } - public function retrieveAllSketchList():SortedList + public function retrieveAllSketchList(fromWeb:Boolean=true):SortedList { _isData = false; var result:Object; - result = syncList(cachedList,_webList); + result = syncList(cachedList,_webList,fromWeb); cachedList = result.syncedList; //TODO: Handle toBeSavedList here //result.toBeSavedList @@ -170,7 +170,7 @@ import flash.net.SharedObject; } // Probably the most efficient way of syncing the sketch list in the cache and // sketch list from the web - private function syncList(cacheList:SortedList,webList:SortedList): Object { + private function syncList(cacheList:SortedList,webList:SortedList,fromWeb:Boolean=true): Object { var comparator:IComparator = new KSketch_ListItem(); var allList:SortedList = new SortedList(comparator); var updateList:SortedList = new SortedList(comparator); @@ -194,7 +194,9 @@ import flash.net.SharedObject; x += 1; } else if (comparator.compare(cacheList.itemAt(x),webList.itemAt(y)) == 1) { if(isDeletedSketch(webList.itemAt(y).sketchId)) { - deleteSketchOnWeb(isDeletedSketch(webList.itemAt(y).sketchId)); + if(fromWeb) { + deleteSketchOnWeb(isDeletedSketch(webList.itemAt(y).sketchId)); + } }else { allList.add(webList.itemAt(y)); } @@ -210,19 +212,23 @@ import flash.net.SharedObject; return ret; } - public function retrieveWebSketchList():void + public function retrieveWebSketchList(fromWeb:Boolean = true):void { if(user.id != "n.a" && (user.status.indexOf("success") >= 0)) { - //make web request to pull list of sketches - var parameter:String = "{\"sketchID\":[],\"userid\":" + user.id + ",\"token\":\""+user.token +"\"}"; - - _httpService.removeEventListener(ResultEvent.RESULT, dataResultHandler); - _httpService.addEventListener(FaultEvent.FAULT, faultHandler); - _httpService.addEventListener(ResultEvent.RESULT, listResultHandler); - - _httpService.url = KSketchWebLinks.jsonurlSketch + "/" + parameter; - _httpService.send(); + if(fromWeb) { + //make web request to pull list of sketches + var parameter:String = "{\"sketchID\":[],\"userid\":" + user.id + ",\"token\":\"" + user.token + "\"}"; + + _httpService.removeEventListener(ResultEvent.RESULT, dataResultHandler); + _httpService.addEventListener(FaultEvent.FAULT, faultHandler); + _httpService.addEventListener(ResultEvent.RESULT, listResultHandler); + + _httpService.url = KSketchWebLinks.jsonurlSketch + "/" + parameter; + _httpService.send(); + } else { + _homeView.displaySketchList(retrieveAllSketchList(fromWeb)); + } } else { @@ -273,18 +279,23 @@ import flash.net.SharedObject; private function listResultHandler(event:ResultEvent):void { - //TODO: RAM check for negative cases var rawData:String = String(event.result); var resultObj:Object = com.adobe.serialization.json.JSON.decode(rawData,true); _webList.clear(); var tempArr:Array = (resultObj.entities as Array); - for each(var tempObj:Object in tempArr) - { - var _ksketchListItem:KSketch_ListItem = new KSketch_ListItem(); - _ksketchListItem.fromWebData(tempObj); - _webList.add(_ksketchListItem); + if(resultObj) { + if (resultObj.hasOwnProperty("status")) { + if (resultObj.status == "session_expired") { + _homeView.handleExpiredSession(); + } + }else { + for each(var tempObj:Object in tempArr) { + var _ksketchListItem:KSketch_ListItem = new KSketch_ListItem(); + _ksketchListItem.fromWebData(tempObj); + _webList.add(_ksketchListItem); + } + } } - _homeView.displaySketchList(retrieveAllSketchList()); } @@ -446,7 +457,7 @@ import flash.net.SharedObject; deleteSketchOnWeb(Number(sketchID)); this.deleteFromCache(sketchID,fileName); } - _homeView.refresh(); + _homeView.refresh(false); } } } \ No newline at end of file