@canterbury-air-patrol/scenario-weighting-worksheet
Version:
SAR Scenario Weighting Worksheet
132 lines • 7.32 kB
JavaScript
// scenario-weighting-worksheet.tsx
import React from "react";
import Table from "react-bootstrap/Table";
import Button from "react-bootstrap/Button";
var ScenarioWeightingTitleBlock = class extends React.Component {
render() {
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Table, null, /* @__PURE__ */ React.createElement("tbody", null, /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("th", null, "Operation Name:"), /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement("input", { type: "text", value: this.props.operationName })), /* @__PURE__ */ React.createElement("th", null, "Time:"), /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement("input", { type: "text" }))), /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("th", null, "Prepared by:"), /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement("input", { type: "text" })), /* @__PURE__ */ React.createElement("th", null, "Date:"), /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement("input", { type: "text" }))))));
}
};
var ScenarioWeightingScenarioNames = class extends React.Component {
constructor(props) {
super(props);
this.updateScenarioName = this.updateScenarioName.bind(this);
}
updateScenarioName(event) {
const target = event.target;
const value = target.value;
const id = target.id;
this.props.updateScenarioName(Number(id), value);
}
render() {
const scenarios = [];
for (const scenario in this.props.scenarios) {
scenarios.push(
/* @__PURE__ */ React.createElement("tr", { key: scenario }, /* @__PURE__ */ React.createElement("td", null, scenario), /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement("input", { type: "text", defaultValue: this.props.scenarios[scenario], onChange: this.updateScenarioName, id: scenario })))
);
}
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Table, null, /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("td", null, "Scenario"), /* @__PURE__ */ React.createElement("td", null, "Short Description"))), /* @__PURE__ */ React.createElement("tbody", null, scenarios, /* @__PURE__ */ React.createElement("tr", { key: "new" }, /* @__PURE__ */ React.createElement("td", { colSpan: 2 }, /* @__PURE__ */ React.createElement(Button, { type: "button", onClick: this.props.addScenario }, "Add Scenario"))))));
}
};
var ScenarioWeightingWeightings = class extends React.Component {
constructor(props) {
super(props);
this.updateRanking = this.updateRanking.bind(this);
}
updateRanking(event) {
const target = event.target;
const value = target.value;
const id = target.id;
const components = id.split("_");
this.props.updateRanking(Number(components[0]), Number(components[1]), Number(value));
}
render() {
const rows = [];
const scenarios = [];
const scenarioTotals = [];
const relativeWeights = [/* @__PURE__ */ React.createElement("th", { key: "blank" }, "Relative Weights")];
for (const participant in this.props.participants) {
const data = [/* @__PURE__ */ React.createElement("th", { key: participant }, participant)];
for (const scenario in this.props.scenarios) {
data.push(
/* @__PURE__ */ React.createElement("td", { key: participant + "_" + scenario }, /* @__PURE__ */ React.createElement("input", { type: "number", min: 0, max: 100, id: participant + "_" + scenario, onChange: this.updateRanking, value: this.props.rankings[participant][scenario] }))
);
}
rows.push(/* @__PURE__ */ React.createElement("tr", { key: participant }, data));
}
let allScenariosTotal = 0;
for (const scenario in this.props.scenarios) {
scenarios.push(/* @__PURE__ */ React.createElement("th", { key: scenario }, this.props.scenarios[scenario]));
let total = 0;
for (const participant in this.props.participants) {
total += this.props.rankings[participant][scenario];
}
scenarioTotals.push(total);
allScenariosTotal += total;
}
for (const scenario in scenarioTotals) {
relativeWeights.push(/* @__PURE__ */ React.createElement("td", { key: scenario }, Math.trunc(scenarioTotals[scenario] / allScenariosTotal * 100), "%"));
}
return /* @__PURE__ */ React.createElement(Table, { bordered: true, hover: true }, /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("th", { key: "label" }, "Participant"), scenarios)), /* @__PURE__ */ React.createElement("tbody", null, rows, /* @__PURE__ */ React.createElement("tr", { key: "new" }, /* @__PURE__ */ React.createElement("td", null, /* @__PURE__ */ React.createElement(Button, { type: "button", onClick: this.props.addParticipant }, "Add Participant")))), /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", null, relativeWeights)));
}
};
var ScenarioWeightingWorksheet = class extends React.Component {
constructor(props) {
super(props);
this.state = {
operationName: "",
scenarios: [],
participants: [],
rankings: []
};
this.addScenario = this.addScenario.bind(this);
this.updateScenarioName = this.updateScenarioName.bind(this);
this.addParticipant = this.addParticipant.bind(this);
this.updateRanking = this.updateRanking.bind(this);
}
addScenario() {
this.setState(function(oldState) {
oldState.scenarios.push("");
for (const participant in oldState.participants) {
oldState.rankings[participant].push(0);
}
return oldState;
});
}
addParticipant() {
this.setState(function(oldState) {
oldState.participants.push("");
const rankings = oldState.scenarios.map(() => 0);
oldState.rankings.push(rankings);
return oldState;
});
}
updateScenarioName(scenarioId, name) {
this.setState(function(oldState) {
oldState.scenarios[scenarioId] = name;
return oldState;
});
}
updateRanking(participant, scenario, ranking) {
this.setState(function(oldState) {
oldState.rankings[participant][scenario] = ranking;
return oldState;
});
}
render() {
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(ScenarioWeightingTitleBlock, { operationName: this.state.operationName }), /* @__PURE__ */ React.createElement(ScenarioWeightingScenarioNames, { scenarios: this.state.scenarios, addScenario: this.addScenario, updateScenarioName: this.updateScenarioName }), /* @__PURE__ */ React.createElement(
ScenarioWeightingWeightings,
{
scenarios: this.state.scenarios,
participants: this.state.participants,
addParticipant: this.addParticipant,
rankings: this.state.rankings,
updateRanking: this.updateRanking
}
));
}
};
export {
ScenarioWeightingWorksheet
};
//# sourceMappingURL=scenario-weighting-worksheet.mjs.map