Added a tab for the license in the help.

master
Pacman Ghost 6 years ago
parent c497c97721
commit e9393aac91
  1. 3
      setup.py
  2. 31
      vasl_templates/webapp/main.py
  3. 9
      vasl_templates/webapp/static/help/index.html
  4. 4
      vasl_templates/webapp/static/help/main.css
  5. 19
      vasl_templates/webapp/static/help/main.js
  6. 25
      vasl_templates/webapp/tests/test_help.py

@ -32,6 +32,9 @@ setup(
],
},
include_package_data = True,
data_files = [
( "vasl-templates", ["LICENSE.txt"] ),
],
entry_points = {
"console_scripts": "vasl-templates = vasl_templates.main:main",
}

@ -3,7 +3,7 @@
import os
import json
from flask import request, render_template, jsonify, redirect, url_for
from flask import request, render_template, jsonify, send_file, redirect, url_for, abort
from vasl_templates.webapp import app
from vasl_templates.webapp.config.constants import DATA_DIR
@ -31,6 +31,35 @@ def show_help():
# ---------------------------------------------------------------------
@app.route( "/license" )
def get_license():
"""Get the license."""
# locate the license file
dname = os.path.split( __file__ )[0]
fname = os.path.join( dname, "../../LICENSE.txt" ) # nb: if we're running from source
if not os.path.isfile( fname ):
fname = os.path.join( dname, "../../../LICENSE.txt" ) # nb: if we're running as a compiled binary
if not os.path.isfile( fname ):
# FUDGE! If we've been pip install'ed walk up the directory tree, looking for the license file :-/
dname = os.path.split( fname )[0]
while True:
# go up a directory
prev_dname = dname
dname = os.path.split( dname )[0]
if dname == prev_dname:
break
# check if we can find the license file
fname = os.path.join( dname, "vasl-templates/LICENSE.txt" )
if os.path.isfile( fname ):
break
if not os.path.isfile( fname ):
abort( 404 )
return send_file( fname, "text/plain" )
# ---------------------------------------------------------------------
default_scenario = None
@app.route( "/default-scenario" )

@ -26,6 +26,7 @@
<li> <a href="#helptabs-userguide">User Guide</a>
<li> <a href="#helptabs-templatepacks">Template packs</a>
<li> <a href="#helptabs-fordevelopers">For developers</a>
<li> <a href="#helptabs-license">License</a>
</ul>
<div id="helptabs-content">
@ -290,6 +291,14 @@ The script will compile the program, then package it all up with the necessary s
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="helptabs-license">
<div class="content"></div>
</div>
<!-- ----------------------------------------------------------------- -->
</div> <!-- #helptabs-content -->

@ -22,3 +22,7 @@ p { margin-top: 0.5em ; }
#helptabs .ui-tabs-active a { color: #444 ; }
#helptabs .ui-tabs-panel { padding: 0.5em 1em 0.5em 1em ; }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#helptabs-license .content { white-space: pre ; font-family: monospace ; }

@ -33,9 +33,26 @@ $(document).ready( function() {
$(this).wrap( "<a href='" + url + "'></a>" ).imageZoom( $ ) ;
} ) ;
// load the license
if ( window.parent.location.protocol !== "file:" ) {
var url = window.parent.location.protocol + "//" + window.parent.location.hostname ;
if ( window.parent.location.port )
url += ":" + window.parent.location.port ;
url += "/license" ;
$.get( url, function(data) {
$( "#helptabs-license .content" ).text( data ) ;
} ).fail( function( xhr, status, errorMsg ) {
$( "#helptabs-license .content" ).text( "Couldn't get the license: " + errorMsg ) ;
} ) ;
} else {
$( "#helptabs li:contains('License')" ).hide() ;
$( "#helptabs-license" ).hide() ;
}
// initialize the tabs
if ( getUrlParam( "embedded" ) ) {
$( "#helptabs li:eq(0)" ).remove() ;
// update the UI
$( "#helptabs li:contains('Installation')" ).remove() ;
$( "#helptabs-installation" ).remove() ;
}
$("#loader").fadeOut( 500 ) ;

@ -1,7 +1,7 @@
""" Test the help page. """
from vasl_templates.webapp.tests.utils import \
init_webapp, select_menu_option, find_child, find_children
init_webapp, select_menu_option, find_child, find_children, wait_for, wait_for_elem
# ---------------------------------------------------------------------
@ -23,9 +23,26 @@ def test_help( webapp, webdriver ):
# show the help
select_menu_option( "show_help" )
webdriver.switch_to.frame( find_child( "#tabs-help iframe" ) )
assert "everyone's favorite scenario" in webdriver.page_source
webdriver.switch_to.default_content()
# make sure that the HELP tab is now visible
assert "tabs-help" in get_tabs()
# check what's in the help iframe
try:
# switch to the frame
webdriver.switch_to.frame( find_child( "#tabs-help iframe" ) )
# check that the content loaded OK
assert "everyone's favorite scenario" in webdriver.page_source
# check that the license loaded OK
elem = wait_for_elem( 2, "a.ui-tabs-anchor[href='#helptabs-license']" )
assert elem.is_displayed()
wait_for( 2, lambda: "GNU AFFERO GENERAL PUBLIC LICENSE" in webdriver.page_source )
assert "Version 3" in webdriver.page_source
finally:
# switch back to the main window
webdriver.switch_to.default_content()

Loading…
Cancel
Save