FEATURE: Locale support for seeded categories and topics (#7110)

FEATURE: Locale support for seeded categories and topics (#7110)

diff --git a/app/assets/javascripts/admin/controllers/modals/admin-reseed.js.es6 b/app/assets/javascripts/admin/controllers/modals/admin-reseed.js.es6
new file mode 100644
index 0000000..f71c7ea
--- /dev/null
+++ b/app/assets/javascripts/admin/controllers/modals/admin-reseed.js.es6
@@ -0,0 +1,42 @@
+import ModalFunctionality from "discourse/mixins/modal-functionality";
+import { ajax } from "discourse/lib/ajax";
+
+export default Ember.Controller.extend(ModalFunctionality, {
+  loading: true,
+  reseeding: false,
+  categories: null,
+  topics: null,
+
+  onShow() {
+    ajax("/admin/customize/reseed")
+      .then(result => {
+        this.setProperties({
+          categories: result.categories,
+          topics: result.topics
+        });
+      })
+      .finally(() => this.set("loading", false));
+  },
+
+  _extractSelectedIds(items) {
+    return items.filter(item => item.selected).map(item => item.id);
+  },
+
+  actions: {
+    reseed() {
+      this.set("reseeding", true);
+      ajax("/admin/customize/reseed", {
+        data: {
+          category_ids: this._extractSelectedIds(this.categories),
+          topic_ids: this._extractSelectedIds(this.topics)
+        },
+        method: "POST"
+      })
+        .then(
+          () => this.send("closeModal"),
+          () => bootbox.alert(I18n.t("generic_error"))
+        )
+        .finally(() => this.set("reseeding", false));
+    }
+  }
+});
diff --git a/app/assets/javascripts/admin/routes/admin-site-text-index.js.es6 b/app/assets/javascripts/admin/routes/admin-site-text-index.js.es6
index 4c3e826..dfec2f6 100644
--- a/app/assets/javascripts/admin/routes/admin-site-text-index.js.es6
+++ b/app/assets/javascripts/admin/routes/admin-site-text-index.js.es6
@@ -1,3 +1,5 @@
+import showModal from "discourse/lib/show-modal";
+
 export default Ember.Route.extend({
   queryParams: {
     q: { replace: true },
@@ -13,5 +15,11 @@ export default Ember.Route.extend({
 
   setupController(controller, model) {
     controller.set("siteTexts", model);
+  },
+
+  actions: {
+    showReseedModal() {
+      showModal("admin-reseed", { admin: true });
+    }
   }
 });
diff --git a/app/assets/javascripts/admin/templates/modal/admin-reseed.hbs b/app/assets/javascripts/admin/templates/modal/admin-reseed.hbs
new file mode 100644
index 0000000..0095bdf
--- /dev/null
+++ b/app/assets/javascripts/admin/templates/modal/admin-reseed.hbs
@@ -0,0 +1,36 @@
+{{#d-modal-body title="admin.reseed.modal.title" subtitle="admin.reseed.modal.subtitle" class="reseed-modal"}}
+  {{#conditional-loading-spinner condition=loading}}
+    {{#if categories}}
+      <fieldset>
+        <legend class="options-group-title">{{i18n "admin.reseed.modal.categories"}}</legend>
+
+        {{#each categories as |category|}}
+          <label>
+            {{input class="option" type="checkbox" checked=category.selected}}
+            <span>{{category.name}}</span>
+          </label>
+        {{/each}}
+      </fieldset>
+    {{/if}}
+
+    <br>
+
+    {{#if topics}}
+      <fieldset>
+        <legend class="options-group-title">{{i18n "admin.reseed.modal.topics"}}</legend>
+
+        {{#each topics as |topic|}}
+          <label>
+            {{input class="option" type="checkbox" checked=topic.selected}}
+            <span>{{topic.name}}</span>
+          </label>
+        {{/each}}
+      </fieldset>
+    {{/if}}
+  {{/conditional-loading-spinner}}
+{{/d-modal-body}}
+
+<div class="modal-footer">
+  {{d-button action=(action "reseed") class="btn-danger" label="go_ahead" disabled=reseeding}}
+  {{d-modal-cancel close=(route-action "closeModal")}}
+</div>
diff --git a/app/assets/javascripts/admin/templates/site-text-index.hbs b/app/assets/javascripts/admin/templates/site-text-index.hbs
index e75b4a1..de6b4e7 100644
--- a/app/assets/javascripts/admin/templates/site-text-index.hbs
+++ b/app/assets/javascripts/admin/templates/site-text-index.hbs
@@ -7,12 +7,20 @@
                autofocus="true"
                key-up=(action "search")}}
 
-  <div class='extra-options'>
+  <div class="reseed">
+    {{d-button action=(route-action "showReseedModal")
+               class="btn-default"
+               label="admin.reseed.action.label"
+               title="admin.reseed.action.title"
+               icon="sync"}}
+  </div>
+
+  <p class="filter-options">
     <label>
       {{input type="checkbox" checked=overridden click=(action "toggleOverridden")}}
       {{i18n 'admin.site_text.show_overriden'}}
     </label>
-  </div>
+  </p>
 </div>
 
 {{#conditional-loading-spinner condition=searching}}
diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss
index a6821b0..d040fbe 100644
--- a/app/assets/stylesheets/common/admin/admin_base.scss
+++ b/app/assets/stylesheets/common/admin/admin_base.scss
@@ -204,11 +204,8 @@ $mobile-breakpoint: 700px;
       font-size: $font-0;
       width: 50%;
     }
-    .extra-options {
+    .reseed {
       float: right;
-      input[type="checkbox"] {
-        margin-right: 0.5em;
-      }
     }
   }
   .text-highlight {
diff --git a/app/assets/stylesheets/common/admin/customize.scss b/app/assets/stylesheets/common/admin/customize.scss
index fbd4e40..a5f6b99 100644
--- a/app/assets/stylesheets/common/admin/customize.scss
+++ b/app/assets/stylesheets/common/admin/customize.scss
@@ -781,3 +781,15 @@
     }
   }
 }
+
+.reseed-modal {
+  .options-group-title {
+    font-size: $font-up-2;
+    font-weight: bold;
+    margin: 8px 0;
+  }
+
+  .option {
+    margin-left: 1em;
+  }
+}
diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rb
index 1cd37e3..46998cd 100644
--- a/app/controllers/admin/site_texts_controller.rb
+++ b/app/controllers/admin/site_texts_controller.rb
@@ -78,6 +78,31 @@ class Admin::SiteTextsController < Admin::AdminController
     render_serialized(site_text, SiteTextSerializer, root: 'site_text', rest_serializer: true)
   end
 
+  def get_reseed_options
+    render_json_dump(
+      categories: SeedData::Categories.with_default_locale.reseed_options,
+      topics: SeedData::Topics.with_default_locale.reseed_options
+    )
+  end
+
+  def reseed
+    hijack do
+      if params[:category_ids].present?
+        SeedData::Categories.with_default_locale.update(
+          site_setting_names: params[:category_ids]
+        )
+      end
+
+      if params[:topic_ids].present?
+        SeedData::Topics.with_default_locale.update(
+          site_setting_names: params[:topic_ids]
+        )
+      end
+
+      render json: success_json
+    end
+  end
+
   protected
 
   def record_for(k, value = nil)
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 37c711e..765a775 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4227,6 +4227,17 @@ en:
           add: "Add"
           filter: "Search (URL or External URL)"
 
+      reseed:
+        action:
+          label: "Reseed…"
+          title: "Update content created by Discourse with latest translations"
+
+        modal:
+          title: "Reseed"
+          subtitle: "Update seeded categories and topics with latest translations"
+          categories: "Categories"
+          topics: "Topics"
+
   wizard_js:
     wizard:
       done: "Done"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 28a20a7..b1724d1 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -578,6 +578,8 @@ en:
 
       [trust]: https://blog.discourse.org/2018/06/understanding-discourse-trust-levels/
 
+  admin_quick_start_title: "READ ME FIRST: Admin Quick Start Guide"
+
   category:
     topic_prefix: "About the %{category} category"
     replace_paragraph: "(Replace this first paragraph with a brief description of your new category. This guidance will appear in the category selection area, so try to keep it below 200 characters.)"
@@ -1266,7 +1268,7 @@ en:
   site_settings:

[... diff too long, it was truncated ...]

GitHub sha: 3fd04df7

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: