Commit 751c2361 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add very preliminary search.

parent 0f166d7e
<section class="container mx-auto mx-2">
<form on:submit="search(event)">
<div class="flex flex-wrap items-stretch w-full">
<div class="flex -mr-px">
<span class="flex items-center leading-normal bg-teal-lightest rounded rounded-r-none border border-r-0 border-teal-light px-3 whitespace-no-wrap text-teal-dark text-sm"><i class="fas fa-search"></i></span>
</div>
<input class="border border-teal-light focus:border-blue flex-1 flex-auto flex-grow flex-shrink h-10 leading-normal w-px focus:shadow px-3 relative rounded rounded-l-none" placeholder="informatique et libertés…" type="text" bind:value="term">
<button class="bg-teal hover:bg-teal-dark font-bold ml-2 py-2 px-4 rounded text-white" type="submit">
Rechercher
</button>
</div>
</form>
</section>
<script>
import { goto } from "../../__sapper__/client"
import { buildSearchUrl } from "../strings"
export default {
data() {
return {
term: "",
}
},
methods: {
search(event) {
event.preventDefault()
const limit = 10
const { term } = this.get()
goto(buildSearchUrl("recherche", { limit, offset: 0, term }))
},
},
}
</script>
\ No newline at end of file
......@@ -63,6 +63,7 @@ const config = {
url: "a-propos",
},
],
searchUrl: "http://localhost:8005/",
senatApiUrl: "http://localhost:8004/",
title: "Tricoteuses",
url: ".",
......
......@@ -6,7 +6,7 @@ import { generateDossierAssemblee } from "./dossier"
export async function generateDossiersAssemblee(fs, path, uidsToSkip) {
const graphqlData = await assembleeGraphqlClient.query({
query: gql`
query uidsDossiersAssemblee($legislature: Int!) {
query UidsDossiersAssemblee($legislature: Int!) {
dossiersParlementaires(legislature: $legislature) {
... on DossierCommissionEnquete {
uid
......
......@@ -692,9 +692,7 @@ export function generateDossierParlementaireFragments({ withDocuments = false })
libelle
}
titreDossier {
titre
titreChemin
senatChemin
...TitreDossierFragment
}
uid
`
......@@ -715,6 +713,7 @@ export function generateDossierParlementaireFragments({ withDocuments = false })
...generateIndexationFragments(),
...generateInitiateurFragments(),
...generateOrganeFragments({ withParent: true }),
...generateTitreDossierFragments(),
[fragmentName]: `
fragment ${fragmentName} on DossierParlementaire {
... on DossierCommissionEnquete {
......@@ -1230,3 +1229,21 @@ export function generateTexteLoiFragments({ withDossier = false }) {
}
return fragments
}
export function generateTitreDossierFragments() {
let fragments = fragmentsCache.TitreDossierFragment
if (fragments === undefined) {
fragments = fragmentsCache.TitreDossierFragment = {
TitreDossierFragment: `
fragment TitreDossierFragment on TitreDossier {
titre
titreChemin
senatChemin
}
`
.trim()
.replace(/^ {6}/gm, ""),
}
}
return fragments
}
......@@ -2,6 +2,8 @@
<title>{config.title}</title>
</svelte:head>
<SearchForm {term}/>
<section class="mx-2">
<h1 class="my-4">Dossiers législatifs en cours</h1>
......@@ -179,9 +181,13 @@
import { colorFromEtaloilib } from "../model/senat/helpers"
export default {
components: {
SearchForm: "../components/SearchForm.html",
},
data() {
return {
legislature: 15,
term: "",
}
},
helpers: {
......
......@@ -14,14 +14,14 @@
<ListErrors {errors}/>
<form on:submit='submit(event)'>
<form on:submit="submit(event)">
<fieldset class="form-group">
<input class="form-control form-control-lg" type="email" placeholder="Email" bind:value=email>
</fieldset>
<fieldset class="form-group">
<input class="form-control form-control-lg" type="password" placeholder="Password" bind:value=password>
</fieldset>
<button class="btn btn-lg btn-primary pull-xs-right" type="submit" disabled='{!email || !password}'>
<button class="btn btn-lg btn-primary pull-xs-right" type="submit" disabled="{!email || !password}">
Sign in
</button>
</form>
......
<svelte:head>
<title>Recherche | {config.title}</title>
</svelte:head>
<SearchForm {term}/>
{#if hits && hits.length > 0}
<ul class="list-reset">
{#each hits as hit}
<li>
<a href="dossiers/assemblee/{hit.doc.uid}">{hit.doc.titre}</a>
</li>
{/each}
</ul>
{/if}
<script>
import resolveUrl from "url-resolve"
import config from "../config"
import { buildSearchUrl } from "../strings"
export default {
components: {
SearchForm: "../components/SearchForm.html",
},
helpers: {
config,
},
async preload({ /* params, */ query }) {
const term = query.q || ""
const url = buildSearchUrl(resolveUrl(config.searchUrl, "dossiers"), {
term: term,
})
let response = await this.fetch(url, {
credentials: "same-origin",
})
let result =
response.ok
? await response.json()
: { error: { code: response.status, message: await response.text() } }
if (result.error) {
console.log(`An error occured while calling ${url}:`, result)
}
return {
...result,
term,
}
},
}
</script>
\ No newline at end of file
......@@ -14,7 +14,7 @@
<ListErrors {errors}/>
<form on:submit='submit(event)'>
<form on:submit="submit(event)">
<fieldset class="form-group">
<input class="form-control form-control-lg" type="text" placeholder="Your Name" bind:value=username>
</fieldset>
......
export function buildSearchUrl(url, { limit = 10, offset = 0, term = "" }) {
let query = []
if (term) {
query.push(`q=${encodeURIComponent(term).replace("(", " ").replace(")", " ")}`)
}
if (offset !== 0) {
query.push(`offset=${offset}`)
}
if (limit !== 10) {
query.push(`limit=${limit}`)
}
query = query.join("&")
if (query) {
query = (url.includes("?") ? "&" : "?") + query
}
return url + query
}
export function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
......
......@@ -49,7 +49,7 @@ export function validateConfig(config) {
const errors = {}
const remainingKeys = new Set(Object.keys(config))
for (let key of ["amendaUrl", "assembleeApiUrl", "senatApiUrl"]) {
for (let key of ["amendaUrl", "assembleeApiUrl", "searchUrl", "senatApiUrl"]) {
remainingKeys.delete(key)
const [value, error] = validateUrl(config[key])
config[key] = value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment