Files
photoassistant/templates/dups.html

232 lines
14 KiB
HTML

{% extends "base.html" %} {% block main_content %}
<div class="container-fluid">
<h3 class="offset-2">{{page_title}}</h3>
<div class="row">
<form id="psform" class="d-flex justify-content-center form-inline" method="POST" action="">
<input type="hidden" name="fe_msg_id" value="{{fe_msg_id}}"></input>
<h6>
<div class="input-group">
<label class="input-group-text" for="pagesize">{{DD.total_dups}} duplicate files ({{DD.uniq_dups}} Unique) -- Showing&nbsp;</label>
<select id="pagesize" class="form-select" name="pagesize" onChange="ResetPageSize()">
{% for o in "5", "10", "15", "20", "25", "50", "75", "100", "200", "500", "1000", "5000", "20000" %}
<option
{% if o|int == pagesize %}
selected
{% endif %}
>{{o}}</option>
{% endfor %}
</select>
<span class="input-group-text">&nbsp;duplicates at a time &nbsp;
<svg width="16" height="16" fill="currentColor">
<use xlink:href="{{url_for('internal', filename='icons.svg')}}#info" onMouseOver="$('#dbox').modal('show'); return false;"/>
</svg>
</span>
</div class="input-group">
</h6>
</form>
</div class="row">
<script>
let D=[]
let F=[]
function ResetPageSize()
{
console.log( $("#pagesize").val() )
$("#psform").submit()
return false;
}
$('#dbox-title').html('Duplicate Files Processing (info)')
div=`
<p>The duplicates are shown below ({{pagesize}} at a time) in a per set of files or sets of directories</p>
<p>The per file sets are shown with the title 'Choose between these fiels' and show a series of duplicate files in a row, that comprise one of:</p>
<ul>
<li>3 or more of the same file</li>
<li>different file names in the same or different directories</li>
</ul>
<p>The per direcory sets are shown with the title 'Choose path to KEEP...' and show a series of directories in a row, that contain duplicate files. In this view duplicates have the same file name and any other files in these directories that are not duplicates will not be deleted</p>
<p>TO BE CLEAR: after you click the "Delete Duplicates" button, the files in red and duplicate files in directories in red will be deleted from the file system</p>
`
$('#dbox-content').html(div)
function KeepFile(row, which, al)
{
$('[id^=kf' + row + '-f]').attr('class', 'alert alert-danger sm-txt py-1')
$('[id^=kf' + row + '-f]').attr('class', 'alert alert-danger sm-txt py-1')
$('#kf'+row+'-f'+which).attr('class', 'alert alert-' + al + ' py-1')
$('#kfid-'+row).val( F[row.toString()+which.toString()] )
}
function KeepDir(row, which)
{
$('[id^=kd'+row+'-d]').attr('class', 'alert alert-danger sm-txt py-1')
$('#kd'+row+'-d'+which).attr('class', 'alert alert-success py-1')
$('#kdid-'+row).val( D[row.toString()+which.toString()] )
}
</script>
<div class="row">
<form class="form form-inline col-12" action="{{url_for('rm_dups')}}" method="POST">
{# pass this through so that the back-end can delete this message when it rm_dups #}
<input type="hidden" name="fe_msg_id" value={{fe_msg_id}}>
{% set auto=namespace(str="") %}
{% set page=namespace(cnt=0) %}
{% set pref=namespace(have="") %}
{% set count=namespace( del=0, keep=0 ) %}
{% set all_count=namespace( d_files=0, k_files=0, md_files=0, mk_files=0, manual=0 ) %}
{% set kfid=namespace( count=0 ) %}
{# for each hash in ip_to_sp_dups_*, auto keep the _keep, auto delete the _del, only need hidden input #}
{% for h in DD.ip_to_sp_dups_keep %}
{% set kfid.count = kfid.count+1 %}
<input type="hidden" name="kfhash-{{kfid.count}}" value="{{h}}">
<input type="hidden" name="kfid-{{kfid.count}}" value="{{DD.ip_to_sp_dups_keep[h].id}}">
{% set count.keep = count.keep+1 %}
{% set count.del = count.del + DD.ip_to_sp_dups_del[h]|length %}
{% endfor %}
{% if count.keep %}
{% set auto.str = auto.str + "<li>Keeping {} files in storage path and deleting {} from import path</li>".format(count.keep, count.del) %}
{% set all_count.k_files = all_count.k_files + count.keep %}
{% set all_count.d_files = all_count.d_files + count.del %}
{% endif %}
<h5 class="col-12">Choose between these files:</h5>
{% set count=namespace( del=0, keep=0, man_del=0, man_keep=0 ) %}
{% for dups in DD.per_file_dups %}
{% set outer_loop=loop.index %}
{% set pref.have="" %}
{% for dup in dups %}
{# for each hash in preferred_file, auto keep it, only need hidden input, dont process further #}
{% if DD.preferred_file[dup.h] %}
{% set pref.have = "True" %}
{% if DD.preferred_file[dup.h] == dup.id %}
{% set kfid.count = kfid.count+1 %}
<input type="hidden" name="kfhash-{{kfid.count}}" value="{{dup.h}}">
<input type="hidden" name="kfid-{{kfid.count}}" value="{{dup.id}}">
{% set count.keep = count.keep + 1 %}
{% else %}
{% set count.del = count.del + 1 %}
{% endif %}
{% else %}
{# okay, show an alert / make it choosable for each of these manually processed dups #}
{% if loop.index == 1 %}
{% set all_count.manual = all_count.manual + 1 %}
{# we arent necessarily keeping this one, but we count the first as manual keep, the rest as manual del #}
{# sometimes we are both in an import dir and have multiple copies in storage dir, dont double count keep, we will keep 1 from earlier code for this hash #}
{% if dup.h not in DD.ip_to_sp_dups_keep %}
{% set count.man_keep = count.man_keep + 1 %}
{% endif %}
{% set count.man_del = count.man_del + dups|length-1 %}
{% endif %}
{% if page.cnt <= pagesize %}
{% if loop.index == 1 %}
<div class="col-12 py-2">
{% set kfid.count = kfid.count+1 %}
<input type="hidden" name="kfhash-{{kfid.count}}" value="{{dup.h}}">
<input type="hidden" id="kfid-{{kfid.count}}" name="kfid-{{kfid.count}}" value="">
{% endif %}
<alert id="kf{{kfid.count}}-f{{loop.index}}" style="cursor: pointer;" class="alert"
onClick="KeepFile({{kfid.count}},{{loop.index}},'success')">{{dup.d}}/{{dup.f}}</alert>
{% if DD.preferred_file[dup.h] == dup.id %}
{% set pref.have="kf{}-f{}".format(outer_loop,loop.index) %}
{% endif %}
{% if loop.index < dups|length %}
or
{% endif %}
<script>
F[{{kfid.count}}{{loop.index}}]="{{dup.id}}"
</script>
{% if loop.index == dups|length %}
</div class="col-12">
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if pref.have == "" %}
<script>KeepFile( {{kfid.count}}, 1,'warning' )</script>
{% set page.cnt = page.cnt + 1 %}
{% endif %}
{% endfor %}
{% if count.keep %}
{% set auto.str = auto.str + "<li>Keeping {} files inside storage path, Deleting {} duplicates files from storage path</li>".format(count.keep, count.del) %}
{% set all_count.k_files = all_count.k_files + count.keep %}
{% set all_count.d_files = all_count.d_files + count.del %}
{% set all_count.mk_files = count.man_keep %}
{% set all_count.md_files = count.man_del %}
{% endif %}
{% set count=namespace( keep_d=0, keep_f=0, m_files=0, m_dirs=0 ) %}
{% for dup in DD.per_path_dups %}
{% if DD.preferred_path[dup.did1] or DD.preferred_path[dup.did2] %}
<input name="kdhash-{{loop.index}}" type="hidden" value="{{dup.hashes}}">
{% if DD.preferred_path[dup.did1] %}
<input type="hidden" name="kdid-{{loop.index}}" value="{{dup.did1}}">
{% else %}
<input type="hidden" name="kdid-{{loop.index}}" value="{{dup.did2}}">
{% endif %}
{% set count.keep_d = count.keep_d + 1 %}
{% set count.keep_f = count.keep_f + dup.hashes|wordcount %}
{% else %}
{% set all_count.manual = all_count.manual + 1 %}
{% set count.m_files = count.m_files + dup.hashes|wordcount %}
{% set count.m_dirs = count.m_dirs +1 %}
{% if page.cnt <= pagesize %}
<div class="col-12 py-2">
<h5 class="col-12 mt-3">Choose path to KEEP (same file names in 2 different directories):</h5>
{{dup.count}} duplicates in:
{% if dup.d1 == "" %}
{% set d1="/" %}
{% else %}
{% set d1=dup.d1 %}
{% endif %}
{% if dup.d2 == "" %}
{% set d2="/" %}
{% else %}
{% set d2=dup.d2 %}
{% endif %}
<alert id="kd{{loop.index}}-d1" style="cursor: pointer;" onClick="KeepDir({{loop.index}}, 1)" class="alert">{{d1}}</alert> or
<alert id="kd{{loop.index}}-d2" style="cursor: pointer;" onClick="KeepDir({{loop.index}}, 2)" class="alert">{{d2}}</alert>
<input id="kdid-{{loop.index}}" type="hidden" name="kdid-{{loop.index}}">
<input name="kdhash-{{loop.index}}" type="hidden" value="{{dup.hashes}}">
<script>
D[{{loop.index}}1]="{{dup.did1}}"
D[{{loop.index}}2]="{{dup.did2}}"
</script>
</div>
{% set page.cnt = page.cnt + 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% if count.keep_d %}
<div class="col-12">
{% set auto.str = auto.str + "<li>Keeping {} files in {} paths, Deleting={} file in {} paths</li>".format( count.keep_f, count.keep_d, count.keep_f, count.keep_d) %}
{% set all_count.k_files = all_count.k_files + count.keep_f %}
{% set all_count.d_files = all_count.d_files + count.keep_f %}
{% set all_count.mk_files = all_count.mk_files + count.m_files %}
{% set all_count.md_files = all_count.md_files + count.m_files %}
</div>
{% endif %}
{% if auto.str|length %}
<alert class="alert alert-info">AUTOMATICALLY matched naming conventions resulting in:
<ul>
{{auto.str|safe}}
</ul>
Automatically Keeping {{all_count.k_files}} files and deleting {{all_count.d_files}} files<br>
Leaving {{all_count.manual}} manual choices to make (to keep {{all_count.mk_files}} files and delete {{all_count.md_files}} files)
{#
So by counting/double-check, uniq files kept = {{all_count.k_files+all_count.mk_files}}, overall dups = {{all_count.k_files+all_count.d_files+all_count.mk_files+all_count.md_files}}
#}
</alert>
{% endif %}
<div class="col-12"></div>
<input class="btn btn-danger mt-2" type="submit" value="Delete Duplicates">
</form>
</div class="row">
</div class="container">
{% endblock main_content %}
{% block script_content %}
<script>
// force choose last of each dir set
$('[id$=d2]').each( function() { $(this).click() } )
</script>
{% endblock script_content %}