-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.courselistcontroller.js
131 lines (131 loc) · 5.3 KB
/
app.courselistcontroller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var App;
(function (App) {
/**
* AngularJS contorller for the simple course list view. Holds the list of courses and can
* update the table via some computed parameters e.g. whether a class should be shown in the table based on the current settings.
* @class
*/
var CourseListController = (function () {
/**
* @constructor
* @param {ng.IScope} $scope - AngularJS scope
* @param {NgTableParams} NgTableParams - ng-table module
*/
function CourseListController($scope, NgTableParams, courses) {
this._courses = [];
this._specializations = [];
// these will be the options in the semester selector dropdown that we will be populating with angular from here
// id will be a number on the JS side
this.semesterOptions = [{ id: App.Semester.Future, text: "All courses" },
{ id: App.Semester.Spring2017, text: "Current only" },
{ id: App.Semester.Fall2017, text: "Current + Fall2017" }];
this._$scope = $scope;
this._ngTableClass = NgTableParams;
if (courses) {
this._courses = courses;
}
}
Object.defineProperty(CourseListController.prototype, "courses", {
/** @property {Course[]} Courses The course data as an array */
get: function () {
return this._courses;
},
set: function (c) {
this._courses = c;
this.currentSelection = App.Semester.Spring2017;
this.tableParams = new this._ngTableClass({
count: 80,
sorting: { available: "asc" }
}, {
counts: [],
dataset: this._courses
});
},
enumerable: true,
configurable: true
});
/**
* @function
* @param {number} id - Course id (without the subject)
* @returns {Course} The found course, null if not found
*/
CourseListController.prototype.getById = function (id) {
var found;
this._courses.forEach(function (item) {
if (item.id == id) {
found = item;
}
});
return found;
};
/**
* @function
* @param {number} id - Course id (without the subject)
* @returns {boolean} Whether the queried class should be shown in the table based on the current settings
*/
CourseListController.prototype.canShow = function (id) {
var course = this.getById(id);
if (course == null) {
console.log("Can't find course id# " + id + ", it won't show up in the table");
return false;
}
var avail = course.available;
if (typeof avail == "string") {
// can happen that it's in string format convert back to enum/number and compare
// (toString needed for typescript because it thinks it is an enum but this case it isn't)
if (this.currentSelection == App.Semester.Future)
return true;
return 0 < App.Semester[avail.toString()] && App.Semester[avail.toString()] <= this.currentSelection;
}
else if (typeof avail == "number") {
// happy path
if (this.currentSelection == App.Semester.Future)
return true;
return 0 < avail && avail <= this.currentSelection;
}
else {
console.log("Cannot read availability property of id# " + id + ", it won't show up in the table");
return false;
}
};
/**
* Convert the semester enum into user-friendly text
* @function
* @param {number} num - Semester enum, which is esentially a number on the JS side
* @returns {string} Enum converted to display-friendly text
*/
CourseListController.prototype.availabilityText = function (num) {
switch (num) {
case App.Semester.Before:
return "Before Fall 2015";
break;
case App.Semester.Fall2015:
return "Fall 2015";
break;
case App.Semester.Spring2016:
return "Spring 2016";
break;
case App.Semester.Fall2016:
return "Fall 2016";
break;
case App.Semester.Spring2017:
return "Spring 2017";
break;
case App.Semester.Fall2017:
return "Fall 2017";
break;
case App.Semester.Future:
return "Future";
break;
case App.Semester.Discontinued:
return "Discountinued";
break;
default:
return "Uknown availability property";
}
};
return CourseListController;
})();
App.CourseListController = CourseListController;
})(App || (App = {}));
//# sourceMappingURL=app.courselistcontroller.js.map