Add feed reading functionality
authorChip Black <bytex64@bytex64.net>
Tue, 24 Apr 2012 03:42:46 +0000 (20:42 -0700)
committerChip Black <bytex64@bytex64.net>
Tue, 24 Apr 2012 03:42:46 +0000 (20:42 -0700)
www/css/blerg.css
www/jssrc/blerg/API.js
www/jssrc/blerg/Blerg.js
www/jssrc/blerg/Controls.js
www/jssrc/blerg/Feed.js [new file with mode: 0644]
www/jssrc/blerg/package.js

index ed87bc6..a167578 100644 (file)
@@ -74,6 +74,10 @@ a > img {
        font-size: 14pt;
 }
 
+.feed-button.new {
+       background-color: #E4C010;
+}
+
 .spew-button {
        color: #333;
        background-color: #0D0;
index 1370234..203706a 100644 (file)
@@ -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,
index f40a277..3228d67 100644 (file)
@@ -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) {
index e593976..daf06bd 100644 (file)
@@ -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 (file)
index 0000000..1bb4e37
--- /dev/null
@@ -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);
+    }
+});
index 70d4520..9640acd 100644 (file)
@@ -14,5 +14,6 @@ enyo.depends(
     'Pager.js',
     'User.js',
     'Tag.js',
+    'Feed.js',
     'Blerg.js'
 );