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

Commit

Permalink
feat(TM details): Add editor url to TM results (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Sep 30, 2016
1 parent e1951ce commit 9f030e5
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 991 deletions.
30 changes: 0 additions & 30 deletions zanata-war/eclipse/launch/webtrans-dummy.launch

This file was deleted.

Expand Up @@ -68,6 +68,7 @@
import org.zanata.search.LevenshteinUtil;
import org.zanata.service.TranslationMemoryService;
import org.zanata.util.SysProperties;
import org.zanata.util.UrlUtil;
import org.zanata.webtrans.shared.model.TransMemoryDetails;
import org.zanata.webtrans.shared.model.TransMemoryQuery;
import org.zanata.webtrans.shared.model.TransMemoryResultItem;
Expand Down Expand Up @@ -131,6 +132,9 @@ public class TranslationMemoryServiceImpl implements TranslationMemoryService {
@Inject @FullText
private FullTextEntityManager entityManager;

@Inject
private UrlUtil urlUtil;

// sort desc by lastChanged of HTextFlowTarget
private final Sort lastChangedSort = new Sort(
SortField.FIELD_SCORE,
Expand All @@ -153,9 +157,10 @@ public class TranslationMemoryServiceImpl implements TranslationMemoryService {
getTransMemoryDetail(HLocale hLocale, HTextFlow tf) {
HTextFlowTarget tft = tf.getTargets().get(hLocale.getId());

String iterationName = tf.getDocument().getProjectIteration().getSlug();
String projectName =
tf.getDocument().getProjectIteration().getProject().getName();
HDocument document = tf.getDocument();
HProjectIteration version = document.getProjectIteration();
HProject project = version.getProject();

String msgContext =
(tf.getPotEntryData() == null) ? null : tf.getPotEntryData()
.getContext();
Expand All @@ -164,10 +169,14 @@ public class TranslationMemoryServiceImpl implements TranslationMemoryService {
&& tft.getLastModifiedBy().hasAccount()) {
username = tft.getLastModifiedBy().getAccount().getUsername();
}
String url = urlUtil.editorTransUnitUrl(project.getSlug(),
version.getSlug(), hLocale.getLocaleId(),
document.getSourceLocaleId(), document.getDocId(), tf.getId());

return new TransMemoryDetails(HSimpleComment.toString(tf.getComment()),
HSimpleComment.toString(tft.getComment()), projectName,
iterationName, tf.getDocument().getDocId(), tf.getResId(),
msgContext, tft.getState(), username, tft.getLastChanged());
HSimpleComment.toString(tft.getComment()), project.getName(),
version.getSlug(), tf.getDocument().getDocId(), tf.getResId(),
msgContext, tft.getState(), username, tft.getLastChanged(), url);
}

/**
Expand Down
Expand Up @@ -87,6 +87,7 @@ protected void selectDoc(int selected) {
String iteration = "";
String doc = "";
String lastModifiedBy = "";
String url = "";
Date lastModifiedDate = null;

if (selected >= 0) {
Expand All @@ -98,6 +99,7 @@ protected void selectDoc(int selected) {
doc = item.getDocId();
lastModifiedBy = item.getLastModifiedBy();
lastModifiedDate = item.getLastModifiedDate();
url = item.getUrl();
display.setState(item.getState());
}

Expand All @@ -106,7 +108,7 @@ protected void selectDoc(int selected) {
display.setProjectName(project);
display.setVersionName(iteration);
display.setDocumentName(doc);

display.setUrl(url);
display.setLastModified(lastModifiedBy, lastModifiedDate);
}

Expand Down
Expand Up @@ -34,6 +34,8 @@ public interface TransMemoryDetailsDisplay extends WidgetDisplay {

void setLastModified(String lastModifiedBy, Date lastModifiedDate);

void setUrl(String url);

void clearSourceAndTarget();

void setSource(List<String> sourceContents);
Expand Down
Expand Up @@ -18,6 +18,7 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.InlineHTML;
Expand Down Expand Up @@ -48,6 +49,9 @@ interface TMIUiBinder extends UiBinder<HTMLPanel, TransMemoryDetailsView> {
@UiField(provided = true)
DialogBoxCloseButton closeButton;

@UiField
Anchor urlLink;

@UiField
ListBox documentListBox;
@UiField
Expand Down Expand Up @@ -117,6 +121,16 @@ public void setLastModified(String lastModifiedBy, Date lastModifiedDate) {
}
}

@Override
public void setUrl(String url) {
urlLink.setHref(url);
if (Strings.isNullOrEmpty(url)) {
urlLink.addStyleName("is-hidden");
} else {
urlLink.removeStyleName("is-hidden");
}
}

@Override
public void clearSourceAndTarget() {
sourceTextContainer.clear();
Expand Down
Expand Up @@ -47,7 +47,12 @@
</div>
</div>

<g:InlineLabel ui:field='lastModified' styleName="txt--understated" />
<g:Anchor ui:field='urlLink' target="_blank" styleName="l--push-all-quarter">
Link to translation
</g:Anchor>

<g:InlineLabel ui:field='lastModified'
styleName="l--float-right txt--understated" />
</div>
</g:HTMLPanel>
</ui:UiBinder>
Expand Up @@ -19,6 +19,7 @@ public class TransMemoryDetails implements IsSerializable {
private ContentState state;
private String lastModifiedBy;
private Date lastModifiedDate;
private String url;

@SuppressWarnings("unused")
private TransMemoryDetails() {
Expand All @@ -27,7 +28,7 @@ private TransMemoryDetails() {
public TransMemoryDetails(String sourceComment, String targetComment,
String projectName, String iterationName, String docId,
String resId, String msgContext, ContentState state,
String lastModifiedBy, Date lastModifiedDate) {
String lastModifiedBy, Date lastModifiedDate, String url) {
this.sourceComment = sourceComment;
this.targetComment = targetComment;
this.projectName = projectName;
Expand All @@ -38,6 +39,7 @@ public TransMemoryDetails(String sourceComment, String targetComment,
this.state = state;
this.lastModifiedBy = lastModifiedBy;
this.lastModifiedDate = lastModifiedDate;
this.url = url;
}

public String getSourceComment() {
Expand Down Expand Up @@ -80,6 +82,10 @@ public Date getLastModifiedDate() {
return lastModifiedDate;
}

public String getUrl() {
return url;
}

@Override
public String toString() {
// @formatter:off
Expand All @@ -94,6 +100,7 @@ public String toString() {
add("state", state).
add("lastModifiedBy", lastModifiedBy).
add("lastModifiedDate", lastModifiedDate).
add("url", url).
toString();
// @formatter:on
}
Expand Down
59 changes: 0 additions & 59 deletions zanata-war/src/main/webapp/WEB-INF/web.xml

This file was deleted.

Expand Up @@ -71,6 +71,7 @@
import org.zanata.transaction.TransactionUtil;
import org.zanata.ui.model.statistic.WordStatistic;
import org.zanata.util.IServiceLocator;
import org.zanata.util.UrlUtil;
import org.zanata.util.Zanata;
import org.zanata.webtrans.shared.model.DocumentStatus;
import org.zanata.webtrans.shared.model.ValidationId;
Expand Down Expand Up @@ -112,7 +113,8 @@
VersionStateCacheImpl.class,
TranslationStateCacheImpl.class,
ValidationServiceImpl.class,
TransactionUtil.class
TransactionUtil.class,
UrlUtil.class
})
public class CopyTransServiceImplParameterizedTest {

Expand All @@ -136,6 +138,9 @@ public class CopyTransServiceImplParameterizedTest {
@Produces @Mock @FullText
FullTextEntityManager fullTextEntityManager;

@Produces @Mock
private UrlUtil urlUtil;

@Produces @Mock
private CacheLoader<DocumentLocaleKey, WordStatistic> documentStatisticLoader;

Expand Down
Expand Up @@ -54,6 +54,7 @@
import org.zanata.test.CdiUnitRunner;
import org.zanata.ui.model.statistic.WordStatistic;
import org.zanata.util.IServiceLocator;
import org.zanata.util.UrlUtil;
import org.zanata.util.Zanata;
import org.zanata.webtrans.shared.model.DocumentStatus;
import org.zanata.webtrans.shared.model.ValidationId;
Expand Down Expand Up @@ -92,6 +93,9 @@ public class CopyTransServiceImplTest extends ZanataDbunitJpaTest {
@Inject DocumentDAO documentDAO;
@Inject CopyTransServiceImpl copyTransService;

@Produces @Mock
private UrlUtil urlUtil;

@Produces @Mock IServiceLocator serviceLocator;
@Produces @Mock @FullText FullTextEntityManager fullTextEntityManager;

Expand Down
Expand Up @@ -169,7 +169,7 @@ private static TransMemoryResultItem importedTmResult(Long sourceId,

private static TransMemoryDetails tmDetail() {
return new TransMemoryDetails("", "", "project a", "master",
"pot/msg.pot", "resId", null, null, null, null);
"pot/msg.pot", "resId", null, null, null, null, null);
}

private TransMemoryQuery
Expand Down
Expand Up @@ -16,6 +16,7 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.zanata.common.ContentType;
import org.zanata.common.LocaleId;
import org.zanata.dao.LocaleDAO;
Expand All @@ -35,6 +36,7 @@
import org.zanata.test.ParamTestCdiExtension;
import org.zanata.test.rule.DataSetOperation;
import org.zanata.test.rule.JpaRule;
import org.zanata.util.UrlUtil;
import org.zanata.util.Zanata;

import javax.enterprise.inject.Produces;
Expand Down Expand Up @@ -104,6 +106,9 @@ public static class TranslationFinderParameterizedTest {
@Inject
TranslationMemoryServiceImpl translationMemoryService;

@Produces @Mock
private UrlUtil urlUtil;

@Parameterized.Parameter(0)
Execution execution;

Expand Down Expand Up @@ -308,6 +313,9 @@ FullTextEntityManager getFullTextEntityManager() {
return Search.getFullTextEntityManager(jpaRule.getEntityManager());
}

@Produces @Mock
private UrlUtil urlUtil;

@Produces @Zanata
EntityManagerFactory getEntityManagerFactory() {
return jpaRule.getEntityManagerFactory();
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.zanata.common.LocaleId;
import org.zanata.dao.LocaleDAO;
import org.zanata.dao.TextFlowDAO;
Expand All @@ -38,6 +39,7 @@
import org.zanata.test.ParamTestCdiExtension;
import org.zanata.test.rule.DataSetOperation;
import org.zanata.test.rule.JpaRule;
import org.zanata.util.UrlUtil;
import org.zanata.util.Zanata;
import org.zanata.webtrans.shared.model.TransMemoryDetails;
import org.zanata.webtrans.shared.model.TransMemoryQuery;
Expand Down Expand Up @@ -84,6 +86,9 @@ public static class TranslationMemoryServiceNonParameterizedTest {
@Inject
LocaleDAO localeDAO;

@Produces @Mock
private UrlUtil urlUtil;

@Produces @Zanata
EntityManagerFactory getEntityManagerFactory() {
return jpaRule.getEntityManagerFactory();
Expand Down Expand Up @@ -266,6 +271,9 @@ public static class TranslationMemoryServiceImplParameterizedTest {
@Inject
LocaleDAO localeDAO;

@Produces @Mock
private UrlUtil urlUtil;

@Produces @Zanata
EntityManagerFactory getEntityManagerFactory() {
return jpaRule.getEntityManagerFactory();
Expand Down

0 comments on commit 9f030e5

Please sign in to comment.