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

Commit

Permalink
update undo unsuccessful message and TranslationServiceImpl to work o…
Browse files Browse the repository at this point in the history
…n null history
  • Loading branch information
Patrick Huang committed Jul 4, 2012
1 parent 0f276b0 commit 489e2c8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions functional-test/pom.xml
Expand Up @@ -266,6 +266,9 @@
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>

</excludes>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.zanata.webtrans.shared.model.TransUnitId;
import org.zanata.webtrans.shared.model.TransUnitUpdateInfo;
import org.zanata.webtrans.shared.model.TransUnitUpdateRequest;
import com.google.common.collect.Lists;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -578,8 +579,14 @@ public List<TranslationResult> revertTranslations(LocaleId localeId, List<TransU
}
else
{
log.warn("got null previous target for tu with id {}, version {}. Cannot revert with no previous state.", hTextFlow.getId(), info.getPreviousVersionNum());
results.add(buildFailResult(hTextFlowTarget));
log.info("got null previous target for tu with id {}, version {}. Assuming previous state is untranslated", hTextFlow.getId(), info.getPreviousVersionNum());
List<String> emptyContents = Lists.newArrayList();
for (int i = 0; i < hTextFlowTarget.getContents().size(); i++)
{
emptyContents.add("");
}
TransUnitUpdateRequest request = new TransUnitUpdateRequest(tuId, emptyContents, ContentState.New, versionNum);
updateRequests.add(request);
}
}
else
Expand Down
Expand Up @@ -243,12 +243,18 @@ public interface WebTransMessages extends Messages
@DefaultMessage("Undo successful")
String undoSuccess();

// @formatter:off
@Description("Message for unsuccessful undo")
@DefaultMessage("{0} items can not be undone")
@DefaultMessage("{0} items can not be undone. {1} items are reverted")
@AlternateMessage({
"one", "Item can not be undone",
"=0", "Undo failed" })
String undoFailure(@PluralCount int unsuccessfulCount);
"one|=0", "Item can not be undone",
"other|=0", "Items can not be undone"
})
String undoUnsuccessful(@PluralCount int unsuccessfulCount, @PluralCount int successfulCount);
// @formatter:on

@DefaultMessage("Undo failed")
String undoFailure();

@DefaultMessage("Undo not possible in read-only workspace")
String cannotUndoInReadOnlyMode();
Expand Down
Expand Up @@ -22,14 +22,14 @@
package org.zanata.webtrans.client.ui;

import java.util.Collection;
import javax.annotation.Nullable;

import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.shared.model.TransUnitUpdateInfo;
import org.zanata.webtrans.shared.rpc.RevertTransUnitUpdates;
import org.zanata.webtrans.shared.rpc.UpdateTransUnitResult;
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
Expand Down Expand Up @@ -110,6 +110,7 @@ private void disableLink()
canUndo = false;
}

// we should make this a presenter if the size or logic grows
private class RevertTransUnitUpdateClickHandler implements ClickHandler
{
private final RevertTransUnitUpdates revertAction;
Expand All @@ -134,7 +135,7 @@ public void onClick(ClickEvent event)
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, messages.undoFailure(0)));
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, messages.undoFailure()));
setText(messages.undo());
enableLink();
}
Expand All @@ -151,8 +152,10 @@ public void onSuccess(UpdateTransUnitResult result)
{
//most likely the undo link became stale i.e. entity state has changed on the server
Collection<TransUnitUpdateInfo> unsuccessful = Collections2.filter(result.getUpdateInfoList(), UnsuccessfulUpdatePredicate.INSTANCE);
int number = unsuccessful.size();
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Info, messages.undoFailure(number)));
int unsuccessfulCount = unsuccessful.size();
int successfulCount = result.getUpdateInfoList().size() - unsuccessfulCount;
Log.info("undo not all successful. #" + unsuccessfulCount + " unsucess and #" + successfulCount + " success");
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Info, messages.undoUnsuccessful(unsuccessfulCount, successfulCount)));
setText("");
}
//we ensure the undo can only be click once.
Expand Down

0 comments on commit 489e2c8

Please sign in to comment.