Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded nook UI and Reservation booking form changes #237

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
07d2409
Prevent request and search for reservations that overlap with others.
arkokoley Jun 10, 2017
dd24c1d
Test case for overlapping reservations
arkokoley Jun 10, 2017
02fbdda
Collapsible sidebar.
arkokoley Jul 18, 2017
649553d
multi-search selection for locations
arkokoley Jul 18, 2017
74247aa
Time selection changed to dropdowns
arkokoley Jul 19, 2017
1551ffe
Limiting a user to selecting hour/half hour
arkokoley Jul 20, 2017
d478b07
Retain nooks as sidebar is toggled
arkokoley Jul 20, 2017
1ccf99e
Filter by amenities from response nooks
arkokoley Jul 21, 2017
68e555d
Search for nooks by specifying capacity
arkokoley Jul 24, 2017
38292af
Removed matching rooms from sidebar filter
arkokoley Jul 25, 2017
11245b4
Add Room type filter to sidebar
arkokoley Jul 25, 2017
ac0e3ab
Merge branch 'dev' into ui-improvements
arkokoley Jul 26, 2017
a8b1012
Completes nook search by capacity
arkokoley Jul 26, 2017
18ff1fb
Fixes bug #221
arkokoley Jul 27, 2017
c3ca2df
Fix for error in #221 arising from commit
arkokoley Jul 30, 2017
5f099cb
Fix nook registrations form fail on searching with "Any" time
arkokoley Aug 1, 2017
36ff94c
Redirect to same search filter results after redirection
arkokoley Aug 2, 2017
3eb31fd
Removed old code related to removed filter fields
arkokoley Aug 2, 2017
89ebc76
Fix nook helper code that fails in tests
arkokoley Aug 2, 2017
0976f73
Basic expanded ui created
arkokoley Aug 8, 2017
d27325b
WIP: Updated full-view column for nook registration
arkokoley Aug 12, 2017
d10e3ba
WIP: Modify full column nook view
arkokoley Aug 13, 2017
a7cf112
limit nook results to 4 in full column view
arkokoley Aug 17, 2017
d0093e1
Form autofill condition for no time selected
arkokoley Aug 18, 2017
68e756b
Fixed booked reservations not showing up in full column view
arkokoley Aug 19, 2017
e0bf268
Add styling to indicate selected nook
arkokoley Aug 19, 2017
050aa98
Remove extraneous reservation form field
arkokoley Aug 19, 2017
d6a73bc
Add Day to reservation form.
arkokoley Aug 19, 2017
03158ff
Reservation form cleanup
arkokoley Aug 19, 2017
9484684
Add No_of_people field to reservation form
arkokoley Aug 21, 2017
eda4354
Updated Factories to include no_of_people in reservations
arkokoley Aug 28, 2017
1bca3fe
Merge branch 'disable_overlapping_reservation' into phase3
arkokoley Aug 29, 2017
59b75bf
Fix issue with OpenSchedule in admin panel
arkokoley Oct 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//= require moment
//= require selectize
//= require twitter/bootstrap
//= require bootstrap-datepicker.min
//= require datetime_picker
//= require bootstrap-slider.min
//= require masonry.min
//= require imagesloaded.pkgd.min
Expand Down
340 changes: 136 additions & 204 deletions app/assets/javascripts/filters.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,69 @@
$(function() {
/**
* Filters general
*/

// updating nooks wall
$(document).on('filter-updated', function (e, params) {
var searchParams = {};

// locations filter selection
var selected = [];
$('.selected-location-item').each(function (k, val) {
selected.push($(this).attr('data-item-id'));
});
searchParams.location_ids = selected;
function getSearchParams() {
var searchParams = {};

// time filter selection
var time = $('#hour-range-slider').slider('getValue');

searchParams.time_range = {
start: time[0] * 3600,
end: time[1] * 3600
};
// locations filter selection
var selected = [];
$("#location-element option:selected").each(function () {
selected.push($(this).val());
});
$('.selected-location-item').each(function (k, val) {
selected.push($(this).attr('data-item-id'));
});
searchParams.location_ids = selected;

// date filter selection
var selected = [];
function convert_to_time(s){
s = s.split(' ');
var time = s[0].split(':').reverse().reduce((prev, curr, i) => prev + (curr == 12 ? 0 : curr)*Math.pow(60, i+1), 0);
if(s[1]=="PM"){
time += 12*3600;
}
return time;
}
// time filter selection
var timeStart = $('#timeStart').val();
var timeEnd = $('#timeEnd').val();
searchParams.time_range = {
start: convert_to_time(timeStart),
end: convert_to_time(timeEnd)
};

var selectedDate = $('.datepicker-element').first().datepicker('getFormattedDate');
var dateArr = selectedDate.split('/');
// date filter selection
var selected = [];

var date = dateArr[2] + '-' + dateArr[0] + '-' + dateArr[1];
var selectedDate = $('#datepicker-element').data('DateTimePicker').date();
var date = selectedDate.format('YYYY-MM-DD');

selected.push(date);
searchParams.days = selected;
selected.push(date);
searchParams.days = selected;
searchParams.nook_capacity = $('#nook_capacity').val();

// amentities filter selection
searchParams.amenities = [];
$('.amenity input:checked').each(function (key, val) {
var elem = $(this);
// amentities filter selection
searchParams.amenities = [];
$('.amenity input:checked').each(function (key, val) {
var elem = $(this);

searchParams.amenities.push(elem.val());
});
searchParams.amenities.push(elem.val());
});

// matching rooms filter selection
searchParams.matching_rooms = [];
$('#matching-rooms-list input:checked').each(function (key, val) {
var elem = $(this);
// matching rooms types filter selection
searchParams.nook_types = [];
$('#matching-types-list input:checked').each(function (key, val) {
var elem = $(this);

searchParams.matching_rooms.push(elem.val());
});
searchParams.nook_types.push(elem.val());
});
return searchParams;
}

// matching rooms types filter selection
searchParams.nook_types = [];
$('#matching-types-list input:checked').each(function (key, val) {
var elem = $(this);
$(function() {
/**
* Filters general
*/

searchParams.nook_types.push(elem.val());
});
// updating nooks wall
$(document).on('filter-updated',function (e, params) {

var searchParams = getSearchParams();
// getting nooks items
updateWall(searchParams);
});
Expand All @@ -65,179 +72,68 @@ $(function() {
* Date filter
*/

$('.datepicker-element').datepicker('setDate', 'today');

$(".datepicker-element").on("changeDate", function (event) {
NProgress.start();

$(document).trigger('filter-updated');
$('#datepicker-element').datetimepicker({
inline: true,
format: 'YYYY-MM-DD'
});

$(".datepicker-element").on("hide", function (event) {
console.log('foo');
$('#timeStart').datetimepicker({
format: 'LT',
stepping: 30,
showClear: true,
icons: {
clear: 'clear btn btn-primary'
}
});

$('form.booking .date-this-week button').on('click', function () {
NProgress.start();

$(this).toggleClass('active');

$(document).trigger('filter-updated');
$('#timeEnd').datetimepicker({
format: 'LT',
stepping: 30,
showClear: true,
icons: {
clear: 'clear btn btn-primary'
},
useCurrent: false //Important! See issue #1075
});

/**
* Time filter
*/

$("#hour-range-slider").slider({});
$("#hour-range-slider").on('change', function (object) {
var min_start = object.value["oldValue"][0];
var min_end = object.value["newValue"][0];
var max_start = object.value["oldValue"][1];
var max_end = object.value["newValue"][1];
var minutes, hour;

if (min_start != min_end) {
hour = Math.floor(min_end);
minutes = s.lpad((min_end - hour) * 60, 2, '0');
$(this).parent().find('.slider-min').html((hour > 12 ? hour - 12 : hour) + ':' + minutes + (hour >= 12 ? 'PM' : 'AM'));
}
if (max_start != max_end) {
hour = Math.floor(max_end);
minutes = s.lpad((max_end - hour) * 60, 2, '0');
$(this).parent().find('.slider-max').html((hour > 12 ? hour - 12 : hour) + ':' + minutes + (hour >= 12 ? 'PM' : 'AM'));
}

// refresh a list only when user finished moving
if (typeof hourRangeTimer !== 'undefined') {
clearTimeout(hourRangeTimer);
}
hourRangeTimer = setTimeout(function () {
NProgress.start();

// getting nooks items
$("#timeStart").on("dp.show", function(e) {
$('.clear').html("Any Time");
}).on("dp.change", function (e) {
$('#timeEnd').data("DateTimePicker").minDate(e.date);
var endDate = $('#timeEnd').data("DateTimePicker").date();
if (endDate <= e.date || endDate == undefined) {
$('#timeEnd').data("DateTimePicker").date(e.date);
}
if(e.date === false){
$(e.target).val("Any");
}
$(document).trigger('filter-updated');
}, 700);
NProgress.start();
});

/**
* Location filter
*/

// get client geolocation to show distance to each location
$(document).ready(function () {
if ( $('#select-locations-link').length ) {
var href = $('#select-locations-link').attr('href');
$('#add-location-button').toggle();

if( navigator.geolocation ) {
// Call getCurrentPosition with success and failure callbacks
navigator.geolocation.getCurrentPosition( function(position) {
var clientLocation = [position.coords.latitude, position.coords.longitude];
href = href + '?client_location=' + clientLocation
$('#select-locations-link').attr('href', href);
showSelectLocationButton();
}, function() {
showSelectLocationButton();
} );
} else {
showSelectLocationButton();
$("#timeEnd").on("dp.show", function(e) {
$('.clear').html("Any Time");
}).on("dp.change", function (e) {
if(e.date === false){
$(e.target).val("Any");
}
}

function showSelectLocationButton() {
$('.loading').remove();
$('#add-location-button').toggle();
}
$(document).trigger('filter-updated');
NProgress.start();
});
$("#datepicker-element").on("dp.change", function (event) {
NProgress.start();

// selecting location items
$(document).on('click', '#locations-select li', function (e) {
$(this).toggleClass('active');
$(document).trigger('filter-updated');
});

// process location selection
$(document).on('click', '#process-locations-select', function () {
var locationActiveItems = $('#locations-select li.active');

$('form.booking .date-this-week button').on('click', function () {
NProgress.start();

locationActiveItems.each(function (key, item) {
var locationData = $(item).data('item');

var newElem = $('<div/>', {
class: 'btn selected-location-item',
'data-item-id': locationData.id
});

var nameElem = $('<span/>', {
text: locationData.name
});

var removeElem = $('<span/>', {
class: 'remove_input',
text: 'x'
});

removeElem.on('click', function () {
NProgress.start();

$(this).parent().remove();
$(document).trigger('filter-updated');
});

nameElem.appendTo(newElem);
removeElem.appendTo(newElem);

$('#add-location-button').before(newElem);
});
$(this).toggleClass('active');

$(document).trigger('filter-updated');

modal.modal('hide');
});

locationsModalLoaded = function () {
var selected = [];
$('.selected-location-item').each(function (k, val) {
selected.push($(this).attr('data-item-id'));
});

$('#locations-select li').each(function (key, value) {
var elem = $(this);

var locationData = elem.data('item');

if (selected.indexOf(String(locationData.id)) !== -1) {
elem.remove();
}
});
};

/**
* Time period filter
*/

$('form.booking #when button').on('click', function () {
var elem = $(this);

$('#when button').removeClass('active');
elem.addClass('active');

if (elem.val() === 'today') {
NProgress.start();
$('.filter.date').removeClass('this-week future').addClass('today');
$('.filter.date').addClass('inactive');
var searchParams = {};
searchParams.when = elem.val();

// getting nooks items
$(document).trigger('filter-updated');
} else if (elem.val() === 'future') {
$('.filter.date').removeClass('today this-week').addClass('future');
$('.filter.date').removeClass('inactive');
}

$('.clear-time').on('click',function() {
console.log("clearing");
$('#timeStart').data("DateTimePicker").date(null);
$('#timeEnd').data("DateTimePicker").date(null);
});

/**
Expand All @@ -259,4 +155,40 @@ $(function() {

$(document).trigger('filter-updated');
});

var $select = $('#location-element').selectize();
$('select').on('change', function(e){
NProgress.start();

$(document).trigger('filter-updated');
});
$('form.booking #clear-select').on('click',function(e){
e.preventDefault();
var control = $select[0].selectize;
control.clear();
});

if($(document).find(".alert.alert-danger").length > 0){
var data = window.localStorage.getItem('form');
if(data){
var formData = JSON.parse(data);
var locationsToRemove = _.reject($select[0].selectize.items, function(x) {
return _.some(formData.location_ids, function(y) {
return y == x
})
});
locationsToRemove.forEach(function(item){
$select[0].selectize.removeItem(item,false);
})
$('#datepicker-element').data("DateTimePicker").date(new Date(formData.days[0]));
$('#timeStart').val(moment().startOf('day').seconds(formData.time_range.start).format("hh:mm A"));
$('#timeEnd').val(moment().startOf('day').seconds(formData.time_range.end).format("hh:mm A"));
$('#nook_capacity').val(formData.nook_capacity);
window.localStorage.removeItem('form');
}
}

NProgress.start();

$(document).trigger('filter-updated');
});
Loading