aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
new file mode 100644
index 00000000000..a36f6aa1066
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
@@ -0,0 +1,77 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2009 SonarSource SA
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+class Dashboard < ActiveRecord::Base
+ belongs_to :user
+
+ has_many :widgets, :include => 'widget_properties', :dependent => :delete_all
+ has_many :active_dashboards, :dependent => :delete_all
+
+ validates_length_of :name, :within => 1..256
+ validates_length_of :description, :maximum => 1000, :allow_blank => true, :allow_nil => true
+ validates_length_of :column_layout, :maximum => 10, :allow_blank => false, :allow_nil => false
+ validates_uniqueness_of :name, :scope => :user_id
+
+ def shared?
+ read_attribute(:shared) || false
+ end
+
+ def author
+ dashboard.user
+ end
+
+ def author_name
+ author ? author.name : nil
+ end
+
+ def editable_by?(user)
+ (user && user_id==user.id) || (user_id.nil? && user.has_role?(:admin))
+ end
+
+ def owner?(user)
+ self.user_id==user.id
+ end
+
+ def number_of_columns
+ column_layout.split('-').size
+ end
+
+ def column_size(column_index)
+ last_widget=widgets.select{|w| w.column_index==column_index}.max{|x,y| x.order_index <=> y.order_index}
+ last_widget ? last_widget.order_index : 0
+ end
+
+ def deep_copy()
+ dashboard=Dashboard.new(attributes)
+ dashboard.shared=false
+ self.widgets.each do |child|
+ new_widget = Widget.create(child.attributes)
+
+ child.widget_properties.each do |prop|
+ widget_prop = WidgetProperty.create(prop.attributes)
+ new_widget.widget_properties << widget_prop
+ end
+
+ new_widget.save
+ dashboard.widgets << new_widget
+ end
+ dashboard.save
+ dashboard
+ end
+end \ No newline at end of file