Skip to content

Commit 8782421

Browse files
committed
Added a course info popup when you click on the course titles. Fixes #3 and Fixes #58.
Also did some minor code cleanup.
1 parent 66df680 commit 8782421

File tree

8 files changed

+125
-29
lines changed

8 files changed

+125
-29
lines changed

api/entity.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@
256256
echo json_encode(array("sections" => $sections));
257257
break;
258258

259+
case "courseForSection":
260+
echo json_encode(getCourseBySectionId($_POST['id'], true));
261+
break;
262+
259263
default:
260264
die(json_encode(array("error" => "argument", "msg" => "You must provide a valid action.")));
261265

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
angular.module('sm').directive('courseDetailPopover', function($http, $filter) {
2+
var RMPUrl = $filter('RMPUrl'),
3+
parseTimes = $filter('parseSectionTimes'),
4+
formatTime = $filter('formatTime');
5+
6+
function getTimesHTML(times) {
7+
if(!times) {
8+
return '';
9+
}
10+
var parsedTimes = parseTimes(times, true);
11+
var HTML = '<div style="font-size: small">';
12+
for (var timeIndex = 0; timeIndex < parsedTimes.length; timeIndex++) {
13+
var time = parsedTimes[timeIndex];
14+
HTML += time.days + ' <span style="white-space: nowrap">' + formatTime(time.start) + '-' + formatTime(time.end) + '</span> <span style="font-style: italic; white-space: nowrap">Location: ' + time.location + '</span>';
15+
}
16+
HTML += '</div>';
17+
18+
return HTML;
19+
}
20+
return {
21+
restrict: 'A',
22+
scope: {
23+
sectionId: '=courseDetailPopover'
24+
},
25+
link: function(scope, elm) {
26+
if(scope.sectionId != '') {
27+
var loaded = false,
28+
opened = false,
29+
$body = $("body");
30+
31+
function hidePopoverOnBodyClick() {
32+
setTimeout(function() {
33+
34+
$body.off('click.hidepopovers');
35+
$body.on('click.hidepopovers', function () {
36+
elm.popover('hide');
37+
$body.off('click.hidepopovers');
38+
opened = false;
39+
});
40+
}, 100);
41+
}
42+
43+
elm.on('click', function() {
44+
if(!loaded) {
45+
loaded = true;
46+
$http.post('/entity/courseForSection',
47+
$.param({
48+
id: scope.sectionId
49+
})
50+
).success(function(data) {
51+
elm.popover({
52+
html:true,
53+
trigger:'manual',
54+
placement:'auto left',
55+
title: data.courseNum,
56+
content: '<div class="well-sm pull-right" style=" background-color: #ddd;" title="Other students enrolled as of 6AM today">' + data.curenroll + '/' + data.maxenroll + ' <i class="fa fa-user"></i></div><p>' + data.title + '<br><span class="label label-default popover-white">' + RMPUrl(data.instructor) + '</span></p><p>' + getTimesHTML(data.times) + '</p><p>' + data.description + '</p>',
57+
container: '#container'
58+
});
59+
elm.popover('show');
60+
opened = true;
61+
hidePopoverOnBodyClick();
62+
}).error(function() {
63+
loaded = false;
64+
});
65+
} else {
66+
elm.popover('toggle');
67+
opened = !opened;
68+
if(opened) {
69+
hidePopoverOnBodyClick();
70+
}
71+
}
72+
});
73+
}
74+
}
75+
};
76+
});

assets/src/modules/sm/App/styles/global.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ body.print {
3131
a[ui-sref] {
3232
cursor: pointer;
3333
}
34+
[course-detail-popover] {
35+
cursor: pointer;
36+
}
37+
38+
[course-detail-popover]:hover {
39+
text-decoration: underline;
40+
}
3441

3542
table {
3643
overflow:auto;
@@ -473,6 +480,9 @@ select.ng-invalid {
473480
.popover a {
474481
color: #000 !important;
475482
}
483+
.popover .popover-white a {
484+
color: #fff !important;
485+
}
476486
.popover-title {
477487
display:block;
478488
}

assets/src/modules/sm/App/templates/cart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h4 class="list-group-item-heading" title="{{course.title?course.title:course.se
3636
<button type="button" class="btn pull-right btn-danger visible-md visible-lg" ng-click="section.selected = !section.selected">
3737
<i class="fa fa-minus"></i> <i class="fa fa-shopping-cart"></i>
3838
</button>
39-
<h4 class="list-group-item-heading" title="{{section.title}}">{{section.courseNum?section.courseNum:(course | courseNum)+'-'+section.section}}</h4>
39+
<h4 class="list-group-item-heading" title="{{section.title}}"><span course-detail-popover="section.id">{{section.courseNum?section.courseNum:(course | courseNum)+'-'+section.section}}</span></h4>
4040
<p class="list-group-item-text" ng-bind-html="section.instructor | RMPUrl"></p>
4141
<button type="button" class="btn btn-danger btn-block visible-xs visible-sm" ng-click="section.selected = !section.selected">
4242
<i class="fa fa-minus"></i> <i class="fa fa-shopping-cart"></i>

assets/src/modules/sm/Generate/templates/courseselect.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<li class="list-group-item course-info">
3232
<div class="row">
3333
<div class="col-sm-8">
34-
<h4 class="list-group-item-heading">{{$index + 1}}. {{section.courseNum}}</h4>
34+
<h4 class="list-group-item-heading"><span course-detail-popover="section.id">{{$index + 1}}. {{section.courseNum}}</span></h4>
3535
<small>{{section.title}}</small>
3636
<p class="list-group-item-text label-line ">
3737
<span class="label label-default" ng-bind-html="section.instructor | RMPUrl"></span>

assets/src/modules/sm/Schedule/directives/scheduleDirective.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ angular.module('sm').directive('schedule', function($timeout, $filter) {
186186
pre: function(scope, elm, attrs) {
187187
scope.scheduleController = new Schedule(scope);
188188
scope.itemEnter = function($event) {
189-
$target = $($event.target);
190-
$scope = $target.scope();
189+
var $target = $($event.target),
190+
$scope = $target.scope();
191191
if($scope.item.boundry.height < 70) {
192192
$scope.item.boundry.orig_height = $scope.item.boundry.height;
193193
$scope.item.boundry.height = 70;
194194
}
195195
};
196196
scope.itemLeave = function($event) {
197-
$target = $($event.target);
198-
$scope = $target.scope();
197+
var $target = $($event.target),
198+
$scope = $target.scope();
199199
if($scope.item.boundry.orig_height) {
200200
$scope.item.boundry.height = $scope.item.boundry.orig_height;
201201
}
@@ -221,25 +221,22 @@ angular.module('sm').directive('schedule', function($timeout, $filter) {
221221
// Only redraw if valid options
222222
scope.scheduleController.draw();
223223

224-
// Fix pixel alignment issues
225-
$timeout(function() {
226-
var offset = elm.find("svg").offset(),
227-
vert = 1 - parseFloat('0.'+('' + offset.top).split('.')[1]);
228-
horz = 1 - parseFloat('0.'+('' + offset.left).split('.')[1]);
229-
scope.grid.opts.pixelAlignment ='translate('+horz+','+vert+')';
230-
231-
// Everything is dumb
232-
//if(window.chrome) {
233-
var svg = $(elm).find('svg');
234-
svg.hide();
235-
setTimeout(function() {
236-
svg.show();
237-
},0);
238-
//}
239-
},10,true);
240-
224+
// Fix pixel alignment issues
225+
$timeout(function() {
226+
var offset = elm.find("svg").offset(),
227+
vert = 1 - parseFloat('0.'+('' + offset.top).split('.')[1]);
228+
horz = 1 - parseFloat('0.'+('' + offset.left).split('.')[1]);
229+
scope.grid.opts.pixelAlignment ='translate('+horz+','+vert+')';
230+
231+
// Toggle showing and hiding svgs, which forces a redraw
232+
var svg = $(elm).find('svg');
233+
svg.hide();
234+
setTimeout(function() {
235+
svg.show();
236+
}, 0);
237+
},10,true);
241238
}
242-
}
239+
};
243240

244241
if(!scope.overrideDrawOptions) {
245242
scope.$watchCollection('state.drawOptions', update);

inc/databaseConn.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ function getMeetingInfo($sectionData) {
4747
"online" => $sectionData['type'] == "O"
4848
);
4949

50+
if(isset($sectionData['description'])) {
51+
$course['description'] = $sectionData['description'];
52+
}
53+
5054
// If the course is online, then don't even bother looking for it's times
5155
if($course['online']) { return $course; }
5256

@@ -74,20 +78,25 @@ function getMeetingInfo($sectionData) {
7478

7579
/**
7680
* Retrieves a course based on the id of a section
77-
* @param $id int The if of the section
78-
* @return array The information about the section
81+
* @param $id int The if of the section
82+
* @param $withDescription bool If to include the description
83+
* @throws Exception
84+
* @return array The information about the section
7985
*/
80-
function getCourseBySectionId($id) {
86+
function getCourseBySectionId($id, $withDescription = false) {
8187
// Sanity check for the section id
8288
if($id == "" || !is_numeric($id)) {
8389
trigger_error("A valid section id was not provided");
8490
}
8591

92+
// Setup the SQL if we want descriptions
93+
$descriptionSQL = ($withDescription)? ', c.description': '';
94+
8695
// Build the query to get section info
8796
$query = "SELECT s.id,
8897
(CASE WHEN (s.title != '') THEN s.title ELSE c.title END) AS title,
8998
c.id AS courseId,
90-
s.instructor, s.curenroll, s.maxenroll, s.type, c.quarter, c.course, s.section, d.number, d.code
99+
s.instructor, s.curenroll, s.maxenroll, s.type, c.quarter, c.course{$descriptionSQL}, s.section, d.number, d.code
91100
FROM sections AS s
92101
JOIN courses AS c ON s.course = c.id
93102
JOIN departments AS d ON d.id = c.department

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "schedulemaker",
3-
"version": "3.0.11",
3+
"version": "3.0.12",
44
"private": true,
55
"description": "A course database lookup tool and schedule building web application for use at Rochester Institute of Technology.",
66
"main": "index.php",

0 commit comments

Comments
 (0)