diff --git a/src/app.html b/src/app.html index aaf59790f2c1d2e4b508bb49828f986118cc3b66..28d68aaee17afd183743e36ec5ee5550fae705af 100644 --- a/src/app.html +++ b/src/app.html @@ -7,6 +7,6 @@ %svelte.head% </head> <body> - <div id="svelte">%svelte.body%</div> + <div>%svelte.body%</div> </body> </html> diff --git a/src/hooks.ts b/src/hooks.ts index 25aa8695efc2a347a3f3fbcd18c5d473790a4492..e27db3c3a17ccfb9b2e4cd843e1e3f219c56d261 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,16 +1,13 @@ -import type { GetSession, Handle } from "@sveltejs/kit" +import type { GetSession } from "@sveltejs/kit" import config from "$lib/server/config" import { oauth2Authenticator } from "$lib/server/oauth2" -import type { Session } from "$lib/sessions" const { githubPersonalAccessToken, openfiscaRepository } = config -export const getSession: GetSession = async (request): Promise<Session> => { - const { user } = - oauth2Authenticator === undefined - ? { user: undefined } - : await oauth2Authenticator.getSession(request) +export const getSession: GetSession = async (event): Promise<App.Session> => { + const oauth2Session = await oauth2Authenticator?.getSession(event) + const user = oauth2Session?.user return { advanced: config.advanced, apiBaseUrls: config.apiBaseUrls, @@ -36,13 +33,3 @@ export const getSession: GetSession = async (request): Promise<Session> => { user, } } - -export const handle: Handle = async ({ request, resolve }) => { - // TODO https://github.com/sveltejs/kit/issues/1046 - const searchParams = request.url.searchParams - if (searchParams.has("_method")) { - request.method = searchParams.get("_method").toUpperCase() - } - - return await resolve(request) -} diff --git a/src/lib/components/ValueChangeCompare.svelte b/src/lib/components/ValueChangeCompare.svelte index 7a6928c4a9c8920c84e67cbb1c357fdd8d76da8e..5171985b77ce3034544e4839ddacc78769afdd81 100644 --- a/src/lib/components/ValueChangeCompare.svelte +++ b/src/lib/components/ValueChangeCompare.svelte @@ -87,7 +87,7 @@ <div class="flex flex-col"> {#if showLawValue0 || showLawValue1} {#if lawValue0Formatted === lawValue1Formatted} - <div class="flex flex-col justify-center"> + <div class="flex flex-col items-center"> <div class={showBillValue0 || showBillValue1 ? "line-through-bill text-2xl" @@ -123,14 +123,14 @@ </div> </div> {#if legend} - <div class="font-normal ml-1 mx-auto text-xs">(loi en vigueur)</div> + <div class="font-normal ml-1 self-center text-xs">(loi en vigueur)</div> {/if} {/if} {/if} {#if showBillValue0 || showBillValue1} <br /> {#if billValue0Formatted === billValue1Formatted} - <div class="flex flex-col justify-center"> + <div class="flex flex-col items-center"> <div class="text-le-rouge-bill text-2xl" class:line-through-amendment={showAmendmentValue0 || @@ -160,7 +160,7 @@ </div> </div> {#if legend} - <div class="font-normal ml-1 mx-auto text-xs text-le-rouge-bill"> + <div class="font-normal ml-1 self-center text-xs text-le-rouge-bill"> (PLF/PLFSS) </div> {/if} @@ -169,7 +169,7 @@ {#if showAmendmentValue0 || showAmendmentValue1} <br /> {#if amendmentValue0Formatted === amendmentValue1Formatted} - <div class="flex flex-col justify-center"> + <div class="flex flex-col items-center"> <div class="text-black bg-le-jaune px-1 text-2xl"> {amendmentValue0Formatted} </div> @@ -189,7 +189,7 @@ </div> </div> {#if legend} - <div class="font-normal ml-1 mx-auto text-xs text-le-jaune-dark"> + <div class="font-normal ml-1 self-center text-xs text-le-jaune-dark"> (votre réforme) </div> {/if} diff --git a/src/lib/components/test_cases/TestCaseCompareModal.svelte b/src/lib/components/test_cases/TestCaseCompareModal.svelte index d88a79d59e70332aa29db8b7b6d70571bf1ee804..0e87e527e9c8c34b6768a2b165b0bd834a9f4013 100644 --- a/src/lib/components/test_cases/TestCaseCompareModal.svelte +++ b/src/lib/components/test_cases/TestCaseCompareModal.svelte @@ -11,16 +11,24 @@ import { getContext } from "svelte" import type { Writable } from "svelte/store" + import type { EvaluationByName } from "$lib/decompositions" import type { Situation } from "$lib/situations" + import type { ValuesByCalculationNameByVariableName } from "$lib/variables" export let isOpen = false + const evaluationByNameArray = getContext("evaluationByNameArray") as Writable< + EvaluationByName[] + > const testCaseIndex = getContext("testCaseIndex") as Writable<number> const testCaseToCompareIndex = getContext( "testCaseToCompareIndex", ) as Writable<number | undefined> let selectedTestCaseIndex = $testCaseToCompareIndex const testCases = getContext("testCases") as Writable<Situation[]> + const valuesByCalculationNameByVariableNameArray = getContext( + "valuesByCalculationNameByVariableNameArray", + ) as Writable<ValuesByCalculationNameByVariableName[]> function closeModal() { isOpen = false @@ -31,6 +39,23 @@ const duplicatedTestCase = deepCopy($testCases[$testCaseIndex]) duplicatedTestCase.title = `Copie de ${duplicatedTestCase.title}` $testCases = [...$testCases, duplicatedTestCase] + + const duplicatedEvaluationByName = deepCopy( + $evaluationByNameArray[$testCaseIndex], + ) + $evaluationByNameArray = [ + ...$evaluationByNameArray, + duplicatedEvaluationByName, + ] + + const duplicatedValuesByCalculationNameByVariableName = deepCopy( + $valuesByCalculationNameByVariableNameArray[$testCaseIndex], + ) + $valuesByCalculationNameByVariableNameArray = [ + ...$valuesByCalculationNameByVariableNameArray, + duplicatedValuesByCalculationNameByVariableName, + ] + isOpen = false } diff --git a/src/lib/components/test_cases/TestCaseCompareView.svelte b/src/lib/components/test_cases/TestCaseCompareView.svelte index b9985813e35271b9ba8f8d56d76f8e3df8d459bc..1c6cda12175fddcff995fe0ea1f72388895fb822 100644 --- a/src/lib/components/test_cases/TestCaseCompareView.svelte +++ b/src/lib/components/test_cases/TestCaseCompareView.svelte @@ -602,68 +602,55 @@ </div> --> </div> {#if displayMode.parametersVariableName !== undefined && decompositionByName[displayMode.parametersVariableName] !== undefined} - <div class="flex justify-between gap-4 mt-2"> - <div class="flex-col "> - <p class="text-lg font-black mb-1"> - {decompositionByName[displayMode.parametersVariableName] - .ux_name ?? - decompositionByName[displayMode.parametersVariableName] - .label ?? - displayMode.parametersVariableName} : - </p> - <div class="text-2xl font-semibold"> - <ValueChangeCompare - unit={Unit.CurrencyEUR} - value0ByCalculationName={{ - amendment: - Object.keys($parametricReform).length === 0 - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["amendment"] - ?.deltaAtVectorIndex ?? 0, - bill: - $billName === undefined - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["bill"] - ?.deltaAtVectorIndex ?? 0, - law: - evaluationByName[displayMode.parametersVariableName] - ?.calculationEvaluationByName["law"] - ?.deltaAtVectorIndex ?? 0, - }} - value1ByCalculationName={{ - amendment: - Object.keys($parametricReform).length === 0 - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["amendment"] - ?.deltaAtVectorIndex ?? 0, - bill: - $billName === undefined - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["bill"] - ?.deltaAtVectorIndex ?? 0, - law: - evaluationByName[displayMode.parametersVariableName] - ?.calculationEvaluationByName["law"] - ?.deltaAtVectorIndex ?? 0, - }} - /> - </div> + <div class="flex-col mt-2"> + <p class="text-lg font-black mb-1"> + {decompositionByName[displayMode.parametersVariableName] + .ux_name ?? + decompositionByName[displayMode.parametersVariableName] + .label ?? + displayMode.parametersVariableName} : + </p> + <div class="text-2xl font-semibold"> + <ValueChangeCompare + unit={Unit.CurrencyEUR} + value0ByCalculationName={{ + amendment: + Object.keys($parametricReform).length === 0 + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["amendment"] + ?.deltaAtVectorIndex ?? 0, + bill: + $billName === undefined + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["bill"] + ?.deltaAtVectorIndex ?? 0, + law: + evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["law"] + ?.deltaAtVectorIndex ?? 0, + }} + value1ByCalculationName={{ + amendment: + Object.keys($parametricReform).length === 0 + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["amendment"] + ?.deltaAtVectorIndex ?? 0, + bill: + $billName === undefined + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["bill"] + ?.deltaAtVectorIndex ?? 0, + law: + evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["law"] + ?.deltaAtVectorIndex ?? 0, + }} + /> </div> - - <!-- <div class="flex-col w-1/2"> - <p class="text-gray-500 font-bold ">Détail dispositif</p> - <p class="text-base">1000 €</p> - <p class="text-gray-500 font-bold ">Détail dispositif</p> - <p class="text-base">1000 €</p> - </div> --> </div> {/if} </div> diff --git a/src/lib/components/test_cases/TestCaseView.svelte b/src/lib/components/test_cases/TestCaseView.svelte index 49ccb5added9e333aade67d6e817f394e72d59b2..aceb5335d384a9127dc3dfdadf57eea2df910c87 100644 --- a/src/lib/components/test_cases/TestCaseView.svelte +++ b/src/lib/components/test_cases/TestCaseView.svelte @@ -469,48 +469,37 @@ </div> --> </div> {#if displayMode.parametersVariableName !== undefined && decompositionByName[displayMode.parametersVariableName] !== undefined} - <div class="flex justify-between gap-4 mt-2"> - <div class="flex-col "> - <p class="text-lg font-black mb-1"> - {decompositionByName[displayMode.parametersVariableName] - .ux_name ?? - decompositionByName[displayMode.parametersVariableName] - .label ?? - displayMode.parametersVariableName} : - </p> - <div class="text-2xl font-semibold"> - <ValueChange - unit={Unit.CurrencyEUR} - valueByCalculationName={{ - amendment: - Object.keys($parametricReform).length === 0 - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["amendment"] - ?.deltaAtVectorIndex ?? 0, - bill: - $billName === undefined - ? undefined - : evaluationByName[ - displayMode.parametersVariableName - ]?.calculationEvaluationByName["bill"] - ?.deltaAtVectorIndex ?? 0, - law: - evaluationByName[displayMode.parametersVariableName] - ?.calculationEvaluationByName["law"] - ?.deltaAtVectorIndex ?? 0, - }} - /> - </div> + <div class="flex-col mt-2"> + <p class="text-lg font-black mb-1"> + {decompositionByName[displayMode.parametersVariableName] + .ux_name ?? + decompositionByName[displayMode.parametersVariableName] + .label ?? + displayMode.parametersVariableName} : + </p> + <div class="text-2xl font-semibold"> + <ValueChange + unit={Unit.CurrencyEUR} + valueByCalculationName={{ + amendment: + Object.keys($parametricReform).length === 0 + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["amendment"] + ?.deltaAtVectorIndex ?? 0, + bill: + $billName === undefined + ? undefined + : evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["bill"] + ?.deltaAtVectorIndex ?? 0, + law: + evaluationByName[displayMode.parametersVariableName] + ?.calculationEvaluationByName["law"] + ?.deltaAtVectorIndex ?? 0, + }} + /> </div> - - <!-- <div class="flex-col w-1/2"> - <p class="text-gray-500 font-bold ">Détail dispositif</p> - <p class="text-base">1000 €</p> - <p class="text-gray-500 font-bold ">Détail dispositif</p> - <p class="text-base">1000 €</p> - </div> --> </div> {/if} </div> diff --git a/src/lib/server/oauth2.ts b/src/lib/server/oauth2.ts index e6ae036719bcdac8234642f1c0d1643fbce152d7..d7e2d77f2c190c35b47fbd876c787efa302ec063 100644 --- a/src/lib/server/oauth2.ts +++ b/src/lib/server/oauth2.ts @@ -2,9 +2,8 @@ import { SvelteKitAuth } from "sk-auth" import { OAuth2Provider } from "sk-auth/providers" import config from "$lib/server/config" -import type { User } from "$lib/users" -type Profile = User +type Profile = App.User interface Tokens { access_token: string diff --git a/src/lib/sessions.ts b/src/lib/sessions.ts deleted file mode 100644 index c28aa6161f07301565bffbac7a4a6a4a4629fc7a..0000000000000000000000000000000000000000 --- a/src/lib/sessions.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { User } from "$lib/users" - -export interface Session { - advanced: boolean - apiBaseUrls: string[] - apiWebSocketBaseUrls: string[] - baseUrl: string - authenticationEnabled: boolean - childrenKey: string - familyEntityKey: string - hasGithubPersonalAccessToken: boolean - hiddenEntitiesKeyPlural?: string[] - matomo?: { - prependDomain?: boolean - siteId: number - subdomains?: string - url: string - } - openfiscaRepository: SessionOpenFiscaRepository - portalUrl: string - reformName?: string - showTutorial?: boolean - title: string - user?: User -} - -export interface SessionOpenFiscaRepository { - branch: string - group: string - project: string - rawUrlTemplate: string - urlTemplate: string -} diff --git a/src/lib/users.ts b/src/lib/users.ts deleted file mode 100644 index 19b723dc090dc704a879a7164dbce2c061d9638f..0000000000000000000000000000000000000000 --- a/src/lib/users.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface User { - email: string // "john@doe.com" - email_verified: boolean - family_name: string // "Doe" - given_name: string // "John" - last_name: string // "Doe" - locale: string // "fr" - name: string // "John Doe" - preferred_username: string // "jdoe", - roles?: string[] // [ 'offline_access', 'default-roles-leximpact', 'uma_authorization' ], - sub: string // "12345678-9abc-def0-1234-56789abcdef0" -} diff --git a/src/routes/__error.svelte b/src/routes/__error.svelte index b7c5ca2e5fa6efe5eca90da81786a4cc5de6c3cc..711384de8c646f199eb40ceb2f49cbcd1039068a 100644 --- a/src/routes/__error.svelte +++ b/src/routes/__error.svelte @@ -1,7 +1,7 @@ <script context="module" lang="ts"> - import type { ErrorLoadInput, LoadOutput } from "@sveltejs/kit" + import type { ErrorLoad } from "@sveltejs/kit" - export function load({ error, status }: ErrorLoadInput): LoadOutput { + export const load: ErrorLoad = function ({ error, status }) { return { props: { title: `${status}: ${error.message}`, diff --git a/src/routes/parameters/[parameter]/edit.svelte b/src/routes/parameters/[parameter]/edit.svelte index 1fc1821f5e6ac59b2bc2e69d93f68ba618f67b28..77f4393ae40719d5a78434b476407864e3b960cc 100644 --- a/src/routes/parameters/[parameter]/edit.svelte +++ b/src/routes/parameters/[parameter]/edit.svelte @@ -5,7 +5,7 @@ iterParameterAncestors, ParameterClass, } from "@openfisca/json-model" - import type { LoadInput, LoadOutput } from "@sveltejs/kit" + import type { Load } from "@sveltejs/kit" import yaml from "js-yaml" import { @@ -13,13 +13,8 @@ labelFromParameterClass, rootParameter, } from "$lib/parameters" - import type { SessionOpenFiscaRepository } from "$lib/sessions" - export async function load({ - fetch, - params, - session, - }: LoadInput): Promise<LoadOutput> { + export const load: Load = async function ({ fetch, params, session }) { const { parameter: name } = params const processedParameter = getParameter(rootParameter, name) if (processedParameter === undefined) { @@ -77,7 +72,7 @@ } export function newParameterRepositoryRawUrl( - { branch, group, project, rawUrlTemplate }: SessionOpenFiscaRepository, + { branch, group, project, rawUrlTemplate }: App.SessionOpenFiscaRepository, parameter: Parameter, ): string | undefined { const path = parameter.file_path diff --git a/src/routes/parameters/[parameter]/index.svelte b/src/routes/parameters/[parameter]/index.svelte index d8f491efcdf217fa79a04b5686468ffbb1aa6b84..3f6b2871867f292632c7b64a1890e608350e0e57 100644 --- a/src/routes/parameters/[parameter]/index.svelte +++ b/src/routes/parameters/[parameter]/index.svelte @@ -1,9 +1,9 @@ <script context="module" lang="ts"> - import type { LoadInput, LoadOutput } from "@sveltejs/kit" + import type { Load } from "@sveltejs/kit" import { getParameter, rootParameter } from "$lib/parameters" - export function load({ params }: LoadInput): LoadOutput { + export const load: Load = function ({ params }) { const { parameter: name } = params const parameter = getParameter(rootParameter, name) if (parameter === undefined) { diff --git a/src/routes/simulations/[simulation].svelte b/src/routes/simulations/[simulation].svelte index 1b2e87c7fb1f8c279447dce2727fba92166c3c13..57966e98c3c6856275f62fe218b322ad3d42cfcc 100644 --- a/src/routes/simulations/[simulation].svelte +++ b/src/routes/simulations/[simulation].svelte @@ -1,10 +1,7 @@ <script context="module" lang="ts"> - import type { LoadInput, LoadOutput } from "@sveltejs/kit" + import type { Load } from "@sveltejs/kit" - export async function load({ - fetch, - params, - }: LoadInput): Promise<LoadOutput> { + export const load: Load = async function ({ fetch, params }) { const { simulation: token } = params const urlString = `/simulations/${token}.json` const res = await fetch(urlString) diff --git a/src/routes/variables/[variable]/index.svelte b/src/routes/variables/[variable]/index.svelte index 081195b927f09a05c4a73ee98c15bc0b6271c790..1c3ccec2b8ec1fcbb2fd7fa7632e2dd82b401510 100644 --- a/src/routes/variables/[variable]/index.svelte +++ b/src/routes/variables/[variable]/index.svelte @@ -1,10 +1,7 @@ <script context="module" lang="ts"> - import type { LoadInput, LoadOutput } from "@sveltejs/kit" + import type { Load } from "@sveltejs/kit" - export async function load({ - fetch, - params, - }: LoadInput): Promise<LoadOutput> { + export const load: Load = async function ({ fetch, params }) { const { variable: name } = params const urlString = `/variables/${name}.json` const res = await fetch(urlString) diff --git a/src/routes/variables/[variable]/inputs/[date].svelte b/src/routes/variables/[variable]/inputs/[date].svelte index 84aee505278e0260935c6f45db20ba34be119517..d8fdd8a75a727c0b60a3274f04964a19f4044569 100644 --- a/src/routes/variables/[variable]/inputs/[date].svelte +++ b/src/routes/variables/[variable]/inputs/[date].svelte @@ -1,12 +1,12 @@ <script context="module" lang="ts"> - import type { LoadInput, LoadOutput } from "@sveltejs/kit" + import type { Load } from "@sveltejs/kit" import { iterVariableInputVariables, variableSummaryByName, } from "$lib/variables" - export function load({ params }: LoadInput): LoadOutput { + export const load: Load = function ({ params }) { const { date, variable: name } = params const variable = variableSummaryByName[name] if (variable === undefined) { diff --git a/svelte.config.js b/svelte.config.js index f0be0c52d8af6ebfa41cd8277c6bf3688a160356..38cf9a819f88415b66bade8607cc27245cf499b0 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -11,9 +11,6 @@ const config = { precompress: true, }), - // hydrate the <div id="svelte"> element in src/app.html - target: "#svelte", - vite: { build: { // Increase size of chunks to 5 MB, to be able to import