Permalink
Browse files

XWIKI-7671: Add a repository selector on the extension search bar

* Refactor the search bar
* Remove duplicated Velocity code from XWiki.InstalledExtensions and XWiki.CoreExtensions
  • Loading branch information...
mflorea committed Mar 29, 2012
1 parent aa54051 commit 9da5721ef4e4b6e113a5188075cec0fdf045d4cd
@@ -182,8 +182,8 @@ TTblp5ECixqHCAX8AEonFxlHq+tGuw3SAAAAAElFTkSuQmCC
{{velocity}}
## Ajax call for a single extension
-#if ($request.extensionid && $request.extensionversion && $request.ajax)
- #set ($extension = $extensionManager.resolve($request.extensionid, $request.extensionversion))
+#if ($request.extensionId && $request.extensionVersion && $request.ajax)
+ #set ($extension = $extensionManager.resolve($request.extensionId, $request.extensionVersion))
#displayExtension($extension)
#elseif ($request.actionuninstall)
#handleUninstallExtensionRequest()
@@ -192,37 +192,56 @@ TTblp5ECixqHCAX8AEonFxlHq+tGuw3SAAAAAElFTkSuQmCC
#else
(% class="full column" %)(((
#displayExtensionSearchBar()
- #if ($request.extensionid)
+ #if ($request.extensionId && $request.extensionVersion)
## Advanced search.
- #set ($extension = $extensionManager.resolve($request.extensionid, $request.extensionversion))
+ #set ($extension = $extensionManager.resolve($request.extensionId, $request.extensionVersion))
#if ($extension)
#displayExtension($extension)
#else
- {{info}}$msg.get('extensions.advancedSearch.noResults', ["**{{{$!request.extensionid}}}**", "**{{{$!request.extensionversion}}}**"]){{/info}}
+ {{info}}$msg.get('extensions.advancedSearch.noResults', ["**{{{$!request.extensionId}}}**", "**{{{$!request.extensionVersion}}}**"]){{/info}}
#end
#else
## Simple search.
#set ($paginationParams = {})
## Dump whitespace generated by the pagination macro
#set ($discard = "#paginationPrepareParams($paginationParams)")
- #set ($extensions = $extensionManager.search("$!{request.searchextension}", $paginationParams.firstItem, $paginationParams.itemsPerPage))
- #if ("$!request.searchextension" == '')
- == $msg.get('extensions.browse.title') ==
- #else
- == $msg.get('extensions.search.results.title', ["""//$request.searchextension//"""]) ==
+ #set ($repository = $extensionManager)
+ #if ($request.repo)
+ #set ($selectedRepositoryId = $request.repo)
#end
-
- #if ($extensions.size == 0)
- {{info}}$msg.get('extensions.search.noResults', ["""//$!{request.searchextension}//"""]){{/info}}
+ #if ("$!selectedRepositoryId" != '')
+ #set ($repository = $extensionManager.getRepository($selectedRepositoryId))
+ #if ("$!request.search" == '')
+ ## Fetch extensions from known repositories.
+ #if ($selectedRepositoryId == 'core')
+ #set($extensions = $extensionManager.getCoreExtensions())
+ #elseif ($selectedRepositoryId == 'installed')
+ #if ($xcontext.isMainWiki())
+ #set($extensions = $extensionManager.getInstalledExtensions())
+ #else
+ #set($extensions = $extensionManager.getInstalledExtensions($extensionNamespace))
+ #end
+ #elseif ($selectedRepositoryId == 'local')
+ #set($extensions = $extensionManager.getLocalExtensions())
+ #end
+ #if ($extensions)
+ #set ($totalHits = $extensions.size())
+ ## All extensions from the specified repository have been fetched. We need to display only the current page.
+ #set ($extensions = $extensions.subList($paginationParams.firstItem, $mathtool.min($extensions.size(), $mathtool.add($paginationParams.firstItem, $paginationParams.itemsPerPage))))
+ #end
+ #end
+ #end
+ #if (!$extensions)
+ #set ($extensions = $repository.search("$!request.search", $paginationParams.firstItem, $paginationParams.itemsPerPage))
+ #set ($totalHits = $extensions.totalHits)
+ #end
+ #if (!$extensions.iterator().hasNext())
+ {{info}}$msg.get('extensions.search.noResults', ["""//$!{request.search}//"""]){{/info}}
#else
- #if ($extensions.totalHits && $extensions.totalHits > $paginationParams.itemsPerPage)
+ #if ($totalHits && $totalHits > $paginationParams.itemsPerPage)
#set ($hasPagination = true)
- #set ($paginationURL = $doc.getURL($xcontext.action, $request.getQueryString().replaceAll('(^|&)firstIndex=[^&]++&?', '$1')))
- #if ("$!{request.searchextension}" != '')
- #set ($paginationURL = "${paginationURL}&searchextension=${request.searchextension}")
- #end
- #set($paginationParams.totalItems = $extensions.totalHits)
- #set($paginationParams.url = $paginationURL)
+ #set ($paginationParams.totalItems = $totalHits)
+ #set ($paginationParams.url = $doc.getURL($xcontext.action, $request.getQueryString().replaceAll('(^|&)firstIndex=[^&]++&?', '$1')))
{{html}}#pagination($paginationParams){{/html}}
#end
#foreach($extension in $extensions)
@@ -180,40 +180,8 @@ mIOXEBZsDeaDZW/j4WPEk92XEEG7l6QsEy+qpnvvw7PCy5N6embGHpFlI5xEiN+T9NIV7xQChjQI
2xG+mbecbY+YA1vR9BcQJFn40YRwItlcNaRjIzxhJp3kThR/zijENyab8su4WgfZQ/TS/w+hdHID
KBfuuaQu/iwAAAAASUVORK5CYII=
</content></attachment>
-<content>{{include document="ExtensionManagerMacros" /}}
+<content>{{velocity}}
+#set ($selectedRepositoryId = 'core')
+{{/velocity}}
-{{velocity}}
-## Ajax call for a single extension
-#if ($request.extensionid &amp;&amp; $request.extensionversion &amp;&amp; $request.ajax)
- #set($extension = $extensionManager.resolve($request.extensionid, $request.extensionversion))
- #displayExtension($extension $actions)
-#else
- (% class="full column" %)(((
- #displayExtensionSearchBar()
-
- = $msg.get('extensions.core.title')
-
- #if ($request.extensionid &amp;&amp; $request.extensionversion)
- #set ($extensions = [$extensionManager.resolve($request.extensionid, $request.extensionversion)])
- #else
- #set($extensions = $extensionManager.getCoreExtensions())
- #end
- #if ($extensions.isEmpty())
- {{info}}$msg.get('extensions.core.noExtensions'){{/info}}##
- #else
- #if ($extensions.size() &gt; 1)
- #set ($paginationParams = {'totalItems': $extensions.size(), 'url': $doc.getURL($xcontext.action, $request.getQueryString().replaceAll('(^|&amp;)firstIndex=[^&amp;]++&amp;?', '$1'))})
- {{html}}#pagination($paginationParams){{/html}}
- #set ($extensions = $extensions.subList($paginationParams.firstItem, $mathtool.min($extensions.size(), $mathtool.add($paginationParams.firstItem, $paginationParams.itemsPerPage))))
- #end
- #foreach($extension in $extensions)
- #displayExtension($extension $actions)
- #end
- #if ($paginationParams)
- #set ($discard = $paginationParams.put('position', 'bottom'))
- {{html}}#pagination($paginationParams){{/html}}
- #end
- #end
- )))
-#end
-{{/velocity}}</content></xwikidoc>
+{{include document="AddExtensions" /}}</content></xwikidoc>
Oops, something went wrong.

0 comments on commit 9da5721

Please sign in to comment.