Package com.gitblit.wicket.panels

Examples of com.gitblit.wicket.panels.GravatarImage


        } else {
          UserModel responsible = app().users().getUserModel(ticket.responsible);
          if (responsible == null) {
            responsible = new UserModel(ticket.responsible);
          }
          GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
              responsible.emailAddress, null, 16, true);
          avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
          item.add(avatar);
        }

        // votes indicator
        Label v = new Label("votes", "" + ticket.votesCount);
View Full Code Here


          String username = item.getModelObject();
          UserModel user = app().users().getUserModel(username);
          if (user == null) {
            user = new UserModel(username);
          }
          item.add(new GravatarImage("participant", user.getDisplayName(),
              user.emailAddress, null, 25, true));
        }
      };
      add(participantsView);
    } else {
      // gravatar prohibited
      add(new Label("participantsLabel").setVisible(false));
      add(new Label("participants").setVisible(false));
    }


    /*
     * LARGE STATUS INDICATOR WITH ICON (DISCUSSION TAB->SIDE BAR)
     */
    Fragment ticketStatus = new Fragment("ticketStatus", "ticketStatusFragment", this);
    Label ticketIcon = getStateIcon("ticketIcon", ticket);
    ticketStatus.add(ticketIcon);
    ticketStatus.add(new Label("ticketStatus", ticket.status.toString()));
    WicketUtils.setCssClass(ticketStatus, getLozengeClass(ticket.status, false));
    add(ticketStatus);


    /*
     * UPDATE FORM (DISCUSSION TAB)
     */
    if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
      if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
        /*
         * OPEN TICKET
         */
        Fragment controls = new Fragment("controls", "openControlsFragment", this);

        /*
         * STATUS
         */
        List<Status> choices = new ArrayList<Status>();
        if (ticket.isProposal()) {
          choices.addAll(Arrays.asList(TicketModel.Status.proposalWorkflow));
        } else if (ticket.isBug()) {
          choices.addAll(Arrays.asList(TicketModel.Status.bugWorkflow));
        } else {
          choices.addAll(Arrays.asList(TicketModel.Status.requestWorkflow));
        }
        choices.remove(ticket.status);

        ListDataProvider<Status> workflowDp = new ListDataProvider<Status>(choices);
        DataView<Status> statusView = new DataView<Status>("newStatus", workflowDp) {
          private static final long serialVersionUID = 1L;

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

              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));
View Full Code Here

  protected void addUserAttributions(MarkupContainer container, Change entry, int avatarSize) {
    UserModel commenter = app().users().getUserModel(entry.author);
    if (commenter == null) {
      // unknown user
      container.add(new GravatarImage("changeAvatar", entry.author,
          entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
      container.add(new Label("changeAuthor", entry.author.toLowerCase()));
    } else {
      // known user
      container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),
          commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
              avatarSize, true).setVisible(avatarSize > 0));
      container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
          UserPage.class, WicketUtils.newUsernameParameter(commenter.username)));
    }
View Full Code Here

    LinkPanel email = new LinkPanel("userEmail", null, user.emailAddress, "mailto:#");
    email.setRenderBodyOnly(true);
    add(email.setVisible(app().settings().getBoolean(Keys.web.showEmailAddresses, true) && !StringUtils.isEmpty(user.emailAddress)));

    PersonIdent person = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
    add(new GravatarImage("gravatar", person, 210));

    UserModel sessionUser = GitBlitWebSession.get().getUser();
    if (sessionUser != null && user.canCreate() && sessionUser.equals(user)) {
      // user can create personal repositories
      add(new BookmarkablePageLink<Void>("newRepository", EditRepositoryPage.class));
View Full Code Here

      public void populateItem(final Item<GitNote> item) {
        GitNote entry = item.getModelObject();
        item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
        item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
            Constants.SearchType.AUTHOR));
        item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
        item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
            .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
        item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
            entry.content)).setEscapeModelStrings(false));
      }
View Full Code Here

      UserModel user = session.getUser();
      boolean editCredentials = app().authentication().supportsCredentialChanges(user);
      boolean standardLogin = session.authenticationType.isStandard();

      if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
        add(new GravatarImage("username", user, "navbarGravatar", 20, false));
      } else {
        add(new Label("username", user.getDisplayName()));
      }

      add(new Label("displayName", user.getDisplayName()));
View Full Code Here

      public void populateItem(final Item<GitNote> item) {
        GitNote entry = item.getModelObject();
        item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
        item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
            Constants.SearchType.AUTHOR));
        item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
        item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
            .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
        item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
            entry.content)).setEscapeModelStrings(false));
      }
View Full Code Here

    default:
      typeKey = "gb.commit";
      linkClass = CommitPage.class;
      break;
    }
    add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));

    add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
    add(new Label("tagId", tagRef.getObjectId().getName()));
    add(new LinkPanel("taggedObject", "list", tagRef.getReferencedObjectId().getName(),
        linkClass, linkParameters));
View Full Code Here

          String username = item.getModelObject();
          UserModel user = app().users().getUserModel(username);
          if (user == null) {
            user = new UserModel(username);
          }
          item.add(new GravatarImage("participant", user.getDisplayName(),
              user.emailAddress, null, 25, true));
        }
      };
      add(participantsView);
    } else {
      // gravatar prohibited
      add(new Label("participantsLabel").setVisible(false));
      add(new Label("participants").setVisible(false));
    }


    /*
     * LARGE STATUS INDICATOR WITH ICON (DISCUSSION TAB->SIDE BAR)
     */
    Fragment ticketStatus = new Fragment("ticketStatus", "ticketStatusFragment", this);
    Label ticketIcon = TicketsUI.getStateIcon("ticketIcon", ticket);
    ticketStatus.add(ticketIcon);
    ticketStatus.add(new Label("ticketStatus", ticket.status.toString()));
    WicketUtils.setCssClass(ticketStatus, TicketsUI.getLozengeClass(ticket.status, false));
    add(ticketStatus);


    /*
     * UPDATE FORM (DISCUSSION TAB)
     */
    if (user.canEdit(ticket, repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
      if (user.canAdmin(ticket, repository) && ticket.isOpen()) {
        /*
         * OPEN TICKET
         */
        Fragment controls = new Fragment("controls", "openControlsFragment", this);

        /*
         * STATUS
         */
        List<Status> choices = new ArrayList<Status>();
        if (ticket.isProposal()) {
          choices.addAll(Arrays.asList(TicketModel.Status.proposalWorkflow));
        } else if (ticket.isBug()) {
          choices.addAll(Arrays.asList(TicketModel.Status.bugWorkflow));
        } else {
          choices.addAll(Arrays.asList(TicketModel.Status.requestWorkflow));
        }
        choices.remove(ticket.status);

        ListDataProvider<Status> workflowDp = new ListDataProvider<Status>(choices);
        DataView<Status> statusView = new DataView<Status>("newStatus", workflowDp) {
          private static final long serialVersionUID = 1L;

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

              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));
View Full Code Here

  protected void addUserAttributions(MarkupContainer container, Change entry, int avatarSize) {
    UserModel commenter = app().users().getUserModel(entry.author);
    if (commenter == null) {
      // unknown user
      container.add(new GravatarImage("changeAvatar", entry.author,
          entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
      container.add(new Label("changeAuthor", entry.author.toLowerCase()));
    } else {
      // known user
      container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),
          commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
              avatarSize, true).setVisible(avatarSize > 0));
      container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
          UserPage.class, WicketUtils.newUsernameParameter(commenter.username)));
    }
View Full Code Here

TOP

Related Classes of com.gitblit.wicket.panels.GravatarImage

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.