Problem/Motivation

Make a smoother workflow for adding and editing issue summaries by allowing the user to insert the issue summary template.

Proposed resolution

Provide a button through dreditor for prepend the template from http://drupal.org/node/1155816 into the Issue node body. See image:

A patch to add this button is available in #51 . To test, save dreditor locally (right-click/save as), apply the patch, and then open the patched copy in your browser. The patch has been tested in both Chrome and Firefox.

Remaining tasks

  • Revised patch in #51 needs review.
  • Some users may wish to automatically insert the template on node creation, so dreditor could provide that option as well.
  • The fetched page is not cached. A cache is done through #1115636: Issue Macros and Templates

User interface changes

An "Insert template" button appears next to the "Description" label on node add and edit forms, including in the issue summary inline editor. Clicking this button inserts the issue summary headers at the top of the issue summary body field.

On node edit forms, the final "original report" header automatically includes the original poster's name and profile link.

On node add forms, the "original report" header is omitted.

CommentFileSizeAuthor
#73 Screen Shot 2013-08-11 at 12.58.47 AM.png37.74 KBmarkhalliwell
#73 Screen Shot 2013-08-11 at 1.41.49 AM.png51.97 KBmarkhalliwell
#73 interdiff.txt6.94 KBmarkhalliwell
#88 dreditor-button-to-prepend-1277974-88.patch3.96 KBcweagans
#88 interdiff.txt2.35 KBcweagans
#86 dreditor-button-to-prepend-1277974-86.patch3.94 KBmarkhalliwell
#86 interdiff.txt2.11 KBmarkhalliwell
#81 dreditor-button-to-prepend-1277974-81.patch3.94 KBmarkhalliwell
#81 interdiff.txt2.37 KBmarkhalliwell
#80 dreditor-button-to-prepend-1277974-80.patch6.07 KBmarkhalliwell
#80 interdiff.txt1.07 KBmarkhalliwell
#79 dreditor-button-to-prepend-1277974-79.patch6.03 KBmarkhalliwell
#79 interdiff.txt616 bytesmarkhalliwell
#78 dreditor-button-to-prepend-1277974-77.patch6.03 KBmarkhalliwell
#78 interdiff.txt1.55 KBmarkhalliwell
#77 interdiff.txt8 KBmarkhalliwell
#76 dreditor-button-to-prepend-1277974-76.patch5.95 KBmarkhalliwell
#72 dreditor-button-to-prepend-1277974-72.patch5.72 KBmarkhalliwell
#70 dreditor-1277974-70.patch3.58 KBstar-szr
#70 interdiff.txt2.35 KBstar-szr
#68 dups-dreditor-sum.png183.1 KByesct
#67 dreditor-button-to-prepend-1277974-67.patch3.85 KBmarkhalliwell
#67 interdiff.txt1.04 KBmarkhalliwell
#60 dreditor-1277974-60.patch3.4 KBxjm
#60 interdiff-55-60.txt2.14 KBxjm
#55 dreditor-1277974-55.patch3.19 KBxjm
#51 dreditor-1277974-51.patch3.04 KBxjm
#48 dreditor-1277974-48.patch3.02 KBxjm
#47 dreditor-1277974-46.patch3.71 KBxjm
#45 inline-editor.png8.92 KBxjm
#44 issue-summary-link.png20.24 KBxjm
#38 template_button.png17.21 KBxjm
#36 dreditor-1277974-36.patch3.28 KBxjm
#36 interdiff-32-36.txt4.09 KBxjm
#32 dreditor-1277974-32.patch4 KBclemens.tolboom
#32 Button to prepend the _Issue summary standard_ template into Issue body. | drupal.org_.png17.21 KBclemens.tolboom
#31 interdiff-21-25.patch5.28 KBxjm
#25 template_button-1277974-25.patch4.02 KBxjm
#21 dreditor-1277974-21.patch2.37 KBclemens.tolboom
#19 template_button-1277974-19.patch3.74 KBxjm
#16 issue_summary_button-1277974-16.patch3.74 KBxjm
#14 insert_template_final-er.patch2.33 KBxjm
#13 insert_template_final.patch2.33 KBxjm
#10 issue_summary_template.patch2.14 KBxjm
#5 dreditor-inject-template-1277974-5.patch1.66 KBclemens.tolboom
#4 dreditor-inject-template-1277974-4.patch1.76 KBclemens.tolboom
#1 dreditor-inject-template-1277974-1.patch1.76 KBclemens.tolboom

Comments

clemens.tolboom’s picture

StatusFileSize
new1.76 KB

The patch does two things

1. Inject the template for new Issues
2. Add button to append to existing issues.

clemens.tolboom’s picture

Status: Active » Needs review

Please review the patch and try to make it better on the points mentioned below:

+++ b/dreditor.user.js
@@ -1359,6 +1359,51 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+  // TODO: autoinject template?
+  $('body.logged-in.page-node div.project-issue #edit-body').once('dreditorIssueAdd', function() {
+    if ($('#edit-body').text() == '') {
+      injectTemplate();
+    };

Do we want this auto inject for New Issues?

Can we configure this behaviour through dreditor config somehow?

+++ b/dreditor.user.js
@@ -1359,6 +1359,51 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    // Make it a commandbutton
+    $action.wrap('<div class="dreditor-actions"></div>');

The button comes below the label which is not nice. How do this better?

clemens.tolboom’s picture

Status: Needs review » Needs work
+++ b/dreditor.user.js
@@ -1359,6 +1359,51 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+      text = text.replace(/<h3/g, "\n\n<h3").replace(/<\/h3>/g, "<h3>\n\n");

It misses the close h3

clemens.tolboom’s picture

Issue summary: View changes

Used the patch to see it in action.

clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.76 KB

Fixed #3

Open issues from #4
- auto-inject for new issues: yes or no?
- button for existing issue edit is located ugly. [edit]Use dreditor-button class and wrap with span[/edit]

Others
- there is no cache ... implemented in #1115636: Issue Macros and Templates
- do we have to display an error if the GET fails?

clemens.tolboom’s picture

StatusFileSize
new1.66 KB

I misused the .text(). Now use .val(). This caused weird errs in both FF and Chrome.

Changed to dreditor-button class.

Open issues:
- auto inject for node/add issue.
- there is no cache used for the template

clemens.tolboom’s picture

Issue summary: View changes

Added XREF to template

clemens.tolboom’s picture

It is a little annoying indeed to have the template on every _new_ issue. On the other hand deleting is easy.

Adding a template to an existing issue should be placed _before_ the existing text. That makes it easy to remain the original text.

See the current version in action on http://drupal.org/sandbox/clemenstolboom/1125712

clemens.tolboom’s picture

Issue summary: View changes

Removed remaining task 'white lines'

clemens.tolboom’s picture

Title: Insert the 'Issue summary standard' template into Issue body. » Button to prepend the 'Issue summary standard' template into Issue body.

I changed append to prepend with is a little smoother workflow.

clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

helmo’s picture

* The summary-original-report section is not relevant when creating a new issue.

* I don't really like that the template is automatically added for new issues.

--
just my 2 cents

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
Status: Needs review » Needs work

There is just one template available for the issue summary. I don't want to fiddle with that.

There should be an option the disable the insertion automatic. I'll work on that.

xjm’s picture

Status: Needs review » Needs work
StatusFileSize
new2.14 KB

Okay I totally didn't find this issue and hacked it up myself, but here's my version of this functionality. It's probably kinda gross (rather than looking up the template, I just stuck it in an escaped string of barf), but worth a look for comparison? It scrapes for the original poster's username and automatically inserts a profile link; kinda nice.

I don't bother inserting the template in new issues. You can create an issue with a blank body and then just click the edit link. Alternately, could just add the button on the node add form as well.

xjm’s picture

Status: Needs work » Needs review
xjm’s picture

Assigned: clemens.tolboom » xjm
Status: Needs work » Needs review

I'll work on incorporating @clemens.tolboom's functionality into my patch, plus adding buttons to the normal add/edit pages, without the final header on add pages.

I think this functionality is pretty important. I started to write up a slideshow about contributing summaries today and realized the current workflow is actually stupid-complicated. I'd rather be able to say "install dreditor." :)

xjm’s picture

StatusFileSize
new2.33 KB

Much nicer patch parsing from the actual document as in @clemens.tolboom's version. Try it out! The button adds the "original report by" header with a link to the original poster on edit, but on add, it just inputs the other headers. It doesn't do it automatically.

It also doesn't insert the notes in parentheses. If you're using dreditor, you are experienced enough to read the doc or figure it out on your own. :)

I did notice the GET requests are kinda slow sometimes. We might want to cache the template markup somehow. For now, though, I think this is a whole lot better. :)

Edit: aside from the hunk of trailing whitespace. sorry. I'll fix that.

xjm’s picture

StatusFileSize
new2.33 KB

W/o gross whitespace.

xjm’s picture

+++ b/dreditor.user.jsundefined
@@ -1360,6 +1360,65 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+  $('body.logged-in.page-node.node-type-project-issue #edit-body').once('dreditorIssueTemplate', function() {
+      addTemplateButton(1);
+  });
+
+  $('body.logged-in.page-node div.project-issue #edit-body').once('dreditorIssueTemplate', function() {
+    addTemplateButton(0);
+  });

It occurs to me a couple inline comments explaining what's going on here might be helpful, but I'll wait to see what others say about the patch as a whole. :)

how i can computer? why is blue? views? modules? wtf?

xjm’s picture

StatusFileSize
new3.74 KB

With reasonable code documentation.

xjm’s picture

Issue summary: View changes

Changed the injection to prepend instead of append.
Added XRef to sandbox and quick install.

xjm’s picture

Issue summary: View changes

(xjm) Described status with current patch in #16.

clemens.tolboom’s picture

@xjm Darns ... sorry.

I'll update the issue summary ... I have a dreditor sandbox for this :(

http://drupal.org/sandbox/clemenstolboom/1125712

I like your add_form _with argument

clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

I looked; I don't see my patch in your sandbox? And I'd checked earlier and the last commit was back before your remark in #9. So I added that note to the summary as well... please clarify.

Please give the patch a try; it's fully functional. :)

xjm’s picture

StatusFileSize
new3.74 KB

Mmm, just touching up funky indentation. (I think? jQuery indentation gives me brain freeze, and it's not even yummy like ice cream.)

xjm’s picture

Issue summary: View changes

#16 is not in the sandbox?

clemens.tolboom’s picture

Status: Needs review » Needs work
+++ b/dreditor.user.js
@@ -1360,6 +1360,99 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+      // Insert blank lines and strip parenthetical comments.
+      text = text.replace(/<\/h3>/g, "</h3>\n\n\n").replace(/\(.*\)/g, "").replace(/\/\/.*\./,"");

These comments helps me to know what to do.

I don't want to remove these.

+++ b/dreditor.user.js
@@ -1360,6 +1360,99 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+  var addTemplateButton = function(edit_form) {

I left out the add/edit flag ... when there is no text it's a new issue right?

Committed to my sandbox

clemens.tolboom’s picture

clemens.tolboom’s picture

@xjm: your insertion of the user name is very nice :-)

What now remains is the checkbox for not always inject on new issues as requested by helmo. Or did I missed something from you patch (which I applied by hand ... sorry for that)

clemens.tolboom’s picture

And we should add a link to the template page for more instructions I guess.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

#22 / #23 -- I removed the feature to automatically insert on new node creation because people above stated that it was annoying, and I'd agree with them; and it takes no additional effort to just click the button. Also, I disagree entirely about the parenthetical instructions, for two reasons:

  1. People who use dreditor are savvy enough to learn what to put in each section if they don't know, and it's just an extra annoyance to delete them each time.
  2. In my experience in mentoring summary contributors, people tend to leave the parenthetical instructions in and I have to keep telling contributors to delete them.

I guess I did not mean this as a patch against your sandbox, which I gather is something of a feature fork of dreditor; I meant it for inclusion in the main script.

I do think adding a link to the template after the button is a good idea and I will reroll #19 to that end.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB

Please test against the main branch of dreditor. Let's wait for a third opinion on whether or not the parenthetical lines are included, etc.

clemens.tolboom’s picture

Please reroll against #21 (I'm not doing this for fun ;-)

clemens.tolboom’s picture

Status: Needs review » Needs work

See #26 for needs work.

Patch #21 is against dreditor master branch :-)

I do agree with removing the the comments when we have the link available.

xjm’s picture

But #21 is missing all my comment cleanup and my change to the once() behavior? My patch was already based on your earlier patch.

Edit: I really don't understand; my patch applies cleanly, and is essentially the same thing as #21 but refined. It works without a hitch in my testing and it's easy to read and follow.

What is needs work here? What is not correct about the patch? Do you have any specific patch review? Did you test it?

clemens.tolboom’s picture

Status: Needs work » Needs review

@xjm ... rerolling not against the lastest patch #21 is imho rude. I tried to add your parts from #19 to my work and review #20 so expected the same from you :(

I set status to needs review as your additions are great.

xjm’s picture

I'm very sorry; I don't intend to be rude... what I don't understand is that #21 discarded all the changes I'd made in #13 through #19, without any explanation as to why they were discarded. I'm not sure how that's different? Like I said, I already started from your patch earlier in the issue.

xjm’s picture

StatusFileSize
new5.28 KB

Had a possible insight a moment ago... Are you just asking for this?

Edit: If you want, I can explain each "change" as well (though all except the insert template link are changes that you discarded from #21). Like I said in the message I left in IRC, I think we're just not quite communicating. Please just explain what you are asking for. :)

clemens.tolboom’s picture

clemens.tolboom’s picture

Status: Needs review » Needs work
+++ b/dreditor.user.js
@@ -1360,6 +1360,107 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+  var injectTemplate = function(edit_form) {
+    // Load the issue summary instructions.

We could replace this argument by just testing for emptyness of the issue body right?

Or change the name to a boolean isNew

clemens.tolboom’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

We could replace this argument by just testing for emptyness of the issue body right?

Or change the name to a boolean isNew

Hm, well, the issue body could be empty when you are updating it, or could already have things in it when it is new, but we still don't want it to try to load the node page if it doesn't exist yet. So I think the boolean option is better.

xjm’s picture

Though, I wonder if maybe we should just check the current URL for node/add/project-issue. It might also be cleaner to parse the issue link from the URL rather than looking for the view tab.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new4.09 KB
new3.28 KB

Attached patch simply checks the URL for whether we are adding or editing and for the link to the node page. I think this is more robust than relying on the DOM, and probably more performant as well. The code is also a lot simpler.

xjm’s picture

Assigned: xjm » Unassigned
xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

StatusFileSize
new17.21 KB

Mmm, the image filter is not liking the screeshot for me, so here it is again.

xjm’s picture

Issue summary: View changes

Adding screenshot.

xjm’s picture

Issue summary: View changes

Updated issue summary.

amateescu’s picture

I tried out the patched Dreditor and it works as advertised, in the summary Edit popup and also in node add/edit forms. Great work :)

Unrelated: the Edit popup could use a close button!

cweagans’s picture

Status: Needs review » Reviewed & tested by the community

Patched code works as advertised.

Code looks solid (though it'll need to be updated quickly if the issue summary template page ever gets reorganized or something - it might be better to edit that page and add a really unique class name to the code block and find it based on the class).

I'd say that's probably of minimal concern though. I'd also say RTBC :)

cweagans’s picture

Issue summary: View changes

Updated issue summary.

sun’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+Drupal.behaviors.dreditorIssueAddEdit = function(context) {

1) dreditorIssueSummaryTemplate

2) [and elsewhere] There should be a space after function and before the opening parenthesis for anonymous functions to make clear that it's not a function with the name function.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+   * Fetches the node to retrieve the original poster's name and profile link.
...
+    // Try to find a path to the node from the URL.
+    var node_path = location.href.match(/^.*node\/[0-9]*/);

It's not clear to me why we need to reload the node view page.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+  var getPoster = function() {
...
+  var injectTemplate = function() {
...
+  var addTemplateButton = function() {

Abstraction into private/locally defined anonymous functions like this doesn't really make sense. They are not callable from elsewhere. And since they don't take any arguments, they also don't really provide atomic functionality. At minimum, they should take context as an argument; but to make any sense as separate functions, they should take explicit arguments to act on and also possibly return something useful.

In this current form, these functions are merely wrapping chunks of procedural code into code blocks without any purpose, which actually makes it harder to understand what's going on.

Either we turn them into real functions with proper arguments and possibly return values, or we drop them entirely. Personally, I'd rather go with the latter.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+        var link = $(data).find('div.node > div.submitted a');
...
+        var new_link = '<a href="' + link.attr('href') + '">' + link.text() + '</a>';

1) [and elsewhere] Variables that are jQuery objects should have a $ prefix; i.e., $link in this case. All other variables without; e.g., $new_link in this case.

2) For the link text, we want to use .html() instead of .text(), because we are inserting the value back into a HTML document.

3) [and elsewhere] The variable names could be a bit more self-descriptive than "link" and "new_link".

4) [and elsewhere] In JavaScript, we use camelCase variable names.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    // Load the issue summary instructions.
+    $.get('http://drupal.org/node/1155816', function(data) {

I wonder whether we can prevent jQuery from sending cookies, so we get the cached version of that page?

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+      // Insert blank lines and strip parenthetical comments.
+      text = text.replace(/<\/h3>/g, "</h3>\n\n\n").replace(/\(.*\)/g, "").replace(/\/\/.*\./,"");

Would it be possible to have an already prepared issue summary template for pasting on that handbook page or a child page of it?

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    // We want to append the button in the label area.
+    var $label = $('label[for="edit-body"]');

This is going to clash with the commit message button, no?

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+      .text("Insert template")
...
+      .text("Issue summary standards");

Single quotes.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    $action.wrap('<span>&nbsp;&nbsp;</span>');

Wondering whether this is really needed? Thought there were generic CSS classes for aligning Dreditor buttons... but not sure.

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    // Add a link to view the issue summary instructions.

It's not clear to me why we're adding this link to the instructions... doesn't that exist already?

+++ b/dreditor.user.js
@@ -1360,6 +1360,94 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    var $instructions = $('<a>')
+      .attr('href', 'http://drupal.org/node/1155816')

1) I think we can simply define the attributes and link text in the HTML string instead of working on the object.

2) target=_blank might make sense, as we don't want to lose potentially existing input.

xjm’s picture

Assigned: Unassigned » xjm

Yay, thanks for the review! Couple followups to #41:

It's not clear to me why we need to reload the node view page.

This was to scrape the username and profile link for the original poster. This information isn't available on the node edit tab that I could see. Is there a better way to get it?

Would it be possible to have an already prepared issue summary template for pasting on that handbook page or a child page of it?

This is a good point; I'll look into this.

This is going to clash with the commit message button, no?

I don't think so? I'm running my patched version currently, and both the template button and the commit message button seem to work fine. Also, one is on the comment form, whereas the other is on the node edit form.

Wondering whether this is really needed? Thought there were generic CSS classes for aligning Dreditor buttons... but not sure.

I was wondering that as well. I'll try removing it and see if anything breaks.

It's not clear to me why we're adding this link to the instructions... doesn't that exist already?

It's only available on the normal node edit page (and not in the inline editor). It's also kind of hard to see on the normal node add/edit page; we are moving it to a more obvious/intuitive spot. See screenshot:

I'll reroll the patch with the other cleanups from #41.

sun’s picture

IIRC, the dreditorIssueSummary "inline editor" behavior explicitly hides the dsm() that contains the link to the issue summary instructions. We might want to reconsider that.

xjm’s picture

StatusFileSize
new20.24 KB

Here is what the node edit tab looks like. The links indicated by red arrows are to the same page:

issue-summary-link.png

I don't think we want the whole huge blue box on the inline editor. On the other hand, would it be better to clone the existing link? We're hardcoding the path anyway to fetch the template. I do think the text change to "Issue summary standards" makes more sense here, since the document includes more than just the template itself and it's right next tot the template button.

xjm’s picture

StatusFileSize
new8.92 KB

For comparison, the inline editor with the current patch:
inline-editor.png

xjm’s picture

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

Alright, I think I've got all the feedback from #41 covered here. Attached:

  • Still adds a static link to the issue summary instructions, but makes it open in a new window/tab with target="_blank".
  • Still wraps the button with a span. Without this, it was scrunched up against the label text. (I guess an alternative would be to add a little margin or padding to the button CSS, or perhaps there's some better existing CSS to use that I'm not aware of.)
  • Refactors to remove the named lambdas.
  • Uses http://drupal.org/node/1326662 to fetch "bare" versions of the template. (Thanks davereid for super cow power help.)
  • Cleans up code style and variable naming according to the points in #41.
xjm’s picture

StatusFileSize
new3.02 KB

Er. Ignore that last patch; it's against a previous commit rather than the main branch. This one. :)

clemens.tolboom’s picture

Please make note of #1287934: The book pages need a prefix to distinguise them from eg the real project. where jhodson want to distinguish user pages versus machine readable d.o pages.

xjm’s picture

Status: Needs review » Needs work

#49: Well, the page is also useful for people not using dreditor who don't want to have to remove the comments each time, so it is human-readable.

I changed the markup of the page to be less ugly. However, at some point in cleaning up the code, I broke the user name insertion. Debugging that now.

xjm’s picture

StatusFileSize
new3.04 KB

2) For the link text, we want to use .html() instead of .text(), because we are inserting the value back into a HTML document.

Ah, this was not actually the case (the link markup is being inserted into the input field).

Attached reverts that change so the link markup is inserted and uses the corrected template markup.

I did a bit of reading to see if it were possible to have $.get() not send cookies, but the only suggestions I found were server-side solutions. I don't know much about it, though.

xjm’s picture

Assigned: xjm » Unassigned
Status: Needs work » Needs review
xjm’s picture

Issue summary: View changes

Removed sandbox ref as I cannot follow the speed this patch goes :-) by clemens.tolboom

xjm’s picture

Status: Needs review » Needs work
+++ b/dreditor.user.jsundefined
@@ -1360,6 +1360,77 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+    // Add a link to view the issue summary instructions.
+    var $instructions = $('<a href="http://drupal.org/node/1155816" target="_blank">Issue summary standards</a>')
+    .appendTo($label);
+    $instructions.before('(');
+    $instructions.after(')');

tim.plunkett reviewed this for me in IRC. The indentation here is off, and this could probably all be chained in one go.

Revised edit: The patch has a bug with a variable that was not renamed properly, and furthermore has an issue due to the refactoring where the [username] token does not get replaced because the GET request finishes too late. Looking into this.

xjm’s picture

Assigned: Unassigned » xjm

Also checking to see if it would be better to use .load().

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.19 KB

Attached resolves the issues described in #53 and also refactors a little to remove more superfluous variable declarations. I also got rid of the extra markup and &nbsp; and am just adding a small margin to the button instead. I did check through the dreditor styles available but there didn't seem to be one that fit.

das-peter’s picture

Review of #55:
patch applies, button shows up (Win 7, FF 7), and template is inserted.
Further to me the code looks nice - chaining used, just a few new variables and docs all over the place :)

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Same review as #56 (Win 7, FF 7) and everything looks good, from functionality to code style.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Updated http://drupal.org/node/1326662 with some suggestions from sun; rolling the changes into a new patch now.

xjm’s picture

#112805: JSON menu callback for project issues would significantly reduce the overhead of this functionality.

xjm’s picture

Status: Needs work » Needs review
StatusFileSize
new2.14 KB
new3.4 KB

Attached uses the new template.

Once #112805: JSON menu callback for project issues is fixed, I think it would be best to add the issue JSON data to Drupal.dreditor generally. Then we can fix this feature to use that data instead.

clemens.tolboom’s picture

Status: Needs review » Needs work
+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+          $templateText = $(data).find('div#summary-template > div > code').text();

Better add a .first() here? Like $(data).find('div#summary-template > div > code').first().text()

+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+            // Fall back to simply "Original report" for the header text.

This fallback is never happening as the $.get has no failure flow.

xjm’s picture

Better add a .first() here? Like $(data).find('div#summary-template > div > code').first().text()

Are you sure that isn't just adding overhead? There won't be multiple instances of this.

This fallback is never happening as the $.get has no failure flow.

Eh? This text will be used if the original node cannot be found by matching the path. See:

+++ b/dreditor.user.jsundefined
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+            // Fall back to simply "Original report" for the header text.
+            var profileLinkMarkup = '';
+
+            // To find the original poster, try to find a path to the node
+            // from the URL.  We do this now rather than when adding the
+            // original report header because retrieving the profile link can
+            // be slow, so we want that to happen asynchronously.
+            // @see http://drupal.org/node/112805
+            var nodePath = location.href.match(/^.*node\/[0-9]*/);
+            if (nodePath) {
clemens.tolboom’s picture

Are you sure that isn't just adding overhead? There won't be multiple instances of this.

Yes it is overhead when using .first() ... but it's a better 'statement' ... give me the first code block. It's np to me when not added.

For the happy flow part. I expected something

if (nodePath) {
  ...
  $.get() {
  }
}
else {
  $('#edit-body').val($('#edit-body').val().replace(/by \[username\]/, ''));
}

According to http://api.jquery.com/jQuery.get/ there is no error flow for $.get so you should either use http://api.jquery.com/jQuery.ajax/ with an error callback or rephrase the documentation into 'Only replace when succesful'. This

+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+            // Fall back to simply "Original report" for the header text.

fallback is not in the code flow.

+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+            if (nodePath) {

Failure on nodePath has no replace action

+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+              $.get(nodePath[0], function (data) {

Failed on $.get has no replace action

+++ b/dreditor.user.js
@@ -1360,6 +1360,85 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+                profileLinkMarkup = 'by <a href="' + $profileLink.attr('href') + '">' + $profileLink.text() + '</a>';
+                $('#edit-body').val($('#edit-body').val().replace(/by \[username\]/, profileLinkMarkup));

This replace is only executed when the nodePath is found and $.get successful.

clemens.tolboom’s picture

This could use some love again :)

xjm’s picture

Assigned: xjm » Unassigned

I don't know how to address the reviews above (which is why I gave up on this and instead just used my patch locally), so if you or anyone who groks JS better wants to fix it that would be awesome. :)

yesct’s picture

#1803622: Add a create follow-up issue link which fills in values (clone an issue) just a little related.

This issue could use some love.

markhalliwell’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB
new3.85 KB

Ok the button at least works now. I didn't dig in too deep, so let me know what else needs to get worked on or if this is RTBC.

yesct’s picture

Status: Needs review » Needs work
StatusFileSize
new183.1 KB

I tried this, it's really neat.

but it has two lines trying to get who has posted the original description.

dups-dreditor-sum.png

<h3 id="summary-original-report">Original report by <a href="undefined"></a></h3>

<h3 id="summary-original-report">Original report by [username]</h3>

---
the instructions link opens in another window superly to https://drupal.org/node/1155816
I wonder if we want to use https://drupal.org/issue-summaries though

star-szr’s picture

Assigned: Unassigned » star-szr

Working on this a bit to see if I can improve it.

star-szr’s picture

Assigned: star-szr » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.35 KB
new3.58 KB

Updated based on feedback and review from @YesCT!

  • Addressed the duplicate "Original report by" - now the Original report by gets stripped out on the node/add page instead of another one being added.
  • Addressed the possibility of getting <a href="undefined"></a> - I used https://drupal.org/node/1797364 for testing before and after.
  • Updated the issue summary standards link to use the aliased URL.
  • Bonus: updated one String.replace() to use a string instead of a RegEx. We only have one to replace and this is faster and easier to read. Ref. http://jsperf.com/string-replace-regexp-vs-string for speed claims.
star-szr’s picture

Tested in Chrome 28 and Firefox 23:

  • Node add form
  • Node edit form
  • Dreditor issue summary edit popover thinger
markhalliwell’s picture

Ok. I refactored a lot of this code to utilize jQuery DOM manipulation and targeting tag IDs instead of raw strings. This will allow more flexiblility if the template gets updated in the future. I also added a warning on the bare issue summary template's edit page to inform anyone (that has dreditor) that a new issue window will appear so a proper review can be done. I'll attach screenshots shortly

markhalliwell’s picture

Status: Fixed » Needs review
StatusFileSize
new6.94 KB
new51.97 KB
new37.74 KB

Here's the interdiff between #70 -> #72. Guess it eaten by the diff monster :-/

edit: removed images since this implementation wasn't committed.

star-szr’s picture

Status: Needs review » Needs work

First of all, you made this much faster @Mark Carver! Very nice. When I was testing #70 it took several seconds to fill in and even longer to fetch the username. I reviewed and tested the patch (other than the automatic new issue thing), here are some comments:

  1. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    + * Adds a button to insert the issue summary template.
    + */
    +Drupal.behaviors.dreditorIssueSummaryTemplate = function (context) {
    +
    +  // Show a warning on the bare issue summary template edit page.
    

    Should the warning on editing the template be in a different behavior?

  2. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +                $doc.find('#edit-assigned').val('501638');
    

    This won't always work (most people won't be able to assign to you) but that's probably okay?

  3. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +  }
    +    // Add the template button above the issue summary field.
    +  $('body.logged-in.page-node div.project-issue #edit-body').once('dreditorIssueTemplate', function () {
    

    Alignment of the inline comment is a bit off and if they are staying in the same behaviour there should be a blank line between the two sections IMO.

  4. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +          else if (!location.href.match(/^.*node\/[^\/]*\/edit/)) {
    +            var $profileLink = $('div.node > div.submitted a').clone();
    +            $profileLink.text('@' + $profileLink.text());
    +            $template.find('#summary-original-report a').replaceWith($('<div/>').html($profileLink).html());
    +          }
    ...
    +          else {
    +            var nodePath = location.href.match(/^.*node\/[0-9]*/);
    +            if (nodePath) {
    +              $.getJSON(nodePath[0] + '/project-issue/json', function(json){
    +                // Find the link to the original poster's profile.
    +                var $profileLink = $('<a/>').text('@' + json.authorName).attr('href', json.authorUrl);
    +                var $bodyVal = $('<div/>').html($body.val());
    +                $bodyVal.find('#summary-original-report a').replaceWith($('<div/>').html($profileLink).html());
    +                $body.val($bodyVal.html());
    +              });
    +            }
    +          }
    

    Neither of these handle the case of issues posted by Anonymous, leading to some different cases.

    For quick edit, we get this (which is probably fine):

    <h3 id="summary-original-report">Original report by </h3>

    For node edit, we get this (it actually tries to link to Anonymous!):

    <h3 id="summary-original-report">Original report by <a href="https://drupal.org/user/1504084">@</a></h3>

  5. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +          // Prepend text to current body.
    +          $body.val($template.html().replace(/<\/em>/g, "</em>\n\n").replace(/<\/h3>/g, "</h3>\n\n") + $body.val());
    +        });
    +        // Take no action other than executing the .click() behavior.
    +        return false;
    +        }
    +    );
    

    Alignment on the closing curly brace (second last line in the code sample) looks off, but I could be wrong.

  6. @@ -1551,6 +1551,122 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +  if (!(location.href.search('node/1326662/edit') === -1)) {
    ...
    +          if (!(location.href.search('node/add') === -1)) {
    

    JSHint was not happy with these lines:

    "Confusing use of '!'"

And definitely a nitpick but I think it'd be nice not to rely on dgo.to to link to the Dreditor project, just link directly to the project page.

star-szr’s picture

Hmm, maybe d.o or my machine was just being slower last night, not noticing a big difference between #70 and #72 today as far as speed. Still fast though :)

markhalliwell’s picture

Status: Needs work » Needs review
StatusFileSize
new5.95 KB

Addressed the concerns in #74:

  1. I'm going to keep this in the same Drupal.behaviors.dreditorIssueSummary behavior. They both pertain to the Issue Summary. I went ahead and moved the warning portion to the bottom of the behavior though since it is really just an extra "gate" mechanism to notify us of changes to the template.
  2. Removed. I wasn't thinking (would be nice though).
  3. Fixed
  4. Fixed. This will keep the will simply replace the templates <a href="#">@username</a> with <a href="#">Anonymous</a>
  5. Fixed. Actually both the ending curly and parenthesis should have been together, it's the ending .click() function.
  6. Fixed. The way I did that was dumb lol (I was tired)
  7. Fixed nitpick too, you're right, we should use the full path (I just like using the shortened URLs :)). I also went ahead and removed the protocol prefixes too, they all start with //drupal.org.
markhalliwell’s picture

StatusFileSize
new8 KB

Sigh... here's the interdiff for #72 -> #76 (not sure why my drush_iq isn't auto generating one, maybe because it's on a "master" branch and not a Drupal specific one).

markhalliwell’s picture

StatusFileSize
new1.55 KB
new6.03 KB

Fixed preventing default event per jQuery coding standards (https://drupal.org/node/1720586#event-delegation)

markhalliwell’s picture

StatusFileSize
new616 bytes
new6.03 KB

Fixed issue with author not being set properly on node edit pages

markhalliwell’s picture

StatusFileSize
new1.07 KB
new6.07 KB

Improved better detection of various different types of anon users

markhalliwell’s picture

StatusFileSize
new2.37 KB
new3.94 KB

Removed warning, I would rather lock down that page if possible so it is only editable by certain people (with a note saying who people should contact).

star-szr’s picture

Gave the latest patch a test and it seems to be working well, found some very minor touch-ups with the code, leaving at CNR so we can get more manual testing.

  1. @@ -1551,6 +1551,84 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +        $.get('//drupal.org/node/1326662', function(data) {
    ...
    +              $.getJSON(nodePath[0] + '/project-issue/json', function(json){
    

    Need spacing here per https://drupal.org/node/172169#functions.

    function (data) {
    function (json) {

  2. @@ -1551,6 +1551,84 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +          // Prepend text to current body.
    +          $body.val($template.html().replace(/<\/em>/g, "</em>\n\n").replace(/<\/h3>/g, "</h3>\n\n") + $body.val());
    +        });
    +        // Prevent default "click" event.
    +        e.preventDefault();
    +       });
    

    Double-check indents lining up here please.

  3. @@ -1551,6 +1551,84 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
    +    // Add a link to view the issue summary instructions.
    +    $('<a href="//drupal.org/issue-summaries" target="_blank">Issue summary instructions</a>')
    +      .appendTo($label)
    +      .before('(')
    +      .after(')');
    +  });
    

    Closing indent looks off.

star-szr’s picture

It sounds like #82.3 was pretty much the same as #74.5, so don't mind me. I'll get used to reviewing JavaScript eventually :)

Edit: although a blank line in between might help make it clearer :)

jenlampton’s picture

zomg, #81 is going to change my world. No more chrome autocomplete on the word "bare"
RTBC from me :)

cweagans’s picture

Assigned: Unassigned » cweagans

I'd like to take a quick look at this before commit, please :)

markhalliwell’s picture

StatusFileSize
new2.11 KB
new3.94 KB

Addressed issues in #82

markhalliwell’s picture

Assigned: cweagans » Unassigned

Feel free to take a look. Cottser and I have made significant progress on this issue and would like to commit this soon. We have had many reviews and are simply going through some minor coding standards nitpicks now. I doubt we'll have any major changes to actual functionality or logic used here.

edit: a lot of which we've already discussed in the #dreditor irc channel

cweagans’s picture

StatusFileSize
new2.35 KB
new3.96 KB

I realize the issue summary says caching will be handled elsewhere, but I think it's important to implement it here. There's already a localstorage wrapper in dreditor, so I've just used that. There's no way to modify the Cookie header in an XMLHttpRequest (at least, not in the browser context), so there's no possibility of retrieving the cached version of this page from Drupal.org. This implementation only adds a bit of code, and avoids hammering Drupal.org for something that's easily cached.

interdiff against 86

cweagans’s picture

(and for the browsers where localStorage is not supported, nothing will happen - we'll just grab the markup from d.o as normal)

markhalliwell’s picture

+++ b/dreditor.user.js
@@ -1555,6 +1555,98 @@ Drupal.behaviors.dreditorIssueSummary = function (context) {
+        if (!Drupal.storage.load('issueSummaryTemplate')) {
+          $.get('//drupal.org/node/1326662', function(data){
+            Drupal.storage.save('issueSummaryTemplate', data);
+            dreditorIssueTemplateProcess(data);
+          });
+        }
+        else {
+          var data = Drupal.storage.load('issueSummaryTemplate');
+          dreditorIssueTemplateProcess(data);
+        }
+
+        // Process the issue summary instructions.
+        function dreditorIssueTemplateProcess(data) {

This creates the function after it's called (see the else code block, which isn't asynchronous). It also doesn't timestamp difference these at all, so this would always be cached and the user would never get an updated version if the template were to change.

In all reality and TBCH, I'd really like to make this a whole separate issue. I'm not saying this isn't needed, but it certainly deserves it's own special attention.

FWIW, caching in Dreditor needs to be something more of a "service" so we have better handling of things like this in general (which certainly falls out of the scope of this issue) and before you say "if we don't put it in, then it'll hammer drupal.org" again, everyone already does this... just manually so they can copy and paste it.

Like I said, @Cottser and I have already discussed a lot of this kind of stuff in #dreditor. I suggest following this issue too (which is kinda short ATM) #2061841: [META] Overhaul/New Version

yesct’s picture

Status: Needs review » Reviewed & tested by the community

#86 manually tested on contrib and core. that looks ready to go. Lets make a new issue for caching.
I gave a quick read through the code and nothing standards wise jumped out at me.

markhalliwell’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @YesCT! Committed d210e57

Great job everyone! I went ahead and created #2063851: Implement a better service for caching data with expirations as a follow-up.

Status: Needs review » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.