Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is it possible to force the defect checkbox in a crucible review to be checked by default

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2016

Use Case: We're finding that many comments made by developers are actually defects, but they're not flagged as such. If the Defect checkbox in crucible were checked by default, comments would be flagged as defects by default forcing developers to take the right action.

Question: Is it possible to have the Defect checkbox checked by default, either by an option in crucible administration, or by implementing a plugin

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Vitalii Petrychuk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 26, 2016

Hi Javier,

Unfortunately the flag is not configurable.
But you are also interested in plugin implementing. So if you create a custom plugin it is possible to autoselect the checkbox using JavaScript.

There are two version of doing it. Please pick the one that matches your Crucible version.

AJS.$(function () {
  AJS.$('#frxs').on('comment-form-added', function (e) {
    var $commentForm = AJS.$(e.target);
 
    // Wait for magic to happen on Crucible side
    setTimeout(function () {
 
      // Do not enable defect while editing the comment
      var commentId = Number($commentForm.find('[name="commentId"]').val());
      if (commentId && commentId > 0) {
        return;
      }
 
      // Manually select "Defect" checkbox if it's not selected and show metrics
      var $defect = $commentForm.find('[name="defect"]');
      if ($defect.is(':checked') === false) {
        var $fields = $commentForm.find('.defectFields');
        $defect.prop('checked', true);
        $defect.val(true);
        $fields.show();
      }
    });
  });
});
AJS.$(function () {
  AJS.$('#frxs').on('comment-form-added', function (e) {
    var $commentForm = AJS.$(e.target);
 
    // Wait for magic to happen on Crucible side
    setTimeout(function () {
 
      // Do not enable defect while editing the comment
      var commentId = Number($commentForm.find('[name="commentId"]').val());
      if (commentId && commentId > 0) {
        return;
      }
 
      // Click "Defect" checkbox if it's not selected
      var $defect = $commentForm.find('[name="defect"]');
      if ($defect.is(':checked') === false) {
        $commentForm.find('[name="defect"]').click();
      }
    });
  });
});
Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2016

Vitalii, thanks for your help.

I tried to follow your suggestion but I can't make it work. I did the following

  • src/main/resources/atlassian-plugin.xml
<web-resource key="web-resources" name="Plugin resources">
        <resource type="download" name="atlgeneral.js" location="js/atlgeneral.js"/>
         <context>atl.general</context>
    </web-resource>
  • src/main/resources/js/atlgeneral.js
AJS.$('#frxs').on('comment-form-added', function () {
  setTimeout(function () {
    AJS.$('#defect-revision').prop('checked', true);
  })
})

The module is enabled, I can see it in the plugin in the add-ons section as below when clicking on the 2 of 2 modules enabled

image2016-10-1 12:5:34.png

Any further help I'd appreciate it

Vitalii Petrychuk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2016

Do you execute the code on documents ready event?
#frxs element might not be rendered yet so the listener cannot be attached.

AJS.$(function () {
  // Put the code here
})

Or maybe you do have some errors in browser's console?
What version of Crucible do you use?

-----

If one of your goals is to force developers to take an action then you might be interested in "Resolving comments" feature we've released in 4.2 version wink

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2016

Yes, now it works smile

However.... it's not opening the Select Ranking and Select Classification drop boxes. Is that possible with this approach...?

 

I'm using release 3.9. I took a look at "Resolving comments" in the online documentation, it's still not quite what I'm looking for... Developers will still be able to make comments but not declare them as defects, even if they're. Having a check in the defect checkbox by default is a more conservative approach: if after review, in the end is not a defect, it's a better scenario than a comment that was a defect but it wasn't declared as such. The optimal approach would be to have defect as a mandatory field: the developer would have to consciously declare his comment as defect or otherwise.

Vitalii Petrychuk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2016

Got it.
Try the code below. I tested it in 4.2, must work for 3.9 as well.

AJS.$(function () {
  AJS.$('#frxs').on('comment-form-added', function (e) {
    var $commentForm = AJS.$(e.target);

    // Wait for magic to happen on Crucible side
    setTimeout(function () {

      // Do not enable defect while editing the comment
      var commentId = Number($commentForm.find('[name="commentId"]').val());
      if (commentId && commentId > 0) {
        return;
      }

      // Click "Defect" checkbox if it's not selected
      var $defect = $commentForm.find('[name="defect"]');
      if ($defect.is(':checked') === false) {
        $commentForm.find('[name="defect"]').click();
      }
    });
  });
});
Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2016

Same thing... it checks the box, but Select Ranking and Select Classification don't open

 

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2016

Humm... not only that. The defect checkbox gets checked, but even though, when clicking on button comment to save the comments, the comment is not registered as defect

Vitalii Petrychuk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2016

In 3.9 there is a bug that doesn't allow to properly handle the click. I prepared the workaround for 3.9 - 4.1 versions. Please check the edited answer above. Hope it helps.

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

Vitalii, works like a charm now. Thanks for pursuing this until making it work, you must like what you're doing!

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2016

Vitalii, one last thing if you don't mind... would it be possible to enhance your code so the comment is rejected if field Select Ranking doesn't have a value?. With this developers wouldn't have a chance... the would be forced to either uncheck the checkbox if it's not a defect, or selecting a ranking if it's defect (confirming this is a defect)

 

Vitalii Petrychuk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 3, 2016

This must be doable. I cannot help with the code right now but I can give you a hint:

If the comment form is opened and defect is selected and '.defectFields' aren't selected:

  1. Disable "Comment" button immediately.
  2. Attach a change listener to '.defectFields' and enable comment button respectively to selected values.

Hope this helps.

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2016

Thanks Vitalii, I have it working now!

Clément Honoré February 15, 2018

Hi Javier !

Im' looking for the exact same thing. Can you share you final implementation with us ?

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2018

It's been long time, not sure what the piece of code was, but this is what I have

AJS.$(function () {
  AJS.$('#frxs').on('comment-form-added', function (e) {
    var $commentForm = AJS.$(e.target);
 
    // Wait for magic to happen on Crucible side
    setTimeout(function () {
 
      // Do not enable defect while editing the comment
      var commentId = Number($commentForm.find('[name="commentId"]').val());
      if (commentId && commentId > 0) {
        return;
      }
 
var buttons = document.getElementsByClassName('aui-button aui-button-primary postButton defaultButton');
var commentsButton = buttons[0];

var $pp=$commentForm.find('[class="aui-button aui-button-primary postButton defaultButton"]');

      // Manually select "Defect" checkbox if it's not selected and show metrics
      var $defect = $commentForm.find('[name="defect"]');
 
      if ($defect.is(':checked') === false) {
        var $fields = $commentForm.find('.defectFields');
        $defect.prop('checked', true);
        $defect.val(true);
        $fields.show();
      }


commentsButton.setAttribute('aria-disabled', 'true');
$pp.prop('disabled', true);

AJS.$('[name="rank"]').change(function() {

    var $rank = $commentForm.find('[name="rank"]');
    
    if ( $rank.val() == '' ) {
        commentsButton.setAttribute('aria-disabled', 'true');
        $pp.prop('disabled', true);
    } else {
        commentsButton.setAttribute('aria-disabled', 'false');
        $pp.prop('disabled', false);
    }
});

AJS.$('[name="defect"]').change(function() {
    if ($defect.is(':checked') === false) {
        commentsButton.setAttribute('aria-disabled', 'false');
        $pp.prop('disabled', false);
    } else {
        var $rank = $commentForm.find('[name="rank"]');
        if ( $rank.val() == '' ) {
            commentsButton.setAttribute('aria-disabled', 'true');
            $pp.prop('disabled', true);
        } else {
            commentsButton.setAttribute('aria-disabled', 'false');
            $pp.prop('disabled', false);
        }
    }
});


    });
  });
});
TAGS
AUG Leaders

Atlassian Community Events