Class: ModelInfoController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ModelInfoController
- Defined in:
- app/controllers/model_info_controller.rb,
app/controllers/model_info_controller.rb
Instance Method Summary collapse
- #add_comment ⇒ Object
- #add_note ⇒ Object
- #DBNotes ⇒ Object
- #get_author_name ⇒ Object
- #get_column_notes_count ⇒ Object
-
#get_column_notes_count_within_a_table(table_name) ⇒ Object
This will be called when user clicks on a particular table-name in the Accordion control.
- #get_models_info ⇒ Object
-
#get_table_notes_count ⇒ Object
This will be called on page-load via Ajax.
- #is_user_logged_in ⇒ Object
-
#show_notes_for_column ⇒ Object
Below actions are called by Ajax calls and return JSON.
- #user_authenticate ⇒ Object
-
#user_logged_in ⇒ Object
This is called in before_filter for add_note() & add_comment().
Instance Method Details
#add_comment ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/controllers/model_info_controller.rb', line 135 def add_comment #table_name = params[:table_name] #column_name = params[:column_name] = params[:author] comment_text = params[:comment_text] note_id = params[:note_id] @c = Comment.create :author => , :comment_text => comment_text, :note_id => note_id respond_to do |format| format.any(:xml, :html, :json) { render :json => @c.to_json} end end |
#add_note ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/model_info_controller.rb', line 124 def add_note table_name = params[:table_name] column_name = params[:column_name] = params[:author] note_text = params[:note_text] @n = Note.create :table_name => table_name, :column_name => column_name, :author => , :note_text => note_text respond_to do |format| format.any(:xml, :html, :json) { render :json => @n.to_json } end end |
#DBNotes ⇒ Object
2 3 |
# File 'app/controllers/model_info_controller.rb', line 2 def DBNotes end |
#get_author_name ⇒ Object
120 121 122 |
# File 'app/controllers/model_info_controller.rb', line 120 def render :json => session[:username].to_json end |
#get_column_notes_count ⇒ Object
164 165 166 |
# File 'app/controllers/model_info_controller.rb', line 164 def get_column_notes_count() render :json => Note.find_by_sql("select table_name, column_name, count(*) as note_count from Notes group by table_name, column_name").to_json end |
#get_column_notes_count_within_a_table(table_name) ⇒ Object
This will be called when user clicks on a particular table-name in the Accordion control
157 158 159 160 161 |
# File 'app/controllers/model_info_controller.rb', line 157 def get_column_notes_count_within_a_table (table_name) # write code that outputs some json # {"col1": 10, "col2": 5, "col3": 3,......} render :json => Note.find_by_sql("select table_name, column_name, count(*) as note_count from Notes where table_name = ? group by table_name, column_name", table_name).to_json end |
#get_models_info ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/model_info_controller.rb', line 13 def get_models_info # The below line requires "cache_classes" to be "on" # It seems it is "on" by default in Dev , but not in Prod # See the following SO question & answers - http://stackoverflow.com/questions/516579/is-there-a-way-to-get-a-collection-of-all-the-models-in-your-rails-app Rails.application.eager_load! #Dir.glob(Rails.root.join('app/models/*')).each do |x| # require x #end @models = ActiveRecord::Base.descendants return @models end |
#get_table_notes_count ⇒ Object
This will be called on page-load via Ajax
149 150 151 152 153 |
# File 'app/controllers/model_info_controller.rb', line 149 def get_table_notes_count # write code to that outputs some json # {"table1": 21, "table2": 2,.....} render :json => Note.find_by_sql("select table_name, count(*) as note_count from Notes group by table_name").to_json end |
#is_user_logged_in ⇒ Object
114 115 116 117 |
# File 'app/controllers/model_info_controller.rb', line 114 def is_user_logged_in logged_in_status = !session[:username].blank? render :json => logged_in_status.to_json end |
#show_notes_for_column ⇒ Object
Below actions are called by Ajax calls and return JSON
103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/model_info_controller.rb', line 103 def show_notes_for_column @table_name = params[:table] @column_name = params[:column] @notes = Note.where(:table_name => @table_name, :column_name => @column_name) #respond_to do |format| #format.any(:xml, :html, :json) { render :json => @notes.to_json(:include => :comments) } #end render :json => @notes.to_json(:include => :comments) end |
#user_authenticate ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/model_info_controller.rb', line 85 def user_authenticate username = params[:username] password = params[:password] #jira_response = jira(username, password) #jira_response = IcentrisJira::get_user_info(username, password) # Used IcentrisJira gem (which has the same code as jira() method above) jira_response = IcentrisJira::getJSON("https://jira2.icentris.com/jira/rest/api/2/user?username=" + username, username, password) if jira_response.include? "username=" session[:username] = jira_response.split('"displayName":')[1].split(",")[0] render :json => "Authentication Successful".to_json # send back user's full name if authentication is successful else session[:username] = nil render :json => "Authentication Failed".to_json # send back "Authentication Failed" if authentication has failed end end |
#user_logged_in ⇒ Object
This is called in before_filter for add_note() & add_comment()
59 60 61 62 63 64 65 |
# File 'app/controllers/model_info_controller.rb', line 59 def user_logged_in if session[:username].blank? render :json => "not logged in".to_json else true end end |