Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #150 from YACS-RCOS/staging
Browse files Browse the repository at this point in the history
Routing
  • Loading branch information
Bad-Science authored Oct 21, 2016
2 parents 463b014 + 60d8fa7 commit b1876a6
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 279 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'pickle'
gem 'webrat'
# gem 'webrat'
gem 'database_cleaner'
gem "capybara"
gem "cucumber-rails", require: false
Expand Down
63 changes: 27 additions & 36 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ GEM
byebug (2.7.0)
columnize (~> 0.3)
debugger-linecache (~> 1.2)
capybara (2.7.1)
capybara (2.10.1)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand All @@ -61,12 +61,12 @@ GEM
coderay (1.1.1)
columnize (0.9.0)
concurrent-ruby (1.0.2)
coveralls (0.8.14)
coveralls (0.8.15)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
tins (>= 1.6.0, < 2)
crono (1.0.3)
activerecord (>= 4.0)
activesupport (>= 4.0)
Expand All @@ -80,12 +80,12 @@ GEM
multi_test (>= 0.1.2)
cucumber-core (1.5.0)
gherkin (~> 4.0)
cucumber-rails (1.4.3)
cucumber-rails (1.4.5)
capybara (>= 1.1.2, < 3)
cucumber (>= 1.3.8, < 3)
cucumber (>= 1.3.8, < 4)
mime-types (>= 1.16, < 4)
nokogiri (~> 1.5)
railties (>= 3, < 5)
railties (>= 3, < 5.1)
cucumber-wire (0.0.1)
dalli (2.7.6)
database_cleaner (1.5.3)
Expand All @@ -102,15 +102,15 @@ GEM
railties (>= 3.0.0)
ffi (1.9.14)
gherkin (4.0.0)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
handlebars_assets (0.23.0)
handlebars_assets (0.23.1)
execjs (~> 2.0)
multi_json (~> 1.0)
sprockets (>= 2.0.0)
tilt (>= 1.2)
i18n (0.7.0)
jbuilder (2.5.0)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
json (1.8.3)
Expand All @@ -124,18 +124,16 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
minitest (5.9.1)
multi_json (1.12.1)
multi_test (0.1.2)
newrelic_rpm (3.16.0.318)
nokogiri (1.6.8)
newrelic_rpm (3.16.3.323)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pg (0.18.4)
pg (0.19.0)
pickle (0.5.1)
cucumber (>= 0.8)
rake
pkg-config (1.1.7)
poltergeist (1.10.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand All @@ -157,7 +155,7 @@ GEM
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
railroady (1.5.1)
railroady (1.5.2)
rails (4.2.5.1)
actionmailer (= 4.2.5.1)
actionpack (= 4.2.5.1)
Expand All @@ -184,19 +182,19 @@ GEM
activesupport (= 4.2.5.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.2.2)
rake (11.3.0)
ref (2.0.0)
responders (2.2.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec-core (3.5.1)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.1)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand All @@ -207,7 +205,7 @@ GEM
rspec-support (3.5.0)
rubyzip (1.2.0)
sass (3.4.22)
sass-rails (5.0.5)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
Expand All @@ -223,36 +221,33 @@ GEM
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.7.2)
sprockets (3.6.3)
spring (2.0.0)
activesupport (>= 4.2)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.1.1)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
term-ansicolor (1.3.2)
term-ansicolor (1.4.0)
tins (~> 1.0)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
tins (1.6.0)
tins (1.12.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (3.0.0)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
websocket (1.2.3)
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -296,10 +291,6 @@ DEPENDENCIES
therubyracer
uglifier (>= 1.3.0)
web-console (~> 2.0)
webrat

RUBY VERSION
ruby 2.2.3p173

BUNDLED WITH
1.12.5
1.11.2
4 changes: 3 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
// about supported directives.
//
//= require_tree ../../../vendor/assets/javascripts
//= require yacs
//= require ./lib/yacs
//= require_tree ./lib
//= require_tree ./templates
//= require_tree .
69 changes: 69 additions & 0 deletions app/assets/javascripts/controllers/courses/controller.js
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();
}
});
};
43 changes: 43 additions & 0 deletions app/assets/javascripts/controllers/courses/helpers.js
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 app/assets/javascripts/controllers/departments/controller.js
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);
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// TODO: Move index.html to hbs template
// TODO: emulate text input and caret

/**
* Root view of YACS. Controls site navigation and search
* @param {HTMLElement} target- The element in which this view should be rendered
* @return {undefined}
* @memberOf Yacs.views
*/
Yacs.views.index = function () {
var homeButton = document.getElementById('page-title');
Yacs.views.root = function (target) {
var searchbar = document.getElementById('searchbar');
var scheduleButton = document.getElementById('schedule-btn');
var content = document.getElementById('content');

Yacs.on('click', homeButton, function () { Yacs.views.departments(content); });
Yacs.on('click', scheduleButton, function () { Yacs.views.schedule(content); });
Yacs.router.define('/', function (params) {
Yacs.views.departments(target, params);
});
Yacs.router.define('/courses', function (params) {
Yacs.views.courses(target, params);
});
Yacs.router.define('/schedules', function (params) {
Yacs.views.schedules(target, params);
});

/**
* Handle input destined for search bar. Assume all text input is intended
Expand All @@ -30,24 +36,15 @@ Yacs.views.index = function () {
} else if (key == 13) {
// enter searches
if (searchbar.value) {
Yacs.models.courses.query({ search: searchbar.value,
show_sections: true,
show_periods: true },
function (data, success) {
if (success)
Yacs.views.courses(content, data);
});
Yacs.router.visit('/courses?search=' + searchbar.value);
}
}
}
});

// Yacs.on('click', document.body, function () { searchbar.focus() });
// TODO lol previous line was a bit of an oversight, must emulate caret

searchbar.focus();

Yacs.models.schools.preload(function () {
Yacs.views.departments(content);
Yacs.router.listen();
});
};
Loading

0 comments on commit b1876a6

Please sign in to comment.