Skip to content

Commit

Permalink
LIMS-1514: Allow sorting of visit list (#854)
Browse files Browse the repository at this point in the history
* LIMS-1514: Allow sorting of visit list

* LIMS-1514: Remove editing artifacts

* LIMS-1514: Allow searching by beamline name

---------

Co-authored-by: Mark Williams <[email protected]>
  • Loading branch information
ndg63276 and Mark Williams authored Dec 3, 2024
1 parent bb2f836 commit 443a354
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
33 changes: 8 additions & 25 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ function _get_visits($visit = null, $output = true)
}

if ($this->has_arg('s')) {
$where .= " AND s.visit_number LIKE :" . (sizeof($args) + 1);
$where .= " AND (s.visit_number LIKE :" . (sizeof($args) + 1) . " OR s.beamlinename LIKE :" . (sizeof($args) + 2) . ")";
array_push($args, $this->arg('s'));
array_push($args, $this->arg('s'));
}

Expand Down Expand Up @@ -435,7 +436,9 @@ function _get_visits($visit = null, $output = true)
$order = 's.startdate DESC';

if ($this->has_arg('sort_by')) {
$cols = array('ST' => 's.startdate', 'EN' => 's.enddate', 'VIS' => 's.visit_number', 'BL' => 's.beamlinename', 'LC' => 's.beamlineoperator', 'COMMENT' => 's.comments');
$cols = array('ST' => 's.startdate', 'EN' => 's.enddate', 'VIS' => 's.visit_number', 'BL' => 's.beamlinename',
'LC' => 's.beamlineoperator', 'COMMENT' => 's.comments', 'ERA' => 's.riskrating',
'SESSIONTYPE' => 'sessiontype', 'DCCOUNT' => 'dccount');
$dir = $this->has_arg('order') ? ($this->arg('order') == 'asc' ? 'ASC' : 'DESC') : 'ASC';
if (array_key_exists($this->arg('sort_by'), $cols))
$order = $cols[$this->arg('sort_by')] . ' ' . $dir;
Expand Down Expand Up @@ -469,42 +472,22 @@ function _get_visits($visit = null, $output = true)
s.beamcalendarid,
CONCAT(p.proposalcode, p.proposalnumber) AS proposal,
COUNT(shp.personid) AS persons,
COUNT(distinct dc.datacollectionid) AS dccount,
s.proposalid
FROM BLSession s
INNER JOIN proposal p ON p.proposalid = s.proposalid
LEFT OUTER JOIN sessiontype st ON st.sessionid = s.sessionid
LEFT OUTER JOIN session_has_person shp ON shp.sessionid = s.sessionid
LEFT OUTER JOIN beamlinesetup bls on bls.beamlinesetupid = s.beamlinesetupid
LEFT OUTER JOIN beamcalendar bc ON bc.beamcalendarid = s.beamcalendarid
LEFT OUTER JOIN datacollectiongroup dcg ON dcg.sessionid = s.sessionid
LEFT OUTER JOIN datacollection dc ON dcg.datacollectiongroupid = dc.datacollectiongroupid
$where
GROUP BY s.sessionid
ORDER BY $order", $args);

$ids = array();
$wcs = array();
foreach ($rows as $r) {
array_push($ids, $r['SESSIONID']);
array_push($wcs, 'dcg.sessionid=:' . sizeof($ids));
}

$dcs = array();
if (sizeof($ids)) {
$where = implode(' OR ', $wcs);
$tdcs = $this->db->pq("SELECT count(dc.datacollectionid) as c, dcg.sessionid
FROM datacollection dc
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
WHERE $where GROUP BY dcg.sessionid", $ids);
foreach ($tdcs as $t)
$dcs[$t['SESSIONID']] = $t['C'];
}

foreach ($rows as &$r) {
$dc = array_key_exists($r['SESSIONID'], $dcs) ? $dcs[$r['SESSIONID']] : 0;
$r['COMMENT'] = $r['COMMENTS'];
$r['DCCOUNT'] = $dc;

$bl_type = $this->_get_type_from_beamline($r['BL']);

$r['TYPE'] = $bl_type ? $bl_type : 'gen';
}

Expand Down
42 changes: 34 additions & 8 deletions client/src/js/modules/visits/views/visit_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
<div class="tw-pb-2">
<input data-testid="visit-table-search"
placeholder='Search'
v-on:keyup.enter="fetchData"
v-on:keyup="fetchData"
v-model = "searchVisit"/>
</div>

<table data-testid="visit-table" class="tw-w-full tw-mb-2">
<thead>
<td v-for="(value) in headers" :key="value.id" data-testid="visit-table-headers"
class="tw-w-1/8 tw-bg-table-header-background tw-text-table-header-color tw-font-bold tw-py-2 tw-text-center">
{{value.title}}
class="tw-w-1/8 tw-bg-table-header-background tw-text-table-header-color tw-py-2 tw-text-center">
<button v-if="value.key != 'DEWARS'" class="tw-font-bold" :id="value.order || value.key" @click="headerClick($event)">{{value.title}}</button>
<span v-else class="tw-font-bold">{{value.title}}</span>
</td>
</thead>

Expand Down Expand Up @@ -120,21 +121,25 @@ export default {
visits: [],
dewars: [],
searchVisit : '',
orderBy: '',
order: 1,
headers: [
{
key: "STARTDATE",
title: 'Start'
title: 'Start',
order: 'ST'
},
{
key: "ENDDATE",
title: 'End'
title: 'End',
order: 'EN'
},
{
key: "VIS",
title: 'Number'
},
{
key: "BEAMLINENAME",
key: "BL",
title: 'Beamline'
},
{
Expand All @@ -147,7 +152,8 @@ export default {
},
{
key: "UNIQUELCS",
title: 'Local Contact'
title: 'Local Contact',
order: 'LC'
},
{
key: "COMMENTS",
Expand Down Expand Up @@ -178,6 +184,7 @@ export default {
window.location.href = '/proposals/';
}
this.fetchData()
this.fetchData = _.debounce(this.fetchData, 500)
},
methods: {
async fetchData() {
Expand All @@ -188,8 +195,18 @@ export default {
page: this.currentPage,
per_page: this.pageSize,
prop: this.proposal,
s: this.searchVisit,
order: 'order',
directions: {
'-1': 'asc',
'1': 'desc',
},
};
this.visitCollection.state = {
sortKey: 'sort_by',
order: this.order,
};
if (this.searchVisit) this.visitCollection.queryParams.s = this.searchVisit;
if (this.orderBy) this.visitCollection.queryParams.sort_by = this.orderBy;
const results = await this.$store.dispatch('getCollection', this.visitCollection);
this.visits = results.toJSON().map((e) => {
Expand Down Expand Up @@ -259,6 +276,15 @@ export default {
window.location.href = 'dc/visit/' + this.proposal + '-' + visit.VIS;
}
},
headerClick(event) {
if (this.orderBy === event.target.id) {
this.order = -this.order;
} else {
this.order = 1;
}
this.orderBy = event.target.id;
this.fetchData();
},
handleFocusOut(visit) {
// if click outside of active input box then input returns to text
if(visit.clicked) {
Expand Down

0 comments on commit 443a354

Please sign in to comment.