mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
feat: #7090, abililty to hide widgets
This commit is contained in:
@@ -8,11 +8,27 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<label>Groups:</label>
|
<label>Groups:</label>
|
||||||
<div>
|
<div>
|
||||||
<select name="groups" class="form-control" multiple size="10">
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
<!-- BEGIN groups -->
|
<li role="presentation" class="active"><a href="#showto" aria-controls="showto" role="tab" data-toggle="tab">Show to</a></li>
|
||||||
<option value="{groups.displayName}">{groups.displayName}</option>
|
<li role="presentation"><a href="#hidefrom" aria-controls="hidefrom" role="tab" data-toggle="tab">Hide from</a></li>
|
||||||
<!-- END groups -->
|
</ul>
|
||||||
</select>
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div role="tabpanel" class="tab-pane active" id="showto">
|
||||||
|
<select name="groups" class="form-control" multiple size="10">
|
||||||
|
<!-- BEGIN groups -->
|
||||||
|
<option value="{groups.displayName}">{groups.displayName}</option>
|
||||||
|
<!-- END groups -->
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div role="tabpanel" class="tab-pane" id="hidefrom">
|
||||||
|
<select name="groupsHideFrom" class="form-control" multiple size="10">
|
||||||
|
<!-- BEGIN groups -->
|
||||||
|
<option value="{groups.displayName}">{groups.displayName}</option>
|
||||||
|
<!-- END groups -->
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
|
|||||||
@@ -51,13 +51,12 @@ async function renderWidget(widget, uid, options) {
|
|||||||
if (!widget || !widget.data || (!!widget.data['hide-mobile'] && options.req.useragent.isMobile)) {
|
if (!widget || !widget.data || (!!widget.data['hide-mobile'] && options.req.useragent.isMobile)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let isVisible = true;
|
|
||||||
if (widget.data.groups.length) {
|
const isVisible = await checkVisibility(widget, uid);
|
||||||
isVisible = await groups.isMemberOfAny(uid, widget.data.groups);
|
|
||||||
}
|
|
||||||
if (!isVisible) {
|
if (!isVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = options.res.locals.config || {};
|
let config = options.res.locals.config || {};
|
||||||
if (options.res.locals.isAPI) {
|
if (options.res.locals.isAPI) {
|
||||||
config = await loadConfigAsync(options.req);
|
config = await loadConfigAsync(options.req);
|
||||||
@@ -99,6 +98,18 @@ async function renderWidget(widget, uid, options) {
|
|||||||
return { html: html };
|
return { html: html };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkVisibility(widget, uid) {
|
||||||
|
let isVisible = true;
|
||||||
|
let isHidden = false;
|
||||||
|
if (widget.data.groups.length) {
|
||||||
|
isVisible = await groups.isMemberOfAny(uid, widget.data.groups);
|
||||||
|
}
|
||||||
|
if (widget.data.groupsHideFrom.length) {
|
||||||
|
isHidden = await groups.isMemberOfAny(uid, widget.data.groupsHideFrom);
|
||||||
|
}
|
||||||
|
return isVisible && !isHidden;
|
||||||
|
}
|
||||||
|
|
||||||
widgets.getWidgetDataForTemplates = async function (templates) {
|
widgets.getWidgetDataForTemplates = async function (templates) {
|
||||||
const keys = templates.map(tpl => 'widgets:' + tpl);
|
const keys = templates.map(tpl => 'widgets:' + tpl);
|
||||||
const data = await db.getObjects(keys);
|
const data = await db.getObjects(keys);
|
||||||
@@ -144,6 +155,11 @@ function parseWidgetData(data) {
|
|||||||
if (widget.data.groups && !Array.isArray(widget.data.groups)) {
|
if (widget.data.groups && !Array.isArray(widget.data.groups)) {
|
||||||
widget.data.groups = [widget.data.groups];
|
widget.data.groups = [widget.data.groups];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
widget.data.groupsHideFrom = widget.data.groupsHideFrom || [];
|
||||||
|
if (widget.data.groupsHideFrom && !Array.isArray(widget.data.groupsHideFrom)) {
|
||||||
|
widget.data.groupsHideFrom = [widget.data.groupsHideFrom];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return widgets;
|
return widgets;
|
||||||
|
|||||||
Reference in New Issue
Block a user