Skip to content

Commit

Permalink
Merge pull request #710 from eyra/rank-prefer
Browse files Browse the repository at this point in the history
Rank prefer
  • Loading branch information
mellelieuwes authored Apr 29, 2024
2 parents 70a89c7 + 1c7cb0b commit 66d9b2e
Show file tree
Hide file tree
Showing 145 changed files with 5,842 additions and 1,823 deletions.
8 changes: 8 additions & 0 deletions core/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ import { FeldsparApp } from "./feldspar_app";
import { Wysiwyg } from "./wysiwyg";
import { AutoSubmit } from "./auto_submit";
import { Sticky } from "./sticky";
import { TimeZone } from "./timezone";

window.registerAPNSDeviceToken = registerAPNSDeviceToken;

window.addEventListener("phx:page-loading-stop", (info) => {
if (info.detail.kind == "initial") {
TimeZone.sendToServer();
}
});

window.blurHash = () => {
return {
show: true,
Expand Down Expand Up @@ -105,6 +112,7 @@ let Hooks = {
Wysiwyg,
AutoSubmit,
Sticky,
TimeZone,
};

let liveSocket = new LiveSocket("/live", Socket, {
Expand Down
35 changes: 35 additions & 0 deletions core/assets/js/timezone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const TimeZone = {
mounted() {
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log("TimeZone", timezone);
this.pushEventTo(".timezone", "timezone", timezone);
},
sendToServer() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

console.log("[TimeZone]", timezone);

let csrfToken = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");

if (typeof window.localStorage != "undefined") {
try {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/api/timezone", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("x-csrf-token", csrfToken);
xhr.onreadystatechange = function () {
console.log(
"[TimeZone] POST onreadystatechange",
this.status,
this.readyState
);
};
xhr.send(`{"timezone": "${timezone}"}`);
} catch (e) {
console.log("[TimeZone] Error while sending timezone to server", e);
}
}
},
};
3 changes: 2 additions & 1 deletion core/bundles/next/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ config :core, :features,
member_google_sign_in: false,
password_sign_in: true,
notification_mails: false,
debug_expire_force: false
debug_expire_force: false,
leaderboard: false

config :core, :meta,
bundle_title: "Eyra",
Expand Down
37 changes: 0 additions & 37 deletions core/bundles/next/lib/console/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,4 @@ defmodule Next.Console.Page do
quick_summary: ""
}
end

def convert_to_vm(
_socket,
%{
id: spot_id,
name: name,
updated_at: updated_at,
tool: %{
id: tool_id,
title: title,
status: status
}
}
) do
tag = get_tag(status)

quick_summary =
updated_at
|> CoreWeb.UI.Timestamp.apply_timezone()
|> CoreWeb.UI.Timestamp.humanize()
|> Macro.camelize()

%{
path: ~p"/graphite/#{tool_id}/#{spot_id}",
title: title,
subtitle: "#{name}",
tag: tag,
level: :critical,
image: nil,
quick_summary: quick_summary
}
end

defp get_tag(:concept), do: %{type: :warning, text: dgettext("eyra-project", "label.concept")}
defp get_tag(:online), do: %{type: :success, text: dgettext("eyra-project", "label.online")}
defp get_tag(:offline), do: %{type: :delete, text: dgettext("eyra-project", "label.offline")}
defp get_tag(:idle), do: %{type: :idle, text: dgettext("eyra-project", "label.idle")}
end
37 changes: 0 additions & 37 deletions core/bundles/self/lib/console/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,4 @@ defmodule Self.Console.Page do
quick_summary: ""
}
end

def convert_to_vm(
_socket,
%{
id: spot_id,
name: name,
updated_at: updated_at,
tool: %{
id: tool_id,
title: title,
status: status
}
}
) do
tag = get_tag(status)

quick_summary =
updated_at
|> CoreWeb.UI.Timestamp.apply_timezone()
|> CoreWeb.UI.Timestamp.humanize()
|> Macro.camelize()

%{
path: ~p"/graphite/#{tool_id}/#{spot_id}",
title: title,
subtitle: "#{name}",
tag: tag,
level: :critical,
image: nil,
quick_summary: quick_summary
}
end

defp get_tag(:concept), do: %{type: :warning, text: dgettext("eyra-project", "label.concept")}
defp get_tag(:online), do: %{type: :success, text: dgettext("eyra-project", "label.online")}
defp get_tag(:offline), do: %{type: :delete, text: dgettext("eyra-project", "label.offline")}
defp get_tag(:idle), do: %{type: :idle, text: dgettext("eyra-project", "label.idle")}
end
2 changes: 2 additions & 0 deletions core/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ config :core, :content, backend: Systems.Content.LocalFS

config :core, :feldspar, backend: Systems.Feldspar.LocalFS

config :core, :features, leaderboard: true

try do
import_config "dev.secret.exs"
rescue
Expand Down
19 changes: 14 additions & 5 deletions core/frameworks/green_light/live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Frameworks.GreenLight.Live do
require Logger

@moduledoc """
The Live module enables automatic authorization checks for LiveViews.
"""
Expand Down Expand Up @@ -26,11 +28,18 @@ defmodule Frameworks.GreenLight.Live do
quote do
if Module.defines?(__MODULE__, {:get_authorization_context, 3}) do
defp access_allowed?(params, session, socket) do
@greenlight_authmodule.can_access?(
socket,
get_authorization_context(params, session, socket),
__MODULE__
)
user = Map.get(socket.assigns, :current_user)

can_access? =
@greenlight_authmodule.can_access?(
socket,
get_authorization_context(params, session, socket)
|> Core.Authorization.print_roles(),
__MODULE__
)

Logger.notice("User #{user.id} can_access? #{__MODULE__}: #{can_access?}")
can_access?
end
else
defp access_allowed?(_params, session, socket) do
Expand Down
58 changes: 58 additions & 0 deletions core/frameworks/pixel/components/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ defmodule Frameworks.Pixel.Form do
attr(:reserve_error_space, :boolean, default: true)
attr(:debounce, :string, default: "1000")
attr(:maxlength, :string, default: "1000")
attr(:disabled, :boolean, default: false)

def text_input(assigns) do
~H"""
Expand All @@ -238,6 +239,39 @@ defmodule Frameworks.Pixel.Form do
debounce={@debounce}
maxlength={@maxlength}
type="text"
disabled={@disabled}
/>
"""
end

attr(:form, :any, required: true)
attr(:field, :atom, required: true)
attr(:label_text, :string, default: nil)
attr(:label_color, :string, default: "text-grey1")
attr(:background, :atom, default: :light)
attr(:placeholder, :string, default: "")
attr(:reserve_error_space, :boolean, default: true)
attr(:debounce, :string, default: "1000")
attr(:maxlength, :string, default: "1000")
attr(:value, :string, default: "")

# FIXME: discuss how to make this neater. Now I just force the display of the
# provided value
# Used for working with providing a list of values in one text field in a form.
def list_input(assigns) do
~H"""
<.input
form={@form}
field={@field}
label_text={@label_text}
label_color={@label_color}
background={@background}
placeholder={@placeholder}
reserve_error_space={@reserve_error_space}
debounce={@debounce}
maxlength={@maxlength}
type="text"
value={@value}
/>
"""
end
Expand Down Expand Up @@ -314,6 +348,30 @@ defmodule Frameworks.Pixel.Form do
"""
end

attr(:form, :any, required: true)
attr(:field, :atom, required: true)
attr(:label_text, :string)
attr(:label_color, :string, default: "text-grey1")
attr(:background, :atom, default: :light)
attr(:disabled, :boolean, default: false)
attr(:reserve_error_space, :boolean, default: true)

def datetime_input(assigns) do
~H"""
<.input
form={@form}
field={@field}
label_text={@label_text}
label_color={@label_color}
background={@background}
reserve_error_space={@reserve_error_space}
type="datetime-local"
disabled={@disabled}
debounce={""}
/>
"""
end

attr(:form, :any, required: true)
attr(:field, :atom, required: true)
attr(:label_text, :string)
Expand Down
3 changes: 2 additions & 1 deletion core/frameworks/pixel/components/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ defmodule Frameworks.Pixel.Text do

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

def title6(assigns) do
~H"""
<div class={"text-title6 font-title6 #{@margin} #{@color}"}>
<div class={"text-title6 font-title6 #{@align} #{@margin} #{@color}"}>
<%= render_slot(@inner_block) %>
</div>
"""
Expand Down
6 changes: 4 additions & 2 deletions core/frameworks/signal/_public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Frameworks.Signal.Public do

import Frameworks.Utililty.PrettyPrint

# FIXME: move this registration outside of framework
@signal_handlers [
"Core.Accounts.SignalHandlers",
"Core.Mailer.SignalHandlers",
Expand All @@ -18,15 +19,16 @@ defmodule Frameworks.Signal.Public do
"Systems.Campaign.Switch",
"Systems.NextAction.Switch",
"Systems.Crew.Switch",
"Systems.Instruction.Switch"
"Systems.Instruction.Switch",
"Systems.Graphite.Switch"
]

def dispatch(signal, message) do
message = Map.put_new(message, :from_pid, self())

Logger.notice(
"SIGNAL: #{pretty_print(signal)} => #{pretty_print(Map.keys(message))}, FROM: #{inspect(Map.get(message, :from_pid))}",
ansi_color: :light_magenta
ansi_color: :blue
)

results = Enum.map(signal_handlers(), & &1.intercept(signal, message))
Expand Down
5 changes: 5 additions & 0 deletions core/frameworks/utililty/ecto_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ defmodule Frameworks.Utility.EctoHelper do
alias Core.Repo
alias Frameworks.Signal

def get_assoc(entity, assoc) when is_atom(assoc) do
Repo.preload(entity, [assoc])
|> Map.get(assoc)
end

def put_assoc(changeset, key, value, execute?) do
if execute? do
Changeset.put_assoc(changeset, key, value)
Expand Down
3 changes: 3 additions & 0 deletions core/frameworks/utililty/list.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule Frameworks.Utility.List do
def append_if(list, false, _element), do: list
def append_if(list, true, element), do: append(list, element)
def append_if(list, nil), do: list
def append_if(list, element), do: append(list, element)

def append(list, element), do: list ++ [element]

def insert_at_every(list, every, fun) do
Expand Down
40 changes: 23 additions & 17 deletions core/frameworks/utililty/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,33 @@ defmodule Frameworks.Utility.Query do
end
end

def quote_expr({:!=, _, [{property, _, _}, nil]}, parent) do
parent
|> quote_property(property)
|> quote_is_nil()
|> quote_not()
end

def quote_expr({:==, _, [{property, _, _}, nil]}, parent) do
{:is_nil, [],
[
{
{:., [],
[
{parent, [], nil},
property
]},
[],
[]
}
]}
parent
|> quote_property(property)
|> quote_is_nil()
end

def quote_expr({operator, _, [{property, _, _}, value]}, parent) do
{operator, [],
[
{{:., [], [{parent, [], nil}, property]}, [no_parens: true], []},
value
]}
{operator, [], [quote_property(parent, property), value]}
end

def quote_not(inner_quote) do
{:not, [], [inner_quote]}
end

def quote_is_nil(inner_quote) do
{:is_nil, [], [inner_quote]}
end

def quote_property(parent, property) do
{{:., [], [{parent, [], nil}, property]}, [no_parens: true], []}
end

def compile_clauses([], _parent), do: []
Expand Down
Loading

0 comments on commit 66d9b2e

Please sign in to comment.