Skip to content

Commit

Permalink
Fixed erros. Added mocked followings
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ortega Moreno committed Jan 13, 2017
1 parent af79ca2 commit 3d779f4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 50 deletions.
58 changes: 37 additions & 21 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,48 @@
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>googleplus-timeline Demo</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../googleplus-timeline.html">
</head>
<body unresolved>
<p>An example of <code>&lt;googleplus-timeline&gt;</code>:</p>
<link rel="import" href="../../google-login/google-login.html">
</head>

<body unresolved>

<template id="Demo" is="dom-bind">
<googleplus-timeline token="{{token}}" language="{{language}}" api_key="{{api_key}}"
accuracy-probability=85>
</googleplus-timeline>
</br></br>
<button name="es" on-click="changeIdiom">Spanish</button>
<button name="en" on-click="changeIdiom">English</button>
<template id="Demo" is="dom-bind">
<google-login class="button-login" client_id="37385538925-jv2d25auk59lisafr1gu83r04d9cuivt.apps.googleusercontent.com" scope="https://www.googleapis.com/auth/contacts https://www.googleapis.com/auth/contacts.readonly"
callback="http://localhost:8080" static="true" on-google-logged="onSignIn"></google-login>
<template is="dom-if" if="{{token}}">
<googleplus-timeline token="{{token}}" language="{{language}}" api_key="{{api_key}}">
</googleplus-timeline>
</br>
</br>
<button name="es" on-click="changeIdiom">Spanish</button>
<button name="en" on-click="changeIdiom">English</button>
</template>
</template>
<script>
Demo.language = "es";
Demo.token = "ya29.CjnPA7ijuAvHRLPRaimF05UFtr7dG6sgy6kkyCtKT5H7NOZyd6uqmXiRM4DSiCWCLAepmlU0E3qxzkc";
Demo.api_key = "AIzaSyAArT6pflqm1-rj9Nwppuj_4z15FFh4Kis";
Demo.changeIdiom = function(event,detail) {
Demo.language = event.target.getAttribute('name');
}
Demo.api_key = "AIzaSyAArT6pflqm1-rj9Nwppuj_4z15FFh4Kis";
Demo.language = "es";
//Demo.token = "ya29.CjnRAz_mClEKcmL-LIZs_YtX9qLwuAfmQGLfWpWUyn8dLqTt__tJxRh5topeWsOn-pSaAoFl_bf1DBg";
//Demo.token = "ya29.CjTRAzEeBHRAyGJJhusqHue_zXcejU_XVffonJxprB9DVpQZixyGy6NRr7aSe__Wnc0tAEXc";
Demo.changeIdiom = function (event, detail) {
Demo.language = event.target.getAttribute('name');
}

Demo.onSignIn = function (googleUser) {
// The ID token you need to pass to your backend:
// We set the access token obtained
Demo.token = googleUser.detail.token;
console.log(Demo.token);
};

</script>
</body>
</html>

</body>

</html>
62 changes: 33 additions & 29 deletions googleplus-timeline.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<style is="custom-style">
:host {
display: inline-block;
width: var(--github-events-width, 450px);
height: var(--github-events-height, 450px);
width: var(--google-timeline-width, 450px);
height: var(--google-timeline-height, 450px);
min-height: 200px;
min-width: 200px;

Expand All @@ -55,9 +55,9 @@
paper-header-panel {
width: 100%;
height: 100%;
@apply(--shadow-elevation-3dp);
border-radius: 8px;
background-color: #fff;
@apply(--shadow-elevation-3dp);
}
div.paper-header {
height: 60px;
Expand Down Expand Up @@ -338,6 +338,14 @@
on-response="_responsePosts"
>
</iron-ajax>
<iron-ajax
id="requestMock"
method="GET"
handleAs='json'
url="{{mockUrl}}"
on-response="_responseFollowings"
>
</iron-ajax>

<paper-header-panel mode="waterfall" class="red">
<div class="paper-header">
Expand Down Expand Up @@ -501,14 +509,14 @@
</paper-material>
</template>
<!-- "Load More" button -->

<div id="loading">
<!--<img src="http://www.downgraf.com/wp-content/uploads/2014/09/01-progress.gif" width="100%">-->
<img src="http://i.imgur.com/S3YnJBQ.jpg" width="100%">
</div>
<div on-click="_loadMorePosts" class="horizontal center-justified layout" id="loadMoreDiv" hidden>
<paper-button id="loadMoreButton">{{language_data.load_more}}</paper-button>
<paper-button id="loadMoreButton">{{language_data.load_more}}</paper-button>
</div>

<div class="loading" id="loadingGif">
<img src="loading.gif">
<p>Loading...</p>
<!-- </template> -->
</div>
</div>
</paper-header-panel>
Expand Down Expand Up @@ -633,6 +641,12 @@
value: 15,
reflectToAttribute: true,
notify: true
},
mockUrl: {
type: String,
value: function(){
return this.resolveUrl('mockData/following.json');
},
}
},

Expand All @@ -650,19 +664,12 @@
}
},

_changeUserId: function(item) {
userId = item.actor.displayName;
console.log(this.accuracyProbability);
if(this.probability(this.accuracyProbability))
userId = this.language_data.user;
return userId;
},
_changeText: function(item) {
var text = item.object.content;
console.log(this.accuracyProbability);
if(this.probability(this.accuracyProbability))
text = 'Text fail';
return text;
_changeData: function(item) {
if(this.probability(this.accuracyProbability)){
item.actor.displayName = this.language_data.user;
item.object.content = 'Text fail'
}
return item;
},
_responseFollowings: function(event, detail){
//We generate an ajax request to get the post published by the authenticated user
Expand Down Expand Up @@ -722,8 +729,7 @@
_updateTimelinePosts: function(user_post){
// If the post was published inside the period fixed for the page, we add it to the
// list of post that are being showed to the user
user_post.actor.displayName = this._changeUserId(user_post);
user_post.object.content = this._changeText(user_post);
user_post = this._changeData(user_post);
if(user_post.published >= this.page_timestamp){
this.push('timeline_posts', user_post);
//We increment the var that represents the posts displayed per page
Expand All @@ -737,11 +743,9 @@
},

_responsePosts: function(event, detail){
this.$.loading.hidden = true;
// We reset the params field for the next request of requestPost iron-ajax
this.$.requestPosts.setAttribute("params", '{}');
this.$.loadMoreDiv.removeAttribute('hidden');
this.$.loadingGif.setAttribute('hidden',true);

//Appends all user posts to the user timeline
user_posts = detail.response.items;
// If the user hasn't posted anything yet, we just ignore it
Expand All @@ -765,7 +769,7 @@
// We obtain the next page for the user_posts, in order to obtain all the post in a given period (specified by page_timestamp)

this._obtainNextPagePost(current_page_details.author, current_page_details.timestamp, current_page_details.nextPageToken);

this.$.loadMoreDiv.hidden = false;
}
},

Expand Down Expand Up @@ -802,7 +806,7 @@
"Timing-Allow-origin": "*"};
this.$.requestFollowing.setAttribute("headers", JSON.stringify(headers));
this.$.requestPosts.setAttribute("headers", JSON.stringify(headers));
this.$.requestFollowing.generateRequest();
this.$.requestMock.generateRequest();
}
},

Expand Down
52 changes: 52 additions & 0 deletions mockData/following.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"kind": "plus#peopleFeed",
"etag": "\"FT7X6cYw9BSnPtIywEFNNGVVdio/O9hTR3m8tAQKjevlkfuBOi1Zlug\"",
"title": "Google+ List of Visible People",
"totalItems": 4,
"items": [
{
"kind": "plus#person",
"etag": "\"FT7X6cYw9BSnPtIywEFNNGVVdio/iNdJcri8bifEzDHo8flY6apSfSM\"",
"objectType": "person",
"id": "114562083342340135920",
"displayName": "Ana Isabel Lopera",
"url": "https://plus.google.com/114562083342340135920",
"image": {
"url": "https://lh3.googleusercontent.com/-j8JjAgelUec/AAAAAAAAAAI/AAAAAAAAALU/hPEQ9nyc6Mk/photo.jpg?sz=50"
}
},
{
"kind": "plus#person",
"etag": "\"FT7X6cYw9BSnPtIywEFNNGVVdio/ecO9qIfc-O3CtgsrX4Gm58apaf0\"",
"objectType": "page",
"id": "117105793163182226623",
"displayName": "Google Cloud",
"url": "https://plus.google.com/+googlecloud",
"image": {
"url": "https://lh6.googleusercontent.com/-X94QCdk41Dk/AAAAAAAAAAI/AAAAAAAALrA/qeRgs05tbfQ/photo.jpg?sz=50"
}
},
{
"kind": "plus#person",
"etag": "\"FT7X6cYw9BSnPtIywEFNNGVVdio/ltJ_N1ZpRF2_IUW13B_nE9bNf3g\"",
"objectType": "page",
"id": "111395306401981598462",
"displayName": "Google Developers",
"url": "https://plus.google.com/+GoogleDevelopers",
"image": {
"url": "https://lh6.googleusercontent.com/-Fgp8KFpgQqE/AAAAAAAAAAI/AAAAAAAAY1o/Ch6QYQwEmQo/photo.jpg?sz=50"
}
},
{
"kind": "plus#person",
"etag": "\"FT7X6cYw9BSnPtIywEFNNGVVdio/qvIGMeSKZ6Al8cV10ixXxHWhOFo\"",
"objectType": "page",
"id": "107187849809354688692",
"displayName": "Polymer",
"url": "https://plus.google.com/+PolymerProject",
"image": {
"url": "https://lh6.googleusercontent.com/-90wHGmiWUzs/AAAAAAAAAAI/AAAAAAAAAT4/GFxDJPUx9zM/photo.jpg?sz=50"
}
}
]
}

0 comments on commit 3d779f4

Please sign in to comment.