Parcourir la source

Added notice when query is part of dashboard

Andrew Kane il y a 8 ans
Parent
commit
9335500677
2 fichiers modifiés avec 4 ajouts et 0 suppressions
  1. 1 0
      app/models/blazer/query.rb
  2. 3 0
      app/views/blazer/queries/_form.html.erb

+ 1 - 0
app/models/blazer/query.rb

@@ -3,6 +3,7 @@ module Blazer
     belongs_to :creator, class_name: Blazer.user_class.to_s if Blazer.user_class
     has_many :checks, dependent: :destroy
     has_many :dashboard_queries, dependent: :destroy
+    has_many :dashboards, through: :dashboard_queries
     has_many :audits
 
     validates :name, presence: true

+ 3 - 0
app/views/blazer/queries/_form.html.erb

@@ -48,6 +48,9 @@
         <% end %>
         <%= f.submit @query.persisted? ? "Update" : "Create", class: "btn btn-success" %>
       </div>
+      <% if @query.persisted? && (dashboards_count = @query.dashboards.count) > 0 %>
+        <div class="alert alert-info" style="margin-top: 10px; padding: 8px 12px;">Part of <%= pluralize(dashboards_count, "dashboard") %>. Be careful when editing.</div>
+      <% end %>
     </div>
   </div>
 <% end %>