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
Community moderators have prevented the ability to post new answers.
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(); } }); }); });
Vitalii, thanks for your help.
I tried to follow your suggestion but I can't make it work. I did the following
<web-resource key="web-resources" name="Plugin resources"> <resource type="download" name="atlgeneral.js" location="js/atlgeneral.js"/> <context>atl.general</context> </web-resource>
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, now it works
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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(); } }); }); });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same thing... it checks the box, but Select Ranking and Select Classification don't open
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vitalii, works like a charm now. Thanks for pursuing this until making it work, you must like what you're doing!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
'
.defectFields
'
and enable comment button respectively to selected values.Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Vitalii, I have it working now!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Javier !
Im' looking for the exact same thing. Can you share you final implementation with us ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
}
});
});
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.