diff options
author | dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2008-09-17 17:29:43 (GMT) |
---|---|---|
committer | dave@33eels.com <dave@33eels.com@4eb1ac78-321c-0410-a911-ec516a8615a5> | 2008-09-17 17:29:43 (GMT) |
commit | d49f767738e9e95958092231d79b673037b5d734 (patch) | |
tree | 66990d532619d96ec47f8aee4e9ef94c458b0b8e | |
parent | 11167b6977aa03778bf22eab7a78d1ee45366032 (diff) |
- Added unread count and editable bits to feed binding.
- Fixed a bug caused duplicate database entries.
git-svn-id: http://svn.mozilla.org/addons/trunk@18336 4eb1ac78-321c-0410-a911-ec516a8615a5
-rw-r--r-- | bandwagon/components/bandwagon-service.js | 3 | ||||
-rw-r--r-- | bandwagon/content/scripts/factory/feedFactory.js | 35 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/feed.js | 37 | ||||
-rw-r--r-- | bandwagon/content/scripts/model/feedItem.js | 5 | ||||
-rw-r--r-- | bandwagon/content/ui/bindings/bandwagon.xml | 18 | ||||
-rw-r--r-- | bandwagon/content/ui/feedsPaneController.js | 42 | ||||
-rw-r--r-- | bandwagon/skin/extensionsOverlay.css | 16 | ||||
-rw-r--r-- | bandwagon/skin/images/star.png | bin | 0 -> 14249 bytes |
8 files changed, 135 insertions, 21 deletions
diff --git a/bandwagon/components/bandwagon-service.js b/bandwagon/components/bandwagon-service.js index d165b31..3c418a4 100644 --- a/bandwagon/components/bandwagon-service.js +++ b/bandwagon/components/bandwagon-service.js @@ -390,7 +390,8 @@ BandwagonService.prototype = { "CREATE TABLE IF NOT EXISTS feedItems " + "(id INTEGER PRIMARY KEY AUTOINCREMENT, " + "feed INTEGER NOT NULL, " - + "addon INTEGER NOT NULL)" + + "addon INTEGER NOT NULL, " + + "read INTEGER NOT NULL DEFAULT 0)" ); this._storageConnection.executeSimpleSQL( "CREATE TABLE IF NOT EXISTS addons " diff --git a/bandwagon/content/scripts/factory/feedFactory.js b/bandwagon/content/scripts/factory/feedFactory.js index 946d509..0a1ee64 100644 --- a/bandwagon/content/scripts/factory/feedFactory.js +++ b/bandwagon/content/scripts/factory/feedFactory.js @@ -207,7 +207,7 @@ Bandwagon.Factory.FeedFactory.prototype._openFeedItems = function(feed) { var feedItems = {}; - var statement = this.connection.createStatement("SELECT addons.* FROM addons LEFT JOIN feedItems ON addons.id = feedItems.addon WHERE feedItems.feed = ?1"); + var statement = this.connection.createStatement("SELECT addons.*, feedItems.id, feedItems.read FROM addons LEFT JOIN feedItems ON addons.id = feedItems.addon WHERE feedItems.feed = ?1"); try { @@ -232,6 +232,8 @@ Bandwagon.Factory.FeedFactory.prototype._openFeedItems = function(feed) feedItem.author = statement.getUTF8String(12); feedItem.category = statement.getUTF8String(13); feedItem.dateAdded = new Date(statement.getInt32(14)*1000); + feedItem.feedItemId = statement.getInt32(15); + feedItem.read = (statement.getInt32(16)==1?true:false); feedItem.compatibleApplications = this._openFeedItemCompatibleApplications(feedItem); feedItem.compatibleOS = this._openFeedItemCompatibleOS(feedItem); @@ -462,24 +464,33 @@ Bandwagon.Factory.FeedFactory.prototype._commitFeedItem = function(feed, feedIte // add the feedItem connector - if (feedItem.id == -1) - { - statement = this.connection.createStatement("REPLACE INTO feedItems VALUES (?1, ?2, ?3)"); + statement = this.connection.createStatement("REPLACE INTO feedItems VALUES (?1, ?2, ?3, ?4)"); - try + try + { + if (feedItem.feedItemId == -1) { statement.bindNullParameter(0); - statement.bindInt32Parameter(1, feed.id); - statement.bindInt32Parameter(2, addonid); - - statement.execute(); } - finally + else { - statement.reset(); + statement.bindInt32Parameter(0, feedItem.feedItemId); } - feedItem.id = this.connection.lastInsertRowID; + statement.bindInt32Parameter(1, feed.id); + statement.bindInt32Parameter(2, addonid); + statement.bindInt32Parameter(3, (feedItem.read?1:0)); + + statement.execute(); + } + finally + { + statement.reset(); + } + + if (feedItem.feedItemId == -1) + { + feedItem.feedItemId = this.connection.lastInsertRowID; } return true; diff --git a/bandwagon/content/scripts/model/feed.js b/bandwagon/content/scripts/model/feed.js index 15ec5d8..9fad754 100644 --- a/bandwagon/content/scripts/model/feed.js +++ b/bandwagon/content/scripts/model/feed.js @@ -50,11 +50,36 @@ Bandwagon.Model.Feed = function() this.showNotifications = false; this.autoPublish = false; this.active = true; + this.preview = false; + this.editable = false; this.feedItems = {}; } +Bandwagon.Model.Feed.prototype.getUnreadFeedItems = function() +{ + var unreadFeedItems = []; + + for (var id in this.feedItems) + { + if (!this.feedItems[id].read) + { + unreadFeedItems.push(this.feedItems[id]); + } + } + + return unreadFeedItems; +} + +Bandwagon.Model.Feed.prototype.setRead = function() +{ + for (var id in this.feedItems) + { + this.feedItems[id].read = true; + } +} + Bandwagon.Model.Feed.prototype.toString = function() { return this.name + " (" + this.url + ")"; @@ -76,7 +101,17 @@ Bandwagon.Model.Feed.prototype.unserialize = function(xaddons) feedItem.unserialize(xaddon); if (feedItem.guid && feedItem.guid != "" && feedItem.name && feedItem.name != "") - this.feedItems[feedItem.guid] = feedItem; + { + if (this.feedItems[feedItem.guid]) + { + // "merge" with existing item + this.feedItems[feedItem.guid].unserialize(xaddon); + } + else + { + this.feedItems[feedItem.guid] = feedItem; + } + } } /* TODO feed is missing info for the following: diff --git a/bandwagon/content/scripts/model/feedItem.js b/bandwagon/content/scripts/model/feedItem.js index 4b76a96..9bc04ee 100644 --- a/bandwagon/content/scripts/model/feedItem.js +++ b/bandwagon/content/scripts/model/feedItem.js @@ -41,7 +41,8 @@ Bandwagon.Model.FeedItem = function() this.TYPE_EXTENSION = 1; this.STATUS_PUBLIC = 4; - this.id = -1; // internal bandwagon id + this.id = -1; // internal bandwagon addon id + this.feedItemId = -1; // internal bandwagon feeditem id this.name = ""; this.type = -1; @@ -65,6 +66,8 @@ Bandwagon.Model.FeedItem = function() this.dateAdded = new Date(); this.comments = []; + this.read = false; + // *** temp comment //this.comments.push({comment: "Hey guys - you need to check out this cool new add-on! Two days in and I'm addicted!", author: "Bob"}); diff --git a/bandwagon/content/ui/bindings/bandwagon.xml b/bandwagon/content/ui/bindings/bandwagon.xml index ba5108d..9bf8e86 100644 --- a/bandwagon/content/ui/bindings/bandwagon.xml +++ b/bandwagon/content/ui/bindings/bandwagon.xml @@ -51,7 +51,11 @@ </resources> <content> - <xul:label anonid="name" flex="1"/> + <hbox flex="1" align="center"> + <xul:image anonid="star" src="chrome://bandwagon/skin/images/star.png" style="width: 1em; height: 1em;" collapsed="true"/> + <xul:label anonid="name"/> + <xul:label anonid="unread" collapsed="true"/> + </hbox> </content> <handlers> @@ -104,6 +108,16 @@ onset="this.setAttribute('preview', val);" /> + <property name="editable" + onget="return !document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed" + onset="document.getAnonymousElementByAttribute(this, 'anonid', 'star').collapsed = !val;" + /> + + <property name="unread" + onget="return !document.getAnonymousElementByAttribute(this, 'anonid', 'unread').value" + onset="document.getAnonymousElementByAttribute(this, 'anonid', 'unread').value = val; document.getAnonymousElementByAttribute(this, 'anonid', 'unread').collapsed = (val == 0);" + /> + <method name="setFeed"> <parameter name="feed"/> <body> @@ -112,6 +126,8 @@ this.name = (feed.name && feed.name !=""?feed.name:feed.url); this.url = feed.url; this.preview = feed.preview; + this.editable = feed.editable; + this.unread = feed.getUnreadFeedItems().length; ]]> </body> </method> diff --git a/bandwagon/content/ui/feedsPaneController.js b/bandwagon/content/ui/feedsPaneController.js index 39d2ec5..0fdf1c5 100644 --- a/bandwagon/content/ui/feedsPaneController.js +++ b/bandwagon/content/ui/feedsPaneController.js @@ -57,8 +57,6 @@ Bandwagon.Controller.FeedsPane.init = function() Bandwagon.Logger.debug("Initializing Bandwagon.Controller.FeedsPane"); - Bandwagon.Controller.FeedsPane.initialized = true; - this.elemBandwagonFeeds = document.getElementById("bandwagon-feeds-list"); this.elemBandwagonFeedItems = document.getElementById("bandwagon-feeditems-list"); this.elemBandwagonButtonViewSite = document.getElementById("bandwagon-button-viewsite"); @@ -86,6 +84,8 @@ Bandwagon.Controller.FeedsPane.bindingsReady = function() Bandwagon.Controller.FeedsPane._selectPreferredFeed(); Bandwagon.Controller.FeedsPane.initializedBindings = true; } + + Bandwagon.Controller.FeedsPane.initialized = true; } Bandwagon.Controller.FeedsPane.uninit = function() @@ -125,15 +125,34 @@ Bandwagon.Controller.FeedsPane.invalidate = function() Bandwagon.Controller.FeedsPane.feedUpdateObserver = function(feed) { + if (feed == null) + return; + Bandwagon.Logger.debug("In Bandwagon.Controller.FeedsPane.feedUpdateObserver() with feed '" + feed.url + "'"); if (Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem == null) return; - if (!feed.equals(Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed)) - return; + // update the unread count for this feed - Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(feed); + const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var elemsBandwagonFeed = Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.getElementsByTagNameNS(XULNS, "bandwagonFeed"); + + for (var i=0; i<elemsBandwagonFeed.length; i++) + { + if (elemsBandwagonFeed[i].feed.equals(feed)) + { + elemsBandwagonFeed[i].unread = feed.getUnreadFeedItems().length; + break; + } + } + + // if this feed is currently selected, update the view + + if (feed.equals(Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.feed)) + { + Bandwagon.Controller.FeedsPane._repopulateFeedItemsList(feed); + } } Bandwagon.Controller.FeedsPane.doUpdateAll = function(event) @@ -258,6 +277,19 @@ Bandwagon.Controller.FeedsPane.doShowFeed = function() // invalidate Bandwagon.Controller.FeedsPane.invalidate(); + + // set all items in this feed to be "read" + // if we've just opened this dialog, don't update the read count + + if (feed) + { + feed.setRead(); + + if (Bandwagon.Controller.FeedsPane.initialized) + { + Bandwagon.Controller.FeedsPane.elemBandwagonFeeds.selectedItem.unread = 0; + } + } } Bandwagon.Controller.FeedsPane.doExpandFeedItem = function(event) diff --git a/bandwagon/skin/extensionsOverlay.css b/bandwagon/skin/extensionsOverlay.css index 4a6cd58..b760456 100644 --- a/bandwagon/skin/extensionsOverlay.css +++ b/bandwagon/skin/extensionsOverlay.css @@ -71,6 +71,14 @@ radio[noimage="true"]#bandwagon-feeds-view { background: -moz-dialog;
}
+bandwagonFeed {
+ padding-top: 6px;
+ padding-bottom: 6px;
+ -moz-padding-start: 7px;
+ -moz-padding-end: 7px;
+ min-height: 25px;
+}
+
bandwagonFeed[selected="true"] {
background-color: -moz-cellhighlight;
color: -moz-cellhighlighttext;
@@ -85,6 +93,14 @@ richlistbox:focus > bandwagonFeed[selected="true"] { color: HighlightText;
}
+bandwagonFeed label[anonid="unread"] {
+ background-color: blue;
+ color: white;
+ min-width: 1.7em;
+ text-align: center;
+ -moz-border-radius: 40%;
+}
+
bandwagonFeedItem {
padding-top: 6px;
padding-bottom: 6px;
diff --git a/bandwagon/skin/images/star.png b/bandwagon/skin/images/star.png Binary files differnew file mode 100644 index 0000000..0a34484 --- /dev/null +++ b/bandwagon/skin/images/star.png |