Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow source lang selection for TMX export
- Loading branch information
Alex Eng
committed
Jun 21, 2017
1 parent
fa8f01c
commit 5360ec1
Showing
18 changed files
with
796 additions
and
4 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
api/zanata-common-api/src/main/java/org/zanata/rest/dto/SourceLocaleDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonPropertyOrder; | ||
import org.codehaus.jackson.map.annotate.JsonSerialize; | ||
|
||
import javax.xml.bind.annotation.XmlAttribute; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import javax.xml.bind.annotation.XmlType; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
@XmlType(name = "sourceLocaleDetailsType") | ||
@XmlRootElement(name = "sourceLocaleDetails") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonPropertyOrder({"docCount", "localeDetails"}) | ||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) | ||
public class SourceLocaleDetails implements Serializable { | ||
private Integer docCount; | ||
private LocaleDetails localeDetails; | ||
|
||
public SourceLocaleDetails() { | ||
this(null, null); | ||
} | ||
|
||
public SourceLocaleDetails(Integer docCount, LocaleDetails localeDetails) { | ||
this.docCount = docCount; | ||
this.localeDetails = localeDetails; | ||
} | ||
|
||
@XmlAttribute(name = "docCount", required = true) | ||
public Integer getDocCount() { | ||
return docCount; | ||
} | ||
|
||
public void setDocCount(Integer docCount) { | ||
this.docCount = docCount; | ||
} | ||
|
||
@XmlAttribute(name = "localeDetails", required = true) | ||
public LocaleDetails getLocaleDetails() { | ||
return localeDetails; | ||
} | ||
|
||
public void setLocaleDetails(LocaleDetails localeDetails) { | ||
this.localeDetails = localeDetails; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
SourceLocaleDetails details = (SourceLocaleDetails) o; | ||
|
||
if (docCount != null ? !docCount.equals(details.docCount) : | ||
details.docCount != null) return false; | ||
return localeDetails != null ? | ||
localeDetails.equals(details.localeDetails) : | ||
details.localeDetails == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = docCount != null ? docCount.hashCode() : 0; | ||
result = | ||
31 * result + | ||
(localeDetails != null ? localeDetails.hashCode() : 0); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
api/zanata-common-api/src/test/java/org/zanata/rest/dto/SourceLocaleDetailsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.zanata.rest.dto; | ||
|
||
import org.junit.Test; | ||
import org.zanata.common.LocaleId; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
public class SourceLocaleDetailsTest { | ||
@Test | ||
public void testEmptyConstructor() { | ||
SourceLocaleDetails details = new SourceLocaleDetails(); | ||
assertThat(details.getDocCount(), equalTo(null)); | ||
assertThat(details.getLocaleDetails(), equalTo(null)); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
LocaleDetails localeDetails = | ||
new LocaleDetails(LocaleId.DE, "German", "", "", true, | ||
false, ""); | ||
SourceLocaleDetails details = | ||
new SourceLocaleDetails(10, localeDetails); | ||
|
||
assertThat(details.getDocCount(), equalTo(10)); | ||
assertThat(details.getLocaleDetails(), equalTo(localeDetails)); | ||
} | ||
|
||
@Test | ||
public void testGetterSetter() { | ||
SourceLocaleDetails details = new SourceLocaleDetails(); | ||
details.setDocCount(100); | ||
assertThat(details.getDocCount(), equalTo(100)); | ||
|
||
LocaleDetails localeDetails = | ||
new LocaleDetails(LocaleId.DE, "German", "", "", true, | ||
false, ""); | ||
details.setLocaleDetails(localeDetails); | ||
assertThat(details.getDocCount(), equalTo(localeDetails)); | ||
|
||
} | ||
|
||
@Test | ||
public void testEqualsAndHashCode() { | ||
LocaleDetails localeDetails = | ||
new LocaleDetails(LocaleId.DE, "German", "", "", true, | ||
false, ""); | ||
SourceLocaleDetails details1 = | ||
new SourceLocaleDetails(10, localeDetails); | ||
|
||
SourceLocaleDetails details2 = | ||
new SourceLocaleDetails(10, localeDetails); | ||
|
||
assertThat(details1.hashCode(), equalTo(details2.hashCode())); | ||
assertThat(details1.equals(details2), equalTo(true)); | ||
|
||
details2 = | ||
new SourceLocaleDetails(100, localeDetails); | ||
|
||
assertThat(details1.hashCode(), not(equalTo(details2.hashCode()))); | ||
assertThat(details1.equals(details2), equalTo(false)); | ||
|
||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
server/zanata-frontend/src/frontend/app/actions/tmx-actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { createAction } from 'redux-actions' | ||
import { CALL_API } from 'redux-api-middleware' | ||
import { isUndefined, includes } from 'lodash' | ||
import { | ||
getJsonHeaders, | ||
buildAPIRequest, | ||
} from './common-actions' | ||
import { apiUrl } from '../config' | ||
|
||
export const TMX_TYPE = ['all', 'project', 'version'] | ||
|
||
export const SHOW_EXPORT_TMX_MODAL = Symbol('SHOW_EXPORT_TMX_MODAL') | ||
export const TOGGLE_SHOW_SOURCE_LANGUAGES = Symbol('TOGGLE_SHOW_SOURCE_LANGUAGES') | ||
|
||
export const GET_LOCALE_REQUEST = Symbol('GET_LOCALE_REQUEST') | ||
export const GET_LOCALE_SUCCESS = Symbol('GET_LOCALE_SUCCESS') | ||
export const GET_LOCALE_FAILURE = Symbol('GET_LOCALE_FAILURE') | ||
|
||
export const showExportTMXModal = createAction(SHOW_EXPORT_TMX_MODAL) | ||
export const toggleShowSourceLanguages = createAction(TOGGLE_SHOW_SOURCE_LANGUAGES) | ||
|
||
const fetchSourceLanguages = (endpoint) => { | ||
const apiTypes = [ | ||
GET_LOCALE_REQUEST, | ||
{ | ||
type: GET_LOCALE_SUCCESS, | ||
payload: (action, state, res) => { | ||
const contentType = res.headers.get('Content-Type') | ||
if (contentType && includes(contentType, 'json')) { | ||
return res.json().then((json) => { | ||
return json | ||
}) | ||
} | ||
}, | ||
meta: { | ||
receivedAt: Date.now() | ||
} | ||
}, | ||
GET_LOCALE_FAILURE | ||
] | ||
return { | ||
[CALL_API]: buildAPIRequest(endpoint, 'GET', getJsonHeaders(), apiTypes) | ||
} | ||
} | ||
|
||
// get all source language in all active documents | ||
const fetchAllSourceLanguages = () => { | ||
const endpoint = apiUrl + '/locales/source' | ||
return fetchSourceLanguages(endpoint) | ||
} | ||
|
||
// get all source language in all active documents in project | ||
const fetchProjectSourceLanguages = (project) => { | ||
const endpoint = apiUrl + '/projects/p/' + project + '/locales/source' | ||
return fetchSourceLanguages(endpoint) | ||
} | ||
|
||
// get all source language in all active documents in project version | ||
const fetchVersionSourceLanguages = (project, version) => { | ||
const endpoint = apiUrl + '/projects/p/' + project + '/iteration/i/' + version + '/locales/source' | ||
return fetchSourceLanguages(endpoint) | ||
} | ||
|
||
export const showSourceLanguages = (show, type) => { | ||
return (dispatch, getState) => { | ||
toggleShowSourceLanguages(show) | ||
if (show && isUndefined(getState().tmx.sourceLanguages)) { | ||
if (type === 'all') { | ||
dispatch(fetchAllSourceLanguages()) | ||
} else if (type === 'project') { | ||
dispatch(fetchProjectSourceLanguages(getState().tmx.projectName)) | ||
} else { | ||
dispatch(fetchVersionSourceLanguages(getState().tmx.projectName, | ||
getState().tmx.version)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const exportTMX = () => { | ||
return (dispatch, getState) => { | ||
|
||
} | ||
} | ||
|
||
|
Oops, something went wrong.