Skip to content

Commit

Permalink
Update experiment picker
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Jun 12, 2024
1 parent d2c1026 commit 9b3377a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions labotel/indico_labotel/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from indico.core.plugins import IndicoPluginBlueprint

from indico_labotel.controllers import RHLabotelStats, RHLabotelStatsCSV, RHUserExperiment
from indico_labotel.controllers import RHLabotelStats, RHLabotelStatsCSV, RHUserDivision


blueprint = IndicoPluginBlueprint('labotel', __name__, url_prefix='/rooms')

blueprint.add_url_rule('/api/user/experiment', 'user_experiment', RHUserExperiment, methods=('GET', 'POST'))
blueprint.add_url_rule('/api/user/division', 'user_division', RHUserDivision, methods=('GET', 'POST'))
blueprint.add_url_rule('/api/labotel-stats', 'stats', RHLabotelStats)
blueprint.add_url_rule('/labotel-stats.csv', 'stats_csv', RHLabotelStatsCSV)

Expand Down
22 changes: 11 additions & 11 deletions labotel/indico_labotel/client/js/components/BootstrapOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// them and/or modify them under the terms of the MIT License; see
// the LICENSE file for more details.

import defaultExperimentURL from 'indico-url:plugin_labotel.user_experiment';
import defaultDivisionURL from 'indico-url:plugin_labotel.user_division';

import PropTypes from 'prop-types';
import React from 'react';
Expand All @@ -14,19 +14,19 @@ import {Button} from 'semantic-ui-react';
import {Translate} from 'indico/react/i18n';
import {indicoAxios, handleAxiosError} from 'indico/utils/axios';

export const EXPERIMENTS = ['ATLAS', 'CMS', 'ALICE', 'LHCb', 'HSE'];
export const DIVISIONS = ['Laser', 'Clean Room', 'DSF/QART'];

export default class BootstrapOptions extends React.Component {
static propTypes = {
setOptions: PropTypes.func.isRequired,
options: PropTypes.object.isRequired,
};

handleExperimentClick = async experiment => {
handleDivisionClick = async division => {
const {setOptions} = this.props;
setOptions({division: experiment});
setOptions({division});
try {
await indicoAxios.post(defaultExperimentURL(), {value: experiment});
await indicoAxios.post(defaultDivisionURL(), {value: division});
} catch (error) {
handleAxiosError(error);
}
Expand All @@ -39,19 +39,19 @@ export default class BootstrapOptions extends React.Component {

return (
<Button.Group style={{marginBottom: 10}}>
{EXPERIMENTS.map(experiment => (
{DIVISIONS.map(div => (
<Button
key={experiment}
onClick={() => this.handleExperimentClick(experiment)}
key={div}
onClick={() => this.handleDivisionClick(div)}
type="button"
primary={division === experiment}
primary={division === div}
>
{experiment}
{div}
</Button>
))}
<Button
key="other"
onClick={() => this.handleExperimentClick(null)}
onClick={() => this.handleDivisionClick(null)}
type="button"
primary={!division}
>
Expand Down
6 changes: 3 additions & 3 deletions labotel/indico_labotel/client/js/components/ExtraFilters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {FilterDropdownFactory} from 'indico/modules/rb/common/filters/FilterBar'
import FilterFormComponent from 'indico/modules/rb/common/filters/FilterFormComponent';
import {Translate} from 'indico/react/i18n';

import {EXPERIMENTS} from './BootstrapOptions';
import {DIVISIONS} from './BootstrapOptions';

// eslint-disable-next-line react/prop-types
const divisionRenderer = ({division}) => (!division ? null : <span>{division}</span>);
Expand All @@ -36,7 +36,7 @@ class ExtraFilterForm extends FilterFormComponent {
const {division} = this.state;
return (
<Form.Group>
{EXPERIMENTS.map(div => (
{DIVISIONS.map(div => (
<Form.Radio
checked={division === div}
key={div}
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class ExtraFilters extends React.Component {
return (
<FilterDropdownFactory
name="division"
title={<Translate>Experiment</Translate>}
title={<Translate>Category</Translate>}
form={({division}, setParentField) => (
<ExtraFilterForm setParentField={setParentField} division={division} />
)}
Expand Down
10 changes: 5 additions & 5 deletions labotel/indico_labotel/client/js/components/LabotelLanding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// them and/or modify them under the terms of the MIT License; see
// the LICENSE file for more details.

import defaultExperimentURL from 'indico-url:plugin_labotel.user_experiment';
import defaultDivisionURL from 'indico-url:plugin_labotel.user_division';

import React from 'react';

Expand All @@ -21,14 +21,14 @@ export default class LabotelLanding extends React.Component {
async componentDidMount() {
let response;
try {
response = await indicoAxios.get(defaultExperimentURL());
response = await indicoAxios.get(defaultDivisionURL());
} catch (error) {
handleAxiosError(error);
return;
}
const experiment = response.data.value;
if (this.landing.current && experiment) {
this.landing.current.setExtraState({division: experiment});
const division = response.data.value;
if (this.landing.current && division) {
this.landing.current.setExtraState({division});
}
}

Expand Down
2 changes: 1 addition & 1 deletion labotel/indico_labotel/client/js/components/Stats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function StatsTable({data, numDays, months}) {
<Translate>Building</Translate>
</Table.HeaderCell>
<Table.HeaderCell>
<Translate>Experiment</Translate>
<Translate>Category</Translate>
</Table.HeaderCell>
<Table.HeaderCell>
<Translate>Number of desks</Translate>
Expand Down
12 changes: 6 additions & 6 deletions labotel/indico_labotel/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ def _process(self):
return WPLabotelBase.display('room_booking.html')


class RHUserExperiment(RHProtected):
class RHUserDivision(RHProtected):
def _process_GET(self):
from indico_labotel.plugin import LabotelPlugin
return jsonify(value=LabotelPlugin.user_settings.get(session.user, 'default_experiment'))
return jsonify(value=LabotelPlugin.user_settings.get(session.user, 'default_division'))

@use_kwargs({
'value': fields.String(validate=validate.OneOf({'ATLAS', 'CMS', 'ALICE', 'LHCb', 'HSE'}), allow_none=True)
'value': fields.String(validate=validate.OneOf({'Laser', 'Clean Room', 'DSF/QART'}), allow_none=True)
})
def _process_POST(self, value):
from indico_labotel.plugin import LabotelPlugin
LabotelPlugin.user_settings.set(session.user, 'default_experiment', value)
LabotelPlugin.user_settings.set(session.user, 'default_division', value)


class RHLabotelStats(RHProtected):
Expand Down Expand Up @@ -83,7 +83,7 @@ def process(self, start_month, end_month):
# number of days within the boundary dates (inclusive)
num_days = ((end_dt - start_dt).days + 1)

headers = ['Building', 'Experiment', 'Number of labs']
headers = ['Building', 'Category', 'Number of labs']
for m in months:
headers += [m.strftime('%b %Y'), m.strftime('%b %Y (%%)')]
headers.append('Total')
Expand All @@ -94,7 +94,7 @@ def process(self, start_month, end_month):
for experiment, row_data in experiments:
row = {
'Building': building,
'Experiment': experiment,
'Category': experiment,
'Number of labs': row_data['desk_count']
}
for i, m in enumerate(row_data['months']):
Expand Down
2 changes: 1 addition & 1 deletion labotel/indico_labotel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LabotelPlugin(IndicoPlugin):
'cern_identity_provider': ''
}
default_user_settings = {
'default_experiment': None,
'default_division': None,
}

def init(self):
Expand Down

0 comments on commit 9b3377a

Please sign in to comment.