Class: Databasium::RecordsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Databasium::RecordsController
- Includes:
- ActionView::RecordIdentifier, Pagy::Method
- Defined in:
- app/controllers/databasium/records_controller.rb
Instance Method Summary collapse
- #bulk_destroy ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
- #records ⇒ Object
- #sidebar ⇒ Object
- #update ⇒ Object
Instance Method Details
#bulk_destroy ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/databasium/records_controller.rb', line 59 def bulk_destroy deleted_records = @record_service.bulk_destroy(params[:ids]) unless deleted_records raise ActiveRecord::RecordInvalid, deleted_records.errors..join(", ") end doms_ids = deleted_records.map { |record| dom_id(record) } render turbo_stream: doms_ids.flat_map { |dom_id| [ turbo_stream.remove(dom_id), turbo_stream.remove("record-tab-#{dom_id}"), turbo_stream.remove("record-form-#{dom_id}") ] } end |
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/databasium/records_controller.rb', line 11 def create new_record = @record_service.create_new(attributes: model_columns_params) raise ActiveRecord::RecordInvalid, new_record.errors..join(", ") unless new_record render turbo_stream: [ turbo_stream.append( "records_body", Components::Databasium::Records::Table::Row.new( record: new_record, turbo_frame: "records_list" ) ), turbo_stream.remove("suggestion") ] end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/databasium/records_controller.rb', line 7 def index render Views::Databasium::Records::Index.new end |
#records ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/databasium/records_controller.rb', line 27 def records @context = records_context pagy, records = pagy( @record_service.filter_records(filter_params), limit: params[:limit].presence || 10, root_key: "records" ) if foreign_records_frame?(@context[:turbo_frame]) render_foreign_records_table else respond_to do |format| format.html { render_records_table(records: records, pagy: pagy) } format.turbo_stream { render_records_table_turbo_stream(records: records, pagy: pagy) } end end end |
#sidebar ⇒ Object
77 78 79 80 81 |
# File 'app/controllers/databasium/records_controller.rb', line 77 def @pagy_tables, @tables = pagy(@schema_service.get_tables(params[:search]), limit: 7, root_key: "tables") render Components::Databasium::SearchResults::Tables.new(tables: @tables, pagy: @pagy_tables) end |
#update ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/databasium/records_controller.rb', line 46 def update record = @record_service.update_by_id(params[:id], attributes: model_columns_params) raise ActiveRecord::RecordInvalid, record.errors..join(", ") unless record render turbo_stream: turbo_stream.replace( dom_id(record), Components::Databasium::Records::Table::Row.new( record: record, turbo_frame: "records_list" ) ) end |