Skip to content

Commit

Permalink
Merge pull request #25 from andreyzb/YUOPENY-13
Browse files Browse the repository at this point in the history
Disable "View PDF" button when schedule page returns no results
  • Loading branch information
podarok authored Oct 20, 2022
2 parents 59565c1 + 1063e7c commit 591b5cd
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
js/repeat/node_modules/
js/repeat/package-lock.json
2 changes: 1 addition & 1 deletion js/repeat.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion js/repeat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "repeat.js",
"scripts": {
"build": "webpack --config webpack.config.js --mode=production",
"dev": "webpack --config webpack.config.js --mode=development"
"dev": "webpack --config webpack.config.js --mode=development",
"watch": "webpack --config webpack.config.js --mode=development --watch"
},
"author": "",
"license": "ISC",
Expand Down
116 changes: 63 additions & 53 deletions js/repeat/src/repeat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VueRouter from 'vue-router'
import VueRouter from 'vue-router';
Vue.use(VueRouter);

(function ($) {
Expand Down Expand Up @@ -32,7 +32,7 @@ Vue.use(VueRouter);
/* Check the settings of whether to display Instructor column or not */
function displayInstructorOrNot() {
var instructorDisplay = window.OpenY.field_prgf_repeat_schedule_instr[0].value;
if (parseInt(instructorDisplay) != 1) {
if (parseInt(instructorDisplay) !== 1) {
$('.instructor-column').remove();
}
}
Expand All @@ -42,13 +42,14 @@ Vue.use(VueRouter);
// Set number of column classes.
function calculateColumns() {
if ($('.schedules-data__header').length > 0) {
var colCount = $('.schedules-data__header > div').length;
var cols = $('.schedules-data__header > div');
var colCount = cols.length;
if ($('.schedules-data__row .register-btn').length === 0) {
colCount = colCount - 1;
$('.schedules-data__header > div').last().hide();
cols.last().hide();
}
else {
$('.schedules-data__header > div').last().show();
cols.last().show();
}
$('.schedules-data')
.removeClass('schedules-data__cols-5')
Expand Down Expand Up @@ -81,6 +82,7 @@ Vue.use(VueRouter);
categoriesLimit: [],
className: [],
isLoading: true,
weekHasResults: false,
locationPopup: {
address: '',
email: '',
Expand Down Expand Up @@ -183,36 +185,38 @@ Vue.use(VueRouter);
}

this.runAjaxRequest();

this.runAjaxWeekResultsRequest();
// We add watchers dynamically otherwise initially there will be
// up to three requests as we are changing values while initializing
// from GET query parameters.
component.$watch('date', function () {
component.runAjaxRequest();
component.resetPager();
$('#datepicker').datepicker("setDate", moment(component.date).format('YYYY-MM-DD'));

this.$watch('date', () => {
this.runAjaxRequest();
this.runAjaxWeekResultsRequest();
this.resetPager();
});
component.$watch('locations', function () {

this.$watch('locations', function () {
component.runAjaxRequest();
component.resetPager();
component.resetRooms();
});
component.$watch('categories', function () {
this.$watch('categories', function () {
component.runAjaxRequest();
component.resetPager();
});

component.$watch('className', function () {
this.$watch('className', function () {
component.runAjaxRequest();
component.resetPager();
});
component.$watch('classPopup', function () {
this.$watch('classPopup', function () {
component.runAjaxRequest();
});
component.$watch('instructorPopup', function () {
this.$watch('instructorPopup', function () {
component.runAjaxRequest();
});
component.$watch("instructorPopup_schedule", function () {
this.$watch("instructorPopup_schedule", function () {
component.runAjaxRequest();
});
},
Expand Down Expand Up @@ -244,7 +248,7 @@ Vue.use(VueRouter);
return diff > -limitDays;
}
}).on('changeDate', function (event) {
// In case if use unselect date.
// In case we use unselect date.
var date = new Date().toISOString();
if (event.format()) {
var parsed = moment(event.format(), 'YYYY-MM-DD');
Expand Down Expand Up @@ -348,11 +352,8 @@ Vue.use(VueRouter);

// Hide cancelled sessions.
resultTable = resultTable.filter(function (item) {
if (item.name.indexOf('CANCELLED') >= 0) {
return false;
}
return true;
})
return item.name.indexOf('CANCELLED') < 0;
});

return resultTable;
},
Expand All @@ -371,22 +372,20 @@ Vue.use(VueRouter);
}
},
methods: {
runAjaxRequest: function () {
this.isLoading = true;
var component = this;
prepareRequest: function () {
var requestString = '';
var date = moment(this.date).format('YYYY-MM-DD');

var url = drupalSettings.path.baseUrl + 'schedules/get-event-data';
var locsUrl = '/0'
var locsUrl = '/0';
if (this.locations.length > 0) {
locsUrl = '/' + encodeURIComponent(this.locations.join(';'))
locsUrl = '/' + encodeURIComponent(this.locations.join(';'));
}
else if (this.locationsLimit.length > 0) {
locsUrl = '/' + encodeURIComponent(this.locationsLimit.join(';'))
locsUrl = '/' + encodeURIComponent(this.locationsLimit.join(';'));
}
url += locsUrl;
url += this.categories.length > 0 ? '/' + encodeURIComponent(this.categories.join(';')) : '/0';
url += date ? '/' + encodeURIComponent(date) : '';
requestString += locsUrl;
requestString += this.categories.length > 0 ? '/' + encodeURIComponent(this.categories.join(';')) : '/0';
requestString += date ? '/' + encodeURIComponent(date) : '';

var query = [];
if (this.categoriesExcluded.length > 0) {
Expand All @@ -397,9 +396,18 @@ Vue.use(VueRouter);
}

if (query.length > 0) {
url += '?' + query.join('&');
requestString += '?' + query.join('&');
}

return requestString;
},
runAjaxRequest: function () {
this.isLoading = true;
var component = this;
var date = moment(this.date).format('YYYY-MM-DD');

var url = drupalSettings.path.baseUrl + 'schedules/get-event-data' + this.prepareRequest();

$('.schedules-empty_results').addClass('hidden');

$.getJSON(url, function (data) {
Expand All @@ -417,7 +425,15 @@ Vue.use(VueRouter);
categories: this.categories.join(';'),
cn: this.className.join(';')
}
}).catch(err => { });
}).catch(err => {
console.log(err);
});
},
runAjaxWeekResultsRequest: function (){
var url = drupalSettings.path.baseUrl + 'schedules/get-week-has-events' + this.prepareRequest();
$.getJSON(url, (data) => {
this.weekHasResults = data;
});
},
toggleTab: function (filter) {
var component = this;
Expand Down Expand Up @@ -449,19 +465,14 @@ Vue.use(VueRouter);
}

// Show all items if tab is expanded.
if (this.filterTabs.location === 1) {
return true;
}

return false;
return this.filterTabs.location === 1;
},
populatePopupLocation: function (index) {
$('.modal').modal('hide');
this.locationPopup = this.filteredTable[index].location_info;
},
populatePopupClass: function (sessionId) {
var component = this;
var date = moment(this.date).format('YYYY-MM-DD');
component.classPopup = {};
// Make sure popups work OK on all devices.
$('.modal').modal('hide');
Expand All @@ -487,8 +498,9 @@ Vue.use(VueRouter);
bySessionUrl += encodeURIComponent(sessionId);

$.getJSON(bySessionUrl, function (data) {
$('.schedules-loading').removeClass('hidden');
component.classPopup = data[0]['class_info'];
var loader = $('.schedules-loading');
loader.removeClass('hidden');
component.classPopup = data[0].class_info;
component.classPopup.schedule = data.filter(function (item) {
item.cancelled = item.name.indexOf('CANCELLED');
if (component.locations.length > 0) {
Expand All @@ -497,14 +509,12 @@ Vue.use(VueRouter);
else {
return true;
}

});
$('.schedules-loading').addClass('hidden');
loader.addClass('hidden');
});
},
populatePopupInstructor: function (instructor) {
var component = this;
var date = moment(this.date).format('YYYY-MM-DD');
component.instructorPopup = {};
component.instructorPopup.name = instructor;

Expand Down Expand Up @@ -590,6 +600,9 @@ Vue.use(VueRouter);
getResultsCount: function () {
return this.filteredTable.length;
},
getWeekHasResults: function () {
return this.weekHasResults;
},
getTotalPages: function () {
var count = 1;

Expand Down Expand Up @@ -628,7 +641,7 @@ Vue.use(VueRouter);
return;
}

// Loop over each room and remove if if corresponding location
// Loop over each room and remove if corresponding location is
// unselected.
this.room.forEach(function (item) {
var parts = item.split('||');
Expand All @@ -645,8 +658,7 @@ Vue.use(VueRouter);
},
showBackArrow: function () {
var diff = moment().diff(moment(this.date), 'hours');
var result = this.isLoading ? false : diff < 0;
return result;
return this.isLoading ? false : diff < 0;
},
showForwardArrow: function () {
var limit = drupalSettings.openy_repeat.calendarLimitDays;
Expand All @@ -657,13 +669,11 @@ Vue.use(VueRouter);
var date = moment(this.date);
var now = moment();
var diff = date.diff(now, 'days');
var result = this.isLoading ? false : diff < (limit - 1);

return result;
return this.isLoading ? false : diff < (limit - 1);
},
showAddToCalendar: function (index, selector) {
$(selector + " .atcb-link").each(function (i) {
if (index == i) {
if (index === i) {
if (!$(this).hasClass('open')) {
$(".atcb-link").removeClass('open').parent().find('ul').removeClass('active').css('visibility', 'hidden !important');
$(this).addClass('open').parent().find('ul').addClass('active').css('visibility', 'visible !important').find('.atcb-item-link:eq(0)').focus();
Expand Down Expand Up @@ -707,7 +717,7 @@ Vue.use(VueRouter);

var limitCategories = window.OpenY.field_prgf_repeat_schedule_categ || [];
if (limitCategories && limitCategories.length > 0) {
if (limitCategories.length == 1) {
if (limitCategories.length === 1) {
limit.push(encodeURIComponent(limitCategories[0].title));
}
else {
Expand Down
9 changes: 9 additions & 0 deletions openy_repeat.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ openy_repeat.schedules_by_instructor:
date: ''
requirements:
_permission: 'access content'
openy_repeat.schedules_has_week_results:
path: '/schedules/get-week-has-events/{location}/{category}/{date}'
defaults:
_controller: '\Drupal\openy_repeat\Controller\RepeatController::ajaxSchedulerHasWeekResults'
location: ''
category: ''
date: '0'
requirements:
_permission: 'access content'
openy_repeat.pdf:
path: /schedules/get-pdf
defaults:
Expand Down
Loading

0 comments on commit 591b5cd

Please sign in to comment.