The Unified and Autonomous Development Platform
midwork
robin shine99175d181222
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.htmlindex e406e33e1f..027fa3cfbd 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.html@@ -4,21 +4,7 @@<div class="body"><svg class="lane"></svg><ul class="list list-unstyled">- <li wicket:id="commits" class="commit clearfix">- <div class="avatar pull-left">- <span wicket:id="avatar"></span>- </div>- <div class="detail pull-left">- <div wicket:id="message"></div>- <div class="author">- <span wicket:id="name"></span> authored <span wicket:id="age"></span>- </div>- </div>- <div class="info pull-right">- <span wicket:id="hash"></span>- <a wicket:id="codeLink" title="Browse code at this point" class="btn btn-xs btn-default"><span class="fa fa-code"></span></a>- </div>- </li>+ <li wicket:id="commits" class="commit clearfix"></li></ul></div><div wicket:id="foot" class="foot">@@ -26,4 +12,22 @@<div wicket:id="tooMany" class="alert alert-warning">Too many commits to load</div></div></div>+ <wicket:fragment wicket:id="commitFrag">+ <div class="avatar pull-left">+ <span wicket:id="avatar"></span>+ </div>+ <div class="detail pull-left">+ <div wicket:id="message"></div>+ <div class="author">+ <span wicket:id="name"></span> authored <span wicket:id="age"></span>+ </div>+ </div>+ <div class="info pull-right">+ <span wicket:id="hash"></span>+ <a wicket:id="codeLink" title="Browse code at this point" class="btn btn-xs btn-default"><span class="fa fa-code"></span></a>+ </div>+ </wicket:fragment>+ <wicket:fragment wicket:id="dateFrag">+ <div wicket:id="date"></div>+ </wicket:fragment></wicket:extend>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.javaindex b9531b2415..e2317d191e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/RepoCommitsPage.java@@ -19,6 +19,7 @@ import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.link.BookmarkablePageLink;+import org.apache.wicket.markup.html.panel.Fragment;import org.apache.wicket.markup.repeater.RepeatingView;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;@@ -27,6 +28,9 @@ import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.mapper.parameter.PageParameters;import org.apache.wicket.request.resource.CssResourceReference;import org.apache.wicket.request.resource.JavaScriptResourceReference;+import org.joda.time.DateTime;+import org.joda.time.format.DateTimeFormat;+import org.joda.time.format.DateTimeFormatter;import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.ObjectMapper;@@ -58,6 +62,8 @@ public class RepoCommitsPage extends RepositoryPage {private static final String PARAM_STEP = "step";+ private static DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");+private HistoryState state = new HistoryState();private String revisionHash;@@ -101,6 +107,9 @@ public class RepoCommitsPage extends RepositoryPage {sort(lastAndCurrentCommits.current, lastMaxCount);+ lastAndCurrentCommits.last = separateByDate(lastAndCurrentCommits.last);+ lastAndCurrentCommits.current = separateByDate(lastAndCurrentCommits.current);+return lastAndCurrentCommits;}@@ -168,6 +177,14 @@ public class RepoCommitsPage extends RepositoryPage {});}+ private Component replaceItem(AjaxRequestTarget target, int index) {+ Component item = commitsView.get(index);+ Component newItem = newCommitItem(item.getId(), index);+ item.replaceWith(newItem);+ target.add(newItem);+ return newItem;+ }+@Overrideprotected void onInitialize() {super.onInitialize();@@ -184,15 +201,30 @@ public class RepoCommitsPage extends RepositoryPage {state.step++;LastAndCurrentCommits commits = lastAndCurrentCommitsModel.getObject();+ int commitIndex = 0;for (int i=0; i<commits.last.size(); i++) {Commit lastCommit = commits.last.get(i);Commit currentCommit = commits.current.get(i);+ if (lastCommit == null) {+ if (currentCommit == null) {+ if (!commits.last.get(i+1).getHash().equals(commits.current.get(i+1).getHash()))+ replaceItem(target, i);+ } else {++ }+ } else {+ if (currentCommit == null) {+ } else {+ }+ }if (!lastCommit.getHash().equals(currentCommit.getHash())) {Component item = commitsView.get(i);Component newItem = newCommitItem(item.getId(), i);item.replaceWith(newItem);target.add(newItem);}+ if (currentCommit != null)+ commitIndex++;}StringBuilder builder = new StringBuilder();@@ -205,7 +237,8 @@ public class RepoCommitsPage extends RepositoryPage {}target.prependJavaScript(builder);target.add(foot);- target.appendJavaScript(getCommitLaneScript());+ String script = String.format("gitplex.repocommits.renderCommitLane(%s);", getCommitsJson());+ target.appendJavaScript(script);pushState(target);}@@ -238,37 +271,50 @@ public class RepoCommitsPage extends RepositoryPage {private RepeatingView newCommitsView() {RepeatingView commitsView = new RepeatingView("commits");- for (int i=0; i<lastAndCurrentCommitsModel.getObject().current.size(); i++)- commitsView.add(newCommitItem(commitsView.newChildId(), i));+ int commitIndex = 0;+ List<Commit> commits = lastAndCurrentCommitsModel.getObject().current;+ for (int i=0; i<commits.size(); i++) {+ Component item = newCommitItem(commitsView.newChildId(), i);+ if (commits.get(i) != null)+ item.setMarkupId("commitindex-" + commitIndex++);+ commitsView.add(item);+ }return commitsView;}private Component newCommitItem(String itemId, final int index) {- WebMarkupContainer item = new WebMarkupContainer(itemId);- Commit commit = lastAndCurrentCommitsModel.getObject().current.get(index);- item.add(new PersonLink("avatar", Model.of(commit.getAuthor()), AvatarMode.AVATAR));+ List<Commit> current = lastAndCurrentCommitsModel.getObject().current;+ Commit commit = current.get(index);++ Fragment item;+ if (commit != null) {+ item = new Fragment(itemId, "commitFrag", this);+ item.add(new PersonLink("avatar", Model.of(commit.getAuthor()), AvatarMode.AVATAR));- item.add(new CommitMessagePanel("message", repoModel, new LoadableDetachableModel<Commit>() {+ item.add(new CommitMessagePanel("message", repoModel, new LoadableDetachableModel<Commit>() {- @Override- protected Commit load() {- return lastAndCurrentCommitsModel.getObject().current.get(index);- }-- }));+ @Override+ protected Commit load() {+ return lastAndCurrentCommitsModel.getObject().current.get(index);+ }++ }));- item.add(new PersonLink("name", Model.of(commit.getAuthor()), AvatarMode.NAME));- item.add(new Label("age", DateUtils.formatAge(commit.getAuthor().getWhen())));-- item.add(new CommitHashPanel("hash", Model.of(commit.getHash())));-- RepoFileState state = new RepoFileState();- state.blobIdent.revision = commit.getHash();- item.add(new BookmarkablePageLink<Void>("codeLink", RepoFilePage.class,- RepoFilePage.paramsOf(repoModel.getObject(), state)));-- item.setMarkupId("commitindex-" + index);+ item.add(new PersonLink("name", Model.of(commit.getAuthor()), AvatarMode.NAME));+ item.add(new Label("age", DateUtils.formatAge(commit.getAuthor().getWhen())));++ item.add(new CommitHashPanel("hash", Model.of(commit.getHash())));++ RepoFileState state = new RepoFileState();+ state.blobIdent.revision = commit.getHash();+ item.add(new BookmarkablePageLink<Void>("codeLink", RepoFilePage.class,+ RepoFilePage.paramsOf(repoModel.getObject(), state)));+ } else {+ item = new Fragment(itemId, "dateFrag", this);+ DateTime dateTime = new DateTime(current.get(index+1).getCommitter().getWhen());+ item.add(new Label("date", dateFormatter.print(dateTime)));+ }item.setOutputMarkupId(true);return item;@@ -309,29 +355,49 @@ public class RepoCommitsPage extends RepositoryPage {super.onDetach();}- private String getCommitLaneScript() {+ private String getCommitsJson() {List<Commit> commits = lastAndCurrentCommitsModel.getObject().current;Map<String, Integer> hash2index = new HashMap<>();- for (int i=0; i<commits.size(); i++)- hash2index.put(commits.get(i).getHash(), i);+ int commitIndex = 0;+ for (int i=0; i<commits.size(); i++) {+ Commit commit = commits.get(i);+ if (commit != null)+ hash2index.put(commit.getHash(), commitIndex++);+ }List<List<Integer>> commitIndexes = new ArrayList<>();for (Commit commit: commits) {- List<Integer> parentIndexes = new ArrayList<>();- for (String parentHash: commit.getParentHashes()) {- Integer parentIndex = hash2index.get(parentHash);- if (parentIndex != null)- parentIndexes.add(parentIndex);+ if (commit != null) {+ List<Integer> parentIndexes = new ArrayList<>();+ for (String parentHash: commit.getParentHashes()) {+ Integer parentIndex = hash2index.get(parentHash);+ if (parentIndex != null)+ parentIndexes.add(parentIndex);+ }+ commitIndexes.add(parentIndexes);}- commitIndexes.add(parentIndexes);}try {- String json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commitIndexes);- return String.format("gitplex.repocommits.renderCommitLane(%s);", json);+ return GitPlex.getInstance(ObjectMapper.class).writeValueAsString(commitIndexes);} catch (JsonProcessingException e) {throw new RuntimeException(e);}}+ private List<Commit> separateByDate(List<Commit> commits) {+ List<Commit> separated = new ArrayList<>();+ DateTime groupTime = null;+ for (Commit commit: commits) {+ DateTime commitTime = new DateTime(commit.getCommitter().getWhen());+ if (groupTime == null || commitTime.getYear() != groupTime.getYear()+ || commitTime.getDayOfYear() != groupTime.getDayOfYear()) {+ groupTime = commitTime;+ separated.add(null);+ }+ separated.add(commit);+ }+ return separated;+ }+@Overridepublic void renderHead(IHeaderResponse response) {super.renderHead(response);@@ -342,7 +408,8 @@ public class RepoCommitsPage extends RepositoryPage {response.render(CssHeaderItem.forReference(new CssResourceReference(RepoCommitsPage.class, "repo-commits.css")));- response.render(OnDomReadyHeaderItem.forScript(getCommitLaneScript()));+ String script = String.format("gitplex.repocommits.init(%s);", getCommitsJson());+ //response.render(OnDomReadyHeaderItem.forScript(script));}/*diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.cssindex c4c8b1a49b..c78224247c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.css@@ -56,94 +56,94 @@}.commit-lane-dot {- fill: #000080;+ fill: #53a8fd;}.commit-lane-line {stroke-width: 2px;- stroke: #000080;+ stroke: #53a8fd;fill: none;}.commit-lane-dot1 {- fill: #000080;+ fill: #53a8fd;}.commit-lane-line1 {- stroke: #000080;+ stroke: #53a8fd;}.commit-lane-dot2 {- fill: #008000;+ fill: #09c112;}.commit-lane-line2 {- stroke: #008000;+ stroke: #09c112;}.commit-lane-dot3 {- fill: #800000;+ fill: #ff4242;}.commit-lane-line3 {- stroke: #800000;+ stroke: #ff4242;}.commit-lane-dot4 {- fill: #0000ff;+ fill: #0252a2;}.commit-lane-line4 {- stroke: #0000ff;+ stroke: #0252a2;}.commit-lane-dot5 {- fill: #00ff00;+ fill: #056d0b;}.commit-lane-line5 {- stroke: #00ff00;+ stroke: #056d0b;}.commit-lane-dot6 {- fill: #ff0000;+ fill: #b00000;}.commit-lane-line6 {- stroke: #ff0000;+ stroke: #b00000;}.commit-lane-dot7 {- fill: #808000;+ fill: #af29f8;}.commit-lane-line7 {- stroke: #808000;+ stroke: #af29f8;}.commit-lane-dot8 {- fill: #800080;+ fill: #ee6c1e;}.commit-lane-line8 {- stroke: #800080;+ stroke: #ee6c1e;}.commit-lane-dot9 {- fill: #008080;+ fill: #ef56cd;}.commit-lane-line9 {- stroke: #008080;+ stroke: #ef56cd;}.commit-lane-dot10 {- fill: #ffff00;+ fill: #630596;}.commit-lane-line10 {- stroke: #ffff00;+ stroke: #630596;}.commit-lane-dot11 {- fill: #ff00ff;+ fill: #8e4509;}.commit-lane-line11 {- stroke: #ff00ff;+ stroke: #8e4509;}.commit-lane-dot12 {- fill: #00ffff;+ fill: #9b0f7b;}.commit-lane-line12 {- stroke: #00ffff;+ stroke: #9b0f7b;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.jsindex 293ad8d67b..63528f5812 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/commit/repo-commits.js@@ -1,4 +1,12 @@-gitplex.repocommits = {+gitplex.repocommits = {+ init: function(commits) {+ $(window).resize(function(e) {+ e.stopPropagation();+ gitplex.repocommits.drawCommitLane();+ });+ gitplex.repocommits.renderCommitLane(commits);+ },+/** commits is an array of ordered commit object, and the commit object is itself a* list of parent indexes