mirror of https://github.com/Fabio286/antares.git
fix: query result sort not working with aliased tables, fixes #765
This commit is contained in:
parent
dd5b41716a
commit
de9dac3e8a
|
@ -31,7 +31,7 @@
|
||||||
:class="{ 'active': resultsetIndex === index }"
|
:class="{ 'active': resultsetIndex === index }"
|
||||||
@click="selectResultset(index)"
|
@click="selectResultset(index)"
|
||||||
>
|
>
|
||||||
<a>{{ result.fields ? result.fields[0]?.table : '' }} ({{ result.rows.length }})</a>
|
<a>{{ result.fields ? result.fields[0]?.tableAlias ?? result.fields[0]?.table : `${t('general.results')} #${index}` }} ({{ result.rows.length }})</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div ref="table" class="table table-hover">
|
<div ref="table" class="table table-hover">
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
:title="`${field.type} ${fieldLength(field) ? `(${fieldLength(field)})` : ''}`"
|
:title="`${field.type} ${fieldLength(field) ? `(${fieldLength(field)})` : ''}`"
|
||||||
>
|
>
|
||||||
<div ref="columnResize" class="column-resizable">
|
<div ref="columnResize" class="column-resizable">
|
||||||
<div class="table-column-title" @click="sort(field.name)">
|
<div class="table-column-title" @click="sort(field)">
|
||||||
<div v-if="field.key" :title="keyName(field.key)">
|
<div v-if="field.key" :title="keyName(field.key)">
|
||||||
<BaseIcon
|
<BaseIcon
|
||||||
icon-name="mdiKey"
|
icon-name="mdiKey"
|
||||||
|
@ -56,8 +56,8 @@
|
||||||
</div>
|
</div>
|
||||||
<span>{{ field.alias || field.name }}</span>
|
<span>{{ field.alias || field.name }}</span>
|
||||||
<BaseIcon
|
<BaseIcon
|
||||||
v-if="isSortable && currentSort === field.name || currentSort === `${field.table}.${field.name}`"
|
v-if="isSortable && currentSort[resultsetIndex]?.field === field.name || currentSort[resultsetIndex]?.field === `${field.tableAlias || field.table}.${field.name}`"
|
||||||
:icon-name="currentSortDir === 'asc' ? 'mdiSortAscending' : 'mdiSortDescending'"
|
:icon-name="currentSort[resultsetIndex].dir === 'asc' ? 'mdiSortAscending' : 'mdiSortDescending'"
|
||||||
:size="18"
|
:size="18"
|
||||||
class="sort-icon ml-1"
|
class="sort-icon ml-1"
|
||||||
/>
|
/>
|
||||||
|
@ -314,8 +314,7 @@ const hasFocus = ref(false);
|
||||||
const contextEvent = ref(null);
|
const contextEvent = ref(null);
|
||||||
const selectedCell = ref(null);
|
const selectedCell = ref(null);
|
||||||
const selectedRows = ref([]);
|
const selectedRows = ref([]);
|
||||||
const currentSort = ref('');
|
const currentSort: Ref<{field: string; dir: 'asc' | 'desc'}[]> = ref([]);
|
||||||
const currentSortDir = ref('asc');
|
|
||||||
const resultsetIndex = ref(0);
|
const resultsetIndex = ref(0);
|
||||||
const scrollElement = ref(null);
|
const scrollElement = ref(null);
|
||||||
const rowHeight = ref(23);
|
const rowHeight = ref(23);
|
||||||
|
@ -358,14 +357,16 @@ const isHardSort = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortedResults = computed(() => {
|
const sortedResults = computed(() => {
|
||||||
if (currentSort.value && !isHardSort.value) {
|
if (currentSort.value[resultsetIndex.value] && !isHardSort.value) {
|
||||||
|
const sortObj = currentSort.value[resultsetIndex.value];
|
||||||
|
|
||||||
return [...localResults.value].sort((a: any, b: any) => {
|
return [...localResults.value].sort((a: any, b: any) => {
|
||||||
let modifier = 1;
|
let modifier = 1;
|
||||||
let valA = typeof a[currentSort.value] === 'string' ? a[currentSort.value].toLowerCase() : a[currentSort.value];
|
let valA = typeof a[sortObj.field] === 'string' ? a[sortObj.field].toLowerCase() : a[sortObj.field];
|
||||||
if (!isNaN(valA)) valA = Number(valA);
|
if (!isNaN(valA)) valA = Number(valA);
|
||||||
let valB = typeof b[currentSort.value] === 'string' ? b[currentSort.value].toLowerCase() : b[currentSort.value];
|
let valB = typeof b[sortObj.field] === 'string' ? b[sortObj.field].toLowerCase() : b[sortObj.field];
|
||||||
if (!isNaN(valB)) valB = Number(valB);
|
if (!isNaN(valB)) valB = Number(valB);
|
||||||
if (currentSortDir.value === 'desc') modifier = -1;
|
if (sortObj.dir === 'desc') modifier = -1;
|
||||||
if (valA < valB) return -1 * modifier;
|
if (valA < valB) return -1 * modifier;
|
||||||
if (valA > valB) return 1 * modifier;
|
if (valA > valB) return 1 * modifier;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -784,32 +785,42 @@ const contextMenu = (event: MouseEvent, cell: any) => {
|
||||||
isContext.value = true;
|
isContext.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sort = (field: string) => {
|
const sort = (field: TableField) => {
|
||||||
if (!isSortable.value) return;
|
if (!isSortable.value) return;
|
||||||
|
|
||||||
selectedRows.value = [];
|
selectedRows.value = [];
|
||||||
|
let fieldName = field.name;
|
||||||
|
const hasTableInFieldname = Object.keys(localResults.value[0]).find(k => k !== '_antares_id').includes('.');
|
||||||
|
|
||||||
if (props.mode === 'query')
|
if (props.mode === 'query' && hasTableInFieldname)
|
||||||
field = `${getTable(resultsetIndex.value)}.${field}`;
|
fieldName = `${field.tableAlias || field.table}.${field.name}`;
|
||||||
|
|
||||||
if (field === currentSort.value) {
|
if (fieldName === currentSort.value[resultsetIndex.value]?.field) {
|
||||||
if (currentSortDir.value === 'asc')
|
if (currentSort.value[resultsetIndex.value].dir === 'asc')
|
||||||
currentSortDir.value = 'desc';
|
currentSort.value[resultsetIndex.value].dir = 'desc';
|
||||||
else
|
else
|
||||||
resetSort();
|
resetSort();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentSortDir.value = 'asc';
|
currentSort.value[resultsetIndex.value] = {
|
||||||
currentSort.value = field;
|
field: fieldName,
|
||||||
|
dir: 'asc'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHardSort.value)
|
if (isHardSort.value) {
|
||||||
emit('hard-sort', { field: currentSort.value, dir: currentSortDir.value });
|
emit('hard-sort', {
|
||||||
|
field: currentSort.value[resultsetIndex.value].field,
|
||||||
|
dir: currentSort.value[resultsetIndex.value].dir
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetSort = () => {
|
const resetSort = () => {
|
||||||
currentSort.value = '';
|
currentSort.value[resultsetIndex.value] = {
|
||||||
currentSortDir.value = 'asc';
|
field: null,
|
||||||
|
dir: 'asc'
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectResultset = (index: number) => {
|
const selectResultset = (index: number) => {
|
||||||
|
|
Loading…
Reference in New Issue