]> source.dussan.org Git - gitblit.git/commitdiff
Whoops. Missed adding LucenePage.
authorJames Moger <james.moger@gitblit.com>
Fri, 2 Mar 2012 23:56:45 +0000 (18:56 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 2 Mar 2012 23:56:45 +0000 (18:56 -0500)
src/com/gitblit/wicket/pages/LucenePage.java [new file with mode: 0644]

diff --git a/src/com/gitblit/wicket/pages/LucenePage.java b/src/com/gitblit/wicket/pages/LucenePage.java
new file mode 100644 (file)
index 0000000..75df314
--- /dev/null
@@ -0,0 +1,109 @@
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.wicket.pages;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.markup.html.basic.Label;\r
+import org.apache.wicket.markup.html.form.Form;\r
+import org.apache.wicket.markup.html.form.TextField;\r
+import org.apache.wicket.markup.repeater.Item;\r
+import org.apache.wicket.markup.repeater.data.DataView;\r
+import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
+import org.apache.wicket.model.Model;\r
+import org.eclipse.jgit.lib.Repository;\r
+\r
+import com.gitblit.GitBlit;\r
+import com.gitblit.models.SearchResult;\r
+import com.gitblit.utils.LuceneUtils;\r
+import com.gitblit.wicket.WicketUtils;\r
+import com.gitblit.wicket.panels.LinkPanel;\r
+\r
+public class LucenePage extends RootPage {\r
+\r
+       public LucenePage() {\r
+               super();\r
+               setup(null);\r
+       }\r
+\r
+       public LucenePage(PageParameters params) {\r
+               super(params);\r
+               setup(params);\r
+       }\r
+\r
+       private void setup(PageParameters params) {\r
+               setupPage("", "");\r
+               final List<SearchResult> results = new ArrayList<SearchResult>();\r
+               ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);\r
+               final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {\r
+                       private static final long serialVersionUID = 1L;\r
+                       public void populateItem(final Item<SearchResult> item) {\r
+                               SearchResult sr = item.getModelObject();\r
+                               switch(sr.type) {\r
+                               case commit: {\r
+                                       Label icon = WicketUtils.newIcon("type", "icon-refresh");\r
+                                       WicketUtils.setHtmlTooltip(icon, "commit");\r
+                                       item.add(icon);\r
+                                       item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class, WicketUtils.newObjectParameter(sr.repository, sr.id)));\r
+                                       break;\r
+                               }\r
+                               case blob: {\r
+                                       Label icon = WicketUtils.newIcon("type", "icon-file");\r
+                                       WicketUtils.setHtmlTooltip(icon, "blob");\r
+                                       item.add(icon);\r
+                                       item.add(new LinkPanel("summary", null, sr.id, BlobPage.class, WicketUtils.newPathParameter(sr.repository, sr.branch, sr.id)));\r
+                                       break;\r
+                               }\r
+                               case issue: {\r
+                                       Label icon = WicketUtils.newIcon("type", "icon-file");\r
+                                       WicketUtils.setHtmlTooltip(icon, "issue");\r
+                                       item.add(icon);\r
+                                       item.add(new Label("summary", "issue: " + sr.id));\r
+                                       break;\r
+                               }\r
+                               }\r
+                               item.add(new Label("repository", sr.repository));\r
+                               item.add(new Label("branch", sr.branch));\r
+                               item.add(new Label("author", sr.author));\r
+                               item.add(WicketUtils.createTimestampLabel("date", sr.date, getTimeZone()));\r
+                       }\r
+               };              \r
+               \r
+               final Model<String> fragment = new Model<String>();\r
+               Form<Void> form = new Form<Void>("searchForm") {\r
+                       @Override\r
+                       public void onSubmit() {\r
+                               String f = fragment.getObject();\r
+                               List<Repository> repositories = new ArrayList<Repository>();\r
+                               for (String r : GitBlit.self().getRepositoryList()) {\r
+                                       repositories.add(GitBlit.self().getRepository(r));\r
+                               }\r
+                               List<SearchResult> srs = LuceneUtils.search(f, 100, repositories.toArray(new Repository[repositories.size()]));\r
+                               results.clear();\r
+                               results.addAll(srs);\r
+                               for (Repository r : repositories) {\r
+                                       r.close();\r
+                               }\r
+                               resultsView.setVisible(true);\r
+                       }\r
+               };\r
+               form.add(new TextField<String>("fragment", fragment));\r
+               add(form);\r
+               add(resultsView.setVisible(false));\r
+       }\r
+}\r