diff --git a/app/assets/stylesheets/terminals.css b/app/assets/stylesheets/terminals.css index 890f1fd11..9ce1ea6ec 100644 --- a/app/assets/stylesheets/terminals.css +++ b/app/assets/stylesheets/terminals.css @@ -144,4 +144,15 @@ caret-color: var(--color-negative); color: var(--color-negative); } + + /* @TODO: Review these. */ + .terminal--output { + overflow: scroll; + max-height: 400px; + display: none; + + .terminal--showing-output & { + display: block; + } + } } diff --git a/app/javascript/controllers/terminal_controller.js b/app/javascript/controllers/terminal_controller.js index ca347f63d..ed34bda83 100644 --- a/app/javascript/controllers/terminal_controller.js +++ b/app/javascript/controllers/terminal_controller.js @@ -1,16 +1,15 @@ import { Controller } from "@hotwired/stimulus" import { HttpStatus } from "helpers/http_helpers" -import { delay, nextFrame } from "helpers/timing_helpers" import { marked } from "marked" export default class extends Controller { - static targets = [ "input", "form", "confirmation", "redirected" ] - static classes = [ "error", "confirmation", "help" ] + static targets = [ "input", "form", "output", "confirmation", "redirected" ] + static classes = [ "error", "confirmation", "help", "output" ] static values = { originalInput: String, waitingForConfirmation: Boolean, autoSubmitAfterRedirection: Boolean } connect() { if (this.waitingForConfirmationValue) { this.focus() } - if (this.autoSubmitAfterRedirectionValue) { this.submitAfterRedirection() } + if (this.autoSubmitAfterRedirectionValue) { this.#submitAfterRedirection() } } // Actions @@ -26,13 +25,13 @@ export default class extends Controller { event.preventDefault() event.stopPropagation() } else { - this.hideHelpMenu() + this.#hideHelpMenu() } } - hideHelpMenu() { - if (this.#showHelpCommandEntered) { this.#reset() } - this.element.classList.remove(this.helpClass) + hideMenus() { + this.#hideHelpMenu() + this.#hideOutput() } handleKeyPress(event) { @@ -46,12 +45,7 @@ export default class extends Controller { const response = event.detail.fetchResponse?.response if (event.detail.success) { - if (response.headers.get("Content-Type")?.includes("application/json")) { - response.json().then((responseJson) => { - this.element.querySelector("#chat-insight").innerHTML = marked.parse(responseJson.message) - }) - } - this.#reset() + this.#handleSuccessResponse(response) } else if (response) { this.#handleErrorResponse(response) } @@ -77,10 +71,24 @@ export default class extends Controller { this.element.classList.add(this.helpClass) } + #hideHelpMenu() { + if (this.#showHelpCommandEntered) { this.#reset() } + this.element.classList.remove(this.helpClass) + } + get #isHelpMenuOpened() { return this.element.classList.contains(this.helpClass) } + #handleSuccessResponse(response) { + if (response.headers.get("Content-Type")?.includes("application/json")) { + response.json().then((responseJson) => { + this.#showOutput(marked.parse(responseJson.message)) + }) + } + this.#reset() + } + async #handleErrorResponse(response) { const status = response.status @@ -145,9 +153,18 @@ export default class extends Controller { this.formTarget.requestSubmit() } - submitAfterRedirection() { + #submitAfterRedirection() { this.inputTarget.value = this.originalInputValue this.redirectedTarget.value = "redirected" this.formTarget.requestSubmit() } + + #showOutput(html) { + this.element.classList.add(this.outputClass) + this.outputTarget.innerHTML = html + } + + #hideOutput(html) { + this.element.classList.remove(this.outputClass) + } } diff --git a/app/models/card/searchable.rb b/app/models/card/searchable.rb index cacf7fd6d..b2de0c1c8 100644 --- a/app/models/card/searchable.rb +++ b/app/models/card/searchable.rb @@ -8,8 +8,8 @@ module Card::Searchable scope :mentioning, ->(query) do if query = sanitize_query_syntax(query) - cards = Card.search_similar(query).select(:id).to_sql - comments = Comment.search_similar(query).select(:id).to_sql + cards = Card.search(query).select(:id).to_sql + comments = Comment.search(query).select(:id).to_sql left_joins(:comments).where("cards.id in (#{cards}) or comments.id in (#{comments})").distinct else diff --git a/app/views/commands/_form.html.erb b/app/views/commands/_form.html.erb index 989bba4b9..75b69ab2e 100644 --- a/app/views/commands/_form.html.erb +++ b/app/views/commands/_form.html.erb @@ -4,7 +4,7 @@ data: { controller: "form", terminal_target: "form", - action: "turbo:submit-end->terminal#focus keydown.meta+k@document->terminal#focus keydown.enter->terminal#executeCommand keydown.esc->terminal#hideHelpMenu turbo:submit-end->terminal#handleCommandResponse" + action: "turbo:submit-end->terminal#focus keydown.meta+k@document->terminal#focus keydown.enter->terminal#executeCommand keydown.esc->terminal#hideMenus turbo:submit-end->terminal#handleCommandResponse" } do %> diff --git a/app/views/commands/_terminal.html.erb b/app/views/commands/_terminal.html.erb index 1d4c3480c..02639d079 100644 --- a/app/views/commands/_terminal.html.erb +++ b/app/views/commands/_terminal.html.erb @@ -6,9 +6,10 @@ terminal_error_class: "terminal--error", terminal_confirmation_class: "terminal--confirmation", terminal_help_class: "terminal--showing-help", + terminal_output_class: "terminal--showing-output", toggle_class_toggle_class: "terminal--open", turbo_permanent: true, - action: "keydown->terminal#handleKeyPress keydown->navigable-list#navigate focusin->navigable-list#select keydown.esc->toggle-class#remove:stop keydown.esc->terminal#focus keydown.esc->navigable-list#selectLast keydown.esc@document->terminal#hideHelpMenu" } do %> + action: "keydown->terminal#handleKeyPress keydown->navigable-list#navigate focusin->navigable-list#select keydown.esc->toggle-class#remove:stop keydown.esc->terminal#focus keydown.esc->navigable-list#selectLast keydown.esc@document->terminal#hideMenus" } do %> <%= turbo_frame_tag :recent_commands, src: commands_path, refresh: "morph" %> <%= render "commands/form" %> diff --git a/app/views/commands/index.html.erb b/app/views/commands/index.html.erb index 2dc10906c..dea89369a 100644 --- a/app/views/commands/index.html.erb +++ b/app/views/commands/index.html.erb @@ -2,7 +2,6 @@ -

-  

+
<%= render "commands/help" %> <% end %>