Skip to content

Commit

Permalink
refactor commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviaBth committed Oct 16, 2024
1 parent ad18741 commit 20b105c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def call
styles.value[@ident] = ""
styles.save!

create_constraint_never(@config_var == :scoped_styles ? :scoped_styles : :scoped_admin_styles)

broadcast(:ok, @ident)
rescue StandardError => e
broadcast(:invalid, e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Admin
class DestroyScopedStyle < Command
# Public: Initializes the command.
#
# key - the key to destroy inside scoped_styles
# key - the key to destroy inside scoped_styles/scoped_admin_styles
# organization
def initialize(key, organization, config_var = :scoped_styles)
@key = key
Expand All @@ -28,7 +28,6 @@ def call
styles.value.except!(@key)
styles.save!
# remove constrains associated (a new config var is generated automatically, by removing it, it will trigger destroy on dependents)
constraint = @config_var == :scoped_styles ? :scoped_styles : :scoped_admin_styles
constraint = AwesomeConfig.find_by(var: "#{constraint}_#{@key}", organization: @organization)
constraint.destroy! if constraint.present?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def destroy
private

def config_var
return :scoped_admin_styles if params[:private] == "true"
return :scoped_admin_styles if params[:admin] == "true"

:scoped_styles
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
<% form.object.send(config_var)&.each do |key, value| %>
<div class="card p-4 scoped_styles_container<%= " private" if admin_styles %> js-box-container" data-key="<%= key %>" data-var="<%= config_var %>">
<%= render(partial: "decidim/decidim_awesome/admin/config/autoedit_box_label", locals: { var: config_var, key: key, scope: "#{style}_#{key}", delete_path: decidim_admin_decidim_awesome.scoped_style_path(key: key) }) %>
<%= render(partial: "decidim/decidim_awesome/admin/config/autoedit_box_label", locals: { var: config_var, key: key, scope: "#{style}_#{key}", delete_path: decidim_admin_decidim_awesome.scoped_style_path(key: key, admin: admin_styles) }) %>
<p class="form-error is-visible" id="custom-style-error-<%= key %>"><%= errors[key.to_sym].join("<br>") if errors %></p>
<%= text_area_tag key, value, name: "config[#{config_var}][#{key}]", rows: 5 %>
<%= render(partial: "decidim/decidim_awesome/admin/config/constraints", locals: { key: "#{style}_#{key}", constraints: constraints_for("#{style}_#{key}") }) %>
</div>
<% end %>
<%= link_to decidim_admin_decidim_awesome.scoped_styles_path(private: admin_styles), method: :post, class: "button button__sm button__text-secondary mr-auto" do %>
<%= link_to decidim_admin_decidim_awesome.scoped_styles_path(admin: admin_styles), method: :post, class: "button button__sm button__text-secondary mr-auto" do %>
<%= icon("add-box-line") %>
<%= t("new", scope: "decidim.decidim_awesome.admin.config.form_#{config_var}") %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ en:
sure_to_remove: Are you sure you want to destroy this private fields box?
form_scoped_admin_styles:
delete: Delete
new: Add a new CSS box
new: Add a new "admin panel" CSS box
remove: Remove this CSS box
sure_to_remove: Are you sure you want to destroy this CSS box?
form_scoped_admins:
Expand All @@ -369,7 +369,7 @@ en:
group?
form_scoped_styles:
delete: Delete
new: Add a new CSS box
new: Add a new "public frontend" CSS box
remove: Remove this CSS box
sure_to_remove: Are you sure you want to destroy this CSS box?
none: "⛔ Never! - Deactivate any other constraint"
Expand Down

0 comments on commit 20b105c

Please sign in to comment.