Init commit

This commit is contained in:
Mathieu Saby 2019-08-04 14:37:36 +02:00
parent ef08ea1368
commit 27d5fb88fa
5 changed files with 363 additions and 1 deletions

View File

@ -516,6 +516,7 @@ function init() {
"styles/widgets/slider-widget.less", "styles/widgets/slider-widget.less",
"styles/views/data-table-view.less", "styles/views/data-table-view.less",
"styles/views/column-join.less",
"styles/dialogs/expression-preview-dialog.less", "styles/dialogs/expression-preview-dialog.less",
"styles/dialogs/clustering-dialog.less", "styles/dialogs/clustering-dialog.less",

View File

@ -550,6 +550,7 @@
"core-views/url-fetch": "Formulate the URLs to fetch:", "core-views/url-fetch": "Formulate the URLs to fetch:",
"core-views/http-headers": "HTTP headers to be used when fetching URLs:", "core-views/http-headers": "HTTP headers to be used when fetching URLs:",
"core-views/enter-col-name": "Enter new column name", "core-views/enter-col-name": "Enter new column name",
"core-views/join-col":"Join columns",
"core-views/split-col": "Split column", "core-views/split-col": "Split column",
"core-views/several-col": "into several columns", "core-views/several-col": "into several columns",
"core-views/how-split": "How to Split Column", "core-views/how-split": "How to Split Column",
@ -680,6 +681,18 @@
"core-views/use-values-as-identifiers2": "Mark cells as reconciled with their values as identifiers", "core-views/use-values-as-identifiers2": "Mark cells as reconciled with their values as identifiers",
"core-views/choose-reconciliation-service": "Choose a reconciliation service", "core-views/choose-reconciliation-service": "Choose a reconciliation service",
"core-views/choose-reconciliation-service-alert": "Please choose a reconciliation service first.", "core-views/choose-reconciliation-service-alert": "Please choose a reconciliation service first.",
"core-views/column-join": "Join columns",
"core-views/column-join-before-column-picker": "Select and order columns to join",
"core-views/column-join-before-options": "Select options",
"core-views/column-join-field-separator": "Separator between the content of each column :",
"core-views/column-join-field-separator-advice": "Enter one or more character, or keep blank to juxtapose the columns.",
"core-views/column-join-replace-nulls": "Replace nulls with...",
"core-views/column-join-skip-nulls": "Skip nulls.",
"core-views/column-join-replace-nulls-advice": "Enter one or more character, or keep blank to replace nulls with blank strings.",
"core-views/column-join-skip-nulls-advice": "Skipping nulls will make impossible the reverse the join.",
"core-views/column-join-write-active-column": "Write result in active column.",
"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-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",

View File

@ -0,0 +1,60 @@
<div class="dialog-frame" style="width: 800px;">
<div class="dialog-header" bind="dialogHeader"></div>
<div class="dialog-body" bind="dialogBody">
<div class="grid-layout grid-layout-for-ui layout-full" >
<div class="column-join-left-pane">
<p bind = "or_views_column_join_before_column_picker"></p>
<div class="column-join-inner-left-pane">
<div bind="column_join_columnPicker" class="column-join-inner-left-pane-list"></div>
<div class="column-join-global-selection">
<button class="button" bind="selectAllButton"></button>
<button class="button" bind="deselectAllButton"></button>
</div>
</div>
</div>
<div class="column-join-right-pane grid-layout ">
<p bind="or_views_column_join_before_options"></p>
<div class="column-join-inner-right-pane">
<div class="option">
<label for="$field-separator" bind="or_views_column_join_field_separator"></label>
<input size="10" value="" bind="field_separatorInput" id="$field-separator"/>
<p class = "tip" bind= "or_views_column_join_field_separator_advice"></p>
</div>
<div class="option">
<div>
<input type="radio" checked="true" bind="replace_nullsInput" name="manage-nulls" value="replace-nulls" id="$replace-nulls" >
<label for="$replace-nulls" bind="or_views_column_join_replace_nulls"></label>
<input size="10" value="" bind="null_substituteInput" id="$null-substitute" />
<p class = "tip" bind= "or_views_column_join_replace_nulls_advice"></p>
</div>
<div>
<input type="radio" bind="skip_nullsInput" name="manage-nulls" value="skip-nulls" id="$skip-nulls" />
<label for="$skip-nulls" bind="or_views_column_join_skip_nulls"></label>
<p class = "tip" bind= "or_views_column_join_skip_nulls_advice"></p>
</div>
</div>
<div class="option">
<div>
<input type="radio" bind ="write_active_columnInput" name="write-or-copy" value="write-active-column" id="$write-active-column" checked />
<label for="$write-active-column" bind="or_views_column_join_write_active_column"></label>
</div>
<div>
<input type="radio" bind ="copy_to_new_columnInput" name="write-or-copy" value="copy-to-new-column" id="$copy-to-new-column" />
<label for="$copy-to-new-column" bind="or_views_column_join_copy_to_new_column"></label>
<input size="20" value="" bind ="new_column_nameInput" id="$new-column-name" />
</div>
</div>
<div class="option">
<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>
</div>
</div>
</div>
</div>
</div>
<div class="dialog-footer" bind="dialogFooter">
<button class="button" bind="okButton"></button>
<button class="button" bind="cancelButton"></button>
</div>
</div>

View File

@ -33,6 +33,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
var columnIndex = Refine.columnNameToColumnIndex(column.name); var columnIndex = Refine.columnNameToColumnIndex(column.name);
var doTextTransform = function(columnName, expression, onError, repeat, repeatCount) {
Refine.postCoreProcess(
"text-transform",
{
columnName: columnName,
onError: onError,
repeat: repeat,
repeatCount: repeatCount
},
{ expression: expression },
{ cellsChanged: true }
);
};
var doAddColumn = function() { var doAddColumn = function() {
var frame = $( var frame = $(
DOM.loadHTML("core", "scripts/views/data-table/add-column-dialog.html") DOM.loadHTML("core", "scripts/views/data-table/add-column-dialog.html")
@ -320,14 +334,204 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
); );
dismiss(); dismiss();
}); });
};
var doJoinColumns = function() {
var self = this;
self.onError = "keep-original" ;
self.repeat = false ;
self.repeatCount = "";
/*
* Close the dialog window
*/
var dismiss = function() {
DialogSystem.dismissUntil(self.level - 1);
};
/*
* Join the columns according to user input
*/
var transform = function() {
// get options
self.deleteJoinedColumns = self.elmts.delete_joined_columnsInput[0].checked;
self.writeOrCopy = $("input[name='write-or-copy']:checked")[0].value;
self.newColumnName = self.elmts.new_column_nameInput[0].value;
self.manageNulls = $("input[name='manage-nulls']:checked")[0].value;
self.nullSubstitute = self.elmts.null_substituteInput[0].value;
self.fieldSeparator = self.elmts.field_separatorInput[0].value;
// correct options if they are not consistent
if (self.newColumnName != "") {
self.writeOrCopy ="copy-to-new-column";
} else
{
self.writeOrCopy ="write-active-column";
};
if (self.nullSubstitute != "") {
self.manageNulls ="replace-nulls";
};
// build GREL expression
var columnsToJoin = [];
self.elmts.column_join_columnPicker
.find('.column-join-column input[type="checkbox"]:checked')
.each(function() {
columnsToJoin.push (this.closest ('.column-join-column').getAttribute('column'));
});
self.expression = columnsToJoin.map (function (colName) {
if (self.manageNulls == "skip-nulls") {
return "cells['"+colName+"'].value";
}
else {
return "coalesce(cells['"+colName+"'].value, '"+self.nullSubstitute+ "')";
}
}).join (',');
self.expression = 'join ([' + self.expression + '],"' + self.fieldSeparator + '")';
// apply expression to active column or new column
if (self.writeOrCopy =="copy-to-new-column") {
Refine.postCoreProcess(
"add-column",
{
baseColumnName: column.name,
newColumnName: self.newColumnName,
columnInsertIndex: columnIndex + 1,
onError: self.onError
},
{ expression: self.expression },
{ modelsChanged: true }
);
}
else {
doTextTransform(column.name, self.expression, self.onError, self.repeat, self.repeatCount);
}
// delete joined columns
if (self.deleteJoinedColumns) {
// do not delete the active cell if it contains the result
if (self.writeOrCopy !="copy-to-new-column") {
columnsToJoin = columnsToJoin.filter(function(item) {
return item !== column.name
});
}
columnsToJoin.forEach (function (columnName) {
// FIXME ERREUR dans Refine.postProcess (project.js l. 359) :
// Index: 5, Size: 5
// Index: 6, Size: 5
// No column named e
Refine.postCoreProcess(
"remove-column",
{
columnName: columnName
},
null,
{ modelsChanged: true }
);
});
}
};
// core of doJoinColumn
self.dialog = $(DOM.loadHTML("core","scripts/views/data-table/column-join.html"));
self.elmts = DOM.bind(self.dialog);
self.level = DialogSystem.showDialog(self.dialog);
self.elmts.dialogHeader.text($.i18n('core-views/column-join'));
self.elmts.or_views_column_join_before_column_picker.text($.i18n('core-views/column-join-before-column-picker'));
self.elmts.or_views_column_join_before_options.text($.i18n('core-views/column-join-before-options'));
self.elmts.or_views_column_join_replace_nulls.text($.i18n('core-views/column-join-replace-nulls'));
self.elmts.or_views_column_join_replace_nulls_advice.text($.i18n('core-views/column-join-replace-nulls-advice'));
self.elmts.or_views_column_join_skip_nulls.text($.i18n('core-views/column-join-skip-nulls'));
self.elmts.or_views_column_join_skip_nulls_advice.text($.i18n('core-views/column-join-skip-nulls-advice'));
self.elmts.or_views_column_join_write_active_column.text($.i18n('core-views/column-join-write-active-column'));
self.elmts.or_views_column_join_copy_to_new_column.text($.i18n('core-views/column-join-copy-to-new-column'));
self.elmts.or_views_column_join_delete_joined_columns.text($.i18n('core-views/column-join-delete-joined-columns'));
self.elmts.or_views_column_join_field_separator.text($.i18n('core-views/column-join-field-separator'));
self.elmts.or_views_column_join_field_separator_advice.text($.i18n('core-views/column-join-field-separator-advice'));
self.elmts.selectAllButton.html($.i18n('core-buttons/select-all'));
self.elmts.deselectAllButton.html($.i18n('core-buttons/deselect-all'));
self.elmts.okButton.html($.i18n('core-buttons/ok'));
self.elmts.cancelButton.html($.i18n('core-buttons/cancel'));
/*
* Populate column list.
*/
for (var i = 0; i < theProject.columnModel.columns.length; i++) {
var col = theProject.columnModel.columns[i];
var colName = col.name;
var div = $('<div>').
addClass("column-join-column")
.attr("column", colName)
.appendTo(this.elmts.column_join_columnPicker);
$('<input>').
attr('type', 'checkbox')
.prop('checked',(i == columnIndex) ? true : false)
.appendTo(div);
$('<span>')
.text(colName)
.appendTo(div);
}
// Move the active column on the top of the list
if (columnIndex > 0) {
activeColumn = self.elmts.column_join_columnPicker
.find('.column-join-column')
.eq(columnIndex);
activeColumn.parent().prepend(activeColumn);
}
// Make the list sortable
self.elmts.column_join_columnPicker.sortable({});
/*
* Hook up event handlers.
*/
self.elmts.column_join_columnPicker
.find('.column-join-column')
.click(function() {
self.elmts.column_join_columnPicker
.find('.column-join-column')
.removeClass('selected');
$(this).addClass('selected');
});
self.elmts.selectAllButton
.click(function() {
self.elmts.column_join_columnPicker
.find('input[type="checkbox"]')
.prop('checked',true);
});
self.elmts.deselectAllButton
.click(function() {
self.elmts.column_join_columnPicker
.find('input[type="checkbox"]')
.prop('checked',false);
});
self.elmts.okButton.click(function() {
transform();
dismiss();
});
self.elmts.cancelButton.click(function() {
dismiss();
});
self.elmts.new_column_nameInput.change(function() {
if (self.elmts.new_column_nameInput[0].value != "") {
self.elmts.copy_to_new_columnInput.prop('checked',true);
} else
{
self.elmts.write_active_columnInput.prop('checked',true);
};
});
self.elmts.null_substituteInput.change(function() {
self.elmts.replace_nullsInput.prop('checked',true);
});
}; };
/*
* Create global menu
*/
MenuSystem.appendTo(menu, [ "core/edit-column" ], [ MenuSystem.appendTo(menu, [ "core/edit-column" ], [
{ {
id: "core/split-column", id: "core/split-column",
label: $.i18n('core-views/split-into-col')+"...", label: $.i18n('core-views/split-into-col')+"...",
click: doSplitColumn click: doSplitColumn
}, },
{
id: "core/join-column",
label: $.i18n('core-views/join-col')+"...",
click : doJoinColumns
},
{}, {},
{ {
id: "core/add-column", id: "core/add-column",
@ -369,7 +573,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
{ {
id: "core/move-column-to-left", id: "core/move-column-to-left",
label: $.i18n('core-views/move-to-left'), label: $.i18n('core-views/move-to-left'),
click: function() { doMoveColumnBy(-1); } click: function() { doMoveColumnBy(-1);}
}, },
{ {
id: "core/move-column-to-right", id: "core/move-column-to-right",

View File

@ -0,0 +1,84 @@
/*
Copyright 2019, Mathieu Saby.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
Same properties as dialogs/custom-tabular-exporter-dialog.less, applied to the class and ids of colum-join.html
*/
@import-less url("../theme.less");
.dialog-header,.dialog_body,.dialog-footer,.global_selection {
clear:both;
}
.column-join-left-pane {
float:left;
width : 40%;
}
.column-join-inner-left-pane,.column-join-inner-right-pane {
border: 1px solid @chrome_primary;
height: 24em;
padding: @padding_loose;
}
.column-join-inner-left-pane-list {
overflow: auto;
height:22em;
}
.column-join-global-selection {
margin-top:0.5em;
}
.column-join-column {
border: 1px solid @chrome_primary;
background: @fill_secondary;
padding: @padding_tighter;
margin: @padding_tight;
cursor: move;
.rounded_corners();
}
.column-join-column.selected {
background: @chrome_primary;
font-weight: bold;
}
.column-join-inner-right-pane .option {
margin-top:1em;
}
.column-join-inner-right-pane .tip,.column-join-inner-left-pane .tip{
font-size:0.9em;
}