Skip to content

Commit 278b3ea

Browse files
committed
feat: update matrix UI to allow _all_ versions with a particular tag to be specified
1 parent c47c27a commit 278b3ea

File tree

3 files changed

+60
-56
lines changed

3 files changed

+60
-56
lines changed

lib/pact_broker/ui/controllers/matrix.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ class Matrix < Base
5959
def create_selector_objects(selector_hashes)
6060
selector_hashes.collect do | selector_hash |
6161
o = OpenStruct.new(selector_hash)
62-
o.tag_disabled = o.tag ? nil : 'disabled'
63-
o.version_disabled = o.pacticipant_version_number ? nil : 'disabled'
64-
o.specify_latest_tag_checked = o.tag ? 'checked' : nil
65-
o.specify_latest_checked = o.latest ? 'checked' : nil
66-
o.specify_version_checked = o.pacticipant_version_number ? 'checked' : nil
67-
o.specify_all_versions_checked = !(o.tag || o.pacticipant_version_number) ? 'checked' : nil
62+
o.specify_latest_tag = o.tag && o.latest ? 'checked' : nil
63+
o.specify_all_tagged = o.tag && !o.latest ? 'checked' : nil
64+
o.specify_latest = o.latest ? 'checked' : nil
65+
o.specify_version = o.pacticipant_version_number ? 'checked' : nil
66+
o.specify_all_versions = !(o.tag || o.pacticipant_version_number) ? 'checked' : nil
6867
o
6968
end
7069
end

lib/pact_broker/ui/views/matrix/show.haml

+15-17
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,27 @@
2929
%input{name: 'q[]pacticipant', id: "pacticipant1#{index}", value: selector.pacticipant_name}
3030

3131
.input-group
32-
%input{type: 'radio', name: "ignorethis#{index}", class: 'specify-all-versions version-selectorizor', value: 'all_versions', id: "pacticipant#{index}_all_versions", checked: selector.specify_all_versions_checked}
33-
%label{for: "pacticipant#{index}_all_versions"}
34-
All versions
3532

3633
.input-group
37-
%input{type: 'radio', name: "ignorethis#{index}", class: 'specify-version version-selectorizor', value: 'version', id: "pacticipant#{index}_by_version", checked: selector.specify_version_checked}
38-
%label{for: "pacticipant#{index}_by_version"}
39-
Version
40-
%input{name: 'q[]version', type: 'text', id: "pacticipant#{index}_version", class: 'by-version', value: selector.pacticipant_version_number}
34+
%select{ name: "ignorethis#{index}", class: 'version-selectorizor' }
35+
%option{ value: 'specify-all-versions', selected: selector.specify_all_versions }
36+
All versions
37+
%option{ value: 'specify-latest', selected: selector.specify_latest }
38+
Latest version
39+
%option{ value: 'specify-version', selected: selector.specify_version }
40+
Version number ...
41+
%option{ value: 'specify-latest-tag', selected: selector.specify_latest_tag }
42+
Latest version with tag ...
43+
%option{ value: 'specify-all-tagged', selected: selector.specify_all_tagged }
44+
All versions with tag...
4145

42-
.input-group
43-
%input{type: 'radio', name: "ignorethis#{index}", class: 'specify-latest version-selectorizor', value: 'tag', id: "pacticipant#{index}_latest", checked: selector.specify_latest_checked}
44-
%label{for: "pacticipant#{index}_latest"}
45-
Latest version
46-
%input{name: 'q[]latest', value: 'true', hidden: true, class: 'latest-flag'}
46+
%input{name: 'q[]version', type: 'text', id: "pacticipant#{index}_version", class: 'version', value: selector.pacticipant_version_number}
47+
48+
%input{name: 'q[]tag', type: 'text', id: "pacticipant#{index}_tag", class: 'tag', value: selector.tag}
4749

48-
.input-group
49-
%input{type: 'radio', name: "ignorethis#{index}", class: 'specify-latest-tag version-selectorizor', value: 'tag', id: "pacticipant#{index}_by_tag", checked: selector.specify_latest_tag_checked}
50-
%label{for: "pacticipant#{index}_by_tag"}
51-
Latest version with tag
52-
%input{name: 'q[]tag', type: 'text', id: "pacticipant#{index}_tag", class: "by-latest-tag", value: selector.tag}
5350
%input{name: 'q[]latest', value: 'true', hidden: true, class: 'latest-flag'}
5451

52+
5553
%div.top-of-group
5654
.input-group
5755
%input{type: 'radio', name: "latestby", class: '', value: '', id: 'all_rows', checked: options.all_rows_checked}

public/javascripts/matrix.js

+40-33
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
1-
function handleRadioButtonClicked() {
2-
selectApplicableTextBox($(this));
3-
clearOtherTextBoxes($(this));
4-
}
51

6-
function selectApplicableTextBox(selectedRadioButton) {
7-
selectedRadioButton.closest('.input-group').find('input[type="text"]').first().focus();
2+
function setTextboxVisibility(selectBox, cssSelector, visibility) {
3+
var textbox = selectBox.closest('.selector').find(cssSelector);
4+
textbox.toggle(visibility);
5+
if(visibility) {
6+
textbox.prop('disabled', '');
7+
textbox.focus();
8+
} else {
9+
textbox.prop('disabled', 'disabled');
10+
}
811
}
912

10-
function handleTextBoxClicked() {
11-
selectApplicableRadioButton($(this));
12-
clearOtherTextBoxes($(this));
13+
function toggleLatestFlag(selectBox, enabled) {
14+
var flagElement = selectBox.closest('.selector').find('.latest-flag');
15+
if(enabled) {
16+
flagElement.prop('disabled', '');
17+
} else {
18+
flagElement.prop('disabled', 'disabled');
19+
}
1320
}
1421

15-
function selectApplicableRadioButton(selectedTextBox) {
16-
selectedTextBox.closest('.input-group').find('.version-selectorizor').prop('checked', 'checked');
22+
function showApplicableTextBoxes(selectorizor) {
23+
var selectorizorType = selectorizor.val();
24+
if( selectorizorType === 'specify-version') {
25+
setTextboxVisibility(selectorizor, '.version', true);
26+
setTextboxVisibility(selectorizor, '.tag', false);
27+
}
28+
else if( selectorizorType === 'specify-latest-tag' || selectorizorType === 'specify-all-tagged') {
29+
setTextboxVisibility(selectorizor, '.version', false);
30+
setTextboxVisibility(selectorizor, '.tag', true);
31+
}
32+
else if ( selectorizorType === 'specify-all-versions' || selectorizorType === 'specify-latest') {
33+
setTextboxVisibility(selectorizor, '.version', false);
34+
setTextboxVisibility(selectorizor, '.tag', false);
35+
}
36+
37+
if (selectorizorType === 'specify-latest' || selectorizorType === 'specify-latest-tag') {
38+
toggleLatestFlag(selectorizor, true);
39+
} else {
40+
toggleLatestFlag(selectorizor, false);
41+
}
1742
}
1843

19-
function clearOtherTextBoxes(clickedElement) {
20-
clickedElement.closest('.selector').find('input[type="text"]').each(function(){
21-
if(!$.contains(clickedElement.closest('.input-group')[0], $(this)[0])) {
22-
$(this).prop('value', '');
23-
}
24-
});
44+
function handleSelectorizorChanged() {
45+
showApplicableTextBoxes($(this));
2546
}
2647

2748
function onSubmit() {
@@ -30,26 +51,12 @@ function onSubmit() {
3051
}
3152

3253
function disableFieldsThatShouldNotBeSubmitted() {
33-
disableInputsForUncheckedRadioButtons();
34-
disableRadioButtons();
35-
}
36-
37-
function disableInputsForUncheckedRadioButtons() {
38-
$('.version-selectorizor').each(function(){
39-
if($(this).prop('checked') === false) {
40-
$(this).closest('.input-group').find('input').prop('disabled', 'disabled');
41-
}
42-
});
43-
}
44-
45-
function disableRadioButtons() {
4654
$('.version-selectorizor').prop('disabled', 'disabled');
4755
}
4856

4957
$(document).ready(function(){
50-
$('.by-version').click(handleTextBoxClicked);
51-
$('.by-latest-tag').click(handleTextBoxClicked);
52-
$('.version-selectorizor').click(handleRadioButtonClicked);
58+
$('.version-selectorizor').change(handleSelectorizorChanged);
59+
$('.version-selectorizor').each(function(){ showApplicableTextBoxes($(this)); });
5360

5461
$("#matrix").tablesorter({
5562
textExtraction : function(node, table, cellIndex){

0 commit comments

Comments
 (0)