This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from YACS-RCOS/staging
Routing
- Loading branch information
Showing
25 changed files
with
353 additions
and
279 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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.3 | ||
before_install: | ||
- wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 | ||
- tar -xjf phantomjs-2.0.0-ubuntu-12.04.tar.bz2 | ||
- sudo rm -rf /usr/local/phantomjs/bin/phantomjs | ||
- sudo mv phantomjs /usr/local/phantomjs/bin/phantomjs | ||
before_script: | ||
- psql -c 'create database "yacs-test";' -U postgres |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Courses view. Displays courses and their sections | ||
* @param {HTMLElement} target- The element in which this view should be rendered | ||
* @param {Object} params - API params for this view | ||
* @return {undefined} | ||
* @memberOf Yacs.views | ||
*/ | ||
Yacs.views.courses = function (target, params) { | ||
params.show_sections = params.show_periods = true; | ||
|
||
/** | ||
* When a section is clicked, toggle whether it is selected. | ||
* Uses Yacs.user for POT of selections | ||
* When a course is clicked, toggle its sections as selected. | ||
* Uses CSS for POT of selections | ||
*/ | ||
var bindListeners = function () { | ||
Yacs.on('click', target.querySelectorAll('section'), function (section) { | ||
Yacs.user.removeSelection(section.dataset.id) || | ||
Yacs.user.addSelection(section.dataset.id); | ||
}); | ||
|
||
Yacs.on('click', target.querySelectorAll('course-info'), function (courseInfo) { | ||
var courseSelected = courseInfo.parentElement.classList.contains('selected'); | ||
if (courseSelected) { | ||
var sections = courseInfo.parentElement.querySelectorAll('section'); | ||
Yacs.user.removeSelections(map(sections, function (section) { | ||
return section.dataset.id; | ||
})); | ||
} else { | ||
var sections = courseInfo.parentElement.querySelectorAll('section:not(.closed)'); | ||
Yacs.user.addSelections(map(sections, function (section) { | ||
return section.dataset.id; | ||
})); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
* Update selected status (class) of sections and courses. If all open | ||
* sections of a course are selected, the course is considered selected. | ||
*/ | ||
var updateSelected = function () { | ||
var selected = Yacs.user.getSelections(); | ||
each(target.querySelectorAll('course'), function (course) { | ||
var courseSelected = false; | ||
var sections = course.querySelectorAll('section'); | ||
if (sections.length > 0) { | ||
courseSelected = true; | ||
each(sections, function (section) { | ||
var sectionSelected = selected.indexOf(section.dataset.id) !== -1; | ||
section.classList.toggle('selected', sectionSelected); | ||
if (!sectionSelected && !section.classList.contains('closed')) | ||
courseSelected = false; | ||
}); | ||
} | ||
course.classList.toggle('selected', courseSelected); | ||
}); | ||
}; | ||
|
||
Yacs.models.courses.query(params, function (data, success) { | ||
if (success) { | ||
Yacs.render(target, 'courses', data) | ||
Yacs.observe('selection', document.querySelector('courses'), updateSelected); | ||
bindListeners(); | ||
updateSelected(); | ||
} | ||
}); | ||
}; |
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,43 @@ | ||
Handlebars.registerHelper('department_code', function (id) { | ||
return new Handlebars.SafeString(Yacs.models.departments.store.id[id].code); | ||
}); | ||
|
||
Handlebars.registerHelper('course_credits', function (c) { | ||
var outString = ''; | ||
// render "credit(s)" properly | ||
if (c.min_credits != c.max_credits) { | ||
outString = c.min_credits + '-' + c.max_credits + ' credits'; | ||
} | ||
else { | ||
outString = c.max_credits + ' credit' + (c.max_credits == 1 ? '' : 's'); | ||
} | ||
return new Handlebars.SafeString(outString); | ||
}); | ||
|
||
Handlebars.registerHelper('join', function (arr) { | ||
return new Handlebars.SafeString(arr.join(', ')); | ||
}); | ||
|
||
Handlebars.registerHelper('seats_available', function (s) { | ||
var remaining = s.seats - s.seats_taken; | ||
return new Handlebars.SafeString(remaining); | ||
}); | ||
|
||
Handlebars.registerHelper('closed_status', function (s) { | ||
return new Handlebars.SafeString(s.seats > 0 && s.seats_taken >= s.seats ? 'closed' : ''); | ||
}); | ||
|
||
Handlebars.registerHelper('day_name', function (n) { | ||
return new Handlebars.SafeString(['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][n]); | ||
}); | ||
|
||
Handlebars.registerHelper('time_range', function (start, end) { | ||
return new Handlebars.SafeString([start, end].map(function (time) { | ||
var hour = Math.floor(time / 100); | ||
var ampm = hour > 12 ? 'p' : 'a'; | ||
hour = hour > 12 ? hour - 12 : hour == 0 ? 12 : hour; | ||
var minutes = time % 100; | ||
minutes = minutes > 9 ? minutes : minutes == 0 ? '' : '0' + minutes; | ||
return hour + (minutes ? ':' + minutes : '') + ampm; | ||
}).join('-')); | ||
}); |
11 changes: 11 additions & 0 deletions
11
app/assets/javascripts/controllers/departments/controller.js
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,11 @@ | ||
/** | ||
* Home page view. Displays departments by school. | ||
* If no arguments are given, the view will use the preloaded Schools | ||
* @param {HTMLElement} target- The element in which this view should be rendered | ||
* @return {undefined} | ||
* @memberOf Yacs.views | ||
*/ | ||
Yacs.views.departments = function (target) { | ||
var data = { schools: Yacs.models.schools.store.all }; | ||
Yacs.render(target, 'departments', data); | ||
}; |
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.