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

Commit

Permalink
Merge branch 'language-react' of https://github.com/zanata/zanata-server
Browse files Browse the repository at this point in the history
 into language-react
  • Loading branch information
kgough committed Oct 11, 2016
2 parents 2f0c1c7 + 7bcb82c commit c6552bc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
36 changes: 36 additions & 0 deletions zanata-frontend/src/frontend/app/actions/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const LANGUAGE_PERMISSION_REQUEST = 'LANGUAGE_PERMISSION_REQUEST'
export const LANGUAGE_PERMISSION_SUCCESS = 'LANGUAGE_PERMISSION_SUCCESS'
export const LANGUAGE_PERMISSION_FAILURE = 'LANGUAGE_PERMISSION_FAILURE'

export const CREATE_LANGUAGE_REQUEST = 'CREATE_LANGUAGE_REQUEST'
export const CREATE_LANGUAGE_SUCCESS = 'CREATE_LANGUAGE_SUCCESS'
export const CREATE_LANGUAGE_FAILURE = 'CREATE_LANGUAGE_FAILURE'

export const LANGUAGE_DELETE_REQUEST = 'LANGUAGE_DELETE_REQUEST'
export const LANGUAGE_DELETE_SUCCESS = 'LANGUAGE_DELETE_SUCCESS'
export const LANGUAGE_DELETE_FAILURE = 'LANGUAGE_DELETE_FAILURE'
Expand Down Expand Up @@ -187,6 +191,32 @@ const deleteLanguage = (dispatch, localeId) => {
}
}

const createNewLanguage = (details) => {
const endpoint = window.config.baseUrl + window.config.apiRoot +
'/locales/locale/'

let headers = getJsonHeaders()
headers['Content-Type'] = 'application/json'

const apiTypes = [
CREATE_LANGUAGE_REQUEST,
{
type: CREATE_LANGUAGE_SUCCESS,
payload: (action, state, res) => {
return res
},
meta: {
receivedAt: Date.now()
}
},
CREATE_LANGUAGE_FAILURE
]
return {
[CALL_API]: buildAPIRequest(endpoint, 'POST', headers, apiTypes,
JSON.stringify(details))
}
}

export const initialLoad = () => {
return (dispatch, getState) => {
// validate page number from query
Expand Down Expand Up @@ -265,3 +295,9 @@ export const handleLoadSuggestion = (query) => {
}
}
}

export const handleSaveNewLanguage = (details) => {
return (dispatch, getState) => {
dispatch(createNewLanguage(details))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {

import {
handleNewLanguageDisplay,
handleLoadSuggestion
handleLoadSuggestion,
handleSaveNewLanguage
} from '../../actions/languages'

class NewLanguageModal extends Component {
Expand Down Expand Up @@ -140,15 +141,15 @@ class NewLanguageModal extends Component {
<FormControl type='text'
onChange={(e) => this.updateField('displayName', e)}
placeholder='Default display name'
defaultValue={details.displayName} />
value={details.displayName} />
<FormControl.Feedback />
</FormGroup>
<FormGroup>
<ControlLabel>Native Name</ControlLabel>
<FormControl type='text'
onChange={(e) => this.updateField('nativeName', e)}
placeholder='Default native name'
defaultValue={details.nativeName} />
value={details.nativeName} />
</FormGroup>
<FormGroup>
<strong className='Mend(eq)'>Language Code</strong>
Expand All @@ -161,7 +162,7 @@ class NewLanguageModal extends Component {
<FormControl type='text'
onChange={(e) => this.updateField('alias', e)}
placeholder='eg. en-US'
defaultValue={details.alias} />
value={details.alias} />
</FormGroup>
<FormGroup>
<ControlLabel>Plural forms</ControlLabel>
Expand All @@ -170,7 +171,7 @@ class NewLanguageModal extends Component {
onChange={(e) => this.updateField('pluralForms', e)}
placeholder='Default plural forms (if empty):
nplurals=2;plural=(n>1)'
defaultValue={details.pluralForms} />
value={details.pluralForms} />
</FormGroup>
<FormGroup>
<Checkbox
Expand Down Expand Up @@ -240,7 +241,7 @@ const mapDispatchToProps = (dispatch) => {
dispatch(handleNewLanguageDisplay(false))
},
handleOnSave: (details) => {
console.info(details)
dispatch(handleSaveNewLanguage(details))
},
loadSuggestion: (query) => {
updateSuggestion(query.value)
Expand Down
14 changes: 7 additions & 7 deletions zanata-frontend/src/frontend/app/reducers/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default handleActions({
...state,
user: {
...state.user,
loading: true
loading: false
},
loading: false,
notification: {
severity: SEVERITY.ERROR,
message: ERROR_MSG
permission: {
canDeleteLocale: false,
canAddLocale: false
}
}
} else {
Expand All @@ -86,9 +86,9 @@ export default handleActions({
loading: false
},
loading: false,
notification: {
severity: SEVERITY.ERROR,
message: ERROR_MSG
permission: {
canDeleteLocale: false,
canAddLocale: false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,20 @@ public Response delete(String localeId) {
identity.checkPermission("delete-language");

try {
// localeServiceImpl.delete(locale);
localeServiceImpl.delete(locale);
return Response.ok().build();
} catch (ConstraintViolationException e) {
return Response.status(Response.Status.METHOD_NOT_ALLOWED).build();
}
}

@Override
public Response createLanguage(LocaleDetails localeDetails) {
identity.checkPermission("insert-language");
// todo: add new language
return Response.status(Response.Status.CREATED).build();
}

private int validatePage(int page) {
return page < 1 ? 1 : page;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.ws.rs.core.Response;

import org.apache.deltaspike.jpa.api.transaction.Transactional;
import org.zanata.rest.dto.LocaleDetails;
import org.zanata.rest.editor.MediaTypes;
import org.zanata.rest.service.RestResource;

Expand Down Expand Up @@ -80,4 +81,18 @@ public Response get(@QueryParam("filter") String filter,
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response delete(@PathParam("localeId") String localeId);

/**
* Create new language in Zanata
* @return The following response status codes will be returned from this
* operation:<br>
* OK(201) - Locale is added. <br>
* INTERNAL SERVER ERROR(500) - If there is an unexpected error in
* the server while performing this operation.
*/
@POST
@Path("/locale")
@Produces({ MediaTypes.APPLICATION_ZANATA_LOCALES_JSON,
MediaType.APPLICATION_JSON })
public Response createLanguage(LocaleDetails localeDetails);
}

0 comments on commit c6552bc

Please sign in to comment.