From 6d7e38dba65de6325cc499f163ec32422835cf46 Mon Sep 17 00:00:00 2001 From: Morg42 <43153739+Morg42@users.noreply.github.com> Date: Mon, 14 Oct 2024 09:27:22 +0200 Subject: [PATCH] database: change selection to modal dialogue --- database/__init__.py | 21 ++++++---- database/webif/__init__.py | 8 ++-- database/webif/static/style.css | 37 +++++++++++++++++ database/webif/templates/index.html | 64 +++++++++++++++++++++-------- 4 files changed, 102 insertions(+), 28 deletions(-) create mode 100644 database/webif/static/style.css diff --git a/database/__init__.py b/database/__init__.py index 086251a90..4128c5dc1 100755 --- a/database/__init__.py +++ b/database/__init__.py @@ -976,15 +976,18 @@ def reassign_orphaned_id(self, orphan_id, to): :type orphan_id: int :type to: int """ - self.logger.error(f'reassign called: {orphan_id} -> {to}') - cur = self._db_maint.cursor() - self._execute(self._prepare("UPDATE {log} SET item_id = :newid WHERE item_id = :orphanid;"), {'newid': to, 'orphanid': orphan_id}, cur=cur) - self._execute(self._prepare("DELETE FROM {item} WHERE id = :orphanid LIMIT 1;"), {'orphanid': orphan_id}, cur=cur) - self.logger.info(f'reassigned orphaned id {orphan_id} to new id {to}') - cur.close() - self._db_maint.commit() - self.logger.debug('rebuilding orphan list') - self.build_orphanlist() + try: + self.logger.warning(f'reassigning orphaned data from (old) id {orphan_id} to (new) id {to}') + cur = self._db_maint.cursor() + self._execute(self._prepare("UPDATE {log} SET item_id = :newid WHERE item_id = :orphanid;"), {'newid': to, 'orphanid': orphan_id}, cur=cur) + self._execute(self._prepare("DELETE FROM {item} WHERE id = :orphanid LIMIT 1;"), {'orphanid': orphan_id}, cur=cur) + self.logger.warning(f'reassigned orphaned id {orphan_id} to new id {to}') + cur.close() + self._db_maint.commit() + self.logger.warning('rebuilding orphan list') + self.build_orphanlist() + except Exception as e: + self.logger.error(f'error on reassigning id {orphan_id} to {to}: {e}') def _delete_orphan(self, item_path): """ diff --git a/database/webif/__init__.py b/database/webif/__init__.py index d31a4b270..79b10c6dd 100755 --- a/database/webif/__init__.py +++ b/database/webif/__init__.py @@ -63,7 +63,7 @@ def __init__(self, webif_dir, plugin): @cherrypy.expose def index(self, reload=None, action=None, item_id=None, item_path=None, time_end=None, day=None, month=None, year=None, - time_orig=None, changed_orig=None, orphanID=None, newID=None): + time_orig=None, changed_orig=None, orphan_id=None, new_id=None): """ Build index.html for cherrypy @@ -76,8 +76,10 @@ def index(self, reload=None, action=None, item_id=None, item_path=None, time_end if item_path is not None: item = self.plugin.items.return_item(item_path) delete_triggered = False - if orphanID is not None and newID is not None and orphanID != newID: - self.plugin.reassign_orphaned_id(orphanID, to=newID) + self.logger.error(f'index called with oid {orphan_id} and nid {new_id}') + if orphan_id is not None and new_id is not None and orphan_id != new_id: + self.logger.error(f'calling reassign for {orphan_id} and {new_id}') + self.plugin.reassign_orphaned_id(orphan_id, to=new_id) if action is not None: if action == "delete_log" and item_id is not None: if time_orig is not None and changed_orig is not None: diff --git a/database/webif/static/style.css b/database/webif/static/style.css new file mode 100644 index 000000000..94a8b7bf9 --- /dev/null +++ b/database/webif/static/style.css @@ -0,0 +1,37 @@ +/* The Modal (background) */ +.or-modal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 999; /* Sit on top */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ +} + +/* Modal Content/Box */ +.or-modal-content { + background-color: #fefefe; + margin: 15% auto; /* 15% from the top and centered */ + padding: 20px; + border: 1px solid #888; + width: 80%; /* Could be more or less, depending on screen size */ +} + +/* The Close Button */ +.or-close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.or-close:hover, +.or-close:focus { + color: black; + text-decoration: none; + cursor: pointer; +} \ No newline at end of file diff --git a/database/webif/templates/index.html b/database/webif/templates/index.html index 9939883f1..c65e8a91a 100755 --- a/database/webif/templates/index.html +++ b/database/webif/templates/index.html @@ -4,6 +4,10 @@ {% set dataSet = 'overview' %} {% set tab1title = _('Database Items') %} +{% block pluginstyles %} + +{% endblock pluginstyles %} + {%- block pluginscripts %} {{ super() }} +
+
+ × +
+ Neuzuweisen von Itemreihe (ID ) +
+
+ Bitte wählen Sie die Itemreihe aus, der die verwaisten Daten zugewiesen werden sollen: + + + +
+
+
+
{% if p.remove_orphan or len(p.orphanlist) == 0 %} @@ -214,16 +255,7 @@ {{ _(p.db_itemtype(item)) }} {{ itemid }} - - + {% if p.count_logentries %} {{ p._orphan_logcount[p.id(item, create=False)] }}