diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 526c15cca..ae4570622 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,7 +47,7 @@ jobs: ########################################################################## - name: Admin | Build `test` image run: | - docker build --target test -t "gradido/admin:test" admin/ + docker build --target test -t "gradido/admin:test" admin/ --build-arg NODE_ENV="test" docker save "gradido/admin:test" > /tmp/admin.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -294,6 +294,35 @@ jobs: - name: Admin Interface | Lint run: docker run --rm gradido/admin:test yarn run lint + ############################################################################## + # JOB: LOCALES ADMIN ###################################################### + ############################################################################## + locales_admin: + name: Locales - Admin + runs-on: ubuntu-latest + needs: [build_test_admin] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # DOWNLOAD DOCKER IMAGE ################################################## + ########################################################################## + - name: Download Docker Image (Admin Interface) + uses: actions/download-artifact@v2 + with: + name: docker-admin-test + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/admin.tar + ########################################################################## + # LOCALES FRONTEND ####################################################### + ########################################################################## + - name: admin | Locales + run: docker run --rm gradido/admin:test yarn run locales + ############################################################################## # JOB: LINT BACKEND ########################################################## ############################################################################## diff --git a/admin/Dockerfile b/admin/Dockerfile index 44ee4850c..41f986f87 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -13,7 +13,7 @@ ENV BUILD_VERSION="0.0.0.0" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 ENV BUILD_COMMIT="0000000" ## SET NODE_ENV -ENV NODE_ENV="production" +ARG NODE_ENV="production" ## App relevant Envs ENV PORT="8080" diff --git a/admin/babel.config.js b/admin/babel.config.js index 80b148fd1..742388ea3 100644 --- a/admin/babel.config.js +++ b/admin/babel.config.js @@ -1,4 +1,15 @@ -module.exports = { - presets: ['@babel/preset-env'], - plugins: ['transform-require-context'], +module.exports = function (api) { + api.cache(true) + + const presets = ['@babel/preset-env'] + const plugins = [] + + if (process.env.NODE_ENV === 'test') { + plugins.push('transform-require-context') + } + + return { + presets, + plugins, + } } diff --git a/admin/package.json b/admin/package.json index 9d70c0b06..c94d0a2b0 100644 --- a/admin/package.json +++ b/admin/package.json @@ -12,7 +12,8 @@ "dev": "yarn run serve", "build": "vue-cli-service build", "lint": "eslint --ext .js,.vue .", - "test": "jest --coverage" + "test": "jest --coverage", + "locales": "scripts/missing-keys.sh && scripts/sort.sh" }, "dependencies": { "@babel/core": "^7.15.8", diff --git a/admin/scripts/missing-keys.sh b/admin/scripts/missing-keys.sh new file mode 100755 index 000000000..6dbaee897 --- /dev/null +++ b/admin/scripts/missing-keys.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +ROOT_DIR=$(dirname "$0")/.. + +sorting="jq -f $ROOT_DIR/scripts/sort_filter.jq" +english="$sorting $ROOT_DIR/src/locales/en.json" +german="$sorting $ROOT_DIR/src/locales/de.json" +listPaths="jq -c 'path(..)|[.[]|tostring]|join(\".\")'" +diffString="<( $english | $listPaths ) <( $german | $listPaths )" +if eval "diff -q $diffString"; +then + : # all good +else + eval "diff -y $diffString | grep '[|<>]'"; + printf "\nEnglish and German translation keys do not match, see diff above.\n" + exit 1 +fi diff --git a/admin/scripts/sort.sh b/admin/scripts/sort.sh new file mode 100755 index 000000000..e5c5c41c6 --- /dev/null +++ b/admin/scripts/sort.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +ROOT_DIR=$(dirname "$0")/.. + +tmp=$(mktemp) +exit_code=0 + +for locale_file in $ROOT_DIR/src/locales/*.json +do + jq -f $(dirname "$0")/sort_filter.jq $locale_file > "$tmp" + if [ "$*" == "--fix" ] + then + mv "$tmp" $locale_file + else + if diff -q "$tmp" $locale_file > /dev/null ; + then + : # all good + else + exit_code=$? + echo "$(basename -- $locale_file) is not sorted by keys" + fi + fi +done + +exit $exit_code diff --git a/admin/scripts/sort_filter.jq b/admin/scripts/sort_filter.jq new file mode 100644 index 000000000..9d108f8f0 --- /dev/null +++ b/admin/scripts/sort_filter.jq @@ -0,0 +1,13 @@ +def walk(f): + . as $in + | if type == "object" then + reduce keys_unsorted[] as $key + ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f + elif type == "array" then map( walk(f) ) | f + else f + end; + +def keys_sort_by(f): + to_entries | sort_by(.key|f ) | from_entries; + +walk(if type == "object" then keys_sort_by(ascii_upcase) else . end) \ No newline at end of file diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index efaff3481..9d1309cae 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -171,14 +171,17 @@ export default { currentMonth: { short: this.$moment().format('MMMM'), long: this.$moment().format('YYYY-MM-DD'), + year: this.$moment().format('YYYY'), }, lastMonth: { short: this.$moment().subtract(1, 'month').format('MMMM'), long: this.$moment().subtract(1, 'month').format('YYYY-MM') + '-01', + year: this.$moment().subtract(1, 'month').format('YYYY'), }, beforeLastMonth: { short: this.$moment().subtract(2, 'month').format('MMMM'), long: this.$moment().subtract(2, 'month').format('YYYY-MM') + '-01', + year: this.$moment().subtract(2, 'month').format('YYYY'), }, submitObj: null, isdisabled: true, @@ -190,6 +193,7 @@ export default { // Auswählen eines Zeitraumes updateRadioSelected(name, index, openCreation) { this.createdIndex = index + this.text = 'Schöpfung für ' + name.short + ' ' + name.year // Wenn Mehrfachschöpfung if (this.type === 'massCreation') { // An Creation.vue emitten und radioSelectedMass aktualisieren diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index eae328adf..3a82663ce 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -36,6 +36,10 @@ hover stacked="md" > + +