File tree 4 files changed +78
-5
lines changed
4 files changed +78
-5
lines changed Original file line number Diff line number Diff line change @@ -434,6 +434,26 @@ def request(self, identifier):
434
434
return self .all_info [identifier ]
435
435
except :
436
436
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
+
437
457
438
458
def find (self , criteria ):
439
459
'''
Original file line number Diff line number Diff line change @@ -89,13 +89,31 @@ def save():
89
89
return {'success' : False , 'message' : str (e )}
90
90
91
91
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
+
92
109
@app .route ('/download' , method = 'GET' )
93
110
def download ():
94
111
hash_id = bottle .request .query .get ('id' , '' )
95
- dwn_type = bottle .request .query .get ('type' , '' )
96
112
fullpath = meta_db .request (hash_id )['filename' ]
97
113
path , filename = os .path .split ( fullpath )
98
-
114
+
115
+ dwn_type = bottle .request .query .get ('type' , '' )
116
+
99
117
if dwn_type == 'metadata' :
100
118
return bottle .static_file (filename , root = path , download = filename )
101
119
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ <h4 class='header'>Browse</h4>
150
150
</ div >
151
151
152
152
< 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; " >
154
154
</ ul >
155
155
</ div >
156
156
@@ -227,7 +227,19 @@ <h4 class='header'>Search</h4>
227
227
< a href ="#! " class ="modal-close waves-effect waves-green btn-flat disabled " id ="modal_btn "> Done</ a >
228
228
</ div >
229
229
</ 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
+
231
243
<!-- partial -->
232
244
< script src ="/static/js/jquery.min.js "> </ script >
233
245
< script src ="/static/js/materialize.min.js "> </ script >
Original file line number Diff line number Diff line change @@ -104,11 +104,34 @@ function refresh_info () {
104
104
$ ( '#project-list' ) . html ( '' ) ;
105
105
let prj_name = $ ( "#project-select" ) . val ( ) ;
106
106
$ . 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>' ) ) ;
108
108
} )
109
109
} )
110
110
}
111
111
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
+
112
135
// INITIALIZATION OF AUTOCOMPLETE LIST
113
136
function get_available_options ( ) {
114
137
$ . get ( '/known' ) . success ( function ( data ) {
You can’t perform that action at this time.
0 commit comments