Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | 736x 736x 736x 736x 217x 519x 519x 519x 519x 23x 1275x 661x 148x 148x 148x 29x 148x 291x 291x 291x 29x 291x 222x 222x 222x 29x 222x 114x 114x 114x 9x 114x 114x 114x 29x 114x 23x 124x 29x 1x 1x 387x 78x 78x 110x 22x | /**
* @prettier
*/
/*
* Part of Pleiar.no - a collection of tools for nurses
*
* Copyright (C) Eskild Hustvedt 2017-2018
* Copyright (C) Fagforbundet 2019
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// @flow
import * as React from "react";
import { Row, Col, Input, Label } from "reactstrap";
import { connect } from "react-redux";
import { toggleRounding, toggleFormulaVisibility } from "../actions/global";
import type { pleiarReduxState } from "../reducers/root";
type CalcExplanationEntryPropsFromRedux = {|
formulaVisibility: boolean,
|};
type CalcExplanationType = "description" | "formula" | "calculation";
type CalcExplanationEntryOwnProps = {|
children?: React.Node,
className: string,
lg: number,
type: CalcExplanationType,
|};
type CalcExplanationEntryProps = {|
...CalcExplanationEntryOwnProps,
...CalcExplanationEntryPropsFromRedux,
|};
/**
* Lowest level of a CalcExplanationLine, outputs the column if needed
*/
class CalcExplanationEntryUnconnected extends React.PureComponent<CalcExplanationEntryProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const { formulaVisibility, children, lg, type } = this.props;
let className: string = this.props.className;
className += " calcExplanationEntry";
if (!formulaVisibility && type === "formula") {
return <div />;
}
const xsWidthValues = {
formulaVisible: {
description: 5,
calculation: 3,
formula: 4,
},
formulaHidden: {
description: 7,
calculation: 5,
formula: 0,
},
};
const xsWidthSource = formulaVisibility
? "formulaVisible"
: "formulaHidden";
const xsWidth: number = xsWidthValues[xsWidthSource][type];
return (
<Col xs={xsWidth} lg={lg} className={className}>
{children}
</Col>
);
}
}
const CalcExplanationEntry: React.AbstractComponent<CalcExplanationEntryOwnProps> =
connect<
CalcExplanationEntryProps,
CalcExplanationEntryOwnProps,
CalcExplanationEntryPropsFromRedux,
_,
pleiarReduxState,
_,
>(
(state: pleiarReduxState): CalcExplanationEntryPropsFromRedux => {
return {
formulaVisibility: state.global.formulaVisibility,
};
},
() => {
return {};
},
)(CalcExplanationEntryUnconnected);
type CalcExplanationDescriptionProps = {|
children?: React.Node,
header?: boolean,
|};
/**
* The description of a calculation
*/
class CalcExplanationDescription extends React.PureComponent<CalcExplanationDescriptionProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const { header, children } = this.props;
let className: string = "calcDescription-desc";
if (header) {
className = "header";
}
return (
<CalcExplanationEntry
type="description"
className={className}
lg={5}
>
{children}
</CalcExplanationEntry>
);
}
}
type CalcExplanationCalculationProps = {|
children?: React.Node,
header?: boolean,
|};
/**
* The description of a calculation
*/
class CalcExplanationCalculation extends React.PureComponent<CalcExplanationCalculationProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const { header, children } = this.props;
let className: string = "calcCalculation-calc calculation";
if (header) {
className = "header";
}
return (
<CalcExplanationEntry
type="calculation"
className={className}
lg={4}
>
{children}
</CalcExplanationEntry>
);
}
}
type CalcExplanationFormulaProps = {|
children?: React.Node,
header?: boolean,
|};
/**
* The description of a calculation
*/
class CalcExplanationFormula extends React.PureComponent<CalcExplanationFormulaProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const { header, children } = this.props;
let className: string = "calcFormula formula";
if (header) {
className = "header";
}
return (
<CalcExplanationEntry type="formula" className={className} lg={3}>
{children}
</CalcExplanationEntry>
);
}
}
type CalcExplanationOwnProps = {|
children: React.Node,
hasAdditionalCalculations?: boolean,
additionalCalculationsToggle?: () => mixed,
additionalCalculations?: boolean,
|};
type CalcExplanationReduxStateProps = {|
rounding: boolean,
formulaVisibility: boolean,
|};
type CalcExplanationReduxDispatchProps = {|
onToggleRounding: () => mixed,
onToggleFormulaVisibility: () => mixed,
|};
type CalcExplanationProps = {|
...CalcExplanationOwnProps,
...CalcExplanationReduxStateProps,
...CalcExplanationReduxDispatchProps,
|};
/**
* Root element of a line of calculation explanations
*/
class CalcExplanationUnconnected extends React.PureComponent<CalcExplanationProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const checkboxes = [];
let className: string = "calculator-descriptions";
if (this.props.formulaVisibility === true) {
className += " mobileOverflowScrolling";
}
checkboxes.push(
<Label
check
className="roundingToggle ml-2 ml-sm-0"
key="precision"
>
<Input
type="checkbox"
checked={!this.props.rounding}
onChange={this.props.onToggleRounding}
/>{" "}
Vis tal med full presisjon
</Label>,
);
checkboxes.push(
<Label
check
className="ml-4 ml-sm-2 formulaVisibilityToggle"
key="formulas"
>
<Input
type="checkbox"
checked={this.props.formulaVisibility}
onChange={this.props.onToggleFormulaVisibility}
/>{" "}
Vis formlar
</Label>,
);
if (this.props.hasAdditionalCalculations) {
checkboxes.push(
<Label
check
className="ml-4 ml-sm-2 additionalCalculationsToggle"
key="additionalCalculations"
>
<Input
type="checkbox"
checked={this.props.additionalCalculations}
onChange={this.props.additionalCalculationsToggle}
/>{" "}
Vis utrekning av «andre tidseiningar»
</Label>,
);
}
return (
<div className={className}>
<Row className="mt-5 text-muted">
<Col>
<h5>Utrekning</h5>
<small>
<Row>
<Col className="form-inline">{checkboxes}</Col>
</Row>
<CalcExplanationLine>
<CalcExplanationDescription header={true}>
Skildring
</CalcExplanationDescription>
<CalcExplanationCalculation header={true}>
Utrekning
</CalcExplanationCalculation>
<CalcExplanationFormula header={true}>
Formel
</CalcExplanationFormula>
</CalcExplanationLine>
{this.props.children}
</small>
</Col>
</Row>
</div>
);
}
}
const CalcExplanation: React.AbstractComponent<CalcExplanationOwnProps> =
connect<
CalcExplanationProps,
CalcExplanationOwnProps,
CalcExplanationReduxStateProps,
CalcExplanationReduxDispatchProps,
_,
_,
>(
(state): CalcExplanationReduxStateProps => {
return {
formulaVisibility: state.global.formulaVisibility,
rounding: state.global.round,
};
},
(dispatch): CalcExplanationReduxDispatchProps => {
return {
onToggleRounding: () => {
dispatch(toggleRounding());
},
onToggleFormulaVisibility: () => {
dispatch(toggleFormulaVisibility());
},
};
},
)(CalcExplanationUnconnected);
type CalcExplanationLineProps = {|
children: React.Node,
|};
/**
* A line containing calculation descriptions
*/
class CalcExplanationLine extends React.PureComponent<CalcExplanationLineProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
return <Row className="calcDescription-row">{this.props.children}</Row>;
}
}
type FractionProps = {|
top: number | string,
bottom: number | string,
|};
/**
* A fraction
*/
class Fraction extends React.PureComponent<FractionProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
const { top, bottom } = this.props;
return (
<div className="fraction">
<div className="above">{top}</div>
<div className="below">{bottom}</div>
</div>
);
}
}
type FractionResultProps = {|
children: React.Node,
|};
/**
* The result of a fraction
*/
class FractionResult extends React.PureComponent<FractionResultProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
return <div className="fractionResult">{this.props.children}</div>;
}
}
type FractionComponentProps = {|
children: React.Node,
|};
/**
* The result of a fraction
*/
class FractionComponent extends React.PureComponent<FractionComponentProps> {
// eslint-disable-next-line require-jsdoc
render(): React.Node {
return <div className="fractionComponent">{this.props.children}</div>;
}
}
export {
CalcExplanation,
CalcExplanationLine,
CalcExplanationDescription,
CalcExplanationCalculation,
CalcExplanationFormula,
Fraction,
FractionResult,
FractionComponent,
};
|