Blame view

datalets/datatable-datalet/datatable-datalet.html 4.97 KB
73bcce88   luigser   COMPONENTS
1
  <!--

5e6ba8af   isisadmin   datalet doc update
2
3
  @license

      The MIT License (MIT)

73bcce88   luigser   COMPONENTS
4
  

707a1508   root   update data-table...
5
      Copyright (c) 2015 Dipartimento di Informatica - Universit� di Salerno - Italy

5e6ba8af   isisadmin   datalet doc update
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  

      Permission is hereby granted, free of charge, to any person obtaining a copy

      of this software and associated documentation files (the "Software"), to deal

      in the Software without restriction, including without limitation the rights

      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

      copies of the Software, and to permit persons to whom the Software is

      furnished to do so, subject to the following conditions:

  

      The above copyright notice and this permission notice shall be included in

      all copies or substantial portions of the Software.

  

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

      THE SOFTWARE.

  -->

ae17a8dc   Luigi Serra   Controllet and da...
25
  <!--

950d181d   Luigi Serra   license updates
26
27
  * Developed by :

  * ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu

ae17a8dc   Luigi Serra   Controllet and da...
28
29
  *

  -->

5e6ba8af   isisadmin   datalet doc update
30
  

98d9d8a5   Renato De Donato   filters+groupby
31
  <link rel="import" href="../base-ajax-json-alasql-datalet/base-ajax-json-alasql-datalet.html">

5e6ba8af   isisadmin   datalet doc update
32
33
34
  

  <!--

  The `datatable-datalet` is a porting of Datatables JQuery library in a web component that has built up by using Polymer.

73bcce88   luigser   COMPONENTS
35
36
37
  Pass to this component a data url(CKAN api uri) and a string with one or multiple query in JsonPath format(separated by spaces) and it'll show a

  table with data and query attributes with all Datatables library features.

  

5e6ba8af   isisadmin   datalet doc update
38
  Example:

73bcce88   luigser   COMPONENTS
39
  

5e6ba8af   isisadmin   datalet doc update
40
41
42
      <datatable-datalet

          data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=#"

          fields='["field1","field2"]'>

73bcce88   luigser   COMPONENTS
43
44
      </datatables-datalet>

  

5e6ba8af   isisadmin   datalet doc update
45
46
47
48
  @element datatable-datalet

  @status v0.1

  @demo demo/index.html

  @group datalets

73bcce88   luigser   COMPONENTS
49
  -->

73bcce88   luigser   COMPONENTS
50
51
52
  

  <dom-module id="datatable-datalet">

      <template>

707a1508   root   update data-table...
53
          <link rel="stylesheet" type="text/css" href="js/DataTables/datatables.css"/>

73bcce88   luigser   COMPONENTS
54
  

707a1508   root   update data-table...
55
          <table id="datatable" class="stripe row-border" cellspacing="0" style="height: auto; width: auto;">

73bcce88   luigser   COMPONENTS
56
          </table>

498cdf34   Andrea Petta   leafletjs
57
          <base-ajax-json-alasql-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}" title="{{title}}" description="{{description}}" export_menu="{{export_menu}}"></base-ajax-json-alasql-datalet>

73bcce88   luigser   COMPONENTS
58
59
      </template>

  

707a1508   root   update data-table...
60
      <script type="text/javascript" src="js/DataTables/datatables.js"></script>

73bcce88   luigser   COMPONENTS
61
62
63
  

      <script>

          var DatatableBehavior = {

73bcce88   luigser   COMPONENTS
64
  

5bc002a2   isisadmin   datalet refactoring
65
              presentData: function(){

707a1508   root   update data-table...
66
67
                  var html = "";

  

9d4a34db   Luigi Serra   selection control...
68
                  if(!this.data || this.data[0] == undefined) return;

73bcce88   luigser   COMPONENTS
69
                  html += '<thead>'+

707a1508   root   update data-table...
70
                          '<tr>';

a1f0799c   isisadmin   datalet global re...
71
72
                  for(var x = 0; x<this.data.length; x++){

                      html += '<th>' + this.data[x].name + '</th>';

73bcce88   luigser   COMPONENTS
73
                  }

707a1508   root   update data-table...
74
75
                  html +=  '</tr>' +

                          '</thead>' +

73bcce88   luigser   COMPONENTS
76
                          '<tbody>';

a1f0799c   isisadmin   datalet global re...
77
                  for(var i = 0; i<this.data[0].data.length; i++){

73bcce88   luigser   COMPONENTS
78
                      html += '<tr>';

a1f0799c   isisadmin   datalet global re...
79
                      for(var x = 0; x<this.data.length; x++){

707a1508   root   update data-table...
80
                          html += '<td>' + this.data[x].data[i] + '</td>';

73bcce88   luigser   COMPONENTS
81
82
83
84
85
                      }

                      html += '</tr>';

                  }

                  html += '</tbody>';

  

f748e9cf   Luigi Serra   new controllet an...
86
                  $(this._component.$.datatable).html(html);

736f8317   Luigi Serra   datatable bug fixing
87
                  $(this._component.$.datatable).DataTable({"order": [], destroy: true});

73bcce88   luigser   COMPONENTS
88
89
90
91
92
              }

          };

  

          Polymer({

              is : 'datatable-datalet' ,

e5b73e81   isisadmin   addded behavior p...
93
94
  

              properties: {

413bc541   Renato De Donato   data cache
95
  

e5b73e81   isisadmin   addded behavior p...
96
97
98
99
100
101
102
103
104
105
                  /**

                   * It's the component behavior

                   *

                   * @attribute behavior

                   * @type Object

                   * @default {}

                   */

                  behavior : {

                      type : Object,

                      value : {}

498cdf34   Andrea Petta   leafletjs
106
                  },

413bc541   Renato De Donato   data cache
107
108
109
110
111
  

                  data : {

                      type : Array,

                      value : undefined

                  },

498cdf34   Andrea Petta   leafletjs
112
113
114
115
116
117
118
119
120
121
122
                  /**

                   * Control the export menu

                   * xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)

                   *

                   * @attribute export_menu

                   * @type Number

                   * @default 15

                   */

                  export_menu : {

                      type  : Number,

                      value : 9 // xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)

e5b73e81   isisadmin   addded behavior p...
123
124
125
                  }

              },

  

73bcce88   luigser   COMPONENTS
126
              ready: function(){

98d9d8a5   Renato De Donato   filters+groupby
127
                  this.behavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonAlasqlBehavior, DatatableBehavior);

b4accc86   Renato De Donato   datalet improved
128
                  this.async(function(){this.behavior.init(this)},0);

73bcce88   luigser   COMPONENTS
129
              }

73bcce88   luigser   COMPONENTS
130
          });

e5b73e81   isisadmin   addded behavior p...
131
  

73bcce88   luigser   COMPONENTS
132
133
134
      </script>

  </dom-module>