Commit ff5962e2 authored by Alberto Pascual's avatar Alberto Pascual
Browse files

initial version

parents
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt
The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<dom-module id="ajax-review">
<template>
<div>
<iron-ajax auto
url="{{getName(id)}}"
handle-as="json"
last-response="{{places}}"
on-response="completed"></iron-ajax>
<iron-ajax
id="ajax"
url="{{getIdURL(id)}}"
handle-as="json"
last-response="{{reviews}}"
on-response="finished"></iron-ajax>
<template is="dom-repeat" items="{{reviews}}" as="review">
<template is="dom-if" if="{{isOpen()}}">
<div style="width: 100%; text-align: center;">Place Name: <span>{{checkplace(id)}}</span></div>
</br>
</template>
<template is="dom-if" if="{{checkIndex(index)}}">
<div style="display: inline-block; width: 100%">
<div style="width: 10%; text-align: center; float: left"><img src={{checkSource(review.source)}} style="height: 20px"></div>
<div style="width: 80%; float: left; overflow: hidden">{{checkText(review.text)}}</div>
<div style="width: 10%; text-align: center; float: right">{{checkRating(review.rating)}}<img src="https://cdn4.iconfinder.com/data/icons/pretty_office_3/256/Star-Full.png" style="height: 15px; margin-left: 5px" /></div>
<div style="clear:both"></br></div>
</div>
</template>
</template>
</div>
</template>
<script>
Polymer({
is: 'ajax-review',
properties: {
reviews: {
type: Array
},
places: {
type: Array
},
id: {
type: String
},
isShowed: {
type: Boolean,
value: false
}
},
ready: function() {
},
isOpen: function() {
if(!this.isShowed){
this.isShowed = true
return true
}
return false
},
checkSource: function(source) {
if(source == "Foursquare")
return "https://playfoursquare.s3.amazonaws.com/press/2014/foursquare-logomark.png"
else if(source == "GooglePlaces")
return "http://www.reynoldsam.com/wordpress/wp-content/themes/ram/_images/locations/gpluslocal.png"
else if(source == "Facebook")
return "http://96bda424cfcc34d9dd1a-0a7f10f87519dba22d2dbc6233a731e5.r41.cf2.rackcdn.com/bikramyogaroslyn/1024px-Facebook_Home_svg.png"
},
checkText: function(text) {
if(text)
return text
else
return "No Review"
},
checkRating: function(rating) {
if(rating)
return rating
else
return "0"
},
checkIndex: function(index) {
//console.log(index)
if(index < 10)
return true
else
return false
},
getNameIndex: function(index) {
if(this.places != undefined)
return this.places.name
else
return "Undefined"
},
getName: function(id) {
return "http://tour-pedia.org/api/getPlaceDetails?id=" + id
},
getIdURL: function(id) {
return "http://tour-pedia.org/api/getReviewsByPlaceId?placeId=" + id
},
completed: function(){
console.log("iron-ajax completed")
this.$.ajax.generateRequest();
},
finished: function(){
console.log("iron-ajax review completed")
},
checkplace: function(id){
if (id == this.places.id){
return(this.places.name)
}
}
});
</script>
</dom-module>
\ No newline at end of file
{
"name": "reviews-table",
"authors": [
"gsi-upm"
],
"description": "Web component to visualize reviews from Tourpedia",
"main": "reviews-table.html",
"keywords": [
"tourpedia",
"webcomponents",
"polymer",
"reviews"
],
"dependencies": {
"polymer": "Polymer/polymer#^1.1.0",
"paper-material": "PolymerElements/paper-material#^1.0.0",
"iron-pages": "PolymerElements/iron-pages#^1.0.0",
"paper-button": "PolymerElements/paper-button#^1.0.0"
},
"license": "MIT",
"homepage": "https://lab.cluster.gsi.dit.upm.es/sefarad/reviews-table"
}
.top-bar{
width: 100%;
background-color: var(--dark-primary-color);
border-radius: 5px 5px 0 0;
color: white;
text-align: center;
height: 35px;
line-height: 35px;
}
.top-bar span {
vertical-align: middle;
}
iron-icon {
margin-right: 8px;
width: 21px;
height: 21px;
}
\ No newline at end of file
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at https://polymer.github.io/LICENSE.txt
The complete set of authors may be found at https://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at https://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at https://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../iron-pages/iron-pages.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="ajax-review.html">
<dom-module id="reviews-table">
<style is="custom-style">
@import url("../../styles/app-theme.html");
</style>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="import" type="css" href="reviews-table.css">
<template>
<paper-material elevation="1">
<div class="top-bar">
<iron-icon icon="{{icon}}"></iron-icon>
<span>Some Reviews</span>
</div>
<table class="table table-striped">
<tr>
<th style="width: 10%; text-align: center">Source</th>
<th style="width: 80%; text-align: center">Opinion</th>
<th style="width: 10%; text-align: center">Rating</th>
</tr>
</table>
<iron-pages id="pages" selected="0">
<template is="dom-repeat" items="{{ids}}" as="id">
<ajax-review id="{{id}}"></ajax-review>
</template>
</iron-pages>
</table>
<div style="text-align:center; margin: 0 auto">
<paper-button on-click="previousPage">&lt;&lt;</paper-button>
<span style="color: blue">{{actual}}</span>
<paper-button on-click="nextPage">&gt;&gt;</paper-button>
</div>
</paper-material>
</template>
<script>
var filtered = false;
Polymer({
is: 'reviews-table',
properties: {
reviews: {
type: Array
},
icon: {
type: String
},
actual: {
type: String,
value: "1"
},
ids:{
type: Array,
value: ["481","482","32512","32420","91963","96677","160677","131425","322429","322612"]
},
fields: {
type: Array,
value: function() { return []; }
},
index: {
type: String
},
subindex: {
type: String
},
query: {
type: String,
observer: '_queryChanged'
},
filters: {
type: Array,
notify: true,
value: function() { return []; }
}
},
observers: [
'_filtersChange(filters.*)'
],
ready: function() {
},
checkSource: function(source) {
if(source == "Foursquare")
return "https://playfoursquare.s3.amazonaws.com/press/2014/foursquare-logomark.png"
else if(source == "GooglePlaces")
return "http://www.reynoldsam.com/wordpress/wp-content/themes/ram/_images/locations/gpluslocal.png"
else if(source == "Facebook")
return "http://96bda424cfcc34d9dd1a-0a7f10f87519dba22d2dbc6233a731e5.r41.cf2.rackcdn.com/bikramyogaroslyn/1024px-Facebook_Home_svg.png"
},
checkText: function(text) {
if(text)
return text
else
return "No Review"
},
checkRating: function(rating) {
if(rating)
return rating
else
return "0"
},
checkIndex: function(index) {
if(index < 10)
return true
else
return false
},
previousPage: function() {
this.$.pages.selectPrevious()
this.actual = 1 + this.$.pages.selected
},
nextPage: function() {
this.$.pages.selectNext()
this.actual = 1 + this.$.pages.selected
},
getIdURL: function(index) {
return "http://tour-pedia.org/api/getReviewsByPlaceId?placeId="+this.ids[index]
},
_queryChanged: function() {
this.query ? this.queryChange(this.query) : this.queryDefault();
},
queryChange: function(value) {
var client = new $.es.Client({
hosts: this.host
});
var id = this.extraId;
var doc = this;
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
multi_match:{
query: this.query,
fields: this.fields
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
doc.ids = [];
hits.forEach(function(entry) {
doc.push('ids',entry._id)
});
});
},
queryDefault: function() {
var client = new $.es.Client({
hosts: this.host
});
var id = this.extraId;
var doc = this;
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
match_all: {}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
doc.ids = [];
hits.forEach(function(entry) {
doc.push('ids',entry._id)
});
});
},
_filtersChange: function() {
if(filtered){
var client = new $.es.Client({
hosts: this.host
});
var id = this.extraId;
var doc = this;
client.search({
// undocumented params are appended to the query string
index: this.index,
type: this.subindex,
body: {
size: 10,
query: {
bool: {
must: this.filters,
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
doc.ids = [];
hits.forEach(function(entry) {
doc.push('ids',entry._id)
});
});
}
}
});
</script>
</dom-module>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment