Implemented export functionality. Minor layout fixes.

This commit is contained in:
Prominence 2016-08-20 23:50:06 +03:00
parent 34048f9525
commit 98dfa730ce
8 changed files with 99 additions and 43 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@
target target
.idea .idea
*.zip *.zip
*.iml
.slcache .slcache

View File

@ -1,5 +1,8 @@
package by.prominence.translations package by.prominence.translations
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
class TranslationsManagementController { class TranslationsManagementController {
def bundleService def bundleService
@ -54,4 +57,39 @@ class TranslationsManagementController {
redirect action: 'index' redirect action: 'index'
} }
def export() {
if (params.bundleName) {
Bundle bundle = bundleService.findBundleByName(params.bundleName)
if (params.langTag) {
File exportFile = bundle.languages.find { lang ->
lang.languageTag == params.langTag
}?.languageFile
if (exportFile && exportFile.exists()) {
response.setHeader "Content-disposition", "attachment; filename=${exportFile.name}"
response.contentType = 'text/plain'
response.contentLength = exportFile.size()
response.outputStream << exportFile.bytes
}
} else {
response.contentType = 'aplication/octet-stream'
response.setHeader('Content-disposition', "attachment; filename=\"${bundle.name}.zip\"")
ZipOutputStream zipOutputStream = new ZipOutputStream(response.outputStream)
bundle.languages.each { lang ->
ZipEntry language = new ZipEntry(lang.languageFile.name)
zipOutputStream.putNextEntry(language)
zipOutputStream.write(lang.languageFile.bytes)
}
zipOutputStream.close()
}
} else {
redirect action: 'index'
}
}
} }

View File

@ -8,7 +8,7 @@ class BundleService {
private static final String DEFAULT_FOLDER = "i18n" private static final String DEFAULT_FOLDER = "i18n"
private static final String DEFAULT_EXTENSION = '.properties' private static final String DEFAULT_EXTENSION = '.properties'
private static final String STANDARD_LANGUAGE_TAG = 'standard' private static final String STANDARD_LANGUAGE_TAG = 'default'
HashSet<Bundle> getBundles(boolean noCache = false) { HashSet<Bundle> getBundles(boolean noCache = false) {
if (!cachedBundles || noCache) { if (!cachedBundles || noCache) {

View File

@ -3,13 +3,14 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><g:layoutTitle default="Translations overview" /></title> <title><g:layoutTitle default="Translations overview" /></title>
<r:require modules="bootstrap"/>
<r:layoutResources/> <r:layoutResources/>
</head> </head>
<r:layoutResources/> <r:layoutResources/>
<link rel="stylesheet" href="${resource(dir: 'css', file: 'translations.css')}" type="text/css"> <link rel="stylesheet" href="${resource(dir: 'css', file: 'translations.css')}" type="text/css">
<body> <body>
<div class="container main-container"> <div class="container translations-container">
<g:layoutBody /> <g:layoutBody />
</div> </div>

View File

@ -3,17 +3,11 @@
<head> <head>
<meta name="layout" content="main"/> <meta name="layout" content="main"/>
<title><g:message code="plugin.translations.overview.edit.page.title" args="${[bundle.name]}"/></title> <title><g:message code="plugin.translations.overview.edit.page.title" args="${[bundle.name]}"/></title>
<r:require modules="bootstrap"/>
</head> </head>
<body> <body>
<div class="container"> <g:each in="${bundle.languages}" var="language">
<div class="row"> <g:render template="templates/language" model="${[language: language]}" />
<g:each in="${bundle.languages}" var="language"> </g:each>
<g:render template="templates/language" model="${[language: language]}" />
<br />
</g:each>
</div>
</div>
</body> </body>
</html> </html>

View File

@ -3,7 +3,6 @@
<head> <head>
<meta name="layout" content="main"/> <meta name="layout" content="main"/>
<title><g:message code="plugin.translations.overview.index.page.title" /></title> <title><g:message code="plugin.translations.overview.index.page.title" /></title>
<r:require modules="bootstrap"/>
</head> </head>
<body> <body>
@ -34,22 +33,20 @@
<b>${bundle.name}</b> <b>${bundle.name}</b>
</td> </td>
<td> <td>
<div class="action-buttons"> <g:link action="export" params="${[bundleName: bundle.name]}"
<g:link action="edit" params="${[bundleName: bundle.name]}" class="btn btn-default">
class="btn btn-default"> <g:message code="plugin.translations.action.export"/>
<g:message code="plugin.translations.action.edit"/> </g:link>
</g:link> <g:link action="edit" params="${[bundleName: bundle.name]}"
<g:link action="export" params="${[bundleName: bundle.name]}" class="btn btn-primary">
class="btn btn-primary"> <g:message code="plugin.translations.action.edit"/>
<g:message code="plugin.translations.action.export"/> </g:link>
</g:link>
</div>
</td> </td>
</tr> </tr>
</g:each> </g:each>
</tbody> </tbody>
</table> </table>
<div class="total"> <div class="translations-total-label">
<g:message code="plugin.translations.totalBundles" args="${[bundles.size()]}"/> <g:message code="plugin.translations.totalBundles" args="${[bundles.size()]}"/>
</div> </div>
</g:if> </g:if>

View File

@ -1,12 +1,32 @@
<g:form action="saveFile" name="${language.languageTag}"> <div class="row">
<h3>${language.languageTag.toUpperCase()}</h3> <div class="translations-main-block">
<g:textField name="lang" value="${language.languageTag}" hidden="true"/> <g:form action="saveFile" name="${language.languageTag}" class="form-horizontal">
<g:textField name="bundleName" value="${language.bundle.name}" hidden="true"/> <h3>${language.languageTag.toUpperCase()}</h3>
<g:textField name="langFile" value="${language.languageFile.path}" hidden="true"/> <g:textField name="lang" value="${language.languageTag}" hidden="true"/>
<g:each in="${language.translations}" var="translation"> <g:textField name="bundleName" value="${language.bundle.name}" hidden="true"/>
<g:set var="key" value="${ts.propertyKey(property: translation)}"/> <g:textField name="langFile" value="${language.languageFile.path}" hidden="true"/>
<label>${key}</label> <g:textField name="translations.${key}" value="${ts.propertyValue(property: translation)}" /> <div class="form-group">
<br/> <g:each in="${language.translations}" var="translation">
</g:each> <g:set var="key" value="${ts.propertyKey(property: translation)}"/>
<g:submitButton name="save" class="btn btn-primary" value="${g.message(code: 'plugin.translations.action.save')}"/> <div class="col-sm-4">
</g:form> <label class="control-label">${key}</label>
</div>
<div class="col-sm-8">
<g:textField class="form-control" name="translations.${key}"
value="${ts.propertyValue(property: translation)}" />
</div>
<br/>
</g:each>
</div>
<div class="pull-right">
<g:link class="btn btn-default" action="export" params="[bundleName: language.bundle.name,
langTag: language.languageTag]">
<g:message code="plugin.translations.action.export"/>
</g:link>
<g:submitButton name="save" class="btn btn-primary"
value="${g.message(code: 'plugin.translations.action.save')}"/>
</div>
</g:form>
</div>
</div>

View File

@ -12,8 +12,9 @@ table {
width: 100%; width: 100%;
} }
.main-container { .translations-container {
margin-top: 10%; margin-top: 5%;
margin-bottom: 5%;
border: #000 solid 1px; border: #000 solid 1px;
background-color: #707070; background-color: #707070;
padding: 10px; padding: 10px;
@ -21,16 +22,20 @@ table {
font-size: 1.2em; font-size: 1.2em;
} }
.total { .translations-total-label {
margin: 10px; margin: 10px;
font-size: 1.5em; font-size: 1.5em;
} }
.action-buttons {
padding-top: 1px;
padding-bottom: 1px;
}
.table-hover tbody tr:hover { .table-hover tbody tr:hover {
color: #111; color: #111;
}
input {
color: #000;
}
.translations-main-block {
margin-left: 25px;
margin-right: 25px;
} }