Skip to content

Commit

Permalink
Got links working, added back button, made some style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelle Dick committed Jul 6, 2016
1 parent b117f38 commit 3c2ec8b
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 112 deletions.
83 changes: 36 additions & 47 deletions grapevine.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ var grapevine = {
callback();
}
});
}
});
}
});
},
//https call to google translate API
translate: function(search_query, from_language, to_language, callback){
Expand All @@ -87,11 +87,11 @@ var grapevine = {
method: 'GET'
};

logger.debug("translation path: ", httpOptions.host + httpOptions.path);
// logger.debug("translation path: ", httpOptions.host + httpOptions.path);

var request = https.request(httpOptions, function(response) {
// logger.debug("response data: ", response);
logger.debug("statusCode: ", response.statusCode);
// logger.debug("statusCode: ", response.statusCode);
// logger.debug("headers: ", response.headers);
var response_string = '';
response.on('data', function(d) {
Expand All @@ -100,7 +100,7 @@ var grapevine = {
});
response.on('end', function() {
var translation;
logger.info("response_string: ", response_string);
// logger.info("response_string: ", response_string);
var response_data = JSON.parse(response_string).data;
if (response_data) {
translation = response_data.translations[0].translatedText;
Expand Down Expand Up @@ -239,6 +239,7 @@ var grapevine = {
{
// logger.info('Searching ' + search_query + ' from ' + country_code);
var that = this;
var sim_country_callback = callback;
var to_language = this.countries[country_code].language_code;
console.log("to_language", to_language);
this.translate(search_query, from_language, to_language, function(result){
Expand All @@ -251,69 +252,58 @@ var grapevine = {
var news_xml = result;
var news_json = parser.toJson(news_xml);
for(idx in JSON.parse(news_json).rss.channel.item){
logger.info("idx = ", idx);
var xml_news_description = JSON.parse(news_json).rss.channel.item[idx].description.split('<font size="-1">');
news_stories[idx] = {};
news_stories[idx].untranslated_title = JSON.parse(news_json).rss.channel.item[idx].title;
news_stories[idx].link = JSON.parse(news_json).rss.channel.item[idx].link;
news_stories[idx].source = striptags(xml_news_description[1]);
news_stories[idx].untranslated_summary = striptags(xml_news_description[2]);
logger.info(news_stories[idx]);
}

var translator = function(i)
{
that.translate(news_stories[i].untranslated_summary, to_language, from_language, function(result){
news_stories[i].translated_summary = xhtmlUnescape(result);
that.translate(news_stories[i].untranslated_title, to_language, from_language, function(result){
news_stories[i].translated_title = xhtmlUnescape(result);
//logger.info('news_stories[' + i + '] = ' + news_stories[i].translated_title + ': ' + news_stories[i].translated_summary);
if (++translated == results.length)
{
callback(news_stories);
}
});
});
};

var xhtmlUnescape = function(escapedXhtml) {
escapedXhtml = escapedXhtml.replace(/&quot;/g, '"');
escapedXhtml = escapedXhtml.replace(/&amp;/g, '&');
escapedXhtml = escapedXhtml.replace(/&lt;/g, '<');
escapedXhtml = escapedXhtml.replace(/&gt;/g, '>');
escapedXhtml = escapedXhtml.replace(/&#39;/g, "'");
escapedXhtml = escapedXhtml.replace(/&nbsp;/g, " ");

return escapedXhtml;
};

});
});


var add_translations = function(news_stories, callback){
var news = [];
//for each news story
for(idx in news_stories){
var translated = 0;
translator(idx, function(result){
news.push(result);
if(++translated==idx){
callback(news);
}
});
}
}

var translator = function(idx, callback){
that.translate(news_stories[idx].untranslated_summary, to_language, from_language, function(result){
news_stories[idx].translated_summary = xhtmlUnescape(result);
that.translate(news_stories[idx].untranslated_title, to_language, from_language, function(result){
news_stories[idx].translated_title = xhtmlUnescape(result);
callback(news_stories[idx]);
});
});
}

// var results = result;
//add translated versions into news stories
add_translations(news_stories, function(news){
logger.info("hello hello line 300 news_stories...", news);
// grapevine.news_stories = news_stories;
callback(news);
});

});
});

// for (var i = 0; i < results.length; i++)
// {
// var news_story = {
// untranslated_title: results[i].titleNoFormatting,
// untranslated_summary: results[i].content,
// url: results[i].unescapedUrl
// };
// if (results[i].image) {
// news_story.image_url = results[i].image.tbUrl;
// }
//
// news_story.untranslated_summary = xhtmlUnescape(striptags(news_story.untranslated_summary));
// news_story.untranslated_title = xhtmlUnescape(striptags(news_story.untranslated_title));
// news_stories.push(news_story);
// translator(i);
// }
// });
// });
},
shutdown : function (callback)
{
Expand All @@ -325,7 +315,6 @@ var grapevine = {
}
});
callback();

}
};

Expand Down
12 changes: 6 additions & 6 deletions grapevine_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var server = require('http').Server(app);
//any socket made with socket io library will be bound to the server
var io = require('socket.io')(server);

var port = 8091;
//listens on localhost:8091 for event emissions
var port = 8090;
//listens on localhost:8090 for event emissions
server.listen(port);
console.log('listening on port ' + 8091);
console.log('listening on port ' + 8090);

var grapevine = require('./grapevine');
//define the init function
Expand All @@ -32,12 +32,12 @@ grapevine.init(function(){

//data = JSON.parse(data);
var search_query = data.search_query;
console.log("search_query:",search_query)
console.log("search_query:", search_query);
var countries = data.countries;
var user_language = data.user_language;
console.log("user_language:",user_language)
console.log("user_language:", user_language);
var result_start = data.result_start;
// console.log("result_start:",result_start)
// console.log("result_start:",result_start);
var grapes = function(i)
{
grapevine.simulate_country(search_query, countries[i], user_language, result_start[countries[i]], function(result){
Expand Down
1 change: 1 addition & 0 deletions news_result.json

Large diffs are not rendered by default.

73 changes: 49 additions & 24 deletions public/css/grapevine.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,41 @@
url('../fonts/BellGothicBT-Black.woff2') format('woff2');
}

@font-face {
font-family: 'Front Page News';
src: url('../fonts/FrontPageNews.woff') format('woff'),
url('../fonts/FrontPageNews.woff2') format('woff2');
}

body {
font-family: 'PT Sans';
font-family: 'Arial';
overflow-x: hidden;
}

h4 {
font-family: 'PT Sans';
font-family: 'Arial';
}


.row.no-gutters {
margin-right: 0;
margin-left: 0;
}
.row.no-gutters > [class^="col-"],
.row.no-gutters > [class*=" col-"] {
padding-right: 0;
padding-left: 0;
}

.grapevine-header{
font-family: "Front Page News";
margin-top: 40px;
}

.article-headline {
font-family: Arial;
font-weight: bold;
font-color: black;
}

.country-selection-alert {
Expand All @@ -42,7 +70,7 @@ h4 {
.title {
background-color: #000;
color: #FFF;
padding: 10px 20px;
padding: 10px 20px;
}

.inline {
Expand All @@ -52,17 +80,20 @@ h4 {
/* Making the country list scrollable: */
.country-list {
overflow-y: scroll;
overflow-x: hidden;
height: 50vh;
width: 100%;
border: 1px solid #E6E6E6;
padding-top: 10px;
}
.country-names{
margin-left: 15px;
}

.list-group-item{
border: none;
}
.list-group-item:hover{
background-color: #1B1464;
color: #fff;
background-color: #eee;
}

.list-group{
Expand All @@ -74,16 +105,6 @@ h4 {
width: 100%;
}

.gv-logo {
margin-top: 21px;
margin-left: 25px;
}

.description {
text-align: center;
padding-bottom: 20px;
}

.spacer {
margin-bottom: 20px;
}
Expand All @@ -97,11 +118,12 @@ h4 {
}

.country-input {
border: 1px solid #E6E6E6;
background-color: #EEE;
}

.form-control {
border: 1px solid #E6E6E6;
border-radius: 0px;
border: none;
}

.form-control:focus {
Expand All @@ -115,8 +137,7 @@ h4 {

.btn-primary.active {
background-color: #1abc9c;
border: 1px solid #1abc9c;
transition: border-color 0.15s ease-in-out 0s, background-color 0.15s ease-in-out 0s;
transition: border-color 0.15s ease-in-out 0s, background-color 0.5s ease-in-out 0s;
}

.country-tags {
Expand All @@ -125,12 +146,12 @@ h4 {
list-style: none;
margin: 0;
margin-top: 35px;
overflow: hidden;
overflow: hidden;
padding: 0;
}

.country-tags li {
float: left;
float: left;
}

.country-tag {
Expand Down Expand Up @@ -175,5 +196,9 @@ h4 {
}

.country-tag:hover::after {
border-left-color: #1B1464;
}
border-left-color: #1B1464;
}

.searchbar {
background-color: #EEE;
}
13 changes: 8 additions & 5 deletions public/css/news.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
}
.news-story {
border-bottom: 1px solid #EEE;
height: 300px;
overflow: hidden;
height: 100%;
}
.news-panel {
background-color: #EEE;
border-radius: 4px;
background-color: #FFF;
padding: 1px 10px 10px 10px;
border-left: 1px solid #666666;
border-right: 1px solid #666666;
}
.indent {
padding-left: 10px;
}
}
.article-country-name {
text-align: center;
}
Binary file added public/fonts/FrontPageNews.woff
Binary file not shown.
Binary file added public/fonts/FrontPageNews.woff2
Binary file not shown.
Loading

0 comments on commit 3c2ec8b

Please sign in to comment.