-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
52 changed files
with
1,568 additions
and
209 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,33 @@ | ||
defmodule CoursePlanner.Accounts.Supervisors do | ||
@moduledoc false | ||
import Ecto.Query | ||
alias CoursePlanner.{Repo, Accounts.User, Accounts.Users} | ||
|
||
@supervisors from u in User, where: u.role == "Supervisor", | ||
order_by: [u.name, u.family_name, u.nickname] | ||
|
||
def all do | ||
Repo.all(@supervisors) | ||
end | ||
|
||
def new(user, token) do | ||
user | ||
|> Map.put("role", "Supervisor") | ||
|> Users.new_user(token) | ||
end | ||
|
||
def update(id, params) do | ||
case Repo.get(User, id) do | ||
nil -> {:error, :not_found} | ||
supervisor -> | ||
supervisor | ||
|> User.changeset(params, :update) | ||
|> Repo.update | ||
|> format_error(supervisor) | ||
end | ||
end | ||
|
||
defp format_error({:ok, supervisor}, _), do: {:ok, supervisor} | ||
defp format_error({:error, changeset}, supervisor), do: {:error, supervisor, changeset} | ||
|
||
end |
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
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
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
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
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
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
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
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
83 changes: 83 additions & 0 deletions
83
lib/course_planner_web/controllers/supervisor_controller.ex
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,83 @@ | ||
defmodule CoursePlannerWeb.SupervisorController do | ||
@moduledoc false | ||
use CoursePlannerWeb, :controller | ||
alias CoursePlanner.{Accounts.Users, Accounts.User, | ||
Accounts.Supervisors, | ||
Auth.Helper} | ||
alias CoursePlannerWeb.{Router.Helpers, Auth.UserEmail} | ||
|
||
import Canary.Plugs | ||
plug :authorize_resource, model: User | ||
|
||
def index(conn, _params) do | ||
render(conn, "index.html", supervisors: Supervisors.all()) | ||
end | ||
|
||
def new(conn, _params) do | ||
changeset = User.changeset(%User{}) | ||
render(conn, "new.html", changeset: changeset) | ||
end | ||
|
||
def create(conn, %{"user" => user}) do | ||
token = Helper.get_random_token_with_length 48 | ||
url = Helpers.password_url(conn, :edit, token) | ||
case Supervisors.new(user, token) do | ||
{:ok, supervisor} -> | ||
UserEmail.send_user_email(:welcome, supervisor, url) | ||
conn | ||
|> put_flash(:info, "Supervisor created and notified by.") | ||
|> redirect(to: supervisor_path(conn, :index)) | ||
{:error, changeset} -> | ||
conn | ||
|> put_flash(:error, "Something went wrong.") | ||
|> render("new.html", changeset: changeset) | ||
end | ||
end | ||
|
||
def show(conn, %{"id" => id}) do | ||
supervisor = Repo.get!(User, id) | ||
render(conn, "show.html", supervisor: supervisor) | ||
end | ||
|
||
def edit(conn, %{"id" => id}) do | ||
supervisor = Repo.get!(User, id) | ||
changeset = User.changeset(supervisor) | ||
render(conn, "edit.html", supervisor: supervisor, changeset: changeset) | ||
end | ||
|
||
def update(%{assigns: %{current_user: current_user}} = conn, %{"id" => id, "user" => params}) do | ||
case Supervisors.update(id, params) do | ||
{:ok, supervisor} -> | ||
Users.notify_user(supervisor, | ||
current_user, | ||
:user_modified, | ||
supervisor_url(conn, :show, supervisor)) | ||
conn | ||
|> put_flash(:info, "Supervisor updated successfully.") | ||
|> redirect(to: supervisor_path(conn, :show, supervisor)) | ||
{:error, :not_found} -> | ||
conn | ||
|> put_status(404) | ||
|> render(CoursePlannerWeb.ErrorView, "404.html") | ||
{:error, supervisor, changeset} -> | ||
render(conn, "edit.html", supervisor: supervisor, changeset: changeset) | ||
end | ||
end | ||
|
||
def delete(%{assigns: %{current_user: %User{id: current_user_id}}} = conn, %{"id" => id}) do | ||
case Users.delete(id, current_user_id) do | ||
{:ok, _supervisor} -> | ||
conn | ||
|> put_flash(:info, "Supervisor deleted successfully.") | ||
|> redirect(to: supervisor_path(conn, :index)) | ||
{:error, :not_found} -> | ||
conn | ||
|> put_flash(:error, "Supervisor was not found.") | ||
|> redirect(to: supervisor_path(conn, :index)) | ||
{:error, _changeset} -> | ||
conn | ||
|> put_flash(:error, "Something went wrong.") | ||
|> redirect(to: supervisor_path(conn, :index)) | ||
end | ||
end | ||
end |
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
56 changes: 56 additions & 0 deletions
56
lib/course_planner_web/templates/attendance/index_supervisor.html.eex
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,56 @@ | ||
|
||
<div class="row middle-xs page-header"> | ||
<div class="col-xs-12 page-title"> | ||
Attendances by courses | ||
</div> | ||
</div> | ||
|
||
<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp page"> | ||
<thead> | ||
<tr> | ||
<th class="mdl-data-table__cell--non-numeric">Term</th> | ||
<th class="mdl-data-table__cell--non-numeric">Course type</th> | ||
<th class="mdl-data-table__cell--non-numeric">Teachers</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= Enum.with_index(@offered_courses) |> Enum.map(fn {offered_course,index} -> %> | ||
<tr> | ||
<td class="mdl-data-table__cell--non-numeric"> | ||
<%= offered_course.term.name %> | ||
</td> | ||
<td class="mdl-data-table__cell--non-numeric"> | ||
<%= offered_course.course.name %> | ||
</td> | ||
<td class="mdl-data-table__cell--non-numeric"> | ||
<%= get_teacher_display_name(offered_course.teachers) %> | ||
</td> | ||
<td> | ||
<button id="tr_menu_<%= offered_course.id %>" | ||
class="mdl-button mdl-js-button mdl-button--icon" | ||
> | ||
<i class="material-icons">more_vert</i> | ||
</button> | ||
<ul | ||
class=" | ||
mdl-menu mdl-js-menu | ||
<%= | ||
if index > 10 and index > length(@offered_courses)-4 do | ||
'mdl-menu--top-right' | ||
else | ||
'mdl-menu--bottom-right' | ||
end | ||
%> | ||
" | ||
for="tr_menu_<%= offered_course.id %>" | ||
> | ||
<li class="mdl-menu__item"> | ||
<%= link "Show", to: attendance_path(@conn, :show, offered_course) %> | ||
</li> | ||
</ul> | ||
</td> | ||
</tr> | ||
<% end) %> | ||
</tbody> | ||
</table> |
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
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
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
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
23 changes: 23 additions & 0 deletions
23
lib/course_planner_web/templates/layout/supervisor_app_navbar.html.eex
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,23 @@ | ||
<%= CoursePlannerWeb.SharedView.navbar "Course Planner" do %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Dashboard", @conn, dashboard_path(@conn, :show) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Calendar", @conn, schedule_path(@conn, :show) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_separator %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Coordinators", @conn, coordinator_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Students", @conn, student_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Supervisors", @conn, supervisor_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Teachers", @conn, teacher_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Volunteers", @conn, volunteer_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "All users", @conn, user_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_separator %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Course types", @conn, course_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Terms", @conn, term_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_separator %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Courses", @conn, offered_course_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Classes", @conn, class_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Attendances", @conn, attendance_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Tasks", @conn, task_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Events", @conn, event_path(@conn, :index) %> | ||
<%= CoursePlannerWeb.SharedView.navbar_separator %> | ||
<%= CoursePlannerWeb.SharedView.navbar_item "Settings", @conn, setting_path(@conn, :show) %> | ||
<%= if show_program_about?(), do: CoursePlannerWeb.SharedView.navbar_item "About #{get_program_name()}", @conn, about_path(@conn, :show) %> | ||
<% end %> |
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
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
Oops, something went wrong.