Skip to content

Commit c874b60

Browse files
committed
Added the possibility to delete metadata files and their descriptors from the library and the web UI
1 parent d5af824 commit c874b60

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

metadata_db.py

+20
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,26 @@ def request(self, identifier):
434434
return self.all_info[identifier]
435435
except:
436436
return {}
437+
438+
def remove (self, identifier):
439+
'''
440+
Phisically delete the metadata file and its descriptor
441+
'''
442+
info = self.request(identifier)
443+
444+
metadata_file = info['filename']
445+
info_file = metadata_file + '.info'
446+
447+
try:
448+
os.remove(metadata_file)
449+
os.remove(info_file)
450+
451+
self.refresh_all_info()
452+
return True
453+
454+
except:
455+
return False
456+
437457

438458
def find(self, criteria):
439459
'''

metadata_db_server.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,31 @@ def save():
8989
return {'success' : False, 'message' : str(e)}
9090

9191

92+
@app.route('/delete', method='GET')
93+
def delete_metadata_file():
94+
hash_id = bottle.request.query.get('id', '')
95+
96+
if hash_id:
97+
fullpath = meta_db.request(hash_id)['filename']
98+
99+
try:
100+
meta_db.remove(hash_id)
101+
return {'success' : True, 'message' : 'Metadata file successfully deleted.'}
102+
103+
except Exception as e:
104+
return {'success' : False, 'message' : str(e)}
105+
else:
106+
return {'success' : False, 'message' : 'A valid identifier must be provided'}
107+
108+
92109
@app.route('/download', method='GET')
93110
def download():
94111
hash_id = bottle.request.query.get('id', '')
95-
dwn_type = bottle.request.query.get('type', '')
96112
fullpath = meta_db.request(hash_id)['filename']
97113
path, filename = os.path.split( fullpath )
98-
114+
115+
dwn_type = bottle.request.query.get('type', '')
116+
99117
if dwn_type == 'metadata':
100118
return bottle.static_file (filename, root=path, download=filename)
101119

static/index.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ <h4 class='header'>Browse</h4>
150150
</div>
151151

152152
<div class="row col s12">
153-
<ul class="collection col s6" id="project-list">
153+
<ul class="collection col s6" id="project-list" style="border:0px;">
154154
</ul>
155155
</div>
156156

@@ -227,7 +227,19 @@ <h4 class='header'>Search</h4>
227227
<a href="#!" class="modal-close waves-effect waves-green btn-flat disabled" id="modal_btn">Done</a>
228228
</div>
229229
</div>
230-
230+
231+
<!-- Refresh Modal Structure -->
232+
<div id="delete_modal" class="modal">
233+
<div class="modal-content">
234+
<p id="modal_delete_text">Are you sure you want to delete this metadata file? This cannot be undone.</p>
235+
</div>
236+
<div class="modal-footer">
237+
<a href="#!" class="modal-close waves-effect waves-green btn-flat" id="modal_delete_confirm_btn">Delete</a>
238+
<a href="#!" class="modal-close waves-effect waves-green btn-flat" id="modal_delete_cancel_btn">Cancel</a>
239+
240+
</div>
241+
</div>
242+
231243
<!-- partial -->
232244
<script src="/static/js/jquery.min.js"></script>
233245
<script src="/static/js/materialize.min.js"></script>

static/js/script.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,34 @@ function refresh_info () {
104104
$('#project-list').html('');
105105
let prj_name = $("#project-select").val();
106106
$.each(data[prj_name], function (filename, identifier) {
107-
$('#project-list').append($('<a href="#" class="collection-item" onclick="update_browser(\''+identifier+'\');return false;"></a>').text(filename));
107+
$('#project-list').append($('<a href="#" class="collection-item" onclick="update_browser(\''+identifier+'\');return false;" style="display:inline-block">'+filename+'</a><a class="fa fa-trash" style="color:grey;float:right;margin-top:15px;" onclick="delete_metadata(\''+identifier+'\');"></a>'));
108108
})
109109
})
110110
}
111111

112+
function delete_metadata(identifier) {
113+
114+
$('#delete_modal').show();
115+
$('#delete_modal').focus();
116+
117+
$('#modal_delete_cancel_btn').click(function(){
118+
$('#delete_modal').hide();
119+
});
120+
121+
$('#modal_delete_confirm_btn').click(function(){
122+
$.ajax({
123+
url: '/delete',
124+
timeout: 60 * 1000,
125+
data : {'id' : identifier},
126+
type: 'GET'
127+
}).success( function( data ){
128+
$('#modal_delete_text').html(data.message);
129+
$('#modal_delete_confirm_btn').addClass("disabled");
130+
$('#modal_delete_cancel_btn').text("OK");
131+
});
132+
});
133+
}
134+
112135
// INITIALIZATION OF AUTOCOMPLETE LIST
113136
function get_available_options () {
114137
$.get( '/known').success( function( data ){

0 commit comments

Comments
 (0)