Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight certain dates in the calendar datepicker #259

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1608805
gwsumm.js: allow highlighting of selected dates
mattpitkin Apr 25, 2019
b86dd26
bootstrap.py: allow calendar to take selected dates
mattpitkin Apr 25, 2019
494feef
gwsumm.js: only add selected dates if array length is greater than 0
mattpitkin Apr 25, 2019
ce7c087
core.py: attempt to parse selected dates from calendar ini file section
mattpitkin Apr 25, 2019
8704e18
Some changes to the highlighted dates option
mattpitkin Apr 26, 2019
b4ec533
core.py: fix typo
mattpitkin Apr 26, 2019
6e4d7d9
a variety of fixes
mattpitkin Apr 26, 2019
c147007
Add option for highlighting available dates
mattpitkin Apr 26, 2019
638975f
Minor fixes
mattpitkin Apr 26, 2019
a1951da
Add PHP directory lister
mattpitkin Apr 26, 2019
1a721be
Some fixes to setup.py
mattpitkin Apr 26, 2019
52e5f83
Get rid of PHP and just create file listing the available directories…
mattpitkin Apr 27, 2019
d3b4805
Do not highlight today if highlighting selected dates
mattpitkin Apr 27, 2019
319a196
gwsumm.js: minor fix
mattpitkin Apr 27, 2019
d93b394
bootstrap.py: shorted to elif as suggested by @alurban
mattpitkin Apr 27, 2019
16e0e22
core.py: swap try except for using default value from pop as suggeste…
mattpitkin Apr 27, 2019
866afde
Update the unit test of calendar
mattpitkin Apr 27, 2019
01dcdef
test_bootstrap.py: fix calendar unit tests
mattpitkin Apr 27, 2019
b510807
core.py: fix indent
mattpitkin Apr 28, 2019
8f88e87
gwsumm.js: strip whitespace from date list, and remove unncessary con…
mattpitkin Apr 29, 2019
3eb6ed4
Make sure all tabs can see the file that lists date directories
mattpitkin Apr 29, 2019
e7ce564
Fix calendar test
mattpitkin Apr 29, 2019
c97d4c1
gw_summary: make sure directories are sorted
mattpitkin Apr 30, 2019
282a058
gw_summary: minor fix of directory listing
mattpitkin May 1, 2019
5ac29a1
static.py: Remove blank line
mattpitkin May 1, 2019
d0cebb9
test_bootstrap.py: minor formatting change
mattpitkin May 1, 2019
83523c4
Set the file containing the list of highlighted dates in the config p…
mattpitkin May 1, 2019
19dd9f8
test_bootstrap.py: fix test_calendar
mattpitkin May 1, 2019
1dfeae7
core.py: fix typo
mattpitkin May 1, 2019
60261ee
Update bin/gw_summary
May 2, 2019
224cbef
gw_summary: check if config already contains a date-file
mattpitkin May 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions gwsumm/html/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class option for <p>


def calendar(date, tag='a', class_='navbar-brand dropdown-toggle',
id_='calendar', dateformat=None, mode=None):
id_='calendar', dateformat=None, mode=None,
highlighteddates=None, highlightavailable=False):
"""Construct a bootstrap-datepicker calendar.

Parameters
Expand Down Expand Up @@ -109,9 +110,16 @@ def calendar(date, tag='a', class_='navbar-brand dropdown-toggle',
page = markup.page()
page.a('&laquo;', 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['highlight-dates'] = highlighteddates.replace('-', '')
else:
mattpitkin marked this conversation as resolved.
Show resolved Hide resolved
if highlightavailable:
attributekwargs['highlight-available-dates'] = 'true'
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})
**attributekwargs)
page.add(datestring)
page.b('', class_='caret')
page.a.close()
Expand Down
29 changes: 28 additions & 1 deletion gwsumm/tabs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@ def from_ini(cls, cp, section)
except KeyError:
kwargs['duration'] = cp.getfloat(section, 'duration')

# check for calendar dates to highlight
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', 'highlight-available'):
try:
kwargs['highlightavailable']
except KeyError:
kwargs['highlightavailable'] = cp.getboolean('calendar', 'highlight-available')
print(kwargs)
mattpitkin marked this conversation as resolved.
Show resolved Hide resolved

return cls(name, *args, **kwargs)

# -- HTML operations ------------------------
Expand Down Expand Up @@ -788,6 +802,17 @@ def __init__(self, *args, **kwargs):
% (type(self).__name__, mode))
else:
span = (start, end)

try:
mattpitkin marked this conversation as resolved.
Show resolved Hide resolved
self.highlighteddates = kwargs.pop('highlighteddates')
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)

Expand All @@ -810,7 +835,9 @@ 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,
highlighteddates=self.highlighteddates,
highlightavailable=self.highlightavailable)

def html_navbar(self, brand=None, calendar=True, **kwargs):
"""Build the navigation bar for this `Tab`.
Expand Down
32 changes: 31 additions & 1 deletion share/js/gwsumm.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,37 @@ $(window).load(function() {
weekStart: 1,
endDate: moment().utc().format('DD/MM/YYYY'),
todayHighlight: true,
todayBtn: "linked"
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') ){
// highlight selected dates if given
var 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
return {enabled: false, tooltip: 'Date not available'};
}
else{
return {classes: 'highlighted', enabled: true};
}
}
}
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);

// load correct run type
Expand Down