removed label from shift template, added seeds for shift templates

This commit is contained in:
Adam Piontek 2021-03-07 08:01:46 -05:00
parent 57c8b5b322
commit 66471c2931
14 changed files with 1143 additions and 75 deletions

View file

@ -11,5 +11,13 @@ $font-family-sans-serif: Lato, system-ui, -apple-system, "Segoe UI", Roboto,
// $font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas,
// "Liberation Mono", "Courier New", monospace !important;
// Features
$enable-shadows: true;
$enable-negative-margins: true;
// Colors
$primary: #662c91;
$secondary: #ee6c4d;
$success: #a1c181;
$info: #81c3d7;
$warning: #fcca46;

View file

@ -8,7 +8,6 @@ defmodule Shift73k.ShiftTemplates.ShiftTemplate do
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "shift_templates" do
field :label, :string
field :subject, :string, default: "My Work Shift"
field :description, :string
field :location, :string
@ -26,7 +25,6 @@ defmodule Shift73k.ShiftTemplates.ShiftTemplate do
def changeset(shift_template, attrs) do
shift_template
|> cast(attrs, [
:label,
:subject,
:description,
:location,

View file

@ -6,10 +6,6 @@
phx_change: "validate",
phx_submit: "save" %>
<%= label f, :label %>
<%= text_input f, :label %>
<%= error_tag f, :label %>
<%= label f, :subject %>
<%= text_input f, :subject %>
<%= error_tag f, :subject %>

View file

@ -8,20 +8,46 @@
<% end %>
<div class="d-flex justify-content-between d-flex align-items-center">
<div class="row justify-content-center">
<div class="col-md-12 col-lg-10 col-xl-9 ">
<div class="d-flex justify-content-between d-flex align-items-center mb-3">
<h2>
<%= icon_div @socket, "bi-clock-history", [class: "icon baseline"] %>
My Shift Templates
</h2>
<%= live_patch "New Shift Template", to: Routes.shift_template_index_path(@socket, :new), class: "btn btn-primary" %>
</div>
</div>
<div class="table-responsive">
<table class="table">
<div class="row justify-content-center">
<div class="col-12 col-sm-10 col-md-9 col-lg-7 col-xl-6 ">
<%= for shift <- @shift_templates do %>
<div class="card">
<div class="card-body">
<h5 class="card-title"><%= shift.subject %></h5>
<h6 class="card-subtitle mb-2 text-muted"><%= shift.description %></h6>
<p class="card-text">huh ok</p>
<a href="#" class="card-link">Card link</a>
<a href="#" class="card-link">Another link</a>
</div>
</div>
<% end %>
</div>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Label</th>
<th>Subject</th>
<th>Description</th>
<th>Location</th>
@ -33,23 +59,25 @@
</tr>
</thead>
<tbody id="shift_templates">
<%= for shift_template <- @shift_templates do %>
<tr id="shift_template-<%= shift_template.id %>">
<td><%= shift_template.label %></td>
<td><%= shift_template.subject %></td>
<td><%= shift_template.description %></td>
<td><%= shift_template.location %></td>
<td><%= shift_template.timezone %></td>
<td><%= shift_template.start_time |> Calendar.strftime("%I:%M %p") %></td>
<td><%= shift_template.length_hours %>h <%= shift_template.length_minutes || 0 %>m</td>
<%= for shift <- @shift_templates do %>
<tr id="shift_template-<%= shift.id %>">
<td><%= shift.subject %></td>
<td><%= shift.description %></td>
<td><%= shift.location %></td>
<td><%= shift.timezone %></td>
<td><%= shift.start_time |> Calendar.strftime("%I:%M %p") %></td>
<td><%= shift.length_hours %>h <%= shift.length_minutes || 0 %>m</td>
<td>
<span><%= live_redirect "Show", to: Routes.shift_template_show_path(@socket, :show, shift_template) %></span>
<span><%= live_patch "Edit", to: Routes.shift_template_index_path(@socket, :edit, shift_template) %></span>
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift_template.id, data: [confirm: "Are you sure?"] %></span>
<span><%= live_redirect "Show", to: Routes.shift_template_show_path(@socket, :show, shift) %></span>
<span><%= live_patch "Edit", to: Routes.shift_template_index_path(@socket, :edit, shift) %></span>
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"] %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
</table>
</div>
</div>
</div>

View file

@ -11,11 +11,6 @@
<ul>
<li>
<strong>Label:</strong>
<%= @shift_template.label %>
</li>
<li>
<strong>Subject:</strong>
<%= @shift_template.subject %>

View file

@ -5,7 +5,7 @@
</div>
<div class="modal-footer">
<%= link "Cancel", to: "#", class: "btn btn-secondary me-2", phx_click: "cancel", phx_target: @myself %>
<%= link "Cancel", to: "#", class: "btn me-2", phx_click: "cancel", phx_target: @myself %>
<%= link "Confirm Delete", to: "#",
class: "btn btn-danger",
phx_click: "confirm",

View file

@ -59,7 +59,7 @@
</div>
<div class="modal-footer">
<%= link "Cancel", to: "#", class: "btn btn-secondary", phx_click: "cancel", phx_target: @myself %>
<%= link "Cancel", to: "#", class: "btn", phx_click: "cancel", phx_target: @myself %>
<%= submit "Save",
class: "btn btn-primary ",
disabled: !@changeset.valid?,

View file

@ -1,4 +1,4 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<nav class="navbar navbar-expand-lg navbar-dark bg-secondary mb-4">
<div class="container">
<h1 class="fs-4 my-0 py-0 lh-base">

View file

@ -33,7 +33,7 @@
Aliquam ultrices elit purus, eget dignissim orci pulvinar id. Curabitur tincidunt, ligula eu condimentum porttitor, nibh sapien scelerisque urna, nec cursus nisi nisi a neque. Mauris hendrerit orci blandit, suscipit ante nec, porttitor neque. Nunc.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,6 @@ defmodule Shift73k.Repo.Migrations.CreateShiftTemplates do
def change do
create table(:shift_templates, primary_key: false) do
add :id, :binary_id, primary_key: true
add :label, :string
add :subject, :string, null: false
add :description, :string
add :location, :string

View file

@ -43,22 +43,23 @@ alias Shift73k.Accounts.User
# if Mix.env() == :dev do
this_path = Path.dirname(__ENV__.file)
users_json = Path.join(this_path, "MOCK_DATA_users.json")
# count_to_take = 15
count_to_take = 15
mock_users = users_json |> File.read!() |> Jason.decode!()
# |> Enum.take_random(count_to_take)
mock_users = users_json |> File.read!() |> Jason.decode!() |> Enum.take_random(count_to_take)
mock_users = ~s([
extra_mock_users = ~s([
{"email":"adam@73k.us","password":"adamadamA1","role":"admin","inserted_at":"2018-12-14T01:01:01Z","confirmed_at":true},
{"email":"karen@73k.us","password":"karenkarenA1","role":"manager","inserted_at":"2018-12-14T01:06:01Z","confirmed_at":true},
{"email":"kat@73k.us","password":"katkatA1","role":"manager","inserted_at":"2018-12-14T01:06:01Z","confirmed_at":true}
]) |> Jason.decode!() |> Enum.concat(mock_users)
])
mock_users =
Enum.map(mock_users, fn e ->
extra_mock_users
|> Jason.decode!()
|> Enum.concat(mock_users)
|> Enum.map(fn e ->
add_dt = NaiveDateTime.from_iso8601!(e["inserted_at"])
%{
@ -73,3 +74,48 @@ mock_users =
Repo.insert_all(User, mock_users)
# end
#####
# shift tepmlates
alias Shift73k.ShiftTemplates.ShiftTemplate
shifts_json = Path.join(this_path, "MOCK_DATA_shift-templates.json")
mock_shifts = shifts_json |> File.read!() |> Jason.decode!()
time_from_mock = fn mock_time ->
case String.length(mock_time) do
4 -> Time.from_iso8601!("T0#{mock_time}:00")
5 -> Time.from_iso8601!("T#{mock_time}:00")
end
end
seconds_day = 86_400
seconds_days_14 = seconds_day * 14
seconds_half_day = Integer.floor_div(seconds_day, 2)
for user <- Accounts.list_users() do
user_shifts =
mock_shifts
|> Enum.take_random(:rand.uniform(15) + 5)
|> Enum.map(fn e ->
seconds_to_add = :rand.uniform(seconds_days_14) + seconds_half_day
add_dt = NaiveDateTime.add(user.inserted_at, seconds_to_add)
%{
subject: e["subject"],
description: e["description"],
location: e["location"],
timezone: (Tzdata.zone_list() |> Enum.random()),
start_time: time_from_mock.(e["start_time"]),
length_hours: e["length_hours"],
length_minutes: e["length_minutes"],
user_id: user.id,
inserted_at: add_dt,
updated_at: add_dt
}
end)
Repo.insert_all(ShiftTemplate, user_shifts)
end

View file

@ -32,7 +32,6 @@ defmodule Shift73k.ShiftTemplatesTest do
test "create_shift_template/1 with valid data creates a shift_template" do
assert {:ok, %ShiftTemplate{} = shift_template} = ShiftTemplates.create_shift_template(@valid_attrs)
assert shift_template.description == "some description"
assert shift_template.label == "some label"
assert shift_template.length_hours == 42
assert shift_template.length_minutes == 42
assert shift_template.location == "some location"
@ -49,7 +48,6 @@ defmodule Shift73k.ShiftTemplatesTest do
shift_template = shift_template_fixture()
assert {:ok, %ShiftTemplate{} = shift_template} = ShiftTemplates.update_shift_template(shift_template, @update_attrs)
assert shift_template.description == "some updated description"
assert shift_template.label == "some updated label"
assert shift_template.length_hours == 43
assert shift_template.length_minutes == 43
assert shift_template.location == "some updated location"

View file

@ -5,9 +5,9 @@ defmodule Shift73kWeb.ShiftTemplateLiveTest do
alias Shift73k.ShiftTemplates
@create_attrs %{description: "some description", label: "some label", length_hours: 42, length_minutes: 42, location: "some location", start_time: ~T[14:00:00], subject: "some subject", timezone: "some timezone"}
@update_attrs %{description: "some updated description", label: "some updated label", length_hours: 43, length_minutes: 43, location: "some updated location", start_time: ~T[15:01:01], subject: "some updated subject", timezone: "some updated timezone"}
@invalid_attrs %{description: nil, label: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil}
@create_attrs %{description: "some description", length_hours: 12, length_minutes: 42, location: "some location", start_time: ~T[14:00:00], subject: "some subject", timezone: "some timezone"}
@update_attrs %{description: "some updated description", length_hours: 12, length_minutes: 43, location: "some updated location", start_time: ~T[15:01:01], subject: "some updated subject", timezone: "some updated timezone"}
@invalid_attrs %{description: nil, length_hours: nil, length_minutes: nil, location: nil, start_time: nil, subject: nil, timezone: nil}
defp fixture(:shift_template) do
{:ok, shift_template} = ShiftTemplates.create_shift_template(@create_attrs)