Skip to content

Commit

Permalink
Refactor leaderboard to segmented variant and used it on 3 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes committed Jun 21, 2023
1 parent 80697b0 commit d3599be
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 179 deletions.
2 changes: 1 addition & 1 deletion core/bundles/link/lib/onboarding/wizard_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ defmodule Link.Onboarding.WizardPage do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<Navigation.action_bar>
<Tabbar.container id={@tabbar_id} tabs={@tabs} initial_tab={:welcome} />
</Navigation.action_bar>
Expand Down
2 changes: 1 addition & 1 deletion core/bundles/next/lib/user/signin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Next.User.Signin do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<div id="signup_content" phx-hook="LiveContent" data-show-errors={true}>
<Area.content>
<Margin.y id={:page_top} />
Expand Down
21 changes: 21 additions & 0 deletions core/frameworks/pixel/components/selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ defmodule Frameworks.Pixel.Selector do
defp grid_options(_, grid_options) when grid_options != "", do: grid_options
defp grid_options(:radio, _), do: "flex flex-col gap-3"
defp grid_options(:checkbox, _), do: "flex flex-row flex-wrap gap-x-8 gap-y-3 items-center"

defp grid_options(:segmented, _),
do: "flex flex-row flex-wrap gap-0 items-center rounded-full overflow-hidden"

defp grid_options(_, _), do: "flex flex-row flex-wrap gap-3 items-center"

defp multiselect?(:radio), do: false
defp multiselect?(:segmented), do: false
defp multiselect?(_), do: true

@impl true
Expand Down Expand Up @@ -142,6 +147,7 @@ defmodule Frameworks.Pixel.Selector do

defp item_component(:radio), do: &Frameworks.Pixel.Selector.Item.radio/1
defp item_component(:checkbox), do: &Frameworks.Pixel.Selector.Item.checkbox/1
defp item_component(:segmented), do: &Frameworks.Pixel.Selector.Item.segment/1
defp item_component(_), do: &Frameworks.Pixel.Selector.Item.label/1

@impl true
Expand Down Expand Up @@ -246,6 +252,21 @@ defmodule Frameworks.Pixel.Selector.Item do
attr(:multiselect?, :boolean, default: true)
attr(:background, :atom, default: :light)

def segment(assigns) do
~H"""
<div
x-bind:class="{ 'bg-primary text-white': active, 'bg-grey5 text-grey2': !active}"
class="px-6 py-3 text-label font-label select-none"
>
<%= @item.value %>
</div>
"""
end

attr(:item, :map, required: true)
attr(:multiselect?, :boolean, default: true)
attr(:background, :atom, default: :light)

def checkbox(%{item: %{value: value} = item, multiselect?: multiselect?} = assigns) do
accent = Map.get(item, :accent)

Expand Down
1 change: 1 addition & 0 deletions core/lib/core/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ defmodule Core.Authorization do
grant_access(Systems.Project.NodePage, [:researcher, :owner])
grant_access(Systems.Project.ItemContentPage, [:researcher, :owner])
grant_access(Systems.Benchmark.ToolPage, [:member, :owner])
grant_access(Systems.Benchmark.LeaderboardPage, [:visitor, :member])

grant_access(CoreWeb.User.Signin, [:visitor])
grant_access(CoreWeb.User.Signup, [:visitor])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ defmodule CoreWeb.Layouts.Stripped.Component do
end

attr(:title, :string, default: nil)
attr(:user, :string, required: true)
attr(:menus, :map, required: true)
slot(:inner_block, required: true)

Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/live/user/await_confirmation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule CoreWeb.User.AwaitConfirmation do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<div>
<Area.sheet>
<Margin.y id={:page_top} />
Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/live/user/reset_password.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule CoreWeb.User.ResetPassword do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<Area.content>
<Margin.y id={:page_top} />
<Area.form>
Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/live/user/reset_password_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule CoreWeb.User.ResetPasswordToken do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<Area.content>
<Margin.y id={:page_top} />
<Area.form>
Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/live/user/signup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule CoreWeb.User.Signup do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<div id="signup_content" phx-hook="LiveContent" data-show-errors={true}>
<Area.content>
<Margin.y id={:page_top} />
Expand Down
36 changes: 28 additions & 8 deletions core/priv/gettext/en/LC_MESSAGES/eyra-benchmark.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ msgstr "Please note that you are allowed to submit up to three methods."
msgid "submissions.title"
msgstr "Submissions"

#, elixir-autogen, elixir-format, fuzzy
msgid "expectations.subhead"
msgstr "Please note that only top submissions will be made publicly available on the platform."

#, elixir-autogen, elixir-format
msgid "highlight.deadline.title"
msgstr "Days untill deadline"
Expand Down Expand Up @@ -173,10 +169,6 @@ msgstr "Submissions"
msgid "import.leaderboard.title"
msgstr "Import"

#, elixir-autogen, elixir-format
msgid "leaderboard.latest.title"
msgstr "Latest version"

#, elixir-autogen, elixir-format
msgid "csv-import-button"
msgstr "Import selected file"
Expand All @@ -192,3 +184,31 @@ msgstr "Select file"
#, elixir-autogen, elixir-format
msgid "csv-select-placeholder"
msgstr "Select a leaderboard csv file"

#, elixir-autogen, elixir-format
msgid "challenge.forward.button"
msgstr "Go to challenge"

#, elixir-autogen, elixir-format
msgid "leaderboard.forward.button"
msgstr "Public"

#, elixir-autogen, elixir-format
msgid "leaderboard.github.label"
msgstr "Github"

#, elixir-autogen, elixir-format
msgid "leaderboard.method.label"
msgstr "Method"

#, elixir-autogen, elixir-format
msgid "leaderboard.position.label"
msgstr "Position"

#, elixir-autogen, elixir-format
msgid "leaderboard.score.label"
msgstr "Score"

#, elixir-autogen, elixir-format
msgid "leaderboard.team.label"
msgstr "Team"
36 changes: 28 additions & 8 deletions core/priv/gettext/eyra-benchmark.pot
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ msgstr ""
msgid "submissions.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "expectations.subhead"
msgstr ""

#, elixir-autogen, elixir-format
msgid "highlight.deadline.title"
msgstr ""
Expand Down Expand Up @@ -173,10 +169,6 @@ msgstr ""
msgid "import.leaderboard.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.latest.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "csv-import-button"
msgstr ""
Expand All @@ -192,3 +184,31 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "csv-select-placeholder"
msgstr ""

#, elixir-autogen, elixir-format
msgid "challenge.forward.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.forward.button"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.github.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.method.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.position.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.score.label"
msgstr ""

#, elixir-autogen, elixir-format
msgid "leaderboard.team.label"
msgstr ""
36 changes: 28 additions & 8 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-benchmark.po
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ msgstr "Let op, je kan maximaal drie methodes indienen."
msgid "submissions.title"
msgstr "Indienen"

#, elixir-autogen, elixir-format, fuzzy
msgid "expectations.subhead"
msgstr " Let op, alleen de hoogst scorende methodes worden getoond op het publieke scoreboard op het platform."

#, elixir-autogen, elixir-format
msgid "highlight.deadline.title"
msgstr "Dagen tot deadline"
Expand Down Expand Up @@ -173,10 +169,6 @@ msgstr "Methodes"
msgid "import.leaderboard.title"
msgstr "Importeren"

#, elixir-autogen, elixir-format
msgid "leaderboard.latest.title"
msgstr "Laatste versie"

#, elixir-autogen, elixir-format
msgid "csv-import-button"
msgstr "Importeer gekozen bestand"
Expand All @@ -192,3 +184,31 @@ msgstr "Kies bestand"
#, elixir-autogen, elixir-format
msgid "csv-select-placeholder"
msgstr "Kies een ranglijst csv bestand"

#, elixir-autogen, elixir-format
msgid "challenge.forward.button"
msgstr "Naar de challenge"

#, elixir-autogen, elixir-format
msgid "leaderboard.forward.button"
msgstr "Publiek"

#, elixir-autogen, elixir-format
msgid "leaderboard.github.label"
msgstr "Github"

#, elixir-autogen, elixir-format
msgid "leaderboard.method.label"
msgstr "Methode"

#, elixir-autogen, elixir-format
msgid "leaderboard.position.label"
msgstr "Poisitie"

#, elixir-autogen, elixir-format
msgid "leaderboard.score.label"
msgstr "Score"

#, elixir-autogen, elixir-format
msgid "leaderboard.team.label"
msgstr "Team"
2 changes: 1 addition & 1 deletion core/systems/admin/login_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Systems.Admin.LoginPage do
@impl true
def render(assigns) do
~H"""
<.stripped user={@current_user} menus={@menus}>
<.stripped menus={@menus}>
<Area.content>
<Margin.y id={:page_top} />
<Area.form>
Expand Down
7 changes: 7 additions & 0 deletions core/systems/benchmark/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ defmodule Systems.Benchmark.Public do
Benchmark
}

# FIXME: should come from CMS
@main_category "f1_score"

def get_tool!(id, preload \\ []) do
from(tool in Benchmark.ToolModel, preload: ^preload)
|> Repo.get!(id)
Expand Down Expand Up @@ -198,11 +201,15 @@ defmodule Systems.Benchmark.Public do
preload: ^preload
)
|> Repo.all()
|> Enum.sort(&sort_categories/2)
else
[]
end
end

defp sort_categories(%{name: @main_category}, _), do: true
defp sort_categories(_, _), do: false

def count_leaderboard_versions() do
list =
from(leaderboard in Benchmark.LeaderboardModel,
Expand Down
5 changes: 5 additions & 0 deletions core/systems/benchmark/_routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ defmodule Systems.Benchmark.Routes do
live("/:id/:spot", ToolPage)
get("/:id/export/submissions", ExportController, :submissions)
end

scope "/benchmark", Systems.Benchmark do
pipe_through([:browser])
live("/:id/public/leaderboard", LeaderboardPage)
end
end
end
end
Loading

0 comments on commit d3599be

Please sign in to comment.