Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-legi-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
Exploration
leximpact-legi-ui
Commits
f876d902
Commit
f876d902
authored
2 months ago
by
David Smadja
Browse files
Options
Downloads
Patches
Plain Diff
Get first article when link points to LEGITEXT
parent
a8ddce3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/routes/api/article/[article]/+server.ts
+50
-3
50 additions, 3 deletions
src/routes/api/article/[article]/+server.ts
src/routes/bill/[bill]/+page.svelte
+9
-1
9 additions, 1 deletion
src/routes/bill/[bill]/+page.svelte
with
59 additions
and
4 deletions
src/routes/api/article/[article]/+server.ts
+
50
−
3
View file @
f876d902
...
...
@@ -6,15 +6,62 @@ interface queryDataArticle {
data
:
LegiArticle
}
interface
queryFirstArticle
{
premier_article_id
:
string
}
export
const
GET
:
RequestHandler
=
async
({
params
,
locals
})
=>
{
const
{
article
}
=
params
as
{
article
:
string
}
const
{
article
:
requestedArticle
}
=
params
as
{
article
:
string
}
const
{
sql
}
=
locals
const
dbConnection
=
await
sql
.
reserve
()
let
articleTxtFromDb
:
queryDataArticle
[]
=
[]
if
(
requestedArticle
.
startsWith
(
"
LEGITEXT
"
))
{
const
[
firstArticle
]:
[
queryFirstArticle
?]
=
await
dbConnection
<
queryFirstArticle
>
`
WITH RECURSIVE section_hierarchy AS (
SELECT
element->>'@id' as section_id,
ARRAY[ordinality] as path_array,
1 as depth
FROM textelr,
jsonb_array_elements(data->'STRUCT'->'LIEN_SECTION_TA')
WITH ORDINALITY as t(element, ordinality)
WHERE element->>'@etat' = 'VIGUEUR'
AND id =
${
requestedArticle
}
UNION ALL
SELECT
sub_element->>'@id' as section_id,
sh.path_array || sub_ordinality::int as path_array,
sh.depth + 1
FROM section_hierarchy sh
JOIN section_ta st ON st.id = sh.section_id
CROSS JOIN jsonb_array_elements(st.data->'STRUCTURE_TA'->'LIEN_SECTION_TA')
WITH ORDINALITY as sub_t(sub_element, sub_ordinality)
WHERE sub_element->>'@etat' = 'VIGUEUR'
AND sh.depth < 10
AND st.data @? '$.STRUCTURE_TA.LIEN_SECTION_TA[*] ? (@."@etat" == "VIGUEUR")'
)
SELECT
st.data #>> '{STRUCTURE_TA,LIEN_ART,0,@id}' as premier_article_id
FROM section_hierarchy sh
JOIN section_ta st ON st.id = sh.section_id
WHERE st.data @? '$.STRUCTURE_TA.LIEN_ART[0] ? (@."@etat" == "VIGUEUR")'
ORDER BY sh.path_array
LIMIT 1;`
const
articleTxtFromDb
:
queryDataArticle
[]
=
await
dbConnection
<
JSON
>
`
articleTxtFromDb
=
await
dbConnection
<
JSON
>
`
select data
from article
where id=
${
article
}
`
where id=
${
firstArticle
?.
premier_article_id
}
`
}
else
if
(
requestedArticle
.
startsWith
(
"
LEGIARTI
"
))
{
articleTxtFromDb
=
await
dbConnection
<
JSON
>
`
select data
from article
where id=
${
requestedArticle
}
`
}
dbConnection
.
release
()
if
(
articleTxtFromDb
.
length
===
1
)
{
...
...
This diff is collapsed.
Click to expand it.
src/routes/bill/[bill]/+page.svelte
+
9
−
1
View file @
f876d902
...
...
@@ -8,6 +8,7 @@
let
activePanel
:
"
bill
"
|
"
law
"
=
"
bill
"
let
screenWidth
=
$state
(
1024
)
let
isMobilePhone
=
$derived
(
screenWidth
<
768
)
let
isFetchingArticle
=
$state
(
false
)
let
{
data
}:
PageProps
=
$props
()
...
...
@@ -17,9 +18,13 @@
$effect
(()
=>
{
if
(
lawArticle
)
{
isFetchingArticle
=
true
fetch
(
`/api/article/
${
lawArticle
}
`
)
.
then
((
res
)
=>
(
res
.
ok
?
res
.
json
()
:
null
))
.
then
((
data
)
=>
(
articleJson
=
data
))
.
then
((
data
)
=>
{
isFetchingArticle
=
false
articleJson
=
data
})
.
catch
(()
=>
(
lawArticle
=
""
))
}
else
{
articleJson
=
undefined
...
...
@@ -31,6 +36,9 @@
<div
class=
"fixed flex min-h-full w-full flex-row overflow-hidden"
>
<div
class=
"h-screen w-1/2 overflow-y-auto"
><Bill
{
billHTML
}
>
</Bill></div>
<div
class=
"h-screen w-1/2 overflow-y-auto bg-blue-100"
>
{
#if
isFetchingArticle
}
Article en cours de récupération...
{
/if
}
{
#if
articleJson
!==
undefined
}
<Article
{
articleJson
}
>
</Article>
{
:
else
}
...
...
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