diff --git a/Gemfile b/Gemfile index fa55582d..dcd9ffd2 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem "tzinfo-data", platforms: %i[ windows jruby ] gem "bootsnap", require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] -# gem "image_processing", "~> 1.2" +gem "image_processing", "~> 1.2" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem @@ -72,3 +72,5 @@ end gem "devise", "~> 4.9" gem "pry-rails", "~> 0.3.9" + +gem "actiontext", "~> 7.1" diff --git a/Gemfile.lock b/Gemfile.lock index f71f1806..e3f6a2e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,10 +109,14 @@ GEM warden (~> 1.2.3) drb (2.2.1) erubi (1.12.0) + ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.4) concurrent-ruby (~> 1.0) + image_processing (1.12.2) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) @@ -135,6 +139,7 @@ GEM marcel (1.0.4) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.12.0) mini_mime (1.1.5) minitest (5.22.2) msgpack (1.7.2) @@ -220,6 +225,8 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) + ruby-vips (2.2.1) + ffi (~> 1.12) rubyzip (2.3.2) selenium-webdriver (4.18.1) base64 (~> 0.2) @@ -287,10 +294,12 @@ PLATFORMS x86_64-linux DEPENDENCIES + actiontext (~> 7.1) bootsnap capybara debug devise (~> 4.9) + image_processing (~> 1.2) importmap-rails jbuilder pry-rails (~> 0.3.9) diff --git a/app/assets/stylesheets/actiontext.css b/app/assets/stylesheets/actiontext.css new file mode 100644 index 00000000..3cfcb2b7 --- /dev/null +++ b/app/assets/stylesheets/actiontext.css @@ -0,0 +1,31 @@ +/* + * Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and + * the trix-editor content (whether displayed or under editing). Feel free to incorporate this + * inclusion directly in any other asset bundle and remove this file. + * + *= require trix +*/ + +/* + * We need to override trix.css’s image gallery styles to accommodate the + * element we wrap around attachments. Otherwise, + * images in galleries will be squished by the max-width: 33%; rule. +*/ +.trix-content .attachment-gallery > action-text-attachment, +.trix-content .attachment-gallery > .attachment { + flex: 1 0 33%; + padding: 0 0.5em; + max-width: 33%; +} + +.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment, +.trix-content .attachment-gallery.attachment-gallery--2 > .attachment, .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment, +.trix-content .attachment-gallery.attachment-gallery--4 > .attachment { + flex-basis: 50%; + max-width: 50%; +} + +.trix-content action-text-attachment .attachment { + padding: 0 !important; + max-width: 100% !important; +} diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index 8666d2f3..ac054694 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -11,3 +11,4 @@ } */ +@import 'actiontext.css'; \ No newline at end of file diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index c5a28f20..0e1ba441 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -8,6 +8,13 @@ def index # GET /conversations/1 or /conversations/1.json def show + respond_to do |format| + format.turbo_stream { render turbo_stream: turbo_stream.replace("conversation", partial: "conversation") } + format.html do + @conversations = Conversation.all + render :index + end + end end # GET /conversations/new diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb new file mode 100644 index 00000000..6232f828 --- /dev/null +++ b/app/controllers/messages_controller.rb @@ -0,0 +1,29 @@ +class MessagesController < ApplicationController + before_action :set_message + before_action :set_conversation + + def create + @message = Message.new(message_params) + @message.user = current_user + @message.save! + end + + def destroy + @message.destroy! + redirect_to conversation_path(@conversation) + end + + private + + def message_params + params.require(:message).permit(:content) + end + + def set_message + @message = Message.find(params[:id]) + end + + def set_conversation + @conversation = Conversation.find(@message.conversation_id) + end +end diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb new file mode 100644 index 00000000..f1bca9f6 --- /dev/null +++ b/app/helpers/messages_helper.rb @@ -0,0 +1,2 @@ +module MessagesHelper +end diff --git a/app/javascript/application.js b/app/javascript/application.js index 0d7b4940..9ae56c5c 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,3 +1,6 @@ // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" + +import "trix" +import "@rails/actiontext" diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 81fd4a74..68f313d0 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -1,5 +1,5 @@ class Conversation < ApplicationRecord belongs_to :user belongs_to :model_config - has_many :messages + has_many :messages, dependent: :destroy end diff --git a/app/models/message.rb b/app/models/message.rb index 2bef1aad..d007157d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,7 @@ class Message < ApplicationRecord belongs_to :user belongs_to :conversation + + # has_rich_text :content end + \ No newline at end of file diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb new file mode 100644 index 00000000..49ba357d --- /dev/null +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -0,0 +1,14 @@ +
attachment--<%= blob.filename.extension %>"> + <% if blob.representable? %> + <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> + <% end %> + +
+ <% if caption = blob.try(:caption) %> + <%= caption %> + <% else %> + <%= blob.filename %> + <%= number_to_human_size blob.byte_size %> + <% end %> +
+
diff --git a/app/views/conversations/_conversation.html.erb b/app/views/conversations/_conversation.html.erb index 08837744..f794851b 100644 --- a/app/views/conversations/_conversation.html.erb +++ b/app/views/conversations/_conversation.html.erb @@ -1,22 +1,16 @@ -
-

- User: - <%= conversation.user_id %> -

+
+
+
<%= @conversation.title %>
+
Model: <%= @conversation.model_config.name %>
+
-

- Title: - <%= conversation.model_config_id %> -

- -

- Title: - <%= conversation.title %> -

+
+ <%= render @conversation.messages %> +
<% if action_name != "show" %> - <%= link_to "Show this conversation", conversation, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Edit this conversation", edit_conversation_path(conversation), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Show this conversation", @conversation, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> + <%= link_to "Edit this conversation", edit_conversation_path(@conversation), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
<% end %>
diff --git a/app/views/conversations/_conversation_list.html.erb b/app/views/conversations/_conversation_list.html.erb index 6ef3aeed..917f54bf 100644 --- a/app/views/conversations/_conversation_list.html.erb +++ b/app/views/conversations/_conversation_list.html.erb @@ -1,4 +1,4 @@ -
Conversations
+
<%= link_to "Conan", root_path %>
<% conversations.each do |conversation| %> <%= link_to "New conversation", new_conversation_path, class: "rounded-lg py-1 px-3 my-2 text-center bg-blue-600 text-white block font-medium" %> <%= render "conversation_list_item", conversation: %> diff --git a/app/views/conversations/_conversation_list_item.html.erb b/app/views/conversations/_conversation_list_item.html.erb index eda819f5..d80dce9e 100644 --- a/app/views/conversations/_conversation_list_item.html.erb +++ b/app/views/conversations/_conversation_list_item.html.erb @@ -1,3 +1,3 @@
- <%= link_to conversation.title, conversation %> + <%= link_to conversation.title, conversation, data: { turbo_stream: true } %>
\ No newline at end of file diff --git a/app/views/conversations/_no_conversation.html.erb b/app/views/conversations/_no_conversation.html.erb index 0f120ab3..fdacf78a 100644 --- a/app/views/conversations/_no_conversation.html.erb +++ b/app/views/conversations/_no_conversation.html.erb @@ -1,7 +1,5 @@ -
-
- <%= image_tag "conan_ready.svg" %> -
Conan
-
the Librarian
-
+
+ <%= image_tag "conan_ready.svg" %> +
Conan
+
the Librarian
diff --git a/app/views/conversations/index.html.erb b/app/views/conversations/index.html.erb index b1402af1..6a054b7d 100644 --- a/app/views/conversations/index.html.erb +++ b/app/views/conversations/index.html.erb @@ -8,8 +8,17 @@ <%= render "conversation_list", conversations: @conversations %>
-
- <%= render "no_conversation" %> +
+ <%= turbo_stream_from "conversations" %> +
+ <% if @conversation %> + <%= render @conversation %> + <% else %> +
+ <%= render "no_conversation" %> +
+ <% end %> +
diff --git a/app/views/layouts/action_text/contents/_content.html.erb b/app/views/layouts/action_text/contents/_content.html.erb new file mode 100644 index 00000000..9e3c0d0d --- /dev/null +++ b/app/views/layouts/action_text/contents/_content.html.erb @@ -0,0 +1,3 @@ +
+ <%= yield -%> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 052e9bd6..d8cc55f0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,6 +17,6 @@
<%= yield %> - +
diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb new file mode 100644 index 00000000..53989188 --- /dev/null +++ b/app/views/messages/_form.html.erb @@ -0,0 +1,15 @@ +<%= form_with url: messages_path, html: { id: "message_form", class: "mt-3" } do |f| %> +
+
+ <%= f.text_area :message, + class: "form-control w-100", + placeholder: "your message", + autofocus: true, + data: { controller: "submit", "submit-target": "input" } + %> +
+
+ <%= f.submit "Send"%> +
+
+<% end %> diff --git a/app/views/messages/_message.html.erb b/app/views/messages/_message.html.erb new file mode 100644 index 00000000..4f7e699c --- /dev/null +++ b/app/views/messages/_message.html.erb @@ -0,0 +1,6 @@ +
+ <%= content_tag :div, id: dom_id(message) do %> +

<%= message.content %>

+

<%= message.user.email %>

+ <% end %> +
diff --git a/config/importmap.rb b/config/importmap.rb index 909dfc54..6ed7577a 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -5,3 +5,5 @@ pin "@hotwired/stimulus", to: "stimulus.min.js" pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" pin_all_from "app/javascript/controllers", under: "controllers" +pin "trix" +pin "@rails/actiontext", to: "actiontext.esm.js" diff --git a/config/routes.rb b/config/routes.rb index 3cbc28b9..9d9c5689 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do - resources :conversations + resources :conversations do + resources :messages, only: [:create, :destroy] + end + devise_for :users # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html diff --git a/db/migrate/20240310210311_create_active_storage_tables.active_storage.rb b/db/migrate/20240310210311_create_active_storage_tables.active_storage.rb new file mode 100644 index 00000000..e4706aa2 --- /dev/null +++ b/db/migrate/20240310210311_create_active_storage_tables.active_storage.rb @@ -0,0 +1,57 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[7.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :active_storage_blobs, id: primary_key_type do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :key ], unique: true + end + + create_table :active_storage_attachments, id: primary_key_type do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + t.references :blob, null: false, type: foreign_key_type + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records, id: primary_key_type do |t| + t.belongs_to :blob, null: false, index: false, type: foreign_key_type + t.string :variation_digest, null: false + + t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/migrate/20240310210312_create_action_text_tables.action_text.rb b/db/migrate/20240310210312_create_action_text_tables.action_text.rb new file mode 100644 index 00000000..1be48d70 --- /dev/null +++ b/db/migrate/20240310210312_create_action_text_tables.action_text.rb @@ -0,0 +1,26 @@ +# This migration comes from action_text (originally 20180528164100) +class CreateActionTextTables < ActiveRecord::Migration[6.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :action_text_rich_texts, id: primary_key_type do |t| + t.string :name, null: false + t.text :body, size: :long + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + + t.timestamps + + t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/schema.rb b/db/schema.rb index 445668cc..3104d409 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,45 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_03_09_212449) do +ActiveRecord::Schema[7.1].define(version: 2024_03_10_210312) do + create_table "action_text_rich_texts", force: :cascade do |t| + t.string "name", null: false + t.text "body" + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + + create_table "active_storage_attachments", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum" + t.datetime "created_at", null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + create_table "conversations", force: :cascade do |t| t.integer "user_id", null: false t.string "title" @@ -63,6 +101,8 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "conversations", "model_configs" add_foreign_key "conversations", "users" add_foreign_key "messages", "conversations" diff --git a/layout.css b/layout.css new file mode 100644 index 00000000..90c24c6b --- /dev/null +++ b/layout.css @@ -0,0 +1,23 @@ +:root { + --clr-dark: black; + --clr-light: white; + --clr-accent: red; +} + +*, +*::before, +*::after { + box-sizing: border-box; +} + +.item { + width: 150px; + height: 150px; + background-color: indigo; + padding: 1em; + font-weight: 600; + color: darkorange; + text-align: center; + border: 10px solid orange; + border-radius: 10px; +} diff --git a/layout.html b/layout.html new file mode 100644 index 00000000..9cde5854 --- /dev/null +++ b/layout.html @@ -0,0 +1,64 @@ + + + + + + +

Hello!

+
+
Beep
+
Boop
+
Blerp
+
+ + + diff --git a/reloader.sh b/reloader.sh new file mode 100755 index 00000000..737c9c54 --- /dev/null +++ b/reloader.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# htmlreload +# When an HTML or CSS file changes, reload any visible browser windows. +# Usage: +# +# htmlreload [ --browsername ] [ files ... ] +# +# If no files to watch are specified, all files (recursively) in the +# current working directory are monitored. (Note: this can take a long +# time to initially setup if you have a lot of files). +# +# An argument that begins with a dash is the browser to control. +# `htmlreload --chrom` will match both Chromium and Chrome. + +set -o errexit +set -o nounset + +browser="firefox" # Default browser name. (Technically "X11 Class") +keystroke="CTRL+R" # The key that tells the browser to reload. + +sendkey() { + echo "Sending $2 to $1..." + # Given an application name and a keystroke, + # type the key in all windows owned by that application. + xdotool search --all --onlyvisible --class "$1" \ + key --window %@ "$2" +} + +# You may specify the browser name after one or more dashes (e.g., --chromium) +if [[ "${1:-}" == -* ]]; then + browser="${1##*-}" + shift +fi + +# If no filenames given to watch, watch current working directory. +if [[ $# -eq 0 ]]; then + echo "Watching all files under `pwd`" + set - --recursive "`pwd`" #Added quotes for whitespace in path +fi + +inotifywait --monitor --event CLOSE_WRITE "$@" | while read; do + echo "$REPLY" + sendkey $browser $keystroke +done diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb new file mode 100644 index 00000000..d525b26a --- /dev/null +++ b/test/controllers/messages_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class MessagesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml new file mode 100644 index 00000000..8b371ea6 --- /dev/null +++ b/test/fixtures/action_text/rich_texts.yml @@ -0,0 +1,4 @@ +# one: +# record: name_of_fixture (ClassOfFixture) +# name: content +# body:

In a million stars!