Skip to content

Commit

Permalink
feat: GWT MT filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jul 12, 2018
1 parent d4d04af commit 1d25edc
Show file tree
Hide file tree
Showing 22 changed files with 241 additions and 73 deletions.
Expand Up @@ -15,7 +15,7 @@ public class FilterViewEvent extends GwtEvent<FilterViewEventHandler> implements
*/
private static final Type<FilterViewEventHandler> TYPE = new Type<>();
public static final FilterViewEvent DEFAULT = new FilterViewEvent(false,
false, false, false, false, false, EditorFilter.ALL, false);
false, false, false, false, false, false, EditorFilter.ALL, false);

/**
* Gets the type associated with this event.
Expand All @@ -27,20 +27,21 @@ public static Type<FilterViewEventHandler> getType() {
}

private boolean filterTranslated, filterFuzzy, filterUntranslated,
filterApproved, filterRejected, filterHasError;
filterApproved, filterRejected, filterHasError, filterMT;
private boolean cancelFilter;
private EditorFilter editorFilter;

public FilterViewEvent(boolean filterTranslated, boolean filterFuzzy,
boolean filterUntranslated, boolean filterApproved,
boolean filterRejected, boolean filterHasError,
EditorFilter editorFilter, boolean cancelFilter) {
boolean filterMT, EditorFilter editorFilter, boolean cancelFilter) {
this.filterTranslated = filterTranslated;
this.filterFuzzy = filterFuzzy;
this.filterUntranslated = filterUntranslated;
this.filterApproved = filterApproved;
this.filterRejected = filterRejected;
this.filterHasError = filterHasError;
this.filterMT = filterMT;
this.editorFilter = editorFilter;
this.cancelFilter = cancelFilter;
}
Expand Down Expand Up @@ -83,6 +84,10 @@ public boolean isFilterHasError() {
return filterHasError;
}

public boolean isFilterMT() {
return filterMT;
}

public EditorFilter getEditorFilter() {
return editorFilter;
}
Expand All @@ -98,6 +103,7 @@ public GetTransUnitActionContext updateContext(
.withFilterApproved(filterApproved)
.withFilterRejected(filterRejected)
.withFilterHasError(filterHasError)
.withFilterMT(filterMT)
.withEditorFilter(editorFilter);
}

Expand All @@ -110,6 +116,7 @@ public String toString() {
.add("filterApproved", filterApproved)
.add("filterRejected", filterRejected)
.add("filterHasError", filterHasError)
.add("filterMT", filterMT)
.add("editorFilter", editorFilter)
.add("cancelFilter", cancelFilter).toString();
}
Expand Down
Expand Up @@ -16,6 +16,7 @@ enum EditorTokens implements TokensConverter {
static final String KEY_MESSAGE_FILTER_APPROVED = "approved";
static final String KEY_MESSAGE_FILTER_REJECTED = "rejected";
static final String KEY_MESSAGE_FILTER_ERROR = "error";
static final String KEY_MESSAGE_FILTER_MT = "mt";
static final String VALUE_MESSAGE_FILTER = "show";
static final String KEY_RES_ID = "resid";
static final String KEY_MSG_CONTEXT = "msgcontext";
Expand Down Expand Up @@ -54,6 +55,9 @@ public void populateHistoryToken(HistoryToken historyToken, Token token) {
if (key.equals(KEY_MESSAGE_FILTER_ERROR)) {
historyToken.setFilterHasError(true);
}
if (key.equals(KEY_MESSAGE_FILTER_MT)) {
historyToken.setFilterMT(true);
}
if (key.equals(KEY_RES_ID)) {
historyToken.setResId(value);
}
Expand Down Expand Up @@ -99,7 +103,9 @@ public void toTokenString(HistoryToken historyToken, List<Token> tokens) {
|| historyToken.isFilterUntranslated() != historyToken
.isFilterApproved()
|| historyToken.isFilterUntranslated() != historyToken
.isFilterRejected()) {
.isFilterRejected()
|| historyToken.isFilterUntranslated() != historyToken
.isFilterMT()) {
// if filter options is set (not showing everything)
if (historyToken.isFilterUntranslated()) {
tokens.add(new Token(KEY_MESSAGE_FILTER_UNTRANSLATED,
Expand All @@ -125,6 +131,10 @@ public void toTokenString(HistoryToken historyToken, List<Token> tokens) {
tokens.add(new Token(KEY_MESSAGE_FILTER_ERROR,
VALUE_MESSAGE_FILTER));
}
if (historyToken.isFilterMT()) {
tokens.add(new Token(KEY_MESSAGE_FILTER_MT,
VALUE_MESSAGE_FILTER));
}
}
setIfExists(tokens, KEY_RES_ID, historyToken.getResId());
setIfExists(tokens, KEY_MSG_CONTEXT, historyToken.getMsgContext());
Expand Down
Expand Up @@ -62,6 +62,7 @@ public class HistoryToken {
private boolean filterApproved;
private boolean filterRejected;
private boolean filterHasError;
private boolean filterMT;

public HistoryToken() {
view = DEFAULT_VIEW;
Expand Down Expand Up @@ -282,10 +283,18 @@ public void setFilterHasError(boolean filterHasError) {
this.filterHasError = filterHasError;
}

public void setFilterMT(boolean filterMT) {
this.filterMT = filterMT;
}

public boolean isFilterHasError() {
return filterHasError;
}

public boolean isFilterMT() {
return filterMT;
}

public void setResId(String resId) {
this.resId = resId;
}
Expand Down Expand Up @@ -345,6 +354,7 @@ public String getTargetComment() {
public void clearEditorFilterAndSearch() {
filterFuzzy = false;
filterHasError = false;
filterMT = false;
filterTranslated = false;
filterUntranslated = false;
filterApproved = false;
Expand Down
Expand Up @@ -126,18 +126,19 @@ private static void populateHistoryTokenForEditorFilter(
public void messageFilterOptionChanged(Boolean translatedChkValue,
Boolean fuzzyChkValue, Boolean untranslatedChkValue,
Boolean approvedChkValue, Boolean rejectedChkValue,
Boolean hasErrorChkValue) {
Boolean hasErrorChkValue, Boolean mtChkValue) {
UserConfigHolder configHolder = userOptionsService.getConfigHolder();
configHolder.setFilterByTranslated(translatedChkValue);
configHolder.setFilterByFuzzy(fuzzyChkValue);
configHolder.setFilterByUntranslated(untranslatedChkValue);
configHolder.setFilterByApproved(approvedChkValue);
configHolder.setFilterByRejected(rejectedChkValue);
configHolder.setFilterByHasError(hasErrorChkValue);
configHolder.setFilterByMT(mtChkValue);

pushFilterHistory(translatedChkValue, fuzzyChkValue,
untranslatedChkValue, approvedChkValue, rejectedChkValue,
hasErrorChkValue, null);
untranslatedChkValue, approvedChkValue, rejectedChkValue,
hasErrorChkValue, mtChkValue, null);
}

@Override
Expand Down Expand Up @@ -166,13 +167,15 @@ public void onUserConfigChanged(UserConfigChangeEvent event) {
configurationState.isFilterByUntranslated(),
configurationState.isFilterByApproved(),
configurationState.isFilterByRejected(),
configurationState.isFilterByHasError());
configurationState.isFilterByHasError(),
configurationState.isFilterByMT());
pushFilterHistory(configurationState.isFilterByTranslated(),
configurationState.isFilterByFuzzy(),
configurationState.isFilterByUntranslated(),
configurationState.isFilterByApproved(),
configurationState.isFilterByRejected(),
configurationState.isFilterByHasError(), null);
configurationState.isFilterByHasError(),
configurationState.isFilterByMT(), null);
}

}
Expand All @@ -181,13 +184,14 @@ public void onUserConfigChanged(UserConfigChangeEvent event) {
public void onFilterView(FilterViewEvent event) {
if (event.isCancelFilter()) {
updateFilterStates(event.isFilterTranslated(),
event.isFilterFuzzy(), event.isFilterUntranslated(),
event.isFilterApproved(), event.isFilterRejected(),
event.isFilterHasError());
event.isFilterFuzzy(), event.isFilterUntranslated(),
event.isFilterApproved(), event.isFilterRejected(),
event.isFilterHasError(), event.isFilterMT());
pushFilterHistory(event.isFilterTranslated(),
event.isFilterFuzzy(), event.isFilterUntranslated(),
event.isFilterApproved(), event.isFilterRejected(),
event.isFilterHasError(), event.getEditorFilter());
event.isFilterFuzzy(), event.isFilterUntranslated(),
event.isFilterApproved(), event.isFilterRejected(),
event.isFilterHasError(), event.isFilterMT(),
event.getEditorFilter());

} else {
// this is fired from HistoryEventHandlerService
Expand All @@ -200,26 +204,28 @@ public void onFilterView(FilterViewEvent event) {
public void updateFilterStates(boolean filterByTranslated,
boolean filterByFuzzy, boolean filterByUntranslated,
boolean filterByApproved, boolean filterByRejected,
boolean filterByHasError) {
boolean filterByHasError, boolean filterByMT) {
display.setTranslatedFilter(filterByTranslated);
display.setNeedReviewFilter(filterByFuzzy);
display.setUntranslatedFilter(filterByUntranslated);
display.setApprovedFilter(filterByApproved);
display.setRejectedFilter(filterByRejected);
display.setHasErrorFilter(filterByHasError);
display.setMTFilter(filterByMT);
}

private void pushFilterHistory(boolean filterByTranslated,
boolean filterByFuzzy, boolean filterByUntranslated,
boolean filterByApproved, boolean filterByRejected,
boolean filterByHasError, EditorFilter editorFilter) {
boolean filterByHasError, boolean filterByMT, EditorFilter editorFilter) {
HistoryToken token = history.getHistoryToken();
token.setFilterTranslated(filterByTranslated);
token.setFilterFuzzy(filterByFuzzy);
token.setFilterUntranslated(filterByUntranslated);
token.setFilterApproved(filterByApproved);
token.setFilterRejected(filterByRejected);
token.setFilterHasError(filterByHasError);
token.setFilterMT(filterByMT);

if (editorFilter != null) {
populateHistoryTokenForEditorFilter(token, editorFilter);
Expand Down
Expand Up @@ -208,12 +208,12 @@ public void discardChangesAndFilter() {
@Override
public void cancelFilter() {
eventBus.fireEvent(new FilterViewEvent(previousFilterOptions
.isFilterTranslated(), previousFilterOptions.isFilterFuzzy(),
previousFilterOptions.isFilterUntranslated(),
previousFilterOptions.isFilterApproved(), previousFilterOptions
.isFilterRejected(), previousFilterOptions
.isFilterHasError(), previousFilterOptions
.getEditorFilter(), true));
.isFilterTranslated(), previousFilterOptions.isFilterFuzzy(),
previousFilterOptions.isFilterUntranslated(),
previousFilterOptions.isFilterApproved(), previousFilterOptions
.isFilterRejected(), previousFilterOptions
.isFilterHasError(), previousFilterOptions.isFilterMT(),
previousFilterOptions.getEditorFilter(), true));
display.hideFilterConfirmation();
}

Expand Down
Expand Up @@ -77,6 +77,7 @@ public void onValueChange(ValueChangeEvent<String> event) {
configHolder.setFilterByApproved(newHistoryToken.isFilterApproved());
configHolder.setFilterByRejected(newHistoryToken.isFilterRejected());
configHolder.setFilterByHasError(newHistoryToken.isFilterHasError());
configHolder.setFilterByMT(newHistoryToken.isFilterMT());

DocumentId documentId =
documentListPresenter.getDocumentId(newHistoryToken
Expand Down Expand Up @@ -190,14 +191,17 @@ protected void processMessageFilterOptions(HistoryToken token) {
currentHistoryState.isFilterRejected())
|| !equal(token.isFilterHasError(),
currentHistoryState.isFilterHasError())
|| !equal(token.isFilterHasError(),
currentHistoryState.isFilterMT())
|| editorFilterChanged) {
Log.info("[gwt-history] message filter has changed");

eventBus.fireEvent(UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT);
eventBus.fireEvent(new FilterViewEvent(token.isFilterTranslated(),
token.isFilterFuzzy(), token.isFilterUntranslated(), token
.isFilterApproved(), token.isFilterRejected(),
token.isFilterHasError(), newEditorToken, false));
token.isFilterFuzzy(), token.isFilterUntranslated(), token
.isFilterApproved(), token.isFilterRejected(),
token.isFilterHasError(), token.isFilterMT(), newEditorToken,
false));
}
}

Expand Down
Expand Up @@ -169,6 +169,7 @@ public void loadEditorDefaultOptions() {
configHolder.setFilterByApproved(UserConfigHolder.DEFAULT_FILTER);
configHolder.setFilterByRejected(UserConfigHolder.DEFAULT_FILTER);
configHolder.setFilterByHasError(UserConfigHolder.DEFAULT_FILTER);
configHolder.setFilterByMT(UserConfigHolder.DEFAULT_FILTER);
configHolder.setEnabledValidationIds(new ArrayList<ValidationId>());
configHolder.setNavOption(NavOption.FUZZY_UNTRANSLATED);
configHolder
Expand Down
Expand Up @@ -48,6 +48,8 @@ public interface TransFilterDisplay extends WidgetDisplay, EditorSearchFieldList

void setHasErrorFilter(boolean filterByHasError);

void setMTFilter(boolean filterByMT);

void selectPartialText(String text);

interface Listener {
Expand All @@ -56,7 +58,7 @@ interface Listener {
void messageFilterOptionChanged(Boolean translatedChkValue,
Boolean fuzzyChkValue, Boolean untranslatedChkValue,
Boolean approvedChkValue, Boolean rejectedChkValue,
Boolean hasErrorChkValue);
Boolean hasErrorChkValue, Boolean hasMTChkValue);

void onSearchFieldFocused(boolean focused);
}
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class TransFilterView extends Composite implements TransFilterDisplay {

@UiField
CheckBox parentIncompleteChk, untranslatedChk, fuzzyChk, rejectedChk,
parentCompleteChk, translatedChk, approvedChk, hasErrorChk;
parentCompleteChk, translatedChk, approvedChk, hasErrorChk, mtChk;

private Listener listener;

Expand Down Expand Up @@ -119,6 +119,11 @@ public void setHasErrorFilter(boolean filterByHasError) {
updateChildCheckbox(hasErrorChk, filterByHasError);
}

@Override
public void setMTFilter(boolean filterByMT) {
updateChildCheckbox(mtChk, filterByMT);
}

private void updateChildCheckbox(CheckBox checkbox, boolean value) {
checkbox.setValue(value);
updateParentCheckboxes();
Expand Down Expand Up @@ -146,13 +151,13 @@ public void onSearchFieldCancel() {
}

@UiHandler({ "translatedChk", "fuzzyChk", "untranslatedChk", "approvedChk",
"rejectedChk", "hasErrorChk" })
"rejectedChk", "hasErrorChk", "mtChk" })
public void onFilterOptionsChanged(ValueChangeEvent<Boolean> event) {
updateParentCheckboxes();
listener.messageFilterOptionChanged(translatedChk.getValue(),
fuzzyChk.getValue(), untranslatedChk.getValue(),
approvedChk.getValue(), rejectedChk.getValue(),
hasErrorChk.getValue());
hasErrorChk.getValue(), mtChk.getValue());
}

private void updateParentCheckboxes() {
Expand Down Expand Up @@ -222,5 +227,6 @@ public void setOptionsState(ConfigurationState state) {
approvedChk.setValue(state.isFilterByApproved());
rejectedChk.setValue(state.isFilterByRejected());
hasErrorChk.setValue(state.isFilterByHasError());
mtChk.setValue(state.isFilterByMT());
}
}
Expand Up @@ -56,10 +56,10 @@

.hasError {
border-left: 3px solid #e0575b;
padding-right: 5px;
opacity: 0.6;
transition: .3s;
display: inline !important;
}

.mt {
border-left: 3px solid #a456e0;
}

.filterListToggle {
Expand Down Expand Up @@ -206,10 +206,21 @@
</li>

<li class="{style.drop-down}">
<g:CheckBox ui:field="hasErrorChk"
styleName="{style.hasError} {style.checkbox}">
<ui:msg>Invalid</ui:msg>
</g:CheckBox>
<label>Others</label>
<ul class="{style.filterList}">
<li>
<g:CheckBox ui:field="hasErrorChk"
styleName="{style.hasError} {style.checkbox}">
<ui:msg>Invalid</ui:msg>
</g:CheckBox>
</li>
<li>
<g:CheckBox ui:field="mtChk"
styleName="{style.mt} {style.checkbox}">
<ui:msg>Machine Translation</ui:msg>
</g:CheckBox>
</li>
</ul>
</li>
</g:HTMLPanel>
</ui:UiBinder>

0 comments on commit 1d25edc

Please sign in to comment.