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

Commit

Permalink
WIP: version settings - translation tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 21, 2014
1 parent e56caf4 commit 29f0e4c
Show file tree
Hide file tree
Showing 5 changed files with 428 additions and 175 deletions.
Expand Up @@ -599,7 +599,7 @@ public void updateValidationOption(String name, String state) {

update();
addMessage(StatusMessage.Severity.INFO, zanataMessages.getMessage(
"jsf.project.validation.updated",
"jsf.validation.updated",
validatationId.getDisplayName(), state));
}

Expand Down
98 changes: 97 additions & 1 deletion zanata-war/src/main/java/org/zanata/action/VersionHome.java
Expand Up @@ -21,6 +21,7 @@
*/
package org.zanata.action;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -51,11 +52,16 @@
import org.zanata.seam.scope.FlashScopeBean;
import org.zanata.service.LocaleService;
import org.zanata.service.SlugEntityService;
import org.zanata.service.ValidationService;
import org.zanata.service.impl.LocaleServiceImpl;
import org.zanata.util.ZanataMessages;
import org.zanata.webtrans.shared.model.ValidationAction;
import org.zanata.webtrans.shared.model.ValidationId;
import org.zanata.webtrans.shared.validation.ValidationFactory;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -90,6 +96,9 @@ public class VersionHome extends SlugHome<HProjectIteration> {
@In
private LocaleService localeServiceImpl;

@In
private ValidationService validationServiceImpl;

@In
private SlugEntityService slugEntityServiceImpl;

Expand All @@ -99,6 +108,9 @@ public class VersionHome extends SlugHome<HProjectIteration> {
@In
private ZanataMessages zanataMessages;

private Map<ValidationId, ValidationAction> availableValidations = Maps
.newHashMap();

@Override
protected HProjectIteration loadInstance() {
Session session = (Session) getEntityManager().getDelegate();
Expand All @@ -108,7 +120,7 @@ protected HProjectIteration loadInstance() {
.using("slug", getSlug())
.using("project", projectDAO.getBySlug(projectSlug)).load();
} else {
//new version
// new version
HProjectIteration iteration = new HProjectIteration();
HProject project = (HProject) projectDAO.getBySlug(projectSlug);
project.addIteration(iteration);
Expand All @@ -123,6 +135,21 @@ protected HProjectIteration loadInstance() {
}
}

@Restrict("#{s:hasPermission(versionHome.instance, 'update')}")
public void updateRequireTranslationReview(String key, boolean checked) {
getInstance().setRequireTranslationReview(checked);
update();
if (checked) {
addMessage(StatusMessage.Severity.INFO,
zanataMessages
.getMessage("jsf.iteration.requireReview.enabled"));
} else {
addMessage(StatusMessage.Severity.INFO,
zanataMessages
.getMessage("jsf.iteration.requireReview.disabled"));
}
}

@Getter
private AbstractAutocomplete<HLocale> localeAutocomplete =
new AbstractAutocomplete<HLocale>() {
Expand Down Expand Up @@ -191,6 +218,29 @@ public void onSelectItemAction() {
}
};

public List<ValidationAction> getValidationList() {
List<ValidationAction> sortedList =
Lists.newArrayList(getValidations().values());
Collections.sort(sortedList,
ValidationFactory.ValidationActionComparator);
return sortedList;
}

private Map<ValidationId, ValidationAction> getValidations() {
if (availableValidations.isEmpty()) {
Collection<ValidationAction> validationList =
validationServiceImpl.getValidationActions(projectSlug,
slug);

for (ValidationAction validationAction : validationList) {
availableValidations.put(validationAction.getId(),
validationAction);
}
}

return availableValidations;
}

public void validateSuppliedId() {
getInstance(); // this will raise an EntityNotFound exception
// when id is invalid and conversation will not
Expand Down Expand Up @@ -328,6 +378,52 @@ public void setSelectedProjectType(String selectedProjectType) {
}
}

public List<ValidationAction.State> getValidationStates() {
return Arrays.asList(ValidationAction.State.values());
}

@Restrict("#{s:hasPermission(versionHome.instance, 'update')}")
public void updateValidationOption(String name, String state) {
ValidationId validatationId = ValidationId.valueOf(name);

for (Map.Entry<ValidationId, ValidationAction> entry : getValidations()
.entrySet()) {
if (entry.getKey().name().equals(name)) {
getValidations().get(validatationId).setState(
ValidationAction.State.valueOf(state));
ensureMutualExclusivity(getValidations().get(validatationId));
break;
}
getInstance().getCustomizedValidations().put(entry.getKey().name(),
entry.getValue().getState().name());
}

update();
addMessage(StatusMessage.Severity.INFO, zanataMessages.getMessage(
"jsf.validation.updated", validatationId.getDisplayName(),
state));
}

/**
* If this action is enabled(Warning or Error), then it's exclusive
* validation will be turn off
*
* @param selectedValidationAction
*/
private void ensureMutualExclusivity(
ValidationAction selectedValidationAction) {
if (selectedValidationAction.getState() != ValidationAction.State.Off) {
for (ValidationAction exclusiveValAction : selectedValidationAction
.getExclusiveValidations()) {
getInstance().getCustomizedValidations().put(
exclusiveValAction.getId().name(),
ValidationAction.State.Off.name());
getValidations().get(exclusiveValAction.getId()).setState(
ValidationAction.State.Off);
}
}
}

/**
* Use FlashScopeBean to store message in page. Multiple ajax requests for
* re-rendering statistics after updating will clear FacesMessages.
Expand Down
29 changes: 17 additions & 12 deletions zanata-war/src/main/resources/messages.properties
Expand Up @@ -124,7 +124,6 @@ jsf.PageTitle=Zanata | Open Translation, for Everyone
jsf.Reviewed=Reviewed
jsf.Settings=Settings
jsf.Time=Time
jsf.Translation=Translation
jsf.UploadedTranslations=Uploaded translations
jsf.UploadedSource=Uploaded source documents
jsf.YourActivity=Your Activity
Expand All @@ -140,6 +139,16 @@ jsf.EditHomePage=Edit Home Page

#------- Shared ---------
jsf.tooltip.MoreActions=More Actions
jsf.label.review=Review
jsf.Translation=Translation
jsf.validation.source=Source
jsf.validation.target=Target
jsf.validation.updated=Updated validation {0} to {1}.
jsf.CopyTrans=Copy Trans
jsf.Copytrans.message=Copy Trans attempts to reuse translations that have been entered in Zanata by matching them with unstranslated strings in your project/version. Consequently, Copy Trans is best used before translation and review work is initiated on a project.
jsf.Copytrans.message2=Each translation has to pass through each of these checks before it will be copied.
jsf.CopyTrans.Action.message=If all previous steps have passed, <span class="txt--success">copy as translated.</span>
jsf.CopyTrans.Action.message2=Unless previously marked as <strong class="txt--unsure">fuzzy</strong>.

#------ [home] > Projects ------
! 'Action' button
Expand Down Expand Up @@ -203,8 +212,6 @@ jsf.ArchiveProject.Message=This will disable this project and remove it from the
jsf.UnarchiveProject.Message=This will set the project's status to active and make it visible in the public projects list.
jsf.project.readonly.Message=Read only prevents translations being entered. Your project will still be viewable by the public but no new translations can be added.
jsf.project.writable.Message=Your project will be viewable by the public and new translations can be added.
jsf.project.validation.source=Source
jsf.project.validation.target=Target
jsf.project.LanguageRemoved=Language '{0}' has been removed from project.
jsf.project.LanguageAdded=Language '{0}' has been added to project.

Expand Down Expand Up @@ -264,7 +271,6 @@ jsf.Permissions=Permissions
jsf.project.MaintainerRemoved=Maintainer '{0}' has been removed from project.
jsf.project.MaintainerAdded=Maintainer '{0}' has been added to project.
jsf.project.status.updated=Updated project status '{0}'.
jsf.project.validation.updated=Updated validation {0} to {1}.
jsf.field.optional=(optional)
jsf.field.repository=Repository

Expand Down Expand Up @@ -312,13 +318,10 @@ jsf.iteration.writable.Message=This version will be viewable by the public and n
jsf.iteration.status.updated=Updated version status '{0}'.
jsf.iteration.LanguageRemoved=Language '{0}' has been removed from version.
jsf.iteration.LanguageAdded=Language '{0}' has been added to version.
jsf.CopyTrans=Copy Trans

jsf.Copytrans.message=Copy Trans attempts to reuse translations that have been entered in Zanata by matching them with unstranslated strings in your project/version. Consequently, Copy Trans is best used before translation and review work is initiated on a project.
jsf.Copytrans.message2=Each translation has to pass through each of these checks before it will be copied.

jsf.CopyTrans.Action.message=If all previous steps have passed, <span class="txt--success">copy as translated.</span>
jsf.CopyTrans.Action.message2=Unless previously marked as <strong class="txt--unsure">fuzzy</strong>.
jsf.iteration.requireReview.enabled=Enabled translation review
jsf.iteration.requireReview.disabled=Disabled translation review
jsf.iteration.copyTrans.start.question=Do you want to run Copy Trans on this version?
jsf.iteration.CopyTrans.message=This is automatically run whenever a new version is created

! used in coloured display tiles
#FIXME this is actually longer, may not be necessary or should be named better
Expand All @@ -337,6 +340,7 @@ jsf.CopyTrans.ClickHereToViewProgress=Please click here to view progress.
jsf.iteration.CopyTrans.AlreadyStarted.flash=Someone else already started a #{messages['jsf.CopyTrans']} for this version.
jsf.iteration.CopyTrans.NoDocuments=There are no documents in this project version.
jsf.iteration.CopyTrans.Started=#{messages['jsf.CopyTrans']} started.
jsf.iteration.CopyTransOpts.tooltip=Set this version's #{messages['jsf.CopyTrans']} settings.
jsf.iteration.tooltip.readonly=This version is currently read only


Expand Down Expand Up @@ -386,8 +390,9 @@ jsf.iteration.CopyTrans.inProgress=#{messages['jsf.CopyTrans']} in progress...
jsf.iteration.CopyTrans.started=Started #{viewAllStatusAction.copyTransStartTime} ago by #{pHandle.triggeredBy}
jsf.iteration.CopyTrans.estimatedTimeRemaining=Estimated Time Remaining: #{viewAllStatusAction.copyTransEstimatedTimeLeft}
jsf.iteration.CopyTrans.processedDocuments=Processed Documents: #{pHandle.documentsProcessed} of #{viewAllStatusAction.projectIteration.documents.size()}

jsf.iteration.requireTranslationReview=Require translation review
jsf.iteration.requireReview.message=If review is required an extra “reviewed” state will be added to translations and will not be considered finalised until a translation has reached this state.
jsf.iteration.requireReview.help=Help: Turning review on or off

jsf.group.FindGroup=Find Group
jsf.NoResultToDisplay=No result to display.
Expand Down
Expand Up @@ -261,7 +261,7 @@
id="#{validationAction.id.name()}-example">
<div class="g__item w--1-2 l--push-top-quarter">
<h4 class="zeta heading--secondary txt--uppercase">
#{messages['jsf.project.validation.source']}
#{messages['jsf.validation.source']}
</h4>
<pre class="l--push-all-0"><code class="txt--mini">
<h:outputText value="#{validationAction.sourceExample}"
Expand All @@ -270,7 +270,7 @@
</div>
<div class="g__item w--1-2 l--push-top-quarter">
<h4 class="zeta heading--secondary txt--uppercase">
#{messages['jsf.project.validation.target']}
#{messages['jsf.validation.target']}
</h4>
<pre class="l--push-all-0"><code class="txt--mini">
<h:outputText value="#{validationAction.targetExample}"
Expand All @@ -286,7 +286,8 @@
<h3 class="heading--secondary">#{messages['jsf.CopyTrans']}</h3>

<p>#{messages['jsf.Copytrans.message']}
<a href="http://zanata.org/help/reuse/copytrans-explained/" title=""
<a href="http://zanata.org/help/reuse/copytrans-explained/"
title="#{messages['jsf.project.CopyTransOpts.tooltip']}"
data-original-title="#{messages['jsf.project.CopyTransOpts.tooltip']}">
<i class="i i--help"></i>
</a>
Expand Down

0 comments on commit 29f0e4c

Please sign in to comment.