Commit 5e31b047fadf58cd61c354c906fbc258917fbdde

Authored by isisadmin
1 parent e5b73e81

datalet chaching mechanism

controllets/data-sevc-controllet/data-sevc-controllet.html
@@ -936,7 +936,8 @@ Example: @@ -936,7 +936,8 @@ Example:
936 dataUrl : this.dataUrl, 936 dataUrl : this.dataUrl,
937 params : this.params_fields, 937 params : this.params_fields,
938 fields : this.selected_fields, 938 fields : this.selected_fields,
939 - datalet : this.selected_datalet 939 + datalet : this.selected_datalet,
  940 + staticData : JSON.stringify(this.$.datalet_placeholder.children[1].behavior.data)
940 } 941 }
941 942
942 this.fire('data-sevc-controllet.dataletCreated', {data : data}); 943 this.fire('data-sevc-controllet.dataletCreated', {data : data});
datalets/barchart-datalet/barchart-datalet.html
@@ -188,7 +188,7 @@ Example: @@ -188,7 +188,7 @@ Example:
188 ready: function(){ 188 ready: function(){
189 189
190 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, BarchartBehavior); 190 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, BarchartBehavior);
191 - this.behavior.init(this); 191 + this.async(function(){this.behavior.init(this)},1);
192 } 192 }
193 }); 193 });
194 </script> 194 </script>
datalets/base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html
@@ -52,7 +52,7 @@ Example : @@ -52,7 +52,7 @@ Example :
52 52
53 <dom-module id="base-ajax-json-jsonpath-datalet"> 53 <dom-module id="base-ajax-json-jsonpath-datalet">
54 <template> 54 <template>
55 - <base-datalet data-url="{{dataUrl}}" fields="{{fields}}"></base-datalet> 55 + <base-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}"></base-datalet>
56 </template> 56 </template>
57 57
58 <script src="static/js/vendor/jsonpath-0.8.5.js"></script> 58 <script src="static/js/vendor/jsonpath-0.8.5.js"></script>
datalets/base-datalet/static/js/BaseDataletBehaviors.js 0 → 100644
  1 +/*
  2 +@license
  3 + The MIT License (MIT)
  4 +
  5 + Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy
  6 +
  7 + Permission is hereby granted, free of charge, to any person obtaining a copy
  8 + of this software and associated documentation files (the "Software"), to deal
  9 + in the Software without restriction, including without limitation the rights
  10 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 + copies of the Software, and to permit persons to whom the Software is
  12 + furnished to do so, subject to the following conditions:
  13 +
  14 + The above copyright notice and this permission notice shall be included in
  15 + all copies or substantial portions of the Software.
  16 +
  17 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23 + THE SOFTWARE.
  24 +*/
  25 +
  26 +var BaseDataletBehavior ={
  27 +
  28 + properties: {
  29 +
  30 + /**
  31 + * It represent the dataset api url
  32 + *
  33 + * @attribute dataUrl
  34 + * @type string
  35 + * @default 'null'
  36 + */
  37 + dataUrl: {
  38 + type: String,
  39 + value: ""
  40 + },
  41 +
  42 + /**
  43 + * It represents one or multiple fields selected by user
  44 + *
  45 + * @attribute fields
  46 + * @type Array
  47 + * @default empty
  48 + */
  49 + fields: {
  50 + type: String,
  51 + value: ""
  52 + },
  53 +
  54 + /**
  55 + * The selected and transformed data you can use in presentation phase
  56 + *
  57 + * @attribute data
  58 + * @type Array
  59 + * @default empty
  60 + */
  61 + data: {
  62 + type: Array,
  63 + value: []
  64 + }
  65 +
  66 + },
  67 +
  68 + factoryImpl: function(data_url, fields) {
  69 + this.data_url = data_url;
  70 + this.fields = fields;
  71 + }
  72 +
  73 +};
  74 +
  75 +var WorkcycleBehavior = {
  76 + /**
  77 + * A reference to Polymer object
  78 + *
  79 + */
  80 + _component: null,
  81 +
  82 + /**
  83 + * Request data from source(e.g. CKAN by api) using some kind of technology(e.g. Ajax)
  84 + *
  85 + * @method requestData
  86 + */
  87 + requestData: function(){
  88 + },
  89 +
  90 + /**
  91 + * Select the fields from data(typically json) previously retrieved by ajax request. The selection could be done by jsonPath but
  92 + * it depends on the representation data format(CKAN apies return a json representation of the dataset).
  93 + *
  94 + * @method selectData
  95 + */
  96 + selectData: function(){
  97 + },
  98 +
  99 + /**
  100 + * Filter data previously selected. An example of filterting could be an expression such "fields > 30" or "fields = 'AAA'"
  101 + * If you are using jsonPath to select the datas you can apply an expression directly in the jsonPath query string.
  102 + *
  103 + * @method filterData
  104 + */
  105 + filterData: function(){
  106 + },
  107 +
  108 + /**
  109 + * Transform the selected data in order to build the structure that the presentation phase needs.
  110 + *
  111 + * @method transformData
  112 + */
  113 + transformData: function(){
  114 + },
  115 +
  116 + /**
  117 + * Build the object/s for presentation layer.
  118 + *
  119 + * @method presentData
  120 + */
  121 + presentData: function(){
  122 +
  123 + },
  124 +
  125 + /**
  126 + * This method represents the entire datalet workcycle.
  127 + *
  128 + * @method runWorkcycle
  129 + */
  130 + runWorkcycle: function() {
  131 + this.selectData();
  132 + this.filterData();
  133 + this.transformData();
  134 + this.presentData();
  135 + },
  136 +
  137 + /**
  138 + * This method save the reference to the polymer object related to the datalet.
  139 + *
  140 + * @method init
  141 + */
  142 + init: function(component){
  143 + this._component = component;
  144 +
  145 + if(this.properties.data.length == 0){
  146 + this.requestData();
  147 + }else{
  148 + this.transformData();
  149 + this.presentData();
  150 + }
  151 + }
  152 +
  153 +};
0 \ No newline at end of file 154 \ No newline at end of file
datalets/base-datalet/static/js/WorkcycleBehavior.js
@@ -97,7 +97,14 @@ var WorkcycleBehavior = { @@ -97,7 +97,14 @@ var WorkcycleBehavior = {
97 */ 97 */
98 init: function(component){ 98 init: function(component){
99 this._component = component; 99 this._component = component;
100 - this.requestData(); 100 +
  101 + if(this._component.data === undefined || this._component.data == ""){
  102 + this.requestData();
  103 + }else{
  104 + this.data = JSON.parse(this._component.data);
  105 + this.transformData();
  106 + this.presentData();
  107 + }
101 } 108 }
102 109
103 }; 110 };
104 \ No newline at end of file 111 \ No newline at end of file
datalets/column3Dchart-datalet/column3Dchart-datalet.html
@@ -187,7 +187,7 @@ Example: @@ -187,7 +187,7 @@ Example:
187 */ 187 */
188 ready: function(){ 188 ready: function(){
189 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, column3DchartBehavior); 189 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, column3DchartBehavior);
190 - this.behavior.init(this); 190 + this.async(function(){this.behavior.init(this)},1);
191 } 191 }
192 }); 192 });
193 </script> 193 </script>
datalets/columnchart-datalet/columnchart-datalet.html
@@ -186,7 +186,7 @@ Example: @@ -186,7 +186,7 @@ Example:
186 */ 186 */
187 ready: function(){ 187 ready: function(){
188 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, ColumnchartBehavior); 188 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, ColumnchartBehavior);
189 - this.behavior.init(this); 189 + this.async(function(){this.behavior.init(this)},1);
190 } 190 }
191 }); 191 });
192 </script> 192 </script>
datalets/datatable-datalet/datatable-datalet.html
@@ -113,7 +113,7 @@ Example: @@ -113,7 +113,7 @@ Example:
113 113
114 ready: function(){ 114 ready: function(){
115 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, DatatableBehavior); 115 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, DatatableBehavior);
116 - this.behavior.init(this); 116 + this.async(function(){this.behavior.init(this)},1);
117 } 117 }
118 }); 118 });
119 119
datalets/donutpie3dchart-datalet/donutpie3dchart-datalet.html
@@ -139,7 +139,7 @@ Example: @@ -139,7 +139,7 @@ Example:
139 */ 139 */
140 ready: function(){ 140 ready: function(){
141 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, DonutPiechartBehavior); 141 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, DonutPiechartBehavior);
142 - this.behavior.init(this); 142 + this.async(function(){this.behavior.init(this)},1);
143 } 143 }
144 }); 144 });
145 </script> 145 </script>
datalets/highcharts-datalet/highcharts-datalet.html
@@ -57,7 +57,7 @@ Example : @@ -57,7 +57,7 @@ Example :
57 57
58 <template> 58 <template>
59 <div id="container" style="width:auto; height:auto;"></div> 59 <div id="container" style="width:auto; height:auto;"></div>
60 - <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}"></base-ajax-json-jsonpath-datalet> 60 + <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}"></base-ajax-json-jsonpath-datalet>
61 </template> 61 </template>
62 62
63 <script src="static/js/highcharts.js"></script> 63 <script src="static/js/highcharts.js"></script>
datalets/leafletjs-datalet/leafletjs-datalet.html
@@ -160,7 +160,7 @@ Example: @@ -160,7 +160,7 @@ Example:
160 L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images'; 160 L.Icon.Default.imagePath = 'http://services.routetopa.eu/DEEalerProvider/COMPONENTS/datalets/leafletjs-datalet/leafletsjs/images';
161 161
162 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, leafletjsBehavior); 162 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, leafletjsBehavior);
163 - this.behavior.init(this); 163 + this.async(function(){this.behavior.init(this)},1);
164 } 164 }
165 }); 165 });
166 </script> 166 </script>
datalets/linechart-datalet/linechart-datalet.html
@@ -50,7 +50,7 @@ Example: @@ -50,7 +50,7 @@ Example:
50 50
51 <dom-module id="linechart-datalet"> 51 <dom-module id="linechart-datalet">
52 <template> 52 <template>
53 - <highcharts-datalet id="charts" data-url="{{dataUrl}}" fields="{{fields}}"></highcharts-datalet> 53 + <highcharts-datalet id="charts" data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}"></highcharts-datalet>
54 </template> 54 </template>
55 <script> 55 <script>
56 56
@@ -178,7 +178,7 @@ Example: @@ -178,7 +178,7 @@ Example:
178 */ 178 */
179 ready: function(){ 179 ready: function(){
180 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, LinechartBehavior); 180 this.behavior = $.extend(true, {}, HighchartsComponentBehavior, LinechartBehavior);
181 - this.behavior.init(this); 181 + this.async(function(){this.behavior.init(this)},1);
182 } 182 }
183 }); 183 });
184 </script> 184 </script>
datalets/treemap-datalet/treemap-datalet.html
@@ -213,7 +213,7 @@ Example: @@ -213,7 +213,7 @@ Example:
213 213
214 ready: function(){ 214 ready: function(){
215 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, TreemapBehavior); 215 this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, TreemapBehavior);
216 - this.behavior.init(this); 216 + this.async(function(){this.behavior.init(this)},1);
217 } 217 }
218 218
219 }); 219 });