Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scale factor field to models #557

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ def bulk_update

def bulk_update_params
params.permit(
:scale_factor,
:creator_id,
:add_tags,
:remove_tags
)
).compact_blank
end

def model_params
params.require(:model).permit(
:preview_file_id,
:creator_id,
:name,
:scale_factor,
:tags,
links_attributes: [:id, :url, :_destroy]
)
Expand Down
5 changes: 5 additions & 0 deletions app/views/models/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<%= form.text_field :name, class: "form-control col-auto" %>
</div>

<div class="row mb-3 input-group">
<%= form.label :scale_factor, class: "col-sm-2 col-form-label" %>
<%= form.number_field :scale_factor, class: "form-control col-auto" %>
</div>

<div class="row mb-3 input-group">
<%= form.label :preview_file, class: "col-sm-2 col-form-label" %>
<div class='col-sm-10 ps-0'>
Expand Down
7 changes: 7 additions & 0 deletions app/views/models/bulk_edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
<tr>
<th><input type="checkbox" aria-label="Select All" value="0" name="bulk-select-all"></th>
<th>Name</th>
<th>Scale Factor</th>
<th>Tags</th>
<th>Creator</th>
</tr>
<% @models.each do |model| %>
<tr>
<td><%= form.check_box "models[#{model.id}]", { data: { bulk_item: "#{model.id}"}}%></td>
<td><%= link_to model.name, [@library, model], title: model.path %></td>
<td><%= number_to_percentage model.scale_factor, strip_insignificant_zeros: true %></td>
<td><%= render partial: 'tag', collection: model.tags, locals: {selected: nil, model_id: model.id } %></td>
<td><%= link_to model.creator.name, model.creator if model.creator %></td>
</tr>
Expand All @@ -26,6 +28,11 @@

<h3>Select changes to make:</h3>

<div class="row mb-3 input-group">
<%= form.label :scale_factor, class: "col-sm-2 col-form-label" %>
<%= form.number_field :scale_factor, class: "form-control col-auto" %>
</div>

<div class="row mb-3 input-group">
<%= form.label :creator_id, class: "col-sm-2 col-form-label" %>
<%= form.collection_select :creator_id, @creators, :id, :name, {include_blank: true}, {class: "form-control col-auto form-select"} %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/models/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<p>
Path: <code><%= @model.path %></code>
</p>
<p>
Scale: <%= number_to_percentage @model.scale_factor, strip_insignificant_zeros: true %>
</p>
<% end %>

<%= card :secondary, "Actions" do %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220626152444_add_scale_factor_to_models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddScaleFactorToModels < ActiveRecord::Migration[7.0]
def change
add_column :models, :scale_factor, :decimal, null: false, default: 100.0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.