Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start work on JS to update the rss link as required

  • Loading branch information...
commit a9a34cd0751d75862b34b5e9ca1c6ef40525a78c 1 parent f30fe1b
@mitechie authored
View
5 Makefile
@@ -158,7 +158,7 @@ pgsql_test:
jstestserver:
cd bookie/static/js && $(WD)/$(PY) -m SimpleHTTPServer 9000
.PHONY: jstest
-jstest: test_api test_history test_model test_view test_indicator test_tagcontrol
+jstest: test_api test_history test_model test_rsswatch test_view test_indicator test_tagcontrol
.PHONY: jstest_index
jstest_index:
xdg-open http://127.0.0.1:6543/tests/index
@@ -177,6 +177,9 @@ test_model:
.PHONY: test_readable
test_readable:
xdg-open $(JSTESTURL)/test_readable.html
+.PHONY: test_rsswatch
+test_rsswatch:
+ xdg-open $(JSTESTURL)/test_rsswatch.html
.PHONY: test_tagcontrol
test_tagcontrol:
xdg-open $(JSTESTURL)/test_tagcontrol.html
View
101 bookie/static/js/bookie/rsswatch.js
@@ -0,0 +1,101 @@
+/**
+ * Keep up RSS feed link properties.
+ *
+ * RSS link needs to be kept up to date based on changes to the client side
+ * view. If a user filters on a tag, they'll want the rss feed to include that
+ * tag so that the feed matches what they're seeing in the list.
+ *
+ * @namespace bookie
+ * @module rsswatch
+ *
+ */
+YUI.add('bookie-rsswatch', function (Y) {
+ var ns = Y.namespace('bookie.rsswatch');
+
+ /**
+ * Helper function to bind up a single watcher to the page.
+ *
+ * @method bookie.rsswatch.watch
+ *
+ */
+ ns.watch = function () {
+ var watcher = ns.Updater();
+ watcher.bind();
+ };
+
+ /**
+ * Helper that watches over all powerful things to update RSS.
+ *
+ * @class RSSWatch.Updater
+ * @extends Y.base
+ *
+ */
+ ns.Updater = Y.Base.create('bookie-rsswatch-updater', Y.Base, [], {
+ /**
+ * Bind all events to monitor for changes effecting rss url.
+ *
+ * @method _bind_events
+ * @private
+ *
+ */
+ _bind_events: function () {
+ // Potential changes are tags and pagination
+
+ // We need to watch for a new event that the api should shout
+ // about what url was just loaded so that we can s/recent/rss it
+ // and update the rss feed.
+
+
+ // We need this for both the BmarksAll and UserBmarksAll
+
+ },
+
+ /**
+ * Given the data url generated, update it to the valid rss url.
+ *
+ * @method _generate_updated_url
+ * @param {String} data_url
+ * @private
+ *
+ */
+ _generate_updated_url: function (data_url) {
+ var updated_url = data_url.replace('recent', 'rss'),
+ },
+
+ /**
+ * Given the api url just hit, update the rss link to match.
+ *
+ * This is the method the events call to perform the update.
+ *
+ * @method _update_url
+ * @param {String} api_url
+ * @private
+ *
+ */
+ _update_url: function (api_url) {
+ var link = this.get('rss_link');
+
+ if (!link) {
+ console.error('missing rss link');
+ } else {
+ link.setAttribute('href', this._generate_updated_url(api_url));
+ }
+ },
+
+ initializer: function (cfg) {
+ this._bind_events();
+ }
+
+ }, {
+ ATTRS: {
+ rss_link: {
+ valueFn: function (val) {
+ return Y.one('#rss_url');
+ }
+ }
+ }
+ });
+
+
+
+});
View
31 bookie/static/js/tests/test_rsswatch.html
@@ -0,0 +1,31 @@
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <script src="../build/y/yui/yui.js"></script>
+ <script src="../bookie/rsswatch.js"></script>
+ <title>RSS Watch Tests</title>
+</head>
+<body class="yui3-skin-sam">
+ <div id="container"></div>
+ <div id="log"></div>
+ <script src="test_rsswatch.js"></script>
+
+ <script type="text/javascript">
+ YUI().use('test-console', 'test', 'bookie-test-rsswatch', function (Y) {
+ // RUN ALL THE TESTS!!!!!
+ var yconsole = new Y.Test.Console({
+ filters: {
+ pass: true,
+ fail: true
+ },
+ newestOnTop: false
+ });
+ yconsole.render('#log');
+
+ Y.Test.Runner.add(Y.bookie.test.rsswatch.suite);
+ Y.Test.Runner.run();
+ });
+ </script>
+</body>
+
+</html>
View
188 bookie/static/js/tests/test_rsswatch.js
@@ -0,0 +1,188 @@
+YUI.add('bookie-test-tagcontrol', function (Y) {
+ var ns = Y.namespace('bookie.test.tagcontrol'),
+ A = Y.Assert;
+
+ ns.suite = new Y.Test.Suite('Indicator Tests');
+
+ ns.suite.add(new Y.Test.Case({
+ name: "Init Tests",
+
+ setUp: function () {
+ Y.one('#container').appendChild(
+ Y.Node.create('<input/>')
+ );
+ },
+
+ tearDown: function () {
+ Y.one('#container').setContent('');
+
+ if (this.t) {
+ this.t.remove();
+ delete this.t;
+ }
+
+ if (this.tc) {
+ this.tc.destroy();
+ }
+ },
+
+ testViewExists: function () {
+ Y.Assert.isObject(Y.bookie.TagControl,
+ "Should find an object for TagControl");
+ },
+
+ test_view_attaches: function () {
+ // we want to send a required target node to create the widget
+ // against
+ this.t = Y.one('input');
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ Y.Assert.areEqual(this.t, this.tc.get('srcNode'),
+ 'The target node should be the one we sent it');
+ },
+
+ test_view_replaces: function () {
+ // we want to send a required target node to create the widget
+ // against
+ this.t = Y.one('input');
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc.render();
+
+ // now let's start checking out some things
+ Y.Assert.areEqual(1, Y.all('.yui3-bookie-tagcontrol').size());
+ Y.Assert.areEqual(1, Y.all('.yui3-bookie-tagcontrol-item').size());
+ Y.Assert.areEqual(1, Y.all('.yui3-bookie-tagcontrol-input').size());
+ },
+
+ test_view_add: function () {
+ // we want to send a required target node to create the widget
+ // against
+ this.t = Y.one('input');
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc.render();
+
+ // setup a new tag
+ var input = Y.one('.yui3-bookie-tagcontrol-input');
+ input.set('value', 'test');
+
+ input.simulate('keyup', {
+ keyCode: 32
+ });
+
+ // now let's start checking out some things
+ Y.Assert.areEqual(2, Y.all('.yui3-bookie-tagcontrol-item').size());
+ },
+
+ test_original_syncd: function () {
+ // make sure that as we add tags, the original input field is kept
+ // in sync with our list of tags
+ this.t = Y.one('input');
+ this.tc2 = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc2.render();
+
+ // setup a new tag
+ var input = Y.one('.yui3-bookie-tagcontrol-input');
+ input.set('value', 'test');
+ input.simulate('keyup', {
+ keyCode: 32
+ });
+
+ input.set('value', 'test2');
+ input.simulate('keyup', {
+ keyCode: 32
+ });
+
+ // check the value of the original input
+ Y.Assert.areEqual(
+ 'test test2',
+ this.t.get('value'),
+ "The input should have our two tags as values: " + this.t.get('value')
+ );
+ },
+
+ test_view_remove: function () {
+ // we want to send a required target node to create the widget
+ // against
+ this.t = Y.one('input');
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc.render();
+
+ // setup a new tag
+ var input = Y.one('.yui3-bookie-tagcontrol-input');
+ input.set('value', 'test');
+
+ input.simulate('keyup', {
+ keyCode: 32
+ });
+
+ // now let's fire the remove click on the tag
+ var tags = Y.all('.yui3-bookie-tagcontrol-item'),
+ fired = false;
+ tags.each(function (t) {
+ if (t.getContent() === 'test') {
+ t.simulate('click');
+ fired = true;
+ }
+ });
+
+ Y.Assert.isTrue(fired, 'Should have found our node');
+ // our node should be gone
+ Y.Assert.areEqual(1, Y.all('.yui3-bookie-tagcontrol-item').size());
+ Y.Assert.areEqual(0, this.tc.get('tags').length);
+ },
+
+ test_double_backspace: function () {
+ // Hitting delete on the last character removes the previous tag
+ this.t = Y.one('input');
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc.render();
+
+ // setup a new tag
+ var input = Y.one('.yui3-bookie-tagcontrol-input');
+ input.set('value', 'test');
+
+ input.simulate('keyup', {
+ keyCode: 32
+ });
+
+ // Now let's hit the backspace key and we should lose our new tag.
+ input.simulate('keydown', {
+ keyCode: 8
+ });
+
+ // our node should be gone
+ Y.Assert.areEqual(1, Y.all('.yui3-bookie-tagcontrol-item').size());
+ Y.Assert.areEqual(0, this.tc.get('tags').length);
+ },
+
+
+ test_initial_tags: function () {
+ this.t = Y.one('input');
+ this.t.set('value', 'test test2');
+
+ this.tc = new Y.bookie.TagControl({
+ srcNode: this.t
+ });
+ this.tc.render();
+
+ Y.Assert.areEqual(3, Y.all('.yui3-bookie-tagcontrol-item').size());
+ Y.Assert.areEqual(2, this.tc.get('tags').length);
+ }
+ }));
+
+}, '0.4', {
+ requires: [
+ 'test', 'node-event-simulate', 'bookie-tagcontrol'
+ ]
+});
View
2  bookie/templates/bmark/recent.mako
@@ -3,7 +3,7 @@
<%namespace file="rss.mako" import="rss_title"/>
<%def name="title()">Recent Bookmarks</%def>
<%def name="header()">
- <link href="${rss_url}" rel="alternate" title="${rss_title()}" type="application/rss+xml" />
+ <link id="rss_url" href="${rss_url}" rel="alternate" title="${rss_title()}" type="application/rss+xml" />
</%def>
<div class="bmarks"></div>
Please sign in to comment.
Something went wrong with that request. Please try again.