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 #423 from zanata/Loading-on-sort
Browse files Browse the repository at this point in the history
Loading on sort
  • Loading branch information
definite committed Apr 28, 2014
2 parents 0323f24 + 527212a commit ad46a52
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 165 deletions.
2 changes: 1 addition & 1 deletion zanata-war/pom.xml
Expand Up @@ -42,7 +42,7 @@
Waiting for 2.9.0-01. -->
<groovy.eclipse.compiler.version>2.7.0-01</groovy.eclipse.compiler.version>

<zanata.web.assets.version>4</zanata.web.assets.version>
<zanata.web.assets.version>5</zanata.web.assets.version>
</properties>

<build>
Expand Down
42 changes: 15 additions & 27 deletions zanata-war/src/main/java/org/zanata/action/ProjectHomeAction.java
Expand Up @@ -59,6 +59,7 @@
import org.zanata.ui.FilterUtil;
import org.zanata.ui.model.statistic.WordStatistic;
import org.zanata.util.ComparatorUtil;
import org.zanata.util.DateUtil;
import org.zanata.util.StatisticsUtil;
import org.zanata.util.UrlUtil;
import org.zanata.util.ZanataMessages;
Expand Down Expand Up @@ -180,7 +181,6 @@ public WordStatistic getStatisticForVersion(String versionSlug) {
*/
public void sortVersionList() {
Collections.sort(projectVersions, versionComparator);
versionFilter.resetQueryAndPage();
}

private class VersionComparator implements Comparator<HProjectIteration> {
Expand All @@ -191,29 +191,25 @@ public VersionComparator(SortingType sortingType) {
}

@Override
public int compare(HProjectIteration compareFrom,
HProjectIteration compareTo) {
final HProjectIteration item1, item2;
public int compare(HProjectIteration o1, HProjectIteration o2) {
SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();

if (sortingType.isDescending()) {
item1 = compareFrom;
item2 = compareTo;
} else {
item1 = compareTo;
item2 = compareFrom;
if (!selectedSortOption.isAscending()) {
HProjectIteration temp = o1;
o1 = o2;
o2 = temp;
}

SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();
// Need to get statistic for comparison
if (!selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)
&& !selectedSortOption
.equals(SortingType.SortOption.LAST_ACTIVITY)) {

WordStatistic wordStatistic1 =
getStatisticForVersion(item1.getSlug());
getStatisticForVersion(o1.getSlug());
WordStatistic wordStatistic2 =
getStatisticForVersion(item2.getSlug());
getStatisticForVersion(o2.getSlug());

if (selectedSortOption
.equals(SortingType.SortOption.PERCENTAGE)) {
Expand All @@ -234,22 +230,14 @@ public int compare(HProjectIteration compareFrom,
}
} else if (selectedSortOption
.equals(SortingType.SortOption.ALPHABETICAL)) {
return item1.getSlug().toLowerCase()
.compareTo(item2.getSlug().toLowerCase());
return o1.getSlug()
.compareToIgnoreCase(o2.getSlug());
} else if (selectedSortOption
.equals(SortingType.SortOption.LAST_ACTIVITY)) {

Date date1 = getVersionLastActivityDate(item1.getId());
Date date2 = getVersionLastActivityDate(item2.getId());

if (date1 == date2) {
return 0;
} else if (date1 == null) {
return -1;
} else if (date2 == null) {
return 1;
}
return date1.compareTo(date2);
Date date1 = getVersionLastActivityDate(o1.getId());
Date date2 = getVersionLastActivityDate(o2.getId());
return DateUtil.compareDate(date1, date2);
}
return 0;
}
Expand Down
24 changes: 14 additions & 10 deletions zanata-war/src/main/java/org/zanata/action/SortingType.java
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import lombok.Getter;
import lombok.Setter;

import com.google.common.collect.Lists;

Expand All @@ -12,9 +13,6 @@
*/
public class SortingType implements Serializable {

@Getter
private boolean descending = true;

@Getter
private SortOption selectedSortOption = SortOption.ALPHABETICAL;

Expand All @@ -27,23 +25,29 @@ public SortingType(List<SortOption> sortOptions) {

public void setSelectedSortOption(SortOption selectedSortOption) {
if (this.selectedSortOption.equals(selectedSortOption)) {
descending = !descending;
selectedSortOption.setAscending(!selectedSortOption.isAscending());
}
this.selectedSortOption = selectedSortOption;
}

public enum SortOption {
PERCENTAGE("Percent translated"), HOURS("Hours remaining"), WORDS(
"Words remaining"), ALPHABETICAL("Alphabetical"),
LAST_ACTIVITY("Last activity"), LAST_SOURCE_UPDATE(
"Last source updated"), LAST_TRANSLATED("Last translated"),
LAST_UPDATED_BY_YOU("Last updated by you");
PERCENTAGE("Percent translated", false),
HOURS("Hours remaining", false), WORDS("Words remaining", false),
ALPHABETICAL("Alphabetical", true), LAST_ACTIVITY("Last activity",
false), LAST_SOURCE_UPDATE("Last source updated", false),
LAST_TRANSLATED("Last translated", false), LAST_UPDATED_BY_YOU(
"Last updated by you", false);

@Getter
String display;

SortOption(String display) {
@Getter
@Setter
boolean ascending; // default sort

SortOption(String display, boolean ascending) {
this.display = display;
this.ascending = ascending;
}
}
}
Expand Up @@ -197,39 +197,32 @@ public LanguageComparator(SortingType sortingType) {
}

@Override
public int compare(HLocale compareFrom, HLocale compareTo) {
final HLocale item1, item2;

if (sortingType.isDescending()) {
item1 = compareFrom;
item2 = compareTo;
} else {
item1 = compareTo;
item2 = compareFrom;
}

public int compare(HLocale o1, HLocale o2) {
SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();

if (!selectedSortOption.isAscending()) {
HLocale temp = o1;
o1 = o2;
o2 = temp;
}

// Need to get statistic for comparison
if (!selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)) {
WordStatistic wordStatistic1;
WordStatistic wordStatistic2;

if (selectedVersionId == null) {
wordStatistic1 =
getStatisticsForLocale(item1.getLocaleId());
wordStatistic2 =
getStatisticsForLocale(item2.getLocaleId());
wordStatistic1 = getStatisticsForLocale(o1.getLocaleId());
wordStatistic2 = getStatisticsForLocale(o2.getLocaleId());
} else {
wordStatistic1 =
statisticMap.get(new VersionLocaleKey(
selectedVersionId, item1.getLocaleId()));
selectedVersionId, o1.getLocaleId()));
wordStatistic2 =
statisticMap.get(new VersionLocaleKey(
selectedVersionId, item2.getLocaleId()));
selectedVersionId, o2.getLocaleId()));
}

switch (selectedSortOption) {
case PERCENTAGE:
return Double.compare(
Expand All @@ -243,8 +236,8 @@ public int compare(HLocale compareFrom, HLocale compareTo) {
wordStatistic2.getUntranslated());
}
} else {
return item1.retrieveDisplayName().compareTo(
item2.retrieveDisplayName());
return o1.retrieveDisplayName().compareTo(
o2.retrieveDisplayName());
}
return 0;
}
Expand All @@ -261,34 +254,30 @@ public VersionComparator(SortingType sortingType) {
}

@Override
public int compare(HProjectIteration compareFrom,
HProjectIteration compareTo) {
final HProjectIteration item1, item2;
public int compare(HProjectIteration o1, HProjectIteration o2) {
SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();

if (sortingType.isDescending()) {
item1 = compareFrom;
item2 = compareTo;
} else {
item1 = compareTo;
item2 = compareFrom;
if (!selectedSortOption.isAscending()) {
HProjectIteration temp = o1;
o1 = o2;
o2 = temp;
}

SortingType.SortOption selectedSortOption =
sortingType.getSelectedSortOption();
// Need to get statistic for comparison
if (!selectedSortOption.equals(SortingType.SortOption.ALPHABETICAL)) {
WordStatistic wordStatistic1;
WordStatistic wordStatistic2;
if (selectedLocaleId != null) {
wordStatistic1 =
statisticMap.get(new VersionLocaleKey(
item1.getId(), selectedLocaleId));
statisticMap.get(new VersionLocaleKey(o1.getId(),
selectedLocaleId));
wordStatistic2 =
statisticMap.get(new VersionLocaleKey(
item2.getId(), selectedLocaleId));
statisticMap.get(new VersionLocaleKey(o2.getId(),
selectedLocaleId));
} else {
wordStatistic1 = getStatisticForProject(item1.getId());
wordStatistic2 = getStatisticForProject(item2.getId());
wordStatistic1 = getStatisticForProject(o1.getId());
wordStatistic2 = getStatisticForProject(o2.getId());
}

switch (selectedSortOption) {
Expand All @@ -304,8 +293,8 @@ public int compare(HProjectIteration compareFrom,
wordStatistic2.getUntranslated());
}
} else {
return item1.getProject().getName().toLowerCase()
.compareTo(item2.getProject().getName().toLowerCase());
return o1.getProject().getName().toLowerCase()
.compareTo(o2.getProject().getName().toLowerCase());
}
return 0;
}
Expand All @@ -322,7 +311,6 @@ public boolean isUserProjectMaintainer() {
public void sortLanguageList() {
languageComparator.setSelectedVersionId(null);
Collections.sort(activeLocales, languageComparator);
languageTabLanguageFilter.resetQueryAndPage();
}

/**
Expand All @@ -331,7 +319,6 @@ public void sortLanguageList() {
public void sortLanguageList(Long versionId) {
languageComparator.setSelectedVersionId(versionId);
Collections.sort(activeLocales, languageComparator);
projectTabLanguageFilter.resetQueryAndPage();
}

/**
Expand All @@ -342,7 +329,6 @@ public void sortLanguageList(Long versionId) {
public void sortProjectList(LocaleId localeId) {
versionComparator.setSelectedLocaleId(localeId);
Collections.sort(projectIterations, versionComparator);
languageTabVersionFilter.resetQueryAndPage();
}

/**
Expand All @@ -351,7 +337,6 @@ public void sortProjectList(LocaleId localeId) {
public void sortProjectList() {
versionComparator.setSelectedLocaleId(null);
Collections.sort(projectIterations, versionComparator);
projectTabVersionFilter.resetQueryAndPage();
}

public List<HLocale> getActiveLocales() {
Expand Down

0 comments on commit ad46a52

Please sign in to comment.