Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-socio-fiscal-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
leximpact-socio-fiscal-ui
Commits
a84ac6b0
Commit
a84ac6b0
authored
Sep 11, 2023
by
Emmanuel Raviart
Committed by
Toufic Batache
Sep 21, 2023
Browse files
Options
Downloads
Patches
Plain Diff
WIP d'envoi d'email de demande
parent
e1219404
No related branches found
No related tags found
1 merge request
!174
Ajout des demandes du calcul budget
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lib/components/BudgetConnexionModal.svelte
+81
-2
81 additions, 2 deletions
src/lib/components/BudgetConnexionModal.svelte
src/routes/+page.svelte
+4
-1
4 additions, 1 deletion
src/routes/+page.svelte
src/routes/budget/demande/+server.ts
+103
-0
103 additions, 0 deletions
src/routes/budget/demande/+server.ts
with
188 additions
and
3 deletions
src/lib/components/BudgetConnexionModal.svelte
+
81
−
2
View file @
a84ac6b0
...
@@ -10,14 +10,20 @@
...
@@ -10,14 +10,20 @@
import
{
browser
}
from
"
$app/environment
"
import
{
browser
}
from
"
$app/environment
"
import
{
goto
}
from
"
$app/navigation
"
import
{
goto
}
from
"
$app/navigation
"
import
{
page
}
from
"
$app/stores
"
import
{
page
}
from
"
$app/stores
"
import
type
{
DisplayMode
}
from
"
$lib/displays
"
import
{
import
{
trackBudgetPublicSimulation
,
trackBudgetPublicSimulation
,
trackBudgetSignInButton
,
trackBudgetSignInButton
,
}
from
"
$lib/matomo
"
}
from
"
$lib/matomo
"
import
type
{
ParametricReform
}
from
"
$lib/reforms
"
import
type
{
CachedSimulation
}
from
"
$lib/simulations
"
import
type
{
CachedSimulation
}
from
"
$lib/simulations
"
export
let
displayMode
:
DisplayMode
export
let
isOpen
=
false
export
let
isOpen
=
false
const
budgetSimulation
=
getContext
(
"
budgetSimulation
"
)
as
Writable
<
BudgetSimulation
|
undefined
>
let
cachedSimulations
:
CachedSimulation
[]
=
[]
let
cachedSimulations
:
CachedSimulation
[]
=
[]
$
:
if
(
browser
&&
isOpen
)
{
$
:
if
(
browser
&&
isOpen
)
{
...
@@ -39,6 +45,36 @@
...
@@ -39,6 +45,36 @@
function
onClose
()
{
function
onClose
()
{
isOpen
=
false
isOpen
=
false
}
}
async
function
sendSimulationRequest
()
{
const
urlString
=
"
/budget/demande
"
const
res
=
await
fetch
(
urlString
,
{
body
:
JSON
.
stringify
({
displayMode
,
parametricReform
:
Object
.
entries
(
$parametricReform
)
.
sort
(([
keyA
],
[
keyB
])
=>
keyA
.
localeCompare
(
keyB
))
.
reduce
((
filtered
:
ParametricReform
,
[
parameterName
,
value
])
=>
{
if
(
budgetEditableParametersName
.
has
(
parameterName
))
{
filtered
[
parameterName
]
=
value
}
return
filtered
},
{}),
}),
headers
:
{
Accept
:
"
application/json
"
,
"
Content-Type
"
:
"
application/json; charset=utf-8
"
,
},
method
:
"
POST
"
,
})
if
(
!
res
.
ok
)
{
console
.
error
(
`Error
${
res
.
status
}
while sending a simulation request at
${
urlString
}
\n\n
${
await
res
.
text
()}
`
,
)
return
}
}
</script>
</script>
<Transition
appear
show=
{
isOpen
}
>
<Transition
appear
show=
{
isOpen
}
>
...
@@ -154,8 +190,34 @@
...
@@ -154,8 +190,34 @@
<div
<div
class=
"flex md:flex-row flex-col w-full px-0 md:px-10 items-center gap-5"
class=
"flex md:flex-row flex-col w-full px-0 md:px-10 items-center gap-5"
>
>
==== BASE ====
Voir la simulation
<iconify-icon
class=
"align-[-0.25rem] text-xl"
icon=
"ri-arrow-right-line"
/>
</a>
</div>
{
/if
}
<div
class=
"flex flex-col gap-10 bg-gray-100 p-5 border-t mt-10"
>
{
#if
currentSimulationCache === undefined
}
<div>
<h2
class=
"w-full text-left text-2xl font-bold"
>
Demandez le calcul de votre réforme au service
LexImpact
:
</h2>
<p
class=
"w-full text-base font-normal leading-6 mt-1.5 mb-5"
>
Après vérification par nos services, si elle est calculable
avec les données dont nous disposons et répond au secret
statistique, la simulation sera rendue publique. Vous serez
alors informé par e-mail :
</p>
<span
class=
"font-bold text-sm py-2 pl-10"
>
Votre adresse e-mail :
</span
>
<div
<div
class=
"flex rounded-t-md border-b-2 border-b-black bg-white px-2 grow max-w-lg"
class=
"flex md:flex-row flex-col w-full px-0 md:px-10 items-center gap-5"
====
BASE =
===
>
>
<input
<input
autocomplete=
"off"
autocomplete=
"off"
...
@@ -178,9 +240,26 @@
...
@@ -178,9 +240,26 @@
class=
"ml-2 align-[-0.25rem] text-xl"
class=
"ml-2 align-[-0.25rem] text-xl"
icon=
"ri-send-plane-2-line"
icon=
"ri-send-plane-2-line"
/>
/>
==== BASE ====
</div>
<div>
<a
class=
"flex items-center gap-2 py-2 px-5 shadow-lg bg-white hover:bg-gray-100 active:bg-gray-200 rounded-md border-2 border-le-bleu text-le-bleu text-sm font-bold tracking-[0.085em] uppercase"
data-sveltekit-reload
href=
{
`/auth/login?redirect=$
{
encodeURIComponent(
$page.url.toString(),
)
}
`}
title=
"Envoyer votre réforme budgétaire avec cet e-mail"
>
Demander
le
calcul
<iconify-icon
class=
"ml-2 align-[-0.25rem] text-xl"
icon=
"ri-send-plane-2-line"
/>
</a>
</a>
</div>
</div>
</div>
</div>
==== BASE ====
</div>
</div>
</div>
{
#if
cachedSimulations !== undefined && cachedSimulations.length > 0
}
{
#if
cachedSimulations !== undefined && cachedSimulations.length > 0
}
<div
class=
"flex flex-col items-center"
>
<div
class=
"flex flex-col items-center"
>
...
...
This diff is collapsed.
Click to expand it.
src/routes/+page.svelte
+
4
−
1
View file @
a84ac6b0
...
@@ -1762,7 +1762,10 @@
...
@@ -1762,7 +1762,10 @@
</div>
</div>
</div>
</div>
<BudgetConnexionModal
bind:isOpen=
{
isBudgetConnexionModalOpen
}
/>
<BudgetConnexionModal
bind:isOpen=
{
isBudgetConnexionModalOpen
}
{
displayMode
}
/>
{
/if
}
{
/if
}
<!--Bouton flottant "simulation publique" -->
<!--Bouton flottant "simulation publique" -->
...
...
This diff is collapsed.
Click to expand it.
src/routes/budget/demande/+server.ts
0 → 100644
+
103
−
0
View file @
a84ac6b0
import
{
auditRequire
,
cleanAudit
,
type
Audit
}
from
"
@auditors/core
"
import
{
error
,
json
}
from
"
@sveltejs/kit
"
import
fs
from
"
fs-extra
"
import
path
from
"
path
"
import
{
getParameter
,
rootParameter
}
from
"
$lib/parameters
"
import
type
{
ParametricReform
}
from
"
$lib/reforms
"
import
config
from
"
$lib/server/config
"
import
type
{
CachedSimulation
}
from
"
$lib/simulations
"
import
type
{
RequestHandler
}
from
"
./$types
"
import
{
hashObject
}
from
"
$lib/hash
"
const
{
simulationsBudgetDir
}
=
config
function
auditBody
(
audit
:
Audit
,
dataUnknown
:
unknown
):
[
unknown
,
unknown
]
{
if
(
dataUnknown
==
null
)
{
return
[
dataUnknown
,
null
]
}
if
(
typeof
dataUnknown
!==
"
object
"
)
{
return
audit
.
unexpectedType
(
dataUnknown
,
"
object
"
)
}
const
data
=
{
...
dataUnknown
}
const
errors
:
{
[
key
:
string
]:
unknown
}
=
{}
const
remainingKeys
=
new
Set
(
Object
.
keys
(
data
))
audit
.
attribute
(
data
,
"
displayMode
"
,
true
,
errors
,
remainingKeys
,
// TODO
auditRequire
,
)
audit
.
attribute
(
data
,
"
parametricReform
"
,
true
,
errors
,
remainingKeys
,
// TODO
auditRequire
,
)
return
audit
.
reduceRemaining
(
data
,
errors
,
remainingKeys
)
}
export
const
POST
:
RequestHandler
=
async
({
request
,
url
})
=>
{
const
[
body
,
bodyError
]
=
auditBody
(
cleanAudit
,
await
request
.
json
())
if
(
bodyError
!==
null
)
{
console
.
error
(
`Error in
${
url
.
pathname
}
body:\n
${
JSON
.
stringify
(
body
,
null
,
2
,
)}
\n\nError:\n
${
JSON
.
stringify
(
bodyError
,
null
,
2
)}
`
,
)
throw
error
(
400
,
`Invalid body:
${
JSON
.
stringify
(
bodyError
,
null
,
2
)}
`
)
}
const
modifiedParametersTitles
=
Object
.
keys
(
(
body
as
{
parametricReform
:
ParametricReform
}).
parametricReform
,
).
map
((
parameterName
)
=>
getParameter
(
rootParameter
,
parameterName
)?.
title
)
const
modifiedParametersNames
=
Object
.
keys
(
(
body
as
{
parametricReform
:
ParametricReform
}).
parametricReform
,
).
map
((
parameterName
)
=>
getParameter
(
rootParameter
,
parameterName
)?.
name
)
const
bodyJson
=
JSON
.
stringify
(
body
,
null
,
2
)
const
digest
=
hashObject
(
(
body
as
{
parametricReform
:
ParametricReform
}).
parametricReform
,
)
const
simulationDir
=
path
.
join
(
simulationsBudgetDir
,
digest
.
substring
(
0
,
2
))
const
simulationFilePath
=
path
.
join
(
simulationDir
,
`
${
digest
}
.json`
)
if
(
!
(
await
fs
.
pathExists
(
simulationFilePath
)))
{
await
fs
.
ensureDir
(
simulationDir
)
await
fs
.
writeFile
(
simulationFilePath
,
bodyJson
)
}
const
indexDir
=
path
.
join
(
simulationsBudgetDir
,
"
index.json
"
)
const
indexContents
:
CachedSimulation
[]
=
(
await
fs
.
pathExists
(
indexDir
))
?
await
fs
.
readJson
(
indexDir
)
:
[]
const
contents
:
CachedSimulation
[]
=
[
...
indexContents
,
{
date
:
new
Intl
.
DateTimeFormat
(
"
fr-FR
"
).
format
(
new
Date
()),
hash
:
digest
,
parameters
:
modifiedParametersNames
,
title
:
modifiedParametersTitles
.
join
(
"
|
"
),
}
as
CachedSimulation
,
].
filter
(
(
value
,
index
,
self
)
=>
index
===
self
.
findLastIndex
((
el
)
=>
el
.
hash
===
value
.
hash
),
)
await
fs
.
writeFile
(
indexDir
,
JSON
.
stringify
(
contents
))
return
json
({
token
:
digest
})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment