Add storage grid interactions [SCI-10922]

This commit is contained in:
Anton 2024-07-30 14:36:00 +02:00
parent d68e4d9f27
commit 1d63c6f818
4 changed files with 72 additions and 14 deletions

View file

@ -580,8 +580,11 @@ export default {
this.gridApi.forEachNode((node) => { this.gridApi.forEachNode((node) => {
if (this.selectedRows.find((row) => row.id === node.data.id)) { if (this.selectedRows.find((row) => row.id === node.data.id)) {
node.setSelected(true); node.setSelected(true);
} else {
node.setSelected(false);
} }
}); });
this.$emit('selectionChanged', this.selectedRows);
} }
}, },
setSelectedRows(e) { setSelectedRows(e) {
@ -594,6 +597,7 @@ export default {
} else { } else {
this.selectedRows = this.selectedRows.filter((row) => row.id !== e.data.id); this.selectedRows = this.selectedRows.filter((row) => row.id !== e.data.id);
} }
this.$emit('selectionChanged', this.selectedRows);
}, },
emitAction(action) { emitAction(action) {
this.$emit(action.name, action, this.selectedRows); this.$emit(action.name, action, this.selectedRows);
@ -605,6 +609,7 @@ export default {
clickCell(e) { clickCell(e) {
if (e.column.colId !== 'rowMenu' && e.column.userProvidedColDef.notSelectable !== true) { if (e.column.colId !== 'rowMenu' && e.column.userProvidedColDef.notSelectable !== true) {
e.node.setSelected(true); e.node.setSelected(true);
this.$emit('selectionChanged', this.selectedRows);
} }
}, },
applyFilters(filters) { applyFilters(filters) {

View file

@ -9,7 +9,13 @@
</button> </button>
</div> </div>
</div> </div>
<Grid :gridSize="gridSize" :assignedItems="assignedItems" @assign="assignRowToPosition"/> <Grid
:gridSize="gridSize"
:assignedItems="assignedItems"
:selectedItems="selectedItems"
@assign="assignRowToPosition"
@select="selectRow"
/>
</div> </div>
<div class="h-full bg-white p-4"> <div class="h-full bg-white p-4">
<DataTable :columnDefs="columnDefs" <DataTable :columnDefs="columnDefs"
@ -24,6 +30,7 @@
@move="moveRow" @move="moveRow"
@unassign="unassignRows" @unassign="unassignRows"
@tableReloaded="handleTableReload" @tableReloaded="handleTableReload"
@selectionChanged="selectedItems = $event"
/> />
</div> </div>
<Teleport to="body"> <Teleport to="body">
@ -93,6 +100,7 @@ export default {
objectToMove: null, objectToMove: null,
moveToUrl: null, moveToUrl: null,
assignedItems: [], assignedItems: [],
selectedItems: [],
openAssignModal: false, openAssignModal: false,
assignToPosition: null, assignToPosition: null,
assignToContainer: null, assignToContainer: null,
@ -106,6 +114,7 @@ export default {
paginationMode() { paginationMode() {
return this.withGrid ? 'none' : 'pages'; return this.withGrid ? 'none' : 'pages';
}, },
columnDefs() { columnDefs() {
const columns = [{ const columns = [{
field: 'position', field: 'position',
@ -161,6 +170,14 @@ export default {
this.reloadingTable = false; this.reloadingTable = false;
this.assignedItems = items; this.assignedItems = items;
}, },
selectRow(row) {
if (this.$refs.table.selectedRows.includes(row)) {
this.$refs.table.selectedRows = this.$refs.table.selectedRows.filter((r) => r !== row);
} else {
this.$refs.table.selectedRows.push(row);
}
this.$refs.table.restoreSelection();
},
assignRow() { assignRow() {
this.openAssignModal = true; this.openAssignModal = true;
this.rowIdToMove = null; this.rowIdToMove = null;

View file

@ -25,13 +25,21 @@
> >
<div <div
class="h-full w-full rounded-full items-center flex justify-center" class="h-full w-full rounded-full items-center flex justify-center"
@click="assignRow(cell.row, cell.column)" @click="assignRow(cell)"
:class="{ :class="{
'bg-sn-background-green': cellIsOccupied(cell.row, cell.column), 'bg-sn-background-green': cellIsOccupied(cell),
'bg-white cursor-pointer': !cellIsOccupied(cell.row, cell.column) 'bg-sn-grey-100': cellIsHidden(cell),
'bg-white': cellIsAvailable(cell),
'bg-white border-sn-science-blue border-solid border-[1px]': cellIsSelected(cell),
'cursor-pointer': !cellIsHidden(cell)
}" }"
> >
{{ rowsList[cell.row] }}{{ columnsList[cell.column] }} <template v-if="cellIsHidden(cell)">
<i class="sn-icon sn-icon-locked-task"></i>
</template>
<template v-else>
{{ rowsList[cell.row] }}{{ columnsList[cell.column] }}
</template>
</div> </div>
</div> </div>
</div> </div>
@ -51,6 +59,10 @@ export default {
assignedItems: { assignedItems: {
type: Array, type: Array,
default: () => [] default: () => []
},
selectedItems: {
type: Array,
default: () => []
} }
}, },
mounted() { mounted() {
@ -79,14 +91,32 @@ export default {
} }
}, },
methods: { methods: {
cellIsOccupied(row, column) { cellObject(cell) {
return this.assignedItems.some((item) => item.position[0] === row + 1 && item.position[1] === column + 1); return this.assignedItems.find((item) => item.position[0] === cell.row + 1 && item.position[1] === cell.column + 1);
}, },
assignRow(row, column) { cellIsOccupied(cell) {
if (this.cellIsOccupied(row, column)) { return this.cellObject(cell) && !this.cellObject(cell)?.hidden;
},
cellIsHidden(cell) {
return this.cellObject(cell)?.hidden;
},
cellIsSelected(cell) {
return this.selectedItems.some((item) => item.position[0] === cell.row + 1 && item.position[1] === cell.column + 1);
},
cellIsAvailable(cell) {
return !this.cellIsOccupied(cell) && !this.cellIsHidden(cell);
},
assignRow(cell) {
if (this.cellIsOccupied(cell)) {
this.$emit('select', this.cellObject(cell));
return; return;
} }
this.$emit('assign', [row + 1, column + 1]);
if (this.cellIsHidden(cell)) {
return;
}
this.$emit('assign', [cell.row + 1, cell.column + 1]);
}, },
handleScroll() { handleScroll() {
this.$refs.columnsContainer.scrollLeft = this.$refs.cellsContainer.scrollLeft; this.$refs.columnsContainer.scrollLeft = this.$refs.cellsContainer.scrollLeft;

View file

@ -2,18 +2,20 @@
module Lists module Lists
class StorageLocationRepositoryRowSerializer < ActiveModel::Serializer class StorageLocationRepositoryRowSerializer < ActiveModel::Serializer
attributes :created_by, :created_on, :position, :row_id, :row_name include Canaid::Helpers::PermissionsHelper
attributes :created_by, :created_on, :position, :row_id, :row_name, :hidden
def row_id def row_id
object.repository_row.id object.repository_row.id unless hidden
end end
def row_name def row_name
object.repository_row.name object.repository_row.name unless hidden
end end
def created_by def created_by
object.created_by.full_name object.created_by.full_name unless hidden
end end
def created_on def created_on
@ -23,5 +25,9 @@ module Lists
def position def position
object.metadata['position'] object.metadata['position']
end end
def hidden
!can_read_repository?(object.repository_row.repository)
end
end end
end end