Added SSR's.

master
Pacman Ghost 6 years ago
parent 06fa8dd30b
commit cab39f3769
  1. 2
      vasl_templates/webapp/data/default-templates/ssr.j2
  2. 21
      vasl_templates/webapp/static/css/main.css
  3. 6
      vasl_templates/webapp/static/generate.js
  4. BIN
      vasl_templates/webapp/static/images/trash.png
  5. 14
      vasl_templates/webapp/static/main.js
  6. 87
      vasl_templates/webapp/static/ssr.js
  7. 37
      vasl_templates/webapp/static/utils.js
  8. 9
      vasl_templates/webapp/templates/main.html
  9. 70
      vasl_templates/webapp/tests/test_ssr.py

@ -0,0 +1,2 @@
{% for ssr in SSR %}(*) [{{ssr}}]
{% endfor %}

@ -108,6 +108,21 @@ input[type="text"] { margin-bottom: 0.25em ; }
#panel-vc textarea[name="victory_conditions"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; }
#panel-vc input[type="button"] { float: right ; }
#panel-ssr #ssr-sortable { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; }
#panel-ssr #ssr-sortable { list-style-type: none ; margin: 0 ; padding: 0 ; }
#panel-ssr #ssr-sortable li {
margin-bottom: 2px ; padding: 5px ;
border: 1px dotted #333 ; background: #eee ;
}
#panel-ssr #ssr-sortable li.highlighted { background: #48c8ff ; }
#panel-ssr #ssr-sortable li:hover { cursor: pointer ; }
#panel-ssr input#add-ssr { float: left ; }
#panel-ssr #ssr-trash { margin-left: 5px ; float: left ; height: 1.5em ; }
#panel-ssr input[data-id="ssr"] { float: right ; }
#ssr-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
#ssr-hint p { margin-bottom: 1em ; }
#panel-obsetup1 textarea[name="ob_setup_1"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; }
#panel-obsetup1 input[type="button"] { float: right ; }
@ -116,5 +131,11 @@ input[type="text"] { margin-bottom: 0.25em ; }
/* -------------------------------------------------------------------- */
.ui-dialog.edit-ssr .ui-dialog-titlebar { display: none ; }
.ui-dialog.edit-ssr .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; }
#edit-ssr { padding: 2px ; }
.ui-dialog.edit-ssr textarea { resize: none ; width: calc(100% - 4px) ; height: calc(100% - 1.25em) ; }
.ui-dialog.edit-ssr button { margin: 0 0 0 5px ; padding: 0.1em 0.2em ; }
.growl-title { display: none ; }
.growl ul { margin-left: 1em ; }

@ -29,6 +29,12 @@ function generate_snippet( $btn )
params.OB_SETUP_COLOR = gNationalities[params.PLAYER_2].ob_colors[0] ;
params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_2].ob_colors[1] ;
}
else if ( template_id === "ssr" ) {
params.SSR = [] ;
$("#ssr-sortable li").each( function() {
params.SSR.push( $(this).text() ) ;
} ) ;
}
// check for mandatory parameters
if ( template_id in _MANDATORY_PARAMS ) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -12,6 +12,20 @@ $(document).ready( function () {
var navHeight = $("#tabs .ui-tabs-nav").height() ;
$("input[name='scenario_name']").focus().focus() ;
// initialize
$("#ssr-sortable").sortable( { connectWith: "#ssr-trash", cursor: "move" } ) ;
init_ssr( $("#ssr-sortable li") ) ;
$("#add-ssr").click( add_ssr ) ;
$("#ssr-trash").sortable( {
receive: function( evt, ui ) { ui.item.remove() ; update_ssr_hint() ; }
} ) ;
$("#edit-ssr textarea").keydown( function(evt) {
if ( evt.keyCode == 13 && evt.ctrlKey ) {
$(".ui-dialog.edit-ssr button:contains('OK')").click() ;
evt.preventDefault() ;
}
} ) ;
// load the ELR's and SAN's
var buf = [] ;
for ( var i=0 ; i <= 5 ; ++i ) // nb: A19.1: ELR is 0-5

@ -0,0 +1,87 @@
// --------------------------------------------------------------------
function add_ssr()
{
// add a new SSR
edit_ssr( null ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function edit_ssr( $elem )
{
// let the user edit a SSR's content
$("#edit-ssr textarea").val( $elem ? $elem.text() : "" ) ;
$("#edit-ssr").dialog( {
dialogClass: "edit-ssr",
modal: true,
minWidth: 400,
minHeight: 150,
open: function() {
$(this).height( $(this).height() ) ; // fudge: force the textarea to resize
},
buttons: {
OK: function() {
var val = $("#edit-ssr textarea").val().trim() ;
if ( $elem ) {
// update the existing SSR
if ( val !== "" )
$elem.text( val ) ;
else
delete_ssr( $elem ) ;
}
else {
// create a new SSR
if ( val !== "" ) {
var $new_ssr = $( "<li></li>" ) ;
$new_ssr.text( val ) ;
$("#ssr-sortable").append( $new_ssr ) ;
init_ssr( $new_ssr ) ;
}
}
update_ssr_hint() ;
$(this).dialog( "close" ) ;
},
Cancel: function() { $(this).dialog( "close" ) ; },
},
} ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function delete_ssr( $elem )
{
// delete the SSR
$elem.addClass( "highlighted" ) ;
ask( "Delete this SSR?", escapeHTML($elem.text()), {
"ok": function() { $elem.remove() ; update_ssr_hint() ; },
"close": function() { $elem.removeClass("highlighted") ; },
} ) ;
}
// --------------------------------------------------------------------
function init_ssr( $elem )
{
// initialize SSR element(s)
$elem.dblclick( function() {
edit_ssr( $(this) ) ;
} ) ;
$elem.click( function( evt ) {
if ( evt.ctrlKey )
delete_ssr( $(this) ) ;
} ) ;
}
function update_ssr_hint()
{
// show/hide the SSR hint
if ( $("#ssr-sortable li").length === 0 ) {
$("#ssr-sortable").hide() ;
$("#ssr-hint").show() ;
} else {
$("#ssr-sortable").show() ;
$("#ssr-hint").hide() ;
}
}

@ -33,6 +33,37 @@ function copyToClipboard( val )
// --------------------------------------------------------------------
function ask( title, msg, args )
{
// ask a question
var $dlg = $("#ask") ;
$dlg.html( msg ) ;
$dlg.dialog( {
modal: true,
title: title,
buttons: {
OK: function() {
$(this).dialog( "close" ) ;
if ( "ok" in args )
args.ok() ;
},
Cancel: function() {
$(this).dialog( "close" ) ;
if ( "cancel" in args )
args.cancel() ;
},
},
close: function() {
if ( "close" in args )
args.close() ;
},
} ) ;
return false ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showInfoMsg( msg )
{
// show the informational message
@ -40,7 +71,7 @@ function showInfoMsg( msg )
style: "notice",
title: null,
message: msg,
location: "br",
location: "tr",
} ) ;
storeMsgForTestSuite( "_last-info_", msg ) ;
}
@ -54,7 +85,7 @@ function showWarningMsg( msg )
style: "warning",
title: null,
message: msg,
location: "br",
location: "tr",
} ) ;
storeMsgForTestSuite( "_last-warning_", msg ) ;
}
@ -68,7 +99,7 @@ function showErrorMsg( msg )
style: "error",
title: null,
message: msg,
location: "br",
location: "tr",
fixed: true,
} ) ;
storeMsgForTestSuite( "_last-error_", msg ) ;

@ -45,7 +45,10 @@
</fieldset>
</div>
<div id="panel-ssr">
<fieldset> <legend>SSR</legend>
<fieldset> <legend>SSR's</legend>
<div id="ssr-hint"> <p>Click on the "+" below to add a new SSR, double-click on an SSR to edit it. <p>To re-order the SSR's, use the mouse to drag them around. <p>Ctrl-click on an SSR to delete it, or drag it into the trashcan below. </div>
<ul id="ssr-sortable" style="display:none;"></ul>
<input type="button" id="add-ssr" value="+"> <img id="ssr-trash" src="{{url_for('static',filename='images/trash.png')}}"> <input type="button" class="generate" data-id="ssr" value="Go">
</fieldset>
</div>
</div>
@ -91,6 +94,9 @@
</div>
</div>
<div id="edit-ssr" style="display:none;"> <b>Enter the SSR content:</b> <textarea></textarea> </div>
<div id="ask" style="display:none;"></div>
</div>
</body>
@ -104,6 +110,7 @@ gGetNationalitiesUrl = "{{url_for('get_nationalities')}}" ;
</script>
<script src="{{url_for('static',filename='main.js')}}"></script>
<script src="{{url_for('static',filename='generate.js')}}"></script>
<script src="{{url_for('static',filename='ssr.js')}}"></script>
<script src="{{url_for('static',filename='utils.js')}}"></script>
</html>

@ -0,0 +1,70 @@
""" Test generating SSR snippets. """
import html
from selenium.webdriver.common.action_chains import ActionChains
from vasl_templates.webapp.tests.utils import get_clipboard, find_child, find_children
# ---------------------------------------------------------------------
def test_ssr( webapp, webdriver ):
"""Test generating SSR snippets."""
# initialize
webdriver.get( webapp.url_for( "main" ) )
# initialize
expected = []
def add_ssr( val ):
"""Add a new SSR, and check that the SSR snippet is generated correctly."""
# add the SSR
expected.append( val )
elem = find_child( webdriver, "#add-ssr" )
elem.click()
edit_ssr( val )
def edit_ssr( val ):
"""Edit an SSR's content, and check that the SSR snippet is generated correctly."""
# edit the SSR content
textarea = find_child( webdriver, "#edit-ssr textarea" )
textarea.clear()
textarea.send_keys( val )
btn = next(
elem for elem in find_children(webdriver,".ui-dialog.edit-ssr button")
if elem.text == "OK"
)
btn.click()
# check the generated snippet
check_snippet()
def check_snippet():
"""Check the generated SSR snippet."""
btn = find_child( webdriver, "input[type='button'][data-id='ssr']" )
btn.click()
val = "\n".join( "(*) [{}]".format(e) for e in expected )
assert html.unescape(get_clipboard().strip()) == val
# add an SSR and generate the SSR snippet
add_ssr( "This is my first SSR." )
# add an SSR that contains HTML
add_ssr( "This snippet contains <b>bold</b> and <i>italic</i> text." )
# add a multi-line SSR
add_ssr( "line 1\nline 2\nline 3" )
# edit one of the SSR's
elems = find_children( webdriver, "#ssr-sortable li" )
assert len(elems) == 3
elem = elems[1]
ActionChains(webdriver).double_click( elem ).perform()
expected[1] = "This SSR was <i>modified</i>."
edit_ssr( expected[1] )
# delete one of the SSR's
elems = find_children( webdriver, "#ssr-sortable li" )
assert len(elems) == 3
elem = elems[1]
trash = find_child( webdriver, "#ssr-trash" )
ActionChains(webdriver).drag_and_drop( elem, trash ).perform()
del expected[1]
check_snippet()
Loading…
Cancel
Save