From 98dfa730cec9c78a688a5cf5c84eb4189c01ffe8 Mon Sep 17 00:00:00 2001 From: Prominence Date: Sat, 20 Aug 2016 23:50:06 +0300 Subject: [PATCH] Implemented export functionality. Minor layout fixes. --- .gitignore | 1 + .../TranslationsManagementController.groovy | 38 ++++++++++++++++ .../translations/BundleService.groovy | 2 +- grails-app/views/layouts/main.gsp | 3 +- .../views/translationsManagement/edit.gsp | 12 ++--- .../views/translationsManagement/index.gsp | 21 ++++----- .../templates/_language.gsp | 44 ++++++++++++++----- web-app/css/translations.css | 21 +++++---- 8 files changed, 99 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index 8e43d8d..b9d57b1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ target .idea *.zip +*.iml .slcache \ No newline at end of file diff --git a/grails-app/controllers/by/prominence/translations/TranslationsManagementController.groovy b/grails-app/controllers/by/prominence/translations/TranslationsManagementController.groovy index 45252c0..3fa3b46 100644 --- a/grails-app/controllers/by/prominence/translations/TranslationsManagementController.groovy +++ b/grails-app/controllers/by/prominence/translations/TranslationsManagementController.groovy @@ -1,5 +1,8 @@ package by.prominence.translations +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream + class TranslationsManagementController { def bundleService @@ -54,4 +57,39 @@ class TranslationsManagementController { 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' + } + } + } diff --git a/grails-app/services/by/prominence/translations/BundleService.groovy b/grails-app/services/by/prominence/translations/BundleService.groovy index 6489f35..f2bc4c5 100644 --- a/grails-app/services/by/prominence/translations/BundleService.groovy +++ b/grails-app/services/by/prominence/translations/BundleService.groovy @@ -8,7 +8,7 @@ class BundleService { private static final String DEFAULT_FOLDER = "i18n" private static final String DEFAULT_EXTENSION = '.properties' - private static final String STANDARD_LANGUAGE_TAG = 'standard' + private static final String STANDARD_LANGUAGE_TAG = 'default' HashSet getBundles(boolean noCache = false) { if (!cachedBundles || noCache) { diff --git a/grails-app/views/layouts/main.gsp b/grails-app/views/layouts/main.gsp index b042076..026eccb 100644 --- a/grails-app/views/layouts/main.gsp +++ b/grails-app/views/layouts/main.gsp @@ -3,13 +3,14 @@ <g:layoutTitle default="Translations overview" /> + -
+
diff --git a/grails-app/views/translationsManagement/edit.gsp b/grails-app/views/translationsManagement/edit.gsp index 7d5db2a..452a842 100644 --- a/grails-app/views/translationsManagement/edit.gsp +++ b/grails-app/views/translationsManagement/edit.gsp @@ -3,17 +3,11 @@ <g:message code="plugin.translations.overview.edit.page.title" args="${[bundle.name]}"/> - -
-
- - -
-
-
-
+ + + \ No newline at end of file diff --git a/grails-app/views/translationsManagement/index.gsp b/grails-app/views/translationsManagement/index.gsp index f1139cb..7555160 100644 --- a/grails-app/views/translationsManagement/index.gsp +++ b/grails-app/views/translationsManagement/index.gsp @@ -3,7 +3,6 @@ <g:message code="plugin.translations.overview.index.page.title" /> - @@ -34,22 +33,20 @@ ${bundle.name} -
- - - - - - -
+ + + + + + -
+
diff --git a/grails-app/views/translationsManagement/templates/_language.gsp b/grails-app/views/translationsManagement/templates/_language.gsp index 719b74f..8972a36 100644 --- a/grails-app/views/translationsManagement/templates/_language.gsp +++ b/grails-app/views/translationsManagement/templates/_language.gsp @@ -1,12 +1,32 @@ - -

${language.languageTag.toUpperCase()}

-
\ No newline at end of file +
+
+ +

${language.languageTag.toUpperCase()}

+
+
+
\ No newline at end of file diff --git a/web-app/css/translations.css b/web-app/css/translations.css index 1e9dfd1..51b5e4f 100644 --- a/web-app/css/translations.css +++ b/web-app/css/translations.css @@ -12,8 +12,9 @@ table { width: 100%; } -.main-container { - margin-top: 10%; +.translations-container { + margin-top: 5%; + margin-bottom: 5%; border: #000 solid 1px; background-color: #707070; padding: 10px; @@ -21,16 +22,20 @@ table { font-size: 1.2em; } -.total { +.translations-total-label { margin: 10px; font-size: 1.5em; } -.action-buttons { - padding-top: 1px; - padding-bottom: 1px; -} - .table-hover tbody tr:hover { color: #111; +} + +input { + color: #000; +} + +.translations-main-block { + margin-left: 25px; + margin-right: 25px; } \ No newline at end of file