Commit b3db4da7 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

webapp sort columns using column index before alphabetical order

parent c04326b7
Pipeline #109 passed with stage
in 18 seconds
......@@ -39,6 +39,8 @@ import it.inaf.ia2.tsm.UpdateOperations;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import javax.faces.context.FacesContext;
......@@ -517,4 +519,45 @@ public class TapSchemaEditingBean implements Serializable {
}
}).getString();
}
/**
* Returns the columns list sorting them using {@code column_index} if
* available.
*/
public List<Column> getColumns() {
Table table = getSelectedTable();
if (table == null) {
return null;
}
List<Column> columns = new ArrayList<>(table.getAddedOrRemovedChildren());
if (hasColumnsSorter) {
Collections.sort(columns, new Comparator<Column>() {
@Override
public int compare(Column column1, Column column2) {
Integer columnIndex1 = column1.getValue(Column.COLUMN_INDEX, Integer.class);
Integer columnIndex2 = column2.getValue(Column.COLUMN_INDEX, Integer.class);
if (columnIndex1 == null && columnIndex2 == null) {
// When column index is not specified use the column name for sorting
return column1.getName().compareToIgnoreCase(column2.getName());
}
// Columns with the column index must be shown before the ones which don't have it.
if (columnIndex1 != null && columnIndex2 == null) {
return -1;
}
if (columnIndex1 == null && columnIndex2 != null) {
return 1;
}
// Compare the column indexes if they are not null.
return columnIndex1.compareTo(columnIndex2);
}
});
}
return columns;
}
}
......@@ -96,7 +96,7 @@
jsf.ajax.request('main', null, {
'javax.faces.behavior.event': 'action',
execute: '@none',
render: 'main:column_wrapper',
render: 'main:tables_wrapper',
onevent: function (event) {
if (event.status === 'success') {
$('#columns-sorter').modal('hide');
......
......@@ -243,7 +243,7 @@
<div class="columns-wrapper">
<div class="columns-selector">
<ul class="nav nav-pills">
<ui:repeat value="#{tapSchemaEditing.selectedTable.addedOrRemovedChildren}" var="column" id="columns-list">
<ui:repeat value="#{tapSchemaEditing.columns}" var="column" id="columns-list">
<li role="presentation" class="#{tapSchemaEditing.selectedColumn.name eq column.name ? 'active': ''}">
<h:commandLink role="tab" action="#{tapSchemaEditing.setSelectedColumn(column)}" id="column-selector">
<h:commandButton class="btn btn-link remove-btn" disabled="#{!tapSchemaEditing.isColumnRemovable(column)}" value="&#215;" onclick="TSM.stopPropagation(event)" id="column-remover">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment