Skip to content

Commit 2073f6f

Browse files
authored
Merge pull request #69 from Pitastic/202060321_update
march update
2 parents 08f4445 + 227da79 commit 2073f6f

7 files changed

Lines changed: 86 additions & 4 deletions

File tree

app/routes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ def iban(iban) -> str:
159159
{'key':'metatype', 'value': 'rule'}
160160
)
161161
tag_rules = [r.get('name') for r in tag_rules if r.get('name')]
162+
tag_rules.sort()
163+
162164
cat_rules = parent.db_handler.filter_metadata(
163165
{'key':'metatype', 'value': 'category'}
164166
)
165167
cat_rules = [r.get('name') for r in cat_rules if r.get('name')]
168+
cat_rules.sort()
166169

167170
# All distinct Tags
168171
# (must be filtered on our own because TinyDB doesn't support 'distinct' queries)
@@ -390,6 +393,25 @@ def getMeta(rule_filter):
390393
meta = parent.db_handler.filter_metadata(condition=None)
391394
return meta, 200
392395

396+
@current_app.route('/api/deleteMeta/', methods=['DELETE'], defaults={'uuid':None})
397+
@current_app.route('/api/deleteMeta/<uuid>', methods=['DELETE'])
398+
def deleteMeta(uuid):
399+
"""
400+
Löschen von Metadaten anhand der ID
401+
Args (uri):
402+
uuid, str: ID der zu löschenden Metadaten
403+
Returns:
404+
json: Informationen zum Ergebnis der Löschaktion
405+
"""
406+
if not uuid:
407+
return {'error': 'No ID provided'}, 400
408+
409+
r = parent.db_handler.delete_metadata(uuid)
410+
if not r.get('deleted'):
411+
return {'error': f'No data deleted: {r.get("error")}'}, 400
412+
413+
return r, 200
414+
393415
@current_app.route('/api/upload/<iban>', methods=['POST'])
394416
def uploadIban(iban):
395417
"""

app/static/js/functions.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ function apiGet(sub, params, callback, method = "GET") {
446446
* @param {string} sub - The API endpoint to append to the base URL.
447447
* @param {Object} params - An object containing key-value pairs to be sent as query parameters.
448448
* @param {function} callback - A callback function to handle the response.
449-
* Receives the response text and status code as arguments.
449+
* Receives the response text and status code as arguments.
450450
* @param {boolean} [isFile=false] - A switch to enable special file upload handling.
451+
* @param {string} [force_method] - The HTTP method to use for the request (e.g., "POST", "PUT").
452+
* If not provided, it will be determined based on the presence of
453+
* a file in the parameters.
451454
*/
452-
function apiSubmit(sub, params, callback, isFile = false) {
455+
function apiSubmit(sub, params, callback, isFile = false, force_method = undefined) {
453456
const ajax = createAjax(callback);
454457
let method;
455458
let request_uri;
@@ -466,6 +469,11 @@ function apiSubmit(sub, params, callback, isFile = false) {
466469
request_uri = JSON.stringify(params);
467470
}
468471

472+
if (typeof force_method != "undefined") {
473+
console.info("Setting method to", force_method.toUpperCase())
474+
method = force_method.toUpperCase();
475+
}
476+
469477
ajax.open(method, "/api/" + sub, true);
470478

471479
if (method != "POST") {

app/static/js/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,35 @@ function saveSetting() {
190190
showAjaxError(error, response);
191191

192192
} else {
193-
alert('Einstellungen gespeichert' + response)
193+
alert('Einstellungen gespeichert (' + response.inserted + ')');
194194
result_text.value = '';
195195

196196
}
197197
}, false);
198198
}
199199

200+
/**
201+
* Delete a value from Metadate by uuid.
202+
* The key is selected via the select input element 'read-setting'.
203+
*/
204+
function deleteSetting() {
205+
const setting_uuid = document.getElementById('read-setting').value;
206+
if (!setting_uuid) {
207+
alert('Kein Name einer Einstellung angegeben!');
208+
return;
209+
}
210+
211+
apiSubmit('deleteMeta/' + setting_uuid, {}, function (response, error) {
212+
if (error) {
213+
showAjaxError(error, response);
214+
215+
} else {
216+
alert('Einstellung gelöscht !');
217+
window.location.reload();
218+
219+
}
220+
}, false, 'DELETE');
221+
}
200222

201223
// ----------------------------------------------------------------------------
202224
// -- API Functions -----------------------------------------------------------

app/templates/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,13 @@ <h2>Settings</h2>
231231
</select>
232232
<textarea id="set-setting" placeholder="Setting Wert" rows="10" cols="15"></textarea>
233233
</p>
234+
<p>
235+
<small>Settings ohne <i>uuid</i> werden als neuer Eintrag erstellt.</small>
236+
</p>
234237
<footer dir="rtl">
235238
<button class="secondary" onclick="loadSetting()">Laden</button>
236239
<button onclick="saveSetting()">Speichern</button>
240+
<button class="delete" onclick="deleteSetting()">Löschen</button>
237241
</footer>
238242
</details>
239243
</article>

handler/BaseDb.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ def set_metadata(self, entry: dict, overwrite: bool=True):
321321
"""
322322
raise NotImplementedError()
323323

324+
def delete_metadata(self, uuid: str):
325+
"""
326+
Löscht Metadaten aus der Datenbank.
327+
328+
Args:
329+
uuid (str): Unique ID (key) der zu löschenden Metadaten.
330+
Returns:
331+
dict: Informationen über den Löschvorgang.
332+
"""
333+
raise NotImplementedError()
334+
324335
def get_group_ibans(self, group: str, check_before: bool=False):
325336
"""
326337
Ruft die Liste von IBANs einer Gruppe aus der Datenbank ab.

handler/MongoDb.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ def set_metadata(self, entry, overwrite=True):
257257

258258
return {'inserted': 0}
259259

260+
def delete_metadata(self, uuid):
261+
collection = self.connection['metadata']
262+
delete_result = collection.delete_one({'uuid': uuid})
263+
return {'deleted': delete_result.deleted_count}
264+
260265
def _form_condition(self, condition):
261266
"""
262267
Erstellt aus einem Condition-Dict eine entsprechende Query
@@ -300,7 +305,12 @@ def _form_condition(self, condition):
300305
if condition_method == 'all':
301306
stmt = {'$all': condition.get('value')}
302307
if condition_method == 'exact':
303-
stmt = {'$all': condition.get('value'), '$size': len(condition.get('value'))}
308+
if not condition.get('value'):
309+
# Empty lists
310+
stmt = {'$size': 0}
311+
else:
312+
# Lists with exact members
313+
stmt = {'$all': condition.get('value')}
304314

305315
# Nested or Plain Key
306316
condition_key = condition.get('key')

handler/TinyDb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ def set_metadata(self, entry, overwrite=True):
310310

311311
return {'inserted': 0}
312312

313+
def delete_metadata(self, uuid):
314+
collection = self.connection.table('metadata')
315+
deleted_ids = collection.remove(Query().uuid == uuid)
316+
return {'deleted': len(deleted_ids)}
317+
313318
def _form_where(self, condition):
314319
"""
315320
Erstellt aus einem Condition-Dict eine entsprechende Query

0 commit comments

Comments
 (0)