Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update form Master #18

Merged
merged 2 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/config.js.sample
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ var config = {
module: 'newsfeed',
position: 'bottom_bar',
config: {
feedUrl: 'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml',
feeds: [
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
}
],
showSourceTitle: true,
showPublishDate: true
}
},
Expand Down
24 changes: 16 additions & 8 deletions modules/default/calendar/calendarfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
var today = moment().startOf("day").toDate();
var future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1,"seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.



// FIXME:
// Ugly fix to solve the facebook birthday issue.
// Otherwise, the recurring events only show the birthday for next year.
Expand All @@ -57,6 +55,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe

if (event.type === "VEVENT") {

//console.log(event);

var startDate = (event.start.length === 8) ? moment(event.start, "YYYYMMDD") : moment(new Date(event.start));
var endDate;
if (typeof event.end !== "undefined") {
Expand All @@ -65,6 +65,9 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
endDate = startDate;
}

// calculate the duration f the event for use with recurring events.
var duration = parseInt(endDate.format("x")) - parseInt(startDate.format("x"));

if (event.start.length === 8) {
startDate = startDate.startOf("day");
}
Expand All @@ -75,12 +78,15 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe

for (var d in dates) {
startDate = moment(new Date(dates[d]));
newEvents.push({
title: (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary,
startDate: startDate.format("x"),
endDate: endDate.format("x"),
fullDayEvent: isFullDayEvent(event)
});
endDate = moment(parseInt(startDate.format("x")) + duration, 'x');
if (endDate.format("x") > now) {
newEvents.push({
title: (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary,
startDate: startDate.format("x"),
endDate: endDate.format("x"),
fullDayEvent: isFullDayEvent(event)
});
}
}
} else {
// console.log("Single event ...");
Expand Down Expand Up @@ -119,6 +125,8 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
return a.startDate - b.startDate;
});

//console.log(newEvents);

events = newEvents.slice(0, maximumEntries);

self.broadcastEvents();
Expand Down
62 changes: 59 additions & 3 deletions modules/default/newsfeed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ modules: [
// The config property is optional.
// If no config is set, an example calendar is shown.
// See 'Configuration options' for more information.

feeds: [
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
},
{
title: "BBC
",
url: "http://feeds.bbci.co.uk/news/video_and_audio/news_front_page/rss.xml?edition=uk",
},
]
}
}
]
Expand All @@ -35,12 +47,25 @@ The following properties can be configured:
<tbody>

<tr>
<td><code>feedUrl</code></td>
<td>The url of the feed used for the headlines.<br>
<br><b>Default value:</b> <code>'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml'</code>
<td><code>feeds</code></td>
<td>An array of feed urls that will be used as source.<br>
More info about this object can be found below.
<br><b>Default value:</b> <code>[
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
}
]</code>
</td>
</tr>

<tr>
<td><code>showSourceTitle</code></td>
<td>Display the title of the source.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
<tr>
<td><code>showPublishDate</code></td>
<td>Display the publish date of an headline.<br>
Expand Down Expand Up @@ -77,9 +102,40 @@ The following properties can be configured:
<br><b>Default value:</b> <code>2000</code> (2.5 seconds)
</td>
</tr>


</tbody>
</table>

The `feeds` property contains an array with multiple objects. These objects have the following properties:

<table width="100%">
<!-- why, markdown... -->
<thead>
<tr>
<th>Option</th>
<th width="100%">Description</th>
</tr>
<thead>
<tbody>

<tr>
<td><code>title</code></td>
<td>The name of the feed source to be displayed above the news items.<br>
<br>This property is optional.
</td>
</tr>

<tr>
<td><code>url</code></td>
<td>The url of the feed used for the headlines.<br>
<br><b>Example:</b> <code>'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml'</code>
</td>
</tr>
<tr>
<td><code>encoding</code></td>
<td>The encoding of the news feed.<br>
<br>This property is optional.
<br><b>Possible values:</b><code>'UTF-8'</code>, <code>'ISO-8859-1'</code>, etc ...
<br><b>Default value:</b> <code>'UTF-8'</code>
</td>
Expand Down
12 changes: 7 additions & 5 deletions modules/default/newsfeed/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ var Fetcher = function(url, reloadInterval, encoding) {
var regex = /(<([^>]+)>)/ig;
description = description.replace(regex, "");

items.push({
title: item.title,
description: description,
pubdate: item.pubdate,
});
if (item.title && description && item.pubdate) {
items.push({
title: item.title,
description: description,
pubdate: item.pubdate,
});
}
});

parser.on("end", function() {
Expand Down
128 changes: 99 additions & 29 deletions modules/default/newsfeed/newsfeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ Module.register("newsfeed",{

// Default module config.
defaults: {
feedUrl: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
feeds: [
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
encoding: "UTF-8" //ISO-8859-1
}
],
showSourceTitle: true,
showPublishDate: true,
showDescription: false,
reloadInterval: 5 * 60 * 1000, // every 5 minutes
updateInterval: 10 * 1000,
animationSpeed: 2.5 * 1000,
encoding: "UTF-8" //ISO-8859-1
},

// Define required scripts.
Expand All @@ -36,47 +42,49 @@ Module.register("newsfeed",{
this.loaded = false;
this.activeItem = 0;

this.fetchNews();
this.registerFeeds();

},

// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === "NEWS_ITEMS") {
if (payload.url === this.config.feedUrl) {
this.newsItems = payload.items;
if (!this.loaded) {
this.scheduleUpdateInterval();
}
this.generateFeed(payload);

this.loaded = true;
if (!this.loaded) {
this.scheduleUpdateInterval();
}

this.loaded = true;
}
},

// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");

// wrapper.className = "small";
// for (var n in this.newsItems) {
// var item = this.newsItems[n];
// wrapper.innerHTML += item.title + '<br>';
// }
// return wrapper;
if (this.config.feedUrl) {
wrapper.className = "small bright";
wrapper.innerHTML = "The configuration options for the newsfeed module have changed.<br>Please check the documentation.";
return wrapper;
}

if (this.activeItem >= this.newsItems.length) {
this.activeItem = 0;
}

if (this.newsItems.length > 0) {

if (this.config.showPublishDate) {
var timestamp = document.createElement("div");
timestamp.className = "light small dimmed";
timestamp.innerHTML = this.capitalizeFirstLetter(moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ":");
//timestamp.innerHTML = this.config.feedUrl;
wrapper.appendChild(timestamp);
if (this.config.showSourceTitle || this.config.showPublishDate) {
var sourceAndTimestamp = document.createElement("div");
sourceAndTimestamp.className = "light small dimmed";

if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== '') sourceAndTimestamp.innerHTML = this.newsItems[this.activeItem].sourceTitle;
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== '' && this.config.showPublishDate) sourceAndTimestamp.innerHTML += ', ';
if (this.config.showPublishDate) sourceAndTimestamp.innerHTML += moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow();
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== '' || this.config.showPublishDate) sourceAndTimestamp.innerHTML += ':';

wrapper.appendChild(sourceAndTimestamp);
}

var title = document.createElement("div");
Expand All @@ -99,16 +107,78 @@ Module.register("newsfeed",{
return wrapper;
},

/* fetchNews(compliments)
* Requests new data from news proxy.
/* registerFeeds()
* registers the feeds to be used by the backend.
*/
fetchNews: function() {
Log.log("Add news feed to fetcher: " + this.config.feedUrl);
this.sendSocketNotification("ADD_FEED", {
url: this.config.feedUrl,
reloadInterval: this.config.reloadInterval,
encoding: this.config.encoding

registerFeeds: function() {
for (var f in this.config.feeds) {
var feed = this.config.feeds[f];
this.sendSocketNotification("ADD_FEED", {
feed: feed,
config: this.config
});
}
},

/* registerFeeds()
* Generate an ordered list of items for this configured module.
*
* attribute feeds object - An object with feeds returned by the nod helper.
*/
generateFeed: function(feeds) {
var newsItems = [];
for (var feed in feeds) {
var feedItems = feeds[feed];
if (this.subscribedToFeed(feed)) {
for (var i in feedItems) {
var item = feedItems[i];
item.sourceTitle = this.titleForFeed(feed);
newsItems.push(item);
}
}
}
newsItems.sort(function(a,b) {
var dateA = new Date(a.pubdate);
var dateB = new Date(b.pubdate);
return dateB - dateA;
});

this.newsItems = newsItems;
},

/* subscribedToFeed(feedUrl)
* Check if this module is configured to show this feed.
*
* attribute feedUrl string - Url of the feed to check.
*
* returns bool
*/
subscribedToFeed: function(feedUrl) {
for (var f in this.config.feeds) {
var feed = this.config.feeds[f];
if (feed.url === feedUrl) {
return true;
}
}
return false;
},

/* subscribedToFeed(feedUrl)
* Returns title for a specific feed Url.
*
* attribute feedUrl string - Url of the feed to check.
*
* returns string
*/
titleForFeed: function(feedUrl) {
for (var f in this.config.feeds) {
var feed = this.config.feeds[f];
if (feed.url === feedUrl) {
return feed.title || '';
}
}
return '';
},

/* scheduleUpdateInterval()
Expand Down
Loading