From 2e845103535a67586a34e7f2ae3b2e07e66f5a03 Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 8 Aug 2018 09:49:06 +0000 Subject: [PATCH] Added OB notes. --- .../data/default-template-pack/ob_note.j2 | 13 ++ vasl_templates/webapp/static/css/main.css | 10 +- vasl_templates/webapp/static/css/tabs-ob.css | 28 +++-- vasl_templates/webapp/static/main.js | 30 ++++- vasl_templates/webapp/static/ob_setup.js | 87 ------------- vasl_templates/webapp/static/simple_notes.js | 118 ++++++++++++++++++ vasl_templates/webapp/static/snippets.js | 26 ++-- vasl_templates/webapp/templates/index.html | 37 +++--- .../data/default-template-pack/ob_note.j2 | 1 + .../fixtures/template-packs/full/ob_note.j2 | 1 + .../template-packs/new-default/ob_note.j2 | 1 + .../tests/{test_ob_setup.py => test_ob.py} | 99 ++++++++++----- .../webapp/tests/test_scenario_persistence.py | 28 +++-- vasl_templates/webapp/tests/test_snippets.py | 29 +++-- .../webapp/tests/test_template_packs.py | 20 +-- vasl_templates/webapp/tests/utils.py | 25 ++-- 16 files changed, 359 insertions(+), 194 deletions(-) create mode 100644 vasl_templates/webapp/data/default-template-pack/ob_note.j2 delete mode 100644 vasl_templates/webapp/static/ob_setup.js create mode 100644 vasl_templates/webapp/static/simple_notes.js create mode 100644 vasl_templates/webapp/tests/fixtures/data/default-template-pack/ob_note.j2 create mode 100644 vasl_templates/webapp/tests/fixtures/template-packs/full/ob_note.j2 create mode 100644 vasl_templates/webapp/tests/fixtures/template-packs/new-default/ob_note.j2 rename vasl_templates/webapp/tests/{test_ob_setup.py => test_ob.py} (66%) diff --git a/vasl_templates/webapp/data/default-template-pack/ob_note.j2 b/vasl_templates/webapp/data/default-template-pack/ob_note.j2 new file mode 100644 index 0000000..4fc4ad0 --- /dev/null +++ b/vasl_templates/webapp/data/default-template-pack/ob_note.j2 @@ -0,0 +1,13 @@ + + + + + +
+ {{OB_NOTE}} + +
+ + diff --git a/vasl_templates/webapp/static/css/main.css b/vasl_templates/webapp/static/css/main.css index 254e865..77e6099 100644 --- a/vasl_templates/webapp/static/css/main.css +++ b/vasl_templates/webapp/static/css/main.css @@ -111,11 +111,11 @@ input[type="text"] { margin-bottom: 0.25em ; } .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 ; } -.ui-dialog.edit-ob_setup .ui-dialog-titlebar { display: none ; } -.ui-dialog.edit-ob_setup .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; } -#edit-ob_setup { padding: 2px ; } -.ui-dialog.edit-ob_setup textarea { resize: none ; width: calc(100% - 4px) ; height: calc(100% - 3em) ; } -.ui-dialog.edit-ob_setup button { margin: 0 0 0 5px ; padding: 0.1em 0.2em ; } +.ui-dialog.edit-simple_note .ui-dialog-titlebar { display: none ; } +.ui-dialog.edit-simple_note .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; } +#edit-simple_note { padding: 2px ; } +.ui-dialog.edit-simple_note textarea { resize: none ; width: calc(100% - 4px) ; height: calc(100% - 3em) ; } +.ui-dialog.edit-simple_note button { margin: 0 0 0 5px ; padding: 0.1em 0.2em ; } #select-vo { overflow: hidden ; } #select-vo .header { height: 2em ; } diff --git a/vasl_templates/webapp/static/css/tabs-ob.css b/vasl_templates/webapp/static/css/tabs-ob.css index 34bf172..f493959 100644 --- a/vasl_templates/webapp/static/css/tabs-ob.css +++ b/vasl_templates/webapp/static/css/tabs-ob.css @@ -1,22 +1,22 @@ /* -------------------------------------------------------------------- */ -.panel-ob_setup { +.panel-ob_setups { height: 100% ; display: grid ; display: -ms-grid ; grid-template-rows: 1fr 2em ; -ms-grid-rows: 1fr 2em ; grid-template-columns: 1fr ; -ms-grid-columns: 1fr ; } /* FUDGE! IE hackamathon follows... */ -.panel-ob_setup .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; } -.panel-ob_setup .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } +.panel-ob_setups .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; } +.panel-ob_setups .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } -.panel-ob_setup ul.sortable li input[type="button"] { float: right ; } -.panel-ob_setup .footer { text-align: right ; font-size: 75% ; } -.panel-ob_setup .footer .l { float: left ; } -.ob_setup-trash { margin-left: 5px ; height: 2em ; } +.panel-ob_setups ul.sortable li input[type="button"] { float: right ; } +.panel-ob_setups .footer { text-align: right ; font-size: 75% ; } +.panel-ob_setups .footer .l { float: left ; } +.ob_setups-trash { margin-left: 5px ; height: 2em ; } -.ob_setup-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; } -.ob_setup-hint p { margin-bottom: 1em ; } +.ob_setups-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; } +.ob_setups-hint p { margin-bottom: 1em ; } /* -------------------------------------------------------------------- */ @@ -30,8 +30,16 @@ .panel-ob_notes .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; } .panel-ob_notes .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } +.panel-ob_notes ul.sortable li input[type="button"] { float: right ; } .panel-ob_notes .footer { font-size: 75% ; } -.panel-ob_notes div.snippet-control { float: left ; margin: 0.25em 0.25em 0 0 ; } +.panel-ob_notes .footer input[type="button"][data-id="ob_note"] { float: right ; } +.panel-ob_notes div.snippet-control { float: right ; margin: 0.25em 0.25em 0 0 ; } + +.panel-ob_notes .footer .l { float: left ; } +.ob_notes-trash { margin-left: 5px ; height: 2em ; } + +.ob_notes-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; } +.ob_notes-hint p { margin-bottom: 1em ; } /* -------------------------------------------------------------------- */ diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index f5b361a..5ee7646 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -88,22 +88,37 @@ $(document).ready( function () { } ) ; enable_ctrl_enter( $("#edit-ssr"), "OK" ) ; - // initialize OB setup controls - init_sortable( $("#ob_setup-sortable_1"), + // initialize the OB setups + init_sortable( $("#ob_setups-sortable_1"), function() { add_ob_setup(1) ; }, edit_ob_setup ) ; - $("#panel-ob_setup1 input[type='button'][data-id='ob_setup']").click( function() { + $("#panel-ob_setups1 input[type='button'][data-id='ob_setup']").click( function() { edit_template( "ob_setup" ) ; } ) ; - init_sortable( $("#ob_setup-sortable_2"), + init_sortable( $("#ob_setups-sortable_2"), function() { add_ob_setup(2) ; }, edit_ob_setup ) ; - $("#panel-ob_setup2 input[type='button'][data-id='ob_setup']").click( function() { + $("#panel-ob_setups2 input[type='button'][data-id='ob_setup']").click( function() { edit_template( "ob_setup" ) ; } ) ; - enable_ctrl_enter( $("#edit-ob_setup"), "OK" ) ; + + // initialize the OB notes + init_sortable( $("#ob_notes-sortable_1"), + function() { add_ob_note(1) ; }, + edit_ob_note + ) ; + $("#panel-ob_notes1 input[type='button'][data-id='ob_note']").click( function() { + edit_template( "ob_note" ) ; + } ) ; + init_sortable( $("#ob_notes-sortable_2"), + function() { add_ob_note(2) ; }, + edit_ob_note + ) ; + $("#panel-ob_notes2 input[type='button'][data-id='ob_note']").click( function() { + edit_template( "ob_note" ) ; + } ) ; // initialize vehicle controls (1) $("#vehicle-sortable_1").sortable( { connectWith: "#vehicle-trash_1", cursor: "move" } ) ; @@ -260,6 +275,9 @@ $(document).ready( function () { } ) ; enable_ctrl_enter( $("#edit-template"), "Close" ) ; + // enable Ctrl-Enter when editing simple notes + enable_ctrl_enter( $("#edit-simple_note"), "OK" ) ; + // initialize hotkeys init_hotkeys() ; diff --git a/vasl_templates/webapp/static/ob_setup.js b/vasl_templates/webapp/static/ob_setup.js deleted file mode 100644 index fbdd804..0000000 --- a/vasl_templates/webapp/static/ob_setup.js +++ /dev/null @@ -1,87 +0,0 @@ - -// -------------------------------------------------------------------- - -function add_ob_setup( player_id ) -{ - // add a new OB setup - edit_ob_setup( $("#ob_setup-sortable_"+player_id), null ) ; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function edit_ob_setup( $sortable, $entry ) -{ - var $caption, $width ; - - // let the user edit the OB setup - $("#edit-ob_setup").dialog( { - dialogClass: "edit-ob_setup", - modal: true, - minWidth: 400, - minHeight: 150, - open: function() { - $caption = $(this).children( "textarea" ) ; - $width = $(this).children( "input[type='text']" ) ; - if ( $entry ) { - var data = $entry.data( "sortable-data" ) ; - $caption.val( data.caption ) ; - $width.val( data.width ) ; - } - else { - $caption.val( "" ) ; - $width.val( "" ) ; - } - $(this).height( $(this).height() ) ; // fudge: force the textarea to resize - }, - buttons: { - OK: function() { - var caption = $caption.val().trim() ; - var width = $width.val().trim() ; - if ( $entry ) { - // update the existing OB setup - if ( caption === "" ) - delete_sortable_entry( $entry ) ; - else { - $entry.data("sortable-data").caption = caption ; - $entry.data("sortable-data").width = width ; - $entry.empty().append( _make_sortable_entry( caption ) ) ; - } - } - else { - // create a new OB setup - if ( caption !== "" ) { - data = { caption: caption, width: width } ; - do_add_ob_setup( $sortable, data ) ; - } - } - $(this).dialog( "close" ) ; - }, - Cancel: function() { $(this).dialog( "close" ) ; }, - }, - } ) ; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function do_add_ob_setup( $sortable, data ) -{ - // add a new sortable entry - add_sortable( $sortable, _make_sortable_entry(data.caption), data ) ; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -function _make_sortable_entry( caption ) -{ - // generate the sortable entry - var $content = $( "
" + caption + "
" ) ; - - // add a handler for the snippet button - $content.children("input[type='button']").click( function() { - var data = $(this).parent().parent().data( "sortable-data" ) ; - var extra_params = { OB_SETUP: data.caption, OB_SETUP_WIDTH: data.width } ; - generate_snippet( $(this), extra_params ) ; - } ) ; - - return $content ; -} diff --git a/vasl_templates/webapp/static/simple_notes.js b/vasl_templates/webapp/static/simple_notes.js new file mode 100644 index 0000000..cbc9b70 --- /dev/null +++ b/vasl_templates/webapp/static/simple_notes.js @@ -0,0 +1,118 @@ +// NOTE: This module manage simple notes (some text and an optional width), +// which is used by OB setups and OB notes (which differ only in their templates, +// the code to manage them is almost identical). + +// -------------------------------------------------------------------- + +function add_ob_setup( player_id ) { _do_edit_simple_note( $("#ob_setups-sortable_"+player_id), null ) ; } +function do_add_ob_setup( $sortable, data ) { _do_add_simple_note($sortable,data) ; } +function edit_ob_setup( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; } + +function add_ob_note( player_id ) { _do_edit_simple_note( $("#ob_notes-sortable_"+player_id), null ) ; } +function do_add_ob_note( $sortable, data ) { _do_add_simple_note($sortable,data) ; } +function edit_ob_note( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function _do_edit_simple_note( $sortable, $entry ) +{ + // figure out what we're editing + var note_type = _get_note_type_for_sortable( $sortable ) ; + var note_type0 = note_type.substring( 0, note_type.length-1 ) ; // plural -> singular :-/ + + // let the user edit the note + var $caption, $width ; + $("#edit-simple_note").dialog( { + dialogClass: "edit-simple_note", + modal: true, + minWidth: 400, + minHeight: 150, + open: function() { + $caption = $(this).children( "textarea" ) ; + $width = $(this).children( "input[type='text']" ) ; + if ( $entry ) { + var data = $entry.data( "sortable-data" ) ; + $caption.val( data.caption ) ; + $width.val( data.width ) ; + } + else { + $caption.val( "" ) ; + $width.val( "" ) ; + } + $(this).height( $(this).height() ) ; // fudge: force the textarea to resize + }, + buttons: { + OK: function() { + var caption = $caption.val().trim() ; + var width = $width.val().trim() ; + if ( $entry ) { + // update the existing note + if ( caption === "" ) + delete_sortable_entry( $entry ) ; + else { + $entry.data("sortable-data").caption = caption ; + $entry.data("sortable-data").width = width ; + $entry.empty().append( _make_simple_note( note_type, caption ) ) ; + } + } + else { + // create a new note + if ( caption !== "" ) { + data = { caption: caption, width: width } ; + _do_add_simple_note( $sortable, data ) ; + } + } + $(this).dialog( "close" ) ; + }, + Cancel: function() { $(this).dialog( "close" ) ; }, + }, + } ) ; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function _do_add_simple_note( $sortable, data ) +{ + // add a new sortable entry + var note_type = _get_note_type_for_sortable( $sortable ) ; + var $entry = _make_simple_note( note_type, data.caption ) ; + add_sortable( $sortable, $entry , data ) ; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function _make_simple_note( note_type, caption ) +{ + // generate the sortable entry + var note_type0 = note_type.substring( 0, note_type.length-1 ) ; + var buf = [] ; + buf.push( + "
", + "", + caption, + "
" + ) ; + var $content = $( buf.join("") ) ; + + // add a handler for the snippet button + $content.children("input[type='button']").click( function() { + var data = $(this).parent().parent().data( "sortable-data" ) ; + var prefix = (note_type === "ob_setups") ? "OB_SETUP" : "OB_NOTE" ; + var extra_params = {} ; + extra_params[prefix] = data.caption ; + extra_params[prefix+"_WIDTH"] = data.width ; + generate_snippet( $(this), extra_params ) ; + } ) ; + + return $content ; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function _get_note_type_for_sortable( $sortable ) +{ + // figure out what type of note the sortable has + var id = $sortable.prop( "id" ) ; + var match = /^(ob_(setups|notes))-sortable_\d$/.exec( id ) ; + return match[1] ; +} diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 62a0539..216ad5d 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -503,13 +503,22 @@ function do_load_scenario( params ) params_loaded[key] = true ; continue ; } - var player_id ; - if ( key === "OB_SETUP_1" || key === "OB_SETUP_2" ) { + var player_id, $sortable ; + if ( key === "OB_SETUPS_1" || key === "OB_SETUPS_2" ) { player_id = key.substring( key.length-1 ) ; - var $sortable = $( "#ob_setup-sortable_" + player_id ) ; + $sortable = $( "#ob_setups-sortable_" + player_id ) ; for ( i=0 ; i < params[key].length ; ++i ) do_add_ob_setup( $sortable, params[key][i] ) ; params_loaded[key] = true ; + continue ; + } + if ( key === "OB_NOTES_1" || key === "OB_NOTES_2" ) { + player_id = key.substring( key.length-1 ) ; + $sortable = $( "#ob_notes-sortable_" + player_id ) ; + for ( i=0 ; i < params[key].length ; ++i ) + do_add_ob_note( $sortable, params[key][i] ) ; + params_loaded[key] = true ; + continue ; } if ( key === "VEHICLES_1" || key === "ORDNANCE_1" || key === "VEHICLES_2" || key === "ORDNANCE_2" ) { player_id = key.substring( key.length-1 ) ; @@ -562,7 +571,7 @@ function do_load_scenario( params ) function on_save_scenario() { // unload the template parameters - function unload_ob_setups( $sortable ) { + function unload_ob_entries( $sortable ) { var entries = [] ; $sortable.children("li").each( function() { entries.push( $(this).data( "sortable-data" ) ) ; @@ -579,8 +588,10 @@ function on_save_scenario() } var params = {} ; unload_params( params, false ) ; - params.OB_SETUP_1 = unload_ob_setups( $("#ob_setup-sortable_1") ) ; - params.OB_SETUP_2 = unload_ob_setups( $("#ob_setup-sortable_2") ) ; + params.OB_SETUPS_1 = unload_ob_entries( $("#ob_setups-sortable_1") ) ; + params.OB_SETUPS_2 = unload_ob_entries( $("#ob_setups-sortable_2") ) ; + params.OB_NOTES_1 = unload_ob_entries( $("#ob_notes-sortable_1") ) ; + params.OB_NOTES_2 = unload_ob_entries( $("#ob_notes-sortable_2") ) ; extract_vo_names( "VEHICLES_1" ) ; extract_vo_names( "ORDNANCE_1" ) ; extract_vo_names( "VEHICLES_2" ) ; @@ -629,7 +640,8 @@ function on_new_scenario( verbose ) // reset all the template parameters for ( var i=1 ; i <= 2 ; ++i ) { - delete_all_sortable_entries( $("#ob_setup-sortable_"+i) ) ; + delete_all_sortable_entries( $("#ob_setups-sortable_"+i) ) ; + delete_all_sortable_entries( $("#ob_notes-sortable_"+i) ) ; delete_all_vo( "vehicle", i ) ; delete_all_vo( "ordnance", i ) ; } diff --git a/vasl_templates/webapp/templates/index.html b/vasl_templates/webapp/templates/index.html index 22a3303..389f45e 100644 --- a/vasl_templates/webapp/templates/index.html +++ b/vasl_templates/webapp/templates/index.html @@ -88,32 +88,39 @@
OB setup -
+
-

Click on the "+" below to add a new setup note.

To re-order the setup notes, use the mouse to drag them around.

Ctrl-click on a setup note to delete it, or drag it into the trashcan below.

- +

Click on the "+" below to add a new setup note.

To re-order the setup notes, use the mouse to drag them around.

Ctrl-click on a setup note to delete it, or drag it into the trashcan below.

+
Notes
+

Click on the "+" below to add a new setup note.

To re-order the setup notes, use the mouse to drag them around.

Ctrl-click on a setup note to delete it, or drag it into the trashcan below.

+
@@ -165,7 +172,7 @@ -