Skip to content

Commit

Permalink
Merge pull request #6 from idaholab/feature/client
Browse files Browse the repository at this point in the history
various bug fixes and changes
  • Loading branch information
DnOberon authored Aug 22, 2024
2 parents f3f5c68 + 4d4c88e commit 952193f
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 33 deletions.
27 changes: 25 additions & 2 deletions server/lib/ingest/destinations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,36 @@ defmodule Ingest.Destinations do
from(d in Destination,
where:
fragment(
"searchable @@ websearch_to_tsquery(?)",
"searchable @@ to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*'))",
^search_term
) and d.id not in ^Enum.map(exclude, fn d -> d.id end),
order_by: {
:desc,
fragment(
"ts_rank_cd(searchable, websearch_to_tsquery(?), 4)",
"ts_rank_cd(searchable, to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*')), 4)",
^search_term
)
}
)

Repo.all(query)
end

@defaults %{exclude: []}
def search_own(search_term, %User{} = user, opts \\ []) do
%{exclude: exclude} = Enum.into(opts, @defaults)

query =
from(d in Destination,
where:
fragment(
"searchable @@ to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*'))",
^search_term
) and d.id not in ^Enum.map(exclude, fn d -> d.id end) and d.inserted_by == ^user.id,
order_by: {
:desc,
fragment(
"ts_rank_cd(searchable, to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*')), 4)",
^search_term
)
}
Expand Down
6 changes: 3 additions & 3 deletions server/lib/ingest/destinations/destination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule Ingest.Destinations.S3Config do
field :path, Ingest.Encrypted.Binary
field :final_path, Ingest.Encrypted.Binary
field :ssl, :boolean, default: true
field :integrated_metadata, :boolean, default: true
field :integrated_metadata, :boolean, default: false
end

@doc false
Expand Down Expand Up @@ -118,7 +118,7 @@ defmodule Ingest.Destinations.AzureConfig do
field :container, Ingest.Encrypted.Binary
field :path, Ingest.Encrypted.Binary
field :final_path, Ingest.Encrypted.Binary
field :integrated_metadata, :boolean, default: true
field :integrated_metadata, :boolean, default: false
end

@doc false
Expand Down Expand Up @@ -153,7 +153,7 @@ defmodule Ingest.Destinations.LakeFSConfig do
field :repository, Ingest.Encrypted.Binary
field :port, :integer, default: nil
field :ssl, :boolean, default: true
field :integrated_metadata, :boolean, default: true
field :integrated_metadata, :boolean, default: false
end

@doc false
Expand Down
34 changes: 28 additions & 6 deletions server/lib/ingest/requests.ex
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ defmodule Ingest.Requests do
do:
Repo.get!(Request, id)
|> Repo.preload(:templates)
|> Repo.preload(:project)
|> Repo.preload(project: [:templates, :destinations])
|> Repo.preload(:destinations)

@doc """
Expand Down Expand Up @@ -329,13 +329,35 @@ defmodule Ingest.Requests do
from t in Template,
where:
fragment(
"searchable @@ websearch_to_tsquery(?)",
"searchable @@ to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*'))",
^search_term
) and t.id not in ^Enum.map(exclude, fn d -> d.id end),
order_by: {
:desc,
fragment(
"ts_rank_cd(searchable, websearch_to_tsquery(?), 4)",
"ts_rank_cd(searchable, to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*')), 4)",
^search_term
)
}

Repo.all(query)
end

@defaults %{exclude: []}
def search_own_templates(search_term, %User{} = user, opts \\ []) do
%{exclude: exclude} = Enum.into(opts, @defaults)

query =
from t in Template,
where:
fragment(
"searchable @@ to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*'))",
^search_term
) and t.id not in ^Enum.map(exclude, fn d -> d.id end) and t.inserted_by == ^user.id,
order_by: {
:desc,
fragment(
"ts_rank_cd(searchable, to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*')), 4)",
^search_term
)
}
Expand All @@ -350,13 +372,13 @@ defmodule Ingest.Requests do
on: p.id == r.project_id,
where:
fragment(
"p1.searchable @@ websearch_to_tsquery(?)",
"p1.searchable @@ to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*'))",
^search_term
),
) and r.status == :published,
order_by: {
:desc,
fragment(
"ts_rank_cd(p1.searchable, websearch_to_tsquery(?), 4)",
"ts_rank_cd(p1.searchable, to_tsquery(concat(regexp_replace(trim(?), '\W+', ':* & '), ':*')), 4)",
^search_term
)
}
Expand Down
2 changes: 1 addition & 1 deletion server/lib/ingest_web/components_live/destination_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ defmodule IngestWeb.LiveComponents.DestinationForm do
</.label>
<.input type="text" field={config[:base_url]} />
<p class="text-xs">
Leave blank to use the service's default option.
Leave blank to use the service's default option. Do not include trailing slashes or "https://".
</p>
<.label for="status-select">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ defmodule IngestWeb.LiveComponents.MetadataEntryForm do
<.input
label={field.label}
name={field.label}
required={field.required}
field={@metadata_form[field.label]}
type={Atom.to_string(field.type)}
options={
Expand Down
8 changes: 6 additions & 2 deletions server/lib/ingest_web/components_live/search_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ defmodule IngestWeb.LiveComponents.SearchForm do
socket
|> assign(
:results,
Ingest.Requests.search_templates(value, exclude: Enum.flat_map(excludes, fn d -> d end))
Ingest.Requests.search_own_templates(value, socket.assigns.current_user,
exclude: Enum.flat_map(excludes, fn d -> d end)
)
)}
end

Expand All @@ -126,7 +128,9 @@ defmodule IngestWeb.LiveComponents.SearchForm do
socket
|> assign(
:results,
Ingest.Destinations.search(value, exclude: Enum.flat_map(excludes, fn d -> d end))
Ingest.Destinations.search_own(value, socket.assigns.current_user,
exclude: Enum.flat_map(excludes, fn d -> d end)
)
)}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ defmodule IngestWeb.MetadataEntryLive do
upload = Uploads.get_upload!(upload_id)

classifications_allowed =
request.destinations
(request.destinations ++ request.project.destinations)
|> Enum.map(fn d -> d.classifications_allowed end)
|> List.flatten()
|> Enum.uniq()

{:noreply,
socket
|> assign(:classifications_allowed, classifications_allowed)
|> assign(:templates, request.templates)
|> assign(:templates, request.templates ++ request.project.templates)
|> assign(:upload, upload)
|> allow_upload(:files,
auto_upload: true,
Expand All @@ -273,7 +273,7 @@ defmodule IngestWeb.MetadataEntryLive do
original_filename: upload.filename,
filename: "#{entry.client_name}",
user: socket.assigns.current_user,
destinations: request.destinations,
destinations: request.destinations ++ request.project.destinations,
request: request}
end
)
Expand Down
21 changes: 13 additions & 8 deletions server/lib/ingest_web/live/dashboard_live/request_show_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ defmodule IngestWeb.RequestShowLive do
<div>
<div
:if={
@request.destinations == [] || @request.templates == [] ||
(@request.destinations == [] && @project_destinations == []) ||
(@request.templates == [] && @project_templates == []) ||
@request.status != :published
}
class="lg:border-b lg:border-t lg:border-gray-200 mb-10 "
Expand All @@ -36,14 +37,14 @@ defmodule IngestWeb.RequestShowLive do
<span class="flex items-start px-6 py-5 text-sm font-medium lg:pl-9">
<span class="flex-shrink-0">
<span
:if={@request.templates == []}
:if={@request.templates == [] && @project_templates == []}
class="flex h-10 w-10 items-center justify-center rounded-full border-2 border-gray-300"
>
<span class="text-gray-500">X</span>
</span>
<span
:if={@request.templates != []}
:if={@request.templates != [] || @project_templates != []}
class="flex h-10 w-10 items-center justify-center rounded-full bg-indigo-600"
>
<svg
Expand Down Expand Up @@ -86,14 +87,14 @@ defmodule IngestWeb.RequestShowLive do
<span class="flex items-start px-6 py-5 text-sm font-medium lg:pl-9">
<span class="flex-shrink-0">
<span
:if={@request.destinations == []}
:if={@request.destinations == [] && @project_destinations == []}
class="flex h-10 w-10 items-center justify-center rounded-full border-2 border-gray-300"
>
<span class="text-gray-500">X</span>
</span>
<span
:if={@request.destinations != []}
:if={@request.destinations != [] || @project_destinations != []}
class="flex h-10 w-10 items-center justify-center rounded-full bg-indigo-600"
>
<svg
Expand Down Expand Up @@ -238,7 +239,7 @@ defmodule IngestWeb.RequestShowLive do
<p :if={@request.status == :published} class="text-sm font-semibold">Published</p>
</div>
<button
:if={@request.templates != []}
:if={@request.templates != [] || @project_templates != []}
phx-click={JS.toggle(to: "#publish_dropdown", in: "opacity-100", out: "opacity-0")}
type="button"
class={
Expand Down Expand Up @@ -268,7 +269,10 @@ defmodule IngestWeb.RequestShowLive do
</button>
<button
:if={@request.destinations == [] || @request.templates == []}
:if={
(@request.destinations == [] && @project_destinations == []) ||
(@request.templates == [] && @project_templates == [])
}
disable
type="button"
class="inline-flex items-center rounded-l-none rounded-r-md bg-indigo-600 cursor-not-allowed p-2 hover:bg-indigo-700 "
Expand Down Expand Up @@ -1063,7 +1067,8 @@ defmodule IngestWeb.RequestShowLive do
project = Projects.get_project!(request.project_id)

# set back to draft if there are not enough parts - not a catch all, but works most of the time if they remove something
if request.templates == [] || request.destinations == [] do
if (request.templates == [] && project.templates == []) ||
(request.destinations == [] && project.destinations == []) do
Requests.update_request(request, %{status: :draft})
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ defmodule IngestWeb.TemplateBuilderLive do
<div class="mt-2">
<.input type="text" field={@field_form[:file_extensions]} />
</div>
<p class="mt-3 text-sm leading-6 text-gray-400">
Show this field only for the provided file extensions.
</p>
<p class="mt-3 text-sm leading-6 text-gray-400">
Comma-seperated values. Example: .csv,.pdf,.html - Leave blank for all file types
</p>
Expand Down Expand Up @@ -409,7 +412,7 @@ defmodule IngestWeb.TemplateBuilderLive do
case Ingest.Requests.update_template(socket.assigns.template, %{fields: fields}) do
{:ok, _template} ->
socket
|> push_patch(
|> push_navigate(
to:
~p"/dashboard/templates/#{socket.assigns.template.id}/fields/#{socket.assigns.field.id}"
)
Expand Down
4 changes: 2 additions & 2 deletions server/lib/ingest_web/live/dashboard_live/upload_show_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ defmodule IngestWeb.UploadShowLive do
request = Requests.get_request!(id)

classifications_allowed =
request.destinations
(request.destinations ++ request.project.destinations)
|> Enum.map(fn d -> d.classifications_allowed end)
|> List.flatten()
|> Enum.uniq()
Expand All @@ -159,7 +159,7 @@ defmodule IngestWeb.UploadShowLive do
{Ingest.Uploaders.MultiDestinationWriter,
filename: "#{entry.client_name}",
user: socket.assigns.current_user,
destinations: request.destinations,
destinations: request.destinations ++ request.project.destinations,
request: request}
end
)
Expand Down
Loading

0 comments on commit 952193f

Please sign in to comment.