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

Commit

Permalink
Merge pull request #225 from zanata/rhbz1017997
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Oct 11, 2013
2 parents 27b62f3 + 55b17ec commit c09fbb4
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -31,7 +31,7 @@
<gwteventservice.version>1.2.1</gwteventservice.version>
<okapi.version>0.22</okapi.version>

<zanata.api.version>3.1.0</zanata.api.version>
<zanata.api.version>3.1.1-SNAPSHOT</zanata.api.version>
<!-- This should always be the previous version of the used api version above (but only 3.0.1 or later will work) -->
<zanata.api.compat.version>3.0.2</zanata.api.compat.version>
<zanata.client.version>3.0.1</zanata.client.version>
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/java/org/zanata/dao/DocumentDAO.java
Expand Up @@ -415,7 +415,7 @@ public List<HDocument> getAllByProjectIteration(final String projectSlug,
session.createQuery("from HDocument d "
+ "where d.projectIteration.slug = :iterationSlug "
+ "and d.projectIteration.project.slug = :projectSlug "
+ "and d.obsolete = false " + "order by d.name");
+ "and d.obsolete = false " + "order by d.path, d.name");
q.setParameter("iterationSlug", iterationSlug).setParameter(
"projectSlug", projectSlug);
q.setComment("DocumentDAO.getAllByProjectIteration");
Expand Down
Expand Up @@ -345,13 +345,16 @@ public ContainerTranslationStatistics getDocStatistics(Long documentId,

TranslationStatistics wordStatistics =
result.getStats(localeId.getId(), StatUnit.WORD);
wordStatistics.setRemainingHours(getRemainingHours(
wordStatistics.getDraft(), wordStatistics.getUntranslated()));

double remainingHours =
getRemainingHours(wordStatistics.getDraft(),
wordStatistics.getUntranslated());

wordStatistics.setRemainingHours(remainingHours);

TranslationStatistics msgStatistics =
result.getStats(localeId.getId(), StatUnit.MESSAGE);
msgStatistics.setRemainingHours(getRemainingHours(
msgStatistics.getDraft(), msgStatistics.getUntranslated()));
msgStatistics.setRemainingHours(remainingHours);

return result;
}
Expand Down
Expand Up @@ -460,6 +460,7 @@ public void onProjectStatsUpdated(ProjectStatsUpdatedEvent event) {
} else {
currentWordStats.add(wordStats);
}

refreshStatsDisplay();
}

Expand Down
Expand Up @@ -28,6 +28,11 @@
import java.util.List;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletResponse;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import org.zanata.common.LocaleId;
import org.zanata.common.ProjectType;
import org.zanata.rest.dto.stats.ContainerTranslationStatistics;
Expand Down Expand Up @@ -75,6 +80,7 @@
import org.zanata.webtrans.shared.rpc.GetDownloadAllFilesProgressResult;
import org.zanata.webtrans.shared.rpc.RunDocValidationAction;
import org.zanata.webtrans.shared.rpc.RunDocValidationResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
Expand All @@ -83,11 +89,6 @@
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.inject.Inject;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import javax.servlet.http.HttpServletResponse;

public class DocumentListPresenter extends WidgetPresenter<DocumentListDisplay>
implements DocumentListDisplay.Listener, DocumentSelectionHandler,
UserConfigChangeHandler, TransUnitUpdatedEventHandler,
Expand All @@ -101,7 +102,7 @@ public class DocumentListPresenter extends WidgetPresenter<DocumentListDisplay>

private HashMap<DocumentId, DocumentNode> nodes;
private HashMap<DocumentId, Integer> pageRows;
private ArrayList<DocumentNode> sortedNodes;
private ArrayList<DocumentNode> filteredNodes;

private final CachingDispatchAsync dispatcher;

Expand Down Expand Up @@ -132,7 +133,7 @@ public DocumentListPresenter(DocumentListDisplay display,
dispatcher);

nodes = new HashMap<DocumentId, DocumentNode>();
sortedNodes = new ArrayList<DocumentNode>();
filteredNodes = new ArrayList<DocumentNode>();
pageRows = new HashMap<DocumentId, Integer>();

localeId =
Expand Down Expand Up @@ -274,17 +275,17 @@ public void onRevealDisplay() {
// Auto-generated method stub
}

public void setDocuments(List<DocumentInfo> sortedList) {
nodes = new HashMap<DocumentId, DocumentNode>(sortedList.size());
sortedNodes.clear();
public void setDocuments(List<DocumentInfo> sortedDocumentList) {
nodes =
new HashMap<DocumentId, DocumentNode>(sortedDocumentList.size());
filteredNodes.clear();

idsByPath = new HashMap<String, DocumentId>(sortedList.size());
for (DocumentInfo doc : sortedList) {
idsByPath = new HashMap<String, DocumentId>(sortedDocumentList.size());
for (DocumentInfo doc : sortedDocumentList) {
idsByPath.put(doc.getPath() + doc.getName(), doc.getId());
DocumentNode node = new DocumentNode(doc);
node.setVisible(filter.accept(doc));
nodes.put(doc.getId(), node);
sortedNodes.add(node);
filteredNodes.add(node);
}
updatePageCountAndGotoFirstPage();
}
Expand All @@ -294,13 +295,13 @@ public void queryStats() {

ArrayList<GetDocumentStats> queueList =
new ArrayList<GetDocumentStats>();
for (int i = 0; i < sortedNodes.size();) {
for (int i = 0; i < filteredNodes.size();) {
int fromIndex = i;
int toIndex =
i + BATCH_SIZE > sortedNodes.size() ? sortedNodes.size()
: i + BATCH_SIZE;
i + BATCH_SIZE > filteredNodes.size() ? filteredNodes
.size() : i + BATCH_SIZE;
List<DocumentNode> subList =
sortedNodes.subList(fromIndex, toIndex);
filteredNodes.subList(fromIndex, toIndex);
queueList.add(new GetDocumentStats(convertFromNodetoId(subList)));
i = toIndex;
}
Expand All @@ -314,7 +315,7 @@ public void queryStats() {
protected void setStatesForTest(ArrayList<DocumentNode> sortedNodes,
HashMap<DocumentId, DocumentNode> nodes) {
if (!GWT.isClient()) {
this.sortedNodes = sortedNodes;
this.filteredNodes = sortedNodes;
this.nodes = nodes;
}
}
Expand All @@ -333,8 +334,8 @@ public void onSuccess(GetDocumentStatsResult result) {
for (Entry<DocumentId, ContainerTranslationStatistics> entry : result
.getStatsMap().entrySet()) {
DocumentInfo docInfo = getDocumentInfo(entry.getKey());

docInfo.setStats(entry.getValue());

docInfo.setLastTranslated(result.getLastTranslatedMap()
.get(entry.getKey()));

Expand Down Expand Up @@ -365,7 +366,7 @@ private List<DocumentId> convertFromNodetoId(List<DocumentNode> nodes) {

private void updatePageCountAndGotoFirstPage() {
int pageCount =
(int) Math.ceil(sortedNodes.size()
(int) Math.ceil(filteredNodes.size()
* 1.0
/ userOptionsService.getConfigHolder().getState()
.getDocumentListPageSize());
Expand All @@ -379,10 +380,10 @@ private void gotoPage(int page) {
.getDocumentListPageSize();
int fromIndex = (page - 1) * pageSize;
int toIndex =
(fromIndex + pageSize) > sortedNodes.size() ? sortedNodes
(fromIndex + pageSize) > filteredNodes.size() ? filteredNodes
.size() : fromIndex + pageSize;
pageRows =
display.buildContent(sortedNodes.subList(fromIndex, toIndex));
display.buildContent(filteredNodes.subList(fromIndex, toIndex));
display.getPageNavigation().setValue(page, false);
}

Expand All @@ -391,11 +392,10 @@ private void gotoPage(int page) {
* filter patterns will show all documents.
*/
private void runFilter() {
sortedNodes.clear();
filteredNodes.clear();
for (DocumentNode docNode : nodes.values()) {
docNode.setVisible(filter.accept(docNode.getDocInfo()));
if (docNode.isVisible()) {
sortedNodes.add(docNode);
if (filter.accept(docNode.getDocInfo())) {
filteredNodes.add(docNode);
}
}
updatePageCountAndGotoFirstPage();
Expand Down Expand Up @@ -607,10 +607,12 @@ public void cancelFileUpload() {
@Override
public void onFileUploadComplete(SubmitCompleteEvent event) {
display.closeFileUpload();
if (event.getResults().contains(String.valueOf(HttpServletResponse.SC_OK))) {
if (event.getResults().contains(
String.valueOf(HttpServletResponse.SC_OK))) {
if (event.getResults().contains("Warnings")) {
eventBus.fireEvent(new NotificationEvent(Severity.Warning,
"File uploaded with warnings", event.getResults(), true, null));
"File uploaded with warnings", event.getResults(),
true, null));
} else {
eventBus.fireEvent(new NotificationEvent(Severity.Info,
"File uploaded", event.getResults(), true, null));
Expand Down Expand Up @@ -698,9 +700,9 @@ public void onFailure(Throwable caught) {
@Override
public void sortList(String header, boolean asc) {
HeaderComparator comparator = new HeaderComparator(header);
Collections.sort(sortedNodes, comparator);
Collections.sort(filteredNodes, comparator);
if (!asc) {
Collections.reverse(sortedNodes);
Collections.reverse(filteredNodes);
}
gotoPage(1);
}
Expand Down Expand Up @@ -883,8 +885,8 @@ public void pagerValueChanged(Integer value) {
gotoPage(value);
}

public ArrayList<DocumentNode> getSortedNodes() {
return sortedNodes;
public ArrayList<DocumentNode> getFilteredNodes() {
return filteredNodes;
}

public void showLoading(boolean showLoading) {
Expand Down
Expand Up @@ -389,15 +389,15 @@ private Widget getIncompleteWidget(DocumentInfo docInfo,
private Widget getRemainingWidget(DocumentInfo docInfo) {
String text = "0";
if (docInfo.getStats() != null) {
String locale =
userWorkspaceContext.getWorkspaceContext().getWorkspaceId()
.getLocaleId().getId();
text =
messages.statusBarLabelHours(docInfo
.getStats()
.getStats(
userWorkspaceContext.getWorkspaceContext()
.getWorkspaceId().getLocaleId()
.getId(), StatUnit.WORD)
messages.statusBarLabelHours(docInfo.getStats()
.getStats(locale, StatUnit.WORD)
.getRemainingHours());
}

return new InlineLabel(text);
}

Expand Down Expand Up @@ -474,17 +474,27 @@ public void updateStats(int row, ContainerTranslationStatistics stats,
String locale =
userWorkspaceContext.getWorkspaceContext().getWorkspaceId()
.getLocaleId().toString();
TranslationStatistics wordStats =
stats.getStats(locale, StatUnit.WORD);

if (statsByWords) {
translated.setText(String.valueOf(stats.getStats(locale,
StatUnit.WORD).getTranslatedAndApproved()));
untranslated.setText(String.valueOf(stats.getStats(locale,
StatUnit.WORD).getIncomplete()));
translated.setText(String.valueOf(wordStats
.getTranslatedAndApproved()));
untranslated.setText(String.valueOf(wordStats.getIncomplete()));
} else {
translated.setText(String.valueOf(stats.getStats(locale,
StatUnit.MESSAGE).getTranslatedAndApproved()));
untranslated.setText(String.valueOf(stats.getStats(locale,
StatUnit.MESSAGE).getIncomplete()));

TranslationStatistics msgStats =
stats.getStats(locale, StatUnit.MESSAGE);

translated.setText(String.valueOf(msgStats
.getTranslatedAndApproved()));
untranslated.setText(String.valueOf(msgStats.getIncomplete()));
}

HasText remainingHour =
(HasText) this.getWidget(row, REMAINING_COLUMN);
remainingHour.setText(messages.statusBarLabelHours(wordStats
.getRemainingHours()));
}
}

Expand Down
Expand Up @@ -24,7 +24,6 @@

public class DocumentNode {
private DocumentInfo docInfo;
private boolean isVisible = true;

public DocumentNode(DocumentInfo doc) {
this.docInfo = doc;
Expand All @@ -33,12 +32,4 @@ public DocumentNode(DocumentInfo doc) {
public DocumentInfo getDocInfo() {
return docInfo;
}

public boolean isVisible() {
return isVisible;
}

public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
}
Expand Up @@ -169,12 +169,12 @@ public void loadDocsIntoDataProvider() {
// right amount of docs
assertThat(
"the data provider should have the same sized document list returned from the server",
documentListPresenter.getSortedNodes().size(), is(3));
documentListPresenter.getFilteredNodes().size(), is(3));

ArrayList<DocumentInfo> expectedDocs = buildSampleDocumentArray();

ArrayList<DocumentInfo> actualDocInfos = new ArrayList<DocumentInfo>();
for (DocumentNode node : documentListPresenter.getSortedNodes()) {
for (DocumentNode node : documentListPresenter.getFilteredNodes()) {
assertThat(
"the data provider should have only documents that were returned from the server",
node.getDocInfo(), isIn(expectedDocs));
Expand Down Expand Up @@ -389,7 +389,7 @@ public void exactSearchMatchesExactOnly() {
expectedDocs.remove(2); // third doc does not match the filter
expectedDocs.remove(0); // first doc does not match the filter
ArrayList<DocumentInfo> actualDocInfos = new ArrayList<DocumentInfo>();
for (DocumentNode node : documentListPresenter.getSortedNodes()) {
for (DocumentNode node : documentListPresenter.getFilteredNodes()) {
assertThat(
"the data provider should have only documents that exactly match the current filter",
node.getDocInfo(), isIn(expectedDocs));
Expand All @@ -400,7 +400,7 @@ public void exactSearchMatchesExactOnly() {
actualDocInfos, hasItems(expectedDocs.get(0)));
assertThat(
"the data provider list should contain exactly the number of documents matching the filter",
documentListPresenter.getSortedNodes().size(), is(1));
documentListPresenter.getFilteredNodes().size(), is(1));
}

// TODO test case sensitivity option
Expand All @@ -426,7 +426,7 @@ public void commaSeparatedFilter() {
expectedDocs.remove(1); // second doc does not match any of the filter
// strings
ArrayList<DocumentInfo> actualDocInfos = new ArrayList<DocumentInfo>();
for (DocumentNode node : documentListPresenter.getSortedNodes()) {
for (DocumentNode node : documentListPresenter.getFilteredNodes()) {
assertThat(
"the data provider should have only documents that match the current filter",
node.getDocInfo(), isIn(expectedDocs));
Expand All @@ -438,7 +438,7 @@ public void commaSeparatedFilter() {
hasItems(expectedDocs.get(0), expectedDocs.get(1)));
assertThat(
"the data provider list should contain exactly the number of documents matching the filter",
documentListPresenter.getSortedNodes().size(), is(2));
documentListPresenter.getFilteredNodes().size(), is(2));
}

// TODO test case sensitive check updated from history
Expand Down

0 comments on commit c09fbb4

Please sign in to comment.