Wiki source code of Prototype: Activity Page Centered
Last modified by Vincent Massol on 2024/11/19 16:13
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | #set ($limit = 20) | ||
| 3 | #if ($request.limit) | ||
| 4 | #set ($limit = $request.limit) | ||
| 5 | #end | ||
| 6 | #set ($limitIncrement = $limit) | ||
| 7 | ## | ||
| 8 | #set ($query = " | ||
| 9 | SELECT | ||
| 10 | act.page, act.wiki, act.param1, act.user, count(*), max(act.date) | ||
| 11 | FROM | ||
| 12 | ActivityEventImpl as act | ||
| 13 | WHERE | ||
| 14 | not (act.version not like '%.1' and act.type = 'update') and act.hidden<>1 | ||
| 15 | GROUP BY | ||
| 16 | year(act.date), month(act.date), day(act.date), act.page, act.wiki, act.param1, act.user | ||
| 17 | ORDER BY | ||
| 18 | max(act.date) desc | ||
| 19 | ") | ||
| 20 | |||
| 21 | Activity Stream protype which is focused on pages. | ||
| 22 | |||
| 23 | It is very similar to the default Activity Stream implementation that is also page centered, but this version performs a single database query, showing the latest $limit results by $limitIncrement increments (default limit/limitIncrement=20). | ||
| 24 | |||
| 25 | The "catch" is that the displayed information is about 90% of what the default Activity Stream offers, i.e. the specific events for each page are not displayed, but would need to be fetched through an AJAX call, thus delaying any performance heavy event retrieval and processing action only when the user actually needs it. | ||
| 26 | |||
| 27 | {{code}}$query{{/code}} | ||
| 28 | |||
| 29 | #* | ||
| 30 | ## Debugging | ||
| 31 | #set ($rez = $services.query.hql("$query").setOffset(0).setLimit($limit).execute()) | ||
| 32 | #foreach ($rezult in $rez) | ||
| 33 | |||
| 34 | #if ("$!rezult.size()" != '') | ||
| 35 | #foreach ($inRez in $rezult) | ||
| 36 | |$!inRez## | ||
| 37 | #end | ||
| 38 | #elseif ("$!rezult.page" != '') | ||
| 39 | |$rezult.page | ||
| 40 | #else | ||
| 41 | |$!rezult## | ||
| 42 | #end | ||
| 43 | #end | ||
| 44 | *# | ||
| 45 | |||
| 46 | |||
| 47 | #set ($start = $datetool.date) | ||
| 48 | ## | ||
| 49 | ## Prepare data | ||
| 50 | ## | ||
| 51 | #set ($events = $services.query.hql("$query").setOffset(0).setLimit($limit).execute()) | ||
| 52 | #set ($days = $collectionstool.orderedMap) | ||
| 53 | #set ($pageViewCache = {}) | ||
| 54 | #set ($nrOfSecurityChecks = 0) | ||
| 55 | #foreach ($event in $events) | ||
| 56 | #set ($pageName = $event[0]) | ||
| 57 | #set ($wiki = $event[1]) | ||
| 58 | #set ($pageTitle = $event[2]) | ||
| 59 | #set ($user = $event[3]) | ||
| 60 | #set ($changes = $event[4]) | ||
| 61 | #set ($date = $event[5]) | ||
| 62 | ## | ||
| 63 | #set ($canViewPage = false) | ||
| 64 | #if ($pageViewCache.containsKey($pageName)) | ||
| 65 | #set ($canViewPage = $pageViewCache.get($pageName)) | ||
| 66 | #else | ||
| 67 | #set ($canViewPage = $xwiki.hasAccessLevel('view', $xcontext.user, $pageName)) | ||
| 68 | #set ($discard = $pageViewCache.put($pageName, $canViewPage)) | ||
| 69 | #set ($nrOfSecurityChecks = $mathtool.add($nrOfSecurityChecks, 1)) | ||
| 70 | #end | ||
| 71 | ## | ||
| 72 | #if ($canViewPage) | ||
| 73 | #set ($currentDay = $datetool.format("yyyy-MM-dd", $date)) | ||
| 74 | ## | ||
| 75 | #if (!$days.containsKey($currentDay)) | ||
| 76 | #set ($discard = $days.put($currentDay, $collectionstool.orderedMap)) | ||
| 77 | #end | ||
| 78 | #set ($pages = $days.get($currentDay)) | ||
| 79 | ## | ||
| 80 | #if (!$pages.containsKey($pageName)) | ||
| 81 | #set ($discard = $pages.put($pageName, [$wiki, $pageTitle, {"$!user" : $changes}, $date])) | ||
| 82 | #else | ||
| 83 | #set ($discard = $pages.get($pageName)[2].put($user, $changes)) | ||
| 84 | #end | ||
| 85 | #end | ||
| 86 | #end | ||
| 87 | ## | ||
| 88 | ## Display | ||
| 89 | ## | ||
| 90 | #foreach ($day in $days.entrySet()) | ||
| 91 | #set ($currentDay = $day.key) | ||
| 92 | #set ($pages = $day.value) | ||
| 93 | = $currentDay = | ||
| 94 | #foreach ($page in $pages.entrySet()) | ||
| 95 | #set ($pageName = $page.key) | ||
| 96 | #set ($pageData = $page.value) | ||
| 97 | #set ($pageWiki = $pageData[0]) | ||
| 98 | #set ($pageTitle = $pageData[1]) | ||
| 99 | #set ($users = $pageData[2]) | ||
| 100 | #set ($date = $pageData[3]) | ||
| 101 | |||
| 102 | {{html}} | ||
| 103 | <div class='page' style="margin-top: 1em; margin-left: 0.5em"> | ||
| 104 | <div> | ||
| 105 | <a href="$xwiki.getURL($pageName, 'view')">$pageTitle</a> #if ($xcontext.database != $pageWiki) <span style="color:grey; font-size: 0.85em">($pageWiki)</span>#end | ||
| 106 | </span> | ||
| 107 | |||
| 108 | <div style='float:right'>$date</div> | ||
| 109 | |||
| 110 | <div style="font-size: 0.75em; color: grey"> | ||
| 111 | #set ($totalChanges = 0) | ||
| 112 | #foreach ($entry in $users.entrySet()) | ||
| 113 | #set ($totalChanges = $mathtool.add($totalChanges, $entry.value)) | ||
| 114 | #end | ||
| 115 | $totalChanges #if ($totalChanges == 1) change #else changes #end by $users.size() #if ($users.size() == 1) user #else users #end | ||
| 116 | </div> | ||
| 117 | |||
| 118 | <div style="margin-left:2em"> | ||
| 119 | #foreach ($entry in $users.entrySet()) | ||
| 120 | #set ($user = $entry.key) | ||
| 121 | #set ($changes = $entry.value) | ||
| 122 | #if ("$!user" != 'XWiki.XWikiGuest' && "$!user" != '') | ||
| 123 | <a href="$xwiki.getURL($!user)">#smallUserAvatar("$!user")</a> | ||
| 124 | #else | ||
| 125 | #smallUserAvatar("$!user") | ||
| 126 | #end | ||
| 127 | $xwiki.getUserName($!user) ($changes #if ($changes == 1) change #else changes#end) | ||
| 128 | #end | ||
| 129 | </div> | ||
| 130 | </div> | ||
| 131 | |||
| 132 | {{/html}} | ||
| 133 | #end | ||
| 134 | #end | ||
| 135 | |||
| 136 | {{html}} | ||
| 137 | <div style="text-align: center;"><a href="$doc.getURL('view', "limit=$mathtool.add($limit, $limitIncrement)")">Show more...</a></div> | ||
| 138 | {{/html}} | ||
| 139 | |||
| 140 | |||
| 141 | #set ($end = $datetool.date) | ||
| 142 | #set ($time = $mathtool.sub($end.time, $start.time)) | ||
| 143 | Execution took: $time ms | ||
| 144 | Nr. of security checks: $nrOfSecurityChecks | ||
| 145 | {{/velocity}} |