Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 105 exclude candidates from cluster #6448

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe(__filename, function () {
});
});

it('Merge Select & Close', function () {
it('Merge Select & Close without excluding choices', function () {
cy.loadAndVisitProject(fixture);
cy.columnActionClick('location', ['Edit cells', 'Cluster and edit']);
cy.get('#autoId').check();
Expand Down Expand Up @@ -136,6 +136,39 @@ describe(__filename, function () {
]);
});

it('Merge Select & Close with excluding choices', function () {
cy.loadAndVisitProject(fixture);
cy.columnActionClick('location', ['Edit cells', 'Cluster and edit']);
cy.get('#autoId').check();

cy.get('.dialog-container').within(() => {
// check lines to be merged
cy.get(
'.clustering-dialog-entry-table tr.odd input[type="checkbox"]'
).check();

// exclude the first choice
cy.get('#Checkbox0_Choice0').uncheck();

// enter a new cell value
cy.get('.clustering-dialog-entry-table tr.odd input[type="text"]').type(
'testing'
);

cy.get('.dialog-footer button[bind="applyCloseButton"]').click();
});

cy.assertGridEquals([
['location'],
['SWABYS HOME'],
['SWABYS HOME'],
['BALLARDS Rivertesting'],
['BALLARDS River'],
['MOUNT ZION'],
['GRAVEL HILL'],
]);
});

it('Merge Select & Re Cluster', function () {
cy.loadAndVisitProject(fixture);
cy.columnActionClick('location', ['Edit cells', 'Cluster and edit']);
Expand Down Expand Up @@ -196,15 +229,15 @@ describe(__filename, function () {
cy.get('#autoId').check();

cy.get('.dialog-container').within(() => {
cy.get('.clustering-dialog-entry-table tr td:nth-child(3)').should(
cy.get('.clustering-dialog-entry-table tr td:nth-child(2)').should(
'to.contain',
'b ar'
);
cy.get('.clustering-dialog-entry-table tr td:nth-child(3)').should(
cy.get('.clustering-dialog-entry-table tr td:nth-child(2)').should(
'to.contain',
'b  ar'
);
cy.get('.clustering-dialog-entry-table tr td:nth-child(3)').should(
cy.get('.clustering-dialog-entry-table tr td:nth-child(2)').should(
'to.contain',
'b   ar'
);
Expand Down
103 changes: 69 additions & 34 deletions main/webapp/modules/core/scripts/dialogs/clustering-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ ClusteringDialog.prototype._createDialog = function() {

ClusteringDialog.prototype._renderTable = function(clusters) {
var self = this;

var container = this._elmts.tableContainer;

if (clusters.length > 0) {
Expand All @@ -214,11 +213,11 @@ ClusteringDialog.prototype._renderTable = function(clusters) {

var trHead = table.insertRow(table.rows.length);
trHead.className = "header";
$(trHead.insertCell(0)).text($.i18n('core-dialogs/cluster-size'));
$(trHead.insertCell(1)).text($.i18n('core-dialogs/row-count'));
$(trHead.insertCell(2)).text($.i18n('core-dialogs/cluster-values'));
$(trHead.insertCell(3)).text($.i18n('core-dialogs/merge'));
$(trHead.insertCell(4)).text($.i18n('core-dialogs/new-cell-val'));
$(trHead.insertCell(0)).text($.i18n('core-dialogs/merge'));
$(trHead.insertCell(1)).text($.i18n('core-dialogs/cluster-values'));
$(trHead.insertCell(2)).text($.i18n('core-dialogs/new-cell-val'));
$(trHead.insertCell(3)).text($.i18n('core-dialogs/cluster-size'));
$(trHead.insertCell(4)).text($.i18n('core-dialogs/row-count'));

var entryTemplate = document.createElement('a');
entryTemplate.href = "javascript:{}";
Expand All @@ -233,13 +232,7 @@ ClusteringDialog.prototype._renderTable = function(clusters) {
var tr = table.insertRow();
tr.className = index % 2 === 0 ? "odd" : "even"; // TODO: Unused?

var cell = tr.insertCell()
cell.textContent = cluster.choices.length.toString();

cell = tr.insertCell();
cell.textContent = cluster.rowCount.toString();

var facet = {
let facet = {
"c": {
"type":"list",
"name": self._columnName,
Expand All @@ -254,6 +247,7 @@ ClusteringDialog.prototype._renderTable = function(clusters) {
};

var ul = document.createElement('ul');
ul.style.listStyleType = 'none';
var choices = cluster.choices;
var onClick = function() {
var parent = $(this).closest("tr");
Expand All @@ -265,26 +259,46 @@ ClusteringDialog.prototype._renderTable = function(clusters) {
checkbox.prop('checked', true).trigger('change');
return false;
};
for (var c = 0; c < choices.length; c++) {
var choice = choices[c];
for (let c = 0; c < choices.length; c++) {
let choice = choices[c];
var li = document.createElement('li');
let checkBox = $('<input type="checkbox" style = "accent-color: gray;" />')
.appendTo(li);

checkBox.on('change', function() {
cluster.checkBoxes[c] = this.checked;
});
checkBox.attr("checked" , cluster.checkBoxes[c]);
if(!cluster.edit){
checkBox.attr("disabled","true");
}
var checkBoxID = 'Checkbox' + index.toString() + "_Choice" + c.toString();
checkBox.attr("id", checkBoxID);
checkBox.attr("class", "Checkbox_Choice Checkbox_Choice" + index.toString());

var entry = entryTemplate.cloneNode();
entry.textContent = choice.v.toString().replaceAll(' ', '\xa0');
entry.setAttribute('data-value', choice.v.toString());
entry.addEventListener('click', onClick);

li.append(entry);
if (choice.c > 1) {

if (choice.c > 1) {
$('<span></span>').text($.i18n("core-dialogs/cluster-rows", choice.c)).addClass("clustering-dialog-entry-count").appendTo(li);
}
facet.s[c] = {
facet.s.push({
"v": {
"v":choice.v,
"l":choice.v
"v": choice.v,
"l": choice.v
}
};
});
ul.append(li);
}


var div = document.createElement('div');
div.class = "clustering-dialog-value-focus";

var params = [
"project=" + encodeURIComponent(theProject.id),
"ui=" + encodeURIComponent(JSON.stringify({
Expand All @@ -293,24 +307,34 @@ ClusteringDialog.prototype._renderTable = function(clusters) {
];
var url = "project?" + params.join("&");

var div = document.createElement('div');
div.class = "clustering-dialog-value-focus";

var browseLink = $(browseLinkTemplate).clone()
.attr("href",url)
.appendTo(div);

$(tr.insertCell(2))
var editCheck = $('<input type="checkbox" style="accent-color: gray;" />')
.on('change', function() {
var isChecked = $(this).prop('checked');
cluster.edit = isChecked;
const checkboxChoicesList = $(".Checkbox_Choice" + index.toString());

checkboxChoicesList.each(function() {
const checkbox = $(this);
if (isChecked) {
checkbox.prop('disabled', false);
checkbox.prop('checked', true).trigger('change');
} else {
checkbox.prop('checked', false).trigger('change');
checkbox.prop('disabled', true);
}
});
}).appendTo(tr.insertCell(0));

$(tr.insertCell(1))
.on('mouseenter',function() { browseLink.css("visibility", "visible"); })
.on('mouseleave',function() { browseLink.css("visibility", "hidden"); })
.append(ul)
.append(div);

var editCheck = $('<input type="checkbox" />')
.on('change',function() {
cluster.edit = this.checked;
}).appendTo(tr.insertCell(3));


if (cluster.edit) {
editCheck.prop('checked', true);
}
Expand All @@ -319,7 +343,13 @@ ClusteringDialog.prototype._renderTable = function(clusters) {
.val(cluster.value)
.on("keyup change input",function() {
cluster.value = this.value;
}).appendTo(tr.insertCell(4));
}).appendTo(tr.insertCell(2));

var cell = tr.insertCell(3);
cell.textContent = cluster.choices.length.toString();

cell = tr.insertCell(4);
cell.textContent = cluster.rowCount.toString();

return choices.length;
};
Expand Down Expand Up @@ -374,7 +404,7 @@ ClusteringDialog.prototype._cluster = function() {
function(data) {
self._updateData(data);
$(".clustering-dialog-facet").css("display","block");
$('#cluster-and-edit-dialog :input').prop('disabled', false);
$('#cluster-and-edit-dialog :input').not('.Checkbox_Choice').prop('disabled', false);
},
"json"
);
Expand All @@ -387,7 +417,8 @@ ClusteringDialog.prototype._updateData = function(data) {
edit: false,
choices: this,
value: this[0].v,
size: this.length
size: this.length,
checkBoxes : []
};

var sum = 0;
Expand Down Expand Up @@ -448,7 +479,11 @@ ClusteringDialog.prototype._apply = function(onDone) {
if (cluster.edit) {
var values = [];
for (var j = 0; j < cluster.choices.length; j++) {
values.push(cluster.choices[j].v);
let checkBoxID = 'Checkbox' + i.toString() + "_Choice" + j.toString();
let checkBox = document.getElementById(checkBoxID);
if(checkBox.checked){
values.push(cluster.choices[j].v);
}
}

edits.push({
Expand Down