Skip to content

Commit

Permalink
Merge pull request #665 from eyra/rank-prefer
Browse files Browse the repository at this point in the history
Rank PreFer
  • Loading branch information
mellelieuwes authored Apr 3, 2024
2 parents 55515c2 + fece60e commit 4cf8a66
Show file tree
Hide file tree
Showing 137 changed files with 3,010 additions and 2,059 deletions.
18 changes: 4 additions & 14 deletions core/bundles/next/lib/console/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@ defmodule Next.Console.Page do

alias Frameworks.Pixel.Text

alias Systems.{
Project,
NextAction,
Benchmark
}
alias Systems.Project
alias Systems.NextAction

def mount(_params, _session, %{assigns: %{current_user: user}} = socket) do
spot_items =
user
|> Benchmark.Public.list_spots(Benchmark.SpotModel.preload_graph([:tool]))
|> Enum.map(&convert_to_vm(socket, &1))

project_items =
user
|> Project.Public.list_owned_projects(preload: Project.Model.preload_graph(:down))
|> Enum.map(&convert_to_vm(socket, &1))

content_items = spot_items ++ project_items

socket =
socket
|> update_menus()
|> assign(content_items: content_items)
|> assign(content_items: project_items)
|> assign(next_best_action: NextAction.Public.next_best_action(user))

{:ok, socket}
Expand Down Expand Up @@ -104,7 +94,7 @@ defmodule Next.Console.Page do
|> Macro.camelize()

%{
path: ~p"/benchmark/#{tool_id}/#{spot_id}",
path: ~p"/graphite/#{tool_id}/#{spot_id}",
title: title,
subtitle: "#{name}",
tag: tag,
Expand Down
18 changes: 4 additions & 14 deletions core/bundles/self/lib/console/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@ defmodule Self.Console.Page do

alias Frameworks.Pixel.Text

alias Systems.{
Project,
NextAction,
Benchmark
}
alias Systems.Project
alias Systems.NextAction

def mount(_params, _session, %{assigns: %{current_user: user}} = socket) do
spot_items =
user
|> Benchmark.Public.list_spots(Benchmark.SpotModel.preload_graph([:tool]))
|> Enum.map(&convert_to_vm(socket, &1))

project_items =
user
|> Project.Public.list_owned_projects(preload: Project.Model.preload_graph(:down))
|> Enum.map(&convert_to_vm(socket, &1))

content_items = spot_items ++ project_items

socket =
socket
|> update_menus()
|> assign(content_items: content_items)
|> assign(content_items: project_items)
|> assign(next_best_action: NextAction.Public.next_best_action(user))

{:ok, socket}
Expand Down Expand Up @@ -104,7 +94,7 @@ defmodule Self.Console.Page do
|> Macro.camelize()

%{
path: ~p"/benchmark/#{tool_id}/#{spot_id}",
path: ~p"/graphite/#{tool_id}/#{spot_id}",
title: title,
subtitle: "#{name}",
tag: tag,
Expand Down
2 changes: 2 additions & 0 deletions core/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ config :plug, :statuses, %{
404 => "Page not found"
}

config :core, CoreWeb.FileUploader, max_file_size: 100_000_000

config :core,
image_catalog: Core.ImageCatalog.Unsplash,
banking_backend: Systems.Banking.Dummy
Expand Down
5 changes: 5 additions & 0 deletions core/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ if config_env() == :prod do
port: String.to_integer(System.get_env("HTTP_PORT", "8000"))
]

# PHOENIX LIVE UPLOAD

config :core, CoreWeb.FileUploader,
max_file_size: System.get_env("STORAGE_UPLOAD_MAX_SIZE", "100000000") |> String.to_integer()

# MAILGUN

if mailgun_api_key = System.get_env("MAILGUN_API_KEY") do
Expand Down
6 changes: 3 additions & 3 deletions core/frameworks/concept/tool_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ defprotocol Frameworks.Concept.ToolModel do
@spec ready?(t) :: boolean()
def ready?(_t)

@spec form(t) :: atom()
def form(_t)
@spec form(t, special :: atom()) :: atom()
def form(_t, _special)

@spec launcher(t) :: %{url: URI.t()} | %{module: atom(), params: map()} | nil
def launcher(_t)
Expand All @@ -37,7 +37,7 @@ defimpl Frameworks.Concept.ToolModel, for: Ecto.Changeset do
def apply_label(%{data: tool}), do: ToolModel.apply_label(tool)
def open_label(%{data: tool}), do: ToolModel.open_label(tool)
def ready?(%{data: tool}), do: ToolModel.ready?(tool)
def form(%{data: tool}), do: ToolModel.form(tool)
def form(%{data: tool}, special), do: ToolModel.form(tool, special)
def launcher(%{data: tool}), do: ToolModel.launcher(tool)
def task_labels(%{data: tool}), do: ToolModel.task_labels(tool)
def attention_list_enabled?(%{data: tool}), do: ToolModel.attention_list_enabled?(tool)
Expand Down
3 changes: 2 additions & 1 deletion core/frameworks/signal/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Frameworks.Signal.Public do
"Systems.Student.Switch",
"Systems.Campaign.Switch",
"Systems.NextAction.Switch",
"Systems.Crew.Switch"
"Systems.Crew.Switch",
"Systems.Instruction.Switch"
]

def dispatch(signal, message) do
Expand Down
9 changes: 4 additions & 5 deletions core/lib/core/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ defmodule Core.Authorization do
grant_access(Systems.Campaign.Model, [:visitor, :member])
grant_access(Systems.Questionnaire.ToolModel, [:owner, :coordinator, :participant])
grant_access(Systems.Lab.ToolModel, [:owner, :coordinator, :participant])
grant_access(Systems.Benchmark.SpotModel, [:owner])

# Pages
grant_access(Systems.Org.ContentPage, [:admin])
Expand Down Expand Up @@ -56,9 +55,9 @@ defmodule Core.Authorization do
grant_access(Systems.Test.Page, [:visitor, :member])
grant_access(Systems.Project.OverviewPage, [:admin, :researcher])
grant_access(Systems.Project.NodePage, [:researcher, :owner])
grant_access(Systems.Benchmark.ContentPage, [:researcher, :owner])
grant_access(Systems.Benchmark.ToolPage, [:owner])
grant_access(Systems.Benchmark.LeaderboardPage, [:visitor, :member])
grant_access(Systems.Graphite.ContentPage, [:researcher, :owner])
grant_access(Systems.Graphite.ToolPage, [:owner])
grant_access(Systems.Graphite.LeaderboardPage, [:visitor, :member])
grant_access(Systems.Feldspar.AppPage, [:visitor, :member])

grant_access(CoreWeb.User.Signin, [:visitor])
Expand Down Expand Up @@ -108,7 +107,7 @@ defmodule Core.Authorization do

%Core.Authorization.RoleAssignment{
principal_id: principal_id,
role: :owner
role: role
}
end

Expand Down
37 changes: 12 additions & 25 deletions core/lib/core/factories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Core.Factories do
Feldspar,
Document,
Lab,
Benchmark,
Graphite,
Pool,
Budget,
Bookkeeping,
Expand Down Expand Up @@ -241,16 +241,12 @@ defmodule Core.Factories do
build(:submission, %{})
end

def build(:benchmark_submission) do
build(:benchmark_submission, %{description: "description"})
def build(:graphite_submission) do
build(:graphite_submission, %{description: "description"})
end

def build(:benchmark_spot) do
build(:benchmark_spot, %{})
end

def build(:benchmark_tool) do
build(:benchmark_tool, %{})
def build(:graphite_tool) do
build(:graphite_tool, %{})
end

def build(:workflow) do
Expand Down Expand Up @@ -453,14 +449,14 @@ defmodule Core.Factories do
{feldspar_tool, attributes} = get_optional(:feldspar_tool, attributes)
{document_tool, attributes} = get_optional(:document_tool, attributes)
{lab_tool, attributes} = get_optional(:lab_tool, attributes)
{benchmark_tool, attributes} = get_optional(:benchmark_tool, attributes)
{graphite_tool, attributes} = get_optional(:graphite_tool, attributes)

%Project.ToolRefModel{
alliance_tool: alliance_tool,
document_tool: document_tool,
lab_tool: lab_tool,
feldspar_tool: feldspar_tool,
benchmark_tool: benchmark_tool
graphite_tool: graphite_tool
}
|> struct!(attributes)
end
Expand Down Expand Up @@ -604,35 +600,26 @@ defmodule Core.Factories do
|> struct!(attributes)
end

def build(:benchmark_tool, %{} = attributes) do
def build(:graphite_tool, %{} = attributes) do
{auth_node, attributes} = Map.pop(attributes, :auth_node, build(:auth_node))

%Benchmark.ToolModel{
%Graphite.ToolModel{
auth_node: auth_node
}
|> struct!(attributes)
end

def build(:benchmark_spot, %{} = attributes) do
{tool, attributes} = Map.pop(attributes, :tool, build(:benchmark_tool))
def build(:graphite_submission, %{} = attributes) do
{tool, attributes} = Map.pop(attributes, :tool, build(:graphite_tool))
{auth_node, attributes} = Map.pop(attributes, :auth_node, build(:auth_node))

%Benchmark.SpotModel{
%Graphite.SubmissionModel{
tool: tool,
auth_node: auth_node
}
|> struct!(attributes)
end

def build(:benchmark_submission, %{} = attributes) do
{spot, attributes} = Map.pop(attributes, :spot, build(:benchmark_spot))

%Benchmark.SubmissionModel{
spot: spot
}
|> struct!(attributes)
end

def build(:feldspar_tool, %{} = attributes) do
{auth_node, attributes} = Map.pop(attributes, :auth_node, build(:auth_node))

Expand Down
2 changes: 1 addition & 1 deletion core/lib/core_web/controllers/user_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ defmodule CoreWeb.UserAuth do
conn
else
conn
|> put_flash(:error, dgettext("eyra-ui", "authentication.required.error"))
|> put_flash(:info, dgettext("eyra-ui", "authentication.required.message"))
|> maybe_store_return_to()
|> redirect(to: ~p"/user/signin")
|> halt()
Expand Down
9 changes: 7 additions & 2 deletions core/lib/core_web/file_uploader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ defmodule CoreWeb.FileUploader do
# Skip init if it already has been called
def init_file_uploader(%{assigns: %{uploads: _uploads}} = socket, _key), do: socket

def init_file_uploader(socket, key, max_file_size \\ 20_000_000) do
def init_file_uploader(socket, key) do
socket
|> allow_upload(key,
accept: unquote(accept),
progress: &handle_progress/3,
max_file_size: max_file_size,
max_file_size: get_max_file_size(),
auto_upload: true
)
end

def get_max_file_size() do
config = Application.fetch_env!(:core, CoreWeb.FileUploader)
Keyword.fetch!(config, :max_file_size)
end

def handle_progress(_key, entry, socket) do
if entry.done? do
upload_result = consume_file(socket, entry)
Expand Down
2 changes: 1 addition & 1 deletion core/priv/gettext/en/LC_MESSAGES/errors.po
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ msgstr ""
"Language: en\n"

msgid "can't be blank"
msgstr ""
msgstr "Please fill out this field"

msgid "has already been taken"
msgstr ""
Expand Down
Loading

0 comments on commit 4cf8a66

Please sign in to comment.