Skip to content

Commit

Permalink
Merge branch 'master' into Update_copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mellelieuwes authored Dec 5, 2023
2 parents 62c7723 + 3aba4c2 commit 9f1d3ac
Show file tree
Hide file tree
Showing 76 changed files with 1,212 additions and 426 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@2a4836ac76fe8f5d0ee3a0d89aa12a80cc552ad3
uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4
with:
images: |
${{env.REGISTRY}}/eyra/${{github.event.inputs.bundle}}
Expand Down
5 changes: 4 additions & 1 deletion core/.dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[
# https://github.com/phoenixframework/phoenix/issues/5437
{"systems/benchmark/export_controller.ex", :no_return},
{"systems/benchmark/export_controller.ex", :call}
{"systems/benchmark/export_controller.ex", :call},
# issue with HTTPPoison not supporting HTTP method :mkcol
{"systems/storage/yoda/client.ex", :no_return},
{"systems/storage/yoda/client.ex", :call}
]
4 changes: 2 additions & 2 deletions core/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@tailwind components;

trix-toolbar {
@apply mb-4 drop-shadow-lg h-8;
@apply mb-4 h-8;
}

trix-toolbar .trix-button-row {
Expand All @@ -15,7 +15,7 @@ trix-toolbar .trix-button-row {
}

trix-toolbar .trix-button-group {
@apply flex rounded-lg overflow-hidden h-full;
@apply flex border-2 border-grey4 rounded-lg overflow-hidden h-full;
}
trix-toolbar .trix-button-group:not(:first-child) {
margin-left: 1.5vw;
Expand Down
71 changes: 67 additions & 4 deletions core/assets/js/wysiwyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,72 @@ import Trix from "trix";

export const Wysiwyg = {
mounted() {
const element = document.querySelector("trix-editor");
element.editor.element.addEventListener("trix-change", (e) => {
element.dispatchEvent(new Event("input", {bubbles: true}))
console.log("[Wysiwyg] Mounted");
this.init();
this.insertTextArea(this.html);
this.upsert_editor(this.visible);
},
updated() {
console.log("[Wysiwyg] Updated");
if (!this.el.parentNode.classList.contains("border-primary")) {
console.log("[Wysiwyg] Reset");
this.init();
this.insertTextArea(this.html);
this.upsert_editor(this.visible);
}
},
init() {
this.id = this.el.dataset.id;
this.name = this.el.dataset.name;
this.target = this.el.dataset.target;
this.html = this.el.dataset.html;
this.visible = this.el.dataset.visible != undefined;
this.locked = this.el.dataset.locked != undefined;
},
insertTextArea(html) {
if (this.textarea != undefined) {
this.textarea.remove();
}

this.textarea = document.createElement("textarea");
this.textarea.setAttribute("id", this.id);
this.textarea.setAttribute("name", this.name);
this.textarea.setAttribute("phx-target", this.target);
this.textarea.setAttribute("phx-debounce", "1000");
this.textarea.classList.add("hidden");
this.textarea.value = html;
this.el.appendChild(this.textarea);
},
upsert_editor(visible) {
if (visible) {
this.removeEditor();
this.insertEditor();
} else {
this.removeEditor();
}
},
insertEditor() {
this.editor = document.createElement("trix-editor");
this.editor.setAttribute("input", this.textarea.id);
this.editor.classList.add("min-h-wysiwyg-editor");
this.editor.classList.add("max-h-wysiwyg-editor");
this.editor.classList.add("overflow-y-scroll");
this.editor.setAttribute("phx-debounce", "1000");

this.container = document.createElement("div");
this.container.appendChild(this.editor);
this.el.appendChild(this.container);
this.editor.addEventListener("trix-change", (e) => {
this.editor.dispatchEvent(new Event("input", { bubbles: true }));
});
},
};
removeEditor() {
if (this.container != undefined) {
while (this.container.lastElementChild) {
this.container.removeChild(this.container.lastElementChild);
}
this.container.remove();
this.container = undefined;
}
},
};
1 change: 1 addition & 0 deletions core/assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
"./js/**/*.js",
],
safelist: [
"drop-shadow-lg",
"drop-shadow-2xl",
"text-bold",
"text-pre",
Expand Down
9 changes: 9 additions & 0 deletions core/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ config :core,
# access_key_id: "my_access_key",
# secret_access_key: "a_super_secret"

config :core, :content,
backend: Systems.Content.LocalFS,
local_fs_root_path:
File.cwd!()
|> Path.join("priv")
|> Path.join("static")
|> Path.join("content")
|> tap(&File.mkdir_p!/1)

config :core, :feldspar,
backend: Systems.Feldspar.LocalFS,
local_fs_root_path:
Expand Down
12 changes: 9 additions & 3 deletions core/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ if config_env() == :prod do
dsn: System.get_env("SENTRY_DSN"),
environment_name: System.get_env("RELEASE_ENV") || "prod"

config :core, :content,
backend: Systems.Content.S3,
bucket: System.get_env("PUBLIC_S3_BUCKET"),
public_url: System.get_env("PUBLIC_S3_URL"),
prefix: System.get_env("CONTENT_S3_PREFIX", nil)

config :core, :feldspar,
backend: Systems.Feldspar.S3,
bucket: System.get_env("FELDSPAR_S3_BUCKET"),
prefix: System.get_env("FELDSPAR_S3_PREFIX", nil),
bucket: System.get_env("PUBLIC_S3_BUCKET"),
# The public URL must point to the root's (bucket) publicly accessible URL.
# It should have a policy that allows anonymous users to read all files.
public_url: System.get_env("FELDSPAR_S3_PUBLIC_URL")
public_url: System.get_env("PUBLIC_S3_URL"),
prefix: System.get_env("FELDSPAR_S3_PREFIX", nil)

config :core,
:dist_hosts,
Expand Down
4 changes: 4 additions & 0 deletions core/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ config :core, :bundle, :next

config :core, :banking_backend, Systems.Banking.Dummy

config :core, :content,
backend: Systems.Content.LocalFS,
local_fs_root_path: "/tmp"

config :core, :feldspar,
backend: Systems.Feldspar.LocalFS,
local_fs_root_path: "/tmp"
98 changes: 59 additions & 39 deletions core/frameworks/fabric.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ defmodule Fabric do
Phoenix.Component.assign(assigns, element_id, element)
end

def update_child(context, child_id) when is_atom(child_id) do
if exists?(context, child_id) do
compose_child(context, child_id)
def update_child(context, child_name) when is_atom(child_name) do
if exists?(context, child_name) do
compose_child(context, child_name)
else
context
end
end

def compose_child(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_id)
when is_atom(child_id) do
%Phoenix.LiveView.Socket{socket | assigns: compose_child(assigns, child_id)}
def compose_child(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_name)
when is_atom(child_name) do
%Phoenix.LiveView.Socket{socket | assigns: compose_child(assigns, child_name)}
end

def compose_child(%{fabric: fabric} = assigns, child_id) when is_atom(child_id) do
def compose_child(%{fabric: fabric} = assigns, child_name) when is_atom(child_name) do
fabric =
if child = prepare_child(fabric, child_id, compose(child_id, assigns)) do
if child = prepare_child(fabric, child_name, compose(child_name, assigns)) do
add_child(fabric, child)
else
remove_child(fabric, child_id)
remove_child(fabric, child_name)
end

Phoenix.Component.assign(assigns, fabric: fabric)
Expand All @@ -59,29 +59,46 @@ defmodule Fabric do
end
end

# Child id

def child_id(%Fabric.Model{self: self}, child_name), do: child_id(self, child_name)

def child_id(%{pid: pid}, child_name) do
pid_string =
pid
|> :erlang.pid_to_list()
|> to_string()
|> then(&("PID" <> &1))

child_id(pid_string, child_name)
end

def child_id(%{id: id}, child_name), do: child_id(id, child_name)
def child_id(context, child_name), do: "#{child_name}->#{context}"
# Prepare

def prepare_child(context, child_id, %{module: module, params: params}) do
prepare_child(context, child_id, module, params)
def prepare_child(context, child_name, %{module: module, params: params}) do
prepare_child(context, child_name, module, params)
end

def prepare_child(_context, _child_id, _), do: nil

def prepare_child(
%Phoenix.LiveView.Socket{assigns: assigns},
child_id,
child_name,
module,
params
) do
prepare_child(assigns, child_id, module, params)
prepare_child(assigns, child_name, module, params)
end

def prepare_child(%{fabric: fabric}, child_id, module, params) do
prepare_child(fabric, child_id, module, params)
def prepare_child(%{fabric: fabric}, child_name, module, params) do
prepare_child(fabric, child_name, module, params)
end

def prepare_child(%Fabric.Model{self: self}, child_id, module, params) do
child_ref = %Fabric.LiveComponent.RefModel{id: child_id, module: module}
def prepare_child(%Fabric.Model{self: self}, child_name, module, params) do
child_id = child_id(self, child_name)
child_ref = %Fabric.LiveComponent.RefModel{id: child_id, name: child_name, module: module}
child_fabric = %Fabric.Model{parent: self, self: child_ref, children: nil}
params = Map.put(params, :fabric, child_fabric)
%Fabric.LiveComponent.Model{ref: child_ref, params: params}
Expand All @@ -104,20 +121,20 @@ defmodule Fabric do

# CRUD

def get_child(%Phoenix.LiveView.Socket{assigns: %{fabric: fabric}}, child_id) do
get_child(fabric, child_id)
def get_child(%Phoenix.LiveView.Socket{assigns: %{fabric: fabric}}, child_name) do
get_child(fabric, child_name)
end

def get_child(%{fabric: fabric}, child_id) do
get_child(fabric, child_id)
def get_child(%{fabric: fabric}, child_name) do
get_child(fabric, child_name)
end

def get_child(%Fabric.Model{children: children}, child_id) do
Enum.find(List.wrap(children), &(&1.ref.id == child_id))
def get_child(%Fabric.Model{children: children}, child_name) do
Enum.find(List.wrap(children), &(&1.ref.name == child_name))
end

def exists?(context, child_id) do
get_child(context, child_id) != nil
def exists?(context, child_name) do
get_child(context, child_name) != nil
end

def new_fabric(%Phoenix.LiveView.Socket{} = socket) do
Expand Down Expand Up @@ -159,16 +176,16 @@ defmodule Fabric do
)
end

def hide_child(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_id) do
%Phoenix.LiveView.Socket{socket | assigns: hide_child(assigns, child_id)}
def hide_child(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_name) do
%Phoenix.LiveView.Socket{socket | assigns: hide_child(assigns, child_name)}
end

def hide_child(%{fabric: fabric} = assigns, child_id) do
Phoenix.Component.assign(assigns, fabric: remove_child(fabric, child_id))
def hide_child(%{fabric: fabric} = assigns, child_name) do
Phoenix.Component.assign(assigns, fabric: remove_child(fabric, child_name))
end

def show_popup(context, child_id) when is_atom(child_id) do
child = get_child(context, child_id)
def show_popup(context, child_name) when is_atom(child_name) do
child = get_child(context, child_name)
show_popup(context, child)
end

Expand All @@ -184,13 +201,13 @@ defmodule Fabric do
Phoenix.Component.assign(assigns, fabric: add_child(fabric, child))
end

def hide_popup(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_id) do
%Phoenix.LiveView.Socket{socket | assigns: hide_popup(assigns, child_id)}
def hide_popup(%Phoenix.LiveView.Socket{assigns: assigns} = socket, child_name) do
%Phoenix.LiveView.Socket{socket | assigns: hide_popup(assigns, child_name)}
end

def hide_popup(%{fabric: fabric} = assigns, child_id) do
def hide_popup(%{fabric: fabric} = assigns, child_name) do
send_event(fabric, :root, "hide_popup")
Phoenix.Component.assign(assigns, fabric: remove_child(fabric, child_id))
Phoenix.Component.assign(assigns, fabric: remove_child(fabric, child_name))
end

def add_child(%Fabric.Model{children: nil} = fabric, %Fabric.LiveComponent.Model{} = child) do
Expand All @@ -210,8 +227,11 @@ defmodule Fabric do

def remove_child(%Fabric.Model{} = fabric, nil), do: fabric

def remove_child(%Fabric.Model{children: children} = fabric, child_id) do
%Fabric.Model{fabric | children: Enum.filter(List.wrap(children), &(&1.ref.id != child_id))}
def remove_child(%Fabric.Model{children: children} = fabric, child_name) do
%Fabric.Model{
fabric
| children: Enum.filter(List.wrap(children), &(&1.ref.name != child_name))
}
end

# Flow
Expand Down Expand Up @@ -266,8 +286,8 @@ defmodule Fabric do
raise "Sending event '#{name}' to empty flow"
end

def send_event(%Fabric.Model{} = fabric, child_id, name, payload) do
if child = get_child(fabric, child_id) do
def send_event(%Fabric.Model{} = fabric, child_name, name, payload) do
if child = get_child(fabric, child_name) do
send_event(child.ref, %{name: name, payload: payload})
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/frameworks/fabric/html.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule Fabric.Html do
use Phoenix.Component

attr(:id, :any, required: true)
attr(:name, :any, required: true)
attr(:fabric, :map, required: true)
slot(:header)
slot(:footer)

def child(assigns) do
~H"""
<%= if child = Fabric.get_child(@fabric, @id) do %>
<%= if child = Fabric.get_child(@fabric, @name) do %>
<%= render_slot(@header) %>
<.live_child {Map.from_struct(child)} />
<%= render_slot(@footer) %>
Expand Down
4 changes: 2 additions & 2 deletions core/frameworks/fabric/live_component.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Fabric.LiveComponent do
defmodule RefModel do
@type t :: %__MODULE__{id: atom() | binary(), module: atom()}
defstruct [:id, :module]
@type t :: %__MODULE__{id: atom() | binary(), name: atom() | binary(), module: atom()}
defstruct [:id, :name, :module]
end

defmodule Model do
Expand Down
Loading

0 comments on commit 9f1d3ac

Please sign in to comment.