From 04a4fdf9d85e0d0b193300abe0c0e433449cd285 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Mon, 23 Apr 2012 20:42:46 -0700 Subject: [PATCH] Add feed reading functionality --- www/css/blerg.css | 4 ++++ www/jssrc/blerg/API.js | 38 ++++++++++++++++++++++++++++++++----- www/jssrc/blerg/Blerg.js | 6 +----- www/jssrc/blerg/Controls.js | 20 +++++++++++++++++-- www/jssrc/blerg/Feed.js | 31 ++++++++++++++++++++++++++++++ www/jssrc/blerg/package.js | 1 + 6 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 www/jssrc/blerg/Feed.js diff --git a/www/css/blerg.css b/www/css/blerg.css index ed87bc6..a167578 100644 --- a/www/css/blerg.css +++ b/www/css/blerg.css @@ -74,6 +74,10 @@ a > img { font-size: 14pt; } +.feed-button.new { + background-color: #E4C010; +} + .spew-button { color: #333; background-color: #0D0; diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 1370234..203706a 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -68,11 +68,6 @@ enyo.kind({ }); enyo.setCookie('username', '', {"Max-Age": 0}); }, - requestFeedStatus: function() { - if (!blerg.API.loggedIn) - throw new Error('Cannot request feed status when not logged in'); - // TODO - }, loadUserRecords: function(username, from ,to) { var url; if (from != undefined && to != undefined) { @@ -123,6 +118,39 @@ enyo.kind({ }.bind(this)); req.go(); }, + getFeedInfo: function() { + if (!blerg.API.loggedIn) + throw new Error('Cannot request feed status when not logged in'); + + var req = new enyo.Ajax({ + url: baseURL + '/feedinfo', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + this.bubble('onFeedInfo', inResponse); + }.bind(this)); + req.go({ + username: blerg.API.username + }); + }, + loadFeed: function() { + if (!blerg.API.loggedIn) + throw new Error('Cannot request feed status when not logged in'); + + var req = new enyo.Ajax({ + url: baseURL + '/feed', + method: 'POST' + }); + req.response(function(inSender, inResponse) { + this.bubble('onItemsLoaded', { + type: "feed", + entries: inResponse + }); + }.bind(this)); + req.go({ + username: blerg.API.username + }); + }, getSubscriptionStatus: function(username) { var req = new enyo.Ajax({ url: baseURL + '/feedinfo/' + username, diff --git a/www/jssrc/blerg/Blerg.js b/www/jssrc/blerg/Blerg.js index f40a277..3228d67 100644 --- a/www/jssrc/blerg/Blerg.js +++ b/www/jssrc/blerg/Blerg.js @@ -31,7 +31,7 @@ enyo.kind({ ['hash', /^#\/feed(?:\/p(\d+))?$/, "blerg.Feed"], ['hash', /^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/, "blerg.User"] ], - pathHandlers: [ blerg.User, blerg.Tag, blerg.Welcome ], + pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.Welcome ], rendered: function() { this.inherited(arguments); @@ -81,10 +81,6 @@ enyo.kind({ this.$.api.logout(); }, loginSuccessful: function(inSender, inEvent) { - this.$.api.requestFeedStatus(); - this.feedStatusUpdateInterval = setInterval(function() { - this.$.api.requestFeedStatus(); - }.bind(this), 900000); this.waterfall('onLogin', inEvent); }, loginFailed: function(inSender, inEvent) { diff --git a/www/jssrc/blerg/Controls.js b/www/jssrc/blerg/Controls.js index e593976..daf06bd 100644 --- a/www/jssrc/blerg/Controls.js +++ b/www/jssrc/blerg/Controls.js @@ -42,10 +42,12 @@ enyo.kind({ ]}, {classes: "blerg-controls-toolbar", components: [ {kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"}, - {kind: "onyx.Button", content: "Stalk Your Victims", onclick: "feedClicked"}, + {name: "feedButton", kind: "onyx.Button", classes: "feed-button", content: "Stalk Your Victims", onclick: "feedClicked"}, {name: "spewButton", kind: "onyx.Button", classes: "spew-button", content: "Spew It!", onclick: "spewToggle"} ]}, - ]} + ]}, + {name: "api", kind: "blerg.API", + onFeedInfo: "gotFeedInfo"} ], showRSS: function(url) { this.$.rssButton.show(); @@ -82,9 +84,15 @@ enyo.kind({ this.$.userlink.setAttribute('href', '/#' + inEvent.username); this.$.userlink.setContent('@' + inEvent.username); this.username = inEvent.username; + + this.$.api.getFeedInfo(); + this.feedStatusUpdateInterval = setInterval(function() { + this.$.api.getFeedInfo(); + }.bind(this), 900000); }, logout: function(inSender, inEvent) { this.setLoggedIn(false); + clearInterval(this.feedStatusUpdateInterval); }, spewToggle: function(inSender, inEvent) { this.postShowing = !this.postShowing; @@ -94,6 +102,14 @@ enyo.kind({ this.postShowing = inEvent.showing; this.$.spewButton.addRemoveClass('active', inEvent.showing); }, + gotFeedInfo: function(inSender, inEvent) { + this.$.feedButton.addRemoveClass('new', inEvent.new > 0); + if (inEvent.new > 0) { + this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.new + ')'); + } else { + this.$.feedButton.setContent('Stalk Your Victims'); + } + }, chatterClicked: function() { window.location.href = '/#/ref/' + this.username; this.bubble('onNavigate'); diff --git a/www/jssrc/blerg/Feed.js b/www/jssrc/blerg/Feed.js new file mode 100644 index 0000000..1bb4e37 --- /dev/null +++ b/www/jssrc/blerg/Feed.js @@ -0,0 +1,31 @@ +enyo.kind({ + name: "blerg.Feed", + kind: "blerg.Pager", + listKind: "blerg.TagRecord", + published: { + }, + components: [ + {name: "records"}, + {name: "api", kind: "blerg.API", + onItemsLoaded: "itemsLoaded"} + ], + statics: { + locationDetect: function(l) { + var m = l.hash.match(/^#\/feed$/); + if (m) { + return {kind: "blerg.Feed"}; + } + } + }, + create: function() { + this.inherited(arguments); + this.loadMore(); + }, + loadItems: function(from, to) { + this.inherited(arguments); + this.$.api.loadFeed(); + }, + itemsLoaded: function(inSender, inEvent) { + this.addItems(inEvent.entries); + } +}); diff --git a/www/jssrc/blerg/package.js b/www/jssrc/blerg/package.js index 70d4520..9640acd 100644 --- a/www/jssrc/blerg/package.js +++ b/www/jssrc/blerg/package.js @@ -14,5 +14,6 @@ enyo.depends( 'Pager.js', 'User.js', 'Tag.js', + 'Feed.js', 'Blerg.js' ); -- 2.34.1