initial route for ICS retrieval, no actual ICS data yet

This commit is contained in:
Adam Piontek 2021-03-23 14:09:56 -04:00
parent 873723d776
commit 8fe1bc6322
8 changed files with 44 additions and 41 deletions

View file

@ -39,6 +39,10 @@ defmodule Shift73k.Accounts do
Repo.get_by(User, email: email)
end
def get_user_by_calendar_slug(slug) when is_binary(slug) do
Repo.get_by(User, calendar_slug: slug)
end
@doc """
Gets a user by email and password.

View file

@ -5,7 +5,7 @@ defmodule Shift73kWeb.UserShiftsCsvController do
alias Shift73k.Shifts.Shift
def new(conn, _params) do
render(conn, "new.html", error_message: nil)
render(conn, "new.html")
end
def export(conn, %{"csv_export" => request_params}) do

View file

@ -0,0 +1,16 @@
defmodule Shift73kWeb.UserShiftsIcsController do
use Shift73kWeb, :controller
alias Shift73k.Accounts
alias Shift73k.Accounts.User
def index(conn, %{"slug" => slug}) do
case Accounts.get_user_by_calendar_slug(slug) do
%User{} = user ->
render(conn, "index.html", slug: slug, user: user)
_ ->
send_resp(conn, 404, "Not found")
end
end
end

View file

@ -9,24 +9,8 @@ defmodule Shift73kWeb.UserLive.Settings.CalendarUrl do
|> assign(id: assigns.id)
|> assign(current_user: user)
|> live_okreply()
# |> assign(form_week_start_at: user.week_start_at)
end
# def week_start_options do
# week_start = Date.beginning_of_week(Date.utc_today(), hd(weekdays()))
# week_start
# |> Date.range(Date.add(week_start, 6))
# |> Enum.map(&Calendar.strftime(&1, "%A"))
# |> Enum.zip(weekdays())
# end
# @impl true
# def handle_event("changed", %{"calendar_view" => %{"week_start_at" => day}}, socket) do
# {:noreply, assign(socket, form_week_start_at: String.to_existing_atom(day))}
# end
@impl true
def handle_event("save", _params, socket) do
Accounts.change_user_calendar_slug(socket.assigns.current_user.id)

View file

@ -8,26 +8,4 @@
<%= submit "Generate new", class: "btn btn-primary" %>
<% end %>
<%#= form_for :calendar_view, "#", [phx_change: :changed, phx_submit: :save, phx_target: @myself], fn cvf -> %>
<%#= label cvf, :week_start_at, class: "form-label" %>
<%# <div class="inner-addon left-addon mb-3"> %>
<%#= icon_div @socket, "bi-calendar2-range", [class: "icon is-left text-muted fs-5"] %>
<%#= select cvf, :week_start_at, week_start_options(),
value: @current_user.week_start_at,
class: "form-select"
%>
<%# </div> %>
<%# <div class="mb-3"> %>
<%#= submit "Save",
class: "btn btn-primary",
disabled: @form_week_start_at == @current_user.week_start_at,
aria_disabled: (@form_week_start_at == @current_user.week_start_at) && "true" || false,
phx_disable_with: "Saving..."
%>
<%# </div> %>
<%# end %>
</div>

View file

@ -59,6 +59,7 @@ defmodule Shift73kWeb.Router do
scope "/", Shift73kWeb do
pipe_through([:browser, :redirect_if_user_is_authenticated])
# session routes, irrelevant if user is authenticated
get("/users/register", UserRegistrationController, :new)
get("/users/log_in", UserSessionController, :new)
post("/users/log_in", UserSessionController, :create)
@ -70,21 +71,25 @@ defmodule Shift73kWeb.Router do
scope "/", Shift73kWeb do
pipe_through([:browser, :require_authenticated_user])
# # liveview user settings
# user settings (change email, password, calendar week start, etc)
live("/users/settings", UserLive.Settings, :edit)
# original user routes from phx.gen.auth
# confirm email by token
get("/users/settings/confirm_email/:token", UserSettingsController, :confirm_email)
end
scope "/", Shift73kWeb do
pipe_through([:browser])
# session paths
delete("/users/log_out", UserSessionController, :delete)
get("/users/force_logout", UserSessionController, :force_logout)
get("/users/confirm", UserConfirmationController, :new)
post("/users/confirm", UserConfirmationController, :create)
get("/users/confirm/:token", UserConfirmationController, :confirm)
# ics/ical route for user's shifts
get("/ics/:slug", UserShiftsIcsController, :index)
end
scope "/", Shift73kWeb do

View file

@ -0,0 +1,13 @@
<div class="row justify-content-center">
<div class="col-12 col-md-10 col-xl-8">
<h2>
<%= icon_div @conn, "bi-calendar2", [class: "icon baseline"] %>
User Shifts ICS
</h2>
<p class="lead">Shifts for user: <%= @user.email %></p>
<p>Calendar slug: <%= @slug %></p>
</div>
</div>

View file

@ -0,0 +1,3 @@
defmodule Shift73kWeb.UserShiftsIcsView do
use Shift73kWeb, :view
end