Commit b764c982 authored by Bruce Flynn's avatar Bruce Flynn

HTML changes to support station dates.

Squashed commit of the following:

commit 7e0790b9
Author: Bruce Flynn <brucef@ssec.wisc.edu>
Date:   Sat Feb 11 11:08:09 2017 -0600

    new HTML working

commit 2907d5f0
Merge: 42ca0512 5aeea703
Author: Bruce Flynn <brucef@ssec.wisc.edu>
Date:   Fri Feb 10 15:09:05 2017 -0600

    Merge branch 'master' into webform

commit 42ca0512
Merge: 638b3ff2 c273fc68
Author: Bruce Flynn <brucef@ssec.wisc.edu>
Date:   Fri Feb 10 15:08:22 2017 -0600

    Merge branch 'webform' of https://gitlab.ssec.wisc.edu/brucef/AmrcAws into webform

commit 638b3ff2
Author: Bruce Flynn <brucef@ssec.wisc.edu>
Date:   Mon Jan 23 08:11:30 2017 -0600

    Working on new web form.

commit c273fc68
Author: Bruce Flynn <brucef@ssec.wisc.edu>
Date:   Mon Jan 23 08:11:30 2017 -0600

    Working on new web form.
parent 5aeea703
root = True
[*]
end_of_line = lf
insert_final_newline = true
[*.py]
indent_style = space
indent = 4
[*.js]
indent_style = space
indent = 2
\ No newline at end of file
......@@ -2,8 +2,15 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.6.0 (~/code/AmrcAws/env/bin/python3.6)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 2.7.13 (~/code/AmrcAws/env/bin/python)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="backbone" level="application" />
<orderEntry type="library" name="underscore" level="application" />
<orderEntry type="library" name="jquery" level="application" />
<orderEntry type="library" name="moment" level="application" />
<orderEntry type="library" name="bootstrap" level="application" />
<orderEntry type="library" name="bootstrap-datepicker" level="application" />
<orderEntry type="library" name="bootstrap-datetimepicker" level="application" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Chameleon" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="PROJECT" libraries="{backbone, bootstrap, bootstrap-datepicker, bootstrap-datetimepicker, jquery, moment, underscore}" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6.0 (~/code/AmrcAws/env/bin/python3.6)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.13 (~/code/AmrcAws/env/bin/python)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
MIT License
Copyright (c) 2017 UW SSEC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -55,5 +55,9 @@ def main():
except (db.IntegrityError, exc.ParseError, ValueError) as err:
LOG.warning('File insert failed(%s): %s', filepath, err.__class__.__name__)
LOG.info('updating station dates')
db.refresh_station_dates()
if __name__ == '__main__':
main()
......@@ -26,7 +26,7 @@ debugtoolbar.hosts = 0.0.0.0/0
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 8888
port = 5010
###
# logging configuration
......
version: "2"
services:
http:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./data:/usr/share/nginx/html:ro
ports:
- 8080:80
db:
environment:
- POSTGRES_USER=docker
......
$(function () {
'use strict';
// Change this to point to the location of the API
var API_URL_BASE = 'http://localhost:5010';
function apiUrl(part, params) {
var qs = params ? $.param(params) : '';
var url = API_URL_BASE + part + '?' + qs;
console.debug(url);
return url;
}
// Default values for the start and end pickers
var defaultStart = moment.utc().subtract(1, 'year'),
defaultEnd = moment.utc();
var dateFormat = 'YYYY-MM-DD';
// selected values
var form = {
start: defaultStart,
end: defaultEnd,
symbols: [],
stations: [],
output: 'nc',
type: 'q1h'
};
var $stations = $('select#stations');
var $symbols = $('select#symbols');
var $form = $('form');
var $start = $('#start-picker');
var $end = $('#end-picker');
// initialize the start/end datepicker-s
var opts = {
format: dateFormat,
allowInputToggle: true,
maxDate: moment.utc(),
minDate: moment.utc('1980-01-01')
};
$start.datetimepicker(opts);
$start.data('DateTimePicker').date(defaultStart);
$end.datetimepicker(opts);
$end.data('DateTimePicker').date(defaultEnd);
// Setup event handlers
// handle the datepicker changes same as form changes
$start.on('dp.change', formChanged);
$end.on('dp.change', formChanged);
$form.on('change', formChanged);
// handle when the form is submitted
$form.on('submit', submit);
// fetch stations from server based on selected dates and use values
// to reset station select box
function refreshStations() {
if (!form.start.isValid() || !form.end.isValid()) {
return;
}
// remove all existing stations
$stations.find('option').remove();
var params = {
start: form.start.format(dateFormat),
end: form.end.format(dateFormat)
};
$.get(apiUrl('/stations.json', params), function (stations) {
if (stations.length) {
$('#stations-alert').hide(100);
} else {
$('#stations-alert').show(100);
}
var selected = $stations.val();
_.forEach(stations, function (station_name) {
var $opt = $('<option/>').text(station_name);
if (_.contains(station_name, selected)) {
$opt.attr('selected', true);
}
$stations.append($opt);
});
});
}
// Sync internal form state with what's selected.
// start/end are handled separately
function formChanged() {
// only set start/end if the values are valid
var dateChanged = false;
var value = $start.data('DateTimePicker').date();
if (value.isValid() && !form.start.isSame(value)) {
console.debug('start changed', value.format());
form.start = value;
dateChanged = true;
}
var value = $end.data('DateTimePicker').date();
if (value.isValid() && !form.end.isSame(value)) {
console.debug('end changed', value.format());
form.end = value;
dateChanged = true;
}
if (dateChanged) {
// refresh stations for every form change
refreshStations();
}
// the following values are always valid becasue they're not based
// user input
form.output = $('input[name=output]:checked').val();
form.type = $('input[name=type]:checked').val();
form.stations = $stations.val();
form.symbols = $symbols.val();
// only enable the submit button if the form is valid
if (formValid()) {
$('button[type=submit]').prop('disabled', false);
} else {
$('button[type=submit]').prop('disabled', true);
}
}
function formValid() {
return (
form.start.isValid() &&
form.end.isValid() &&
form.stations.length > 0 &&
form.symbols.length > 0
);
}
// construct current API URL and redirect to API
function submit(event) {
event.preventDefault();
var params = {
stations: form.stations.join('|'),
symbols: form.symbols.join('|'),
start: form.start.format(dateFormat) + 'T00:00:00Z',
end: form.end.format(dateFormat) + 'T23:59:59Z',
type: form.type,
};
// causes page to reload to provided API URL
window.location = apiUrl('/data.' + form.output, params);
}
$(document).ready(refreshStations);
});
This diff is collapsed.
......@@ -5,6 +5,7 @@ setup(
name='AmrcAws',
author='Bruce Flynn',
author_email='brucef@ssec.wisc.edu',
license='MIT License',
url='https://gitlab.ssec.wisc.edu/brucef/AmrcAws',
packages=find_packages(),
include_package_data=True,
......@@ -38,6 +39,5 @@ setup(
[console_scripts]
file_insert = amrc_aws.cli.file_insert:main
batch_insert = amrc_aws.cli.batch_insert:main
refresh_stations = amrc_aws.cli.batch_insert:main
""",
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment