Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add revision comment in editor history
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jun 26, 2015
1 parent bd98cc7 commit 23deb7a
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 45 deletions.
12 changes: 7 additions & 5 deletions zanata-model/src/main/java/org/zanata/model/HTextFlowTarget.java
Expand Up @@ -32,8 +32,6 @@
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
Expand Down Expand Up @@ -79,6 +77,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import org.zanata.model.type.TranslationSourceTypeType;

/**
* Represents a flow of translated text that should be processed as a
Expand All @@ -91,7 +90,7 @@
@Entity
@EntityListeners({ HTextFlowTarget.EntityListener.class })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@TypeDef(name = "sourceType", typeClass = TranslationSourceType.class)
@TypeDef(name = "sourceType", typeClass = TranslationSourceTypeType.class)
@Indexed
@Setter
@NoArgsConstructor
Expand Down Expand Up @@ -134,8 +133,6 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents,
@Getter
private Long entityId;

@Getter
@Type(type = "sourceType")
private TranslationSourceType sourceType;

@Getter
Expand All @@ -148,6 +145,11 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents,
@Setter(AccessLevel.PRIVATE)
private Integer oldVersionNum;

@Type(type = "sourceType")
public TranslationSourceType getSourceType() {
return sourceType;
}

public void setRevisionComment(String revisionComment) {
this.revisionComment = revisionComment;
revisionCommentSet = true;
Expand Down
Expand Up @@ -37,7 +37,6 @@
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Immutable;
Expand All @@ -52,6 +51,7 @@
import com.google.common.base.Objects;
import lombok.Getter;
import lombok.Setter;
import org.zanata.model.type.TranslationSourceTypeType;

@Entity
@Immutable
Expand Down Expand Up @@ -80,7 +80,7 @@
name = HTextFlowTargetHistory.QUERY_MATCHING_HISTORY + 6,
query = "select count(*) from HTextFlowTargetHistory t where t.textFlowTarget = :tft and size(t.contents) = :contentCount "
+ "and contents[0] = :content0 and contents[1] = :content1 and contents[2] = :content2 and contents[3] = :content3 and contents[4] = :content4 and contents[5] = :content5") })
@TypeDef(name = "sourceType", typeClass = TranslationSourceType.class)
@TypeDef(name = "sourceType", typeClass = TranslationSourceTypeType.class)
public class HTextFlowTargetHistory extends HTextContainer implements
Serializable, ITextFlowTargetHistory {
static final String QUERY_MATCHING_HISTORY =
Expand Down Expand Up @@ -120,9 +120,7 @@ public static String getQueryNameMatchingHistory(int size) {
@Setter
private Long entityId;

@Getter
@Setter
@Type(type = "sourceType")
private TranslationSourceType sourceType;

@Getter
Expand Down Expand Up @@ -263,6 +261,11 @@ public void setReviewer(HPerson reviewer) {
this.reviewer = reviewer;
}

@Type(type = "sourceType")
public TranslationSourceType getSourceType() {
return sourceType;
}

/**
* Determines whether a Text Flow Target has changed when compared to this
* history object.
Expand All @@ -286,6 +289,8 @@ public boolean hasChanged(HTextFlowTarget current) {
|| !Objects.equal(current.getTextFlow().getId(),
this.textFlowTarget.getId())
|| !Objects.equal(current.getVersionNum(), this.versionNum)
|| !Objects.equal(current.getRevisionComment(), this.revisionComment);
|| !Objects.equal(current.getRevisionComment(), this.revisionComment)
|| !Objects.equal(current.getEntityId(), this.entityId)
|| !Objects.equal(current.getEntityType(), this.entityType);
}
}
Expand Up @@ -25,10 +25,12 @@
import org.zanata.model.HTextFlowTarget;
import org.zanata.model.tm.TransMemoryUnit;

import java.io.Serializable;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
public enum TranslationEntityType {
public enum TranslationEntityType implements Serializable {
TMX(TransMemoryUnit.class),
TFT(HTextFlowTarget.class);
// MT(null);
Expand Down
Expand Up @@ -21,6 +21,7 @@

package org.zanata.model.type;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -31,7 +32,7 @@
/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
public enum TranslationSourceType {
public enum TranslationSourceType implements Serializable {
COPY_TRANS("CT"),
COPY_VERSION("CV"),
MERGE_VERSION("MV"),
Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.StringType;
import org.zanata.common.EntityStatus;


public class TranslationSourceTypeType extends AbstractSingleColumnStandardBasicType<TranslationSourceType>
Expand Down
Expand Up @@ -46,7 +46,7 @@ public TranslationSourceType fromString(String string) {

@Override
public String toString(TranslationSourceType value) {
return value.toString();
return value.getAbbr();
}

@Override
Expand All @@ -56,7 +56,7 @@ public String toString(TranslationSourceType value) {
return null;
}
if (String.class.isAssignableFrom(type)) {
return (X) value.toString();
return (X) String.valueOf(value.getAbbr());
}
throw unknownUnwrap(type);
}
Expand Down
Expand Up @@ -101,7 +101,7 @@ public static final String getTMMergeMessage(TransMemoryUnit tu) {
StringBuilder comment = new StringBuilder();

comment.append(PREFIX_TM_MERGE)
.append(": translation auto-copied from Translation memory '")
.append(": translation copied from translation memory '")
.append(tu.getTranslationMemory().getSlug())
.append("', description '")
.append(tu.getTranslationMemory().getDescription())
Expand Down Expand Up @@ -135,7 +135,7 @@ private static final String generateAutoCopiedMessage(String prefix,
StringBuilder comment = new StringBuilder();

comment.append(prefix)
.append(": translation auto-copied from project '")
.append(": translation copied from project '")
.append(projectName)
.append("', version '")
.append(versionSlug)
Expand Down
Expand Up @@ -275,7 +275,8 @@ && fromDifferentUser(editorClientId)) {
.toString(), updatedTransUnit.getTargets(),
updatedTransUnit.getStatus(),
updatedTransUnit.getLastModifiedBy(),
updatedTransUnit.getLastModifiedTime());
updatedTransUnit.getLastModifiedTime(),
updatedTransUnit.getRevisionComment());
translationHistoryPresenter.displayEntries(latest,
Collections.<TransHistoryItem> emptyList(),
Collections.<ReviewComment> emptyList());
Expand Down
Expand Up @@ -135,7 +135,7 @@ protected void displayEntries(TransHistoryItem latest,
List<String> newTargets = targetContentsPresenter.getNewTargets();
if (!Objects.equal(latest.getContents(), newTargets)) {
all.add(new TransHistoryItem(messages.unsaved(), newTargets,
null, messages.you(), new Date()));
null, messages.you(), new Date(), null));
}
}
all.addAll(otherEntries);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.zanata.webtrans.client.util.ContentStateToStyleUtil;
import org.zanata.webtrans.client.util.DateUtil;
import org.zanata.webtrans.shared.model.TransHistoryItem;
import com.google.common.base.Strings;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
Expand Down Expand Up @@ -65,6 +66,9 @@ public class TransHistoryItemLine extends Composite {
Anchor copyIntoEditor;
@UiField
SpanElement icon;
@UiField
HTMLPanel revisionComment;


public TransHistoryItemLine(TransHistoryItem item,
TranslationHistoryDisplay.Listener listener,
Expand All @@ -85,9 +89,21 @@ public TransHistoryItemLine(TransHistoryItem item,
targetContents =
new InlineHTML(template.targetContent(TextContentsDisplay
.asSyntaxHighlight(item.getContents()).toSafeHtml()));
revision =
if(!Strings.isNullOrEmpty(item.getOptionalTag())) {
revision =
new InlineHTML(template.targetRevision(item.getVersionNum(),
item.getOptionalTag()));
item.getOptionalTag()));
} else {
revision = new InlineHTML("");
}

if(!Strings.isNullOrEmpty(item.getRevisionComment())) {
revisionComment = new HTMLPanel(template.revisionComment(
item.getRevisionComment()));
} else {
revisionComment = new HTMLPanel("");
}

initWidget(ourUiBinder.createAndBindUi(this));

if (item.getStatus() == ContentState.Approved
Expand Down Expand Up @@ -132,5 +148,8 @@ SafeHtml heading(SafeHtml person, String contentStateStyle,

@Template("<span class='txt--neutral'>{0}</span>")
SafeHtml anonymousUser(String anonymous);

@Template("<span class='txt--meta'>{0}</span>")
SafeHtml revisionComment(String comment);
}
}
Expand Up @@ -45,6 +45,7 @@
<g:Anchor ui:field="copyIntoEditor" text="Copy to Editor" />
</li>
</ul>
<g:HTMLPanel ui:field="revisionComment"/>
</div>
</div>
</g:HTMLPanel>
Expand Down
Expand Up @@ -101,7 +101,8 @@ public GetTranslationHistoryResult execute(
GwtRpcUtil.getTargetContentsWithPadding(hTextFlow,
hTextFlowTarget, nPlurals),
hTextFlowTarget.getState(), lastModifiedBy,
hTextFlowTarget.getLastChanged());
hTextFlowTarget.getLastChanged(),
hTextFlowTarget.getRevisionComment());
// history translation
history = hTextFlowTarget.getHistory();
}
Expand Down Expand Up @@ -162,7 +163,8 @@ public TransHistoryItem apply(HTextFlowTargetHistory targetHistory) {
.toString(), targetHistory.getContents(),
targetHistory.getState(),
nameOrEmptyString(targetHistory.getLastModifiedBy()),
targetHistory.getLastChanged());
targetHistory.getLastChanged(),
targetHistory.getRevisionComment());
}
}
}
Expand Up @@ -82,16 +82,16 @@ public TransUnit transform(HTextFlow hTextFlow, HTextFlowTarget target,
.setPlural(hTextFlow.isPlural())
.setSources(sourceContents)
.setSourceComment(
commentToString(hTextFlow.getComment()))
commentToString(hTextFlow.getComment()))
.setTargets(targetContents)
.setTargetComment(
target == null ? null : commentToString(target
.getComment()))
target == null ? null : commentToString(target
.getComment()))
.setMsgContext(msgContext)
.setRowIndex(hTextFlow.getPos())
.setVerNum(
target == null ? NULL_TARGET_VERSION_NUM
: target.getVersionNum())
target == null ? NULL_TARGET_VERSION_NUM
: target.getVersionNum())
.setCommentsCount(getCommentCount(target));

if (target != null) {
Expand All @@ -100,6 +100,7 @@ public TransUnit transform(HTextFlow hTextFlow, HTextFlowTarget target,
builder.setLastModifiedBy(target.getLastModifiedBy().getName());
}
builder.setLastModifiedTime(target.getLastChanged());
builder.setRevisionComment(target.getRevisionComment());
}
return builder.build();
}
Expand Down
Expand Up @@ -22,20 +22,23 @@ public class TransHistoryItem extends ComparableByDate implements
private String modifiedBy;
private Date modifiedDate;
private String optionalTag = "";
private String revisionComment;

@SuppressWarnings("unused")
private TransHistoryItem() {
}

public TransHistoryItem(String versionNum, List<String> contents,
ContentState status, String modifiedBy, Date modifiedDate) {
ContentState status, String modifiedBy, Date modifiedDate,
String revisionComment) {
this.versionNum = versionNum;
// targetHistory.getContents will return Hibernate persistentList which
// RPC can't handle
this.contents = Lists.newArrayList(contents);
this.status = status;
this.modifiedBy = modifiedBy;
this.modifiedDate = modifiedDate;
this.revisionComment = revisionComment;
}

public String getVersionNum() {
Expand All @@ -58,6 +61,10 @@ public Date getModifiedDate() {
return modifiedDate;
}

public String getRevisionComment() {
return revisionComment;
}

@Override
protected Date getDate() {
return modifiedDate;
Expand All @@ -72,6 +79,7 @@ public String toString() {
add("status", status).
add("modifiedBy", modifiedBy).
add("modifiedDate", modifiedDate).
add("revisionComment", revisionComment).
toString();
// @formatter:on
}
Expand Down

0 comments on commit 23deb7a

Please sign in to comment.