feat: expiration date for widgets

closes #10495
This commit is contained in:
Barış Soner Uşaklı
2023-05-03 20:09:15 -04:00
parent 0813ee7818
commit fbf44a10e7
4 changed files with 22 additions and 3 deletions

View File

@@ -10,6 +10,17 @@
<!-- IMPORT admin/partials/widgets/show_hide_groups.tpl -->
<div class="row mb-3">
<div class="col-lg-6">
<label class="form-label">[[admin/extend/widgets:start-date]]</label>
<input class="form-control" name="startDate" type="datetime-local" />
</div>
<div class="col-lg-6">
<label class="form-label">[[admin/extend/widgets:end-date]]</label>
<input class="form-control" name="endDate" type="datetime-local" />
</div>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" name="hide-mobile" id="hide-mobile-check"/>
<label class="form-check-label" for="hide-mobile-check">[[admin/extend/widgets:hide-on-mobile]]</label>

View File

@@ -1,6 +1,6 @@
<div class="row mb-3">
<div class="col-lg-6">
<label>[[admin/extend/widgets:show-to-groups]]</label>
<label class="form-label">[[admin/extend/widgets:show-to-groups]]</label>
<select name="groups" class="form-select" multiple size="10">
{{{ each groups }}}
<option value="{./displayName}">{./displayName}</option>
@@ -8,7 +8,7 @@
</select>
</div>
<div class="col-lg-6">
<label>[[admin/extend/widgets:hide-from-groups]]</label>
<label class="form-label">[[admin/extend/widgets:hide-from-groups]]</label>
<select name="groupsHideFrom" class="form-select" multiple size="10">
{{{ each groups }}}
<option value="{./displayName}">{./displayName}</option>

View File

@@ -101,7 +101,13 @@ widgets.checkVisibility = async function (data, uid) {
if (data.groupsHideFrom.length) {
isHidden = await groups.isMemberOfAny(uid, data.groupsHideFrom);
}
return isVisible && !isHidden;
const isExpired = (
(data.startDate && Date.now() < new Date(data.startDate).getTime()) ||
(data.endDate && Date.now() > new Date(data.endDate).getTime())
);
return isVisible && !isHidden && !isExpired;
};
widgets.getWidgetDataForTemplates = async function (templates) {