Add param to hide financial preview on print

This commit is contained in:
wpetit 2020-04-23 13:40:20 +02:00
parent 52ffbde6ff
commit 9dd9167267
4 changed files with 26 additions and 6 deletions

View File

@ -15,6 +15,7 @@ export interface Params {
timeUnit: TimeUnit
currency: string
roundUpEstimations: boolean
hideFinancialPreviewOnPrint: boolean
}
export const defaults = {
@ -42,6 +43,7 @@ export const defaults = {
roundUpEstimations: true,
currency: "€ H.T.",
costPerTimeUnit: 500,
hideFinancialPreviewOnPrint: false,
}
export function getTimeUnit(project: Project): TimeUnit {
@ -62,4 +64,8 @@ export function getTaskCategories(project: Project): TaskCategoriesIndex {
export function getTaskCategoryCost(taskCategory: TaskCategory): number {
return taskCategory.hasOwnProperty("costPerTimeUnit") ? taskCategory.costPerTimeUnit : defaults.costPerTimeUnit;
}
export function getHideFinancialPreviewOnPrint(project: Project): boolean {
return project.params.hasOwnProperty("hideFinancialPreviewOnPrint") ? project.params.hideFinancialPreviewOnPrint : defaults.hideFinancialPreviewOnPrint;
}

View File

@ -23,10 +23,7 @@ export function newProject(id?: string): Project {
description: "",
tasks: {},
params: {
taskCategories: defaults.taskCategories,
currency: defaults.currency,
roundUpEstimations: defaults.roundUpEstimations,
timeUnit: defaults.timeUnit,
...defaults
},
};
}

View File

@ -6,6 +6,7 @@ import FinancialPreview from "./financial-preview";
import { addTask, updateTaskEstimation, removeTask, updateProjectLabel, updateTaskLabel, ProjectReducerActions } from "../../hooks/use-project-reducer";
import { Task, TaskID, EstimationConfidence } from "../../models/task";
import RepartitionPreview from "./repartition-preview";
import { getHideFinancialPreviewOnPrint } from "../../models/params";
export interface EstimationTabProps {
project: Project
@ -46,7 +47,7 @@ const EstimationTab: FunctionalComponent<EstimationTabProps> = ({ project, dispa
</div>
</div>
<div class="columns">
<div class="column">
<div class={`column ${getHideFinancialPreviewOnPrint(project) ? 'noPrint': ''}`}>
<FinancialPreview project={project} />
</div>
</div>

View File

@ -1,7 +1,7 @@
import { FunctionalComponent, h, Fragment } from "preact";
import { Project } from "../../models/project";
import { ProjectReducerActions, updateParam } from "../../hooks/use-project-reducer";
import { getRoundUpEstimations, getCurrency, getTimeUnit } from "../../models/params";
import { getRoundUpEstimations, getCurrency, getTimeUnit, getHideFinancialPreviewOnPrint } from "../../models/params";
import TaskCategoriesTable from "./task-categories-table";
import { useState } from "preact/hooks";
import { route } from "preact-router";
@ -25,6 +25,11 @@ const ParamsTab: FunctionalComponent<ParamsTabProps> = ({ project, dispatch }) =
dispatch(updateParam("roundUpEstimations", checked));
};
const onHideFinancialPreview = (evt: Event) => {
const checked = (evt.currentTarget as HTMLInputElement).checked;
dispatch(updateParam("hideFinancialPreviewOnPrint", checked));
};
const onCurrencyChange = (evt: Event) => {
const value = (evt.currentTarget as HTMLInputElement).value;
dispatch(updateParam("currency", value));
@ -50,6 +55,17 @@ const ParamsTab: FunctionalComponent<ParamsTabProps> = ({ project, dispatch }) =
return (
<Fragment>
<label class="label is-size-5">Impression</label>
<div class="field">
<input type="checkbox"
id="hideFinancialPreview"
name="hideFinancialPreview"
class="switch"
onChange={onHideFinancialPreview}
checked={getHideFinancialPreviewOnPrint(project)} />
<label for="hideFinancialPreview">Cacher le prévisionnel financier lors de l'impression</label>
</div>
<hr />
<div class="field">
<label class="label is-size-5">Unité de temps</label>
<div class="control">