Last active
August 29, 2015 14:16
-
-
Save mikeyhew/74e4a0185d0d1d2ab8a1 to your computer and use it in GitHub Desktop.
AngularJS - University of Waterloo Exam Schedule
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- note: this gist breaks with the latest stable version (1.3.14) of Angular --> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"></script> | |
<script> | |
function Ctrl ($scope, $http) { | |
window.$scope = $scope; // for in-browser debugging | |
$scope.coursenames = []; | |
$scope.termcode = '1151'; // Change this if you want a different term. | |
$scope.api_key = "This isn't my actual api key. Get your own at https://api.uwaterloo.ca/apikey/"; | |
$scope.addCourseOnEnter = function($event) { | |
if ($event.which === 13) { | |
$scope.coursenames.push($scope.coursename); | |
$scope.coursename = ''; | |
console.log($scope.coursenames); | |
} | |
}; | |
$scope.isInCourseNames = function (exam) { | |
if ($scope.coursenames.indexOf(exam.course) != -1) { | |
return true; | |
} | |
return false; | |
}; | |
$http.get('https://api.uwaterloo.ca/v2/terms/'+$scope.termcode+'/examschedule.json?key='+$scope.api_key).success( | |
function (data) { | |
$scope.exams = data.data; | |
} | |
); | |
} | |
</script> | |
</head> | |
<body ng-app ng-controller="Ctrl"> | |
<h2>University of Waterloo Exam Schedule</h2> | |
<p>Term: {{termcode}}</p> | |
<p>UW OpenData API key: {{api_key}}</p> | |
<p>Enter your course code to view its final exam times.</p> | |
<p>Format is important. Type "CS 115", not "cs 115" or "CS115". </p> | |
<label>Add a course: </label> | |
<input placeholder="Type and Press Enter" type="text" ng-model="coursename" ng-keypress="addCourseOnEnter($event)"> | |
<div ng-repeat="exam in exams | filter:isInCourseNames"> | |
{{exam.course}} | |
<li ng-repeat = "section in exam.sections"> | |
{{section.section}}: {{section.day}} {{section.date | date: 'MMMM d'}} {{section.start_time}}-{{section.end_time}}, {{section.location}} | |
</li> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment