Skip to content

Commit

Permalink
Lazily Load TA Console Tabs (#122)
Browse files Browse the repository at this point in the history
* Lazily load users in TA Console

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load checkin module

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load secretword module

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load announcements module

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load sections module

Signed-off-by: Colin Schoen <[email protected]>

* Add missing JS

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load stats module

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load event types module

Signed-off-by: Colin Schoen <[email protected]>

* Lazily load settings module

Signed-off-by: Colin Schoen <[email protected]>

* Remove old queries when loading TA Console

Signed-off-by: Colin Schoen <[email protected]>
  • Loading branch information
colinschoen authored Jan 5, 2018
1 parent 6eec5ff commit 224e9e8
Show file tree
Hide file tree
Showing 16 changed files with 1,169 additions and 1,062 deletions.
5 changes: 3 additions & 2 deletions app/Checkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public static function perStaff($checkins) {
}


public static function userHours($checkins) {
public static function userHours($checkins, $users=false) {
$user_hours = array();
$users = User::all();
if ($users === false)
$users = User::all();
foreach ($users as $user) {
$user_hours[$user->id] = 0;
}
Expand Down
124 changes: 98 additions & 26 deletions app/Http/Controllers/TAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,51 @@ public function __construct() {
View::share('announcements', $announcements);
}
public function get_console() {
//Get all of our checkins
$checkins = Checkin::with("ta")->with("type")->with("user")->orderBy("created_at", "ASC")->get();
//Get our hours per user
$user_hours = Checkin::userHours($checkins);
$checkins_per_week = Checkin::perWeek($checkins);
$checkins_unique_per_week = Checkin::uniquePerWeek($checkins);
$checkins_per_staff = Checkin::perStaff($checkins);
//Get all of our users
$users = User::with("assignments.sec.category")->orderBy("name", "ASC")->get();
//Get our assigned hours
return view("ta.console");
}

public function get_module_users() {
$users = User::orderBy("name", "ASC")->get();
$checkins = Checkin::with("type")->get();
$types = Type::all();
$staff = $users->filter(function ($user) {
return $user->is_staff();
});
$user_hours = Checkin::userHours($checkins, $users);
$assigned_hours = User::get_assignedHours($users);
//Get under hours
$under_hours = User::get_underHours($users, $assigned_hours);
//Get over hours
$over_hours = User::get_overHours($users, $assigned_hours);
//Get assignments
$assignments = Assignment::with("sec")->with("user")->get();
//Get double booked
$double_booked = User::get_doubleBooked($assignments);
//Get our password

return view("ta.modules.users")->with([
"users" => $users,
"staff" => $staff,
"user_hours" => $user_hours,
"types" => $types]);
}

public function get_module_checkins() {
$checkins = Checkin::with("ta")->with("type")->with("user")->orderBy("created_at", "ASC")->get();
return view("ta.modules.checkins")->with(["checkins" => $checkins]);
}

public function get_module_secretword() {
$password = Password::where("gsi", "=", Auth::user()->id)->first()->password;
//Get our gsis
$gsis = User::where('access', '>', 0)->orderBy("name", "ASC")->get();
//Get our types
$types = Type::all();
//Get our audits
$audits = Audit::with("user")->orderBy('created_at', 'DESC')->get();
//Get our sections
$sections = Section::with("assigned.user")->with("ta")->with("ta2")->with("category")->orderBy("type", "ASC")->get();
//Get our announcements
return view("ta.modules.secretword")->with(["password" => $password]);
}

public function get_module_announcements() {
$announcements = Announcement::with("user")->orderBy("hidden", "DESC")->orderBy("created_at", "DESC")->get();
return view("ta.modules.announcements")->with(["announcements" => $announcements]);
}

public function get_module_export() {
return view("ta.modules.export");
}

public function get_module_sections() {
$sections = Section::with("assigned.user")->with("ta")->with("ta2")->with("category")->orderBy("type", "ASC")->get();
//Get GSis lab assistants
$yourLabAssistants = Section::with("assigned.user")->where("gsi", "=", Auth::user()->id)->orWhere("second_gsi", "=", Auth::user()->id)->get();
$yourLabAssistantsEmails = array();
Expand All @@ -64,10 +78,68 @@ public function get_console() {
}
}
}
//Add some settings

$users = User::orderBy("name", "ASC")->get();
$staff = $users->filter(function ($user) {
return $user->is_staff();
});
$assigned_hours = User::get_assignedHours($users);
$assignments = Assignment::with("sec")->with("user")->get();
$double_booked = User::get_doubleBooked($assignments);
//Get under hours
$under_hours = User::get_underHours($users, $assigned_hours);
//Get over hours
$over_hours = User::get_overHours($users, $assigned_hours);
$types = Type::all();

User::where('access', '>', 0)->orderBy("name", "ASC")->get();
return view("ta.modules.sections")->with([
"yourLabAssistantsEmails" => $yourLabAssistantsEmails,
"yourLabAssistantsNames" => $yourLabAssistantsNames,
"double_booked" => $double_booked,
"over_hours" => $over_hours,
"under_hours" => $under_hours,
"assigned_hours" => $assigned_hours,
"sections" => $sections,
"doubled_booked" => $double_booked,
"types" => $types,
"staff" => $staff
]);
}

public function get_module_stats() {
$checkins = Checkin::with("ta")->with("user")->get();
$checkins_per_week = Checkin::perWeek($checkins);
$checkins_unique_per_week = Checkin::uniquePerWeek($checkins);
$checkins_per_staff = Checkin::perStaff($checkins);
return view("ta.modules.stats")->with([
"checkins_per_week" => $checkins_per_week,
"checkins_unique_per_week" => $checkins_unique_per_week,
"checkins_per_staff" => $checkins_per_staff,
]);
}

public function get_module_eventtypes() {
$types = Type::all();
return view("ta.modules.eventtypes")->with([
"types" => $types
]);
}

public function get_module_auditlog() {
$audits = Audit::with("user")->orderBy('created_at', 'DESC')->get();
return view("ta.modules.auditlog")->with([
"audits" => $audits
]);
}

public function get_module_settings() {
$allowSectionSignups = Setting::getValue("allow_section_signups");
$informationContent = Setting::getValue("information_content");
return view("ta.console")->with(["informationContent" => $informationContent, "allowSectionSignups" => $allowSectionSignups, "yourLabAssistantsEmails" => $yourLabAssistantsEmails, "yourLabAssistantsNames" => $yourLabAssistantsNames, "double_booked" => $double_booked, "over_hours" => $over_hours, "under_hours" => $under_hours, "assigned_hours" => $assigned_hours,"sections" => $sections, "user_hours" => $user_hours, "checkins_unique_per_week" => $checkins_unique_per_week, "checkins_per_staff" => $checkins_per_staff,"checkins_per_week" => $checkins_per_week, "audits" => $audits, "announcements_ta" => $announcements, "gsis" => $gsis, "types" => $types, "checkins" => $checkins, "users" => $users, "password" => $password]);
return view("ta.modules.settings")->with([
"allowSectionSignups" => $allowSectionSignups,
"informationContent" => $informationContent
]);
}

public function post_update_password() {
Expand Down
13 changes: 12 additions & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@
Route::get("ta/announcement/visibility/{id}", ["as" => "taannouncementvisibility", "uses" => "TAController@get_announcement_visibility", "middleware" => "auth.tutor"]);
Route::get("ta/section/delete/{sid}", ["as" => "tasectiondelete", "uses" => "TAController@get_section_delete", "middleware" => "auth.ta"]);
Route::get("ta/checkin/remove/{id}", ["as" => "tacheckinremove", "uses" => "TAController@post_checkin_remove", "middleware" => "auth.tutor"]);
//POST
//SubModules
Route::get('ta/module/users', ["as" => "tamoduleusers", "uses" => "TAController@get_module_users", "middleware" => "auth.tutor"]);
Route::get('ta/module/checkins', ["as" => "tamodulecheckins", "uses" => "TAController@get_module_checkins", "middleware" => "auth.tutor"]);
Route::get('ta/module/secretword', ["as" => "tamodulesecretword", "uses" => "TAController@get_module_secretword", "middleware" => "auth.tutor"]);
Route::get('ta/module/announcements', ["as" => "tamoduleannouncements", "uses" => "TAController@get_module_announcements", "middleware" => "auth.tutor"]);
Route::get('ta/module/export', ["as" => "tamoduleexport", "uses" => "TAController@get_module_export", "middleware" => "auth.tutor"]);
Route::get('ta/module/sections', ["as" => "tamodulesections", "uses" => "TAController@get_module_sections", "middleware" => "auth.tutor"]);
Route::get('ta/module/stats', ["as" => "tamodulestats", "uses" => "TAController@get_module_stats", "middleware" => "auth.tutor"]);
Route::get('ta/module/eventtypes', ["as" => "tamoduleeventtypes", "uses" => "TAController@get_module_eventtypes", "middleware" => "auth.ta"]);
Route::get('ta/module/auditlog', ["as" => "tamoduleauditlog", "uses" => "TAController@get_module_auditlog", "middleware" => "auth.ta"]);
Route::get('ta/module/settings', ["as" => "tamodulesettings", "uses" => "TAController@get_module_settings", "middleware" => "auth.ta"]);
//POST
Route::post("ta/update/password", ["as" => "taupdatepassword", "uses" => "TAController@post_update_password", "middleware" => "auth.tutor"]);
Route::post("ta/user/checkin", ["as" => "tacheckinuser", "uses" => "TAController@post_checkin_user", "middleware" => "auth.tutor"]);
Route::post("ta/user/checkin/edit", ["as" => "taeditcheckinuser", "uses" => "TAController@post_edit_checkin_user", "middleware" => "auth.tutor"]);
Expand Down
6 changes: 6 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ public function is_tutor() {
return false;
}

public function is_staff() {
if ($this->access > 0)
return true;
return false;
}


}
Loading

0 comments on commit 224e9e8

Please sign in to comment.