From 1608805ce41d2d304964aa15a9c54c8ed63b2d33 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 25 Apr 2019 23:03:46 +0100 Subject: [PATCH 01/31] gwsumm.js: allow highlighting of selected dates --- share/js/gwsumm.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index 8f5c4adb..ea723e13 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -191,7 +191,22 @@ $(window).load(function() { weekStart: 1, endDate: moment().utc().format('DD/MM/YYYY'), todayHighlight: true, - todayBtn: "linked" + todayBtn: "linked", + beforeShowDay: function(date) { + // highlight selected dates if given + if ( document.getElementById('calendar').hasAttribute('selected-dates') ){ + var selected_dates = document.getElementById('calendar').getAttribute('selected-dates').split(','); + var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); + var search_index = highlightdays.indexOf(calendar_date); + if ( search_index == -1 ){ + // disable dates that are not given + return {enabled: false, tooltip: 'Date not available'}; + } + else{ + return {classes: 'highlighted', enabled: true}; + } + } + } }).on('changeDate', move_to_date); // load correct run type From b86dd26a4630ede72b700b2a819529b32eb1d0f8 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 25 Apr 2019 23:15:32 +0100 Subject: [PATCH 02/31] bootstrap.py: allow calendar to take selected dates --- gwsumm/html/bootstrap.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index 641ac680..c309bf83 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -76,7 +76,7 @@ class option for

def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', - id_='calendar', dateformat=None, mode=None): + id_='calendar', dateformat=None, mode=None, selecteddates=None): """Construct a bootstrap-datepicker calendar. Parameters @@ -111,7 +111,8 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', onclick='stepDate(-1)') page.a(id_=id_, class_=class_, title='Show/hide calendar', **{'data-date': data_date, 'data-date-format': 'dd-mm-yyyy', - 'data-viewmode': '%ss' % mode.name}) + 'data-viewmode': '%ss' % mode.name, + 'selected-dates': ','.join([str(seldate) for seldate in selected]) }) page.add(datestring) page.b('', class_='caret') page.a.close() From 494feefac3205e220be129a07d975aa50b30805b Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 25 Apr 2019 23:18:12 +0100 Subject: [PATCH 03/31] gwsumm.js: only add selected dates if array length is greater than 0 --- share/js/gwsumm.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index ea723e13..56d169a1 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -196,14 +196,15 @@ $(window).load(function() { // highlight selected dates if given if ( document.getElementById('calendar').hasAttribute('selected-dates') ){ var selected_dates = document.getElementById('calendar').getAttribute('selected-dates').split(','); - var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); - var search_index = highlightdays.indexOf(calendar_date); - if ( search_index == -1 ){ - // disable dates that are not given - return {enabled: false, tooltip: 'Date not available'}; - } - else{ - return {classes: 'highlighted', enabled: true}; + if (selected_dates.length > 0 ){ + var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); + if ( selected_dates.indexOf(calendar_date) == -1 ){ + // disable dates that are not given + return {enabled: false, tooltip: 'Date not available'}; + } + else{ + return {classes: 'highlighted', enabled: true}; + } } } } From ce7c0873a5fe531db0880122c112f2534a2d9a93 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Thu, 25 Apr 2019 23:36:17 +0100 Subject: [PATCH 04/31] core.py: attempt to parse selected dates from calendar ini file section --- gwsumm/tabs/core.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index da5783ea..a637cf01 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -791,6 +791,37 @@ def __init__(self, *args, **kwargs): self.span = span super(IntervalTab, self).__init__(*args, **kwargs) + @classmethod + def from_ini(cls, cp, section='calendar', *args, **kwargs): + """Configure a new `IntervalTab` from a `ConfigParser` section + Parameters + ---------- + cp : :class:`~gwsumm.config.ConfigParser` + configuration to parse. + section : `str` + name of section to read + See Also + -------- + Tab.from_ini : + for documentation of the standard configuration + options + Notes + ----- + On top of the standard configuration options, the `IntervalTab` can + be configured with the ``selected-dates`` option, specifying dates to + be highlighted in the calendar: + .. code-block:: ini + [calendar] + selected-dates = 2019-01-04,2019-01-07 + """ + + if cp.has_option(section, 'selected-dates'): + self.selecteddates = cp.get(section, 'selected-dates')) + else: + self.selecteddates = None + return super(IntervalTab, cls).from_ini(cp, section, url, + *args, **kwargs) + def html_calendar(self): """Build the datepicker calendar for this tab. @@ -810,7 +841,7 @@ def html_calendar(self): "format including %r for archive calendar" % (self.path, requiredpath)) # format calendar - return html.calendar(date, mode=self.mode) + return html.calendar(date, mode=self.mode, selecteddates=self.selecteddates) def html_navbar(self, brand=None, calendar=True, **kwargs): """Build the navigation bar for this `Tab`. From 8704e18e7015f3c5b5f91687830458961df718e3 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 10:11:39 +0100 Subject: [PATCH 05/31] Some changes to the highlighted dates option --- gwsumm/html/bootstrap.py | 12 ++++++++---- gwsumm/tabs/core.py | 27 ++++++++++++++------------- share/js/gwsumm.js | 4 ++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index c309bf83..55c9427c 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -76,7 +76,8 @@ class option for

def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', - id_='calendar', dateformat=None, mode=None, selecteddates=None): + id_='calendar', dateformat=None, mode=None, + highlighteddates=None): """Construct a bootstrap-datepicker calendar. Parameters @@ -109,10 +110,13 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', page = markup.page() page.a('«', class_='navbar-brand step-back', title='Step back', onclick='stepDate(-1)') + attributekwargs = {'data-date': data_date, + 'data-date-format': 'dd-mm-yyyy', + 'data-viewmode': '%ss' % mode.name} + if highlighteddates is not None: + attributekwargs['highlighted-dates'] = highligheddates.replace('-', '') page.a(id_=id_, class_=class_, title='Show/hide calendar', - **{'data-date': data_date, 'data-date-format': 'dd-mm-yyyy', - 'data-viewmode': '%ss' % mode.name, - 'selected-dates': ','.join([str(seldate) for seldate in selected]) }) + **attributekwargs) page.add(datestring) page.b('', class_='caret') page.a.close() diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index a637cf01..f86f72b0 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -792,7 +792,7 @@ def __init__(self, *args, **kwargs): super(IntervalTab, self).__init__(*args, **kwargs) @classmethod - def from_ini(cls, cp, section='calendar', *args, **kwargs): + def from_ini(cls, cp, section, *args, **kwargs): """Configure a new `IntervalTab` from a `ConfigParser` section Parameters ---------- @@ -808,20 +808,20 @@ def from_ini(cls, cp, section='calendar', *args, **kwargs): Notes ----- On top of the standard configuration options, the `IntervalTab` can - be configured with the ``selected-dates`` option, specifying dates to - be highlighted in the calendar: + be configured with the ``highlighted-dates`` option, specifying dates + to be highlighted in the calendar: .. code-block:: ini [calendar] - selected-dates = 2019-01-04,2019-01-07 + highlighted-dates = 2019-01-04,2019-01-07 """ - - if cp.has_option(section, 'selected-dates'): - self.selecteddates = cp.get(section, 'selected-dates')) - else: - self.selecteddates = None - return super(IntervalTab, cls).from_ini(cp, section, url, - *args, **kwargs) - + + # check for highlighted dates + self.highlightteddates = None + if cp.has_option('calendar', 'highlighted-dates'): + self.highlighteddates = cp.get(section, 'highlighted-dates')) + + return super(IntervalTab, cls).from_ini(cp, section, *args, **kwargs) + def html_calendar(self): """Build the datepicker calendar for this tab. @@ -841,7 +841,8 @@ def html_calendar(self): "format including %r for archive calendar" % (self.path, requiredpath)) # format calendar - return html.calendar(date, mode=self.mode, selecteddates=self.selecteddates) + return html.calendar(date, mode=self.mode, + highlighteddates=self.selecteddates) def html_navbar(self, brand=None, calendar=True, **kwargs): """Build the navigation bar for this `Tab`. diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index 56d169a1..241fecf2 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -194,8 +194,8 @@ $(window).load(function() { todayBtn: "linked", beforeShowDay: function(date) { // highlight selected dates if given - if ( document.getElementById('calendar').hasAttribute('selected-dates') ){ - var selected_dates = document.getElementById('calendar').getAttribute('selected-dates').split(','); + if ( document.getElementById('calendar').hasAttribute('highlighted-dates') ){ + var selected_dates = document.getElementById('calendar').getAttribute('highlighted-dates').split(','); if (selected_dates.length > 0 ){ var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); if ( selected_dates.indexOf(calendar_date) == -1 ){ From b4ec533983214d719eeba0dd06bb8644bd330a36 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 02:18:52 -0700 Subject: [PATCH 06/31] core.py: fix typo --- gwsumm/tabs/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index f86f72b0..95f1ea31 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -818,7 +818,7 @@ def from_ini(cls, cp, section, *args, **kwargs): # check for highlighted dates self.highlightteddates = None if cp.has_option('calendar', 'highlighted-dates'): - self.highlighteddates = cp.get(section, 'highlighted-dates')) + self.highlighteddates = cp.get(section, 'highlighted-dates') return super(IntervalTab, cls).from_ini(cp, section, *args, **kwargs) From 6e4d7d957b6b8b417b8ef27854b148b184a5ea8b Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 04:11:31 -0700 Subject: [PATCH 07/31] a variety of fixes --- gwsumm/html/bootstrap.py | 2 +- gwsumm/tabs/core.py | 48 ++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index 55c9427c..4b9ab358 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -114,7 +114,7 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', 'data-date-format': 'dd-mm-yyyy', 'data-viewmode': '%ss' % mode.name} if highlighteddates is not None: - attributekwargs['highlighted-dates'] = highligheddates.replace('-', '') + attributekwargs['highlighted-dates'] = highlighteddates.replace('-', '') page.a(id_=id_, class_=class_, title='Show/hide calendar', **attributekwargs) page.add(datestring) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 95f1ea31..285593d8 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -436,6 +436,14 @@ def from_ini(cls, cp, section) except KeyError: kwargs['duration'] = cp.getfloat(section, 'duration') + # check for calendar dates to highlight + print(cp.has_option('calendar', 'highlighted-dates')) + if cp.has_option('calendar', 'highlighted-dates'): + try: + kwargs['highlighteddates'] + except KeyError: + kwargs['highlighteddates'] = cp.get('calendar', 'highlighted-dates') + return cls(name, *args, **kwargs) # -- HTML operations ------------------------ @@ -774,6 +782,7 @@ def end(self): class IntervalTab(GpsTab): """`Tab` defined within a GPS [start, end) interval """ + #def __init__(self, highlighteddates=None, *args, **kwargs): def __init__(self, *args, **kwargs): try: span = kwargs.pop('span') @@ -788,39 +797,14 @@ def __init__(self, *args, **kwargs): % (type(self).__name__, mode)) else: span = (start, end) - self.span = span - super(IntervalTab, self).__init__(*args, **kwargs) - - @classmethod - def from_ini(cls, cp, section, *args, **kwargs): - """Configure a new `IntervalTab` from a `ConfigParser` section - Parameters - ---------- - cp : :class:`~gwsumm.config.ConfigParser` - configuration to parse. - section : `str` - name of section to read - See Also - -------- - Tab.from_ini : - for documentation of the standard configuration - options - Notes - ----- - On top of the standard configuration options, the `IntervalTab` can - be configured with the ``highlighted-dates`` option, specifying dates - to be highlighted in the calendar: - .. code-block:: ini - [calendar] - highlighted-dates = 2019-01-04,2019-01-07 - """ - # check for highlighted dates - self.highlightteddates = None - if cp.has_option('calendar', 'highlighted-dates'): - self.highlighteddates = cp.get(section, 'highlighted-dates') + try: + self.highlighteddates = kwargs.pop('highlighteddates') + except KeyError: + self.highlighteddates = None - return super(IntervalTab, cls).from_ini(cp, section, *args, **kwargs) + self.span = span + super(IntervalTab, self).__init__(*args, **kwargs) def html_calendar(self): """Build the datepicker calendar for this tab. @@ -842,7 +826,7 @@ def html_calendar(self): % (self.path, requiredpath)) # format calendar return html.calendar(date, mode=self.mode, - highlighteddates=self.selecteddates) + highlighteddates=self.highlighteddates) def html_navbar(self, brand=None, calendar=True, **kwargs): """Build the navigation bar for this `Tab`. From c147007afcae3f9e60aeffc2b522a5e582abff21 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 12:26:54 +0100 Subject: [PATCH 08/31] Add option for highlighting available dates --- gwsumm/html/bootstrap.py | 7 +++++-- gwsumm/tabs/core.py | 26 ++++++++++++++++++-------- share/js/gwsumm.js | 22 ++++++++++++++++++---- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index 4b9ab358..43dc494e 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -77,7 +77,7 @@ class option for

def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', id_='calendar', dateformat=None, mode=None, - highlighteddates=None): + highlighteddates=None, highlightavailable=False): """Construct a bootstrap-datepicker calendar. Parameters @@ -114,7 +114,10 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', 'data-date-format': 'dd-mm-yyyy', 'data-viewmode': '%ss' % mode.name} if highlighteddates is not None: - attributekwargs['highlighted-dates'] = highlighteddates.replace('-', '') + attributekwargs['highlight-dates'] = highlighteddates.replace('-', '') + else: + if highlightavailable: + attributekwargs['highlight-available-dates'] = 'true' page.a(id_=id_, class_=class_, title='Show/hide calendar', **attributekwargs) page.add(datestring) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 285593d8..76f2b4b7 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -437,12 +437,17 @@ def from_ini(cls, cp, section) kwargs['duration'] = cp.getfloat(section, 'duration') # check for calendar dates to highlight - print(cp.has_option('calendar', 'highlighted-dates')) - if cp.has_option('calendar', 'highlighted-dates'): - try: - kwargs['highlighteddates'] - except KeyError: - kwargs['highlighteddates'] = cp.get('calendar', 'highlighted-dates') + if cp.has_section('calendar'): + if cp.has_option('calendar', 'highlighted-dates'): + try: + kwargs['highlighteddates'] + except KeyError: + kwargs['highlighteddates'] = cp.get('calendar', 'highlighted-dates') + elif cp.has_option('calendar', 'highlightavailable'): + try: + kwargs['highlightavailable'] + except KeyError: + kwargs['highlightavailable'] = cp.getboolean('calendar', 'highlight-available') return cls(name, *args, **kwargs) @@ -782,7 +787,6 @@ def end(self): class IntervalTab(GpsTab): """`Tab` defined within a GPS [start, end) interval """ - #def __init__(self, highlighteddates=None, *args, **kwargs): def __init__(self, *args, **kwargs): try: span = kwargs.pop('span') @@ -803,6 +807,11 @@ def __init__(self, *args, **kwargs): except KeyError: self.highlighteddates = None + try: + self.highlightavailable = kwargs.pop('highlightavailable') + except KeyError: + self.highlightavailable = False + self.span = span super(IntervalTab, self).__init__(*args, **kwargs) @@ -826,7 +835,8 @@ def html_calendar(self): % (self.path, requiredpath)) # format calendar return html.calendar(date, mode=self.mode, - highlighteddates=self.highlighteddates) + highlighteddates=self.highlighteddates, + highlightavailable=self.highlightavailable) def html_navbar(self, brand=None, calendar=True, **kwargs): """Build the navigation bar for this `Tab`. diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index 241fecf2..161aaaa8 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -193,11 +193,11 @@ $(window).load(function() { todayHighlight: true, todayBtn: "linked", beforeShowDay: function(date) { - // highlight selected dates if given - if ( document.getElementById('calendar').hasAttribute('highlighted-dates') ){ - var selected_dates = document.getElementById('calendar').getAttribute('highlighted-dates').split(','); + var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); + if ( document.getElementById('calendar').hasAttribute('highlight-dates') ){ + // highlight selected dates if given + var selected_dates = document.getElementById('calendar').getAttribute('highlight-dates').split(','); if (selected_dates.length > 0 ){ - var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); if ( selected_dates.indexOf(calendar_date) == -1 ){ // disable dates that are not given return {enabled: false, tooltip: 'Date not available'}; @@ -207,6 +207,20 @@ $(window).load(function() { } } } + else if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ) { + // highlight dates for which the URL exists (this is slow) + var cururl = window.location.href + var dateurl = cururl.slice(0, -9) + calendar_date; + var request = new XMLHttpRequest(); + request.open('HEAD', dateurl, false); + request.send() + if ( request.status == 404 ){ + return {enabled: false, tooltip: 'Date not available'}; + } + else { + return {classes: 'highlighted', enabled: true}; + } + } } }).on('changeDate', move_to_date); From 638975fdba58dfa8191e6bc4bfa2b4c251df032e Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 04:37:07 -0700 Subject: [PATCH 09/31] Minor fixes --- gwsumm/tabs/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 76f2b4b7..86f4d37f 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -443,11 +443,12 @@ def from_ini(cls, cp, section) kwargs['highlighteddates'] except KeyError: kwargs['highlighteddates'] = cp.get('calendar', 'highlighted-dates') - elif cp.has_option('calendar', 'highlightavailable'): + elif cp.has_option('calendar', 'highlight-available'): try: kwargs['highlightavailable'] except KeyError: kwargs['highlightavailable'] = cp.getboolean('calendar', 'highlight-available') + print(kwargs) return cls(name, *args, **kwargs) From a1951daa6039a2166964a5267e60798a2180c1c4 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 08:57:45 -0700 Subject: [PATCH 10/31] Add PHP directory lister --- bin/gw_summary | 7 +++++++ gwsumm/html/static.py | 4 ++++ gwsumm/tabs/core.py | 1 - setup.py | 8 ++++++++ share/js/gwsumm.js | 45 ++++++++++++++++++++++++++++++++--------- share/php/list-dirs.php | 4 ++++ 6 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 share/php/list-dirs.php diff --git a/bin/gw_summary b/bin/gw_summary index ae8b7241..3b451cca 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -47,6 +47,7 @@ import os import re import warnings from collections import OrderedDict +from shutil import copyfile from configparser import (DEFAULTSECT, NoOptionError, NoSectionError) try: from urllib.parse import urlparse @@ -556,6 +557,12 @@ for arch in archives: css = config.get_css(section='html') javascript = config.get_javascript(section='html') +# add PHP directory lister if required +if mode.is_calendar() and config.has_option("calendar", "highlight-available"): + phppath = os.path.join(opt.output_dir, os.path.split(mode.dir_format())[0]) + from ..html import PHP_LIST_DIRS + copyfile(PHP_LIST_DIRS, phppath) + # enable comments try: globalv.HTML_COMMENTS_NAME = config.get('html', 'disqus-shortname') diff --git a/gwsumm/html/static.py b/gwsumm/html/static.py index 5071f18e..7d0e436f 100644 --- a/gwsumm/html/static.py +++ b/gwsumm/html/static.py @@ -57,6 +57,9 @@ ('gwsumm', os.path.join(STATICDIR, 'gwsumm.min.css')), )) +# the PHP file to list directories +PHP_LIST_DIRS = os.path.join(STATICDIR, 'list-dirs.php') + # -- utilities ---------------------------------------------------------------- @@ -70,3 +73,4 @@ def get_js(): """Return a `dict` of javascript files to link in the HTML """ return JS + diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 86f4d37f..ee44c9b2 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -448,7 +448,6 @@ def from_ini(cls, cp, section) kwargs['highlightavailable'] except KeyError: kwargs['highlightavailable'] = cp.getboolean('calendar', 'highlight-available') - print(kwargs) return cls(name, *args, **kwargs) diff --git a/setup.py b/setup.py index e793b446..9cc5e060 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ import glob import os from distutils import log +from shutil import copyfile from setuptools import (Command, setup, find_packages) from setuptools.command.egg_info import egg_info @@ -178,9 +179,16 @@ def compile(self, source, target): f.write(css) log.info('%s CSS written to %s' % (self.output_style, target)) + def copy_php(self): + phpfile = os.path.join('share', 'php', 'list-dirs.php') + target = self.staticdir + copyfile(phpfile, target) + log.info('%s written to %s' % (phpfile, target) + def run(self): self.compile_sass() self.minify_js() + self.copy_php() if self.staticpackage not in self.distribution.packages: self.distribution.packages.append(self.staticpackage) log.info("added %s to package list" % self.staticpackage) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index 161aaaa8..d7399285 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -175,6 +175,23 @@ function shortenDate() { // When document is ready, run this stuff: $(window).load(function() { + // get directories if required + var date_directories = new Array(); + if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ){ + //var cururl = window.location.href; + var url = window.location.href.split('/'); + var geturl = url.slice(url.length-3, url.length-2).join('/') + '/list-dirs.php'; + console.log(geturl); + var request = new XMLHttpRequest(); + request.onload = function() { + if ( this.status != 404 ){ + date_directories = JSON.parse(this.responseText); + } + }; + request.open("GET", geturl, false); + request.send(); + } + console.log(date_directories); // shorten the date if ($('#calendar').length){ shortenDate();} @@ -209,16 +226,24 @@ $(window).load(function() { } else if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ) { // highlight dates for which the URL exists (this is slow) - var cururl = window.location.href - var dateurl = cururl.slice(0, -9) + calendar_date; - var request = new XMLHttpRequest(); - request.open('HEAD', dateurl, false); - request.send() - if ( request.status == 404 ){ - return {enabled: false, tooltip: 'Date not available'}; - } - else { - return {classes: 'highlighted', enabled: true}; + if ( date_directories.length > 0 ){ + if ( date_directories.indexOf(calendar_date) == -1 ){ + return {enabled: false, tooltip: 'Date not available'}; + } + else{ + return {classes: 'highlighted', enabled: true}; + } + //var cururl = window.location.href + //var dateurl = cururl.slice(0, -9) + calendar_date; + //var request = new XMLHttpRequest(); + //request.open('HEAD', dateurl, false); + //request.send() + //if ( request.status == 404 ){ + // return {enabled: false, tooltip: 'Date not available'}; + //} + //else { + // return {classes: 'highlighted', enabled: true}; + //} } } } diff --git a/share/php/list-dirs.php b/share/php/list-dirs.php new file mode 100644 index 00000000..c6d9d57c --- /dev/null +++ b/share/php/list-dirs.php @@ -0,0 +1,4 @@ + From 1a721be1dfc9a7685f78c1cdd095fbdec4db44b7 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Fri, 26 Apr 2019 09:11:50 -0700 Subject: [PATCH 11/31] Some fixes to setup.py --- bin/gw_summary | 3 ++- setup.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/gw_summary b/bin/gw_summary index 3b451cca..8b93cbf8 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -559,7 +559,8 @@ javascript = config.get_javascript(section='html') # add PHP directory lister if required if mode.is_calendar() and config.has_option("calendar", "highlight-available"): - phppath = os.path.join(opt.output_dir, os.path.split(mode.dir_format())[0]) + phppath = os.path.join(opt.output_dir, os.path.split(mode.dir_format())[0], + 'list-dirs.php') from ..html import PHP_LIST_DIRS copyfile(PHP_LIST_DIRS, phppath) diff --git a/setup.py b/setup.py index 9cc5e060..1613fa27 100644 --- a/setup.py +++ b/setup.py @@ -182,8 +182,8 @@ def compile(self, source, target): def copy_php(self): phpfile = os.path.join('share', 'php', 'list-dirs.php') target = self.staticdir - copyfile(phpfile, target) - log.info('%s written to %s' % (phpfile, target) + copyfile(phpfile, os.path.join(target, 'list-dirs.php')) + log.info('%s written to %s' % (phpfile, target)) def run(self): self.compile_sass() From 52e5f8374d5f27806a8f46f58b127cb2251dc6d8 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 20:57:14 +0100 Subject: [PATCH 12/31] Get rid of PHP and just create file listing the available directories using gw_summary --- bin/gw_summary | 16 +++++++++------- gwsumm/html/static.py | 3 --- setup.py | 8 -------- share/js/gwsumm.js | 38 +++++++++----------------------------- share/php/list-dirs.php | 4 ---- 5 files changed, 18 insertions(+), 51 deletions(-) delete mode 100644 share/php/list-dirs.php diff --git a/bin/gw_summary b/bin/gw_summary index 8b93cbf8..4594c739 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -458,6 +458,15 @@ os.chdir(opts.output_dir) plotdir = os.path.join(path, 'plots') mkdir(plotdir) +# add file containing a list of directories if required +if mode.is_calendar() and config.has_option("calendar", "highlight-available"): + # directory to list + dirpath = os.path.split(path)[:-1][0] + dirs = [dir for dir in os.listdir(dirpath) if os.path.isdir(dir)] + dirfile = os.path.join(os.path.split(path)[:-1][0], 'list-dirs.txt') + with open(dirfile, 'w') as fp: + fp.write(','.join(dirs)) + # ----------------------------------------------------------------------------- # Setup @@ -557,13 +566,6 @@ for arch in archives: css = config.get_css(section='html') javascript = config.get_javascript(section='html') -# add PHP directory lister if required -if mode.is_calendar() and config.has_option("calendar", "highlight-available"): - phppath = os.path.join(opt.output_dir, os.path.split(mode.dir_format())[0], - 'list-dirs.php') - from ..html import PHP_LIST_DIRS - copyfile(PHP_LIST_DIRS, phppath) - # enable comments try: globalv.HTML_COMMENTS_NAME = config.get('html', 'disqus-shortname') diff --git a/gwsumm/html/static.py b/gwsumm/html/static.py index 7d0e436f..2e477243 100644 --- a/gwsumm/html/static.py +++ b/gwsumm/html/static.py @@ -57,9 +57,6 @@ ('gwsumm', os.path.join(STATICDIR, 'gwsumm.min.css')), )) -# the PHP file to list directories -PHP_LIST_DIRS = os.path.join(STATICDIR, 'list-dirs.php') - # -- utilities ---------------------------------------------------------------- diff --git a/setup.py b/setup.py index 1613fa27..e793b446 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,6 @@ import glob import os from distutils import log -from shutil import copyfile from setuptools import (Command, setup, find_packages) from setuptools.command.egg_info import egg_info @@ -179,16 +178,9 @@ def compile(self, source, target): f.write(css) log.info('%s CSS written to %s' % (self.output_style, target)) - def copy_php(self): - phpfile = os.path.join('share', 'php', 'list-dirs.php') - target = self.staticdir - copyfile(phpfile, os.path.join(target, 'list-dirs.php')) - log.info('%s written to %s' % (phpfile, target)) - def run(self): self.compile_sass() self.minify_js() - self.copy_php() if self.staticpackage not in self.distribution.packages: self.distribution.packages.append(self.staticpackage) log.info("added %s to package list" % self.staticpackage) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index d7399285..449611e1 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -176,22 +176,22 @@ function shortenDate() { // When document is ready, run this stuff: $(window).load(function() { // get directories if required - var date_directories = new Array(); + var selected_dates = new Array(); if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ){ //var cururl = window.location.href; var url = window.location.href.split('/'); - var geturl = url.slice(url.length-3, url.length-2).join('/') + '/list-dirs.php'; + var geturl = url.slice(url.length-3, url.length-2).join('/') + '/list-dirs.txt'; console.log(geturl); var request = new XMLHttpRequest(); request.onload = function() { if ( this.status != 404 ){ - date_directories = JSON.parse(this.responseText); + selected_dates = this.responseText.split(','); } }; - request.open("GET", geturl, false); + request.open("GET", geturl, false); // use synchronous request request.send(); } - console.log(date_directories); + console.log(selected_dates); // shorten the date if ($('#calendar').length){ shortenDate();} @@ -211,9 +211,11 @@ $(window).load(function() { todayBtn: "linked", beforeShowDay: function(date) { var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); - if ( document.getElementById('calendar').hasAttribute('highlight-dates') ){ + if ( document.getElementById('calendar').hasAttribute('highlight-dates') || document.getElementById('calendar').hasAttribute('highlight-available-dates') ){ // highlight selected dates if given - var selected_dates = document.getElementById('calendar').getAttribute('highlight-dates').split(','); + if ( document.getElementById('calendar').hasAttribute('highlight-dates') ){ + selected_dates = document.getElementById('calendar').getAttribute('highlight-dates').split(','); + } if (selected_dates.length > 0 ){ if ( selected_dates.indexOf(calendar_date) == -1 ){ // disable dates that are not given @@ -224,28 +226,6 @@ $(window).load(function() { } } } - else if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ) { - // highlight dates for which the URL exists (this is slow) - if ( date_directories.length > 0 ){ - if ( date_directories.indexOf(calendar_date) == -1 ){ - return {enabled: false, tooltip: 'Date not available'}; - } - else{ - return {classes: 'highlighted', enabled: true}; - } - //var cururl = window.location.href - //var dateurl = cururl.slice(0, -9) + calendar_date; - //var request = new XMLHttpRequest(); - //request.open('HEAD', dateurl, false); - //request.send() - //if ( request.status == 404 ){ - // return {enabled: false, tooltip: 'Date not available'}; - //} - //else { - // return {classes: 'highlighted', enabled: true}; - //} - } - } } }).on('changeDate', move_to_date); diff --git a/share/php/list-dirs.php b/share/php/list-dirs.php deleted file mode 100644 index c6d9d57c..00000000 --- a/share/php/list-dirs.php +++ /dev/null @@ -1,4 +0,0 @@ - From d3b48051c6a923451ca0399c1554b4004203cb4e Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 13:22:13 -0700 Subject: [PATCH 13/31] Do not highlight today if highlighting selected dates --- bin/gw_summary | 10 ++++++---- share/js/gwsumm.js | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/gw_summary b/bin/gw_summary index 4594c739..115614e8 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -459,13 +459,15 @@ plotdir = os.path.join(path, 'plots') mkdir(plotdir) # add file containing a list of directories if required -if mode.is_calendar() and config.has_option("calendar", "highlight-available"): +if (mode.get_mode().is_calendar() and + config.has_option("calendar", "highlight-available")): # directory to list dirpath = os.path.split(path)[:-1][0] - dirs = [dir for dir in os.listdir(dirpath) if os.path.isdir(dir)] - dirfile = os.path.join(os.path.split(path)[:-1][0], 'list-dirs.txt') + datedirs = [thisdir for thisdir in os.listdir(dirpath) + if os.path.isdir(os.path.join(dirpath, thisdir))] + dirfile = os.path.join(dirpath, 'list-dirs.txt') with open(dirfile, 'w') as fp: - fp.write(','.join(dirs)) + fp.write(','.join(datedirs)) # ----------------------------------------------------------------------------- # Setup diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index 449611e1..deb9bcd3 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -191,7 +191,6 @@ $(window).load(function() { request.open("GET", geturl, false); // use synchronous request request.send(); } - console.log(selected_dates); // shorten the date if ($('#calendar').length){ shortenDate();} @@ -207,7 +206,7 @@ $(window).load(function() { $('#calendar').datepicker({ weekStart: 1, endDate: moment().utc().format('DD/MM/YYYY'), - todayHighlight: true, + todayHighlight: ( !document.getElementById('calendar').hasAttribute('highlight-available-dates') && !document.getElementById('calendar').hasAttribute('highlight-available-dates') ), todayBtn: "linked", beforeShowDay: function(date) { var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); From 319a1963ccf355ad39c70734cd44f745028780cd Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 13:26:11 -0700 Subject: [PATCH 14/31] gwsumm.js: minor fix --- share/js/gwsumm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index deb9bcd3..dc55700c 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -206,7 +206,7 @@ $(window).load(function() { $('#calendar').datepicker({ weekStart: 1, endDate: moment().utc().format('DD/MM/YYYY'), - todayHighlight: ( !document.getElementById('calendar').hasAttribute('highlight-available-dates') && !document.getElementById('calendar').hasAttribute('highlight-available-dates') ), + todayHighlight: ( !document.getElementById('calendar').hasAttribute('highlight-dates') && !document.getElementById('calendar').hasAttribute('highlight-available-dates') ), todayBtn: "linked", beforeShowDay: function(date) { var calendar_date = date.getUTCFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2); From d93b394904dabc3d07a841812685e6d4fc2438df Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 13:28:30 -0700 Subject: [PATCH 15/31] bootstrap.py: shorted to elif as suggested by @alurban --- gwsumm/html/bootstrap.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index 43dc494e..b542a00a 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -115,9 +115,8 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', 'data-viewmode': '%ss' % mode.name} if highlighteddates is not None: attributekwargs['highlight-dates'] = highlighteddates.replace('-', '') - else: - if highlightavailable: - attributekwargs['highlight-available-dates'] = 'true' + elif highlightavailable: + attributekwargs['highlight-available-dates'] = 'true' page.a(id_=id_, class_=class_, title='Show/hide calendar', **attributekwargs) page.add(datestring) From 16e0e22b3d1cf899e1cf5d4fb63724a7746b0cdd Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 13:31:15 -0700 Subject: [PATCH 16/31] core.py: swap try except for using default value from pop as suggested by @alurban --- gwsumm/tabs/core.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index ee44c9b2..81f3151a 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -802,15 +802,8 @@ def __init__(self, *args, **kwargs): else: span = (start, end) - try: - self.highlighteddates = kwargs.pop('highlighteddates') - except KeyError: - self.highlighteddates = None - - try: - self.highlightavailable = kwargs.pop('highlightavailable') - except KeyError: - self.highlightavailable = False + self.highlighteddates = kwargs.pop('highlighteddates', None) + self.highlightavailable = kwargs.pop('highlightavailable', False) self.span = span super(IntervalTab, self).__init__(*args, **kwargs) From 866afde789c893e542ec5677ece7e5b7529b690d Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 21:56:34 +0100 Subject: [PATCH 17/31] Update the unit test of calendar --- gwsumm/html/tests/test_bootstrap.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index 1c7e688b..d513fc06 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -31,7 +31,7 @@ # global variables DATE = datetime.strptime('20140410', '%Y%m%d') CALENDAR = """« - + {} @@ -51,16 +51,26 @@ def test_banner(): '

') -@pytest.mark.parametrize('mode, datefmt', [ - ('day', 'April 10 2014'), - ('week', 'Week of April 10 2014'), - ('month', 'April 2014'), - ('year', '2014'), +@pytest.mark.parametrize('mode, datefmt, highlighteddates, highlightavailable', [ + ('day', 'April 10 2014', '2014-04-10', False), + ('week', 'Week of April 10 2014', None, True), + ('month', 'April 2014', '20140410,20140412', False), + ('year', '2014', '20140410,20140412', True), ]) -def test_calendar(mode, datefmt): - cal = bootstrap.calendar(DATE, mode=mode) +def test_calendar(mode, datefmt, highlighteddates, highlightavailable): + cal = bootstrap.calendar(DATE, mode=mode, + highlighteddates=highlighteddates, + highlightavailable=highlightavailable) + hdcheck = "" + if highlighteddates is not None: + hdcheck = 'highlight-dates="{}"'.format(highlighteddates.replace('-', + '')) + hacheck = "" + if isinstance(highlightavailable, bool): + if highlightavailable: + hacheck = 'highlight-available="true"' assert parse_html(str(cal)) == parse_html(CALENDAR.format( - '%ss' % mode, datefmt)) + '%ss' % mode, datefmt, hdcheck, hacheck)) def test_calendar_no_mode(): From 01dcdeffe987da7dffe96cdc52095e3f2b2b6049 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Sat, 27 Apr 2019 14:10:38 -0700 Subject: [PATCH 18/31] test_bootstrap.py: fix calendar unit tests --- gwsumm/html/tests/test_bootstrap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index d513fc06..84fb8783 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -62,15 +62,15 @@ def test_calendar(mode, datefmt, highlighteddates, highlightavailable): highlighteddates=highlighteddates, highlightavailable=highlightavailable) hdcheck = "" + hacheck = "" if highlighteddates is not None: hdcheck = 'highlight-dates="{}"'.format(highlighteddates.replace('-', '')) - hacheck = "" - if isinstance(highlightavailable, bool): + elif isinstance(highlightavailable, bool): if highlightavailable: - hacheck = 'highlight-available="true"' + hacheck = 'highlight-available-dates="true"' assert parse_html(str(cal)) == parse_html(CALENDAR.format( - '%ss' % mode, datefmt, hdcheck, hacheck)) + '%ss' % mode, hdcheck, hacheck, datefmt)) def test_calendar_no_mode(): From b510807fd0cb863e88c2289122814029991ed007 Mon Sep 17 00:00:00 2001 From: Matt Pitkin Date: Sun, 28 Apr 2019 09:50:50 +0100 Subject: [PATCH 19/31] core.py: fix indent --- gwsumm/tabs/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 81f3151a..834a3227 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -802,8 +802,8 @@ def __init__(self, *args, **kwargs): else: span = (start, end) - self.highlighteddates = kwargs.pop('highlighteddates', None) - self.highlightavailable = kwargs.pop('highlightavailable', False) + self.highlighteddates = kwargs.pop('highlighteddates', None) + self.highlightavailable = kwargs.pop('highlightavailable', False) self.span = span super(IntervalTab, self).__init__(*args, **kwargs) From 8f88e879a258525882472fbd7e6fa39c970b45f6 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Mon, 29 Apr 2019 02:22:49 -0700 Subject: [PATCH 20/31] gwsumm.js: strip whitespace from date list, and remove unncessary console.log call --- share/js/gwsumm.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index dc55700c..e8a7f9db 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -181,11 +181,10 @@ $(window).load(function() { //var cururl = window.location.href; var url = window.location.href.split('/'); var geturl = url.slice(url.length-3, url.length-2).join('/') + '/list-dirs.txt'; - console.log(geturl); var request = new XMLHttpRequest(); request.onload = function() { if ( this.status != 404 ){ - selected_dates = this.responseText.split(','); + selected_dates = this.responseText.replace(/^\s+|\s+$/g, '').split(','); } }; request.open("GET", geturl, false); // use synchronous request From 3eb6ed4bb373d5aa8d37156db5b21dc771d1866c Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Mon, 29 Apr 2019 02:58:37 -0700 Subject: [PATCH 21/31] Make sure all tabs can see the file that lists date directories --- gwsumm/html/bootstrap.py | 5 ++++- share/js/gwsumm.js | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index b542a00a..0843bb93 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -116,7 +116,10 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', if highlighteddates is not None: attributekwargs['highlight-dates'] = highlighteddates.replace('-', '') elif highlightavailable: - attributekwargs['highlight-available-dates'] = 'true' + # set location of dates file + datefile = '{}/list-dirs.txt'.format( + os.path.split(mode.dir_format())[0]) + attributekwargs['highlight-available-dates'] = datefile page.a(id_=id_, class_=class_, title='Show/hide calendar', **attributekwargs) page.add(datestring) diff --git a/share/js/gwsumm.js b/share/js/gwsumm.js index e8a7f9db..c87a5dff 100644 --- a/share/js/gwsumm.js +++ b/share/js/gwsumm.js @@ -178,9 +178,7 @@ $(window).load(function() { // get directories if required var selected_dates = new Array(); if ( document.getElementById('calendar').hasAttribute('highlight-available-dates') ){ - //var cururl = window.location.href; - var url = window.location.href.split('/'); - var geturl = url.slice(url.length-3, url.length-2).join('/') + '/list-dirs.txt'; + var geturl = document.getElementById('calendar').getAttribute('highlight-available-dates'); var request = new XMLHttpRequest(); request.onload = function() { if ( this.status != 404 ){ From e7ce564792296fd5932b8ad1b1d4ab3b6db33b67 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Mon, 29 Apr 2019 05:08:41 -0700 Subject: [PATCH 22/31] Fix calendar test --- gwsumm/html/tests/test_bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index 84fb8783..4cbbbaf2 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -68,7 +68,7 @@ def test_calendar(mode, datefmt, highlighteddates, highlightavailable): '')) elif isinstance(highlightavailable, bool): if highlightavailable: - hacheck = 'highlight-available-dates="true"' + hacheck = 'highlight-available-dates="{}/list-dirs.txt"'.format(mode) assert parse_html(str(cal)) == parse_html(CALENDAR.format( '%ss' % mode, hdcheck, hacheck, datefmt)) From c97d4c179b1c43f19e8bd56b4b9ecf177f6b32f5 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Tue, 30 Apr 2019 15:27:17 -0700 Subject: [PATCH 23/31] gw_summary: make sure directories are sorted --- bin/gw_summary | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gw_summary b/bin/gw_summary index 115614e8..03806633 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -463,8 +463,8 @@ if (mode.get_mode().is_calendar() and config.has_option("calendar", "highlight-available")): # directory to list dirpath = os.path.split(path)[:-1][0] - datedirs = [thisdir for thisdir in os.listdir(dirpath) - if os.path.isdir(os.path.join(dirpath, thisdir))] + datedirs = sorted([thisdir for thisdir in os.listdir(dirpath) + if os.path.isdir(os.path.join(dirpath, thisdir))]) dirfile = os.path.join(dirpath, 'list-dirs.txt') with open(dirfile, 'w') as fp: fp.write(','.join(datedirs)) From 282a0587e7ab969f8edc2fea53482b50a1bd5b87 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 07:15:31 -0700 Subject: [PATCH 24/31] gw_summary: minor fix of directory listing --- bin/gw_summary | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/gw_summary b/bin/gw_summary index 03806633..2a816c8d 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -462,7 +462,7 @@ mkdir(plotdir) if (mode.get_mode().is_calendar() and config.has_option("calendar", "highlight-available")): # directory to list - dirpath = os.path.split(path)[:-1][0] + dirpath = os.path.split(path)[0] datedirs = sorted([thisdir for thisdir in os.listdir(dirpath) if os.path.isdir(os.path.join(dirpath, thisdir))]) dirfile = os.path.join(dirpath, 'list-dirs.txt') From 5ac29a15850667402444e9bbe8163aeb01fb6c62 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 21:07:54 +0100 Subject: [PATCH 25/31] static.py: Remove blank line --- gwsumm/html/static.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gwsumm/html/static.py b/gwsumm/html/static.py index 2e477243..5071f18e 100644 --- a/gwsumm/html/static.py +++ b/gwsumm/html/static.py @@ -70,4 +70,3 @@ def get_js(): """Return a `dict` of javascript files to link in the HTML """ return JS - From d0cebb9c5ae1c78673d966bd9a5f601efa65d610 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 21:10:09 +0100 Subject: [PATCH 26/31] test_bootstrap.py: minor formatting change --- gwsumm/html/tests/test_bootstrap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index 4cbbbaf2..0249f1ad 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -64,8 +64,8 @@ def test_calendar(mode, datefmt, highlighteddates, highlightavailable): hdcheck = "" hacheck = "" if highlighteddates is not None: - hdcheck = 'highlight-dates="{}"'.format(highlighteddates.replace('-', - '')) + hdcheck = 'highlight-dates="{}"'.format( + highlighteddates.replace('-', '')) elif isinstance(highlightavailable, bool): if highlightavailable: hacheck = 'highlight-available-dates="{}/list-dirs.txt"'.format(mode) From 83523c4b70eb1c01153fbb8e126a7417545998e2 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 21:33:47 +0100 Subject: [PATCH 27/31] Set the file containing the list of highlighted dates in the config parser --- bin/gw_summary | 1 + gwsumm/html/bootstrap.py | 17 ++++++++++++----- gwsumm/html/tests/test_bootstrap.py | 17 ++++++++--------- gwsumm/tabs/core.py | 16 +++++++++------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/bin/gw_summary b/bin/gw_summary index 2a816c8d..3e78ef6c 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -466,6 +466,7 @@ if (mode.get_mode().is_calendar() and datedirs = sorted([thisdir for thisdir in os.listdir(dirpath) if os.path.isdir(os.path.join(dirpath, thisdir))]) dirfile = os.path.join(dirpath, 'list-dirs.txt') + config.set('calendar', 'date-file', dirfile) with open(dirfile, 'w') as fp: fp.write(','.join(datedirs)) diff --git a/gwsumm/html/bootstrap.py b/gwsumm/html/bootstrap.py index 0843bb93..73f2ec87 100644 --- a/gwsumm/html/bootstrap.py +++ b/gwsumm/html/bootstrap.py @@ -77,7 +77,7 @@ class option for

def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', id_='calendar', dateformat=None, mode=None, - highlighteddates=None, highlightavailable=False): + highlighteddates=None, datefile=None): """Construct a bootstrap-datepicker calendar. Parameters @@ -86,6 +86,15 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', active date for the calendar tag : `str` type of enclosing HTML tag, default: ```` + highlighteddates: `str` + a string containing a comma seperated list of dates in the format + ``yyyymmdd`` or ``yyyy-mm-dd`` to highlight in the calendar. + Non-highlighted dates are disabled. + datefile: `str` + the name of a file containing a comma seperated list of dates in the + format ``yyyymmdd`` to highlight in the calendar. Non-highlighted dates + are disabled. The `highlighteddates` option takes precedence over this + one. Returns ------- @@ -115,10 +124,8 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle', 'data-viewmode': '%ss' % mode.name} if highlighteddates is not None: attributekwargs['highlight-dates'] = highlighteddates.replace('-', '') - elif highlightavailable: - # set location of dates file - datefile = '{}/list-dirs.txt'.format( - os.path.split(mode.dir_format())[0]) + elif datefile is not None: + # set location of the dates file attributekwargs['highlight-available-dates'] = datefile page.a(id_=id_, class_=class_, title='Show/hide calendar', **attributekwargs) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index 0249f1ad..bdafaa41 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -52,23 +52,22 @@ def test_banner(): '

Subtest

\n') @pytest.mark.parametrize('mode, datefmt, highlighteddates, highlightavailable', [ - ('day', 'April 10 2014', '2014-04-10', False), - ('week', 'Week of April 10 2014', None, True), - ('month', 'April 2014', '20140410,20140412', False), - ('year', '2014', '20140410,20140412', True), + ('day', 'April 10 2014', '2014-04-10', None), + ('week', 'Week of April 10 2014', None, 'list-dirs.txt'), + ('month', 'April 2014', '20140410,20140412', None), + ('year', '2014', '20140410,20140412', 'list-dirs.txt'), ]) -def test_calendar(mode, datefmt, highlighteddates, highlightavailable): +def test_calendar(mode, datefmt, highlighteddates, datefile): cal = bootstrap.calendar(DATE, mode=mode, highlighteddates=highlighteddates, - highlightavailable=highlightavailable) + datefile=datefile) hdcheck = "" hacheck = "" if highlighteddates is not None: hdcheck = 'highlight-dates="{}"'.format( highlighteddates.replace('-', '')) - elif isinstance(highlightavailable, bool): - if highlightavailable: - hacheck = 'highlight-available-dates="{}/list-dirs.txt"'.format(mode) + elif datefile is not None: + hacheck = 'highlight-available-dates="list-dirs.txt"' assert parse_html(str(cal)) == parse_html(CALENDAR.format( '%ss' % mode, hdcheck, hacheck, datefmt)) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index 834a3227..e2598052 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -443,11 +443,13 @@ def from_ini(cls, cp, section) kwargs['highlighteddates'] except KeyError: kwargs['highlighteddates'] = cp.get('calendar', 'highlighted-dates') - elif cp.has_option('calendar', 'highlight-available'): - try: - kwargs['highlightavailable'] - except KeyError: - kwargs['highlightavailable'] = cp.getboolean('calendar', 'highlight-available') + elif (cp.has_option('calendar', 'highlight-available') and + cp.has_option('calendar', 'date-file')): + if cp.getboolean('calendar', 'highlight-available'): + try: + kwargs['datefile'] + except KeyError: + kwargs['datefile'] = cp.get('calendar', 'date-file') return cls(name, *args, **kwargs) @@ -803,7 +805,7 @@ def __init__(self, *args, **kwargs): span = (start, end) self.highlighteddates = kwargs.pop('highlighteddates', None) - self.highlightavailable = kwargs.pop('highlightavailable', False) + self.datefile = kwargs.pop('datafile', None) self.span = span super(IntervalTab, self).__init__(*args, **kwargs) @@ -829,7 +831,7 @@ def html_calendar(self): # format calendar return html.calendar(date, mode=self.mode, highlighteddates=self.highlighteddates, - highlightavailable=self.highlightavailable) + datefile=self.datefile) def html_navbar(self, brand=None, calendar=True, **kwargs): """Build the navigation bar for this `Tab`. From 19dd9f8c62ebd7be6d746818c4d459c9ae74c7f2 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 13:42:02 -0700 Subject: [PATCH 28/31] test_bootstrap.py: fix test_calendar --- gwsumm/html/tests/test_bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gwsumm/html/tests/test_bootstrap.py b/gwsumm/html/tests/test_bootstrap.py index bdafaa41..438588b9 100644 --- a/gwsumm/html/tests/test_bootstrap.py +++ b/gwsumm/html/tests/test_bootstrap.py @@ -51,7 +51,7 @@ def test_banner(): '') -@pytest.mark.parametrize('mode, datefmt, highlighteddates, highlightavailable', [ +@pytest.mark.parametrize('mode, datefmt, highlighteddates, datefile', [ ('day', 'April 10 2014', '2014-04-10', None), ('week', 'Week of April 10 2014', None, 'list-dirs.txt'), ('month', 'April 2014', '20140410,20140412', None), From 1dfeae707aa409e20703eaab15d5e0dcd2cc8c3e Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Wed, 1 May 2019 13:48:08 -0700 Subject: [PATCH 29/31] core.py: fix typo --- gwsumm/tabs/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gwsumm/tabs/core.py b/gwsumm/tabs/core.py index e2598052..53b03290 100644 --- a/gwsumm/tabs/core.py +++ b/gwsumm/tabs/core.py @@ -805,7 +805,7 @@ def __init__(self, *args, **kwargs): span = (start, end) self.highlighteddates = kwargs.pop('highlighteddates', None) - self.datefile = kwargs.pop('datafile', None) + self.datefile = kwargs.pop('datefile', None) self.span = span super(IntervalTab, self).__init__(*args, **kwargs) From 60261eebbb6803371c63155fe9e9f6e075bdff6d Mon Sep 17 00:00:00 2001 From: "Alex L. Urban" Date: Thu, 2 May 2019 09:20:25 +0100 Subject: [PATCH 30/31] Update bin/gw_summary Co-Authored-By: mattpitkin --- bin/gw_summary | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/gw_summary b/bin/gw_summary index 3e78ef6c..b322abeb 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -47,7 +47,6 @@ import os import re import warnings from collections import OrderedDict -from shutil import copyfile from configparser import (DEFAULTSECT, NoOptionError, NoSectionError) try: from urllib.parse import urlparse From 224cbefea02e0acf02d44cbe33de86d7125fcc35 Mon Sep 17 00:00:00 2001 From: Matthew Pitkin Date: Thu, 2 May 2019 09:42:24 +0100 Subject: [PATCH 31/31] gw_summary: check if config already contains a date-file --- bin/gw_summary | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/gw_summary b/bin/gw_summary index b322abeb..bbef59ee 100644 --- a/bin/gw_summary +++ b/bin/gw_summary @@ -465,9 +465,16 @@ if (mode.get_mode().is_calendar() and datedirs = sorted([thisdir for thisdir in os.listdir(dirpath) if os.path.isdir(os.path.join(dirpath, thisdir))]) dirfile = os.path.join(dirpath, 'list-dirs.txt') - config.set('calendar', 'date-file', dirfile) - with open(dirfile, 'w') as fp: - fp.write(','.join(datedirs)) + if not config.has_option('calendar', 'date-file'): + config.set('calendar', 'date-file') + with open(dirfile, 'w') as fp: + fp.write(','.join(datedirs)) + else: + if not os.path.isfile(config.get('calendar', 'date-file')): + raise parser.error("The file '{}' supplied to 'date-file' in the " + "[calendar] section option does not " + "exist.".format(config.get('calendar', + 'date-file'))) # ----------------------------------------------------------------------------- # Setup