diff --git a/javascripts/discourse/api-initializers/table-builder.js b/javascripts/discourse/api-initializers/table-builder.js index e0329c0..523518d 100644 --- a/javascripts/discourse/api-initializers/table-builder.js +++ b/javascripts/discourse/api-initializers/table-builder.js @@ -1,16 +1,20 @@ import { apiInitializer } from "discourse/lib/api"; +import SpreadsheetEditor from "../components/spreadsheet-editor"; import { action } from "@ember/object"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; export default apiInitializer("0.11.1", (api) => { api.modifyClass("controller:composer", { pluginId: "discourse-table-builder", + modal: service(), @action showTableBuilder() { - showModal("insert-table-modal").setProperties({ - toolbarEvent: this.toolbarEvent, - tableTokens: null, + this.modal.show(SpreadsheetEditor, { + model: { + toolbarEvent: this.toolbarEvent, + tableTokens: null, + }, }); }, }); diff --git a/javascripts/discourse/api-initializers/table-editor.js b/javascripts/discourse/api-initializers/table-editor.js index 1481576..9f187ef 100644 --- a/javascripts/discourse/api-initializers/table-editor.js +++ b/javascripts/discourse/api-initializers/table-editor.js @@ -1,5 +1,5 @@ import { apiInitializer } from "discourse/lib/api"; -import showModal from "discourse/lib/show-modal"; +import SpreadsheetEditor from "../components/spreadsheet-editor"; import { schedule } from "@ember/runloop"; import I18n from "I18n"; import { iconNode } from "discourse-common/lib/icon-library"; @@ -10,6 +10,8 @@ import { parseAsync } from "discourse/lib/text"; import { tokenRange } from "../../discourse-table-builder/lib/utilities"; export default apiInitializer("0.11.1", (api) => { + const modal = api.container.lookup("service:modal"); + function createButton() { const openPopupBtn = document.createElement("button"); openPopupBtn.classList.add( @@ -39,11 +41,12 @@ export default apiInitializer("0.11.1", (api) => { const allTables = tokenRange(tokens, "table_open", "table_close"); const tableTokens = allTables[tableIndex]; - showModal("insert-table-modal", { - model: post, - }).setProperties({ - tableIndex, - tableTokens, + modal.show(SpreadsheetEditor, { + model: { + post, + tableIndex, + tableTokens, + }, }); }) ) diff --git a/javascripts/discourse/components/spreadsheet-editor.hbs b/javascripts/discourse/components/spreadsheet-editor.hbs new file mode 100644 index 0000000..881f3c2 --- /dev/null +++ b/javascripts/discourse/components/spreadsheet-editor.hbs @@ -0,0 +1,74 @@ + + <:body> + {{#if this.isEditingTable}} +
+ + {{#if this.showEditReason}} + + {{/if}} +
+ {{/if}} + + +
+
+ + + <:footer> +
+ + +
+ +
+ + +
    +

    {{theme-i18n "discourse_table_builder.modal.help.title"}}

    +
  • + + {{theme-i18n "discourse_table_builder.modal.help.enter_key"}} + + {{theme-i18n "discourse_table_builder.modal.help.new_row"}} +
  • +
  • + + {{theme-i18n "discourse_table_builder.modal.help.tab_key"}} + + {{theme-i18n "discourse_table_builder.modal.help.new_col"}} +
  • +
  • {{theme-i18n "discourse_table_builder.modal.help.options"}}
  • +
+
+
+ +
\ No newline at end of file diff --git a/javascripts/discourse/components/spreadsheet-editor.js b/javascripts/discourse/components/spreadsheet-editor.js index d73111f..13d78c7 100644 --- a/javascripts/discourse/components/spreadsheet-editor.js +++ b/javascripts/discourse/components/spreadsheet-editor.js @@ -19,7 +19,7 @@ export default class SpreadsheetEditor extends Component { @tracked loading = null; spreadsheet = null; defaultColWidth = 150; - isEditingTable = !!this.args.tableTokens; + isEditingTable = !!this.args.model.tableTokens; // Getters: get modalAttributes() { @@ -50,7 +50,7 @@ export default class SpreadsheetEditor extends Component { schedule("afterRender", () => { this.loadLibraries().then(() => { if (this.isEditingTable) { - this.buildPopulatedTable(this.args.tableTokens); + this.buildPopulatedTable(this.args.model.tableTokens); } else { this.buildNewTable(); } @@ -67,11 +67,6 @@ export default class SpreadsheetEditor extends Component { } } - @action - cancelTableInsertion() { - this.args.triggerModalClose(); - } - @action insertTable() { const updatedHeaders = this.spreadsheet.getHeaders().split(","); // keys @@ -79,8 +74,8 @@ export default class SpreadsheetEditor extends Component { const markdownTable = this.buildTableMarkdown(updatedHeaders, updatedData); if (!this.isEditingTable) { - this.args.toolbarEvent.addText(markdownTable); - return this.args.triggerModalClose(); + this.args.model.toolbarEvent.addText(markdownTable); + return this.args.closeModal(); } else { return this.updateTable(markdownTable); } @@ -205,14 +200,14 @@ export default class SpreadsheetEditor extends Component { } updateTable(markdownTable) { - const tableIndex = this.args.tableIndex; - const postId = this.args.model.id; + const tableIndex = this.args.model.tableIndex; + const postId = this.args.model.post.id; const newRaw = markdownTable; const editReason = this.editReason || I18n.t(themePrefix("discourse_table_builder.edit.default_edit_reason")); - const raw = this.args.model.raw; + const raw = this.args.model.post.raw; const newPostRaw = this.buildUpdatedPost(tableIndex, raw, newRaw); return this.sendTableUpdate(postId, newPostRaw, editReason); @@ -230,7 +225,7 @@ export default class SpreadsheetEditor extends Component { }) .catch(popupAjaxError) .finally(() => { - this.args.triggerModalClose(); + this.args.closeModal(); }); } diff --git a/javascripts/discourse/controllers/insert-table-modal.js b/javascripts/discourse/controllers/insert-table-modal.js deleted file mode 100644 index cd53603..0000000 --- a/javascripts/discourse/controllers/insert-table-modal.js +++ /dev/null @@ -1,9 +0,0 @@ -import Controller from "@ember/controller"; -import { action } from "@ember/object"; - -export default class extends Controller { - @action - closeEditModal() { - this.send("closeModal"); - } -} diff --git a/javascripts/discourse/templates/components/spreadsheet-editor.hbs b/javascripts/discourse/templates/components/spreadsheet-editor.hbs deleted file mode 100644 index 4333dc6..0000000 --- a/javascripts/discourse/templates/components/spreadsheet-editor.hbs +++ /dev/null @@ -1,68 +0,0 @@ - - {{#if this.isEditingTable}} -
- - {{#if showEditReason}} - - {{/if}} -
- {{/if}} - - -
-
-
- - \ No newline at end of file diff --git a/javascripts/discourse/templates/modal/insert-table-modal.hbs b/javascripts/discourse/templates/modal/insert-table-modal.hbs deleted file mode 100644 index 4eec8c6..0000000 --- a/javascripts/discourse/templates/modal/insert-table-modal.hbs +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/scss/modal/insert-table-modal.scss b/scss/modal/insert-table-modal.scss index c579e5d..2cf6dd7 100644 --- a/scss/modal/insert-table-modal.scss +++ b/scss/modal/insert-table-modal.scss @@ -18,7 +18,7 @@ } } -.insert-table-modal-modal { +.insert-table-modal { display: flex; flex-direction: column; align-items: flex-start;