Skip to content

Commit

Permalink
XWIKI-18998: Replace the Livetable of the System Filters of the Notif…
Browse files Browse the repository at this point in the history
…ications Administration with a Live Data macro
  • Loading branch information
manuelleduc committed Jan 26, 2024
1 parent ca748c6 commit 858d0c7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
<input
type='checkbox'
class='toggleableFilterPreferenceCheckbox'
:checked="checked"
:disabled="disabled"
ref="input"
/>
<!-- We keep this section hidden as it is only there to be copied when initializing the toggle -->
Expand Down Expand Up @@ -88,18 +86,12 @@ export default {
},
data() {
return {
iconReady: false
}
},
computed: {
checked() {
return this.entry[`${this.propertyId}_checked`]
},
disabled() {
return this.entry[`${this.propertyId}_disabled`]
},
toggleData() {
return this.entry[`${this.propertyId}_data`]
iconReady: false,
innerChecked: this.entry[`${this.propertyId}_checked`],
innerDisabled: this.entry[`${this.propertyId}_disabled`],
innerData: {
... this.entry[`${this.propertyId}_data`]
}
}
},
watch: {
Expand All @@ -110,25 +102,27 @@ export default {
this.$nextTick(() => {
$(this.$refs.input).bootstrapSwitch({
size: 'mini',
state: component.innerChecked,
disabled: component.innerDisabled,
labelText: this.$refs.icon.$el.outerHTML,
onSwitchChange() {
const toggleData = component.toggleData;
const checkedVal = component.checked;
const disabledVal = component.disabled;
console.log("Before toggle", toggleData, checkedVal, disabledVal);
onSwitchChange(event, state) {
const toggleData = component.innerData;
const disabledVal = component.innerDisabled;
component.logic.triggerEvent("toggle", {
data: toggleData,
checked: checkedVal,
checked: state,
disabled: disabledVal,
callback: function ({
data = toggleData,
checked = checkedVal,
checked = state,
disabled = disabledVal
}) {
// TODO: add callback handling on XWiki.Notifications.Code.NotificationsSystemFiltersPreferencesMacro
component.data = data;
component.checked = checked;
component.disabled = disabled;
component.innerData = data;
component.innerChecked = checked;
component.innerDisabled = disabled;
// The last parameter is skip, preventing to call onSwitchChange again.
$(component.$refs.input).bootstrapSwitch('state', checked, true);
$(component.$refs.input).bootstrapSwitch('disabled', disabled);
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
#set ($objectNumber = $!obj.reference.objectNumber)
#end
#if ($checked)
#set ($checked = 'checked = "checked"')
#set ($checkedAttr = 'checked = "checked"')
#else
#set ($checked = '')
#set ($checkedAttr = '')
#end
#set ($checkbox = "&lt;input type='checkbox' class='toggleableFilterPreferenceCheckbox' data-objectNumber='${objectNumber}' data-filtername='${filter.name}' $checked /&gt;")
#set ($checkbox = "&lt;input type='checkbox' class='toggleableFilterPreferenceCheckbox' data-objectNumber='${objectNumber}' data-filtername='${filter.name}' $checkedAttr /&gt;")
#set ($name = $services.localization.render("notifications.filters.name.$filter.name"))
#set ($element = {
'filterPreferenceId' : $name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,32 @@
keys: [
'settings.saving',
'filters.preferences.setEnabled.done',
'filters.preferences.setEnabled.error',
'filters.preferences.setEnabled.done',
'filters.preferences.setEnabled.error'
]
});

require(['jquery', 'xwiki-l10n!notifications-system-filters-preferences-macro'], function ($, l10n) {

function save(state, filterName, objectNumber, docURL) {
new Promise((resolve) =&gt; {
function save(checked, filterName, objectNumber, docURL) {
return new Promise((resolve) =&gt; {
const notification = new XWiki.widgets.Notification(l10n['settings.saving'], 'inprogress');
if (objectNumber === '') {
// If the object does not exist yet, create it (make this change a minor edit so it's not displayed, by default,
// in notifications)
const restURL = docURL + '/objects?media=json&amp;amp;minorRevision=true';
const restURL = docURL + '/objects?media=json&amp;minorRevision=true';
const params = {
'className': 'XWiki.Notifications.Code.ToggleableFilterPreferenceClass',
'property#filterName': filterName,
'property#isEnabled': state ? '1' : '0'
'property#isEnabled': checked ? '1' : '0'
};
$.post(restURL, params).then(data =&gt; {
notification.hide();
new XWiki.widgets.Notification(l10n['filters.preferences.setEnabled.done'], 'done');
resolve({objectNumber: data.number})
resolve({objectNumber: data.number, checked})
}).catch(() =&gt; {
notification.hide();
new XWiki.widgets.Notification(l10n['filters.preferences.setEnabled.error'], 'error');
resolve({});
resolve({checked: !checked});
});
} else if (objectNumber !== '') {
// If the object already exist, just update its value (make this change a minor edit so it's not displayed, by
Expand All @@ -167,15 +165,15 @@ require(['jquery', 'xwiki-l10n!notifications-system-filters-preferences-macro'],
$.ajax(restURL, {
method: 'PUT',
contentType: 'text/plain',
data: state ? '1' : '0'
data: checked ? '1' : '0'
}).then(() =&gt; {
notification.hide();
new XWiki.widgets.Notification(l10n['filters.preferences.setEnabled.done'], 'done');
resolve({state});
resolve({checked});
}).catch(() =&gt; {
notification.hide();
new XWiki.widgets.Notification(l10n['notifications.filters.preferences.setEnabled.error'], 'error');
resolve({});
new XWiki.widgets.Notification(l10n['filters.preferences.setEnabled.error'], 'error');
resolve({checked: !checked});
});
}
})
Expand All @@ -186,15 +184,15 @@ require(['jquery', 'xwiki-l10n!notifications-system-filters-preferences-macro'],
$(document).on('xwiki:livedata:toggle', '#notificationSystemFilterPreferencesLiveData', (event) =&gt; {
const detail = event.detail;
const data = detail.data
save(!detail.checked, data.filtername, data.objectNumber, docURL).then(({state, objectNumber}) =&gt; {
event.callback({
checked: state,
save(detail.checked, data.filtername, data.objectNumber, docURL).then(({checked, objectNumber}) =&gt; {
detail.callback({
...detail,
data: {
...data,
objectNumber
}
})
;
objectNumber: objectNumber !== undefined ? objectNumber : data.objectNumber
},
checked: checked
});
});
});
})</code>
Expand Down Expand Up @@ -480,15 +478,16 @@ require(['jquery', 'xwiki-l10n!notifications-system-filters-preferences-macro'],
}
}
})

## TODO: localize the description.
#set ($description =
$services.localization.render('notifications.settings.filters.preferences.system.table.description'))
#set ($description = $services.rendering.escape($description, 'xwiki/2.1'))
{{liveData
id='notificationSystemFilterPreferencesLiveData'
properties="$stringtool.join($properties, ',')"
source='liveTable'
sourceParameters="$escapetool.url($sourceParameters)"
limit='10'
description='This table lists every system filter registered in the wiki.'
description="$description"
}}$jsontool.serialize($liveDataConfig){{/liveData}}
#end
{{/velocity}}</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ notifications.settings.filters.preferences.system.table.name=Name
notifications.settings.filters.preferences.system.table.filterType=Description
notifications.settings.filters.preferences.system.table.notificationFormats=Formats
notifications.settings.filters.preferences.system.table.isEnabled=Is enabled?
notifications.settings.filters.preferences.system.table.description=This table lists every system filter registered in the wiki.

## Custom Filter preferences settings
notifications.settings.filters.preferences.custom.title=Custom Filters
Expand Down

0 comments on commit 858d0c7

Please sign in to comment.