nmhive.git
9 years agobower.json: Mention bookmarklet and server in the description
W. Trevor King [Sun, 21 Sep 2014 17:04:56 +0000 (10:04 -0700)]
bower.json: Mention bookmarklet and server in the description

Nmbug is already distributed.  This project is just about providing an
interface for collaborators that don't have notmuch/nmbug locally.

9 years agonmbug.js: Fill in the POST /mid/<message_id> handling
W. Trevor King [Sun, 21 Sep 2014 13:41:39 +0000 (06:41 -0700)]
nmbug.js: Fill in the POST /mid/<message_id> handling

This is currently only (un)setting one tag per request.  If we want, a
later optimization could queue changes and push them all at once (e.g.
after a user pushes a submit button).  It would also be nice to update
the UI based on the list of returned tags, so we hear about changes
made by parallel parties.

9 years agonmhive.py: Accept Content-Type headers via CORS
W. Trevor King [Sun, 21 Sep 2014 13:30:45 +0000 (06:30 -0700)]
nmhive.py: Accept Content-Type headers via CORS

Using the suggested syntax [1] so I can POST from the bookmarklet.

[1]: https://pypi.python.org/pypi/Flask-Cors/1.9.0/#using-json-with-cors

9 years agonmbug.js: Add tag-toggling with a stub _toggle_tag
W. Trevor King [Sun, 21 Sep 2014 13:06:18 +0000 (06:06 -0700)]
nmbug.js: Add tag-toggling with a stub _toggle_tag

This takes care of binding the new method and adjusting the CSS.

9 years agonmbug.js: Add available-tags fetcher and highlight selected tags
W. Trevor King [Sun, 21 Sep 2014 12:48:25 +0000 (05:48 -0700)]
nmbug.js: Add available-tags fetcher and highlight selected tags

Instead of just listing selected tags, list all available tags (using
nmhive.py's new GET /tags).  Mark the selected tags with a background
color.

9 years agonmbug.js: Use bind to avoid forwarding message_id through _get_tags
W. Trevor King [Sun, 21 Sep 2014 12:35:05 +0000 (05:35 -0700)]
nmbug.js: Use bind to avoid forwarding message_id through _get_tags

Instead of telling _get_tags that the callback will always want the
message_id (in addition to the list of that message's tags), use bind
[1] to add that information when we set the _edit_tags callback.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

9 years agonmhive.py: Add GET /tags
W. Trevor King [Sun, 21 Sep 2014 12:22:56 +0000 (05:22 -0700)]
nmhive.py: Add GET /tags

We don't want bookmarklet users adding random tags.  Instead, restrict
them to tags that are already in the database, which allows us to keep
a consistent tag-set and present a simpler UI.  The hard-coded
_AVAILABLE_TAGS will be replaced by a notmuch query once I finish with
the UI.

9 years agonmbug.js: Style the dialog with some round corners and a shadow
W. Trevor King [Sun, 21 Sep 2014 12:09:55 +0000 (05:09 -0700)]
nmbug.js: Style the dialog with some round corners and a shadow

The CSS is from Eiji Kitamura's demo [1].  I'm inlining the CSS here
to avoid more dynamic-loading shenanigans like we needed for the
dialog polyfill.  I don't expect this CSS will grow much larger
anyway.

[1]: http://demo.agektmr.com/dialog/#styling

9 years agonmbug.js: Add dialog-polyfill dependency for Firefox
W. Trevor King [Sat, 20 Sep 2014 23:52:38 +0000 (16:52 -0700)]
nmbug.js: Add dialog-polyfill dependency for Firefox

It looks like Firefox doesn't support the <dialog> element yet [1,2],
so this commit dynamically loads the polyfill replacement [3].  Since
the polyfill files load asynchronously, I need to use onload to decide
when they've all made it down (setting the async property to false
didn't seem to work).

[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
[2]: https://bugzilla.mozilla.org/show_bug.cgi?id=840640
[3]: https://github.com/GoogleChrome/dialog-polyfill

9 years agobower.json: Add boilerplate so I can serve static dependencies
W. Trevor King [Sat, 20 Sep 2014 23:07:12 +0000 (16:07 -0700)]
bower.json: Add boilerplate so I can serve static dependencies

It looks like Firefox doesn't support the <dialog> element yet [1,2],
so I'll need the polyfill replacement.  This commit puts the generic
boilerplate in place, so we can revert just the dialog polyfill later,
while leaving this boilerplate in place for other dependencies.

[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
[2]: https://bugzilla.mozilla.org/show_bug.cgi?id=840640

9 years agonmbug.js: Stub out a dialog for editing tags
W. Trevor King [Sat, 20 Sep 2014 22:32:38 +0000 (15:32 -0700)]
nmbug.js: Stub out a dialog for editing tags

It lists the associated Message-ID and tags, but I haven't added
JavaScript to support editing the tag list yet.  I'm using the
<dialog> element [1] to float this dialog over the launching page
(e.g. Gmane), so we don't have to worry about mucking with whatever's
going on there ;).

[1]: https://html.spec.whatwg.org/multipage/forms.html#the-dialog-element

9 years agonmbug.js: Fill in the tag-fetching portion of nmbug.show
W. Trevor King [Sat, 20 Sep 2014 21:17:55 +0000 (14:17 -0700)]
nmbug.js: Fill in the tag-fetching portion of nmbug.show

Ask nmhive for the tags associated with the given Message-ID.

I've also used bind [1] so that the nmbug.show callback get's called
with this pointing to the nmbug object.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

9 years agonmhive.py: Add GET/POST /mid/<message_id>
W. Trevor King [Sat, 20 Sep 2014 20:17:50 +0000 (13:17 -0700)]
nmhive.py: Add GET/POST /mid/<message_id>

So the bookmarklet can get and set tags on a given message.  This
currently just uses an in-memory store, but eventually we'll drop
notmuch in on the backend.

9 years agoindex.html: Avoid interpreting nmbug.js as text/xml
W. Trevor King [Sat, 20 Sep 2014 19:35:23 +0000 (12:35 -0700)]
index.html: Avoid interpreting nmbug.js as text/xml

When loaded from file:///.../index.html, Firefox seems to assume
nmbug.js is text/xml.  If you're serving nmbug.js from an actual
server, this shouldn't be a problem, but the explicit override makes
local testing easier.

9 years agoindex.html: Supply nmbug.js as a bookmarklet
W. Trevor King [Sat, 20 Sep 2014 18:46:55 +0000 (11:46 -0700)]
index.html: Supply nmbug.js as a bookmarklet

Distribute the bookmarklet as a link, so folks can just drag it up
onto their bookmark toolbar.

We're trying to avoid external dependencies, so I don't want to force
folks to load nmbug.js whenever they run the bookmarklet.  Instead,
load_bookmarklet fetches nmbug.js, adds a bit of wrapping code to
create the bookmarklet, and injects that as the nmbug link's href.

9 years agonmbug.js: Extract the Gmane article id and convert to a Message-ID
W. Trevor King [Sat, 20 Sep 2014 20:00:23 +0000 (13:00 -0700)]
nmbug.js: Extract the Gmane article id and convert to a Message-ID

Using some JavaScript gymnastics to look through the available frames
for an article.gmane.org/ URL.  For example, we might be on a page
like:

  http://thread.gmane.org/gmane.mail.notmuch.general/19055/focus=19056

which is composed of the following frames [1]:

  http://news.gmane.org/group/gmane.mail.notmuch.general/thread=19055/force_load=t/focus=19056
  http://article.gmane.org/gmane.mail.notmuch.general/19056
  http://news.gmane.org/navbar.php?group=gmane.mail.notmuch.general&article=19056&next=19057&prev=19054&newsrc=,19056

Or we might be on the article page directly.  There are also permalink
pages (with 'permalink' instead of 'article' available from the
blog-link view), but I'm not worrying about them yet.

[1]: for (var i = 0; i < window.frames.length; i++) {
       console.log(window.frames[i].document.URL);
     }

9 years agonmhive.py: Add GET /gmane/<group>/<int:article>
W. Trevor King [Sat, 20 Sep 2014 19:51:37 +0000 (12:51 -0700)]
nmhive.py: Add GET /gmane/<group>/<int:article>

Gmane's download endpoint [1] doesn't allow cross-origin requests, and
article.gmane.org -> download.gmane.org is a cross-origin request [2].
Work around that with this proxy endpoint, which uses Flask-Cors [3]
to accept all origins.  The bookmarklet can figure out the current
message's group and article id, and hit this endpoint.  Then nmhive
will use Gmane's download endpoint to fetch the message as an mbox,
after which we can use Python's stdlib to extract the Message-ID from
the mbox, and return the extracted Message-ID to the bookmarklet.

Later on we can also add local caching and rate-limiting here, so we
don't bother Gmane more than necessary (the downloads are somewhat
expensive [1]).

[1]: http://gmane.org/export.php
[2]: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Definition_of_an_origin
[3]: https://pypi.python.org/pypi/Flask-Cors/

9 years agonmbug.js: Sketch out the bookmarklet framework
W. Trevor King [Sat, 20 Sep 2014 18:46:37 +0000 (11:46 -0700)]
nmbug.js: Sketch out the bookmarklet framework

We'll have a generic nmbug.show() to handle the UI for tagging a given
message (using its Message-ID).  To get that Message-ID, we'll have a
list of potential handlers.  When the bookmarklet fires (run()), we'll
iterate through the handlers unril handler.regexp matches
document.URL.  For the first match, we'll run handler.handle, which
will do whatever it needs to figure out the Message-ID, and then
launch nmbug.show (passed in via 'callback') with the extracted id.

9 years agoREADME.rst: Start outlining the project
W. Trevor King [Sat, 20 Sep 2014 18:42:49 +0000 (11:42 -0700)]
README.rst: Start outlining the project