Skip to content

Commit

Permalink
Add upcoming meetings toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
otrok7 committed Dec 7, 2023
1 parent aa0f321 commit b8d51e3
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 37 deletions.
2 changes: 1 addition & 1 deletion crouton.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function enqueueFrontendFiles()
{
if ($this->hasShortcode()) {
$jsfilename = (isset($_GET['croutonjsdebug']) ? "crouton-core.js" : "");
wp_enqueue_style("croutoncss", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton.min.css", false, filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton.min.css"), false);
wp_enqueue_style("croutoncss", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton-core.min.css", false, filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton-core.min.css"), false);
if (isset($_GET['croutonjsdebug'])) {
wp_enqueue_script("croutonnocorejs", plugin_dir_url(__FILE__) . "croutonjs/dist/crouton-nocore.js", array('jquery'), filemtime(plugin_dir_path(__FILE__) . "croutonjs/dist/crouton-nocore.js"), true);
wp_enqueue_script("croutonjs", plugin_dir_url(__FILE__) . "croutonjs/src/js/crouton-core.js", array('croutonnocorejs'), filemtime(plugin_dir_path(__FILE__) . "croutonjs/src/js/crouton-core.js"), true);
Expand Down
4 changes: 2 additions & 2 deletions croutonjs/meetingMap/css/meeting_map.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ input[name='panel']:checked ~ .marker_div_meeting {
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px !important; color: white; font-family: Roboto, Arial, sans-serif !important; font-weight: bold !important;
display: block; float: left; width: 50%; height: 30px; line-height: 30px;
font-size: 14px !important; font-family: Roboto, Arial, sans-serif !important; font-weight: bold !important;
box-sizing: border-box !important;
}

Expand Down
42 changes: 40 additions & 2 deletions croutonjs/meetingMap/js/meeting_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function MeetingMap(inConfig) {
}
else if (menuContext) {
menuContext.imageDir = config.BMLTPlugin_images;
//gDelegate.addControl(createFilterMeetingsToggle(), 'topleft');
gDelegate.addControl(createNext24Toggle(), 'topleft');
gDelegate.addControl(createMenuButton(menuContext), 'topright', cb);
};
}
Expand All @@ -84,6 +84,44 @@ function MeetingMap(inConfig) {

return controlDiv;
}
var next24status = false;
function createNext24Toggle() {
const toggleSrc = `
<div id="next24_toggle" title="Next24_toggle" style="background: rgba(0, 0, 0, 0); cursor: pointer;">
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="next24onoffswitch"/>
<label class="onoffswitch-label" for="next24onoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>`;
rules = [`.onoffswitch-inner:before {
content: "__text__";
padding-left: 10px;
background-color: #2d5c88; color: #FFFFFF;
}`,
`.onoffswitch-inner:after {
content: "__text__";
padding-left: 30px;
background-color: #EEEEEE; color: #2d5c88;
text-align: left;
}`];
rules[0] = rules[0].replace("__text__", crouton.localization.getWord("All Meetings"));
rules[1] = rules[1].replace("__text__", crouton.localization.getWord("Upcoming Meetings"));
var controlDiv = document.createElement('div');
controlDiv.innerHTML = toggleSrc;
controlDiv.querySelector(".onoffswitch").addEventListener('click', function (event) {
if (event.pointerId < 0) return;
next24status = !next24status;
fitDuringFilter = false;
crouton.filterNext24(next24status);
fitDuringFilter = true;
});
document.styleSheets[0].insertRule(rules[0]);
document.styleSheets[0].insertRule(rules[1]);
return controlDiv;
}
function createMenuButton(menuContext) {
var template = hbs_Crouton.templates['mapMenu'];
var controlDiv = document.createElement('div');
Expand Down Expand Up @@ -422,7 +460,7 @@ function MeetingMap(inConfig) {
}
return 0;
};
var markerTemplateSrc = `
const markerTemplateSrc = `
<div class="accordion">
{{#each this}}<div>
<input type="radio" name="panel" id="panel-{{this.id_bigint}}" {{#unless @index}}checked{{/unless}}/>
Expand Down
103 changes: 74 additions & 29 deletions croutonjs/src/js/crouton-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ function Crouton(config) {

self.dayView = function () {
self.resetFilter();
croutonMap && croutonMap.fillMap();
self.lowlightButton(".filterButton");
self.highlightButton("#day");
jQuery('.bmlt-page').each(function (index) {
Expand Down Expand Up @@ -390,6 +389,7 @@ function Crouton(config) {
});
if (!filteringDropdown) {
self.filtering = false;
if (croutonMap) croutonMap.fillMap();
return;
}
var showingNow = [];
Expand Down Expand Up @@ -552,7 +552,44 @@ function Crouton(config) {
self.errorHandler = function(msg) {
jQuery('.geo').removeClass("hide").addClass("show").html('');
};
Crouton.prototype.filterNext24 = function(filterNow = true) {
if (!filterNow) {
jQuery("#filter-dropdown-next24").val('a-');
self.filteredPage();
return;
}
const date = new Date();
const dayNow = date.getDay();
const hour = date.getHours();
const mins = date.getMinutes();
const next24 = self.meetingData.filter(function(meeting) {
var weekday = meeting.weekday_tinyint - 1;
if (weekday == dayNow) {
var time = meeting.start_time.toString().split(':');
var meetingHour = parseInt(time[0]);
if (meetingHour > hour) {
return true;
}
if (meetingHour == hour) {
if (parseInt(time[1]) > mins) {
return true;
}
}
} else if (weekday == (dayNow + 1) % 7) {
return true;
}
return false;
}).map((m)=>m.id_bigint);
jQuery(".bmlt-data-row").each(function(index,row) {
row.dataset.next24 = (next24.includes(row.id.split('-').pop())) ? '1' : '0';
});
jQuery("#filter-dropdown-next24").val('a-1');
self.filteredPage();
}

self.isMeetingInTime = function(meeting, dayNow, hour, mins) {

}
self.distance = function(lat1, lon1, lat2, lon2, unit) {
if ((lat1 === lat2) && (lon1 === lon2)) {
return 0;
Expand Down Expand Up @@ -713,6 +750,9 @@ function Crouton(config) {
self.getUsedVisibility = function(meetings) {
return [{name: 'Visible', value: 1}];
}
self.getUsedNext24 = function(meetings) {
return [{name: 'Next24', value: 1}];
}
self.isEmpty = function(obj) {
for (var key in obj) {
if(obj.hasOwnProperty(key))
Expand Down Expand Up @@ -1097,46 +1137,46 @@ Crouton.prototype.render = function(doMeetingMap = false) {
{placeholder: self.localization.getWord('weekday'), pointer: 'weekdays', elementId: "filter-dropdown-weekdays",
uniqueData: (meetings) => sortListByList(getUniqueValuesOfKey(meetings, "formatted_day"), self.dayNamesSequenced),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_cities) self.dropdownData.push(
{placeholder: self.localization.getWord('cities'), pointer: 'Cities', elementId: "filter-dropdown-cities",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_municipality').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_groups) self.dropdownData.push(
{placeholder: self.localization.getWord('groups'), pointer: 'Groups', elementId: "filter-dropdown-groups",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'meeting_name').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_venues) self.dropdownData.push(
{placeholder: self.localization.getWord('venue_types'), pointer: 'Venues', elementId: "filter-dropdown-venues",
uniqueData: (meetings) => self.getUsedVenueType(meetings),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_areas) self.dropdownData.push(
{placeholder: self.localization.getWord('areas'), pointer: 'Areas', elementId: "filter-dropdown-areas",
uniqueData: (meetings) => self.all_service_bodies.filter((sb)=>getUniqueValuesOfKey(meetings,'service_body_bigint').includes(sb.id)).sortByKey('name'),
objectPointer: (a) => a.id, optionName: (a)=>a.name});
if (self.config.has_regions) self.dropdownData.push(
{placeholder: self.localization.getWord('regions'), pointer: 'Regions', elementId: "filter-dropdown-regions",
uniqueData: (meetings) => self.all_service_bodies.filter((sb)=>getUniqueValuesOfKey(meetings,'service_body_bigint').includes(sb.id) && sb.type==='RS').sortByKey('name'),
objectPointer: (a) => convertToPunyCode(a.name), optionName: (a)=>a.name});
if (self.config.has_locations) self.dropdownData.push(
{placeholder: self.localization.getWord('locations'), pointer: 'Locations', elementId: "filter-dropdown-locations",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_text').map((s)=>s.replace(/(<([^>]+)>)/gi, "")).sort(),
if (self.config.has_states) self.dropdownData.push(
{placeholder: self.localization.getWord('states'), pointer: 'States', elementId: "filter-dropdown-states",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_province').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_sub_province) self.dropdownData.push(
{placeholder: self.localization.getWord('counties'), pointer: 'Counties', elementId: "filter-dropdown-sub_province",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_sub_province').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_cities) self.dropdownData.push(
{placeholder: self.localization.getWord('cities'), pointer: 'Cities', elementId: "filter-dropdown-cities",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_municipality').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_neighborhoods) self.dropdownData.push(
{placeholder: self.localization.getWord('neighborhood'), pointer: 'Neighborhoods', elementId: "filter-dropdown-neighborhoods",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_neighborhood').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_states) self.dropdownData.push(
{placeholder: self.localization.getWord('states'), pointer: 'States', elementId: "filter-dropdown-states",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_province').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_zip_codes) self.dropdownData.push(
{placeholder: self.localization.getWord('postal_codes'), pointer: 'Zips', elementId: "filter-dropdown-zipcodes",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_postal_code_1').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_locations) self.dropdownData.push(
{placeholder: self.localization.getWord('locations'), pointer: 'Locations', elementId: "filter-dropdown-locations",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'location_text').map((s)=>s.replace(/(<([^>]+)>)/gi, "")).sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_regions) self.dropdownData.push(
{placeholder: self.localization.getWord('regions'), pointer: 'Regions', elementId: "filter-dropdown-regions",
uniqueData: (meetings) => self.all_service_bodies.filter((sb)=>getUniqueValuesOfKey(meetings,'service_body_bigint').includes(sb.id) && sb.type==='RS').sortByKey('name'),
objectPointer: (a) => convertToPunyCode(a.name), optionName: (a)=>a.name});
if (self.config.has_areas) self.dropdownData.push(
{placeholder: self.localization.getWord('areas'), pointer: 'Areas', elementId: "filter-dropdown-areas",
uniqueData: (meetings) => self.all_service_bodies.filter((sb)=>getUniqueValuesOfKey(meetings,'service_body_bigint').includes(sb.id)).sortByKey('name'),
objectPointer: (a) => a.id, optionName: (a)=>a.name});
if (self.config.has_groups) self.dropdownData.push(
{placeholder: self.localization.getWord('groups'), pointer: 'Groups', elementId: "filter-dropdown-groups",
uniqueData: (meetings) => getUniqueValuesOfKey(meetings, 'meeting_name').sort(),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_venues) self.dropdownData.push(
{placeholder: self.localization.getWord('venue_types'), pointer: 'Venues', elementId: "filter-dropdown-venues",
uniqueData: (meetings) => self.getUsedVenueType(meetings),
objectPointer: convertToPunyCode, optionName: (s)=>s});
if (self.config.has_formats) self.dropdownData.push(
{placeholder: self.localization.getWord('formats'), pointer: 'Formats', elementId: "filter-dropdown-formats",
uniqueData: (meetings) => getUniqueFormats(meetings),
Expand All @@ -1149,10 +1189,14 @@ Crouton.prototype.render = function(doMeetingMap = false) {
{placeholder: self.localization.getWord('common_needs'), pointer: 'Formats', elementId: "filter-dropdown-commonneeds",
uniqueData: (meetings) => getUniqueFormatsOfType(meetings, 'FC3'),
objectPointer: (f) => convertToPunyCode(f.name), optionName: (f)=>f.name});
self.dropdownData.push(
if (doMeetingMap) self.dropdownData.push(
{placeholder: '', pointer: 'visible', elementId: "filter-dropdown-visibile",
uniqueData: (meetings) => self.getUsedVisibility(meetings),
objectPointer: (s)=>s.value, optionName: (s)=>s.name});
if (doMeetingMap) self.dropdownData.push(
{placeholder: '', pointer: 'next24', elementId: "filter-dropdown-next24",
uniqueData: (meetings) => self.getUsedNext24(meetings),
objectPointer: (s)=>s.value, optionName: (s)=>s.name});
let renderer = doMeetingMap ? self.renderStandaloneMap : self.renderView;
renderer("#" + self.config['placeholder_id'], {
"config": self.config,
Expand All @@ -1176,6 +1220,7 @@ Crouton.prototype.render = function(doMeetingMap = false) {

jQuery("#" + self.config['placeholder_id']).addClass("bootstrap-bmlt");
jQuery("#filter-dropdown-visibile").removeClass("crouton-select").addClass("hide");
jQuery("#filter-dropdown-next24").removeClass("crouton-select").addClass("hide");
jQuery(".crouton-select").select2({
dropdownAutoWidth: true,
allowClear: false,
Expand Down
4 changes: 3 additions & 1 deletion croutonjs/src/js/crouton-localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,9 @@ CroutonLocalization.prototype.getDayOfTheWeekWord = function(day_id) {
};

CroutonLocalization.prototype.getWord = function(word) {
return this.words[this.language][word.toLowerCase()];
const ret = this.words[this.language][word.toLowerCase()];
if (typeof ret === 'undefined') return word;
return ret;
};

CroutonLocalization.prototype.getVenueType = function(type) {
Expand Down
18 changes: 16 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,22 @@ task('css-files', () => {
.pipe(dest(distDir))
.pipe(notify({message: "css-files complete", wait: true}));
});

task('default', series('templates', 'js-files', 'js-gmaps-files', 'js-files-nojquery', 'jsFilesCroutonMap', 'jsFilesCroutonCore', 'jsFilesCroutonNoCore', 'css-files'));
task('css-core-files', () => {
let cssFilesWithFullPath = [];
for (let cssFile of cssFiles) {
cssFilesWithFullPath.push('croutonjs/src/css/' + cssFile);
}
return src(cssFilesWithFullPath)
.pipe(concat('crouton-core.css'))
.pipe(dest(distDir))
.pipe(cleanCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(dest(distDir))
.pipe(notify({message: "css-core-files complete", wait: true}));
});
task('default', series('templates', 'js-files', 'js-gmaps-files', 'js-files-nojquery', 'jsFilesCroutonMap', 'jsFilesCroutonCore', 'jsFilesCroutonNoCore', 'css-files', 'css-core-files'));

task('watch', () => {
watch([
Expand Down

0 comments on commit b8d51e3

Please sign in to comment.