Remove all columns at once and escape input
This commit is contained in:
parent
7836e5b2db
commit
f0616eff79
@ -692,6 +692,7 @@
|
|||||||
"core-views/column-join-write-selected-column": "Write result in selected column.",
|
"core-views/column-join-write-selected-column": "Write result in selected column.",
|
||||||
"core-views/column-join-copy-to-new-column": "Write result in new column named...",
|
"core-views/column-join-copy-to-new-column": "Write result in new column named...",
|
||||||
"core-views/column-join-delete-joined-columns": "Delete joined columns.",
|
"core-views/column-join-delete-joined-columns": "Delete joined columns.",
|
||||||
|
"core-views/column-join-dont-escape": "In separator and nulls substitutes, use \\n for new lines, \\t for tabulation, \\\\n for \\n, \\\\t for \\t.",
|
||||||
"core-buttons/cancel": "Cancel",
|
"core-buttons/cancel": "Cancel",
|
||||||
"core-buttons/ok": " OK ",
|
"core-buttons/ok": " OK ",
|
||||||
"core-buttons/import-proj": "Import Project",
|
"core-buttons/import-proj": "Import Project",
|
||||||
|
@ -34,6 +34,10 @@
|
|||||||
<p class = "tip" bind= "or_views_column_join_skip_nulls_advice"></p>
|
<p class = "tip" bind= "or_views_column_join_skip_nulls_advice"></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="option">
|
||||||
|
<input type="checkbox" bind ="dont_escapeInput" name="dont-escape" id="$dont-escapeInput" />
|
||||||
|
<label for="$dont-escape" bind="or_views_column_join_dont_escape"></label>
|
||||||
|
</div>
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" bind ="write_selected_columnInput" name="write-or-copy" value="write-selected-column" id="$write-selected-column" checked />
|
<input type="radio" bind ="write_selected_columnInput" name="write-or-copy" value="write-selected-column" id="$write-selected-column" checked />
|
||||||
@ -48,7 +52,7 @@
|
|||||||
<div class="option">
|
<div class="option">
|
||||||
<input type="checkbox" bind ="delete_joined_columnsInput" name="delete-joined-columns" id="$delete-joined-columns" />
|
<input type="checkbox" bind ="delete_joined_columnsInput" name="delete-joined-columns" id="$delete-joined-columns" />
|
||||||
<label for="$delete-joined-columns" bind="or_views_column_join_delete_joined_columns"></label>
|
<label for="$delete-joined-columns" bind="or_views_column_join_delete_joined_columns"></label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -343,44 +343,52 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
var dialog = $(DOM.loadHTML("core","scripts/views/data-table/column-join.html"));
|
var dialog = $(DOM.loadHTML("core","scripts/views/data-table/column-join.html"));
|
||||||
var elmts = DOM.bind(dialog);
|
var elmts = DOM.bind(dialog);
|
||||||
var level = DialogSystem.showDialog(dialog);
|
var level = DialogSystem.showDialog(dialog);
|
||||||
/*
|
// Escape strings
|
||||||
* Close the dialog window
|
function escapeString(s,dontEscape) {
|
||||||
*/
|
var dontEscape = dontEscape || false;
|
||||||
|
var temp = s;
|
||||||
|
if (dontEscape) {
|
||||||
|
// replace "\n" with newline and "\t" with tab
|
||||||
|
temp = temp.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
|
||||||
|
// replace "\" with "\\"
|
||||||
|
temp = temp.replace(/\\/g, '\\\\');
|
||||||
|
// replace "\newline" with "\n" and "\tab" with "\t"
|
||||||
|
temp = temp.replace(/\\\n/g, '\\n').replace(/\\\t/g, '\\t');
|
||||||
|
// replace ' with \'
|
||||||
|
temp = temp.replace(/'/g, "\\'");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// escape \ and '
|
||||||
|
temp = s.replace(/\\/g, '\\\\').replace(/'/g, "\\'") ;
|
||||||
|
// useless : .replace(/"/g, '\\"')
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
};
|
||||||
|
// Close the dialog window
|
||||||
var dismiss = function() {
|
var dismiss = function() {
|
||||||
DialogSystem.dismissUntil(level - 1);
|
DialogSystem.dismissUntil(level - 1);
|
||||||
};
|
};
|
||||||
/*
|
// Join the columns according to user input
|
||||||
* Join the columns according to user input
|
|
||||||
*/
|
|
||||||
var transform = function() {
|
var transform = function() {
|
||||||
// function called in a callback
|
// function called in a callback
|
||||||
var deleteColumns = function() {
|
var deleteColumns = function() {
|
||||||
if (deleteJoinedColumns) {
|
if (deleteJoinedColumns) {
|
||||||
// do not delete the selected cell if it contains the result
|
console.log (theProject);
|
||||||
if (writeOrCopy !="copy-to-new-column") {
|
var columnsToKeep = theProject.columnModel.columns
|
||||||
columnsToJoin = columnsToJoin.filter(function(item) {
|
.map (function (col) {return col.name;})
|
||||||
return item !== column.name
|
.filter (function(colName) {
|
||||||
});
|
// keep the selected column if it contains the result
|
||||||
}
|
return (
|
||||||
var columnName = "";
|
(columnsToJoin.indexOf (colName) == -1) ||
|
||||||
var onJoinError = function(e) {
|
((writeOrCopy !="copy-to-new-column") && (colName == column.name)));
|
||||||
alert (e);
|
});
|
||||||
}
|
Refine.postCoreProcess(
|
||||||
var recursiveRemoval = function() {
|
"reorder-columns",
|
||||||
if (columnsToJoin.length > 0) {
|
null,
|
||||||
columnName = columnsToJoin.shift();
|
{ "columnNames" : JSON.stringify(columnsToKeep) },
|
||||||
Refine.postCoreProcess(
|
{ modelsChanged: true },
|
||||||
"remove-column",
|
{ includeEngine: false }
|
||||||
{
|
);
|
||||||
columnName: columnName
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
{ modelsChanged: true },
|
|
||||||
{ onDone:recursiveRemoval, onError:onJoinError }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
recursiveRemoval ();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// get options
|
// get options
|
||||||
@ -389,11 +397,12 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
var repeatCount = "";
|
var repeatCount = "";
|
||||||
var deleteJoinedColumns = elmts.delete_joined_columnsInput[0].checked;
|
var deleteJoinedColumns = elmts.delete_joined_columnsInput[0].checked;
|
||||||
var writeOrCopy = $("input[name='write-or-copy']:checked")[0].value;
|
var writeOrCopy = $("input[name='write-or-copy']:checked")[0].value;
|
||||||
var newColumnName = elmts.new_column_nameInput[0].value;
|
var newColumnName = $.trim(elmts.new_column_nameInput[0].value);
|
||||||
var manageNulls = $("input[name='manage-nulls']:checked")[0].value;
|
var manageNulls = $("input[name='manage-nulls']:checked")[0].value;
|
||||||
var nullSubstitute = elmts.null_substituteInput[0].value;
|
var nullSubstitute = elmts.null_substituteInput[0].value;
|
||||||
var fieldSeparator = elmts.field_separatorInput[0].value;
|
var fieldSeparator = elmts.field_separatorInput[0].value;
|
||||||
// correct options if they are not consistent
|
var dontEscape = elmts.dont_escapeInput[0].checked;
|
||||||
|
// fix options if they are not consistent
|
||||||
if (newColumnName != "") {
|
if (newColumnName != "") {
|
||||||
writeOrCopy ="copy-to-new-column";
|
writeOrCopy ="copy-to-new-column";
|
||||||
} else
|
} else
|
||||||
@ -402,7 +411,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
}
|
}
|
||||||
if (nullSubstitute != "") {
|
if (nullSubstitute != "") {
|
||||||
manageNulls ="replace-nulls";
|
manageNulls ="replace-nulls";
|
||||||
}
|
}
|
||||||
// build GREL expression
|
// build GREL expression
|
||||||
var columnsToJoin = [];
|
var columnsToJoin = [];
|
||||||
elmts.column_join_columnPicker
|
elmts.column_join_columnPicker
|
||||||
@ -412,13 +421,13 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
});
|
});
|
||||||
expression = columnsToJoin.map (function (colName) {
|
expression = columnsToJoin.map (function (colName) {
|
||||||
if (manageNulls == "skip-nulls") {
|
if (manageNulls == "skip-nulls") {
|
||||||
return "cells['"+colName+"'].value";
|
return "cells['"+escapeString(colName) +"'].value";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return "coalesce(cells['"+colName+"'].value, '"+nullSubstitute+ "')";
|
return "coalesce(cells['"+escapeString(colName)+"'].value,'"+ escapeString(nullSubstitute,dontEscape) + "')";
|
||||||
}
|
}
|
||||||
}).join (',');
|
}).join (',');
|
||||||
expression = 'join ([' + expression + '],"' + fieldSeparator + '")';
|
expression = 'join ([' + expression + '],\'' + escapeString(fieldSeparator,dontEscape) + "')";
|
||||||
// apply expression to selected column or new column
|
// apply expression to selected column or new column
|
||||||
if (writeOrCopy =="copy-to-new-column") {
|
if (writeOrCopy =="copy-to-new-column") {
|
||||||
Refine.postCoreProcess(
|
Refine.postCoreProcess(
|
||||||
@ -431,11 +440,17 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
},
|
},
|
||||||
{ expression: expression },
|
{ expression: expression },
|
||||||
{ modelsChanged: true },
|
{ modelsChanged: true },
|
||||||
{ onDone: deleteColumns}
|
{ onFinallyDone: deleteColumns}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
doTextTransform(column.name, expression, onError, repeat, repeatCount,{onDone: deleteColumns});
|
doTextTransform(
|
||||||
|
column.name,
|
||||||
|
expression,
|
||||||
|
onError,
|
||||||
|
repeat,
|
||||||
|
repeatCount,
|
||||||
|
{ onFinallyDone: deleteColumns});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// core of doJoinColumn
|
// core of doJoinColumn
|
||||||
@ -450,6 +465,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
elmts.or_views_column_join_delete_joined_columns.text($.i18n('core-views/column-join-delete-joined-columns'));
|
elmts.or_views_column_join_delete_joined_columns.text($.i18n('core-views/column-join-delete-joined-columns'));
|
||||||
elmts.or_views_column_join_field_separator.text($.i18n('core-views/column-join-field-separator'));
|
elmts.or_views_column_join_field_separator.text($.i18n('core-views/column-join-field-separator'));
|
||||||
elmts.or_views_column_join_field_separator_advice.text($.i18n('core-views/column-join-field-separator-advice'));
|
elmts.or_views_column_join_field_separator_advice.text($.i18n('core-views/column-join-field-separator-advice'));
|
||||||
|
elmts.or_views_column_join_dont_escape.text($.i18n('core-views/column-join-dont-escape'));
|
||||||
elmts.selectAllButton.html($.i18n('core-buttons/select-all'));
|
elmts.selectAllButton.html($.i18n('core-buttons/select-all'));
|
||||||
elmts.deselectAllButton.html($.i18n('core-buttons/deselect-all'));
|
elmts.deselectAllButton.html($.i18n('core-buttons/deselect-all'));
|
||||||
elmts.okButton.html($.i18n('core-buttons/ok'));
|
elmts.okButton.html($.i18n('core-buttons/ok'));
|
||||||
|
Loading…
Reference in New Issue
Block a user