]> source.dussan.org Git - gitblit.git/commitdiff
First Step in My Tickets
authorBUISSON Christian <cbuisson@deltadore.com>
Tue, 15 Apr 2014 13:21:33 +0000 (15:21 +0200)
committerJames Moger <james.moger@gitblit.com>
Thu, 1 May 2014 20:14:14 +0000 (16:14 -0400)
src/main/java/com/gitblit/tickets/FileTicketService.java
src/main/java/com/gitblit/tickets/ITicketService.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/GitBlitWebApp_fr.properties
src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/RootPage.java

index 4386020fa751c511b746f7b332f6906a3b18bea0..ea5d065f98059138fae30eb9d2b5aaca0cb060aa 100644 (file)
@@ -207,62 +207,82 @@ public class FileTicketService extends ITicketService {
        @Override
        public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
                List<TicketModel> list = new ArrayList<TicketModel>();
-
-               Repository db = repositoryManager.getRepository(repository.name);
-               try {
-                       // Collect the set of all json files
-                       File dir = new File(db.getDirectory(), TICKETS_PATH);
-                       List<File> journals = findAll(dir, JOURNAL);
-
-                       // Deserialize each ticket and optionally filter out unwanted tickets
-                       for (File journal : journals) {
-                               String json = null;
-                               try {
-                                       json = new String(FileUtils.readContent(journal), Constants.ENCODING);
-                               } catch (Exception e) {
-                                       log.error(null, e);
-                               }
-                               if (StringUtils.isEmpty(json)) {
-                                       // journal was touched but no changes were written
-                                       continue;
-                               }
-                               try {
-                                       // Reconstruct ticketId from the path
-                                       // id/26/326/journal.json
-                                       String path = FileUtils.getRelativePath(dir, journal);
-                                       String tid = path.split("/")[1];
-                                       long ticketId = Long.parseLong(tid);
-                                       List<Change> changes = TicketSerializer.deserializeJournal(json);
-                                       if (ArrayUtils.isEmpty(changes)) {
-                                               log.warn("Empty journal for {}:{}", repository, journal);
+               List<Repository> databases = new ArrayList<Repository>();
+               List<RepositoryModel> models = new ArrayList<RepositoryModel>();
+               
+               if(repository == null)
+               {
+                       List<String> allRepo = repositoryManager.getRepositoryList();
+                       for(int i = 0; i < allRepo.size(); i++)
+                       {
+                               databases.add(repositoryManager.getRepository(allRepo.get(i)));
+                               models.add(repositoryManager.getRepositoryModel(allRepo.get(i)));
+                       }
+               }
+               else
+               {
+                       databases.add(repositoryManager.getRepository(repository.name));
+                       models.add(repository);
+               }
+               
+               for(int i = 0; i < databases.size(); i++)
+               {
+                       Repository db = databases.get(i);
+                       try {
+                               // Collect the set of all json files
+                               File dir = new File(db.getDirectory(), TICKETS_PATH);
+                               List<File> journals = findAll(dir, JOURNAL);
+       
+                               // Deserialize each ticket and optionally filter out unwanted tickets
+                               for (File journal : journals) {
+                                       String json = null;
+                                       try {
+                                               json = new String(FileUtils.readContent(journal), Constants.ENCODING);
+                                       } catch (Exception e) {
+                                               log.error(null, e);
+                                       }
+                                       if (StringUtils.isEmpty(json)) {
+                                               // journal was touched but no changes were written
                                                continue;
                                        }
-                                       TicketModel ticket = TicketModel.buildTicket(changes);
-                                       ticket.project = repository.projectPath;
-                                       ticket.repository = repository.name;
-                                       ticket.number = ticketId;
-
-                                       // add the ticket, conditionally, to the list
-                                       if (filter == null) {
-                                               list.add(ticket);
-                                       } else {
-                                               if (filter.accept(ticket)) {
+                                       try {
+                                               // Reconstruct ticketId from the path
+                                               // id/26/326/journal.json
+                                               String path = FileUtils.getRelativePath(dir, journal);
+                                               String tid = path.split("/")[1];
+                                               long ticketId = Long.parseLong(tid);
+                                               List<Change> changes = TicketSerializer.deserializeJournal(json);
+                                               if (ArrayUtils.isEmpty(changes)) {
+                                                       log.warn("Empty journal for {}:{}", models.get(i), journal);
+                                                       continue;
+                                               }
+                                               TicketModel ticket = TicketModel.buildTicket(changes);
+                                               ticket.project = models.get(i).projectPath;
+                                               ticket.repository = models.get(i).name;
+                                               ticket.number = ticketId;
+       
+                                               // add the ticket, conditionally, to the list
+                                               if (filter == null) {
                                                        list.add(ticket);
+                                               } else {
+                                                       if (filter.accept(ticket)) {
+                                                               list.add(ticket);
+                                                       }
                                                }
+                                       } catch (Exception e) {
+                                               log.error("failed to deserialize {}/{}\n{}",
+                                                               new Object [] { models.get(i), journal, e.getMessage()});
+                                               log.error(null, e);
                                        }
-                               } catch (Exception e) {
-                                       log.error("failed to deserialize {}/{}\n{}",
-                                                       new Object [] { repository, journal, e.getMessage()});
-                                       log.error(null, e);
                                }
+                       } finally {
+                               db.close();
                        }
-
-                       // sort the tickets by creation
-                       Collections.sort(list);
-                       return list;
-               } finally {
-                       db.close();
                }
+               
+               // sort the tickets by creation
+               Collections.sort(list);
+               return list;
        }
 
        private List<File> findAll(File dir, String filename) {
index 3261ca963d32b1bdb4ede4c22071ed3f32b267a5..e7b4c71d05e762b0614695343e4fba080fc9a066 100644 (file)
@@ -779,12 +779,21 @@ public abstract class ITicketService {
         * @since 1.4.0
         */
        public abstract boolean hasTicket(RepositoryModel repository, long ticketId);
+       
+       /**
+        * Returns all tickets.  This is not a Lucene search!
+        * 
+        * @return all tickets
+        */
+       public List<TicketModel> getTickets() {
+               return getTickets(null, null);
+       }
 
        /**
         * Returns all tickets.  This is not a Lucene search!
         *
         * @param repository
-        * @return all tickets
+        * @return all tickets of a given repository
         * @since 1.4.0
         */
        public List<TicketModel> getTickets(RepositoryModel repository) {
index d4c1bc4012dea768e310f503f5dc95ded6c7a27c..9f002d2ba30953d86ae5006317f01bce56a03824 100644 (file)
@@ -81,6 +81,7 @@ import com.gitblit.wicket.pages.TicketsPage;
 import com.gitblit.wicket.pages.TreePage;
 import com.gitblit.wicket.pages.UserPage;
 import com.gitblit.wicket.pages.UsersPage;
+import com.gitblit.wicket.pages.MyTicketsPage;
 
 public class GitBlitWebApp extends WebApplication {
 
@@ -191,6 +192,7 @@ public class GitBlitWebApp extends WebApplication {
                mount("/tickets/export", ExportTicketPage.class, "r", "h");
                mount("/milestones/new", NewMilestonePage.class, "r");
                mount("/milestones/edit", EditMilestonePage.class, "r", "h");
+               mount("/mytickets", MyTicketsPage.class, "r", "h");
 
                // setup the markup document urls
                mount("/docs", DocsPage.class, "r");
index 1394890f5c53ee00dd7642f9d5c0135ad865fd39..030c5ebeb6d5ad7c22afcf9f25e341a147f56d45 100644 (file)
@@ -677,4 +677,5 @@ gb.editMilestone = edit milestone
 gb.notifyChangedOpenTickets = send notification for changed open tickets
 gb.overdue = overdue
 gb.openMilestones = open milestones
-gb.closedMilestones = closed milestones
\ No newline at end of file
+gb.closedMilestones = closed milestones
+gb.mytickets = my tickets
\ No newline at end of file
index 8a725cf48ff85475140582fffd57eb7bd1c07931..75a3ab7a9cdedce339e35f7dfd87daef05b3afbb 100644 (file)
@@ -670,3 +670,4 @@ gb.repositoryDoesNotAcceptPatchsets = Ce d
 gb.serverDoesNotAcceptPatchsets = Ce serveur n'accepte pas de patchsets.
 gb.ticketIsClosed = Ce ticket est clos.
 gb.mergeToDescription = default integration branch for merging ticket patchsets
+gb.mytickets = mes tickets
diff --git a/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.html
new file mode 100644 (file)
index 0000000..bbb2b96
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"  
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  
+      xml:lang="en"  
+      lang="en"> 
+
+<body>
+       <wicket:extend>
+               <table>
+                       <span>Responsible Tickets</span>
+                       <tbody>
+                               <tr wicket:id="responsibleTickets">
+                                       <td><span wicket:id="ticketName"></span></td>
+                                       <td><span wicket:id="ticketDescription"></span></td>
+                               </tr>
+                       </tbody>
+               </table>
+               
+               <table>
+                       <span>Author Tickets</span>
+                       <tbody>
+                               <tr wicket:id="authorTickets">
+                                       <td><span wicket:id="ticketName"></span></td>
+                                       <td><span wicket:id="ticketDescription"></span></td>
+                               </tr>
+                       </tbody>
+               </table>
+               
+               <table>
+                       <span>Voted Tickets</span>
+                       <tbody>
+                               <tr wicket:id="votedTickets">
+                                       <td><span wicket:id="ticketName"></span></td>
+                                       <td><span wicket:id="ticketDescription"></span></td>
+                               </tr>
+                       </tbody>
+               </table>
+               
+               <table>
+                       <span>Watched Tickets</span>
+                       <tbody>
+                               <tr wicket:id="watchedTickets">
+                                       <td><span wicket:id="ticketName"></span></td>
+                                       <td><span wicket:id="ticketDescription"></span></td>
+                               </tr>
+                       </tbody>
+               </table>
+       </wicket:extend>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java b/src/main/java/com/gitblit/wicket/pages/MyTicketsPage.java
new file mode 100644 (file)
index 0000000..509b00c
--- /dev/null
@@ -0,0 +1,128 @@
+package com.gitblit.wicket.pages;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.gitblit.models.UserModel;
+import com.gitblit.models.TicketModel;
+import com.gitblit.tickets.ITicketService;
+import com.gitblit.wicket.GitBlitWebApp;
+import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.panels.LinkPanel;
+
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.PageParameters;
+
+public class MyTicketsPage extends RootPage {
+       
+       public MyTicketsPage(PageParameters params)
+       {
+               this(); 
+       }
+       
+       public MyTicketsPage()
+       {
+               super();
+               setupPage("", "");
+               
+               UserModel currentUser = GitBlitWebSession.get().getUser();
+               if (currentUser == null) {
+                       currentUser = UserModel.ANONYMOUS;
+               }
+               String username = currentUser.getName();
+               
+               ITicketService tickets = GitBlitWebApp.get().tickets();
+               List<TicketModel> returnedTickets = tickets.getTickets(null);
+               
+               List<TicketModel> responsibleTickets = new ArrayList<TicketModel>();
+               List<TicketModel> authorTickets = new ArrayList<TicketModel>();
+               List<TicketModel> votedTickets = new ArrayList<TicketModel>();
+               List<TicketModel> watchedTickets = new ArrayList<TicketModel>();
+               for(int i = 0; i < returnedTickets.size(); i++)
+               {
+                       TicketModel ticket = returnedTickets.get(i);
+                       if(ticket.isOpen())
+                       {
+                               if(ticket.isResponsible(username))
+                               {
+                                       responsibleTickets.add(ticket);
+                               }
+                               if(ticket.isAuthor(username))
+                               {
+                                       authorTickets.add(ticket);
+                               }
+                               if(ticket.isVoter(username))
+                               {
+                                       votedTickets.add(ticket);
+                               }
+                               if(ticket.isWatching(username))
+                               {
+                                       watchedTickets.add(ticket);
+                               }
+                       }
+               }
+               
+               ListView<TicketModel> responsibleView = new ListView<TicketModel>("responsibleTickets", responsibleTickets)
+               {
+                       private static final long serialVersionUID = 1L;
+                       
+                       @Override
+                       public void populateItem(final ListItem<TicketModel> item)
+                       {
+                               final TicketModel ticket = item.getModelObject();
+                               String ticketUrl = app().tickets().getTicketUrl(ticket);
+                               item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl));
+                               item.add(new Label("ticketDescription", ticket.body));
+                       }
+               };
+               
+               ListView<TicketModel> authorView = new ListView<TicketModel>("authorTickets", authorTickets)
+               {
+                       private static final long serialVersionUID = 1L;
+                       
+                       @Override
+                       public void populateItem(final ListItem<TicketModel> item)
+                       {
+                               final TicketModel ticket = item.getModelObject();
+                               String ticketUrl = app().tickets().getTicketUrl(ticket);
+                               item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl));
+                               item.add(new Label("ticketDescription", ticket.body));
+                       }
+               };
+               
+               ListView<TicketModel> votedView = new ListView<TicketModel>("votedTickets", votedTickets)
+               {
+                       private static final long serialVersionUID = 1L;
+                       
+                       @Override
+                       public void populateItem(final ListItem<TicketModel> item)
+                       {
+                               final TicketModel ticket = item.getModelObject();
+                               String ticketUrl = app().tickets().getTicketUrl(ticket);
+                               item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl));
+                               item.add(new Label("ticketDescription", ticket.body));
+                       }
+               };
+               
+               ListView<TicketModel> watchedView = new ListView<TicketModel>("watchedTickets", watchedTickets)
+               {
+                       private static final long serialVersionUID = 1L;
+                       
+                       @Override
+                       public void populateItem(final ListItem<TicketModel> item)
+                       {
+                               final TicketModel ticket = item.getModelObject();
+                               String ticketUrl = app().tickets().getTicketUrl(ticket);
+                               item.add(new LinkPanel("ticketName", "", ticket.title, ticketUrl));
+                               item.add(new Label("ticketDescription", ticket.body));
+                       }
+               };
+               
+               add(responsibleView);
+               add(authorView);
+               add(votedView);
+               add(watchedView);
+       }
+}
index 5ccc3a4cded3ac19029ca0b914d3c9b03491c7fa..ec413b1927ca9e1a7b028ddc119a321372a094de 100644 (file)
@@ -173,6 +173,7 @@ public abstract class RootPage extends BasePage {
                        pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,\r
                                        getRootPageParameters()));\r
                        pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters()));\r
+                       pages.add(new PageRegistration("gb.mytickets", MyTicketsPage.class, getRootPageParameters()));\r
                        if (app().settings().getBoolean(Keys.web.allowLuceneIndexing, true)) {\r
                                pages.add(new PageRegistration("gb.search", LuceneSearchPage.class));\r
                        }\r