Skip to content
Snippets Groups Projects
Commit 70f39b5d authored by jensilo's avatar jensilo
Browse files

make all templates visible upon opening search modal

parent fe0476b9
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,8 @@ type TemplateFormData struct { ...@@ -67,7 +67,8 @@ type TemplateFormData struct {
// SearchTemplateData contains templates to render as search results and a flag indicating if the query was too short. // SearchTemplateData contains templates to render as search results and a flag indicating if the query was too short.
type SearchTemplateData struct { type SearchTemplateData struct {
Templates []*template.Template Templates []*template.Template
// Deprecated this is expected to be unnecessary with the current implementation of EIFFEL
QueryTooShort bool QueryTooShort bool
} }
...@@ -181,8 +182,21 @@ func renderElicitationPage(io web.IO, data TemplateFormData, success []string, e ...@@ -181,8 +182,21 @@ func renderElicitationPage(io web.IO, data TemplateFormData, success []string, e
} }
func searchModal(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handler { func searchModal(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handler {
templateRepository := util.UnwrapType[template.Repository](appCtx.Repository(template.RepositoryName))
return web.NewController(appCtx, webCtx, func(io web.IO) error { return web.NewController(appCtx, webCtx, func(io web.IO) error {
return io.Render(nil, "eiffel.template.search.modal", "eiffel/_modal-template-search.go.html") ctx := io.Context()
templates, err := templateRepository.FindByQueryForTypeAndUser(ctx, "", BasicTemplateType, user.MustCtxUser(ctx))
if err != nil && !errors.Is(err, persistence.ErrNotFound) {
return io.InlineError(web.ErrInternal, err)
}
return io.Render(
&SearchTemplateData{Templates: templates},
"eiffel.template.search.modal",
"eiffel/_modal-template-search.go.html",
"eiffel/_template-search-result.go.html",
)
}) })
} }
...@@ -197,13 +211,7 @@ func searchTemplate(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handler { ...@@ -197,13 +211,7 @@ func searchTemplate(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handler {
} }
query := request.FormValue("search") query := request.FormValue("search")
if len(query) < 3 { // query too short was removed as it is expected to be unnecessary
return io.Render(
&SearchTemplateData{QueryTooShort: true},
"eiffel.template.search.result",
"eiffel/_template-search-result.go.html",
)
}
ctx := io.Context() ctx := io.Context()
templates, err := templateRepository.FindByQueryForTypeAndUser(ctx, query, BasicTemplateType, user.MustCtxUser(ctx)) templates, err := templateRepository.FindByQueryForTypeAndUser(ctx, query, BasicTemplateType, user.MustCtxUser(ctx))
......
{{ define "eiffel.template.search.modal" }} {{ define "eiffel.template.search.modal" }}
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-dialog-scrollable modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h1 class="modal-title fs-5" id="eiffelTemplateSearchLabel">{{ t "eiffel.elicitation.template.search.title" }}</h1> <h1 class="modal-title fs-5" id="eiffelTemplateSearchLabel">{{ t "eiffel.elicitation.template.search.title" }}</h1>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<div class="modal-body"> <div class="modal-body">
<div class="mb-3"> <div class="mb-3">
<input id="eiffelTemplateSearchInput" <input id="eiffelTemplateSearchInput"
name="search" type="search" class="form-control" name="search" type="search" class="form-control border-dark-subtle"
hx-post="/eiffel/elicitation/templates/search" hx-post="/eiffel/elicitation/templates/search"
hx-trigger="input changed delay:300ms, search" hx-trigger="input changed delay:300ms, search"
hx-target="#eiffelTemplateSearchResults" hx-target="#eiffelTemplateSearchResults"
...@@ -26,9 +26,13 @@ ...@@ -26,9 +26,13 @@
</tr> </tr>
</thead> </thead>
<tbody id="eiffelTemplateSearchResults"> <tbody id="eiffelTemplateSearchResults">
<tr> {{ if not .Data.Templates }}
<td class="text-center" colspan="4">{{ t "eiffel.elicitation.template.search.start" }}</td> <tr>
</tr> <td class="text-center" colspan="4">{{ t "eiffel.elicitation.template.search.start" }}</td>
</tr>
{{ else }}
{{ template "eiffel.template.search.result" . }}
{{ end }}
</tbody> </tbody>
</table> </table>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment