From 397baf02547eabe3eeb41b1f8e632a21c1ae2797 Mon Sep 17 00:00:00 2001 From: gasoved Date: Wed, 7 Apr 2021 22:22:16 +0300 Subject: [PATCH] refactor: widgets (#9471) --- src/views/admin/partials/widget-settings.tpl | 19 +------------------ .../partials/widgets/show_hide_groups.tpl | 18 ++++++++++++++++++ src/widgets/index.js | 14 +++++++------- 3 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 src/views/admin/partials/widgets/show_hide_groups.tpl diff --git a/src/views/admin/partials/widget-settings.tpl b/src/views/admin/partials/widget-settings.tpl index 87d60ea2f1..2549b27d1b 100644 --- a/src/views/admin/partials/widget-settings.tpl +++ b/src/views/admin/partials/widget-settings.tpl @@ -6,24 +6,7 @@
-
-
- - -
-
- - -
-
+
diff --git a/src/views/admin/partials/widgets/show_hide_groups.tpl b/src/views/admin/partials/widgets/show_hide_groups.tpl new file mode 100644 index 0000000000..a640c27716 --- /dev/null +++ b/src/views/admin/partials/widgets/show_hide_groups.tpl @@ -0,0 +1,18 @@ +
+
+ + +
+
+ + +
+
\ No newline at end of file diff --git a/src/widgets/index.js b/src/widgets/index.js index eac16373fc..572121b021 100644 --- a/src/widgets/index.js +++ b/src/widgets/index.js @@ -50,7 +50,7 @@ async function renderWidget(widget, uid, options) { return; } - const isVisible = await checkVisibility(widget, uid); + const isVisible = await widgets.checkVisibility(widget.data, uid); if (!isVisible) { return; } @@ -92,17 +92,17 @@ async function renderWidget(widget, uid, options) { return { html }; } -async function checkVisibility(widget, uid) { +widgets.checkVisibility = async function (data, uid) { let isVisible = true; let isHidden = false; - if (widget.data.groups.length) { - isVisible = await groups.isMemberOfAny(uid, widget.data.groups); + if (data.groups.length) { + isVisible = await groups.isMemberOfAny(uid, data.groups); } - if (widget.data.groupsHideFrom.length) { - isHidden = await groups.isMemberOfAny(uid, widget.data.groupsHideFrom); + if (data.groupsHideFrom.length) { + isHidden = await groups.isMemberOfAny(uid, data.groupsHideFrom); } return isVisible && !isHidden; -} +}; widgets.getWidgetDataForTemplates = async function (templates) { const keys = templates.map(tpl => `widgets:${tpl}`);