Skip to content

Commit

Permalink
yu55#53 Layout changes of the view/annotate page (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
sawickil committed Jan 26, 2016
1 parent 2280a85 commit c5d68ae
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.yu55.yagga.core.annotate.model;

import java.util.LinkedList;
import java.util.List;

/**
* Main class containing a content of selected file to view.
*/
public class AnnotateResponse {

private List<AnnotateResponseLine> annotationResponseLines;

private String annotations;

private String fileContent;
Expand All @@ -11,6 +19,22 @@ public AnnotateResponse(String annotations, String fileContent) {
this.fileContent = fileContent;
}

public AnnotateResponse(List<AnnotateResponseLine> annotateResponseLines) {
this.annotationResponseLines = annotateResponseLines;
}

public AnnotateResponse() {
this.annotationResponseLines = new LinkedList<>();
}

public void addAnnotationResponseLine(AnnotateResponseLine line) {
annotationResponseLines.add(line);
}

public List<AnnotateResponseLine> getAnnotationResponseLines() {
return annotationResponseLines;
}

public String getAnnotations() {
return annotations;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.yu55.yagga.core.annotate.model;

/**
* This class represents a single line of the code displayed on the view page. Each line consists of a few parts like
* commit id, author, date, line number and line.
*/
public class AnnotateResponseLine {

private String commitId;

private String author;

private String commitDate;

private int lineNumber;

private String line;

public AnnotateResponseLine(String commitId, String author, String commitDate, int lineNumber,
String line) {
this.commitId = commitId;
this.author = author;
this.commitDate = commitDate;
this.lineNumber = lineNumber;
this.line = line;
}

public String getCommitId() {
return commitId;
}

public String getAuthor() {
return author;
}

public String getCommitDate() {
return commitDate;
}

public int getLineNumber() {
return lineNumber;
}

public String getLine() {
return line;
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/yu55/yagga/handler/git/GitRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.yu55.yagga.handler.git;

import static org.yu55.yagga.handler.git.command.annotate.GitAnnotateResponseFactory.factorizeAnnotateResponse;
import static org.yu55.yagga.handler.git.command.annotate.GitAnnotateResponseFactory.factorizeAnnotateResponse2;
import static org.yu55.yagga.handler.git.command.grep.GitGrepResponseLineFactory.factorizeGrepResponseLinesList;

import java.nio.file.Path;
Expand Down Expand Up @@ -44,7 +44,7 @@ public AnnotateResponse annotate(AnnotateParameters annotateParameters) {
CommandOutput commandOutput = commandExecutorFactory.factorizeAnnotate(this, annotateParameters).execute();

// perhaps this should be command-dependent
return factorizeAnnotateResponse(commandOutput);
return factorizeAnnotateResponse2(commandOutput);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,61 @@
package org.yu55.yagga.handler.git.command.annotate;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.yu55.yagga.core.annotate.model.AnnotateResponse;
import org.yu55.yagga.core.annotate.model.AnnotateResponseLine;
import org.yu55.yagga.handler.generic.command.CommandOutput;
import org.yu55.yagga.handler.generic.command.CommandOutputLine;

public class GitAnnotateResponseFactory {

public static AnnotateResponse factorizeAnnotateResponse(CommandOutput output) {
List<CommandOutputLine> outputLines = output.getOutputLines();
private static final String LINE_PATTERN =
"(\\w+)\\s+\\(\\s?(.+)\\s+(\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+[\\+\\-]?\\d{4})\\s+(\\d+)\\)(" +
".*)";

// public static AnnotateResponse factorizeAnnotateResponse(CommandOutput output) {
// List<CommandOutputLine> outputLines = output.getOutputLines();
//
// StringBuilder annotationsStringBuilder = new StringBuilder();
// StringBuilder fileContentStringBuilder = new StringBuilder();
//
// for (CommandOutputLine outputLine : outputLines) {
// String annotatedLine = outputLine.getLine();
// if (output.getExitValue() == 0) {
// generateSuccessfulContent(annotationsStringBuilder, fileContentStringBuilder, annotatedLine);
// } else {
// generateFailureContent(annotationsStringBuilder, annotatedLine);
// }
// }
//
// return new AnnotateResponse(annotationsStringBuilder.toString(), fileContentStringBuilder.toString());
// }

StringBuilder annotationsStringBuilder = new StringBuilder();
StringBuilder fileContentStringBuilder = new StringBuilder();
public static AnnotateResponse factorizeAnnotateResponse2(CommandOutput output) {
List<CommandOutputLine> outputLines = output.getOutputLines();
AnnotateResponse response = new AnnotateResponse();

for (CommandOutputLine outputLine : outputLines) {
String annotatedLine = outputLine.getLine();
if (output.getExitValue() == 0) {
generateSuccessfulContent(annotationsStringBuilder, fileContentStringBuilder, annotatedLine);
Matcher matcher = Pattern.compile(LINE_PATTERN).matcher(annotatedLine);
if (matcher.matches()) {
String author = matcher.group(2).trim();
AnnotateResponseLine annotationResponseLine = new AnnotateResponseLine(
!author.equals("Not Committed Yet") ? matcher.group(1).trim() : "",
author, matcher.group(3).trim(),
Integer.parseInt(matcher.group(4).trim()),
matcher.group(5));
response.addAnnotationResponseLine(annotationResponseLine);
}
} else {
generateFailureContent(annotationsStringBuilder, annotatedLine);
response.addAnnotationResponseLine(new AnnotateResponseLine(null, null, null, 0, annotatedLine));
}
}

return new AnnotateResponse(annotationsStringBuilder.toString(), fileContentStringBuilder.toString());
return response;
}

private static void generateSuccessfulContent(StringBuilder annotationsStringBuilder,
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/yu55/yagga/utils/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.yu55.yagga.utils;

/**
* Custom string utility class.
*/
public class StringUtils {

/**
* Replaces all blank substrings with a single-space string.
*
* @param source the source string to be processed
* @return the source string having all blank substrings replaced with a single space character.
*/
public static String wrapBlankSubstrings(String source) {
return source.replaceAll("\\s+", " ");
}
}
45 changes: 33 additions & 12 deletions src/main/resources/static/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@
<title>[{{params.repository}}] {{params.file}}</title>

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.28/angular.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"
type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js" type="text/javascript"></script>
<script src="yagga/js/preview.js" type="text/javascript"></script>
<link href="yagga/css/yagga.css" rel="stylesheet">

</head>
<body>
<h1 style="font-family: monospace">[{{params.repository}}] {{params.file}}</h1>
<table>
<body style="padding: 0px; margin: 0px">
<div id="viewTitle">
<h1>&nbsp; <span style="color: #cc2925">[{{params.repository}}]</span> {{params.file}}</h1>
</div>
<table cellpadding="0" cellspacing="0" border="0" class="annotate" style="margin-top: 10px">
<thead>
<tr>
<td>
<pre>{{annotate.annotations}}</pre>
<th>Id</th>
<th>Author</th>
<th>Date</th>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<tr ng-repeat="annotation in annotate.annotationResponseLines track by $index">
<td class="noselect annotateInfoLight">
<pre>{{annotation.commitId}}</pre>
</td>
<td class="noselect annotateInfo">
<pre>{{annotation.author}}</pre>
</td>
<td class="noselect annotateInfoLight">
<pre>{{annotation.commitDate}}</pre>
</td>
<td class="noselect lineNumber">
<pre>{{annotation.lineNumber}}</pre>
</td>
<td>
<div>
<prettify target="annotate">
<code class="prettyprint">{{target.fileContent}}</code>
</prettify>
</div>
<td style="padding-left: 2em; width: 100%">
<prettify target="annotation"><code class="prettyprint">{{target.line}}</code></prettify>
</td>
</tr>
</tbody>
</table>

</body>
Expand Down
70 changes: 70 additions & 0 deletions src/main/resources/static/yagga/css/yagga.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
background-color: #333;
margin: 0px;
}

#yaggaTitle h1 {
color: #eee;
margin: 0px;
padding: 0px;
font-family: "Nimbus Sans L", Helvetica, Arial;
font-weight: normal;
}

.searchSection {
Expand All @@ -16,3 +19,70 @@
width: 100%;
margin: 0px;
}

.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE/Edge */
user-select: none;
/* non-prefixed version, currently
not supported by any browser */
}

pre {
margin: 0px;
}

#viewTitle {
padding: 5px;
width: 100%;
background-color: #333;
margin: 0px;
}

#viewTitle h1 {
color: #eee;
margin: 0px;
padding: 0px;
font-family: "Nimbus Sans L", Helvetica, Arial;
font-weight: normal;
font-size: 20px
}

.annotate th {
background-color: #e0e0e0;
color: #555;
text-align: center;
font-weight: normal;
font-family: Arial, Helvetica;
padding: 5px;
font-size: 14px;
}

.annotateInfo {
padding-right: 5px;
padding-left: 5px;
text-align: right;
background-color: #555555;
color: white;
font-size: 12px;
}

.annotateInfoLight {
padding-right: 5px;
padding-left: 5px;
text-align: right;
background-color: #888888;
color: white;
font-size: 12px;
}

.lineNumber {
text-align: right;
padding-left: 10px;
padding-right: 5px;
background-color: white;
color: black;
}
2 changes: 1 addition & 1 deletion src/main/resources/static/yagga/js/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ App.directive('prettify', ['$compile', '$timeout', function ($compile, $timeout)
var update = function () {
$timeout(function () {
var compiled = templateFn(scope).html();
var prettified = prettyPrintOne('<pre>' + compiled + '</pre>');
var prettified = prettyPrintOne('<pre style="margin:0px">' + compiled + '</pre>');
element.html(prettified);
}, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.yu55.yagga.util.mockito.DvcsRepositoryResolverMockBehavior.should;
import static org.yu55.yagga.testutils.mockito.DvcsRepositoryResolverMockBehavior.should;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.yu55.yagga.core.grep.model.GrepResponseAssert.assertThat;
import static org.yu55.yagga.util.mockito.DvcsRepositoryMockBehavior.should;
import static org.yu55.yagga.testutils.mockito.DvcsRepositoryMockBehavior.should;

import org.junit.Test;
import org.yu55.yagga.core.grep.model.GrepRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.yu55.yagga.handler.git.GitRepositoryResolver.GIT_REPOSITORY_DISCRIMINATOR;
import static org.yu55.yagga.util.RepositoryFolderStub.stubGitRepository;
import static org.yu55.yagga.util.RepositoryFolderStub.stubUndefinedRepository;
import static org.yu55.yagga.testutils.RepositoryFolderStub.stubGitRepository;
import static org.yu55.yagga.testutils.RepositoryFolderStub.stubUndefinedRepository;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -21,7 +21,7 @@
import org.yu55.yagga.handler.generic.command.CommandOutput;
import org.yu55.yagga.handler.generic.command.CommandOutputLine;
import org.yu55.yagga.handler.git.command.common.GitCommandExecutorFactory;
import org.yu55.yagga.util.RepositoryFolderStub;
import org.yu55.yagga.testutils.RepositoryFolderStub;

@RunWith(MockitoJUnitRunner.class)
public class GitRepositoryResolverTest {
Expand Down Expand Up @@ -136,8 +136,7 @@ public void shouldCorrectlyCreateGitRepositoryInstance() {
}

private CommandExecutor commandExecutorReturningGitVersionOutput(String line) {
CommandOutput commandOutput = new CommandOutput()
.addOutputLine(new CommandOutputLine(line));
CommandOutput commandOutput = new CommandOutput().addOutputLine(new CommandOutputLine(line));
CommandExecutor commandExecutor = mock(CommandExecutor.class);
when(commandExecutor.execute()).thenReturn(commandOutput);
return commandExecutor;
Expand Down
Loading

0 comments on commit c5d68ae

Please sign in to comment.