Skip to content

Commit

Permalink
DEV GI results
Browse files Browse the repository at this point in the history
  • Loading branch information
IciaCarroBarallobre committed Jan 7, 2025
1 parent 9091f2c commit a24ab8d
Show file tree
Hide file tree
Showing 13 changed files with 1,540 additions and 43 deletions.
16 changes: 15 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ import {Socket} from "phoenix"
import {LiveSocket} from "phoenix_live_view"
import topbar from "../vendor/topbar"

let Hooks = {};
Hooks.ClipboardCopy = {
mounted() {
this.handleEvent("clipboard_copy", ({ text }) => {
navigator.clipboard.writeText(text).then(() => {
alert("Link copied to clipboard!");
}).catch(() => {
alert("Failed to copy the link!");
});
});
}
};

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}, hooks: Hooks});
liveSocket.connect();

// Show progress bar on live navigation and form submits
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
Expand Down
2 changes: 1 addition & 1 deletion lib/exploring_beam_community_web/components/footer.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExploringBeamCommunityWeb.Footer do
defmodule ExploringBeamCommunityWeb.Components.Footer do
use Phoenix.Component

attr(:navigation_pages, :list, required: true)
Expand Down
4 changes: 2 additions & 2 deletions lib/exploring_beam_community_web/components/layouts.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule ExploringBeamCommunityWeb.Layouts do
use ExploringBeamCommunityWeb, :html
import ExploringBeamCommunityWeb.CoreComponents
import ExploringBeamCommunityWeb.Navbar, only: [navbar: 1]
import ExploringBeamCommunityWeb.Footer, only: [footer: 1]
import ExploringBeamCommunityWeb.Components.Navbar, only: [navbar: 1]
import ExploringBeamCommunityWeb.Components.Footer, only: [footer: 1]

embed_templates("layouts/*")
end
13 changes: 13 additions & 0 deletions lib/exploring_beam_community_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
</script>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;

mermaid.initialize({
startOnLoad: true,
theme: isDarkMode ? 'base' : 'default',
themeVariables: isDarkMode ? {
primaryTextColor: '#ffffff',
pieOuterStrokeWidth: '0px',
} : {pieOuterStrokeWidth: '0px'},
});
</script>
</head>
<body class="bg-white dark:bg-main-900 antialiased text-main-900 dark:text-white">
<%= @inner_content %>
Expand Down
6 changes: 3 additions & 3 deletions lib/exploring_beam_community_web/components/navbar.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExploringBeamCommunityWeb.Navbar do
defmodule ExploringBeamCommunityWeb.Components.Navbar do
import ExploringBeamCommunityWeb.CoreComponents, only: [icon: 1]

use Phoenix.Component
Expand All @@ -12,7 +12,7 @@ defmodule ExploringBeamCommunityWeb.Navbar do
attr(:navigation_pages, :list, required: true)
attr(:logo, :string, default: "")
attr(:dark_logo, :string, default: "")
slot(:banner, required: false)
slot(:banner, default: nil)

def navbar(assigns) do
~H"""
Expand Down Expand Up @@ -72,7 +72,7 @@ defmodule ExploringBeamCommunityWeb.Navbar do
</nav>
</div>
</header>
<% if @banner != nil do%>
<%= if @banner != nil and @banner != [] do%>
<p class="text-center font-semibold bg-main-200 dark:bg-main-500 py-2">
<%= render_slot(@banner) %>
</p>
Expand Down
88 changes: 88 additions & 0 deletions lib/exploring_beam_community_web/components/question.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
defmodule ExploringBeamCommunityWeb.Components.Question do
import ExploringBeamCommunityWeb.Components.TypeOfQuestion,
only: [multiple_choice_question: 1, single_choice_question: 1, range_question: 1]

import ExploringBeamCommunityWeb.CoreComponents, only: [icon: 1]

use ExploringBeamCommunityWeb, :live_component

@impl true
def mount(socket) do
base_url = ExploringBeamCommunityWeb.Endpoint.url()
{:ok, assign(socket, shown_all: false, top: 5, base_url: base_url)}
end

@impl true
def handle_event("toggle_shown_all", _params, socket) do
{:noreply, update(socket, :shown_all, fn shown -> not shown end)}
end

@impl true
def handle_event("copy_link", %{"question_id" => question_id}, socket) do
base_url = socket.assigns.base_url
shareable_link = "#{base_url}/results##{question_id}"

{:noreply, push_event(socket, "clipboard_copy", %{text: shareable_link})}
end

@impl true
def render(assigns) do
~H"""
<div class="py-12 border-b border-gray-500" id={"q-#{@id}"}>
<div class="flex">
<button
type="button"
phx-target={@myself}
phx-click={JS.push("copy_link", value: %{question_id: "q-#{@id}"})}
class="text-gray-400 hover:text-blue-700 flex items-center gap-1"
title="Copy link to this question"
>
<.icon name="hero-link" class=" mb-3 w-5 h-5 text-gray-400 hover:text-blue-700 "/>
</button>
<p class="ml-2 text-xl mb-3 font-light">
<strong><%= @question["QuestionText"] %></strong>
</p>
</div>
<p class="text-sm text-right mr-4"><%= @question["TotalAnswers"] %> answered</p>
<%= case @question["QuestionType"] do %>
<% "Multiple-choice" -> %>
<%= if (length(@question["Options"]) > @top) do%>
<button
type="button"
phx-click="toggle_shown_all"
phx-target={@myself}
class="text-main-400 hover:text-main-500 flex items-center gap-2"
>
<span>
<%= if @shown_all do %>
Show the top-<%=@top%>
<.icon name="hero-chevron-up" class="w-5 h-5 text-main-500" />
<% else %>
Show all
<.icon name="hero-chevron-down" class="w-5 h-5 text-main-500" />
<% end %>
</span>
</button>
<%end%>
<.multiple_choice_question options={@question["Options"]} shown_all={@shown_all} top={@top} />
<% "Range" -> %>
<.range_question options={@question["Options"]} />
<% "Single-choice" -> %>
<.single_choice_question options={@question["Options"]} />
<% _ -> %>
<p>An error occurred while rendering this question.</p>
<% end %>
<%= if @question["Observation"] do %>
<p class="mt-8 bg-main-100 border-l-4 border-main-400 text-main-800 p-4 rounded-md shadow-sm">
<strong>Observation:</strong> <%= @question["Observation"] %>
</p>
<% end %>
</div>
"""
end
end
78 changes: 78 additions & 0 deletions lib/exploring_beam_community_web/components/type_of_question.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
defmodule ExploringBeamCommunityWeb.Components.TypeOfQuestion do
use Phoenix.Component

attr(:options, :list, required: true)
attr(:top, :integer, default: 5)
attr(:shown_all, :boolean, default: true)

def multiple_choice_question(assigns) do
assigns = assign(assigns, :options, assigns.options |> Enum.sort_by(& &1["Responses"], :desc))

~H"""
<div class="mt-4 space-y-3">
<%= for option <- if @shown_all, do: @options, else: Enum.take(@options, @top) do %>
<div class="relative">
<span class="block text-right font-semibold my-2 flex justify-between items-center">
<span class="text-sm font-bold mb-1"><%= option["Label"] %></span>
<span class="text-right font-semibold my-2">
<span class="text-xs mx-3"><%= option["Responses"] %> resp.</span>
<span class="text-sm"><%= parse_percentage(option["Percentage"]) || "N/A" %></span>
</span>
</span>
<div class="h-6 rounded-md bg-main-100 relative">
<div class="bg-main-500 h-full rounded-md" style={"width: #{String.replace(parse_percentage(option["Percentage"] || "0%"), "%", "")}%;"}></div>
</div>
</div>
<% end %>
</div>
"""
end

attr(:options, :list, required: true)

def single_choice_question(assigns) do
~H"""
<div class="mermaid" class="w-full">
pie
<%= for option <- @options do %>
"<%= option["Label"] %>" : <%= option["Responses"] %>
<% end %>
</div>
"""
end

attr(:options, :list, required: true)

def range_question(assigns) do
~H"""
<div class="mermaid" class="w-full">
xychart-beta
x-axis <%= list_to_text(for option <- @options, do: option["Label"]) %>
y-axis "Responses" 0 --> <%= Enum.max(for option <- @options, do: option["Responses"])%>
bar <%= inspect(for option <- @options, do: option["Responses"])%>
line <%= inspect(for option <- @options, do: option["Responses"])%>
</div>
"""
end

defp parse_percentage(nil), do: "N/A"

defp parse_percentage(percentage) when is_binary(percentage) do
percentage
|> String.replace("%", "")
|> String.to_float()
|> Float.round(1)
|> Kernel.to_string()
|> Kernel.<>("%")
end

def list_to_text(list) do
"[" <>
Enum.join(
for item <- list do
"\"#{item}\""
end,
", "
) <> "]"
end
end
92 changes: 73 additions & 19 deletions lib/exploring_beam_community_web/live/results.ex
Original file line number Diff line number Diff line change
@@ -1,31 +1,85 @@
defmodule ExploringBeamCommunityWeb.ResultsView do
use ExploringBeamCommunityWeb, :live_view
alias ExploringBeamCommunityWeb.Components.{Question}

def mount(_params, _session, socket) do
slides =
%{
id: "form1",
path: "/pdf/slides.pdf"
}
results =
case File.read("priv/static/results/dev_gi.json") do
{:ok, file_content} ->
case Jason.decode(file_content) do
{:ok, data} -> data
{:error, _} -> %{"Questions" => []}
end

{:ok, assign(socket, slides: slides, page_title: "Results")}
{:error, _} ->
%{"Questions" => []}
end

{:ok, assign(socket, results: results, page_title: "Results")}
end

def render(assigns) do
~H"""
<div class="p-3 text-center mx-auto ">
<div class="m-6">
<.button phx-click={JS.navigate("/pdf/slides.pdf")}>
Download PDF <.icon name="hero-arrow-down-on-square" class="h-6 w-6" />
</.button>
</div>
<div style="position: relative; padding-bottom: 80%; height: 0; overflow: hidden;">
<iframe src="/pdf/slides.pdf" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" frameborder="0" allowfullscreen>
This browser does not support PDFs. Please download the PDF to view it: <a href="/pdf/slides.pdf">Download PDF</a>.
</iframe>
</div>
</div>
<!-- Header -->
<div>
<div class="text-center mb-8">
<h1 class="text-4xl md:text-5xl font-extralight my-4">BEAM <%= @results["Name"]%> Survey <%= @results["Year"]%></h1>
<p class="text-lg mt-2 font-light ">
Explore the trends, challenges, and strengths of the BEAM ecosystem from <%= @results["TotalResponses"]%> participants.
</p>
</div>
<!-- Categories Section -->
<div class="text-center font-light my-8">
<div class="flex flex-wrap gap-6 justify-center">
<%= for {section, section_index} <- Enum.with_index(@results["Sections"]) do %>
<%= button_to_section(%{index: section_index, name: section["Name"]}) %>
<% end %>
</div>
</div>
</div>
<!-- Sections & Questions-->
<div class="results-container space-y-8">
<%= for {section, section_index} <- Enum.with_index(@results["Sections"]) do %>
<div id={"section-#{section_index}"} class={"section-#{section_index} p-6"}>
<h3 class="text-2xl text-center font-semibold pb-3 mb-4">
<a href={"#section-#{section_index}"}>
<%= section["Name"] %>
</a>
</h3>
<%= for {question, question_index} <- Enum.with_index(section["Questions"]) do %>
<.live_component
module={Question}
question={question}
id={"section_#{section_index}_question_#{question_index}"
}/>
<% end %>
</div>
<% end %>
</div>
<!-- Final -->
<div class="m-4">
<h3 class="text-center text-light text-2xl m-4"> ✨ A Big Thank You to All Participants! 💌</h3>
<p class="text-center">
We want to extend our heartfelt gratitude to each and every one of you for your invaluable input.
🙏 Your feedback is not just appreciated—it’s truly instrumental in guiding us as we continue to improve and evolve.
We are incredibly grateful for the time and effort you’ve invested. We keep working to make the next ones better. ❤️💜💗
</p>
</div>
"""
end

def button_to_section(assigns) do
~H"""
<a href={"#section-#{@index}"} class="bg-main-500 text-white py-2 px-4 rounded-md hover:bg-main-700 focus:outline-none focus:ring-2 focus:ring-main-400">
<%= @name %>
</a>
"""
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule ExploringBeamCommunity.MixProject do
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:gettext, "~> 0.20"},
{:jason, "~> 1.2"},
{:jason, "~> 1.4"},
{:plug_cowboy, "~> 2.5"},
{:hackney, "~> 1.20"},
{:timex, "~> 3.7"},
Expand Down
3 changes: 3 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"expo": {:hex, :expo, "1.0.0", "647639267e088717232f4d4451526e7a9de31a3402af7fcbda09b27e9a10395a", [:mix], [], "hexpm", "18d2093d344d97678e8a331ca0391e85d29816f9664a25653fd7e6166827827c"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"},
"fss": {:hex, :fss, "0.1.1", "9db2344dbbb5d555ce442ac7c2f82dd975b605b50d169314a20f08ed21e08642", [:mix], [], "hexpm", "78ad5955c7919c3764065b21144913df7515d52e228c09427a004afe9c1a16b0"},
"gen_smtp": {:hex, :gen_smtp, "1.2.0", "9cfc75c72a8821588b9b9fe947ae5ab2aed95a052b81237e0928633a13276fd3", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "5ee0375680bca8f20c4d85f58c2894441443a743355430ff33a783fe03296779"},
"gettext": {:hex, :gettext, "0.25.0", "98a95a862a94e2d55d24520dd79256a15c87ea75b49673a2e2f206e6ebc42e5d", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "38e5d754e66af37980a94fb93bb20dcde1d2361f664b0a19f01e87296634051f"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"kino": {:hex, :kino, "0.14.2", "46c5da03f2d62dc119ec5e1c1493f409f08998eac26015ecdfae322ffff46d76", [:mix], [{:fss, "~> 0.1.0", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.1", [hex: :nx, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}], "hexpm", "f54924dd0800ee8b291fe437f942889e90309eb3541739578476f53c1d79c968"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
Expand All @@ -39,6 +41,7 @@
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"swoosh": {:hex, :swoosh, "1.16.10", "04be6e2eb1a31aa0aa21a731175c81cc3998189456a92daf13d44a5c754afcf5", [:mix], [{:bandit, ">= 1.0.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mua, "~> 0.2.3", [hex: :mua, repo: "hexpm", optional: true]}, {:multipart, "~> 0.4", [hex: :multipart, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:req, "~> 0.5 or ~> 1.0", [hex: :req, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "756be04db173c0cbe318f1dfe2bcc88aa63aed78cf5a4b02b61b36ee11fc716a"},
"table": {:hex, :table, "0.1.2", "87ad1125f5b70c5dea0307aa633194083eb5182ec537efc94e96af08937e14a8", [:mix], [], "hexpm", "7e99bc7efef806315c7e65640724bf165c3061cdc5d854060f74468367065029"},
"tailwind": {:hex, :tailwind, "0.2.3", "277f08145d407de49650d0a4685dc062174bdd1ae7731c5f1da86163a24dfcdb", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "8e45e7a34a676a7747d04f7913a96c770c85e6be810a1d7f91e713d3a3655b5d"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"telemetry_metrics": {:hex, :telemetry_metrics, "1.0.0", "29f5f84991ca98b8eb02fc208b2e6de7c95f8bb2294ef244a176675adc7775df", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f23713b3847286a534e005126d4c959ebcca68ae9582118ce436b521d1d47d5d"},
Expand Down
Loading

0 comments on commit a24ab8d

Please sign in to comment.