diff --git a/api/src/Page/Proposal.php b/api/src/Page/Proposal.php index f8207ed2f..fcc019322 100644 --- a/api/src/Page/Proposal.php +++ b/api/src/Page/Proposal.php @@ -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')); } @@ -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; @@ -469,6 +472,7 @@ 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 @@ -476,35 +480,14 @@ function _get_visits($visit = null, $output = true) 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'; } diff --git a/client/src/js/modules/visits/views/visit_list.vue b/client/src/js/modules/visits/views/visit_list.vue index c3feef51a..26c019ee9 100644 --- a/client/src/js/modules/visits/views/visit_list.vue +++ b/client/src/js/modules/visits/views/visit_list.vue @@ -16,15 +16,16 @@
- {{value.title}} + class="tw-w-1/8 tw-bg-table-header-background tw-text-table-header-color tw-py-2 tw-text-center"> + + {{value.title}} | @@ -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' }, { @@ -147,7 +152,8 @@ export default { }, { key: "UNIQUELCS", - title: 'Local Contact' + title: 'Local Contact', + order: 'LC' }, { key: "COMMENTS", @@ -178,6 +184,7 @@ export default { window.location.href = '/proposals/'; } this.fetchData() + this.fetchData = _.debounce(this.fetchData, 500) }, methods: { async fetchData() { @@ -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) => { @@ -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) {