Skip to content
Snippets Groups Projects
Select Git revision
  • 4169b58edf9887eabf6bb66a551cef874dee76f3
  • master default protected
  • suppression_allegements_specifiques
  • budgetaire_retraites_plf
  • doc-script-gen-off-tests
  • 366-signe-a-cote-du-droit-en-vigueur-sur-l-ui-pour-indiquer-que-la-reforme-a-eu-lieu-mais-qu-elle-n
  • revalo_retraites
  • 381-pb-affichage-labels-des-parametres-sur-plus-de-3-lignes
  • ajoute-duplicate-aide-logement
  • poc_castype_ia
  • parametres-editables-budget
  • ui-parametres
  • 355-les-dispositifs-prestations-sociales-du-graphique-se-cachent-montrent-en-meme-temps-2
  • 358-les-variables-dont-le-montant-est-nul-apparaissent-en-bleu-et-non-cliquables
  • 356-ajuster-la-largeur-sur-les-graphiques-budgetaires
  • incoherence_cas_type_0
  • fix-ui-suppression-tranches-baremes
  • ajout-agregat-cehr-version-plf
  • impact_carbone
  • xlsx
  • header_revamp
  • 0.0.1191
  • 0.0.1190
  • 0.0.1189
  • 0.0.1188
  • 0.0.1187
  • 0.0.1186
  • 0.0.1185
  • 0.0.1184
  • 0.0.1183
  • 0.0.1182
  • 0.0.1181
  • 0.0.1180
  • 0.0.1179
  • 0.0.1178
  • 0.0.1177
  • 0.0.1176
  • 0.0.1175
  • 0.0.1174
  • 0.0.1173
  • 0.0.1172
41 results

urls.ts

Blame
  • urls.ts 2.71 KiB
    import { waterfalls } from "$lib/decompositions"
    import type { DisplayMode } from "$lib/displays"
    
    export interface SelfTargetAProps {
      href: string
      "data-sveltekit-noscroll"?: boolean
    }
    
    export function newSelfTargetAProps(url: string): SelfTargetAProps {
      return {
        href: url,
      }
    }
    
    export function newSimulationUrl(displayMode: DisplayMode): string {
      const parametersQuery: URLSearchParams = new URLSearchParams()
      if (displayMode.budget) {
        parametersQuery.append("budget", "true")
      }
      if (displayMode.edit !== undefined) {
        parametersQuery.append("edit", displayMode.edit.toString())
      }
      if (displayMode.mobileLaw) {
        parametersQuery.append("law", "true")
      }
      if (
        displayMode.testCasesIndex !== undefined &&
        (displayMode.testCasesIndex.length !== 1 ||
          displayMode.testCasesIndex[0] !== 0)
      ) {
        for (const testCaseIndex of displayMode.testCasesIndex) {
          parametersQuery.append("test_case", testCaseIndex.toString())
        }
      }
      if (displayMode.variableName !== undefined) {
        parametersQuery.append("variable", displayMode.variableName)
      }
      if (displayMode.parameterName !== undefined) {
        parametersQuery.append("parameter", displayMode.parameterName)
      }
      if (displayMode.parametersVariableName !== undefined) {
        parametersQuery.append("parameters", displayMode.parametersVariableName)
      }
      if (
        displayMode.waterfallName !== undefined &&
        displayMode.waterfallName !== waterfalls[0].name
      ) {
        parametersQuery.append("waterfall", displayMode.waterfallName)
      }
      if (displayMode.tab !== undefined) {
        parametersQuery.append("tab", displayMode.tab)
      }
      const parametersQueryString = parametersQuery.toString()
    
      const hashesQuery: URLSearchParams = new URLSearchParams()
      if (displayMode.parameterHash !== undefined) {
        hashesQuery.append("parameterHash", displayMode.parameterHash)
      }
      const hashesQueryString = hashesQuery.toString()
    
      return `/${parametersQueryString ? "?" + parametersQueryString : ""}${
        hashesQueryString ? "#" + hashesQueryString : ""
      }`
    }
    
    export function stringifyQuery(queryParameters?: {
      [key: string]: string | string[]
    }): string {
      return Object.entries(queryParameters ?? {})
        .reduce(
          (
            queryArray: string[],
            [key, value]: [string, string | string[]],
          ): string[] => {
            if (Array.isArray(value)) {
              for (const item of value) {
                queryArray.push(
                  `${encodeURIComponent(key)}=${encodeURIComponent(item)}`,
                )
              }
            } else {
              queryArray.push(
                `${encodeURIComponent(key)}=${encodeURIComponent(value ?? "")}`,
              )
            }
            return queryArray
          },
          [],
        )
        .join("&")
        .replace(/\s/g, "+")
    }