-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
9eccc61
commit 6377716
Showing
2 changed files
with
126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
defmodule Mindwendel.Lanes do | ||
@moduledoc """ | ||
The Lanes context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Mindwendel.Repo | ||
|
||
alias Mindwendel.Brainstormings.Lane | ||
|
||
require Logger | ||
|
||
@doc """ | ||
Gets a single lane. | ||
Raises `Ecto.NoResultsError` if the Lane does not exist. | ||
## Examples | ||
iex> get_lane!(123) | ||
%Lane{} | ||
iex> get_lane!(456) | ||
** (Ecto.NoResultsError) | ||
""" | ||
def get_lane!(id), do: Repo.get!(Lane, id) | ||
|
||
@doc """ | ||
Creates a lane. | ||
## Examples | ||
iex> create_lane(%{field: value}) | ||
{:ok, %Lane{}} | ||
iex> create_lane(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def create_lane(attrs \\ %{}) do | ||
%Lane{} | ||
|> Lane.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a lane. | ||
## Examples | ||
iex> update_lane(lane, %{field: new_value}) | ||
{:ok, %Lane{}} | ||
iex> update_lane(lane, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def update_lane(%Lane{} = lane, attrs) do | ||
lane | ||
|> Lane.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Deletes a lane. | ||
## Examples | ||
iex> delete_lane(lane) | ||
{:ok, %Lane{}} | ||
iex> delete_lane(lane) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def delete_lane(%Lane{} = lane) do | ||
Repo.delete(lane) | ||
end | ||
|
||
@doc """ | ||
Returns an `%Ecto.Changeset{}` for tracking lane changes. | ||
## Examples | ||
iex> change_lane(lane) | ||
%Ecto.Changeset{data: %Lane{}} | ||
""" | ||
def change_lane(%Lane{} = lane, attrs \\ %{}) do | ||
Lane.changeset(lane, attrs) | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
lib/mindwendel_web/live/lane_live/form_component.html.heex
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 @@ | ||
<div> | ||
<%= form_for @changeset, "#", [id: "label-form", phx_target: @myself, phx_change: "validate", phx_submit: "save"], fn f -> %> | ||
<%= hidden_input(f, :id) %> | ||
|
||
<%= if Enum.count(f.errors) > 0 do %> | ||
<div class="alert alert-danger"> | ||
<%= gettext("Required fields are either missing or incorrect:") %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="form-group"> | ||
<%= label(f, gettext("Name")) %> | ||
<%= text_input(f, :name, class: "form-control") %> | ||
<%= if message = f.errors[:name] do %> | ||
<span><%= translate_error(message) %></span> | ||
<% end %> | ||
</div> | ||
<%= hidden_input(f, :brainstorming_id) %> | ||
|
||
<%= live_patch(gettext("Close"), | ||
to: @return_to, | ||
id: "label-modal-cancel", | ||
class: "btn btn-secondary form-cancel me-2", | ||
phx_update: "ignore" | ||
) %> | ||
<%= submit(gettext("Save"), | ||
to: @return_to, | ||
phx_disable_with: gettext("Saving..."), | ||
class: "btn btn-primary", | ||
disabled: !@changeset.valid? | ||
) %> | ||
<% end %> | ||
</div> |