diff --git a/.github/workflows/plugin-linting.yml b/.github/workflows/plugin-linting.yml index a9303a71..2847e667 100644 --- a/.github/workflows/plugin-linting.yml +++ b/.github/workflows/plugin-linting.yml @@ -3,7 +3,6 @@ name: Linting on: push: branches: - - master - main pull_request: schedule: diff --git a/.github/workflows/plugin-tests.yml b/.github/workflows/plugin-tests.yml index d443118e..622c4c1a 100644 --- a/.github/workflows/plugin-tests.yml +++ b/.github/workflows/plugin-tests.yml @@ -8,6 +8,10 @@ on: schedule: - cron: '0 */12 * * *' +concurrency: + group: plugin-tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} + cancel-in-progress: true + jobs: build: name: ${{ matrix.build_type }} @@ -29,10 +33,6 @@ jobs: build_type: ["backend", "frontend"] steps: - - name: Find plugin name - run: | - echo "PLUGIN_REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV - - uses: actions/checkout@v3 with: repository: discourse/discourse @@ -41,7 +41,7 @@ jobs: - name: Install plugin uses: actions/checkout@v3 with: - path: plugins/${{ env.PLUGIN_REPOSITORY_NAME }} + path: plugins/${{ github.event.repository.name }} fetch-depth: 1 - name: Setup Git @@ -78,7 +78,7 @@ jobs: - name: Lint English locale if: matrix.build_type == 'backend' - run: bundle exec ruby script/i18n_lint.rb "plugins/${{ env.PLUGIN_REPOSITORY_NAME }}/locales/{client,server}.en.yml" + run: bundle exec ruby script/i18n_lint.rb "plugins/${{ github.event.repository.name }}/locales/{client,server}.en.yml" - name: Get yarn cache directory id: yarn-cache-dir @@ -129,27 +129,25 @@ jobs: - name: Check spec existence id: check_spec - uses: andstor/file-existence-action@v1 - with: - files: "plugins/${{ env.PLUGIN_REPOSITORY_NAME }}/spec" + shell: bash + run: | + if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/spec -type f -name "*.rb" 2> /dev/null | wc -l) ]; then + echo "::set-output name=files_exist::true" + fi - - name: Check qunit existence - id: check_qunit - uses: andstor/file-existence-action@v1 - with: - files: "plugins/${{ env.PLUGIN_REPOSITORY_NAME }}/test/javascripts" + - name: Plugin RSpec + if: matrix.build_type == 'backend' && steps.check_spec.outputs.files_exist == 'true' + run: bin/rake plugin:spec[${{ github.event.repository.name }}] - - name: Plugin RSpec with Coverage - if: matrix.build_type == 'backend' + - name: Check QUnit existence + id: check_qunit + shell: bash run: | - if [ -e plugins/${{ env.PLUGIN_REPOSITORY_NAME }}/.simplecov ] - then - cp plugins/${{ env.PLUGIN_REPOSITORY_NAME }}/.simplecov .simplecov - export COVERAGE=1 + if [ 0 -lt $(find plugins/${{ github.event.repository.name }}/test/javascripts -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then + echo "::set-output name=files_exist::true" fi - bin/rake plugin:spec[${{ env.PLUGIN_REPOSITORY_NAME }}] - name: Plugin QUnit - if: matrix.build_type == 'frontend' && steps.check_qunit.outputs.files_exists == 'true' - run: bin/rake plugin:qunit['${{ env.PLUGIN_REPOSITORY_NAME }}','1200000'] - timeout-minutes: 30 + if: matrix.build_type == 'frontend' && steps.check_qunit.outputs.files_exist == 'true' + run: QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['${{ github.event.repository.name }}','1200000'] + timeout-minutes: 10 diff --git a/assets/javascripts/discourse/components/admin-multilingual-translations.js b/assets/javascripts/discourse/components/admin-multilingual-translations.js new file mode 100644 index 00000000..8e7dca76 --- /dev/null +++ b/assets/javascripts/discourse/components/admin-multilingual-translations.js @@ -0,0 +1,31 @@ +import MultilingualTranslation from "../models/multilingual-translation"; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; + +export default class AdminMultilingualTranslations extends Component { + @tracked refreshing = false; + @tracked translations = []; + + constructor() { + super(...arguments); + this._refresh(); + }; + + _refresh() { + this.refreshing = true; + + MultilingualTranslation.list() + .then((result) => { + this.translations = result; + }) + .finally(() => { + this.refreshing = false; + }); + }; + + @action + refresh() { + this._refresh(); + }; +}; diff --git a/assets/javascripts/discourse/components/admin-translation.js b/assets/javascripts/discourse/components/admin-translation.js new file mode 100644 index 00000000..c82f39f2 --- /dev/null +++ b/assets/javascripts/discourse/components/admin-translation.js @@ -0,0 +1,29 @@ +import MultilingualTranslation from "../models/multilingual-translation"; +import Component from '@glimmer/component'; +import { action } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; + +export default class AdminTranslation extends Component { + @tracked removing = false; + + @action + remove() { + this.removing = true; + + MultilingualTranslation.remove( + this.args.translation.locale, + this.args.translation.file_type + ).then((result) => { + this.removing = false; + this.args.removed(); + }); + }; + + @action + download() { + MultilingualTranslation.download( + this.args.translation.locale, + this.args.translation.file_type + ); + }; +}; diff --git a/assets/javascripts/discourse/components/admin-translation.js.es6 b/assets/javascripts/discourse/components/admin-translation.js.es6 deleted file mode 100644 index 31b5fb89..00000000 --- a/assets/javascripts/discourse/components/admin-translation.js.es6 +++ /dev/null @@ -1,28 +0,0 @@ -import MultilingualTranslation from "../models/multilingual-translation"; -import Component from "@ember/component"; - -export default Component.extend({ - tagName: "tr", - classNames: "language", - - actions: { - remove() { - this.set("removing", true); - - MultilingualTranslation.remove( - this.get("translation.locale"), - this.get("translation.file_type") - ).then((result) => { - this.set("removing", false); - this.removed(result); - }); - }, - - download() { - MultilingualTranslation.download( - this.get("translation.locale"), - this.get("translation.file_type") - ); - }, - }, -}); diff --git a/assets/javascripts/discourse/components/content-language-discovery.js b/assets/javascripts/discourse/components/content-language-discovery.js new file mode 100644 index 00000000..fc86942b --- /dev/null +++ b/assets/javascripts/discourse/components/content-language-discovery.js @@ -0,0 +1,61 @@ +import Component from '@glimmer/component'; +import { inject as service } from "@ember/service"; +import { isContentLanguage } from "../lib/multilingual"; +import { + contentLanguageParam, + getDiscoveryParam +} from "../lib/multilingual-route"; +import I18n from "I18n"; + +export default class ContentLanguageDiscovery extends Component { + @service siteSettings; + @service currentUser; + @service router; + + get shouldRender() { + return ( + this.siteSettings.multilingual_enabled && + this.siteSettings.multilingual_content_languages_enabled && + this.siteSettings.multilingual_content_languages_topic_filtering_enabled && + (this.currentUser || + this.router.currentRouteName.indexOf("categories") === -1) + ); + }; + + get contentLanguages() { + let contentLangs = this.currentUser + ? this.currentUser.content_languages + : this.site.content_languages; + + if (contentLangs) { + if (this.currentUser) { + if (!contentLangs.some((l) => l.locale === "set_content_language")) { + contentLangs.push({ + icon: "plus", + locale: "set_content_language", + name: I18n.t("user.content_languages.set"), + }); + } + } else { + contentLangs.forEach((l) => { + set(l, "classNames", "guest-content-language"); + }); + } + } + return contentLangs + }; + + get hasLanguages() { + let hasLangs; + + if (this.currentUser && this.contentLanguages) { + hasLangs = + this.contentLanguages.filter((l) => + isContentLanguage(l.locale, this.siteSettings) + ).length > 0; + } else { + hasLangs = getDiscoveryParam(this, contentLanguageParam); + } + return hasLangs; + } +}; diff --git a/assets/javascripts/discourse/connectors/before-create-topic-button/before-create-topic-button.hbs b/assets/javascripts/discourse/connectors/before-create-topic-button/before-create-topic-button.hbs new file mode 100644 index 00000000..35d6177d --- /dev/null +++ b/assets/javascripts/discourse/connectors/before-create-topic-button/before-create-topic-button.hbs @@ -0,0 +1 @@ + diff --git a/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.hbs b/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.hbs deleted file mode 100644 index 1a7393d5..00000000 --- a/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.hbs +++ /dev/null @@ -1,5 +0,0 @@ -{{content-languages-dropdown - content=contentLanguages - options=(hash - hasLanguages=hasLanguages - )}} diff --git a/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.js.es6 b/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.js.es6 deleted file mode 100644 index da1d7430..00000000 --- a/assets/javascripts/discourse/connectors/before-create-topic-button/content-language-discovery.js.es6 +++ /dev/null @@ -1,57 +0,0 @@ -import { set } from "@ember/object"; -import { isContentLanguage } from "../../lib/multilingual"; -import { - contentLanguageParam, - getDiscoveryParam, - getRouter, -} from "../../lib/multilingual-route"; -import I18n from "I18n"; - -export default { - shouldRender(attrs, ctx) { - return ( - ctx.siteSettings.multilingual_enabled && - ctx.siteSettings.multilingual_content_languages_enabled && - ctx.siteSettings.multilingual_content_languages_topic_filtering_enabled && - (this.currentUser || - getRouter(ctx).currentRouteName.indexOf("categories") === -1) - ); - }, - - setupComponent(attrs, ctx) { - const currentUser = ctx.get("currentUser"); - const site = ctx.get("site"); - - let hasLanguages; - let contentLanguages = currentUser - ? currentUser.get("content_languages") - : site.get("content_languages"); - - if (!contentLanguages) { - return; - } - - if (currentUser) { - hasLanguages = - contentLanguages.filter((l) => - isContentLanguage(l.locale, ctx.siteSettings) - ).length > 0; - - if (!contentLanguages.some((l) => l.locale === "set_content_language")) { - contentLanguages.push({ - icon: "plus", - locale: "set_content_language", - name: I18n.t("user.content_languages.set"), - }); - } - } else { - hasLanguages = getDiscoveryParam(ctx, contentLanguageParam); - - contentLanguages.forEach((l) => { - set(l, "classNames", "guest-content-language"); - }); - } - - ctx.setProperties({ contentLanguages, hasLanguages }); - }, -}; diff --git a/assets/javascripts/discourse/controllers/admin-multilingual-translations.js.es6 b/assets/javascripts/discourse/controllers/admin-multilingual-translations.js.es6 deleted file mode 100644 index 77b24885..00000000 --- a/assets/javascripts/discourse/controllers/admin-multilingual-translations.js.es6 +++ /dev/null @@ -1,24 +0,0 @@ -import Controller from "@ember/controller"; -import MultilingualTranslation from "../models/multilingual-translation"; - -export default Controller.extend({ - refreshing: false, - - _refresh() { - this.set("refreshing", true); - - MultilingualTranslation.list() - .then((result) => { - this.set("translations", result); - }) - .finally(() => { - this.set("refreshing", false); - }); - }, - - actions: { - refresh() { - this._refresh(); - }, - }, -}); diff --git a/assets/javascripts/discourse/templates/admin-multilingual-languages.hbs b/assets/javascripts/discourse/templates/admin-multilingual-languages.hbs index ee0b7cef..7281639b 100644 --- a/assets/javascripts/discourse/templates/admin-multilingual-languages.hbs +++ b/assets/javascripts/discourse/templates/admin-multilingual-languages.hbs @@ -16,7 +16,7 @@ done=(action "languagesUploaded")}} {{d-button - action="update" + action=(action "update") class="btn-primary" icon="save" label=updateState diff --git a/assets/javascripts/discourse/templates/admin-multilingual-translations.hbs b/assets/javascripts/discourse/templates/admin-multilingual-translations.hbs index 9b1f1fa5..d27eeb85 100644 --- a/assets/javascripts/discourse/templates/admin-multilingual-translations.hbs +++ b/assets/javascripts/discourse/templates/admin-multilingual-translations.hbs @@ -1,30 +1 @@ -
-
- {{multilingual-uploader - id="multilingual-translations-uploader" - uploading=uploading - done=(action "refresh") - uploadType="translation"}} -
-
- -{{#if refreshing}} - {{loading-spinner}} -{{else}} - {{#if translations}} - - - {{table-header-toggle field="locale" labelKey="multilingual.locale" automatic=true}} - {{table-header-toggle field="file_type" labelKey="multilingual.translations.type" automatic=true}} - - - - {{#each translations as |translation|}} - {{admin-translation translation=translation removed=(action "refresh")}} - {{/each}} - -
Actions
- {{else}} -

{{i18n "search.no_results"}}

- {{/if}} -{{/if}} + diff --git a/assets/javascripts/discourse/templates/admin-multilingual.hbs b/assets/javascripts/discourse/templates/admin-multilingual.hbs index c6fdb950..551a9297 100644 --- a/assets/javascripts/discourse/templates/admin-multilingual.hbs +++ b/assets/javascripts/discourse/templates/admin-multilingual.hbs @@ -18,7 +18,7 @@
  • {{d-button - action="showSettings" + action=(route-action "showSettings") label="admin.plugins.change_settings_short" icon="cog"}}
  • diff --git a/assets/javascripts/discourse/templates/components/admin-language.hbs b/assets/javascripts/discourse/templates/components/admin-language.hbs index d9e6ce72..9f5f9b24 100644 --- a/assets/javascripts/discourse/templates/components/admin-language.hbs +++ b/assets/javascripts/discourse/templates/components/admin-language.hbs @@ -41,7 +41,7 @@ {{#if actionsDisabled}} {{i18n "multilingual.languages.disabled"}} {{else}} - {{#d-button click=(action "remove") disabled=removing}} + {{#d-button action=(action "remove") disabled=removing}} {{#if removing}} {{loading-spinner size="small"}} {{else}} diff --git a/assets/javascripts/discourse/templates/components/admin-multilingual-translations.hbs b/assets/javascripts/discourse/templates/components/admin-multilingual-translations.hbs new file mode 100644 index 00000000..235a5aff --- /dev/null +++ b/assets/javascripts/discourse/templates/components/admin-multilingual-translations.hbs @@ -0,0 +1,30 @@ +
    +
    + {{multilingual-uploader + id="multilingual-translations-uploader" + uploading=uploading + done=(action "refresh") + uploadType="translation"}} +
    +
    + +{{#if refreshing}} + {{loading-spinner}} +{{else}} + {{#if this.translations}} + + + {{table-header-toggle field="locale" labelKey="multilingual.locale" automatic=true}} + {{table-header-toggle field="file_type" labelKey="multilingual.translations.type" automatic=true}} + + + + {{#each this.translations as |translation|}} + {{admin-translation translation=translation removed=(action this.refresh)}} + {{/each}} + +
    Actions
    + {{else}} +

    {{i18n "search.no_results"}}

    + {{/if}} +{{/if}} diff --git a/assets/javascripts/discourse/templates/components/admin-translation.hbs b/assets/javascripts/discourse/templates/components/admin-translation.hbs index e4a4d54b..3c1f5b12 100644 --- a/assets/javascripts/discourse/templates/components/admin-translation.hbs +++ b/assets/javascripts/discourse/templates/components/admin-translation.hbs @@ -1,18 +1,20 @@ - - {{translation.locale}} - + + + {{this.args.translation.locale}} + - - {{translation.file_type}} - + + {{this.args.translation.file_type}} + - - {{#d-button click=(action "remove")}} - {{#if removing}} - {{loading-spinner size="small"}} - {{else}} - {{d-icon "times"}} - {{i18n "multilingual.translations.remove"}} - {{/if}} - {{/d-button}} - + + + {{#if removing}} + {{loading-spinner size="small"}} + {{else}} + {{d-icon "times"}} + {{i18n "multilingual.translations.remove"}} + {{/if}} + + + diff --git a/assets/javascripts/discourse/templates/components/content-language-discovery.hbs b/assets/javascripts/discourse/templates/components/content-language-discovery.hbs new file mode 100644 index 00000000..7c169164 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/content-language-discovery.hbs @@ -0,0 +1,7 @@ +{{#if this.shouldRender}} +{{content-languages-dropdown + content=this.contentLanguages + options=(hash + hasLanguages=this.hasLanguages + )}} +{{/if}} diff --git a/assets/javascripts/discourse/templates/components/content-tag-groups-form.hbs b/assets/javascripts/discourse/templates/components/content-tag-groups-form.hbs index 304025c3..d9b609ec 100644 --- a/assets/javascripts/discourse/templates/components/content-tag-groups-form.hbs +++ b/assets/javascripts/discourse/templates/components/content-tag-groups-form.hbs @@ -40,4 +40,3 @@ label="tagging.groups.content_tags.delete.btn"}} - diff --git a/assets/javascripts/discourse/templates/components/language-switcher-bar.hbs b/assets/javascripts/discourse/templates/components/language-switcher-bar.hbs index 4fbb1149..722d9074 100644 --- a/assets/javascripts/discourse/templates/components/language-switcher-bar.hbs +++ b/assets/javascripts/discourse/templates/components/language-switcher-bar.hbs @@ -1,7 +1,7 @@ {{#each visibleLanguages as |l|}}
    {{l.name}}
    {{/each}} {{#if showHiddenToggle}} - {{d-button icon="plus" action="toggleHidden" class="toggle-hidden"}} + {{d-button icon="plus" action=(action "toggleHidden") class="toggle-hidden"}} {{#if showHidden}}
    diff --git a/plugin.rb b/plugin.rb index 9f6c5958..32f024bb 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-multilingual # about: Features to support multilingual forums -# version: 0.2.6 +# version: 0.2.7 # url: https://github.com/paviliondev/discourse-multilingual # authors: Angus McLeod, Robert Barrow # contact_emails: development@pavilion.tech diff --git a/spec/components/tag_spec.rb b/spec/components/tag_spec.rb index e23301cd..88f5baaa 100644 --- a/spec/components/tag_spec.rb +++ b/spec/components/tag_spec.rb @@ -5,6 +5,7 @@ describe Tag do fab!(:tag1) { Fabricate(:tag, name: "fun") } fab!(:tag2) { Fabricate(:tag, name: "fun2") } + fab!(:public_category) { Fabricate(:category) } before do SiteSetting.tagging_enabled = true @@ -16,7 +17,7 @@ end it "top_tags doesn't include content language tags" do - Fabricate(:topic, tags: [tag1, tag2, Tag.find_by(name: 'fr')]) - expect(Tag.top_tags).not_to include(Tag.find_by(name: 'fr').name) + Fabricate(:topic, category: public_category, tags: [tag1, tag2, Tag.find_by(name: 'fr')]) + expect(Tag.top_tags(category: public_category, guardian: Guardian.new(Fabricate(:user)))).not_to include(Tag.find_by(name: 'fr').name) end end