Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Add delete options for job
Browse files Browse the repository at this point in the history
Signed-off-by: Manu S Ajith <neo@codingarena.in>
  • Loading branch information
manusajith committed Jun 6, 2016
1 parent 3d220ef commit b85cf13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ defmodule ElixirJobs.PageController do
|> redirect to: page_path(conn, :show, job.id)
end

def delete(conn, %{"id" => id}) do
q = Query.table("jobs")
|> Query.filter(%{"id": id, "posted_by": get_session(conn, :user)})
|> Query.delete()
Repo.run(q)
conn
|> put_flash(:info, "Yay! Job post deleted!!")
|> redirect to: "/"
end

defp authenticate(conn, _params) do
if is_nil(get_session(conn, :user)) do
conn |> put_flash(:error, "You need to login first") |> redirect(to: "/users/login") |> halt
Expand Down
10 changes: 10 additions & 0 deletions web/static/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
max-width: 930px;
margin: 0 auto;
}

.job-actions {
list-style-type: none;
margin: 0;
padding: 0;
}

.job-actions li {
float: left;
}
9 changes: 8 additions & 1 deletion web/templates/page/show.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
<i class="calendar icon"></i> Posted On <%= convert_date @job["date_created"] %>
<br><br>
<%= if @job["posted_by"] == @user do %>
<a href="<%= page_path(@conn, :edit, @job["id"]) %>" class="ui green button">Edit</a>
<ul class="job-actions">
<li>
<a href="<%= page_path(@conn, :edit, @job["id"]) %>" class="ui green button">Edit</a>
</li>
<li>
<%= link "Delete", to: page_path(@conn, :delete, @job["id"]), method: :delete, class: "ui red button"%>
</li>
</ul>
<% end %>
</div>
<div class="nine wide column"><%= to_html @job["description"] %></div>
Expand Down

0 comments on commit b85cf13

Please sign in to comment.