Skip to content
Commits on Source (9)
......@@ -118,7 +118,16 @@ def admin_folder_show( folder_id ):
INNER JOIN files ON segments_locations.tenprint_id = files.uuid
INNER JOIN submissions ON files.folder = submissions.id
INNER JOIN cnm_folder ON submissions.uuid = cnm_folder.donor
WHERE cnm_folder.uuid = %s
WHERE
cnm_folder.uuid = %s AND
(
fpc <= 10 OR
fpc = 22 OR
fpc = 24 OR
fpc = 25 OR
fpc = 27
)
GROUP BY fpc
ORDER BY fpc ASC
"""
segment_list = config.db.query_fetchall( sql, ( folder_id, ) )
......@@ -188,17 +197,58 @@ def admin_add_segment_to_cnmfolder( folder_id ):
@afis_view.route( "/admin/afis/<folder_id>/segment/<fpc>" )
@admin_required
def admin_view_segment( folder_id, fpc ):
# Get the list of references images depending upon the FPC
multi_img_fpc = {
1: [ 1, 11 ],
2: [ 2, 13 ],
3: [ 3, 13 ],
4: [ 4, 13 ],
5: [ 5, 13 ],
6: [ 6, 12 ],
7: [ 7, 14 ],
8: [ 8, 14 ],
9: [ 9, 14 ],
10: [ 10, 14 ]
}
fpc = int( fpc )
fpcs = multi_img_fpc.get( fpc, [ fpc ] )
tmp_sql = [ "files_segments.pc = %s" ] * len( fpcs )
tmp_sql = " OR ".join( tmp_sql )
sql = """
SELECT
files_segments.tenprint
files_segments.tenprint,
files.uuid as file_uuid,
files_segments.pc
FROM cnm_folder
INNER JOIN submissions ON cnm_folder.donor = submissions.uuid
INNER JOIN files ON submissions.id = files.folder
INNER JOIN files_segments ON files.uuid = files_segments.tenprint
WHERE cnm_folder.uuid = %s AND files_segments.pc = %s
"""
tenprint_id = config.db.query_fetchone( sql, ( folder_id, fpc, ) )[ "tenprint" ]
WHERE
cnm_folder.uuid = %s AND
( {} )
ORDER BY pc ASC
""".format( tmp_sql )
data = [ folder_id, ]
data.extend( fpcs )
tenprints_list = config.db.query_fetchall( sql, data )
# Get the list of marks related to this finger
sql = """
SELECT files.id, files.uuid
FROM files
INNER JOIN mark_info ON files.uuid = mark_info.uuid
INNER JOIN submissions ON files.folder = submissions.id
INNER JOIN cnm_folder ON submissions.uuid = cnm_folder.donor
WHERE
cnm_folder.uuid = %s AND
files.type = 3
"""
mark_list = config.db.query_fetchall( sql, ( folder_id, ) )
# Get the username of the donor
sql = """
SELECT username
FROM users
......@@ -208,6 +258,7 @@ def admin_view_segment( folder_id, fpc ):
"""
username = config.db.query_fetchone( sql, ( folder_id, ) )[ "username" ]
# Get the list of annotations files
sql = """
SELECT id, uuid
FROM cnm_annotation
......@@ -219,7 +270,8 @@ def admin_view_segment( folder_id, fpc ):
"afis/admin/segment.html",
folder_id = folder_id,
fpc = fpc,
tenprint_id = tenprint_id,
tenprints_list = tenprints_list,
mark_list = mark_list,
username = username,
annotations = annotations,
segments_position_code = segments_position_code
......
......@@ -19,6 +19,20 @@
.icnml_list_of_boxes {
grid-template-columns: repeat( auto-fill, calc( var( --imgsize ) + 2 * var( --imgmargin ) ) );
}
.icnml_list_of_boxes_outer {
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px;
margin-bottom: 30px;
}
.icnml_list_of_boxes_desc {
position: relative;
top: -19px;
padding-left: 10px;
padding-right: 20px;
width: fit-content;
background-color: rgb( 238, 238, 238 );
}
#zoom_slider {
position: fixed;
width: 200px;
......@@ -68,38 +82,64 @@
{% include navigation %}
<div class="icnml_content">
<div class="icnml_list_of_boxes">
<div>
<div class="ui-widget-header ui-corner-top icnml_box_top">Segment preview</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
<div
class="icnml_pointer"
id="segment_preview"
style="background-image: url( {{ url_for( 'image.image_segment_serve', tenprint_id = tenprint_id, pc = fpc ) }} )">
<div class="icnml_list_of_boxes_outer">
<div class="icnml_list_of_boxes_desc">Tenprint images preview</div>
<div class="icnml_list_of_boxes">
{% for tenprint in tenprints_list %}
<div>
<div class="ui-widget-header ui-corner-top icnml_box_top">Segment {{ tenprint[ 'pc' ] }}</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
<div
class="icnml_pointer"
id="segment_preview_{{ tenprint[ 'file_uuid' ] }}"
style="background-image: url( {{ url_for( 'image.image_segment_serve', tenprint_id = tenprint[ 'tenprint' ], pc = tenprint[ 'pc' ] ) }} )">
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="icnml_list_of_boxes">
{% for a in annotations %}
<div id="annotations_{{ a[ 'uuid' ] }}_outer">
<div class="ui-widget-header ui-corner-top icnml_box_top">{{ a[ 'id' ] }}</div>
<div class="icnml_list_of_boxes_outer">
<div class="icnml_list_of_boxes_desc">Annotation illustration (from PiAnoS)</div>
<div class="icnml_list_of_boxes">
{% for a in annotations %}
<div id="annotations_{{ a[ 'uuid' ] }}_outer">
<div class="ui-widget-header ui-corner-top icnml_box_top">{{ a[ 'id' ] }}</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
<div
class="icnml_pointer"
id="annotation_{{ a[ 'uuid' ] }}"
style="background-image: url( {{ url_for( 'afis.admin_get_annotation_image', a_uuid = a[ 'uuid' ], folder_id = folder_id) }} )">
</div>
</div>
</div>
{% endfor %}
<div>
<div class="ui-widget-header ui-corner-top icnml_box_top">Add illustration</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
<div
class="icnml_pointer"
id="annotation_{{ a[ 'uuid' ] }}"
style="background-image: url( {{ url_for( 'afis.admin_get_annotation_image', a_uuid = a[ 'uuid' ], folder_id = folder_id) }} )">
<div>
<div id="segment_annotation_illustration_dropzone" class="dropzone icnml_pointer"></div>
</div>
</div>
</div>
{% endfor %}
<div>
<div class="ui-widget-header ui-corner-top icnml_box_top">Add illustration</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
</div>
</div>
<div class="icnml_list_of_boxes_outer">
<div class="icnml_list_of_boxes_desc">Marks</div>
<div class="icnml_list_of_boxes">
{% for mark in mark_list %}
<div>
<div id="segment_annotation_illustration_dropzone" class="dropzone icnml_pointer"></div>
<div class="ui-widget-header ui-corner-top icnml_box_top">Mark {{ mark[ 'id' ] }}</div>
<div class="ui-widget-content ui-corner-bottom icnml_box_content">
<div
class="icnml_pointer"
id="mark_preview_{{ mark[ 'uuid' ] }}"
style="background-image: url( {{ url_for( 'image.image_file_serve', file_id = mark[ 'uuid' ] ) }} )">
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<div id="zoom_slider"></div>
......
......@@ -2,11 +2,20 @@
# -*- coding: UTF-8 -*-
from flask import Blueprint
from flask import current_app
from flask import current_app, jsonify
from PIL import Image
from PiAnoS import caseExistsInDB
from functions import do_decrypt_dek
from utils.decorator import admin_required
from utils.template import my_render_template
from views.images import str2img
import config
pianos_view = Blueprint( "pianos", __name__, template_folder = "templates" )
@pianos_view.route( "/pianos_api" )
......@@ -19,3 +28,108 @@ def pianos_actions():
return my_render_template( "PiAnoS/actions.html" )
@pianos_view.route( "/pianos_api/add_user/all" )
@admin_required
def pianos_update_all_accounts():
"""
serve the function to update the users in PiAnoS
"""
current_app.logger.info( "Copy all accounts to PiAnoS" )
return jsonify( {
"error": not do_pianos_update_all_accounts()
} )
def do_pianos_update_all_accounts():
"""
Copy/update the credentials for all users.
This function keep the credentials in sync between ICNML and PiAnoS.
"""
try:
sql = """
SELECT users.username, users.password, account_type.name as g
FROM users
LEFT JOIN account_type ON users.type = account_type.id
WHERE users.password IS NOT NULL
"""
nb = 0
for user in config.db.query_fetchall( sql ):
nb += 1
username, h, group_name = user
current_app.logger.debug( "Copy the user '{}' to PiAnoS".format( username ) )
groupid = config.pianosdb.create_group( group_name )
pianos_user_id = config.pianosdb.create_user( username = username, hash = h, groupid = groupid )
config.pianosdb.reset_user( username, hash = h )
config.pianosdb.create_folder( "{}'s folder".format( username ), pianos_user_id, None, pianos_user_id )
config.pianosdb.commit()
current_app.logger.info( "{} users copied to PiAnoS".format( nb ) )
return True
except:
return False
@pianos_view.route( "/pianos_api/add_segments/all" )
@admin_required
def pianos_copy_all_segments():
"""
Route to push all segments to PiAnoS.
"""
current_app.logger.info( "Copy all segments to PiAnoS" )
return jsonify( {
"error": not do_pianos_copy_all_segments()
} )
def do_pianos_copy_all_segments():
"""
Copy all segments images to PiAnoS. If the case already exists, the image is not pushed to PiAnoS.
"""
try:
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_segments.pc,
files_v.resolution,
submissions.id as submissionid,
submissions.uuid as submissionuuid
FROM files_segments
LEFT JOIN files_v ON files_segments.tenprint = files_v.uuid
LEFT JOIN submissions ON files_v.folder = submissions.id
"""
for segment in config.db.query_fetchall( sql ):
data = do_decrypt_dek( segment[ "data" ], segment[ "submissionuuid" ] )
img = str2img( data )
current_app.logger.debug( "{}: {}".format( segment[ "uuid" ], img ) )
try:
folder_id = config.pianosdb.create_folder( "submission {}".format( segment[ "submissionid" ] ) )
case_name = "submission {} segment {}".format( segment[ "submissionid" ], segment[ "pc" ] )
config.pianosdb.create_exercise(
folder_id,
case_name, "",
img, segment[ "resolution" ],
empty_img_id, empty_img_res
)
except caseExistsInDB:
continue
except:
raise
config.pianosdb.commit()
return True
except:
return False
......@@ -13,6 +13,27 @@
<script type="text/javascript">
baseurl = "{{ baseurl }}";
var update_all = function()
{
$.ajax( {
url: "{{ url_for( 'pianos.pianos_update_all_accounts' ) }}",
dataType: "json",
success: function( data )
{
if( ! data.error )
{
toastr.success( "PiAnoS updated" );
} else {
toastr.error( "Error while updating" );
}
},
error: function()
{
toastr.error( "Network error" );
}
} );
}
</script>
</head>
<body class="icnml_main_layout">
......@@ -20,19 +41,16 @@
{% include navigation %}
<div class="icnml_content">
<div id="open_pianos_div">
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="open_pianos_button" role="button" aria-disabled="false">
<span class="ui-button-text" id="open_pianos_span">Open PiAnoS</span>
<div id="pianos_update_all_accounts_button_div">
<a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="pianos_update_all_accounts_button" role="button" aria-disabled="false">
<span class="ui-button-text" id="pianos_update_all_accounts_button_span_text">Copy all accounts to PiAnoS</span>
</a>
</div>
</div>
<script type="text/javascript">
$( "#open_pianos_button" )
.on( "click", function()
{
window.location = baseurl + "/pianos";
} );
$( "#pianos_update_all_accounts_button" )
.on( "click", update_all );
$( "#icnml_navigation_pianos" )
.addClass( "activated" );
......@@ -43,3 +61,4 @@
</script>
</body>
</html>