move more fully to runtime config with release, improved docker build, updated phx liveview js

This commit is contained in:
Adam Piontek 2023-01-28 08:14:32 -05:00
parent db9f127e7b
commit 573a1e9cfe
38 changed files with 428 additions and 205 deletions

View file

@ -1,6 +1,6 @@
defmodule Shift73kWeb.ShiftAssignLive.Index do
use Shift73kWeb, :live_view
import Shift73k, only: [app_time_zone: 0]
import Shift73k, only: [get_app_time_zone: 0]
alias Shift73k.Repo
alias Shift73k.Shifts

View file

@ -127,7 +127,7 @@
disabled: @shift_template.id != @custom_shift.id,
phx_debounce: 250,
list: "tz_list",
placeholder: "Default: #{app_time_zone()}"
placeholder: "Default: #{get_app_time_zone()}"
%>
<datalist id="tz_list">
<%= for tz_name <- Tzdata.zone_list() do %>

View file

@ -33,7 +33,7 @@
<div class="inner-addon left-addon mb-3">
<i class="bi bi-map icon is-left text-muted fs-5"></i>
<%= text_input iimf, :time_zone,
value: Shift73k.app_time_zone(),
value: Shift73k.get_app_time_zone(),
class: @tz_valid && "form-control" || "form-control is-invalid",
phx_debounce: 250,
aria_describedby: "ics-import-tz-error",

View file

@ -1,6 +1,6 @@
defmodule Shift73kWeb.ShiftTemplateLive.FormComponent do
use Shift73kWeb, :live_component
import Shift73k, only: [app_time_zone: 0]
import Shift73k, only: [get_app_time_zone: 0]
alias Shift73k.Shifts.Templates
alias Shift73k.Shifts.Templates.ShiftTemplate

View file

@ -88,7 +88,7 @@
class: input_class(f, :time_zone, "form-control"),
phx_debounce: 250,
list: "tz_list",
placeholder: "Default: #{app_time_zone()}"
placeholder: "Default: #{get_app_time_zone()}"
%>
<datalist id="tz_list">
<%= for tz_name <- Tzdata.zone_list() do %>

View file

@ -1,11 +1,11 @@
defmodule Shift73kWeb.UserLive.ResetPassword do
use Shift73kWeb, :live_view
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Accounts
alias Shift73k.Accounts.User
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
@impl true
def mount(_params, session, socket) do
@ -41,5 +41,5 @@ defmodule Shift73kWeb.UserLive.ResetPassword do
end
end
def allow_registration, do: @app_allow_registration
def allow_registration, do: get_app_allow_reg()
end

View file

@ -198,7 +198,7 @@ defmodule Shift73kWeb.UserManagementLive.Index do
def dt_out(ndt) do
ndt
|> DateTime.from_naive!(Shift73k.app_time_zone())
|> DateTime.from_naive!(Shift73k.get_app_time_zone())
|> Calendar.strftime("%Y %b %-d, %-I:%M %p")
end
end

View file

@ -4,12 +4,11 @@ defmodule Shift73kWeb.EnsureAllowRegistrationPlug do
"""
import Plug.Conn
import Phoenix.Controller
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Repo
alias Shift73k.Accounts.User
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
@doc false
@spec init(any()) :: any()
@ -19,7 +18,7 @@ defmodule Shift73kWeb.EnsureAllowRegistrationPlug do
@spec call(Conn.t(), atom() | [atom()]) :: Conn.t()
def call(conn, _opts) do
# If there aren't even any users, or registration is allowed
if !Repo.exists?(User) || @app_allow_registration do
if !Repo.exists?(User) || get_app_allow_reg() do
# We will allow registration
conn
else

View file

@ -12,13 +12,13 @@
<% end %>
</li>
<li>
<%= link nav_link_opts(@conn, to: Routes.shift_index_path(@conn, :index), class: "dropdown-item") do %>
<i class="bi bi-card-list me-1"></i> My Scheduled Shifts
<%= link nav_link_opts(@conn, to: Routes.shift_template_index_path(@conn, :index), class: "dropdown-item") do %>
<i class="bi bi-clock-history me-1"></i> My Shift Templates
<% end %>
</li>
<li>
<%= link nav_link_opts(@conn, to: Routes.shift_template_index_path(@conn, :index), class: "dropdown-item") do %>
<i class="bi bi-clock-history me-1"></i> My Shift Templates
<%= link nav_link_opts(@conn, to: Routes.shift_index_path(@conn, :index), class: "dropdown-item") do %>
<i class="bi bi-card-list me-1"></i> My Scheduled Shifts
<% end %>
</li>

View file

@ -1,11 +1,10 @@
defmodule Shift73kWeb.LayoutView do
use Shift73kWeb, :view
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Repo
alias Shift73k.Accounts.User
alias Shift73kWeb.Roles
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
# With a Vite.js-based workflow, we will import different asset files in development
# and in production builds. Therefore, we will need a way to conditionally render
@ -14,7 +13,7 @@ defmodule Shift73kWeb.LayoutView do
@env Mix.env() # remember value at compile time
def dev_env?, do: @env == :dev
def allow_registration, do: @app_allow_registration
def allow_registration, do: get_app_allow_reg()
def nav_link_opts(conn, opts) do
case Keyword.get(opts, :to) == Phoenix.Controller.current_path(conn) do

View file

@ -1,9 +1,7 @@
defmodule Shift73kWeb.UserConfirmationView do
use Shift73kWeb, :view
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Accounts.User
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
def allow_registration, do: @app_allow_registration
def allow_registration, do: get_app_allow_reg()
end

View file

@ -1,9 +1,7 @@
defmodule Shift73kWeb.UserResetPasswordView do
use Shift73kWeb, :view
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Accounts.User
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
def allow_registration, do: @app_allow_registration
def allow_registration, do: get_app_allow_reg()
end

View file

@ -1,9 +1,7 @@
defmodule Shift73kWeb.UserSessionView do
use Shift73kWeb, :view
import Shift73k, only: [get_app_allow_reg: 0]
alias Shift73k.Accounts.User
@app_vars Application.compile_env(:shift73k, :app_global_vars, allow_registration: :true)
@app_allow_registration @app_vars[:allow_registration]
def allow_registration, do: @app_allow_registration
def allow_registration, do: get_app_allow_reg()
end