Skip to content

Commit

Permalink
#880 [Storage] CMS: Files table
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Jun 26, 2024
1 parent 51881da commit fdc64f4
Show file tree
Hide file tree
Showing 39 changed files with 884 additions and 286 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

## \#2 unreleased

* Changed: Format of the filenames in Storages. Also no folders used anymore. This has impact on Data Donation studies.
* Changed: Assignment does not have a Storage association anymore. Projects can have one Storage that is shared between all the project items.
* Added: Storage project item
* Added: Support for German language in assignments


## \#1 2024-06-12

Initial version
27 changes: 5 additions & 22 deletions core/frameworks/pixel/components/navigation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,13 @@ defmodule Frameworks.Pixel.Navigation do

attr(:right_bar_buttons, :list, default: [])
attr(:more_buttons, :list, default: [])
attr(:size, :atom, default: :wide)
attr(:hide_seperator, :boolean, default: true)
slot(:inner_block, required: true)

def action_bar(%{size: size, right_bar_buttons: right_bar_buttons} = assigns) do
def action_bar(%{right_bar_buttons: right_bar_buttons} = assigns) do
assigns =
assign(assigns, %{
has_right_bar_buttons: not Enum.empty?(right_bar_buttons),
centralize:
if size == :wide do
Enum.empty?(right_bar_buttons)
else
false
end
has_right_bar_buttons: not Enum.empty?(right_bar_buttons)
})

~H"""
Expand All @@ -70,16 +63,9 @@ defmodule Frameworks.Pixel.Navigation do
<Area.content>
<div class="overflow-scroll scrollbar-hidden w-full">
<div class="flex flex-row items-center w-full h-navbar-height">
<%= if @centralize do %>
<div class="flex-grow" />
<div class="flex-wrap">
<%= render_slot(@inner_block) %> <!-- tabbar -->
</div>
<% else %>
<div class="flex-grow">
<%= render_slot(@inner_block) %> <!-- tabbar -->
</div>
<% end %>
<div class="flex-grow">
<%= render_slot(@inner_block) %> <!-- tabbar -->
</div>
<%= if @has_right_bar_buttons do %>
<%= if not @hide_seperator do %>
<div class="flex-wrap px-4">
Expand All @@ -94,9 +80,6 @@ defmodule Frameworks.Pixel.Navigation do
</div>
</div>
<% end %>
<%= if @centralize do %>
<div class="flex-grow" />
<% end %>
</div>
</div>
</Area.content>
Expand Down
122 changes: 122 additions & 0 deletions core/frameworks/pixel/components/table.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
defmodule Frameworks.Pixel.Table do
alias CoreWeb.UI.Timestamp
use CoreWeb, :html

attr(:layout, :list, required: true)
attr(:head_cells, :list, required: true)
attr(:rows, :list, required: true)
attr(:border, :boolean, default: true)

def table(assigns) do
~H"""
<div class={"overflow-hidden #{if @border do "border-[2px] border-grey4 rounded-lg" end} w-full"}>
<table class="w-full table-auto">
<tbody>
<.row top={true} cells={@head_cells} layout={@layout} border={@border}/>
<%= for {cells, index} <- Enum.with_index(@rows) do %>
<.row
bottom={index == Enum.count(@rows)-1}
cells={cells}
layout={@layout}
border={@border}
/>
<% end %>
</tbody>
</table>
</div>
"""
end

attr(:cells, :list, required: true)
attr(:layout, :list, required: true)
attr(:top, :boolean, default: false)
attr(:bottom, :boolean, default: false)
attr(:border, :boolean, default: true)

def row(assigns) do
~H"""
<tr class={
"h-12 w-full #{if not @top do "border-collapse border-y border-grey4 border-spacing-y-1" end}"}>
<%= for {cell, index} <- Enum.with_index(@cells) do %>
<.cell
content={cell}
left={index == 0}
right={index == Enum.count(@cells)-1}
layout={Enum.at(@layout, index)}
top={@top}
bottom={@bottom}
border={@border}
/>
<% end %>
</tr>
"""
end

defp cell_padding(:top, %{border: true, top: true}), do: "pt-2"
defp cell_padding(:left, %{border: true, left: true}), do: "pl-6"
defp cell_padding(:right, %{border: true, right: true}), do: "pr-6"
defp cell_padding(_, _), do: ""

attr(:content, :string, required: true)
attr(:layout, :map, required: true)
attr(:top, :boolean, default: false)
attr(:bottom, :boolean, default: false)
attr(:left, :boolean, default: false)
attr(:right, :boolean, default: false)
attr(:border, :boolean, default: true)

def cell(%{layout: layout, content: content} = assigns) do
layout =
if layout.type == :href and not valid_url?(content) do
%{layout | type: :string}
else
layout
end

padding =
[:top, :left, :right]
|> Enum.map_join(" ", &cell_padding(&1, assigns))

assigns = assign(assigns, %{padding: padding, layout: layout})

~H"""
<td>
<div class={"#{@padding}"}>
<%= if @top do %>
<Text.table_head align={@layout.align}><%= @content %></Text.table_head>
<% else %>
<Text.table_row align={@layout.align}>
<.content type={@layout.type} value={@content} />
</Text.table_row>
<% end %>
</div>
</td>
"""
end

attr(:type, :atom, required: true)
attr(:value, :string, required: true)

def content(%{type: :href} = assigns) do
~H"""
<a class="underline text-primary" href={@value} target="_blank">Link</a>
"""
end

def content(%{type: :date} = assigns) do
~H"""
<%= Timestamp.stamp(@value) %>
"""
end

def content(assigns) do
~H"""
<%= @value %>
"""
end

defp valid_url?(string) do
uri = URI.parse(string)
uri.scheme != nil && uri.host =~ "."
end
end
6 changes: 4 additions & 2 deletions core/frameworks/pixel/components/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,24 @@ defmodule Frameworks.Pixel.Text do
end

attr(:color, :string, default: "text-grey1")
attr(:align, :string, default: "text-left")
slot(:inner_block, required: true)

def table_head(assigns) do
~H"""
<div class={"text-tablehead font-tablehead"}>
<div class={"text-tablehead font-tablehead #{@align}"}>
<%= render_slot(@inner_block) %>
</div>
"""
end

attr(:color, :string, default: "text-grey1")
attr(:align, :string, default: "text-left")
slot(:inner_block, required: true)

def table_row(assigns) do
~H"""
<div class={"text-tablerow font-tablerow"}>
<div class={"text-tablerow font-tablerow #{@align}"}>
<%= render_slot(@inner_block) %>
</div>
"""
Expand Down
63 changes: 32 additions & 31 deletions core/lib/core/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,47 @@ defmodule Core.Authorization do
grant_access(Systems.Lab.ToolModel, [:owner, :participant])

# Pages
grant_access(Systems.Home.Page, [:visitor, :member, :creator])
grant_access(Systems.Desktop.Page, [:creator])
grant_access(Systems.Org.ContentPage, [:admin])
grant_access(Systems.Admin.LoginPage, [:visitor, :member])
grant_access(CoreWeb.FakeQualtrics, [:member])
grant_access(Systems.Account.AwaitConfirmation, [:visitor])
grant_access(Systems.Account.ConfirmToken, [:visitor])
grant_access(Systems.Account.ResetPassword, [:visitor])
grant_access(Systems.Account.ResetPasswordToken, [:visitor])
grant_access(Systems.Account.SignupPage, [:visitor])
grant_access(Systems.Account.UserProfilePage, [:member])
grant_access(Systems.Account.UserSecuritySettings, [:member])
grant_access(Systems.Account.UserSettings, [:member])
grant_access(Systems.Account.UserSignin, [:visitor])
grant_access(Systems.Admin.ConfigPage, [:admin])
grant_access(Systems.Admin.ImportRewardsPage, [:admin])
grant_access(Systems.Budget.FundingPage, [:admin, :creator])
grant_access(Systems.Support.OverviewPage, [:admin])
grant_access(Systems.Support.TicketPage, [:admin])
grant_access(Systems.Support.HelpdeskPage, [:member])
grant_access(Systems.Notification.OverviewPage, [:member])
grant_access(Systems.NextAction.OverviewPage, [:member])
grant_access(Systems.Advert.OverviewPage, [:creator])
grant_access(Systems.Admin.LoginPage, [:visitor, :member])
grant_access(Systems.Advert.ContentPage, [:owner])
grant_access(Systems.Assignment.CrewPage, [:participant, :tester])
grant_access(Systems.Advert.OverviewPage, [:creator])
grant_access(Systems.Alliance.CallbackPage, [:owner])
grant_access(Systems.Assignment.ContentPage, [:owner])
grant_access(Systems.Assignment.CrewPage, [:participant, :tester])
grant_access(Systems.Assignment.LandingPage, [:participant])
grant_access(Systems.Alliance.CallbackPage, [:owner])
grant_access(Systems.Budget.FundingPage, [:admin, :creator])
grant_access(Systems.Desktop.Page, [:creator])
grant_access(Systems.Feldspar.AppPage, [:visitor, :member])
grant_access(Systems.Graphite.LeaderboardContentPage, [:owner])
grant_access(Systems.Graphite.LeaderboardPage, [:owner, :participant, :tester])
grant_access(Systems.Home.Page, [:visitor, :member, :creator])
grant_access(Systems.Lab.PublicPage, [:member])
grant_access(Systems.Promotion.LandingPage, [:visitor, :member])
grant_access(Systems.NextAction.OverviewPage, [:member])
grant_access(Systems.Notification.OverviewPage, [:member])
grant_access(Systems.Org.ContentPage, [:admin])
grant_access(Systems.Pool.DetailPage, [:creator])
grant_access(Systems.Pool.LandingPage, [:visitor, :member, :owner])
grant_access(Systems.Pool.SubmissionPage, [:creator])
grant_access(Systems.Pool.ParticipantPage, [:creator])
grant_access(Systems.Test.Page, [:visitor, :member])
grant_access(Systems.Project.OverviewPage, [:admin, :creator])
grant_access(Systems.Pool.SubmissionPage, [:creator])
grant_access(Systems.Project.NodePage, [:creator, :owner])
grant_access(Systems.Graphite.LeaderboardPage, [:owner, :participant, :tester])
grant_access(Systems.Graphite.LeaderboardContentPage, [:owner])
grant_access(Systems.Feldspar.AppPage, [:visitor, :member])

grant_access(Systems.Account.UserSignin, [:visitor])
grant_access(Systems.Account.SignupPage, [:visitor])
grant_access(Systems.Account.ResetPassword, [:visitor])
grant_access(Systems.Account.ResetPasswordToken, [:visitor])
grant_access(Systems.Account.AwaitConfirmation, [:visitor])
grant_access(Systems.Account.ConfirmToken, [:visitor])
grant_access(Systems.Account.UserProfilePage, [:member])
grant_access(Systems.Account.UserSettings, [:member])
grant_access(Systems.Account.UserSecuritySettings, [:member])
grant_access(CoreWeb.FakeQualtrics, [:member])
grant_access(Systems.Project.OverviewPage, [:admin, :creator])
grant_access(Systems.Promotion.LandingPage, [:visitor, :member])
grant_access(Systems.Storage.EndpointContentPage, [:owner])
grant_access(Systems.Support.HelpdeskPage, [:member])
grant_access(Systems.Support.OverviewPage, [:admin])
grant_access(Systems.Support.TicketPage, [:admin])
grant_access(Systems.Test.Page, [:visitor, :member])

grant_actions(CoreWeb.FakeAllianceController, %{
index: [:visitor, :member]
Expand Down Expand Up @@ -372,6 +372,7 @@ defmodule Core.Authorization do
Systems.Project.NodeModel,
Systems.Workflow.Model,
Systems.Assignment.Model,
Systems.Storage.EndpointModel,
Systems.Crew.Model,
Systems.Graphite.ToolModel,
Systems.Graphite.LeaderboardModel
Expand Down
36 changes: 36 additions & 0 deletions core/lib/core_web/ui/timestamp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,42 @@ defmodule CoreWeb.UI.Timestamp do
Timex.format!(datetime, "%Y-%m-%d", :strftime)
end

def stamp(%DateTime{} = datetime) do
weekday = Timex.format!(datetime, "%A", :strftime)
month = Timex.format!(datetime, "%B", :strftime)
day_of_month = Timex.format!(datetime, "%e", :strftime)
time = Timex.format!(datetime, "%H:%M", :strftime)

dgettext("eyra-ui", "timestamp.datetime",
weekday: weekday,
day_of_month: day_of_month,
month: month,
time: time
)
end

@spec humanize_time(
{{integer(), pos_integer(), pos_integer()},
{non_neg_integer(), non_neg_integer(), non_neg_integer()}
| {non_neg_integer(), non_neg_integer(), non_neg_integer(),
non_neg_integer() | {non_neg_integer(), non_neg_integer()}}}
| {integer(), pos_integer(), pos_integer()}
| %{
:__struct__ => Date | DateTime | NaiveDateTime | Time,
:calendar => atom(),
optional(:day) => pos_integer(),
optional(:hour) => non_neg_integer(),
optional(:microsecond) => {non_neg_integer(), non_neg_integer()},
optional(:minute) => non_neg_integer(),
optional(:month) => pos_integer(),
optional(:second) => non_neg_integer(),
optional(:std_offset) => integer(),
optional(:time_zone) => binary(),
optional(:utc_offset) => integer(),
optional(:year) => integer(),
optional(:zone_abbr) => binary()
}
) :: binary()
def humanize_time(timestamp) do
Timex.format!(timestamp, "%H:%M", :strftime)
end
Expand Down
36 changes: 36 additions & 0 deletions core/priv/gettext/de/LC_MESSAGES/eyra-storage.po
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,39 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "goto.storage.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.data"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.data.forward"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.settings"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.settings.forward"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.monitor"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "tabbar.item.monitor.forward"
msgstr ""

#, elixir-autogen, elixir-format
msgid "table.date.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "table.file.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "table.size.label"
msgstr ""
Loading

0 comments on commit fdc64f4

Please sign in to comment.