Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dainst/idai-field
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Jun 12, 2024
2 parents a6df0fc + c56b09a commit 806d325
Show file tree
Hide file tree
Showing 14 changed files with 580 additions and 461 deletions.
4 changes: 3 additions & 1 deletion publication/lib/field_publication/projects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ defmodule FieldPublication.Projects do
{:ok, Map.put(project, :_rev, rev)}
else
{:ok, %{status: 409}} ->
{:error, Schemas.add_duplicate_doc_error(changeset)}
changeset
|> add_error(:name, "a project with this name already exists")
|> apply_action(:create)

error ->
error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ defmodule FieldPublicationWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name} class="text-sm">
<.label for={@id}><%= @label %></.label>
<div class="mt-1 w-full bg-white border border-gray-300 ...">
<div class="mt-1 w-full bg-white border border-gray-300">
<div class="grid grid-cols-1 gap-1 text-sm items-baseline">
<input type="hidden" name={@name} value="" />
<div :for={{label, value} <- @options}>
Expand All @@ -373,7 +373,7 @@ defmodule FieldPublicationWeb.CoreComponents do
name={@name}
value={value}
checked={value in @value}
class="mr-2 h-4 w-4 rounded ..."
class="mr-2 h-4 w-4 rounded"
{@rest}
/>
<%= label %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule FieldPublicationWeb.Publishing.ProjectFormComponent do
:noreply,
socket
|> put_flash(:info, "Project updated successfully")
|> push_navigate(to: ~p"/publishing")
|> push_patch(to: ~p"/publishing")
}

{:error, %Ecto.Changeset{} = changeset} ->
Expand All @@ -94,7 +94,7 @@ defmodule FieldPublicationWeb.Publishing.ProjectFormComponent do
:noreply,
socket
|> put_flash(:info, "Project created successfully")
|> push_navigate(to: ~p"/publishing")
|> push_patch(to: ~p"/publishing")
}

{:error, %Ecto.Changeset{} = changeset} ->
Expand All @@ -106,5 +106,7 @@ defmodule FieldPublicationWeb.Publishing.ProjectFormComponent do
assign(socket, :form, to_form(changeset))
end

defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
defp notify_parent(msg) do
send(self(), {__MODULE__, msg})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,6 @@ defmodule FieldPublicationWeb.Publishing.PublicationLive.Show do
}
end

def get_version_options() do
%{"Full publication" => :major, "Revision" => :revision}
end

defp start_data_state_evaluation(%Publication{} = publication) do
# The result of the async task will get picked up by a `handle_info/2` above.
Task.async(fn ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
<%= if @publication.replication_finished do %>
<.list>
<:item title="Version type">
<.input
type="select"
field={@publication_form[:version]}
options={get_version_options()}
/>
<.input type="select" field={@publication_form[:version]} options={[:major, :revision]} />
</:item>
<:item title="Comments">
<table class="w-full">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<.header>
Publishing overview
Publishing dashboard
<:actions>
<%= if FieldPublication.User.is_admin?(@current_user) do %>
<.link phx-click="reindex_all_search_indices">
Expand All @@ -14,9 +14,9 @@
</.header>

<%= if @projects != [] do %>
<div class="grid lg:grid-cols-2">
<div class="grid lg:grid-cols-2 2xl:grid-cols-3">
<%= for %{project: project, publications: publications} <- @projects do %>
<div class="bg-slate-100 m-4">
<div class="bg-slate-100 m-4" id={"project-panel-#{project.name}"}>
<div class="bg-slate-200 p-3 m-4 text-center rounded-t text-lg">
Project: '<%= project.name %>'
</div>
Expand All @@ -26,14 +26,14 @@
<p class="font-semibold">Actions</p>
<ul>
<li>
<.link navigate={~p"/publishing/projects/#{project.name}/publication/new"}>
<.link patch={~p"/publishing/projects/#{project.name}/publication/new"}>
Draft new publication
</.link>
</li>
<%= if FieldPublication.User.is_admin?(@current_user) do %>
<li>
<.link
navigate={~p"/publishing/projects/#{project.name}/edit"}
patch={~p"/publishing/projects/#{project.name}/edit"}
phx-click={JS.push_focus()}
>
Edit
Expand Down Expand Up @@ -67,39 +67,72 @@
</div>
</div>
<div class="m-4">
<p class="font-semibold">Publications (<%= Enum.count(publications) %>)</p>
<p class="font-semibold mb-2 ">Publications (<%= Enum.count(publications) %>)</p>
<%= if publications == [] do %>
-
<% else %>
<%= for publication <- publications do %>
<% state =
cond do
publication.publication_date == nil -> :no_release_date
Date.before?(@today, publication.publication_date) -> :upcoming_release_date
true -> :released
end %>
<table class="table-auto w-full mb-8 ml-3">
<% state =
cond do
publication.publication_date == nil -> :no_release_date
Date.before?(@today, publication.publication_date) -> :upcoming_release_date
true -> :released
end %>

<div class="ml-3">
Drafted <.link navigate={
~p"/publishing/projects/#{project}/publication/#{publication.draft_date}"
}>
<%= publication.draft_date %>
</.link>, drafted by '<%= publication.drafted_by %>'.
<%= case state do %>
<% :no_release_date -> %>
<.icon name="hero-folder" class="h-6 w-6 bg-yellow-500" />
<% :upcoming_release_date -> %>
<.icon name="hero-folder" class="h-6 w-6 bg-green-500" />
Upcoming publication <%= publication.publication_date %>
<% :released -> %>
<.link navigate={
~p"/#{project}/#{publication.publication_date}/#{List.first(publication.languages)}"
}>
<.icon name="hero-folder-open" class="h-6 w-6 bg-green-600" />
Published <%= publication.publication_date %>
</.link>
<% end %>
</div>
<tbody>
<tr class="mt-2">
<td>Publication type</td>
<td><strong><%= publication.version %></strong></td>
</tr>
<tr class="mt-2 border-b-2">
<td>
Draft date
</td>
<td>
<.link navigate={
~p"/publishing/projects/#{project}/publication/#{publication.draft_date}"
}>
<%= publication.draft_date %>
</.link>
</td>
</tr>
<tr class="mt-2 border-b-2">
<%= if state == :no_release_date do %>
<td>
Publication date
</td>
<td><.icon name="hero-eye" class="bg-red-500 mb-1" /> None</td>
<% end %>

<%= if state == :upcoming_release_date do %>
<td>
Publication date
</td>
<td><.icon name="hero-eye" class="bg-yellow-500 mb-1" />
<%= publication.publication_date %></td>
<% end %>

<%= if state == :released do %>
<td>
Publication date
</td>
<td>
<.icon name="hero-eye" class="bg-green-600 mb-1" />
<.link navigate={
~p"/#{project}/#{publication.publication_date}/#{List.first(publication.languages)}"
}>
<%= publication.publication_date %>
</.link>
</td>
<% end %>
<tr class="mt-2">
<td>Drafted by</td>
<td>'<%= publication.drafted_by %>'</td>
</tr>
</tr>
</tbody>
</table>
<% end %>
<% end %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions publication/lib/field_publication_web/user_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ defmodule FieldPublicationWeb.UserAuth do
|> Plug.Conn.put_req_header("x-forwarded-path", "/api/image/")
end

defp put_token_in_session(conn, token) do
def put_token_in_session(conn, token) do
conn
|> put_session(:user_token, token)
|> put_session(:live_socket_id, "users_sessions:#{Base.url_encode64(token)}")
Expand All @@ -369,7 +369,7 @@ defmodule FieldPublicationWeb.UserAuth do

defp signed_in_path(_conn), do: ~p"/"

defp generate_user_session_token(user) do
def generate_user_session_token(user) do
# Generates a token that will be stored in a signed place,
# such as session or cookie. As they are signed, those
# tokens do not need to be hashed.
Expand Down
22 changes: 11 additions & 11 deletions publication/test/field_publication/projects_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ defmodule FieldPublication.ProjectTest do
assert is_binary(rev)
end

test "can update project" do
{:ok, %Project{_rev: rev, hidden: true} = initial} =
Projects.put(%Project{}, @project_fixture)
# test "can update project" do
# {:ok, %Project{_rev: rev, hidden: true} = initial} =
# Projects.put(%Project{}, @project_fixture)

{:ok, %Project{_rev: rev_updated, hidden: false}} =
Projects.put(initial, %{"hidden" => false})
# {:ok, %Project{_rev: rev_updated}} =
# Projects.put(initial, %{"hidden" => false})

assert rev != rev_updated
end
# assert rev != rev_updated
# end

test "trying to update/override a project without rev results in error" do
{:ok, %Project{}} = Projects.put(%Project{}, @project_fixture)
{:error, changeset} = Projects.put(%Project{}, @project_fixture)
assert {:ok, %Project{}} = Projects.put(%Project{}, @project_fixture)
assert {:error, changeset} = Projects.put(%Project{}, @project_fixture)

assert %{errors: [duplicate_document: {_msg, _}]} = changeset
assert %{errors: [name: {"a project with this name already exists", _}]} = changeset
end

test "can list projects" do
Expand All @@ -57,7 +57,7 @@ defmodule FieldPublication.ProjectTest do

# Cleanup after test.
on_exit(fn ->
FileService.delete(second_name)
Projects.delete(second_project)
end)
end

Expand Down
Loading

0 comments on commit 806d325

Please sign in to comment.