Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ def iban(iban) -> str:
{'key':'metatype', 'value': 'rule'}
)
tag_rules = [r.get('name') for r in tag_rules if r.get('name')]
tag_rules.sort()

cat_rules = parent.db_handler.filter_metadata(
{'key':'metatype', 'value': 'category'}
)
cat_rules = [r.get('name') for r in cat_rules if r.get('name')]
cat_rules.sort()

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

@current_app.route('/api/deleteMeta/', methods=['DELETE'], defaults={'uuid':None})
@current_app.route('/api/deleteMeta/<uuid>', methods=['DELETE'])
def deleteMeta(uuid):
"""
Löschen von Metadaten anhand der ID
Args (uri):
uuid, str: ID der zu löschenden Metadaten
Returns:
json: Informationen zum Ergebnis der Löschaktion
"""
if not uuid:
return {'error': 'No ID provided'}, 400

r = parent.db_handler.delete_metadata(uuid)
if not r.get('deleted'):
return {'error': f'No data deleted: {r.get("error")}'}, 400

return r, 200

@current_app.route('/api/upload/<iban>', methods=['POST'])
def uploadIban(iban):
"""
Expand Down
12 changes: 10 additions & 2 deletions app/static/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,13 @@ function apiGet(sub, params, callback, method = "GET") {
* @param {string} sub - The API endpoint to append to the base URL.
* @param {Object} params - An object containing key-value pairs to be sent as query parameters.
* @param {function} callback - A callback function to handle the response.
* Receives the response text and status code as arguments.
* Receives the response text and status code as arguments.
* @param {boolean} [isFile=false] - A switch to enable special file upload handling.
* @param {string} [force_method] - The HTTP method to use for the request (e.g., "POST", "PUT").
* If not provided, it will be determined based on the presence of
* a file in the parameters.
*/
function apiSubmit(sub, params, callback, isFile = false) {
function apiSubmit(sub, params, callback, isFile = false, force_method = undefined) {
const ajax = createAjax(callback);
let method;
let request_uri;
Expand All @@ -466,6 +469,11 @@ function apiSubmit(sub, params, callback, isFile = false) {
request_uri = JSON.stringify(params);
}

if (typeof force_method != "undefined") {
console.info("Setting method to", force_method.toUpperCase())
method = force_method.toUpperCase();
}

ajax.open(method, "/api/" + sub, true);

if (method != "POST") {
Expand Down
24 changes: 23 additions & 1 deletion app/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,35 @@ function saveSetting() {
showAjaxError(error, response);

} else {
alert('Einstellungen gespeichert' + response)
alert('Einstellungen gespeichert (' + response.inserted + ')');
result_text.value = '';

}
}, false);
}

/**
* Delete a value from Metadate by uuid.
* The key is selected via the select input element 'read-setting'.
*/
function deleteSetting() {
const setting_uuid = document.getElementById('read-setting').value;
if (!setting_uuid) {
alert('Kein Name einer Einstellung angegeben!');
return;
}

apiSubmit('deleteMeta/' + setting_uuid, {}, function (response, error) {
if (error) {
showAjaxError(error, response);

} else {
alert('Einstellung gelöscht !');
window.location.reload();

}
}, false, 'DELETE');
}

// ----------------------------------------------------------------------------
// -- API Functions -----------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ <h2>Settings</h2>
</select>
<textarea id="set-setting" placeholder="Setting Wert" rows="10" cols="15"></textarea>
</p>
<p>
<small>Settings ohne <i>uuid</i> werden als neuer Eintrag erstellt.</small>
</p>
<footer dir="rtl">
<button class="secondary" onclick="loadSetting()">Laden</button>
<button onclick="saveSetting()">Speichern</button>
<button class="delete" onclick="deleteSetting()">Löschen</button>
</footer>
</details>
</article>
Expand Down
11 changes: 11 additions & 0 deletions handler/BaseDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def set_metadata(self, entry: dict, overwrite: bool=True):
"""
raise NotImplementedError()

def delete_metadata(self, uuid: str):
"""
Löscht Metadaten aus der Datenbank.

Args:
uuid (str): Unique ID (key) der zu löschenden Metadaten.
Returns:
dict: Informationen über den Löschvorgang.
"""
raise NotImplementedError()

def get_group_ibans(self, group: str, check_before: bool=False):
"""
Ruft die Liste von IBANs einer Gruppe aus der Datenbank ab.
Expand Down
12 changes: 11 additions & 1 deletion handler/MongoDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ def set_metadata(self, entry, overwrite=True):

return {'inserted': 0}

def delete_metadata(self, uuid):
collection = self.connection['metadata']
delete_result = collection.delete_one({'uuid': uuid})
return {'deleted': delete_result.deleted_count}

def _form_condition(self, condition):
"""
Erstellt aus einem Condition-Dict eine entsprechende Query
Expand Down Expand Up @@ -300,7 +305,12 @@ def _form_condition(self, condition):
if condition_method == 'all':
stmt = {'$all': condition.get('value')}
if condition_method == 'exact':
stmt = {'$all': condition.get('value'), '$size': len(condition.get('value'))}
if not condition.get('value'):
# Empty lists
stmt = {'$size': 0}
else:
# Lists with exact members
stmt = {'$all': condition.get('value')}

# Nested or Plain Key
condition_key = condition.get('key')
Expand Down
5 changes: 5 additions & 0 deletions handler/TinyDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ def set_metadata(self, entry, overwrite=True):

return {'inserted': 0}

def delete_metadata(self, uuid):
collection = self.connection.table('metadata')
deleted_ids = collection.remove(Query().uuid == uuid)
return {'deleted': len(deleted_ids)}

def _form_where(self, condition):
"""
Erstellt aus einem Condition-Dict eine entsprechende Query
Expand Down
Loading