Skip to content
Commits on Source (3)
......@@ -35,6 +35,7 @@ import qrcode
import webauthn
from NIST import NISTf
from PiAnoS import caseExistsInDB
from const import pfsp
from functions import float_or_null
......@@ -2684,16 +2685,9 @@ def pianos_actions():
@app.route( baseurl + '/pianos_api/add_user/all' )
@admin_required
def pianos_update_all_accounts():
action = do_pianos_update_all_accounts()
if action:
return jsonify( {
'error': False
} )
else:
return jsonify( {
'error': True
} )
return jsonify( {
'error': not do_pianos_update_all_accounts()
} )
def do_pianos_update_all_accounts():
try:
......@@ -2715,6 +2709,48 @@ def do_pianos_update_all_accounts():
except:
return False
@app.route( baseurl + '/pianos_api/add_segments/all' )
@admin_required
def pianos_copy_all_segments():
return jsonify( {
'error': not do_pianos_copy_all_segments()
} )
def do_pianos_copy_all_segments():
try:
folder_id = config.pianosdb.create_folder( "Annotation" )
img = Image.new( "L", ( 200, 200 ), 255 )
empty_img_res = 500
empty_img_id = config.pianosdb.create_image( "PRINT", img, empty_img_res, "empty" )
sql = """
SELECT files_segments.uuid, files_segments.data, files_v.resolution
FROM files_segments
LEFT JOIN files_v ON files_segments.tenprint = files_v.uuid
"""
for segment in config.db.query_fetchall( sql ):
img = str2img( segment[ "data" ] )
print segment[ "resolution" ]
try:
config.pianosdb.create_exercise(
folder_id,
segment[ "uuid" ], "",
img, segment[ "resolution" ],
empty_img_id, empty_img_res
)
except caseExistsInDB:
continue
except:
raise
config.pianosdb.commit()
return True
except:
return False
################################################################################
# Home page
......
......@@ -34,6 +34,44 @@
}
} );
}
var copy_all_segments = function()
{
$( "#pianos_copy_all_segments_button" )
.removeClass( "ui-state-default" )
.addClass( "ui-state-disabled" );
$.ajax( {
url: "{{ url_for( 'pianos_copy_all_segments' ) }}",
dataType: "json",
success: function( data )
{
if( ! data.error )
{
toastr.success( "Segments copied to PiAnoS" );
$( "#pianos_copy_all_segments_button" )
.addClass( "ui-state-default" )
.removeClass( "ui-state-disabled" );
} else {
toastr.error( "Error while copying the segments" );
$( "#pianos_copy_all_segments_button" )
.addClass( "ui-state-default" )
.removeClass( "ui-state-disabled" );
}
},
error: function()
{
toastr.error( "Network error" );
$( "#pianos_copy_all_segments_button" )
.addClass( "ui-state-default" )
.removeClass( "ui-state-disabled" );
}
} );
}
</script>
</head>
<body class="icnml_main_layout">
......@@ -46,12 +84,20 @@
<span class="ui-button-text" id="pianos_update_all_accounts_button_span_text">Copy all accounts to PiAnoS</span>
</a>
</div>
<div id="pianos_copy_all_segments_button_div">
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="pianos_copy_all_segments_button" role="button" aria-disabled="false">
<span class="ui-button-text" id="pianos_copy_all_segments_button_span_text">Copy all segment images to PiAnoS</span>
</a>
</div>
</div>
<script type="text/javascript">
$( "#pianos_update_all_accounts_button" )
.on( "click", update_all );
$( "#pianos_copy_all_segments_button" )
.on( "click", copy_all_segments )
$( "#icnml_navigation_pianos" )
.addClass( "activated" );
......
......@@ -421,6 +421,17 @@
<span class="ui-button-text">Clear</span>
</a>
</div>
<div>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="back_button" role="button" aria-disabled="false">
<span class="ui-button-text">Back page</span>
</a>
</div>
{% elif t == 'back' %}
<div>
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="front_button" role="button" aria-disabled="false">
<span class="ui-button-text">Front page</span>
</a>
</div>
{% endif %}
</div>
</div>
......@@ -629,6 +640,15 @@
$( '#clear_button' ).on( 'click', clear );
$( "#back_button" ).on( "click", function()
{
window.location = "{{ url_for( 'template_tenprint', id = card_id, t = 'back' ) }}";
} )
$( "#front_button" ).on( "click", function()
{
window.location = "{{ url_for( 'template_tenprint', id = card_id, t = 'front' ) }}";
} )
window.addEventListener( 'resize', function( event )
{
update_coordinates_informations();
......