-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Progress Holder, TurboStream, Loading, Preview and Image Genera…
…tion
- Loading branch information
1 parent
94e16b5
commit 1743307
Showing
14 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# == Schema Information | ||
# | ||
# Table name: progress_holders | ||
# | ||
# id :bigint not null, primary key | ||
# task_ref :string | ||
# live_preview_id :integer | ||
# user_id :bigint not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class ProgressHolder < ApplicationRecord | ||
include ActionView::RecordIdentifier | ||
belongs_to :user | ||
|
||
def broadcast_updated(user_id, task_ref, original_prompt, style_template, result) | ||
progress_holder = ProgressHolder.find_or_create_by(task_ref:) do |ph| | ||
ph.user_id = user_id | ||
ph.live_preview_id = result.progress.positive? ? result.id_live_preview : -1 | ||
end | ||
|
||
user = User.find(user_id) | ||
|
||
# Broadcast the updated progress to the user | ||
broadcast_update_to( | ||
"#{dom_id(user)}_main_image", | ||
partial: "txt2_imgs/loading_progress", | ||
locals: { | ||
scroll_to: true, | ||
original_prompt:, | ||
style_template:, | ||
result: JSON.parse(result.to_json) | ||
}, | ||
target: "image_maker" | ||
) | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<turbo-frame id="image_maker"> | ||
<div class="container"> | ||
<div class="spinner-border mt-3" style="width: 5rem; height: 5rem;" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</div> | ||
<br> | ||
<div class="m-3 p-3"> | ||
<% progress = result['progress'].present? ? (result['progress'].to_f * 100) : 0 %> | ||
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="<%=progress%>" aria-valuemin="0" aria-valuemax="100"> | ||
<div class="progress-bar" style="width: <%=progress%>%"></div> | ||
</div> | ||
</div> | ||
<div class="m-3 p-3"> | ||
<p>ETA: <%= result['eta'].to_f %> seconds</p> | ||
</div> | ||
<div class="m-3 p-3"> | ||
<% if result['live_preview'].present? && !result['completed'] != 'true' %> | ||
<%= image_tag "#{result['live_preview']}", alt: "#{original_prompt}", class: 'img-fluid thumbnail' %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</turbo-frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<turbo-frame class="image-maker" action="update"> | ||
We will make your image in a moment. Please wait... | ||
</turbo-frame> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateProgressHolders < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :progress_holders do |t| | ||
t.string :task_ref | ||
t.integer :live_preview_id | ||
t.references :user, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
add_index :progress_holders, :task_ref, unique: true | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
task_ref: MyString | ||
live_preview_id: 1 | ||
user: one | ||
|
||
two: | ||
task_ref: MyString | ||
live_preview_id: 1 | ||
user: two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# == Schema Information | ||
# | ||
# Table name: progress_holders | ||
# | ||
# id :bigint not null, primary key | ||
# task_ref :string | ||
# live_preview_id :integer | ||
# user_id :bigint not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
require "test_helper" | ||
|
||
class ProgressHolderTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters