Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
[OYPD-556] Update openy_group_schedules from Houston YMCA. (#728)
Browse files Browse the repository at this point in the history
* [OYPD-556] Update openy_group_schedules from Houston YMCA.

* [OYPD-556] Fix issues & bring changes more inline with Houston, attempting to resolve anonymous user errors.

* [OYPD-556] Resolve wrong option ids for groupex form.

* [OYPD-556] Resolve class selection overwriting from previous value.

* [OYPD-556] Update groupex pro paragraph behat test after updates.

* [OYPD-556] Fix instructor query & date styles.

* [OYPD-556] Remove schedules date select cache, and include instructor from query param when no user input is provided.

* [OYPD-556] Sync js Drupal.openy_group_schedules.update_class_select from houstonY.

* [OYPD-556] Add Drupal.openy_group_schedules.update_instructor_select to update instructor on after ajax links.

* [OYPD-556] Clean instructor option keys per instruction.

* [OYPD-556] Resolve date and instructor field setting, add submit.
  • Loading branch information
Kerby70 authored and alexschedrov committed Aug 10, 2017
1 parent 9f6e483 commit b5b8595
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 70 deletions.
42 changes: 25 additions & 17 deletions modules/custom/openy_group_schedules/js/openy_group_schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
*/
Drupal.openy_group_schedules.update_filter_date = function(parameters) {
if (typeof(parameters.filter_date) !== 'undefined') {
var date = parameters.filter_date.replace('0','');
if (date.charAt(0) === '0') {
date = date.slice(1);
}
var exists = 0 !== $('select[name="date_select"] option[value="' + date + '"]').length;
if (exists) {
$('select[name="date_select"]').val(date);
}
var split_date = parameters.filter_date.split('/');
var day = split_date[0].length == 1 ? '0' + split_date[0] : split_date[0];
var year = parseInt(split_date[2]) + 2000;
var date = year + '-' + day + '-' + split_date[1];
$('input[name="date_select"]').val(date);
}
};

Expand All @@ -26,10 +23,6 @@
* @param parameters
*/
Drupal.openy_group_schedules.update_class_select = function(parameters) {
if (typeof(parameters.view_mode) !== 'undefined' && parameters.view_mode == 'class') {
$('#date-select-wrapper, #location-wrapper').addClass('hidden');
$('#class-select-wrapper, #location-select-wrapper').removeClass('hidden');
}
if (typeof(parameters.class) !== 'undefined') {
var exists = 0 !== $('#class-select-wrapper select option[value="' + parameters.class + '"]').length;
if (exists) {
Expand All @@ -38,6 +31,20 @@
}
};

/**
* Update "Instructor" select value to be equal with "instructor" query param.
*
* @param parameters
*/
Drupal.openy_group_schedules.update_instructor_select = function(parameters) {
if (typeof(parameters.instructor) !== 'undefined') {
var exists = 0 !== $('#instructor-select-wrapper select option[value="' + parameters.instructor + '"]').length;
if (exists) {
$('#instructor-select-wrapper select').val(parameters.instructor);
}
}
};

/**
* Update "Location" select value to be equal with "location" query param.
*
Expand Down Expand Up @@ -74,18 +81,19 @@
history.pushState(null, null, window.location.pathname + '?' + params.join('&'));

if (typeof(parameters.instructor) !== 'undefined') {
$('#date-select-wrapper, #location-wrapper, #class-select-wrapper').addClass('hidden');
$('#location-wrapper').addClass('hidden');
}
else if (typeof(parameters.view_mode) !== 'undefined' && parameters.view_mode == 'class') {
$('#location-select-wrapper, #class-select-wrapper').removeClass('hidden');
$('#date-select-wrapper, #location-wrapper').addClass('hidden');
$('#location-select-wrapper, #class-select-wrapper, #instructor-select-wrapper').removeClass('hidden');
$('#location-wrapper').addClass('hidden');
}
else {
$('#location-select-wrapper, #date-select-wrapper').removeClass('hidden');
$('#class-select-wrapper, #location-wrapper').addClass('hidden');
$('#location-select-wrapper, #date-select-wrapper, #class-select-wrapper, #instructor-select-wrapper').removeClass('hidden');
$('#location-wrapper').addClass('hidden');
}

Drupal.openy_group_schedules.update_class_select(parameters);
Drupal.openy_group_schedules.update_instructor_select(parameters);
Drupal.openy_group_schedules.update_filter_date(parameters);
Drupal.openy_group_schedules.update_location_select(parameters);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@

## How to run the warmer

``\Drupal::service("groupex_form_cache.warmer")->warm();``
``groupex_form_cache_warm();``

## How to clear the cache

``\Drupal::service("groupex_form_cache.manager")->resetCache(10);``
``\Drupal::service("groupex_form_cache.manager")->resetCache(100);``

or

``groupex_form_cache_reset_all();``

## How to clear the cache (using truncate)

``groupex_form_cache_reset_all_quick();``

## How to clear the only stale cache

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* @file
* Module file.
*/

/**
* Run Groupex Form cache warmer.
*
* @param int $lock_lifetime
* Lock lifetime. 7 hours by default.
*/
function groupex_form_cache_warm($lock_lifetime = 25200) {
$lock_name = "groupex_form_cache_warmer";

// 7 hours of lock lifetime.
$lock = \Drupal::lock();
if ($lock->acquire($lock_name, $lock_lifetime)) {
\Drupal::service('groupex_form_cache.warmer')->warm();
$lock->release($lock_name);
}
else {
$msg = 'Lock "%name" is still working. Exit.';
Drupal::logger('groupex_form_cache')->info(
$msg,
[
'%name' => $lock_name,
]
);
}
}

/**
* Reset all GroupEx form cache.
*/
function groupex_form_cache_reset_all() {
\Drupal::service("groupex_form_cache.manager")->resetCache(100);
}

/**
* Quick Groupex cache reset (using TRUNCATE).
*/
function groupex_form_cache_reset_all_quick() {
\Drupal::service("groupex_form_cache.manager")->quickResetCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,21 @@ public function runCronServices() {
$this->resetStaleCache(10, 172800);
}

/**
* Quick reset of Groupex Form Cache.
*/
public function quickResetCache() {
$tables = [
'groupex_form_cache',
'groupex_form_cache__field_gfc_created',
'groupex_form_cache__field_gfc_options',
'groupex_form_cache__field_gfc_response',
];

foreach ($tables as $table) {
db_truncate($table)->execute();
}
$this->logger->info('Groupex Form Cache has been quickly erased using "TRUNCATE".');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\groupex_form_cache\Entity\GroupexFormCache;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Logger\LoggerChannel;
use Drupal\openy_socrates\OpenyCronServiceInterface;
use Drupal\openy_group_schedules\GroupexRequestTrait;

Expand Down Expand Up @@ -72,8 +71,27 @@ public function warm() {
* Warm up simple elements.
*/
private function simpleWarmUp() {
$this->request(['locations' => TRUE]);
$this->request(['classes' => TRUE]);
// Warm up frequent requests.
$this->request(['query' => ['classes' => TRUE]]);
$locations = $this->request(['query' => ['locations' => TRUE]]);

// Warm up cache for current day for all locations.
$timezone = new \DateTimeZone($this->configFactory->get('system.date')->get('timezone')['default']);
$datetime = new \DateTime('today midnight', $timezone);
$start = $datetime->getTimestamp();
$end = $datetime->add(new \DateInterval('P1D'))->getTimestamp();
foreach ($locations as $location) {
$options = [
'query' => [
'schedule' => TRUE,
'desc' => "true",
'location' => [(string) $location->id],
'start' => $start,
'end' => $end,
]
];
$this->request($options);
}
}

/**
Expand All @@ -85,7 +103,12 @@ private function traverse() {
}

// Loop over each cache entity.
$this->logger->info('Starting warming up %count cache entities.', ['%count' => count($result)]);
krsort($result);
foreach ($result as $item) {
// Let's protect GroupEx servers.
sleep(1);

if (!$entity = GroupexFormCache::load($item)) {
continue;
}
Expand Down
17 changes: 17 additions & 0 deletions modules/custom/openy_group_schedules/openy_group_schedules.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Drupal\openy_group_schedules\GroupexScheduleFetcher;
use Drupal\Component\Utility\Xss;

/**
* Implements hook_theme().
Expand Down Expand Up @@ -241,10 +242,13 @@ function openy_group_schedules_schedule_table_layout(array $schedule) {
$class_item = reset($day['classes']);
if ($class_item) {
$class = $class_item['#class'];
// Allow iframe tag in description to embed video.
$allowed_tags = array_merge(Xss::getAdminTagList(), ['iframe']);
$prefix = [
[
'#type' => 'container',
'#markup' => $class['description'],
'#allowed_tags' => $allowed_tags,
'#attributes' => [
'class' => ['class-description'],
],
Expand All @@ -260,6 +264,19 @@ function openy_group_schedules_schedule_table_layout(array $schedule) {
}
}

// Show help text in case of there is no prefix and there are results.
if (empty($prefix)) {
$prefix = [
[
'#type' => 'container',
'#markup' => '<p>Please note, you may search by class or instructor by clicking on the links in class cards.</p>',
'#attributes' => [
'class' => ['class-description'],
],
],
];
}

// Output schedule by type.
switch ($schedule['type']) {
case 'day':
Expand Down
Loading

0 comments on commit b5b8595

Please sign in to comment.