From 9713f9ba90ea41eff403616fc91e3ab21b4da483 Mon Sep 17 00:00:00 2001 From: Jordan Blasenhauer Date: Wed, 7 Aug 2024 16:20:27 +0200 Subject: [PATCH] update instances and jobs pages * add new list data in instances * update jobs page adding history modal * avoid objet key access on Title and Subtitle * update gitignore to add logs build --- src/ui/builder/instances.py | 2 + src/ui/builder/jobs.py | 96 +- src/ui/client/dashboard/.gitignore | 2 + .../dashboard/components/Forms/Field/List.vue | 2 +- .../dashboard/components/Widget/Subtitle.vue | 2 +- .../dashboard/components/Widget/Title.vue | 3 +- src/ui/client/dashboard/lang/en.json | 6 +- src/ui/client/dashboard/pages/jobs/index.html | 2 +- src/ui/client/dashboard/pages/logs/Logs.vue | 66 + src/ui/client/dashboard/pages/logs/index.html | 24 + src/ui/client/dashboard/pages/logs/logs.js | 11 + src/ui/client/dashboard/utils/global.js | 2 +- src/ui/client/input.css | 4 + src/ui/client/public/css/style.css | 2 +- src/ui/client/tests/builder/instances.py | 22 +- src/ui/client/tests/builder/jobs.py | 96 +- src/ui/client/tests/jobs.json | 1991 ++++++++++++++- src/ui/client/tests/jobs.py | 102 +- src/ui/client/tests/jobs.txt | 2 +- src/ui/client/widgets/widgets.py | 2146 ----------------- src/ui/main.py | 5 +- 21 files changed, 2266 insertions(+), 2322 deletions(-) create mode 100644 src/ui/client/dashboard/pages/logs/Logs.vue create mode 100644 src/ui/client/dashboard/pages/logs/index.html create mode 100644 src/ui/client/dashboard/pages/logs/logs.js delete mode 100644 src/ui/client/widgets/widgets.py diff --git a/src/ui/builder/instances.py b/src/ui/builder/instances.py index 12e3b1564..8f75564cf 100644 --- a/src/ui/builder/instances.py +++ b/src/ui/builder/instances.py @@ -43,6 +43,8 @@ def instances_builder(instances: List[Instance]) -> str: instance = instance_widget( containerColumns={"pc": 6, "tablet": 6, "mobile": 12}, pairs=[ + {"key": "instances_name", "value": instance.name}, + {"key": "instances_type", "value": instance.type}, {"key": "instances_method", "value": instance.method}, {"key": "instances_creation_date", "value": instance.creation_date.strftime("%d-%m-%Y %H:%M:%S")}, {"key": "instances_last_seen", "value": instance.last_seen.strftime("%d-%m-%Y %H:%M:%S")}, diff --git a/src/ui/builder/jobs.py b/src/ui/builder/jobs.py index 1bc5ca782..bd1d1209b 100644 --- a/src/ui/builder/jobs.py +++ b/src/ui/builder/jobs.py @@ -29,14 +29,14 @@ def jobs_builder(jobs): "widgets": [ title_widget("jobs_title"), table_widget( - positions=[2, 2, 1, 1, 1, 2, 3], + positions=[3, 2, 1, 1, 1, 1, 3], header=[ "jobs_table_name", "jobs_table_plugin_id", "jobs_table_interval", "jobs_table_reload", "jobs_table_success", - "jobs_table_last_run_date", + "jobs_table_history", "jobs_table_cache_downloadable", ], items=jobs_list, @@ -46,7 +46,7 @@ def jobs_builder(jobs): "filterName": "keyword", "type": "keyword", "value": "", - "keys": ["name", "plugin_id", "last_run"], + "keys": ["name", "plugin_id"], "field": { "id": "jobs-keyword", "value": "", @@ -150,22 +150,100 @@ def get_jobs_list(jobs): # loop on each value for k, v in value.items(): # override widget type for some keys - if k in ("reload", "success"): + if k in ("reload", "history"): + is_success = v if k == "reload" else v[0].get("success") item.append( { - k: "success" if v else "failed", + k: "success" if is_success else "failed", "type": "Icons", "data": { - "iconName": "check" if v else "cross", + "iconName": "check" if is_success else "cross", }, } ) - continue - if k in ("plugin_id", "every", "last_run"): + if k not in ("history"): + continue + + if k in ("plugin_id", "every"): item.append({k: v, "type": "Text", "data": {"text": v}}) continue + if k in ("history"): + items = [] + for hist in v: + items.append( + [ + { + "type": "Text", + "data": { + "text": hist["start_date"], + }, + }, + { + "type": "Text", + "data": { + "text": hist["end_date"], + }, + }, + { + "type": "Icons", + "data": { + "iconName": "check" if hist["success"] else "cross", + }, + }, + ] + ) + + item.append( + { + "type": "Button", + "data": { + "id": f"open-modal-history-{k}", + "text": "jobs_history", + "hideText": True, + "color": "blue", + "size": "normal", + "iconName": "document", + "iconColor": "white", + "modal": { + "widgets": [ + {"type": "Title", "data": {"title": key}}, + {"type": "Subtitle", "data": {"subtitle": "jobs_history_subtitle"}}, + { + "type": "Table", + "data": { + "title": "jobs_history_table_title", + "minWidth": "", + "header": [ + "jobs_table_start_run", + "jobs_table_end_run", + "jobs_table_success", + ], + "positions": [5, 5, 2], + "items": items, + }, + }, + { + "type": "ButtonGroup", + "data": { + "buttons": [ + { + "id": f"close-history-{k}", + "text": "action_close", + "color": "close", + "size": "normal", + "attrs": {"data-close-modal": ""}, + } + ] + }, + }, + ] + }, + }, + } + ) + if k in ("cache") and len(v) <= 0: item.append({k: v, "type": "Text", "data": {"text": ""}}) continue @@ -201,7 +279,7 @@ def get_jobs_list(jobs): }, "overflowAttrEl": "data-table-body", "containerClass": "table download-cache-file", - "maxBtnChars": 12, + "maxBtnChars": 16, "popovers": [ { "iconName": "info", diff --git a/src/ui/client/dashboard/.gitignore b/src/ui/client/dashboard/.gitignore index fa7b31d54..fa24f223b 100644 --- a/src/ui/client/dashboard/.gitignore +++ b/src/ui/client/dashboard/.gitignore @@ -1,5 +1,6 @@ # Logs logs +!pages/logs *.log npm-debug.log* yarn-debug.log* @@ -7,6 +8,7 @@ yarn-error.log* pnpm-debug.log* lerna-debug.log* + node_modules dist dist-ssr diff --git a/src/ui/client/dashboard/components/Forms/Field/List.vue b/src/ui/client/dashboard/components/Forms/Field/List.vue index 95811743d..cc1f65f45 100644 --- a/src/ui/client/dashboard/components/Forms/Field/List.vue +++ b/src/ui/client/dashboard/components/Forms/Field/List.vue @@ -312,7 +312,7 @@ function closeTab(e) { /** * @name addEntry * @description When clicking add entry or key "Enter", will add the current input value to list. - * @param {e} e - The event object. + * @param {event} e - The event object. * @returns {void} */ function addEntry(e) { diff --git a/src/ui/client/dashboard/components/Widget/Subtitle.vue b/src/ui/client/dashboard/components/Widget/Subtitle.vue index 4ed488eb3..dce91ac02 100644 --- a/src/ui/client/dashboard/components/Widget/Subtitle.vue +++ b/src/ui/client/dashboard/components/Widget/Subtitle.vue @@ -76,7 +76,7 @@ const subtitleEl = ref(null); onMounted(() => { subtitle.class = - props.subtitleClass || subtitleEl.value.closest("[data-is]") + props.subtitleClass || subtitleEl?.value?.closest("[data-is]") ? `subtitle-${subtitleEl.value .closest("[data-is]") .getAttribute("data-is")}` diff --git a/src/ui/client/dashboard/components/Widget/Title.vue b/src/ui/client/dashboard/components/Widget/Title.vue index 710688c82..e9c01865a 100644 --- a/src/ui/client/dashboard/components/Widget/Title.vue +++ b/src/ui/client/dashboard/components/Widget/Title.vue @@ -1,5 +1,6 @@ diff --git a/src/ui/client/dashboard/pages/logs/Logs.vue b/src/ui/client/dashboard/pages/logs/Logs.vue new file mode 100644 index 000000000..785a03053 --- /dev/null +++ b/src/ui/client/dashboard/pages/logs/Logs.vue @@ -0,0 +1,66 @@ + + + diff --git a/src/ui/client/dashboard/pages/logs/index.html b/src/ui/client/dashboard/pages/logs/index.html new file mode 100644 index 000000000..6c28d6590 --- /dev/null +++ b/src/ui/client/dashboard/pages/logs/index.html @@ -0,0 +1,24 @@ + + + + + + + + + BunkerWeb | Logs + + + + + +
+ + + diff --git a/src/ui/client/dashboard/pages/logs/logs.js b/src/ui/client/dashboard/pages/logs/logs.js new file mode 100644 index 000000000..005efa3d0 --- /dev/null +++ b/src/ui/client/dashboard/pages/logs/logs.js @@ -0,0 +1,11 @@ +import { createApp } from "vue"; +import { createPinia } from "pinia"; +import { getI18n } from "@utils/lang.js"; +import Logs from "./Logs.vue"; + +const pinia = createPinia(); + +createApp(Logs) + .use(pinia) + .use(getI18n(["dashboard", "action", "inp", "icons", "logs"])) + .mount("#app"); diff --git a/src/ui/client/dashboard/utils/global.js b/src/ui/client/dashboard/utils/global.js index e54448e1d..b246f78dd 100644 --- a/src/ui/client/dashboard/utils/global.js +++ b/src/ui/client/dashboard/utils/global.js @@ -161,7 +161,7 @@ function useEqualStr(type, compare) { * @name useDataLinkAttr * @description Check from event if the target has a data-link attribute. Case it is, it will be used to redirect the user to the define link. * This is useful to avoid using the tag and use a
or