Skip to content

Commit 5617850

Browse files
committed
Support image descriptions for Basil Commission images
1 parent c052a6c commit 5617850

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

app/controllers/basil_controller.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,24 @@ def delete
836836
end
837837
end
838838

839+
def update_commission
840+
@commission = BasilCommission.find_by(
841+
id: params[:id],
842+
user: current_user
843+
)
844+
845+
if @commission.nil?
846+
render json: { error: "Commission not found" }, status: :not_found
847+
return
848+
end
849+
850+
if @commission.update(update_commission_params)
851+
render json: { success: true }, status: 200
852+
else
853+
render json: { error: @commission.errors.full_messages }, status: :unprocessable_entity
854+
end
855+
end
856+
839857
private
840858

841859
# Cache user content for Basil without universe filtering
@@ -862,4 +880,8 @@ def commission_params
862880
def jam_params
863881
params.require(:commission).permit(:name, :age, features: [])
864882
end
883+
884+
def update_commission_params
885+
params.require(:basil_commission).permit(:notes)
886+
end
865887
end

app/views/content/edit/_gallery_panel.html.erb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@
113113
<% end %>
114114
</div>
115115
<div class="p-3 border-t border-gray-100 dark:border-gray-700">
116-
<span class="text-xs text-purple-600 dark:text-purple-400 font-medium">Generated with Basil</span>
116+
<div class="mb-2 flex items-center justify-between">
117+
<span class="text-xs text-purple-600 dark:text-purple-400 font-medium">Generated with Basil</span>
118+
<% if image_data.image.attached? %>
119+
<span class="text-xs text-gray-500">
120+
<%= Filesize.from("#{image_data.image.byte_size}B").to_f('KB').round(2) %> KB
121+
</span>
122+
<% end %>
123+
</div>
124+
<textarea class="w-full text-sm p-2 border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-blue-500 focus:border-blue-500 js-image-notes" rows="2" placeholder="Add descriptions, creation date, or notes..." data-image-id="<%= image_id %>"><%= image_data.notes %></textarea>
125+
<div class="text-right mt-1">
126+
<button class="btn-small text-xs px-2 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded js-save-image-notes" style="display: none;">Save Notes</button>
127+
</div>
117128
</div>
118129

119130
<!-- Pin button -->
@@ -347,6 +358,8 @@ function initializeGalleryEvents() {
347358
// Handle notes save
348359
function handleNotesSave(textarea, button) {
349360
var imageId = textarea.getAttribute('data-image-id');
361+
var imageItem = textarea.closest('.gallery-sortable-item');
362+
var imageType = imageItem ? imageItem.getAttribute('data-image-type') : 'image_upload';
350363
var notes = textarea.value;
351364

352365
if (button && button.classList.contains('processing')) return;
@@ -361,15 +374,23 @@ function handleNotesSave(textarea, button) {
361374
return;
362375
}
363376

364-
fetch('/image_uploads/' + imageId, {
377+
var endpointUrl = '/image_uploads/' + imageId;
378+
var payload = { image_upload: { notes: notes } };
379+
380+
if (imageType === 'basil_commission') {
381+
endpointUrl = '/ai/basil/commission/' + imageId;
382+
payload = { basil_commission: { notes: notes } };
383+
}
384+
385+
fetch(endpointUrl, {
365386
method: 'PATCH',
366387
headers: {
367388
'X-Requested-With': 'XMLHttpRequest',
368389
'X-CSRF-Token': csrfToken.content,
369390
'Content-Type': 'application/json',
370391
'Accept': 'application/json'
371392
},
372-
body: JSON.stringify({ image_upload: { notes: notes } }),
393+
body: JSON.stringify(payload),
373394
credentials: 'same-origin'
374395
})
375396
.then(response => {

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
post '/:id/save', to: 'basil#save', as: :basil_save
3737
delete '/:id/delete', to: 'basil#delete', as: :basil_delete
3838
get '/commission/:jobid', to: 'basil#commission_info', as: :basil_commission_info
39+
patch '/commission/:id', to: 'basil#update_commission', as: :basil_commission_update
3940

4041
# Landing pages
4142
get '/jam', to: 'basil#jam', as: :basil_jam
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddNotesToBasilCommissions < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :basil_commissions, :notes, :text
4+
end
5+
end

db/schema.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2026_03_21_082539) do
13+
ActiveRecord::Schema.define(version: 2026_04_01_171734) do
1414

1515
create_table "active_storage_attachments", force: :cascade do |t|
1616
t.string "name", null: false
@@ -204,6 +204,7 @@
204204
t.integer "basil_version", default: 2
205205
t.boolean "pinned", default: false
206206
t.integer "position"
207+
t.text "notes"
207208
t.index ["entity_type", "entity_id", "pinned"], name: "index_basil_commissions_on_entity_pinned"
208209
t.index ["entity_type", "entity_id", "position"], name: "index_basil_commissions_on_entity_position"
209210
t.index ["entity_type", "entity_id", "saved_at"], name: "basil_commissions_ees"
@@ -458,6 +459,18 @@
458459
t.index ["user_id"], name: "index_character_magics_on_user_id"
459460
end
460461

462+
create_table "character_system_chats", force: :cascade do |t|
463+
t.integer "character_id"
464+
t.integer "user_id"
465+
t.string "uid"
466+
t.json "messages", default: []
467+
t.datetime "created_at", precision: 6, null: false
468+
t.datetime "updated_at", precision: 6, null: false
469+
t.index ["character_id"], name: "index_character_system_chats_on_character_id"
470+
t.index ["uid"], name: "index_character_system_chats_on_uid", unique: true
471+
t.index ["user_id"], name: "index_character_system_chats_on_user_id"
472+
end
473+
461474
create_table "character_technologies", force: :cascade do |t|
462475
t.integer "user_id"
463476
t.integer "character_id"

0 commit comments

Comments
 (0)