Harmonized all sections to use the new content template and layout
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 27a4f79c42ba8b8ba45399b1211b9c59f0a7b6fe..02103c08bc9eefe661d8e5b2c0e26d3f8589b15c 100644 (file)
@@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
   around_filter :thread_with_api_token, :except => [:render_exception, :render_not_found]
   before_filter :find_object_by_uuid, :except => [:index, :render_exception, :render_not_found]
   before_filter :check_user_agreements, :except => [:render_exception, :render_not_found]
+  before_filter :check_user_notifications, :except => [:render_exception, :render_not_found]
   theme :select_theme
 
   begin
@@ -141,6 +142,14 @@ class ApplicationController < ActionController::Base
      (@object.friendly_link_name if @object.respond_to? :friendly_link_name))
   end
 
+  def index_pane_list
+    %w(recent)
+  end
+
+  def show_pane_list
+    %w(attributes metadata json api)
+  end
+
   protected
     
   def find_object_by_uuid
@@ -276,4 +285,71 @@ class ApplicationController < ActionController::Base
   def select_theme
     return Rails.configuration.arvados_theme
   end
+
+  @@notification_tests = []
+
+  @@notification_tests.push lambda { |controller, current_user|
+    AuthorizedKey.limit(1).where(authorized_user_uuid: current_user.uuid).each do   
+      return nil
+    end
+    return lambda { |view|
+      view.render partial: 'notifications/ssh_key_notification'
+    }
+  }
+
+  @@notification_tests.push lambda { |controller, current_user|
+    AuthorizedKey.limit(1).where(authorized_user_uuid: current_user.uuid).each do   
+      return nil
+    end
+    return lambda { |view|
+      view.render partial: 'notifications/jobs_notification'
+    }
+  }
+
+  @@notification_tests.push lambda { |controller, current_user|
+    Job.limit(1).where(created_by: current_user.uuid).each do   
+      return nil
+    end
+    return lambda { |view|
+      view.render partial: 'notifications/jobs_notification'
+    }
+  }
+
+  @@notification_tests.push lambda { |controller, current_user|
+    Collection.limit(1).where(created_by: current_user.uuid).each do   
+      return nil
+    end
+    return lambda { |view|
+      view.render partial: 'notifications/collections_notification'
+    }
+  }
+
+  @@notification_tests.push lambda { |controller, current_user|
+    PipelineInstance.limit(1).where(created_by: current_user.uuid).each do   
+      return nil
+    end
+    return lambda { |view|
+      view.render partial: 'notifications/pipelines_notification'
+    }
+  }
+
+  def check_user_notifications
+    @notification_count = 0
+    @notifications = []
+
+    if current_user
+      @showallalerts = false      
+      @@notification_tests.each do |t|
+        a = t.call(self, current_user)
+        if a
+          @notification_count += 1
+          @notifications.push a
+        end
+      end
+    end
+
+    if @notification_count == 0
+      @notification_count = ''
+    end
+  end
 end