From 2ecda5108eb5a6eb84c27b11596d52c030dbc78a Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 12 Mar 2015 22:29:55 +0100 Subject: [PATCH 1/8] Updated makefile to point to tag 2.0.0 --- ding_availability.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_availability.make b/ding_availability.make index 4d3a7c2..95353c3 100644 --- a/ding_availability.make +++ b/ding_availability.make @@ -11,5 +11,5 @@ projects[virtual_field][version] = "1.2" projects[ding_provider][type] = "module" projects[ding_provider][download][type] = "git" projects[ding_provider][download][url] = "git@github.com:ding2/ding_provider.git" -projects[ding_provider][download][branch] = "master" +projects[ding_provider][download][tag] = "v2.0.0" From 7acce886b4954084b32eb1e8489dd649a9bf7f71 Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 22 Aug 2014 16:28:14 +0200 Subject: [PATCH 2/8] DDBEASY-32 - Waiting time when no items available. Signed-off-by: Martin Cording --- ding_availability.module | 46 +++++++++++++++++++++++++++++++++ templates/ding-holdings.tpl.php | 1 + 2 files changed, 47 insertions(+) diff --git a/ding_availability.module b/ding_availability.module index 9d655d7..ae7cf08 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -184,7 +184,19 @@ function ding_availability_holdings($provider_ids) { ); $rows = array(); + $copies = 0; + $closest_loan = NULL; foreach ($item['holdings'] as $holding) { + // This item is considered to be waited for. + // Next, the number of holdings is compared to reserved ones. + // Also keep the next loan date. + if (empty($item['available']) && !empty($holding['available_from'])) { + $next_loan_time = strtotime($holding['available_from']); + $copies++; + if (empty($closest_loan) || $closest_loan < $next_loan_time) { + $closest_loan = $next_loan_time; + } + } $rows[] = ding_availability_holdings_row($holding); } @@ -198,6 +210,7 @@ function ding_availability_holdings($provider_ids) { ), 'total_count' => $item['total_count'], 'reserved_count' => $item['reserved_count'], + 'closest_loan' => (count($item['holdings']) == $copies) ? ding_availability_holding_format_time($closest_loan) : NULL, )); } } @@ -205,6 +218,39 @@ function ding_availability_holdings($provider_ids) { return $items; } +/** + * Generate a human-readable amount of wait time. + * + * @param int $date + * Loan date timestamp. + * @return string + * Sane display of time to wait (months/weeks/days). + */ +function ding_availability_holding_format_time($date) { + $days = ceil(($date - time()) / 86400); + + $plurals = array('day' => 'days', 'week' => 'weeks', 'month' => 'months'); + if ($days > 35) { + $days = ceil($days / 30); + $label = 'month'; + } + elseif ($days > 6) { + $days = ceil($days / 7); + $label = 'week'; + } + else { + $label = 'day'; + } + + if ($days > 1) { + $label = $plurals[$label]; + } + + $text = t('The waiting time is currently: @days @label', array('@days' => $days, '@label' => $label)); + + return $text; +} + /** * @param $holding * diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index 0efbb9a..191875b 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -13,4 +13,5 @@ $reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); ?>

+

From 80b859a1bb967601a22e8f65e6c279d049ac716b Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 22 Aug 2014 16:38:59 +0200 Subject: [PATCH 3/8] DDBEASY-33 - Status for materials underway. Signed-off-by: Martin Cording --- ding_availability.module | 7 +++++++ templates/ding-holdings.tpl.php | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index ae7cf08..941e1ee 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -186,6 +186,7 @@ function ding_availability_holdings($provider_ids) { $rows = array(); $copies = 0; $closest_loan = NULL; + $in_acquisition = 0; foreach ($item['holdings'] as $holding) { // This item is considered to be waited for. // Next, the number of holdings is compared to reserved ones. @@ -197,6 +198,11 @@ function ding_availability_holdings($provider_ids) { $closest_loan = $next_loan_time; } } + + if ($holding['status'] == 'inAcquisition') { + $in_acquisition++; + } + $rows[] = ding_availability_holdings_row($holding); } @@ -211,6 +217,7 @@ function ding_availability_holdings($provider_ids) { 'total_count' => $item['total_count'], 'reserved_count' => $item['reserved_count'], 'closest_loan' => (count($item['holdings']) == $copies) ? ding_availability_holding_format_time($closest_loan) : NULL, + 'in_acquisition' => $in_acquisition, )); } } diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index 191875b..b2b41c8 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -9,9 +9,19 @@ * - $reserved_count: Amount of reservations. */ -$total_text = format_plural($total_count, 'We have 1 copy.', 'We have @count copies.', array('@count' => $total_count)); -$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material.', 'There are @count users in queue to loan the material.'); +$total_text = format_plural($total_count, 'We have 1 copy', 'We have @count copies', array('@count' => $total_count)); +$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material', 'There are @count users in queue to loan the material'); +$acquisition_text = format_plural($in_acquisition, '(1 material under way)', '(@count materials under way)', array('@count' => $in_acquisition)); + +if ($in_acquisition > 0) { + $total_text .= ' ' . $acquisition_text; +} + ?> -

-

+

+ +

+

+ +

From a898eaaace27eac0ef023c0615338d07724e1de8 Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 22 Aug 2014 16:41:05 +0200 Subject: [PATCH 4/8] DDBEASY-33 - Translation issues. Signed-off-by: Martin Cording --- ding_availability.module | 2 +- templates/ding-holdings.tpl.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ding_availability.module b/ding_availability.module index 941e1ee..ec1b0bb 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -236,7 +236,7 @@ function ding_availability_holdings($provider_ids) { function ding_availability_holding_format_time($date) { $days = ceil(($date - time()) / 86400); - $plurals = array('day' => 'days', 'week' => 'weeks', 'month' => 'months'); + $plurals = array('day' => t('days'), 'week' => t('weeks'), 'month' => t('months')); if ($days > 35) { $days = ceil($days / 30); $label = 'month'; diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index b2b41c8..b5ca876 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -9,9 +9,9 @@ * - $reserved_count: Amount of reservations. */ -$total_text = format_plural($total_count, 'We have 1 copy', 'We have @count copies', array('@count' => $total_count)); -$reserved_text = format_plural($reserved_count, 'There is 1 user in queue to loan the material', 'There are @count users in queue to loan the material'); -$acquisition_text = format_plural($in_acquisition, '(1 material under way)', '(@count materials under way)', array('@count' => $in_acquisition)); +$total_text = format_plural($total_count, t('We have 1 copy'), t('We have @count copies'), array('@count' => $total_count)); +$reserved_text = format_plural($reserved_count, t('There is 1 user in queue to loan the material'), t('There are @count users in queue to loan the material')); +$acquisition_text = format_plural($in_acquisition, t('(1 material under way)'), t('(@count materials under way)'), array('@count' => $in_acquisition)); if ($in_acquisition > 0) { $total_text .= ' ' . $acquisition_text; From 1c707231d8830f49a5cbe2980bd39b10430b122d Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 5 Dec 2014 13:49:05 +0100 Subject: [PATCH 5/8] DDBEASY-184 - Remove the reservation-queue text, if item is not reservable. Signed-off-by: Martin Cording --- templates/ding-holdings.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/ding-holdings.tpl.php b/templates/ding-holdings.tpl.php index b5ca876..0588e00 100644 --- a/templates/ding-holdings.tpl.php +++ b/templates/ding-holdings.tpl.php @@ -19,7 +19,7 @@ ?>

- + " . $reserved_text . ""; ?>

From e030f4fbf31ccdd39f50e22debb3ab5309cdf95e Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 5 Dec 2014 13:56:00 +0100 Subject: [PATCH 6/8] DDBEASY-40 - Enable [Reserve]-button on searchResult. Signed-off-by: Martin Cording --- js/ding_availability_labels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index e3f2479..f6131a8 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -91,7 +91,7 @@ // Get hold of the reserve button (it hidden as default, so we may need // to show it). - var reserver_btn = element.parents('.ting-object:first').find('[id^=ding-reservation-reserve-form]'); + var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); if (available) { update_availability_elements(element, reserver_btn, 'available'); From a70173c0c1d85a015270983283aa4542a90035ae Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Fri, 5 Dec 2014 14:00:50 +0100 Subject: [PATCH 7/8] DDBEASY-83 - Remove holding table if all items have noHolding attribute. Signed-off-by: Martin Cording --- ding_availability.module | 1 + js/ding_availability.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ding_availability.module b/ding_availability.module index 9d655d7..bb3ba2c 100644 --- a/ding_availability.module +++ b/ding_availability.module @@ -151,6 +151,7 @@ function ding_availability_items($provider_ids) { */ function ding_availability_holdings($provider_ids) { $items = ding_provider_invoke('availability', 'holdings', $provider_ids); + $items = array_filter($items, function($v) { return $v['availability_information']; }); if (!$items) { return array(); } diff --git a/js/ding_availability.js b/js/ding_availability.js index a456ba3..0fce4c8 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -148,6 +148,13 @@ if (Drupal.DADB[entity_id] && (Drupal.DADB[entity_id]['holdings'])) { // Show status for material. $('#' + id).html(Drupal.DADB[entity_id].html); + // Don't show queue time if item not reservable. + if (Drupal.DADB[entity_id].reservable === false) { + $('#' + id + ' span.in-queue').hide(); + } + } + else { + $('div.group-holdings-available').parent().parent().remove(); } } From dc1fb96e3a0ee2ee0a36fdd41d146f678313f57b Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Tue, 17 Mar 2015 19:13:18 +0100 Subject: [PATCH 8/8] DDBEASY-116 - Refactored the availability and reservable logic. --- ding_availability.field.inc | 2 +- js/ding_availability.js | 17 ++--- js/ding_availability_labels.js | 109 ++++++++++++++++++--------------- 3 files changed, 69 insertions(+), 59 deletions(-) diff --git a/ding_availability.field.inc b/ding_availability.field.inc index edcb15b..cef7bee 100644 --- a/ding_availability.field.inc +++ b/ding_availability.field.inc @@ -235,7 +235,7 @@ function ding_availability_field_formatter_view($entity_type, $entity, $field, $ 'link' => array( // The online url can't be used with l(), has it will encode // it. - '#markup' => '' . check_plain($type) . '', + '#markup' => '' . check_plain($type) . '', ), ); } diff --git a/js/ding_availability.js b/js/ding_availability.js index 0fce4c8..f3f10ba 100644 --- a/js/ding_availability.js +++ b/js/ding_availability.js @@ -83,18 +83,18 @@ var available = false; var reservable = false; var is_internet = false; + var element = $('#' + id); + element.removeClass('pending').addClass('processed'); + $.each(entity_ids, function(index, entity_id) { + // Reserve button + var reserver_btn = element.parents('.ting-object:first').find('a[id$=' + entity_id + '].reserve-button'); + if (Drupal.DADB[entity_id]) { available = available || Drupal.DADB[entity_id]['available']; reservable = reservable || Drupal.DADB[entity_id]['reservable']; is_internet = is_internet || Drupal.DADB[entity_id]['is_internet']; - var element = $('#' + id); - element.removeClass('pending').addClass('processed'); - - // Reserve button - var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); - if (available) { element.addClass('available'); @@ -121,7 +121,7 @@ } } - if (!available && !reservable) { + else { element.addClass('not-reservable'); // Add class to reserve button @@ -130,6 +130,9 @@ } } } + else { + reserver_btn.addClass('not-reservable'); + } }); } diff --git a/js/ding_availability_labels.js b/js/ding_availability_labels.js index f6131a8..7bb1338 100644 --- a/js/ding_availability_labels.js +++ b/js/ding_availability_labels.js @@ -74,15 +74,17 @@ */ function update_availability(id, entity_ids) { // Default the status to not available and not reservable. - var available = false; - var reservable = false; + var status = { + available: false, + reservable: false + }; // Loop over the entity ids and if one has available or reservable // true save that value. $.each(entity_ids, function(index, entity_id) { if (Drupal.DADB[entity_id]) { - available = available || Drupal.DADB[entity_id]['available']; - reservable = reservable || Drupal.DADB[entity_id]['reservable']; + status.available = status.available || Drupal.DADB[entity_id]['available']; + status.reservable = status.reservable || Drupal.DADB[entity_id]['reservable']; } }); @@ -93,18 +95,7 @@ // to show it). var reserver_btn = element.parents('.ting-object:first').find('.reserve-button'); - if (available) { - update_availability_elements(element, reserver_btn, 'available'); - } - else if (reservable) { - update_availability_elements(element, reserver_btn, 'reservable'); - } - else if (!available && !reservable) { - update_availability_elements(element, reserver_btn, 'not-reservable'); - } - else { - update_availability_elements(element, reserver_btn, 'unavailable'); - } + update_availability_elements(element, reserver_btn, status); } /** @@ -113,38 +104,38 @@ * * @param element * The target element (material that should be moved). - * @param type - * The type of availability the element has. + * @param status + * Structure with available and reservable state. */ - function update_availability_type(element, type) { - // Select type, if any or create the type. + function update_availability_type(element, status) { var groups_wrapper = element.closest('.search-result--availability'); - var group = $('.js-' + type, groups_wrapper); - if (group.length !== 1) { - // Create group. - if (type === 'available') { - // Add as first line. - group = $('

' + Drupal.t('Available') + ':

'); - groups_wrapper.prepend(group); - } - else if (type === 'unavailable') { - // Add last. - group = $('

' + Drupal.t('Unavailable') + ':

'); - group.insertBefore('.js-pending', groups_wrapper); + var reservable = status['reservable']; + var available = status['available']; + + var group = null; + if ($('.js-online', groups_wrapper).length !== 0) { + group = $('.js-online', groups_wrapper); + } + else if (available) { + group = $('.js-available', groups_wrapper); + + if (group.length === 0) { + group = $('

' + Drupal.t('Available') + ':

'); + groups_wrapper.append(group); } - else if (type === 'reservable') { - // First or after available. - group = $('

' + Drupal.t('Reservable') + ':

'); - if ($('.js-available', groups_wrapper).length) { - group.insertAfter($('.js-available', groups_wrapper)); - } - else { - groups_wrapper.prepend(group); - } + } + else if (reservable) { + group = $('.js-reservable', groups_wrapper); + if (group.length === 0) { + group = $('

' + Drupal.t('Reservable') + ':

'); + groups_wrapper.append(group); } - else { - // Add last to not-reservable. - group = $('

' + Drupal.t('Not reservable') + ':

'); + } + else { + group = $('.js-unavailable', groups_wrapper); + + if (group.length === 0) { + group = $('

' + Drupal.t('Not available') + ':

'); groups_wrapper.append(group); } } @@ -182,16 +173,32 @@ * jQuery availability element to add the class to. * @param btn * Reservation button to add the class to. - * @param class_name - * The class to add to the elements. + * @param status + * Structure with available and reservable state. */ - function update_availability_elements(element, btn, class_name) { - element.addClass(class_name); - if (btn.length) { - btn.addClass(class_name); + function update_availability_elements(element, btn, status) { + var class_name = null; + + for (var i in status) { + if (status[i] === true) { + class_name = i; + } + else { + if (i === 'available') { + class_name = 'un' + i; + } + else if (i === 'reservable') { + class_name = 'not-' + i; + } + } + + element.addClass(class_name); + if (btn.length) { + btn.addClass(class_name); + } } - update_availability_type(element, class_name); + update_availability_type(element, status); } } };