Skip to content

Commit

Permalink
Updates for Tethys 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
swainn committed Jan 20, 2023
1 parent 41916d2 commit 35bb0c8
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 101 deletions.
6 changes: 5 additions & 1 deletion install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file should be committed to your app code.
version: 1.0
# This should be greater or equal to your tethys-platform in your environment
tethys_version: ">=4.0.0"
# This should match the app - package name in your setup.py
name: earth_engine

Expand All @@ -14,4 +16,6 @@ requirements:
- oauth2client
pip:

post:
npm:

post:
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from setuptools import setup, find_namespace_packages
from tethys_apps.app_installation import find_resource_files
from tethys_apps.app_installation import find_all_resource_files
from tethys_apps.base.app_base import TethysAppBase

# -- Apps Definition -- #
app_package = 'earth_engine'
release_package = 'tethysapp-' + app_package
release_package = f'{TethysAppBase.package_namespace}-{app_package}'

# -- Python Dependencies -- #
dependencies = []

# -- Get Resource File -- #
resource_files = find_resource_files('tethysapp/' + app_package + '/templates', 'tethysapp/' + app_package)
resource_files += find_resource_files('tethysapp/' + app_package + '/public', 'tethysapp/' + app_package)
resource_files = find_all_resource_files(app_package, TethysAppBase.package_namespace)


setup(
Expand Down
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Included for native namespace package support
# Included for native namespace package support
30 changes: 7 additions & 23 deletions tethysapp/earth_engine/app.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
from tethys_sdk.base import TethysAppBase, url_map_maker
from tethys_sdk.base import TethysAppBase


class EarthEngine(TethysAppBase):
"""
Tethys app class for Earth Engine.
"""

name = 'Earth Engine'
index = 'earth_engine:home'
icon = 'earth_engine/images/earth-engine-logo.png'
package = 'earth_engine'
name = 'Google Earth Engine Tutorial'
description = ''
package = 'earth_engine' # WARNING: Do not change this value
index = 'home'
icon = f'{package}/images/earth-engine-logo.png'
root_url = 'earth-engine'
color = '#524745'
description = ''
tags = ''
enable_feedback = False
feedback_emails = []

def url_maps(self):
"""
Add controllers
"""
UrlMap = url_map_maker(self.root_url)

url_maps = (
UrlMap(
name='home',
url='earth-engine',
controller='earth_engine.controllers.home'
),
)

return url_maps
feedback_emails = []
9 changes: 5 additions & 4 deletions tethysapp/earth_engine/controllers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime as dt
from django.shortcuts import render
from tethys_sdk.permissions import login_required
from tethys_sdk.gizmos import SelectInput, DatePicker, Button, MapView, MVView
from tethys_sdk.routing import controller
from tethys_sdk.gizmos import SelectInput, DatePicker, Button
from tethys_sdk.gizmos import MapView, MVView
from .gee.products import EE_PRODUCTS


@login_required()
@controller
def home(request):
"""
Controller for the app home page.
Expand Down Expand Up @@ -112,7 +113,7 @@ def home(request):
load_button = Button(
name='load_map',
display_text='Load',
style='default',
style='outline-secondary',
attributes={'id': 'load_map'}
)

Expand Down
3 changes: 0 additions & 3 deletions tethysapp/earth_engine/handoff.py

This file was deleted.

2 changes: 1 addition & 1 deletion tethysapp/earth_engine/public/css/main.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Remove padding on bottom where app-actions section used to be */
#app-content-wrapper #app-content {
padding-bottom: 0;
}
}
2 changes: 1 addition & 1 deletion tethysapp/earth_engine/public/css/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#inner-app-content {
height: 100%;
padding: 0;
}
}
Binary file removed tethysapp/earth_engine/public/images/icon.gif
Binary file not shown.
32 changes: 15 additions & 17 deletions tethysapp/earth_engine/public/js/gee_datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var GEE_DATASETS = (function() {
}
});


$('#start_date').on('change', function() {
let start_date = $('#start_date').val();

Expand Down Expand Up @@ -104,10 +103,10 @@ var GEE_DATASETS = (function() {
if (!m_platform in EE_PRODUCTS) {
alert('Unknown platform selected.');
}

// Clear sensor options
$('#sensor').select2().empty();

// Set the Sensor Options
let first_option = true;
for (var sensor in EE_PRODUCTS[m_platform]) {
Expand All @@ -116,7 +115,7 @@ var GEE_DATASETS = (function() {
$('#sensor').append(new_option);
first_option = false;
}

// Trigger a sensor change event to update select box
$('#sensor').trigger('change');
update_date_bounds();
Expand All @@ -126,20 +125,20 @@ var GEE_DATASETS = (function() {
if (!m_platform in EE_PRODUCTS || !m_sensor in EE_PRODUCTS[m_platform]) {
alert('Unknown platform or sensor selected.');
}

// Clear product options
$('#product').select2().empty();

let first_option = true;

// Set the Product Options
for (var product in EE_PRODUCTS[m_platform][m_sensor]) {
let product_display_name = EE_PRODUCTS[m_platform][m_sensor][product]['display'];
let new_option = new Option(product_display_name, product, first_option, first_option);
$('#product').append(new_option);
first_option = false;
}

// Trigger a product change event to update select box
$('#product').trigger('change');
update_date_bounds();
Expand All @@ -149,40 +148,40 @@ var GEE_DATASETS = (function() {
// Get new date picker bounds for the current product
let earliest_valid_date = EE_PRODUCTS[m_platform][m_sensor][m_product]['start_date'];
let latest_valid_date = EE_PRODUCTS[m_platform][m_sensor][m_product]['end_date'];

// Get current values of date pickers
let current_start_date = $('#start_date').val();
let current_end_date = $('#end_date').val();

// Convert to Dates objects for comparison
let date_evd = Date.parse(earliest_valid_date);
let date_lvd = Date.parse(latest_valid_date) ? (latest_valid_date) : Date.now();
let date_csd = Date.parse(current_start_date);
let date_ced = Date.parse(current_end_date);

// Don't reset currently selected dates if they fall within the new date range
let reset_current_dates = true;

if (date_csd >= date_evd && date_csd <= date_lvd && date_ced >= date_evd && date_ced <= date_lvd) {
reset_current_dates = false;
}

// Update start date datepicker bounds
$('#start_date').datepicker('setStartDate', earliest_valid_date);
$('#start_date').datepicker('setEndDate', latest_valid_date);
if (reset_current_dates) {
$('#start_date').datepicker('update', INITIAL_START_DATE);
m_start_date = INITIAL_START_DATE;
}

// Update end date datepicker bounds
$('#end_date').datepicker('setStartDate', earliest_valid_date);
$('#end_date').datepicker('setEndDate', latest_valid_date);
if (reset_current_dates) {
$('#end_date').datepicker('update', INITIAL_END_DATE);
m_end_date = INITIAL_END_DATE;
}

console.log('Date Bounds Changed To: ' + earliest_valid_date + ' - ' + latest_valid_date);
};

Expand All @@ -198,7 +197,6 @@ var GEE_DATASETS = (function() {
return data;
};


/************************************************************************
* PUBLIC INTERFACE
*************************************************************************/
Expand All @@ -225,4 +223,4 @@ var GEE_DATASETS = (function() {

return public_interface;

}()); // End of package wrapper
}()); // End of package wrapper
20 changes: 10 additions & 10 deletions tethysapp/earth_engine/templates/earth_engine/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
{% block app_title %}{{ tethys_app.name }}{% endblock %}

{% block app_navigation_items %}
<li class="title">App Navigation</li>
<li class="active"><a href="">Home</a></li>
<li><a href="">Jobs</a></li>
<li><a href="">Results</a></li>
<li class="title">Steps</li>
<li><a href="">1. The First Step</a></li>
<li><a href="">2. The Second Step</a></li>
<li><a href="">3. The Third Step</a></li>
<li class="separator"></li>
<li><a href="">Get Started</a></li>
<li class="nav-item title">App Navigation</li>
<li class="nav-item active"><a class="nav-link" href="">Home</a></li>
<li class="nav-item"><a class="nav-link" href="">Jobs</a></li>
<li class="nav-item"><a class="nav-link" href="">Results</a></li>
<li class="nav-item title">Steps</li>
<li class="nav-item"><a class="nav-link" href="">1. The First Step</a></li>
<li class="nav-item"><a class="nav-link" href="">2. The Second Step</a></li>
<li class="nav-item"><a class="nav-link" href="">3. The Third Step</a></li>
<li class="nav-item separator"></li>
<li class="nav-item"><a class="nav-link" href="">Get Started</a></li>
{% endblock %}

{% block app_content %}
Expand Down
10 changes: 5 additions & 5 deletions tethysapp/earth_engine/templates/earth_engine/home.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{% extends "earth_engine/base.html" %}
{% load tethys_gizmos static %}

{% block content_dependent_styles %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'earth_engine/css/map.css' %}" />
{% endblock %}

{% block app_navigation_items %}
<li class="title">Select Dataset</li>
{% gizmo platform_select %}
Expand All @@ -31,3 +26,8 @@
{{ block.super }}
<script src="{% static 'earth_engine/js/gee_datasets.js' %}" type="text/javascript"></script>
{% endblock %}

{% block content_dependent_styles %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'earth_engine/css/map.css' %}" />
{% endblock %}
44 changes: 13 additions & 31 deletions tethysapp/earth_engine/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# Most of your test classes should inherit from TethysTestCase
from tethys_sdk.testing import TethysTestCase

# Use if your app has persistent stores that will be tested against.
# Your app class from app.py must be passed as an argument to the TethysTestCase functions to both
# create and destroy the temporary persistent stores for your app used during testing
# from ..app import EarthEngine

# Use if you'd like a simplified way to test rendered HTML templates.
# You likely need to install BeautifulSoup, as it is not included by default in Tethys Platform
# 1. Open a terminal
# 2. Enter command ". /usr/lib/tethys/bin/activate" to activate the Tethys python environment
# 3. Enter command "pip install beautifulsoup4"
# For help, see https://www.crummy.com/software/BeautifulSoup/bs4/doc/
# For testing rendered HTML templates it may be helpful to use BeautifulSoup.
# from bs4 import BeautifulSoup
# For help, see https://www.crummy.com/software/BeautifulSoup/bs4/doc/


"""
To run any tests:
1. Open a terminal
2. Enter command ". /usr/lib/tethys/bin/activate" to activate the Tethys python environment
3. In portal_config.yml make sure that the default database user is set to tethys_super or is a super user of the database
To run tests for an app:
1. Open a terminal and activate the Tethys environment::
conda activate tethys
2. In portal_config.yml make sure that the default database user is set to tethys_super or is a super user of the database
DATABASES:
default:
ENGINE: django.db.backends.postgresql_psycopg2
Expand All @@ -28,28 +23,15 @@
HOST: 127.0.0.1
PORT: 5435
4. Enter tethys test command.
The general form is: "tethys test -f tethys_apps.tethysapp.<app_name>.<folder_name>.<file_name>.<class_name>.<function_name>"
See below for specific examples
To run all tests across this app:
Test command: "tethys test -f tethys_apps.tethysapp.earth_engine"
3. From the root directory of your app, run the ``tethys manage test`` command::
To run all tests in this file:
Test command: "tethys test -f tethys_apps.tethysapp.earth_engine.tests.tests"
tethys manage test tethysapp/<app_name>/tests
To run tests in the EarthEngineTestCase class:
Test command: "tethys test -f tethys_apps.tethysapp.earth_engine.tests.tests.EarthEngineTestCase"
To run only the test_if_tethys_platform_is_great function in the EarthEngineTestCase class:
Test command: "tethys test -f tethys_apps.tethysapp.earth_engine.tests.tests.EarthEngineTestCase.test_if_tethys_platform_is_great"
To learn more about writing tests, see:
https://docs.djangoproject.com/en/1.9/topics/testing/overview/#writing-tests
https://docs.python.org/2.7/library/unittest.html#module-unittest
https://docs.tethysplatform.org/en/stable/tethys_sdk/testing.html
"""


class EarthEngineTestCase(TethysTestCase):
"""
In this class you may define as many functions as you'd like to test different aspects of your app.
Expand Down

0 comments on commit 35bb0c8

Please sign in to comment.