Skip to content

Commit

Permalink
Update UI to reflect that events cannot be added or removed to confir…
Browse files Browse the repository at this point in the history
…med competitions.
  • Loading branch information
jfly committed Sep 7, 2017
1 parent cf21721 commit 66af566
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
33 changes: 26 additions & 7 deletions WcaOnRails/app/javascript/edit-events/EditEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class EditEvents extends React.Component {
}

render() {
let { competitionId, wcifEvents } = this.props;
let { competitionId, competitionConfirmed, wcifEvents } = this.props;
let unsavedChanges = null;
if(this.unsavedChanges()) {
unsavedChanges = (
Expand All @@ -81,7 +81,7 @@ export default class EditEvents extends React.Component {
{wcifEvents.map(wcifEvent => {
return (
<div key={wcifEvent.id} className="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<EventPanel wcifEvents={wcifEvents} wcifEvent={wcifEvent} />
<EventPanel wcifEvents={wcifEvents} wcifEvent={wcifEvent} competitionConfirmed={competitionConfirmed} />
</div>
);
})}
Expand Down Expand Up @@ -153,7 +153,7 @@ function RoundsTable({ wcifEvents, wcifEvent }) {
);
}

const EventPanel = ({ wcifEvents, wcifEvent }) => {
const EventPanel = ({ wcifEvents, competitionConfirmed, wcifEvent }) => {
let event = events.byId[wcifEvent.id];
let roundCountChanged = e => {
let newRoundCount = parseInt(e.target.value);
Expand All @@ -175,16 +175,35 @@ const EventPanel = ({ wcifEvents, wcifEvent }) => {
rootRender();
};

let panelTitle = null;
let disableAdd = false;
let disableRemove = false;
if(competitionConfirmed) {
if(wcifEvent.rounds.length === 0) {
disableAdd = true;
panelTitle = `Cannot add ${wcifEvent.id} because the competition is confirmed.`;
} else {
disableRemove = true;
panelTitle = `Cannot remove ${wcifEvent.id} because the competition is confirmed.`;
}
}

return (
<div className={cn(`panel panel-default event-${wcifEvent.id}`, { 'event-not-being-held': wcifEvent.rounds.length == 0 })}>
<div className="panel-heading">
<div className="panel-heading" title={panelTitle}>
<h3 className="panel-title">
<span className={cn("img-thumbnail", "cubing-icon", `event-${event.id}`)}></span>
<span className="title">{event.name}</span>
{" "}
<select className="form-control input-xs" name="select-round-count" value={wcifEvent.rounds.length} onChange={roundCountChanged}>
<option value={0}>Not being held</option>
<option disabled="disabled">────────</option>
<select
className="form-control input-xs"
name="select-round-count"
value={wcifEvent.rounds.length}
onChange={roundCountChanged}
disabled={disableAdd}
>
{!disableRemove && <option value={0}>Not being held</option>}
{!disableRemove && <option disabled="disabled">────────</option>}
<option value={1}>1 round</option>
<option value={2}>2 rounds</option>
<option value={3}>3 rounds</option>
Expand Down
5 changes: 3 additions & 2 deletions WcaOnRails/app/javascript/edit-events/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function promiseSaveWcif(wcif) {
let state = {};
export function rootRender() {
ReactDOM.render(
<EditEvents competitionId={state.competitionId} wcifEvents={state.wcifEvents} />,
<EditEvents competitionId={state.competitionId} competitionConfirmed={state.competitionConfirmed} wcifEvents={state.wcifEvents} />,
document.getElementById('events-edit-area'),
)
}
Expand All @@ -37,8 +37,9 @@ function normalizeWcifEvents(wcifEvents) {
});
}

wca.initializeEventsForm = (competitionId, wcifEvents) => {
wca.initializeEventsForm = (competitionId, competitionConfirmed, wcifEvents) => {
state.competitionId = competitionId;
state.competitionConfirmed = competitionConfirmed;
state.wcifEvents = normalizeWcifEvents(wcifEvents);
rootRender();
}
1 change: 1 addition & 0 deletions WcaOnRails/app/views/competitions/edit_events.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$(function() {
wca.initializeEventsForm(
<%= @competition.id.to_json.html_safe %>,
<%= @competition.isConfirmed.to_json.html_safe %>,
<%= @competition.competition_events.map(&:to_wcif).to_json.html_safe %>
);
});
Expand Down

0 comments on commit 66af566

Please sign in to comment.