UNPKG

@canterbury-air-patrol/scenario-weighting-worksheet

Version:
167 lines (166 loc) 9.99 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // scenario-weighting-worksheet.tsx var scenario_weighting_worksheet_exports = {}; __export(scenario_weighting_worksheet_exports, { ScenarioWeightingWorksheet: () => ScenarioWeightingWorksheet }); module.exports = __toCommonJS(scenario_weighting_worksheet_exports); var import_react = __toESM(require("react")); var import_Table = __toESM(require("react-bootstrap/Table")); var import_Button = __toESM(require("react-bootstrap/Button")); var ScenarioWeightingTitleBlock = class extends import_react.default.Component { render() { return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_Table.default, null, /* @__PURE__ */ import_react.default.createElement("tbody", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("th", null, "Operation Name:"), /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("input", { type: "text", value: this.props.operationName })), /* @__PURE__ */ import_react.default.createElement("th", null, "Time:"), /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("input", { type: "text" }))), /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("th", null, "Prepared by:"), /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("input", { type: "text" })), /* @__PURE__ */ import_react.default.createElement("th", null, "Date:"), /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("input", { type: "text" })))))); } }; var ScenarioWeightingScenarioNames = class extends import_react.default.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__ */ import_react.default.createElement("tr", { key: scenario }, /* @__PURE__ */ import_react.default.createElement("td", null, scenario), /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement("input", { type: "text", defaultValue: this.props.scenarios[scenario], onChange: this.updateScenarioName, id: scenario }))) ); } return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_Table.default, null, /* @__PURE__ */ import_react.default.createElement("thead", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("td", null, "Scenario"), /* @__PURE__ */ import_react.default.createElement("td", null, "Short Description"))), /* @__PURE__ */ import_react.default.createElement("tbody", null, scenarios, /* @__PURE__ */ import_react.default.createElement("tr", { key: "new" }, /* @__PURE__ */ import_react.default.createElement("td", { colSpan: 2 }, /* @__PURE__ */ import_react.default.createElement(import_Button.default, { type: "button", onClick: this.props.addScenario }, "Add Scenario")))))); } }; var ScenarioWeightingWeightings = class extends import_react.default.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__ */ import_react.default.createElement("th", { key: "blank" }, "Relative Weights")]; for (const participant in this.props.participants) { const data = [/* @__PURE__ */ import_react.default.createElement("th", { key: participant }, participant)]; for (const scenario in this.props.scenarios) { data.push( /* @__PURE__ */ import_react.default.createElement("td", { key: participant + "_" + scenario }, /* @__PURE__ */ import_react.default.createElement("input", { type: "number", min: 0, max: 100, id: participant + "_" + scenario, onChange: this.updateRanking, value: this.props.rankings[participant][scenario] })) ); } rows.push(/* @__PURE__ */ import_react.default.createElement("tr", { key: participant }, data)); } let allScenariosTotal = 0; for (const scenario in this.props.scenarios) { scenarios.push(/* @__PURE__ */ import_react.default.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__ */ import_react.default.createElement("td", { key: scenario }, Math.trunc(scenarioTotals[scenario] / allScenariosTotal * 100), "%")); } return /* @__PURE__ */ import_react.default.createElement(import_Table.default, { bordered: true, hover: true }, /* @__PURE__ */ import_react.default.createElement("thead", null, /* @__PURE__ */ import_react.default.createElement("tr", null, /* @__PURE__ */ import_react.default.createElement("th", { key: "label" }, "Participant"), scenarios)), /* @__PURE__ */ import_react.default.createElement("tbody", null, rows, /* @__PURE__ */ import_react.default.createElement("tr", { key: "new" }, /* @__PURE__ */ import_react.default.createElement("td", null, /* @__PURE__ */ import_react.default.createElement(import_Button.default, { type: "button", onClick: this.props.addParticipant }, "Add Participant")))), /* @__PURE__ */ import_react.default.createElement("thead", null, /* @__PURE__ */ import_react.default.createElement("tr", null, relativeWeights))); } }; var ScenarioWeightingWorksheet = class extends import_react.default.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__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(ScenarioWeightingTitleBlock, { operationName: this.state.operationName }), /* @__PURE__ */ import_react.default.createElement(ScenarioWeightingScenarioNames, { scenarios: this.state.scenarios, addScenario: this.addScenario, updateScenarioName: this.updateScenarioName }), /* @__PURE__ */ import_react.default.createElement( ScenarioWeightingWeightings, { scenarios: this.state.scenarios, participants: this.state.participants, addParticipant: this.addParticipant, rankings: this.state.rankings, updateRanking: this.updateRanking } )); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ScenarioWeightingWorksheet }); //# sourceMappingURL=scenario-weighting-worksheet.js.map