feat: expiration date for widgets

closes #10495
isekai-main
Barış Soner Uşaklı 2 years ago
parent 0813ee7818
commit fbf44a10e7

@ -26,5 +26,7 @@
"container.placeholder": "Drag and drop a container or enter HTML here.", "container.placeholder": "Drag and drop a container or enter HTML here.",
"show-to-groups": "Show to groups", "show-to-groups": "Show to groups",
"hide-from-groups": "Hide from groups", "hide-from-groups": "Hide from groups",
"start-date": "Start date",
"end-date": "End date",
"hide-on-mobile": "Hide on mobile" "hide-on-mobile": "Hide on mobile"
} }

@ -10,6 +10,17 @@
<!-- IMPORT admin/partials/widgets/show_hide_groups.tpl --> <!-- 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"> <div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" name="hide-mobile" id="hide-mobile-check"/> <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> <label class="form-check-label" for="hide-mobile-check">[[admin/extend/widgets:hide-on-mobile]]</label>

@ -1,6 +1,6 @@
<div class="row mb-3"> <div class="row mb-3">
<div class="col-lg-6"> <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"> <select name="groups" class="form-select" multiple size="10">
{{{ each groups }}} {{{ each groups }}}
<option value="{./displayName}">{./displayName}</option> <option value="{./displayName}">{./displayName}</option>
@ -8,7 +8,7 @@
</select> </select>
</div> </div>
<div class="col-lg-6"> <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"> <select name="groupsHideFrom" class="form-select" multiple size="10">
{{{ each groups }}} {{{ each groups }}}
<option value="{./displayName}">{./displayName}</option> <option value="{./displayName}">{./displayName}</option>

@ -101,7 +101,13 @@ widgets.checkVisibility = async function (data, uid) {
if (data.groupsHideFrom.length) { if (data.groupsHideFrom.length) {
isHidden = await groups.isMemberOfAny(uid, data.groupsHideFrom); 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) { widgets.getWidgetDataForTemplates = async function (templates) {

Loading…
Cancel
Save