From e85d84528c398f94068adafc79071f22b541ff39 Mon Sep 17 00:00:00 2001 From: Jeroen Goossens Date: Mon, 20 Nov 2017 13:30:58 +0100 Subject: [PATCH 1/3] OPEN-57: Added openinghours widget. --- components/21-atoms/openinghours/README.md | 1 + .../openinghours/openinghours--month.twig | 1 + .../openinghours/openinghours--week.twig | 1 + .../openinghours/openinghours.binding.js | 12 ++++ .../openinghours/openinghours.config.json | 22 ++++++ .../21-atoms/openinghours/openinghours.js | 72 +++++++++++++++++++ .../21-atoms/openinghours/openinghours.twig | 1 + components/41-organisms/header/header.twig | 20 +++--- components/_preview.twig | 3 + gulpfile.js | 5 ++ 10 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 components/21-atoms/openinghours/README.md create mode 100644 components/21-atoms/openinghours/openinghours--month.twig create mode 100644 components/21-atoms/openinghours/openinghours--week.twig create mode 100644 components/21-atoms/openinghours/openinghours.binding.js create mode 100644 components/21-atoms/openinghours/openinghours.config.json create mode 100644 components/21-atoms/openinghours/openinghours.js create mode 100644 components/21-atoms/openinghours/openinghours.twig diff --git a/components/21-atoms/openinghours/README.md b/components/21-atoms/openinghours/README.md new file mode 100644 index 0000000..cb62055 --- /dev/null +++ b/components/21-atoms/openinghours/README.md @@ -0,0 +1 @@ +Currently in Alpha since Openinghours isn't in production yet. \ No newline at end of file diff --git a/components/21-atoms/openinghours/openinghours--month.twig b/components/21-atoms/openinghours/openinghours--month.twig new file mode 100644 index 0000000..e26c505 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours--month.twig @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/components/21-atoms/openinghours/openinghours--week.twig b/components/21-atoms/openinghours/openinghours--week.twig new file mode 100644 index 0000000..d951b12 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours--week.twig @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/components/21-atoms/openinghours/openinghours.binding.js b/components/21-atoms/openinghours/openinghours.binding.js new file mode 100644 index 0000000..7728f30 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours.binding.js @@ -0,0 +1,12 @@ +/** + * @file + * Javascript binding of header.functions.js. + */ +(function ($) { + 'use strict'; + + $(window).on('load', function (e) { + $('.openinghours').openingHours(); + }); + +})(jQuery); diff --git a/components/21-atoms/openinghours/openinghours.config.json b/components/21-atoms/openinghours/openinghours.config.json new file mode 100644 index 0000000..20cc842 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours.config.json @@ -0,0 +1,22 @@ +{ + "title": "Openinghours", + "name": "openinghours", + "status": "alpha", + "preview": "@preview", + "handle": "openinghours", + "default": "open-now", + "variants": [ + { + "name": "open-now", + "title": "Open now" + }, + { + "name": "week", + "title": "Open now" + }, + { + "name": "month", + "title": "Open now" + } + ] +} diff --git a/components/21-atoms/openinghours/openinghours.js b/components/21-atoms/openinghours/openinghours.js new file mode 100644 index 0000000..4a43b36 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours.js @@ -0,0 +1,72 @@ +/** + * @file + * Implements Ghent's opening hours widgets. + * + * @author + * Jeroen Goossens + * + */ +(function ($) { + 'use strict'; + + $.fn.openingHours = function (options) { + function _getDate(date) { + return date.getDate() + '-' + (date.getMonth() + 1) + '-' + date.getFullYear(); + } + + var now = new Date(); + var defaults = { + endpoint: '//openingsuren.stad.gent' + }; + options = $.extend(defaults, options); + + $(this).each(function (i) { + function _getOpeningHours(element) { + if (typeof element.data('service') !== 'number' || typeof element.data('channel') !== 'number') { + element.html('Error: Please provide a service and channel.'); + return null; + } + + if (typeof element.data('date') === 'string' && element.data('type') === 'open-now') { + element.html('Error: Date is not supported in the "open now" widget.'); + return null; + } + + var date; + if (typeof element.data('date') !== 'string') { + date = new Date(); + } + else { + date = new Date(element.data('date')); + } + date = _getDate(date); + + switch (element.data('type')) { + case 'open-now': + _request(options.endpoint + '/api/v1/services/' + element.data('service') + '/channels/' + element.data('channel') + '/open-now'); + break; + case 'month': + _request(options.endpoint + '/api/v1/services/' + element.data('service') + '/channels/' + element.data('channel') + '/openinghours/month?date=' + date); + break; + default: + var until = new Date(); + until.setDate(now.getDate() + 6); + _request(options.endpoint + '/api/v1/services/' + element.data('service') + '/channels/' + element.data('channel') + '/openinghours?from=' + date + '&until=' + _getDate(until)); + break; + } + } + function _request(request) { + $.ajax({ + url: request, + dataType: 'html', + success: function (html) { + element.html(html); + } + }); + } + + var element = $(this); + _getOpeningHours(element); + }); + }; +}(jQuery)); diff --git a/components/21-atoms/openinghours/openinghours.twig b/components/21-atoms/openinghours/openinghours.twig new file mode 100644 index 0000000..98e9ea5 --- /dev/null +++ b/components/21-atoms/openinghours/openinghours.twig @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/components/41-organisms/header/header.twig b/components/41-organisms/header/header.twig index e2a5ee9..eafaa6f 100644 --- a/components/41-organisms/header/header.twig +++ b/components/41-organisms/header/header.twig @@ -1,14 +1,16 @@
- - {% include '@hamburger-menu' with { - "items": [ - "Menu item 1", - "Menu item 2", - "Menu item 3", - "Menu item 4" - ] - } %} +