From 465292172d5d00336739d118206fde3dbcfa3af4 Mon Sep 17 00:00:00 2001 From: Ram Vibhakar Date: Mon, 27 Jul 2015 18:42:12 +0800 Subject: [PATCH] Sort by fileName --- .../components/view/KSketch_HomeView.mxml | 19 +- .../ksketch2/canvas/controls/KFileControl.as | 487 ------------------ .../canvas/controls/KMobileControl.as | 149 ------ .../ksketch2/canvas/controls/KWebControl.as | 108 ---- 4 files changed, 9 insertions(+), 754 deletions(-) delete mode 100644 KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KFileControl.as delete mode 100644 KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KMobileControl.as delete mode 100644 KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KWebControl.as 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 3cde0c62..bd2ab177 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 @@ -224,7 +224,6 @@ loginButton.label = "Login"; refreshButton.visible = false; } - _failedLogin = false; refresh(); } @@ -297,16 +296,16 @@ public function displaySketchList(sortedArr:SortedList):void { if (sortedArr) { - //var arr:ArrayCollection = new ArrayCollection(); + var arr:ArrayCollection = new ArrayCollection(); if (sortedArr.size > 0) { for (var i:int = 0; i < sortedArr.size; i++) { - arrDG.addItem(sortedArr.itemAt(i)); + arr.addItem(sortedArr.itemAt(i)); } -// var sort:Sort = new Sort(); -// sort.fields = [new SortField("fileName",true)]; -// arr.sort = sort; -// arr.refresh(); -// arrDG = arr; + var sort:Sort = new Sort(); + sort.fields = [new SortField("fileName",true)]; + arr.sort = sort; + arr.refresh(); + arrDG = arr; listSketches_unavailable.visible = false; } } @@ -489,12 +488,12 @@ public function kSketchItemRendererFuntion(item:*):IFactory { return itemRender; } - + private function scaleView():void { if(Capabilities.screenResolutionX > 1280 && Capabilities.screenResolutionY > 1500) { - KSketchStyles.scale(2); + KSketchStyles.scale(2); } else if(Capabilities.screenResolutionX > 1280 && Capabilities.screenResolutionY < 1500) { diff --git a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KFileControl.as b/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KFileControl.as deleted file mode 100644 index 9b30fb6b..00000000 --- a/KSKInterface/src/sg/edu/smu/ksketch2/canvas/controls/KFileControl.as +++ /dev/null @@ -1,487 +0,0 @@ -package sg.edu.smu.ksketch2.canvas.controls -{ - import com.adobe.serialization.json.JSON; - - import mx.collections.ArrayCollection; - - public class KFileControl - { - public static const DELETE_CACHE:String = "deleteFromCache"; - public static const DELETE_WEB:String = "deleteFromWeb"; - - public static const ADD_SAVE_CACHE:String = "save"; - public static const ADD_SAVE_WEB:String = "saveCurrentFromWeb"; - public static const ADD_SYNC:String = "sync"; - - //main variable to store information - //[0] = user information - //[1] = list of sketches - //[3] = sketch documents - private var informationArr:Array; - private var sync_sketchArr:ArrayCollection = new ArrayCollection(); - private var sync_sketchDocArr:ArrayCollection = new ArrayCollection(); - - public function addNewSketchDocument(record:String, obj:Object, type:String):ArrayCollection - { - var arr:ArrayCollection; - if(record) - { - var tempObj:Object = com.adobe.serialization.json.JSON.decode(record, true); - var tempArr:Array = (tempObj.sketches as Array); - - if(tempArr) - arr = new ArrayCollection(tempArr); - } - - //overwrite existing document with the new objDoc - if(!arr) - arr = new ArrayCollection(); - - if(!sketchExist(arr, obj.fileName, obj.sketchId)) - arr.addItem(obj); - else - { - for(var i:int=0; i= dateCache.time ) - overwrite = true; - else if((dateCache.hours == dateWeb.hours) && ((dateCache.minutes == dateWeb.minutes) || ((dateCache.minutes - dateWeb.minutes) <= 1))) - overwrite = true; - } - - //if both are same versions and cached sketch doesn't contain any fileData, overwrite - if(obj.version == arrObj.version) - { - if(arrObj.fileData == null) - overwrite = true; - - if(obj.save == -1) - overwrite = true; - - if(obj.save == 0) - { - if(obj.revert == 0) - overwrite = true; - } - } - - //if a save has been made, overwrite - if(obj.save == 0) - overwrite = true; - } - - - if(overwrite) - { - arr.removeItemAt(i); - arr.addItem(obj); - } - } - } - } - - return arr; - } - - public function deleteSketchDocument(record:String, obj:Object, type:String):ArrayCollection - { - var tempObj:Object = com.adobe.serialization.json.JSON.decode(record, true); - var tempArr:Array = (tempObj.sketches as Array); - - var arr:ArrayCollection = new ArrayCollection(tempArr); - - for(var i:int=0; i 0) - index = sketchExistIndex(cacheArr_sketch, webObj.fileName, webObj.sketchId); - - if(index != -1) - { - var overwrite:Boolean = false; - - var cacheObj:Object = cacheArr_sketch.getItemAt(index); - - var dateCache:Date = new Date(); - dateCache.setTime(Date.parse(cacheObj.date)); - if(dateCache.hours == 24) - dateCache.hours = 0; - - var dateWeb:Date = new Date(); - dateWeb.setTime(Date.parse(webObj.date)); - if(dateWeb.hours == 24) - dateCache.hours = 0; - - if((dateCache.date < dateWeb.date) && (dateCache.month < dateWeb.month) && (dateCache.fullYear < dateWeb.fullYear)) - overwrite = true; - else if((dateCache.date == dateWeb.date) && (dateCache.month == dateWeb.month) && (dateCache.fullYear == dateWeb.fullYear)) - { - if(dateWeb.time >= dateCache.time ) - overwrite = true; - else if(cacheObj.version > webObj.version) - overwrite = true; - } - - if(overwrite) - { - if(cacheObj.fileData != null && webObj.fileData == null) - webObj.fileData = cacheObj.fileData; - - cacheArr_sketch.removeItemAt(index); - webObj.save = 0; - cacheArr_sketch.addItem(webObj); - } - } - else - { - webObj.save = 0; - cacheArr_sketch.addItem(webObj); - } - - var docObj:Object = new Object(); - if(cacheArr_sketch) - docObj.sketches = cacheArr_sketch.source; - else - docObj.sketches = null; - - newInformationArr = com.adobe.serialization.json.JSON.encode(docObj); - - if(cacheArr_sketch) - cacheArr_sketch.removeAll(); - - return newInformationArr; - } - - /*public function solveDiscrepancy(cacheStr:String, webStr:String):String - { - var newInformationArr:String; - - //get sketches from cache - var cacheArr_sketch:ArrayCollection; - cacheArr_sketch = convertStringToArrayCollection(cacheStr); - - if(!cacheArr_sketch) - cacheArr_sketch = new ArrayCollection(); - - //get sketches from the web - var webArr_sketch:ArrayCollection; - webArr_sketch = convertStringToArrayCollection(webStr); - - //compare web and mobile objects - //if mobile is out of date, then replace with web object - if(webArr_sketch) - { - for(var i:int=0; i= dateCache.time ) - overwrite = true; - else if((dateCache.hours == dateWeb.hours) && ((dateCache.minutes == dateWeb.minutes) || ((dateCache.minutes - dateWeb.minutes) <= 1))) - overwrite = true; - } - - if(overwrite) - { - if(cacheObj.fileData != null && obj.fileData == null) - obj.fileData = cacheObj.fileData; - - cacheArr_sketch.removeItemAt(index); - obj.save = 0; - cacheArr_sketch.addItem(obj); - } - } - else - { - obj.save = 0; - cacheArr_sketch.addItem(obj); - } - - } - } - - var docObj:Object = new Object(); - if(cacheArr_sketch) - docObj.sketches = cacheArr_sketch.source; - else - docObj.sketches = null; - - newInformationArr = com.adobe.serialization.json.JSON.encode(docObj); - - if(cacheArr_sketch) - cacheArr_sketch.removeAll(); - - if(webArr_sketch) - webArr_sketch.removeAll(); - - return newInformationArr; - }*/ - - public function getUserObject(userStr:String):Object - { - var obj:Object; - - if(userStr) - obj = com.adobe.serialization.json.JSON.decode(userStr, true); - - return obj; - } - - public function getSketchArr(sketchString:String):ArrayCollection - { - var sketchArr:ArrayCollection; - - if(sketchString) - { - var sketchObj:Object = com.adobe.serialization.json.JSON.decode(sketchString, true); - var tempArr:Array = (sketchObj.sketches as Array); - - if(tempArr) - { - tempArr.sortOn("lowerFileName"); - sketchArr = new ArrayCollection(tempArr); - } - } - - return sketchArr; - } - - public function getSyncSketchObjects(cacheStr:String):Object - { - var result:Object = new Object(); - var syncArr:ArrayCollection = new ArrayCollection(); - var delArr:ArrayCollection = new ArrayCollection(); - - //get sketches from cache - var cacheArr_sketch:ArrayCollection; - cacheArr_sketch = convertStringToArrayCollection(cacheStr); - - //if there are new objects in cache that don't exist in the web, add them to sync_sketchArr - if(cacheArr_sketch) - { - var selectedDoc:Object; - for each(var obj:Object in cacheArr_sketch) - { - if(obj.deleteFlag == 1) - { - if(!delArr.contains(obj)) - delArr.addItem(obj); - } - - if(obj.save == -1) - { - if(!syncArr.contains(obj)) - syncArr.addItem(obj); - } - } - } - - result.syncArr = syncArr; - result.delArr = delArr; - syncArr = null; - delArr = null; - cacheArr_sketch = null; - - return result; - } - - public function convertArrayToArrayCollection(arr:Array):ArrayCollection - { - var arrColl:ArrayCollection = new ArrayCollection(); - - for(var i:int=0; i= 0) - informationArr[0] = com.adobe.serialization.json.JSON.encode(userObj); - else - informationArr[0] = null; - } - - public function addSketchToList(sketchObj:Object, type:String):void - { - var sketchArr:ArrayCollection; - sketchArr = _fileControl.addNewSketchDocument(informationArr[1], sketchObj, type); - - sketchObj = new Object(); - if(sketchArr) - sketchObj.sketches = sketchArr.source; - else - sketchObj.sketches = null; - - informationArr[1] = com.adobe.serialization.json.JSON.encode(sketchObj); //stringify the JSON objects to store in informationArr[2] - sketchArr.removeAll(); //empty array used - } - - public function deleteSketchFromList(sketchObj:Object, type:String):void - { - var sketchArr:ArrayCollection = _fileControl.deleteSketchDocument(informationArr[1], sketchObj, type); - - sketchObj = new Object(); - if(sketchArr) - sketchObj.sketches = sketchArr.source; - else - sketchObj.sketches = null; - - informationArr[1] = com.adobe.serialization.json.JSON.encode(sketchObj); //stringify the JSON objects to store in informationArr[2] - - writeToCache(informationArr); - - sketchArr = null; - sketchObj = null; - } - - public function get sketchList():ArrayCollection - { - var arr:ArrayCollection; - arr = _fileControl.getSketchArr(informationArr[1]); - return arr; - } - - public function get user():Object - { - var obj:Object; - obj = _fileControl.getUserObject(informationArr[0]); - return obj; - } - - public function set user(userObj:Object):void - { - informationArr[0] = com.adobe.serialization.json.JSON.encode(userObj); - } - - public function get userSketch():Object - { - var obj:Object; - obj = _fileControl.getUserObject(informationArr[1]); - return obj; - } - - public function discardSavedSketches():void - { - //get sketches from cache - var cacheArr_sketch:ArrayCollection; - cacheArr_sketch = _fileControl.convertStringToArrayCollection(informationArr[1]); - - var newArr:ArrayCollection = new ArrayCollection(); - - for(var i:int=0; i= 0) - informationArr[0] = com.adobe.serialization.json.JSON.encode(userObj); - else - informationArr[0] = null; - } - - public function initSketchList(sketchObj:Object):void - { - //add in list of sketches to informationArr[1] - var newArr:ArrayCollection = new ArrayCollection(); - var tempArr:Array = (sketchObj.entities as Array); - if(tempArr.length > 0) - { - var newTempArr:ArrayCollection = new ArrayCollection(tempArr); - for each(var tempObj:Object in newTempArr) - { - tempObj = KWebData.convertWebObjForMobile(tempObj); - newArr.addItem(tempObj); - } - } - - sketchObj = new Object(); - if(tempArr.length > 0) - sketchObj.sketches = newArr.source; - else - sketchObj.sketches = null; - - //stringify the JSON objects to store in informationArr[1] - informationArr[1] = com.adobe.serialization.json.JSON.encode(sketchObj); - } - - public function addSketchToList(docObj:Object, type:String):void - { - var fileControl:KFileControl = new KFileControl(); - var sketchDocsArr:ArrayCollection; - sketchDocsArr = fileControl.addNewSketchDocument(informationArr[1], docObj, type); - - docObj = new Object(); - if(sketchDocsArr) - docObj.sketches = sketchDocsArr.source; - else - docObj.sketches = null; - - informationArr[1] = com.adobe.serialization.json.JSON.encode(docObj); //stringify the JSON objects to store in informationArr[2] - sketchDocsArr.removeAll(); //empty array used - } - - public function get sketchList():ArrayCollection - { - var arr:ArrayCollection; - arr = _fileControl.getSketchArr(informationArr[1]); - return arr; - } - - public function reset():void - { - informationArr[0] = null; - informationArr[1] = null; - } - } -} \ No newline at end of file