Package com.gitblit.models.TicketModel

Examples of com.gitblit.models.TicketModel.Status


    DataView<Status> statiiLinks = new DataView<Status>("statii", resolutionsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Status> item) {
        final Status status = item.getModelObject();
        PageParameters p = queryParameters(queryParam, milestoneParam, new String [] { status.name().toLowerCase() }, assignedToParam, sortBy, desc, 1);
        String css = getStatusClass(status);
        item.add(new LinkPanel("statusLink", css, status.toString(), TicketsPage.class, p).setRenderBodyOnly(true));
      }
    };
    add(statiiLinks);

    // responsible filter
View Full Code Here


              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                Status status = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.status, status);
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            String css = getStatusClass(item.getModel().getObject());
            WicketUtils.setCssClass(link, css);
            item.add(link);
          }
        };
        controls.add(statusView);

        /*
         * RESPONSIBLE LIST
         */
        Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
        for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
          if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {
            userlist.add(rp.registrant);
          }
        }
        List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
        if (!StringUtils.isEmpty(ticket.responsible)) {
          // exclude the current responsible
          userlist.remove(ticket.responsible);
        }
        for (String username : userlist) {
          UserModel u = app().users().getUserModel(username);
          if (u != null) {
            responsibles.add(new TicketResponsible(u));
          }
        }
        Collections.sort(responsibles);
        responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
        ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
        DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketResponsible> item) {
            SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketResponsible responsible = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.responsible, responsible.username);
                if (!StringUtils.isEmpty(responsible.username)) {
                  if (!ticket.isWatching(responsible.username)) {
                    change.watch(responsible.username);
                  }
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(responsibleView);

        /*
         * MILESTONE LIST
         */
        List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
        if (!StringUtils.isEmpty(ticket.milestone)) {
          for (TicketMilestone milestone : milestones) {
            if (milestone.name.equals(ticket.milestone)) {
              milestones.remove(milestone);
              break;
            }
          }
        }
        milestones.add(new TicketMilestone(ESC_NIL));
        ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
        DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketMilestone> item) {
            SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketMilestone milestone = getModel().getObject();
                Change change = new Change(user.username);
                if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
                  change.setField(Field.milestone, "");
                } else {
                  change.setField(Field.milestone, milestone.name);
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(milestoneView);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      } else {
        /*
         * CLOSED TICKET
         */
        Fragment controls = new Fragment("controls", "closedControlsFragment", this);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      }
    } else {
      add(new Label("controls").setVisible(false));
    }


    /*
     * TICKET METADATA
     */
    add(new Label("ticketType", ticket.type.toString()));
    if (StringUtils.isEmpty(ticket.topic)) {
      add(new Label("ticketTopic").setVisible(false));
    } else {
      // process the topic using the bugtraq config to link things
      String topic = bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName, ticket.topic);
      add(new Label("ticketTopic", topic).setEscapeModelStrings(false));
    }


    /*
     * VOTERS
     */
    List<String> voters = ticket.getVoters();
    Label votersCount = new Label("votes", "" + voters.size());
    if (voters.size() == 0) {
      WicketUtils.setCssClass(votersCount, "badge");
    } else {
      WicketUtils.setCssClass(votersCount, "badge badge-info");
    }
    add(votersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isVoter(user.username)) {
        model = Model.of(getString("gb.removeVote"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.vote"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("voteLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isVoter(user.username)) {
            change.unvote(user.username);
          } else {
            change.vote(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("voteLink").setVisible(false));
    }


    /*
     * WATCHERS
     */
    List<String> watchers = ticket.getWatchers();
    Label watchersCount = new Label("watchers", "" + watchers.size());
    if (watchers.size() == 0) {
      WicketUtils.setCssClass(watchersCount, "badge");
    } else {
      WicketUtils.setCssClass(watchersCount, "badge badge-info");
    }
    add(watchersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isWatching(user.username)) {
        model = Model.of(getString("gb.stopWatching"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.watch"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("watchLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isWatching(user.username)) {
            change.unwatch(user.username);
          } else {
            change.watch(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("watchLink").setVisible(false));
    }


    /*
     * TOPIC & LABELS (DISCUSSION TAB->SIDE BAR)
     */
    ListDataProvider<String> labelsDp = new ListDataProvider<String>(ticket.getLabels());
    DataView<String> labelsView = new DataView<String>("labels", labelsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<String> item) {
        final String value = item.getModelObject();
        Label label = new Label("label", value);
        TicketLabel tLabel = app().tickets().getLabel(repository, value);
        String background = MessageFormat.format("background-color:{0};", tLabel.color);
        label.add(new SimpleAttributeModifier("style", background));
        item.add(label);
      }
    };

    add(labelsView);


    /*
     * COMMENTS & STATUS CHANGES (DISCUSSION TAB)
     */
    if (comments.size() == 0) {
      add(new Label("discussion").setVisible(false));
    } else {
      Fragment discussionFragment = new Fragment("discussion", "discussionFragment", this);
      ListDataProvider<Change> discussionDp = new ListDataProvider<Change>(discussion);
      DataView<Change> discussionView = new DataView<Change>("discussion", discussionDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Change> item) {
          final Change entry = item.getModelObject();
          if (entry.isMerge()) {
            /*
             * MERGE
             */
            String resolvedBy = entry.getString(Field.mergeSha);

            // identify the merged patch, it is likely the last
            Patchset mergedPatch = null;
            for (Change c : revisions) {
              if (c.patchset.tip.equals(resolvedBy)) {
                mergedPatch = c.patchset;
                break;
              }
            }

            String commitLink;
            if (mergedPatch == null) {
              // shouldn't happen, but just-in-case
              int len = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
              commitLink = resolvedBy.substring(0, len);
            } else {
              // expected result
              commitLink = mergedPatch.toString();
            }

            Fragment mergeFragment = new Fragment("entry", "mergeFragment", this);
            mergeFragment.add(new LinkPanel("commitLink", null, commitLink,
                CommitPage.class, WicketUtils.newObjectParameter(repositoryName, resolvedBy)));
            mergeFragment.add(new Label("toBranch", MessageFormat.format(getString("gb.toBranch"),
                "<b>" + ticket.mergeTo + "</b>")).setEscapeModelStrings(false));
            addUserAttributions(mergeFragment, entry, 0);
            addDateAttributions(mergeFragment, entry);

            item.add(mergeFragment);
          } else if (entry.isStatusChange()) {
            /*
             *  STATUS CHANGE
             */
            Fragment frag = new Fragment("entry", "statusFragment", this);
            Label status = new Label("statusChange", entry.getStatus().toString());
            String css = getLozengeClass(entry.getStatus(), false);
            WicketUtils.setCssClass(status, css);
            for (IBehavior b : status.getBehaviors()) {
              if (b instanceof SimpleAttributeModifier) {
                SimpleAttributeModifier sam = (SimpleAttributeModifier) b;
                if ("class".equals(sam.getAttribute())) {
                  status.add(new SimpleAttributeModifier("class", "status-change " + sam.getValue()));
                  break;
                }
              }
            }
            frag.add(status);
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          } else {
            /*
             * COMMENT
             */
            String comment = MarkdownUtils.transformGFM(app().settings(), entry.comment.text, repositoryName);
            Fragment frag = new Fragment("entry", "commentFragment", this);
            Label commentIcon = new Label("commentIcon");
            if (entry.comment.src == CommentSource.Email) {
              WicketUtils.setCssClass(commentIcon, "iconic-mail");
            } else {
              WicketUtils.setCssClass(commentIcon, "iconic-comment-alt2-stroke");
            }
            frag.add(commentIcon);
            frag.add(new Label("comment", comment).setEscapeModelStrings(false));
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          }
        }
      };
      discussionFragment.add(discussionView);
      add(discussionFragment);
    }

    /*
     * ADD COMMENT PANEL
     */
    if (UserModel.ANONYMOUS.equals(user)
        || !repository.isBare
        || repository.isFrozen
        || repository.isMirror) {

      // prohibit comments for anonymous users, local working copy repos,
      // frozen repos, and mirrors
      add(new Label("newComment").setVisible(false));
    } else {
      // permit user to comment
      Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
      GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,
          "gravatar-round", avatarWidth, true);
      newComment.add(img);
      CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
      commentPanel.setRepository(repositoryName);
      newComment.add(commentPanel);
      add(newComment);
    }


    /*
     *  PATCHSET TAB
     */
    if (currentPatchset == null) {
      // no patchset available
      RepositoryUrl repoUrl = getRepositoryUrl(user, repository);
      boolean canPropose = repoUrl != null && repoUrl.permission.atLeast(AccessPermission.CLONE) && !UserModel.ANONYMOUS.equals(user);
      if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && canPropose) {
        // ticket & repo will accept a proposal patchset
        // show the instructions for proposing a patchset
        Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
        changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
        changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
        changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        add(changeIdFrag);
      } else {
        // explain why you can't propose a patchset
        Fragment fragment = new Fragment("patchset", "canNotProposeFragment", this);
        String reason = "";
        if (ticket.isClosed()) {
          reason = getString("gb.ticketIsClosed");
        } else if (repository.isMirror) {
          reason = getString("gb.repositoryIsMirror");
        } else if (repository.isFrozen) {
          reason = getString("gb.repositoryIsFrozen");
        } else if (!repository.acceptNewPatchsets) {
          reason = getString("gb.repositoryDoesNotAcceptPatchsets");
        } else if (!canPropose) {
          if (UserModel.ANONYMOUS.equals(user)) {
            reason = getString("gb.anonymousCanNotPropose");
          } else {
            reason = getString("gb.youDoNotHaveClonePermission");
          }
        } else {
          reason = getString("gb.serverDoesNotAcceptPatchsets");
        }
        fragment.add(new Label("reason", reason));
        add(fragment);
      }
    } else {
      // show current patchset
      Fragment patchsetFrag = new Fragment("patchset", "patchsetFragment", this);
      patchsetFrag.add(new Label("commitsInPatchset", MessageFormat.format(getString("gb.commitsInPatchsetN"), currentPatchset.number)));

      patchsetFrag.add(createMergePanel(user, repository));

      if (ticket.isOpen()) {
        // current revision
        MarkupContainer panel = createPatchsetPanel("panel", repository, user);
        patchsetFrag.add(panel);
        addUserAttributions(patchsetFrag, currentRevision, avatarWidth);
        addUserAttributions(panel, currentRevision, 0);
        addDateAttributions(panel, currentRevision);
      } else {
        // current revision
        patchsetFrag.add(new Label("panel").setVisible(false));
      }

      // commits
      List<RevCommit> commits = JGitUtils.getRevLog(getRepository(), currentPatchset.base, currentPatchset.tip);
      ListDataProvider<RevCommit> commitsDp = new ListDataProvider<RevCommit>(commits);
      DataView<RevCommit> commitsView = new DataView<RevCommit>("commit", commitsDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RevCommit> item) {
          RevCommit commit = item.getModelObject();
          PersonIdent author = commit.getAuthorIdent();
          item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
          item.add(new Label("author", commit.getAuthorIdent().getName()));
          item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
              CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new LinkPanel("diff", "link", getString("gb.diff"), CommitDiffPage.class,
              WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new Label("title", StringUtils.trimString(commit.getShortMessage(), Constants.LEN_SHORTLOG_REFS)));
          item.add(WicketUtils.createDateLabel("commitDate", JGitUtils.getCommitDate(commit), GitBlitWebSession
              .get().getTimezone(), getTimeUtils(), false));
          item.add(new DiffStatPanel("commitDiffStat", 0, 0, true));
        }
      };
      patchsetFrag.add(commitsView);
      add(patchsetFrag);
    }


    /*
     * ACTIVITY TAB
     */
    Fragment revisionHistory = new Fragment("activity", "activityFragment", this);
    List<Change> events = new ArrayList<Change>(ticket.changes);
    Collections.sort(events);
    Collections.reverse(events);
    ListDataProvider<Change> eventsDp = new ListDataProvider<Change>(events);
    DataView<Change> eventsView = new DataView<Change>("event", eventsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Change> item) {
        Change event = item.getModelObject();

        addUserAttributions(item, event, 16);

        if (event.hasPatchset()) {
          // patchset
          Patchset patchset = event.patchset;
          String what;
          if (event.isStatusChange() && (Status.New == event.getStatus())) {
            what = getString("gb.proposedThisChange");
          } else if (patchset.rev == 1) {
            what = MessageFormat.format(getString("gb.uploadedPatchsetN"), patchset.number);
          } else {
            if (patchset.added == 1) {
              what = getString("gb.addedOneCommit");
            } else {
              what = MessageFormat.format(getString("gb.addedNCommits"), patchset.added);
            }
          }
          item.add(new Label("what", what));

          LinkPanel psr = new LinkPanel("patchsetRevision", null, patchset.number + "-" + patchset.rev,
              ComparePage.class, WicketUtils.newRangeParameter(repositoryName, patchset.parent == null ? patchset.base : patchset.parent, patchset.tip), true);
          WicketUtils.setHtmlTooltip(psr, patchset.toString());
          item.add(psr);
          String typeCss = getPatchsetTypeCss(patchset.type);
          Label typeLabel = new Label("patchsetType", patchset.type.toString());
          if (typeCss == null) {
            typeLabel.setVisible(false);
          } else {
            WicketUtils.setCssClass(typeLabel, typeCss);
          }
          item.add(typeLabel);

          // show commit diffstat
          item.add(new DiffStatPanel("patchsetDiffStat", patchset.insertions, patchset.deletions, patchset.rev > 1));
        } else if (event.hasComment()) {
          // comment
          item.add(new Label("what", getString("gb.commented")));
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));
        } else if (event.hasReview()) {
          // review
          String score;
          switch (event.review.score) {
          case approved:
            score = "<span style='color:darkGreen'>" + getScoreDescription(event.review.score) + "</span>";
            break;
          case vetoed:
            score = "<span style='color:darkRed'>" + getScoreDescription(event.review.score) + "</span>";
            break;
          default:
            score = getScoreDescription(event.review.score);
          }
          item.add(new Label("what", MessageFormat.format(getString("gb.reviewedPatchsetRev"),
              event.review.patchset, event.review.rev, score))
              .setEscapeModelStrings(false));
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));
        } else {
          // field change
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));

          String what = "";
          if (event.isStatusChange()) {
          switch (event.getStatus()) {
          case New:
            if (ticket.isProposal()) {
              what = getString("gb.proposedThisChange");
            } else {
              what = getString("gb.createdThisTicket");
            }
            break;
          default:
            break;
          }
          }
          item.add(new Label("what", what).setVisible(what.length() > 0));
        }

        addDateAttributions(item, event);

        if (event.hasFieldChanges()) {
          StringBuilder sb = new StringBuilder();
          sb.append("<table class=\"summary\"><tbody>");
          for (Map.Entry<Field, String> entry : event.fields.entrySet()) {
            String value;
            switch (entry.getKey()) {
              case body:
                String body = entry.getValue();
                if (event.isStatusChange() && Status.New == event.getStatus() && StringUtils.isEmpty(body)) {
                  // ignore initial empty description
                  continue;
                }
                // trim body changes
                if (StringUtils.isEmpty(body)) {
                  value = "<i>" + ESC_NIL + "</i>";
                } else {
                  value = StringUtils.trimString(body, Constants.LEN_SHORTLOG_REFS);
                }
                break;
              case status:
                // special handling for status
                Status status = event.getStatus();
                String css = getLozengeClass(status, true);
                value = String.format("<span class=\"%1$s\">%2$s</span>", css, status.toString());
                break;
              default:
                value = StringUtils.isEmpty(entry.getValue()) ? ("<i>" + ESC_NIL + "</i>") : StringUtils.escapeForHtml(entry.getValue(), false);
                break;
            }
View Full Code Here

            || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {
          // description change
          change.setField(Field.body, description);
        }

        Status status = statusModel.getObject();
        if (!ticket.status.equals(status)) {
          // status change
          change.setField(Field.status, status);
        }
View Full Code Here

    DataView<Status> statiiLinks = new DataView<Status>("statii", resolutionsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Status> item) {
        final Status status = item.getModelObject();
        PageParameters p = queryParameters(queryParam, milestoneParam, new String [] { status.name().toLowerCase() }, assignedToParam, sortBy, desc, 1);
        String css = TicketsUI.getStatusClass(status);
        item.add(new LinkPanel("statusLink", css, status.toString(), TicketsPage.class, p).setRenderBodyOnly(true));
      }
    };
    add(statiiLinks);

    // responsible filter
View Full Code Here

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                Status status = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.status, status);
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            String css = TicketsUI.getStatusClass(item.getModel().getObject());
            WicketUtils.setCssClass(link, css);
            item.add(link);
          }
        };
        controls.add(statusView);

        /*
         * RESPONSIBLE LIST
         */
        Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
        if (UserModel.ANONYMOUS.canPush(getRepositoryModel())
            || AuthorizationControl.AUTHENTICATED == getRepositoryModel().authorizationControl) {
          //   authorization is ANONYMOUS or AUTHENTICATED (i.e. all users can be set responsible)
          userlist.addAll(app().users().getAllUsernames());
        } else {
          // authorization is by NAMED users (users with PUSH permission can be set responsible)
          for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
            if (rp.permission.atLeast(AccessPermission.PUSH)) {
              userlist.add(rp.registrant);
            }
          }
        }
        List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
        if (!StringUtils.isEmpty(ticket.responsible)) {
          // exclude the current responsible
          userlist.remove(ticket.responsible);
        }
        for (String username : userlist) {
          UserModel u = app().users().getUserModel(username);
          if (u != null) {
            responsibles.add(new TicketResponsible(u));
          }
        }
        Collections.sort(responsibles);
        responsibles.add(new TicketResponsible(ESC_NIL, "", ""));
        ListDataProvider<TicketResponsible> responsibleDp = new ListDataProvider<TicketResponsible>(responsibles);
        DataView<TicketResponsible> responsibleView = new DataView<TicketResponsible>("newResponsible", responsibleDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketResponsible> item) {
            SimpleAjaxLink<TicketResponsible> link = new SimpleAjaxLink<TicketResponsible>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketResponsible responsible = getModel().getObject();
                Change change = new Change(user.username);
                change.setField(Field.responsible, responsible.username);
                if (!StringUtils.isEmpty(responsible.username)) {
                  if (!ticket.isWatching(responsible.username)) {
                    change.watch(responsible.username);
                  }
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(responsibleView);

        /*
         * MILESTONE LIST
         */
        List<TicketMilestone> milestones = app().tickets().getMilestones(repository, Status.Open);
        if (!StringUtils.isEmpty(ticket.milestone)) {
          for (TicketMilestone milestone : milestones) {
            if (milestone.name.equals(ticket.milestone)) {
              milestones.remove(milestone);
              break;
            }
          }
        }
        milestones.add(new TicketMilestone(ESC_NIL));
        ListDataProvider<TicketMilestone> milestoneDp = new ListDataProvider<TicketMilestone>(milestones);
        DataView<TicketMilestone> milestoneView = new DataView<TicketMilestone>("newMilestone", milestoneDp) {
          private static final long serialVersionUID = 1L;

          @Override
          public void populateItem(final Item<TicketMilestone> item) {
            SimpleAjaxLink<TicketMilestone> link = new SimpleAjaxLink<TicketMilestone>("link", item.getModel()) {

              private static final long serialVersionUID = 1L;

              @Override
              public void onClick(AjaxRequestTarget target) {
                TicketMilestone milestone = getModel().getObject();
                Change change = new Change(user.username);
                if (NIL.equals(milestone.name) || ESC_NIL.equals(milestone.name)) {
                  change.setField(Field.milestone, "");
                } else {
                  change.setField(Field.milestone, milestone.name);
                }
                if (!ticket.isWatching(user.username)) {
                  change.watch(user.username);
                }
                TicketModel update = app().tickets().updateTicket(repository, ticket.number, change);
                app().tickets().createNotifier().sendMailing(update);
                setResponsePage(TicketsPage.class, getPageParameters());
              }
            };
            item.add(link);
          }
        };
        controls.add(milestoneView);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      } else {
        /*
         * CLOSED TICKET
         */
        Fragment controls = new Fragment("controls", "closedControlsFragment", this);

        String editHref = urlFor(EditTicketPage.class, params).toString();
        controls.add(new ExternalLink("editLink", editHref, getString("gb.edit")));

        add(controls);
      }
    } else {
      add(new Label("controls").setVisible(false));
    }


    /*
     * TICKET METADATA
     */
    add(new Label("ticketType", ticket.type.toString()));
    if (StringUtils.isEmpty(ticket.topic)) {
      add(new Label("ticketTopic").setVisible(false));
    } else {
      // process the topic using the bugtraq config to link things
      String topic = bugtraqProcessor().processText(getRepository(), repositoryName, ticket.topic);
      String safeTopic = app().xssFilter().relaxed(topic);
      add(new Label("ticketTopic", safeTopic).setEscapeModelStrings(false));
    }


    /*
     * VOTERS
     */
    List<String> voters = ticket.getVoters();
    Label votersCount = new Label("votes", "" + voters.size());
    if (voters.size() == 0) {
      WicketUtils.setCssClass(votersCount, "badge");
    } else {
      WicketUtils.setCssClass(votersCount, "badge badge-info");
    }
    add(votersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isVoter(user.username)) {
        model = Model.of(getString("gb.removeVote"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.vote"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("voteLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isVoter(user.username)) {
            change.unvote(user.username);
          } else {
            change.vote(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("voteLink").setVisible(false));
    }


    /*
     * WATCHERS
     */
    List<String> watchers = ticket.getWatchers();
    Label watchersCount = new Label("watchers", "" + watchers.size());
    if (watchers.size() == 0) {
      WicketUtils.setCssClass(watchersCount, "badge");
    } else {
      WicketUtils.setCssClass(watchersCount, "badge badge-info");
    }
    add(watchersCount);
    if (user.isAuthenticated && app().tickets().isAcceptingTicketUpdates(repository)) {
      Model<String> model;
      if (ticket.isWatching(user.username)) {
        model = Model.of(getString("gb.stopWatching"));
      } else {
        model = Model.of(MessageFormat.format(getString("gb.watch"), ticket.type.toString()));
      }
      SimpleAjaxLink<String> link = new SimpleAjaxLink<String>("watchLink", model) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
          Change change = new Change(user.username);
          if (ticket.isWatching(user.username)) {
            change.unwatch(user.username);
          } else {
            change.watch(user.username);
          }
          app().tickets().updateTicket(repository, ticket.number, change);
          setResponsePage(TicketsPage.class, getPageParameters());
        }
      };
      add(link);
    } else {
      add(new Label("watchLink").setVisible(false));
    }


    /*
     * TOPIC & LABELS (DISCUSSION TAB->SIDE BAR)
     */
    ListDataProvider<String> labelsDp = new ListDataProvider<String>(ticket.getLabels());
    DataView<String> labelsView = new DataView<String>("labels", labelsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<String> item) {
        final String value = item.getModelObject();
        Label label = new Label("label", value);
        TicketLabel tLabel = app().tickets().getLabel(repository, value);
        String background = MessageFormat.format("background-color:{0};", tLabel.color);
        label.add(new SimpleAttributeModifier("style", background));
        item.add(label);
      }
    };

    add(labelsView);


    /*
     * COMMENTS & STATUS CHANGES (DISCUSSION TAB)
     */
    if (comments.size() == 0) {
      add(new Label("discussion").setVisible(false));
    } else {
      Fragment discussionFragment = new Fragment("discussion", "discussionFragment", this);
      ListDataProvider<Change> discussionDp = new ListDataProvider<Change>(discussion);
      DataView<Change> discussionView = new DataView<Change>("discussion", discussionDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<Change> item) {
          final Change entry = item.getModelObject();
          if (entry.isMerge()) {
            /*
             * MERGE
             */
            String resolvedBy = entry.getString(Field.mergeSha);

            // identify the merged patch, it is likely the last
            Patchset mergedPatch = null;
            for (Change c : revisions) {
              if (c.patchset.tip.equals(resolvedBy)) {
                mergedPatch = c.patchset;
                break;
              }
            }

            String commitLink;
            if (mergedPatch == null) {
              // shouldn't happen, but just-in-case
              int len = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
              commitLink = resolvedBy.substring(0, len);
            } else {
              // expected result
              commitLink = mergedPatch.toString();
            }

            Fragment mergeFragment = new Fragment("entry", "mergeFragment", this);
            mergeFragment.add(new LinkPanel("commitLink", null, commitLink,
                CommitPage.class, WicketUtils.newObjectParameter(repositoryName, resolvedBy)));
            mergeFragment.add(new Label("toBranch", MessageFormat.format(getString("gb.toBranch"),
                "<b>" + ticket.mergeTo + "</b>")).setEscapeModelStrings(false));
            addUserAttributions(mergeFragment, entry, 0);
            addDateAttributions(mergeFragment, entry);

            item.add(mergeFragment);
          } else if (entry.isStatusChange()) {
            /*
             *  STATUS CHANGE
             */
            Fragment frag = new Fragment("entry", "statusFragment", this);
            Label status = new Label("statusChange", entry.getStatus().toString());
            String css = TicketsUI.getLozengeClass(entry.getStatus(), false);
            WicketUtils.setCssClass(status, css);
            frag.add(status);
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          } else {
            /*
             * COMMENT
             */
            String bugtraq = bugtraqProcessor().processText(getRepository(), repositoryName, entry.comment.text);
            String comment = MarkdownUtils.transformGFM(app().settings(), bugtraq, repositoryName);
            String safeComment = app().xssFilter().relaxed(comment);
            Fragment frag = new Fragment("entry", "commentFragment", this);
            Label commentIcon = new Label("commentIcon");
            if (entry.comment.src == CommentSource.Email) {
              WicketUtils.setCssClass(commentIcon, "iconic-mail");
            } else {
              WicketUtils.setCssClass(commentIcon, "iconic-comment-alt2-stroke");
            }
            frag.add(commentIcon);
            frag.add(new Label("comment", safeComment).setEscapeModelStrings(false));
            addUserAttributions(frag, entry, avatarWidth);
            addDateAttributions(frag, entry);
            item.add(frag);
          }
        }
      };
      discussionFragment.add(discussionView);
      add(discussionFragment);
    }

    /*
     * ADD COMMENT PANEL
     */
    if (UserModel.ANONYMOUS.equals(user)
        || !repository.isBare
        || repository.isFrozen
        || repository.isMirror) {

      // prohibit comments for anonymous users, local working copy repos,
      // frozen repos, and mirrors
      add(new Label("newComment").setVisible(false));
    } else {
      // permit user to comment
      Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
      GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,
          "gravatar-round", avatarWidth, true);
      newComment.add(img);
      CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
      commentPanel.setRepository(repositoryName);
      newComment.add(commentPanel);
      add(newComment);
    }


    /*
     *  PATCHSET TAB
     */
    if (currentPatchset == null) {
      // no patchset available
      RepositoryUrl repoUrl = getRepositoryUrl(user, repository);
      boolean canPropose = repoUrl != null && repoUrl.permission.atLeast(AccessPermission.CLONE) && !UserModel.ANONYMOUS.equals(user);
      if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && canPropose) {
        // ticket & repo will accept a proposal patchset
        // show the instructions for proposing a patchset
        Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);
        changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));
        changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));
        changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));
        add(changeIdFrag);
      } else {
        // explain why you can't propose a patchset
        Fragment fragment = new Fragment("patchset", "canNotProposeFragment", this);
        String reason = "";
        if (ticket.isClosed()) {
          reason = getString("gb.ticketIsClosed");
        } else if (repository.isMirror) {
          reason = getString("gb.repositoryIsMirror");
        } else if (repository.isFrozen) {
          reason = getString("gb.repositoryIsFrozen");
        } else if (!repository.acceptNewPatchsets) {
          reason = getString("gb.repositoryDoesNotAcceptPatchsets");
        } else if (!canPropose) {
          if (UserModel.ANONYMOUS.equals(user)) {
            reason = getString("gb.anonymousCanNotPropose");
          } else {
            reason = getString("gb.youDoNotHaveClonePermission");
          }
        } else {
          reason = getString("gb.serverDoesNotAcceptPatchsets");
        }
        fragment.add(new Label("reason", reason));
        add(fragment);
      }
    } else {
      // show current patchset
      Fragment patchsetFrag = new Fragment("patchset", "patchsetFragment", this);
      patchsetFrag.add(new Label("commitsInPatchset", MessageFormat.format(getString("gb.commitsInPatchsetN"), currentPatchset.number)));

      patchsetFrag.add(createMergePanel(user, repository));

      if (ticket.isOpen()) {
        // current revision
        MarkupContainer panel = createPatchsetPanel("panel", repository, user);
        patchsetFrag.add(panel);
        addUserAttributions(patchsetFrag, currentRevision, avatarWidth);
        addUserAttributions(panel, currentRevision, 0);
        addDateAttributions(panel, currentRevision);
      } else {
        // current revision
        patchsetFrag.add(new Label("panel").setVisible(false));
      }

      // commits
      List<RevCommit> commits = JGitUtils.getRevLog(getRepository(), currentPatchset.base, currentPatchset.tip);
      ListDataProvider<RevCommit> commitsDp = new ListDataProvider<RevCommit>(commits);
      DataView<RevCommit> commitsView = new DataView<RevCommit>("commit", commitsDp) {
        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RevCommit> item) {
          RevCommit commit = item.getModelObject();
          PersonIdent author = commit.getAuthorIdent();
          item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
          item.add(new Label("author", commit.getAuthorIdent().getName()));
          item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
              CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new LinkPanel("diff", "link", getString("gb.diff"), CommitDiffPage.class,
              WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
          item.add(new Label("title", StringUtils.trimString(commit.getShortMessage(), Constants.LEN_SHORTLOG_REFS)));
          item.add(WicketUtils.createDateLabel("commitDate", JGitUtils.getCommitDate(commit), GitBlitWebSession
              .get().getTimezone(), getTimeUtils(), false));
          item.add(new DiffStatPanel("commitDiffStat", 0, 0, true));
        }
      };
      patchsetFrag.add(commitsView);
      add(patchsetFrag);
    }


    /*
     * ACTIVITY TAB
     */
    Fragment revisionHistory = new Fragment("activity", "activityFragment", this);
    List<Change> events = new ArrayList<Change>(ticket.changes);
    Collections.sort(events);
    Collections.reverse(events);
    ListDataProvider<Change> eventsDp = new ListDataProvider<Change>(events);
    DataView<Change> eventsView = new DataView<Change>("event", eventsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Change> item) {
        Change event = item.getModelObject();

        addUserAttributions(item, event, 16);

        if (event.hasPatchset()) {
          // patchset
          Patchset patchset = event.patchset;
          String what;
          if (event.isStatusChange() && (Status.New == event.getStatus())) {
            what = getString("gb.proposedThisChange");
          } else if (patchset.rev == 1) {
            what = MessageFormat.format(getString("gb.uploadedPatchsetN"), patchset.number);
          } else {
            if (patchset.added == 1) {
              what = getString("gb.addedOneCommit");
            } else {
              what = MessageFormat.format(getString("gb.addedNCommits"), patchset.added);
            }
          }
          item.add(new Label("what", what));

          LinkPanel psr = new LinkPanel("patchsetRevision", null, patchset.number + "-" + patchset.rev,
              ComparePage.class, WicketUtils.newRangeParameter(repositoryName, patchset.parent == null ? patchset.base : patchset.parent, patchset.tip), true);
          WicketUtils.setHtmlTooltip(psr, patchset.toString());
          item.add(psr);
          String typeCss = getPatchsetTypeCss(patchset.type);
          Label typeLabel = new Label("patchsetType", patchset.type.toString());
          if (typeCss == null) {
            typeLabel.setVisible(false);
          } else {
            WicketUtils.setCssClass(typeLabel, typeCss);
          }
          item.add(typeLabel);

          // show commit diffstat
          item.add(new DiffStatPanel("patchsetDiffStat", patchset.insertions, patchset.deletions, patchset.rev > 1));
        } else if (event.hasComment()) {
          // comment
          item.add(new Label("what", getString("gb.commented")));
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));
        } else if (event.hasReview()) {
          // review
          String score;
          switch (event.review.score) {
          case approved:
            score = "<span style='color:darkGreen'>" + getScoreDescription(event.review.score) + "</span>";
            break;
          case vetoed:
            score = "<span style='color:darkRed'>" + getScoreDescription(event.review.score) + "</span>";
            break;
          default:
            score = getScoreDescription(event.review.score);
          }
          item.add(new Label("what", MessageFormat.format(getString("gb.reviewedPatchsetRev"),
              event.review.patchset, event.review.rev, score))
              .setEscapeModelStrings(false));
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));
        } else {
          // field change
          item.add(new Label("patchsetRevision").setVisible(false));
          item.add(new Label("patchsetType").setVisible(false));
          item.add(new Label("patchsetDiffStat").setVisible(false));

          String what = "";
          if (event.isStatusChange()) {
          switch (event.getStatus()) {
          case New:
            if (ticket.isProposal()) {
              what = getString("gb.proposedThisChange");
            } else {
              what = getString("gb.createdThisTicket");
            }
            break;
          default:
            break;
          }
          }
          item.add(new Label("what", what).setVisible(what.length() > 0));
        }

        addDateAttributions(item, event);

        if (event.hasFieldChanges()) {
          StringBuilder sb = new StringBuilder();
          sb.append("<table class=\"summary\"><tbody>");
          for (Map.Entry<Field, String> entry : event.fields.entrySet()) {
            String value;
            switch (entry.getKey()) {
              case body:
                String body = entry.getValue();
                if (event.isStatusChange() && Status.New == event.getStatus() && StringUtils.isEmpty(body)) {
                  // ignore initial empty description
                  continue;
                }
                // trim body changes
                if (StringUtils.isEmpty(body)) {
                  value = "<i>" + ESC_NIL + "</i>";
                } else {
                  value = StringUtils.trimString(body, Constants.LEN_SHORTLOG_REFS);
                }
                break;
              case status:
                // special handling for status
                Status status = event.getStatus();
                String css = TicketsUI.getLozengeClass(status, true);
                value = String.format("<span class=\"%1$s\">%2$s</span>", css, status.toString());
                break;
              default:
                value = StringUtils.isEmpty(entry.getValue()) ? ("<i>" + ESC_NIL + "</i>") : StringUtils.escapeForHtml(entry.getValue(), false);
                break;
            }
View Full Code Here

    DataView<Status> statiiLinks = new DataView<Status>("statii", resolutionsDp) {
      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(final Item<Status> item) {
        final Status status = item.getModelObject();
        PageParameters p = queryParameters(queryParam, milestoneParam, new String [] { status.name().toLowerCase() }, assignedToParam, sortBy, desc, 1);
        String css = TicketsUI.getStatusClass(status);
        item.add(new LinkPanel("statusLink", css, status.toString(), MyTicketsPage.class, p).setRenderBodyOnly(true));
      }
    };
    add(statiiLinks);

    List<TicketSort> sortChoices = new ArrayList<TicketSort>();
View Full Code Here

        if (StringUtils.isEmpty(name)) {
          return;
        }

        Date due = dueModel.getObject();
        Status status = statusModel.getObject();
        boolean rename = !name.equals(oldName);
        boolean notify = notificationModel.getObject();

        UserModel currentUser = GitBlitWebSession.get().getUser();
        String createdBy = currentUser.username;
View Full Code Here

            || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {
          // description change
          change.setField(Field.body, description);
        }

        Status status = statusModel.getObject();
        if (!ticket.status.equals(status)) {
          // status change
          change.setField(Field.status, status);
        }
View Full Code Here

TOP

Related Classes of com.gitblit.models.TicketModel.Status

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.