diff --git a/app/assets/javascripts/spina/controllers/page_select_controller.js b/app/assets/javascripts/spina/controllers/page_select_controller.js index 179f0b25c..25f0a0769 100644 --- a/app/assets/javascripts/spina/controllers/page_select_controller.js +++ b/app/assets/javascripts/spina/controllers/page_select_controller.js @@ -1,38 +1,3 @@ -import { Controller } from "@hotwired/stimulus" +import SelectController from 'controllers/select_controller' -export default class extends Controller { - - static get targets() { - return ['input', 'label', 'search'] - } - - connect() { - // Show placeholder if there is no page selected yet - if (this.labelTarget.querySelector("turbo-frame") == undefined) { - this.clear() - } - } - - select(event) { - let button = event.currentTarget - - this.inputTarget.value = button.dataset.id - this.labelTarget.innerText = button.dataset.title - } - - clear() { - this.inputTarget.value = "" - this.labelTarget.innerHTML = ` - - ${this.element.dataset.placeholder} - - ` - } - - autofocus() { - setTimeout(function() { - this.searchTarget.focus() - }.bind(this), 100) - } - -} \ No newline at end of file +export default class extends SelectController { } diff --git a/app/assets/javascripts/spina/controllers/select_controller.js b/app/assets/javascripts/spina/controllers/select_controller.js new file mode 100644 index 000000000..70053bd05 --- /dev/null +++ b/app/assets/javascripts/spina/controllers/select_controller.js @@ -0,0 +1,38 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + + static get targets() { + return ['input', 'label', 'search'] + } + + connect() { + // Show placeholder if there is no page selected yet + if (this.labelTarget.querySelector("turbo-frame") == undefined) { + this.clear() + } + } + + select(event) { + let button = event.currentTarget + + this.inputTarget.value = button.dataset.id + this.labelTarget.innerText = button.dataset.title + } + + clear() { + this.inputTarget.value = "" + this.labelTarget.innerHTML = ` + + ${this.element.dataset.placeholder} + + ` + } + + autofocus() { + setTimeout(function () { + this.searchTarget.focus() + }.bind(this), 100) + } + +} diff --git a/app/controllers/spina/admin/resource_select_options_controller.rb b/app/controllers/spina/admin/resource_select_options_controller.rb new file mode 100644 index 000000000..708108599 --- /dev/null +++ b/app/controllers/spina/admin/resource_select_options_controller.rb @@ -0,0 +1,20 @@ +module Spina + module Admin + class ResourceSelectOptionsController < AdminController + + def show + @resource = Resource.find(params[:id]) + end + + def index + end + + def search + @resources ||= Resource.all + @resources = @resources.where("name ILIKE :query OR label ILIKE :query", query: "%#{params[:search]}%").order(created_at: :desc).distinct.page(params[:page]).per(20) + render :index + end + + end + end +end diff --git a/app/models/spina/parts/resource_link.rb b/app/models/spina/parts/resource_link.rb new file mode 100644 index 000000000..9f1187dea --- /dev/null +++ b/app/models/spina/parts/resource_link.rb @@ -0,0 +1,13 @@ +module Spina + module Parts + class ResourceLink < Base + attr_json :resource_id, :integer, default: nil + + attr_accessor :options + + def content + ::Spina::Resource.find_by(id: resource_id) + end + end + end +end diff --git a/app/views/spina/admin/page_select_options/index.html.erb b/app/views/spina/admin/page_select_options/index.html.erb index 802b011fb..17a8b0f9d 100644 --- a/app/views/spina/admin/page_select_options/index.html.erb +++ b/app/views/spina/admin/page_select_options/index.html.erb @@ -1,12 +1,12 @@ <%= turbo_frame_tag "page_select_options_#{params[:object_id]}" do %> <% if params[:search].blank? %> - <% end %> - + <% @pages.each do |page| %> - <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/spina/admin/parts/page_links/_form.html.erb b/app/views/spina/admin/parts/page_links/_form.html.erb index b5c8633f7..800f7e81e 100644 --- a/app/views/spina/admin/parts/page_links/_form.html.erb +++ b/app/views/spina/admin/parts/page_links/_form.html.erb @@ -1,19 +1,16 @@
<%= f.object.hint %>
- -
" class="relative mt-1" data-reveal-away-value> - <%= f.hidden_field :page_id, data: {page_select_target: "input"} %> - - -