Show last authors
1 {{velocity wiki="false"}}
2 #if ($xcontext.action == 'get')
3 ##
4 ## Offset = item # at which to start displaying data
5 ##
6 #set ($offset = $numbertool.toNumber($request.get('offset')))
7 ## offset starts from 0 in velocity and 1 in javascript
8 #set ($offset = $offset - 1)
9 #if ($offset < 0)
10 #set ($offset = 0)
11 #end
12 ##
13 ## Limit = # of items to display
14 ##
15 #set ($limit = $numbertool.toNumber($request.get('limit')))
16 #set ($limitOffset = $offset + $limit)
17 ##
18 ## Build the list of NotificationFilterPreference related to the given user.
19 ##
20 #set ($document = $xwiki.getDocument($services.model.resolveDocument($request.user)))
21 #set ($elements = [])
22 #set ($index = 0)
23 ## First: get the list of available toggeable filters for the user
24 ## We display them first because we don't want them to be hidden by thousands of page filters the autowatch option
25 ## might have created. It would be not good to have to go to the last page of the livetable to find out these commonly
26 ## used filters.
27 #set ($filters = $services.notification.filters.getToggleableNotificationFilters())
28 #foreach ($filter in $filters)
29 #set ($index = $index + 1)
30 ## Optimization to render only displayed rows (between $offset and $limitOffset)
31 #if ($index > $offset and $index <= $limitOffset)
32 #set ($checked = $filter.isEnabledByDefault())
33 #set ($objectNumber = '')
34 #set ($obj = $document.getObject('XWiki.Notifications.Code.ToggleableFilterPreferenceClass', 'filterName', $filter.name))
35 #if ($obj)
36 #set ($checked = $obj.getValue('isEnabled') != 0)
37 #set ($objectNumber = $!obj.reference.objectNumber)
38 #end
39 #if ($checked)
40 #set ($checked = 'checked = "checked"')
41 #else
42 #set ($checked = '')
43 #end
44 #set ($checkbox = "<input type='checkbox' class='toggleableFilterPreferenceCheckbox' data-objectNumber='${objectNumber}' data-filtername='${filter.name}' $checked />")
45 #set ($name = $services.localization.render("notifications.filters.name.$filter.name"))
46 #set ($element = {
47 'filterPreferenceId' : $name,
48 'name' : $name,
49 'filterType' : $services.localization.render("notifications.filters.description.$filter.name"),
50 'eventTypes' : "#displayNotificationsEventTypeList($filter.eventTypes)",
51 'notificationFormats' : "#displayNotificationFormatsList($filter.formats)",
52 'isEnabled' : $checkbox,
53 'doc_viewable' : true,
54 'doc_hasdelete' : false
55 })
56 #set ($discard = $elements.add($element))
57 #end
58 #end
59 #set ($elements = $collectiontool.sort($elements, ['name']))
60 ## Also get the list of available filters for the user
61 #set ($filters = $collectiontool.arrayList)
62 #set ($discard = $filters.addAll($services.notification.filters.filters))
63 #set ($filters = $collectiontool.sort($filters, ['name']))
64 #set ($displayHiddenDocument = "$xwiki.getUserPreference('displayHiddenDocuments')" == '1')
65 #foreach ($filter in $filters)
66 #set ($filtersPreferences = $collectiontool.arrayList)
67 #set ($discard = $filtersPreferences.addAll($services.notification.filters.getFilterPreferences($filter)))
68 #set ($filtersPreferences = $collectiontool.sort($filtersPreferences, ['id']))
69 #foreach ($preference in $filtersPreferences)
70 #set ($page = $preference.pageOnly)
71 #set ($space = $preference.page)
72 #if (!$displayHiddenDocument && ($stringtool.isNotBlank($page) && $xwiki.getDocument($page).isHidden()
73 || $stringtool.isNotBlank($space) && $xwiki.getDocument($services.model.resolveSpace($space, 'default')).isHidden()))
74 ## Don't display a preference for an hidden page or space.
75 ## Why? If a user has the autowatch option enabled and create a new hidden document (for example, when she creates an application with AWM, hidden code pages are created as well),
76 ## we don't want to pollute the livetable with these hidden pages that the user don't know about. Moreover, the notifications will filter events concerning hidden pages,
77 ## so even if the filter exists, it has no effect to the user.
78 ## Here we handle only the case where pages.size() == 1 or spaces.size() == 1.
79 ## In the case there are several elements in the lists, they might have different "hidden" properties, and we don't handle it
80 ## Note: in the current implementation of watched entities, it's never the case.
81 ## TODO: handle these cases too in case custom filters need this.
82 #else
83 #set ($index = $index + 1)
84 ## Optimization to render only displayed rows (between $offset and $limitOffset)
85 #if ($index > $offset and $index <= $limitOffset)
86 #set ($display = $services.rendering.render($services.notification.filters.displayFilterPreference($filter, $preference), 'html/5.0'))
87 #set ($isEnabled = '')
88 #set ($isDisabled = '')
89 ## The watchlist bridge does not handle disabling a specific filter
90 #if ($preference.id.startsWith('watchlist_'))
91 #set ($isDisabled = 'disabled = "disabled"')
92 #end
93 #if ($preference.isEnabled())
94 #set ($isEnabled = 'checked = "checked"')
95 #end
96 #set ($isEnabled = "<input type='checkbox' class='notificationFilterPreferenceCheckbox' data-preferenceId='${preference.id}' $isEnabled $isDisabled />")
97 #set ($element = {
98 'filterPreferenceId' : $preference.id,
99 'name' : $display,
100 'filterType' : $services.localization.render("notifications.filters.type.$!preference.getFilterType().name().toLowerCase()"),
101 'eventTypes' : "#displayNotificationsEventTypeList($preference.eventTypes)",
102 'notificationFormats' : "#displayNotificationFormatsList($preference.notificationFormats)",
103 'isEnabled' : $isEnabled,
104 'doc_viewable' : true
105 })
106 #set ($discard = $elements.add($element))
107 #end
108 #end
109 #end
110 #end
111 ##
112 ## JSON.
113 ##
114 #set ($discard = $response.setContentType('application/json'))
115 #set ($offset = $numbertool.toNumber($request.offset))
116 #if (!$offset)
117 #set ($offset = 1)
118 #end
119 $jsontool.serialize({
120 'totalrows' : $index,
121 'reqNo' : $request.reqNo,
122 'returnedrows': $elements.size(),
123 'offset' : $offset,
124 'rows' : $elements
125 })
126 #end
127 ##
128 ## MACROS
129 ##
130 #macro (displayNotificationsEventTypeList $list)
131 <ul class="list-unstyled">
132 #if ($list.isEmpty())
133 <li>$escapetool.xml($services.localization.render('notifications.filters.preferences.allEvents'))</li>
134 #else
135 #set ($types = {})
136 #foreach ($descriptor in $services.eventstream.getRecordableEventDescriptors($xcontext.isMainWiki()))
137 #set ($discard = $types.put($descriptor.eventType, "$!services.localization.render($descriptor.description)"))
138 #end
139 #foreach ($eventType in $list)
140 <li>$escapetool.xml($types.get($eventType))</li>
141 #end
142 #end
143 </ul>
144 #end
145 #macro (displayNotificationFormatsList $formatList)
146 <ul class="list-unstyled">
147 #foreach ($notificationFormat in $formatList)
148 <li>$services.localization.render("notifications.format.$!notificationFormat.name().toLowerCase()")</li>
149 #end
150 </ul>
151 #end
152 {{/velocity}}

Tips

You can click on the arrows next to the breadcrumb elements to quickly navigate to sibling and children pages.

Need help?

If you need help with XWiki you can contact: