Skip to content

Commit

Permalink
Add active props to reaction types
Browse files Browse the repository at this point in the history
  • Loading branch information
luap42 committed Jul 11, 2021
1 parent 471907e commit 09fe5c7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/controllers/reactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def update
on_post_label: params[:reaction_type][:on_post_label],
color: params[:reaction_type][:color],
icon: params[:reaction_type][:icon],
requires_comment: params[:reaction_type][:requires_comment]
requires_comment: params[:reaction_type][:requires_comment],
active: params[:reaction_type][:active],
position: params[:reaction_type][:position]
render :edit
end

Expand All @@ -81,7 +83,9 @@ def create
on_post_label: params[:reaction_type][:on_post_label],
color: params[:reaction_type][:color],
icon: params[:reaction_type][:icon],
requires_comment: params[:reaction_type][:requires_comment]
requires_comment: params[:reaction_type][:requires_comment],
active: params[:reaction_type][:active],
position: params[:reaction_type][:position]
redirect_to reactions_path
end

Expand Down
1 change: 1 addition & 0 deletions app/models/reaction_type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class ReactionType < ApplicationRecord
include CommunityRelated
scope :active, -> { where(active: true).order(position: :asc) }
end
3 changes: 2 additions & 1 deletion app/views/posts/_expanded.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<button class="react-button button is-muted is-icon-only-button h-fw-bold"
id="post-<%= post.id %>-react" aria-label="Add Reaction"
data-drop="#post-<%= post.id %>-reactions-panel"
data-drop-self-class-toggle="is-active">
data-drop-self-class-toggle="is-active"
data-drop-force-dir="down">
react
</button>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/reactions/_dialog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="droppanel--header">
Mark this <%= post.post_type.name.downcase %> as ...
</div>
<% ReactionType.all.each do |rt| %>
<% ReactionType.active.all.each do |rt| %>
<div class="grid">
<div class="grid--cell">
<input class="form-radio-element reaction-type" type="radio" name="reaction-type"
Expand Down
22 changes: 22 additions & 0 deletions app/views/reactions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@
</div>
</div>

<div class="form-group">
<div class="checkbox-setting">
<div class="checkbox-setting--desc">
<%= f.label :active, 'Active?', class: 'form-element' %>
<span class="form-caption">
Check this box if the reaction is active and can be added to posts by anyone.
</span>
</div>
<div class="checkbox-setting--value">
<%= f.check_box :active, class: 'form-checkbox-element' %>
</div>
</div>
</div>

<div class="form-group">
<%= f.label :position, "Position", class: "form-element" %>
<div class="form-caption">
The order in which the reactions are to be shown in the add reaction dialog; lower positions go first
</div>
<%= f.number_field :position, class: "form-element" %>
</div>

<%= f.submit 'Save', class: 'button is-filled' %>
<%= link_to 'Cancel', reactions_path, class: 'button' %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/reactions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<th>description</th>
<th>label on post</th>
<th>requires comment?</th>
<th>active?</th>
<th>actions</th>
</tr>
<% ReactionType.all.each do |rt| %>
Expand All @@ -26,6 +27,9 @@
<td>
<%= rt.requires_comment ? 'yes' : 'no' %>
</td>
<td>
<%= rt.active ? 'yes' : 'no' %>
</td>
<td>
<div class="h-d-flex">
<%= link_to "edit", edit_reaction_path(rt.id), class: "button is-outlined" %>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20210711210342_add_is_active_to_reaction_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddIsActiveToReactionTypes < ActiveRecord::Migration[5.2]
def change
add_column :reaction_types, :active, :boolean
ReactionType.unscoped.all.update_all(active: true)
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_07_10_204812) do
ActiveRecord::Schema.define(version: 2021_07_11_210342) do

create_table "abilities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "community_id"
Expand Down Expand Up @@ -447,6 +447,7 @@
t.integer "position"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active"
t.index ["community_id"], name: "index_reaction_types_on_community_id"
end

Expand Down

0 comments on commit 09fe5c7

Please sign in to comment.