Skip to content

Commit

Permalink
added lane button
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Sep 17, 2024
1 parent 9eccc61 commit 6377716
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
93 changes: 93 additions & 0 deletions lib/mindwendel/lanes.ex
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 lib/mindwendel_web/live/lane_live/form_component.html.heex
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>

0 comments on commit 6377716

Please sign in to comment.