dashboard-tourpedia.html 7.03 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
5
6
7
8
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../material-search/material-search.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../google-chart-elasticsearch/google-chart.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../reviews-table/reviews-table.html">
<link rel="import" href="../number-chart/number-chart.html">

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

<dom-module id="dashboard-tourpedia">

  <style is="custom-style">
    @import url("../../styles/app-theme.html");
  </style>
  <link rel="import" type="css" href="dashboard-tourpedia.css">

  <template>
    <iron-ajax auto
        url="queries.json"
        handle-as="json"
        last-response="{{queries}}"></iron-ajax>
    <iron-ajax auto
        url="/endpoint.json"
        handle-as="json"
        last-response="{{endpoint}}"></iron-ajax>
26
	<!--    <template is="dom-repeat" items="{{ids}}" as="id"> 
27
28
29
30
      <iron-ajax auto 
        url="{{getName(id)}}"
        handle-as="json"
        on-response="addPlace"></iron-ajax>
31
	</template> -->
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

    <paper-tabs selected="{{selected}}">
      <paper-tab>Dashboard</paper-tab>
      <paper-tab>Sparql Editor</paper-tab>
    </paper-tabs>

    <iron-pages selected="{{selected}}">
      <div>
        <material-search search-value="{{query}}"></material-search>
        <br>
        <div style="width: 100%; display: inline-block">
          <div style="width: 23%; margin-right: 2.6%; float: left">
            <number-chart 
              icon="info"
              stylebg="bg-red"
              data="{{data}}">
            </number-chart>
          </div>
          <div style="width: 23%; margin-right: 2.6%; float: left">
            <number-chart 
              data="{{data}}"
53
54
              object="todayilearned"
              aggKey="subredditName"
55
56
57
58
59
60
              title="Restaurants"
              icon="maps:local-dining"
              stylebg="bg-yellow">
            </number-chart>
          </div>
        </div>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        <!-- <div style="width: 100%; display: inline-block"> -->
        <!--   <div style="width: 23%; margin-right: 2.6%; float: left"> -->
        <!--     <number-chart  -->
        <!--       data="{{data}}" -->
        <!--       object="londres" -->
        <!--       title="Londres" -->
        <!--       icon="maps:local-dining" -->
        <!--       aggkey="location" -->
        <!--       stylebg="bg-yellow"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!--   <div style="width: 23%; margin-right: 2.6%; float: left"> -->
        <!--     <number-chart  -->
        <!--       data="{{data}}" -->
        <!--       object="madrid" -->
        <!--       aggkey="location" -->
        <!--       title="Madrid" -->
        <!--       icon="social:whatshot" -->
        <!--       stylebg="bg-green"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!--   <div style="width: 23%; float: left"> -->
        <!--     <number-chart  -->
        <!--       icon="maps:hotel" -->
        <!--       data="{{data}}" -->
        <!--       title="Paris" -->
        <!--       object="paris" -->
        <!--       aggkey="location" -->
        <!--       stylebg="bg-aqua"> -->
        <!--     </number-chart> -->
        <!--   </div> -->
        <!-- </div> -->
93
94
        <div style="width: 100%; display: inline-block">
          <div class="chart_container" style="right: 0; float: right">
95
96

		  <!--
97
            <google-chart
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
98
              data="{{data}}"
99
              field="subredditName"
100
101
102
103
104
105
106
              id='pie-chart4'
              extra-id='pie-chart4'
              type='pie'
              filters="{{filters}}"
              icon='maps:my-location'
              param='{{param}}'
              options='{"title": "Places at different cities"}'
107
              cols='[{"label": "subredditName", "type": "string"},{"label": "Count", "type": "number"}]'
108
109
            </google-chart>
          </div>
110
		  -->
111
112
          <div class="chart_container" style="left: 0; float: left">
            <google-chart
113
              field="subredditName"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
114
115
116
117
              data="{{data}}"             
              id='pie-chart3'
              extra-id='pie-chart3'
              type='pie'
118
              filters="{{filters}}"
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
119
120
121
              icon='room'
              options='{"title": "Different types of places"}'
              cols='[{"label": "Sentiment", "type": "string"},{"label": "Count", "type": "number"}]'
122
123
124
125
126
127
128
129
            </google-chart>
          </div>
        </div>
      </div>
    </iron-pages>
  </template>

  <script>
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
130
  var ready = false;
131
132
133
134
135
136
137
138
139
    Polymer({
      is: 'dashboard-tourpedia',
      properties: {
        selected: {
          type: Number,
          value: 0
        }, 

        ids:{
140
141
142
          type: Array
          /*value: ["481","482","32512","32420","91963","96677","160677","131425","322429","322612"]*/
           
143
144
145
146
        },
        data:{
          type: Object
        },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
147
148
149
150
        client: {
          type: Object,
          notify: true,
          observer: '_clientChanged'              
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
        },
        fields: {
          type: Array,
          value: function() { return []; }
        },

        places: {
          type: Array,
          notify: true,
          value: []
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },
    
      observers: [
      '_filtersChange(filters.*)'
      ],

      ready: function(){
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
175
        console.log("ready");
176
177
178
179
      },
      
      addPlace: function(event) {
        this.set('places', this.places.concat(event.detail.response))
180
        console.log(this.places)
181
182
183
184
185
186
187
188
189
190
      },
      
      getName: function(id) {
        return "http://tour-pedia.org/api/getPlaceDetails?id=" + id
      },
      
      getPoints: function(f) {
        return f.base;
      },

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
191
192
193
194
      _clientChanged: function() {
        console.log("ClientChanged");
        ready = true;
        this._query();
195
196
      },
      _filtersChange: function() {
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
197
198
199
        this._query();
       },
       _query: function() {
200
        console.log("_filtersChangedash")
201
        var that = this;
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
202
203
204
        console.log("Ready?: ", ready);
        if(ready){
          this.client.search({
205
          // undocumented params are appended to the query string
206
207
          index: "reddit",
          type: "article",
208
209
210
211
212
213
214
215
          body: {
            size: 10,
            query: {
              bool: {
                must: this.filters,
              }
            },
            aggs: {
216
              subredditName: {
217
                terms: {
218
                  field: "subredditName",
219
220
221
222
                  order: {
                    _count: "desc"
                  }
                }
223
224
225
226
              }
            }      
          }
          }).then(function (resp) {
227
228
229
230
            var myids = []
            resp.hits.hits.forEach(function(entry){myids.push(entry._id)})
            that.ids = myids;
            //console.log(that.ids)
231
            that.data = resp;
232
233
			console.log("DATA");
            console.log(that.data);
234
            
235
236
237
238
239
240
241
            });
        }
      }
    });
  </script>

</dom-module>