-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule Opsmaru.Content.Course do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias Opsmaru.Content.Image | ||
alias Opsmaru.Content.Technology | ||
|
||
embedded_schema do | ||
field :title, :string | ||
field :slug, :string | ||
|
||
field :description, :string | ||
|
||
embeds_one :cover, Image | ||
|
||
embeds_one :main_technology, Technology | ||
end | ||
|
||
def changeset(course, params) do | ||
%{"_id" => id, "slug" => %{"current" => slug}} = params | ||
|
||
params = | ||
params | ||
|> Map.put("id", id) | ||
|> Map.put("slug", slug) | ||
|
||
course | ||
|> cast(params, ~w(id title slug description)a) | ||
|> validate_required(~w(id title slug)a) | ||
|> cast_embed(:cover) | ||
|> cast_embed(:main_technology) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule Opsmaru.Courses do | ||
alias __MODULE__.Category | ||
|
||
defdelegate list_categories(options \\ []), | ||
to: Category.Manager, | ||
as: :list | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Opsmaru.Courses.Category do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias Opsmaru.Content.Course | ||
|
||
embedded_schema do | ||
field :name, :string | ||
field :slug, :string | ||
|
||
field :index, :integer | ||
|
||
embeds_many :courses, Course | ||
end | ||
|
||
def changeset(category, params) do | ||
%{"_id" => id, "slug" => %{"current" => slug}} = params | ||
|
||
params = | ||
params | ||
|> Map.put("id", id) | ||
|> Map.put("slug", slug) | ||
|
||
category | ||
|> cast(params, ~w(id name slug index)a) | ||
|> validate_required(~w(id name slug index)a) | ||
|> cast_embed(:courses) | ||
end | ||
|
||
def parse(params) do | ||
%__MODULE__{} | ||
|> changeset(params) | ||
|> apply_action!(:insert) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule Opsmaru.Courses.Category.Manager do | ||
import Opsmaru.Sanity | ||
|
||
alias Opsmaru.Courses.Category | ||
|
||
def list(_options \\ []) do | ||
query = ~s""" | ||
*[_type == "courseCategory"] | order(index asc){ | ||
..., | ||
"courses": *[ _type == "course" && references(^._id) ] { | ||
..., | ||
main_technology -> { | ||
..., | ||
"logo": { "url": logo.asset -> url, "alt": logo.alt } | ||
} | ||
} | ||
} | ||
""" | ||
|
||
query | ||
|> Sanity.query(%{}, perspective: "published") | ||
|> Sanity.request!(sanity_request_opts()) | ||
|> Sanity.result!() | ||
|> Enum.map(&Category.parse/1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
defmodule OpsmaruWeb.CourseComponents do | ||
use OpsmaruWeb, :html | ||
|
||
alias Opsmaru.Courses | ||
|
||
def header(assigns) do | ||
h2 = Enum.find(assigns.section.contents, &(&1.slug == "learn-header-h2")) | ||
title = Enum.find(assigns.section.contents, &(&1.slug == "learn-header-title")) | ||
description = Enum.find(assigns.section.contents, &(&1.slug == "learn-header-description")) | ||
|
||
assigns = | ||
assigns | ||
|> assign(:h2, h2) | ||
|> assign(:title, title) | ||
|> assign(:description, description) | ||
|
||
~H""" | ||
<div class="px-6 lg:px-8"> | ||
<div class="mx-auto max-w-2xl lg:max-w-7xl"> | ||
<h2 class="mt-16 font-mono text-xs/5 font-semibold uppercase tracking-widest text-gray-500 data-[dark]:text-gray-400"> | ||
<%= @h2.body %> | ||
</h2> | ||
<h1 class="mt-2 text-pretty text-4xl font-medium tracking-tighter text-gray-950 data-[dark]:text-white sm:text-6xl"> | ||
<%= @title.body %> | ||
</h1> | ||
<p class="mt-6 max-w-3xl text-2xl font-medium text-gray-500"> | ||
<%= @description.body %> | ||
</p> | ||
</div> | ||
</div> | ||
""" | ||
end | ||
|
||
attr :categories, :list, required: true | ||
|
||
def categories(assigns) do | ||
infrastructure_setup_category = Enum.find(assigns.categories, &(&1.slug == "infrastructure-setup")) | ||
|
||
assigns = assign(assigns, :infrastructure_setup_category, infrastructure_setup_category) | ||
|
||
~H""" | ||
<div class="my-32 px-6 lg:px-8"> | ||
<.infrastructure_setup category={@infrastructure_setup_category} /> | ||
</div> | ||
""" | ||
end | ||
|
||
attr :category, Courses.Category, required: true | ||
|
||
def infrastructure_setup(assigns) do | ||
~H""" | ||
<div class="mx-auto max-w-2xl lg:max-w-7xl"> | ||
<h3 class="mt-24 font-mono text-xs/5 font-semibold uppercase tracking-widest text-gray-500 data-[dark]:text-gray-400"> | ||
<%= @category.name %> | ||
</h3> | ||
<hr class="mt-6 border-t border-slate-200" /> | ||
<ul role="list" class="mx-auto mt-10 grid grid-cols-1 gap-8 lg:grid-cols-2"> | ||
<li :for={course <- @category.courses}> | ||
<img src={course.main_technology.logo.url} alt={course.main_technology.logo.alt} class="h-14" /> | ||
<p class="mt-6 max-w-lg text-sm/6 text-slate-500"> | ||
<%= course.description %> | ||
</p> | ||
<.link navigate={~p"/how-to/#{course.slug}"} class="mt-8 inline-flex items-center justify-center px-2 py-[calc(theme(spacing.[1.5])-1px)] rounded-lg border border-transparent shadow ring-1 ring-black/10 whitespace-nowrap text-sm font-medium text-gray-950 data-[disabled]:bg-transparent data-[hover]:bg-gray-50 data-[disabled]:opacity-40"> | ||
<%= gettext("View course") %> | ||
</.link> | ||
</li> | ||
</ul> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule OpsmaruWeb.CourseLive.Index do | ||
use OpsmaruWeb, :live_view | ||
|
||
alias Opsmaru.Content | ||
alias Opsmaru.Courses | ||
|
||
alias OpsmaruWeb.CourseComponents | ||
|
||
@page_slug "learn" | ||
|
||
def mount(_params, _session, socket) do | ||
page = Content.show_page(@page_slug) | ||
|
||
header_section = Enum.find(page.sections, & &1.slug == "learn-header") | ||
|
||
categories = Courses.list_categories() | ||
|
||
socket = | ||
socket | ||
|> assign(:page_title, page.title) | ||
|> assign(:page, page) | ||
|> assign(:header_section, header_section) | ||
|> assign(:categories, categories) | ||
|
||
{:ok, socket} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<CourseComponents.header section={@header_section} /> | ||
<CourseComponents.categories categories={@categories} /> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters