Skip to content
This repository has been archived by the owner on Dec 11, 2018. It is now read-only.

Commit

Permalink
added tracking versions to graphs, nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
omarali committed Aug 15, 2012
1 parent e823c4a commit a912b47
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Gemfile.lock
Expand Up @@ -79,6 +79,9 @@ GEM
mime-types (1.19)
multi_json (1.3.6)
nokogiri (1.5.5)
paper_trail (2.6.3)
activerecord (~> 3.0)
railties (~> 3.0)
pg (0.14.0)
polyglot (0.3.3)
rack (1.4.1)
Expand Down Expand Up @@ -131,7 +134,6 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thor (0.14.6)
Expand All @@ -157,10 +159,10 @@ DEPENDENCIES
database_cleaner
dynamic_form
jquery-rails
paper_trail
pg
rails (= 3.2.3)
rspec-rails (~> 2.0)
rufus-scheduler (~> 2.0.17)
sqlite3 (= 1.3.5)
therubyracer
uglifier (>= 1.0.3)
5 changes: 5 additions & 0 deletions app/controllers/graphs_controller.rb
Expand Up @@ -115,4 +115,9 @@ def groups_widget

render :partial => "groups_widget", :layout => false#, :layout => !request.xhr?
end

def versions
@graphs = Graph.find(params[:graph_id]).versions.map { |v| v.item }
render 'index'
end
end
5 changes: 5 additions & 0 deletions app/controllers/nodes_controller.rb
Expand Up @@ -130,4 +130,9 @@ def node_widget

render :partial => 'node_widget'
end

def versions
@nodes = Node.find(params[:id]).versions.map { |v| v.item }
render 'index'
end
end
2 changes: 2 additions & 0 deletions app/models/graph.rb
Expand Up @@ -14,6 +14,8 @@ class Graph < ActiveRecord::Base
# Validations
validates :name, :presence => true, :uniqueness => true

has_paper_trail

def all_subgraphs_naive
return [] if subgraphs.nil?
result = subgraphs
Expand Down
2 changes: 2 additions & 0 deletions app/models/node.rb
Expand Up @@ -21,6 +21,8 @@ class Node < ActiveRecord::Base
# Validations
validates :title, :presence => true, :uniqueness => true

has_paper_trail

def related_nodes
related_nodes_A | related_nodes_B
end
Expand Down
2 changes: 2 additions & 0 deletions app/views/graphs/versions.html.erb
@@ -0,0 +1,2 @@
<%= render :partial => "application/flash", :locals => { :flash => flash } %>
<div id="graphData" style="display:none" data-graph_id="<%= @graph.id if @graph %>" data-graph_nodes="<%= @graph.nodes.map{ |n| n.id }.to_json if @graph %>" data-all_graph_nodes="<%= @graph.all_nodes.map{ |n| n.id }.to_json if @graph %>" data-node_id="<%= @node.id if @node %>" ></div>
Empty file.
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -8,11 +8,13 @@

resources :graphs do
get "groups_widget" => "graphs#groups_widget", :as => "groups_widget"
get "versions" => "graphs#versions", :as => "graph_versions"
end

resources :nodes do
get "learning_path" => "nodes#learning_path", :as => "learning_path"
get "node_widget" => "nodes#node_widget", :as => "node_widget"
get "versions" => "nodes#versions", :as => "node_versions"
end

resources :courses do
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20120814002222_create_versions.rb
@@ -0,0 +1,18 @@
class CreateVersions < ActiveRecord::Migration
def self.up
create_table :versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
t.string :event, :null => false
t.string :whodunnit
t.text :object
t.datetime :created_at
end
add_index :versions, [:item_type, :item_id]
end

def self.down
remove_index :versions, [:item_type, :item_id]
drop_table :versions
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120809211628) do
ActiveRecord::Schema.define(:version => 20120814002222) do

create_table "actions", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -127,4 +127,15 @@
t.boolean "track", :default => true
end

create_table "versions", :force => true do |t|
t.string "item_type", :null => false
t.integer "item_id", :null => false
t.string "event", :null => false
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
end

add_index "versions", ["item_type", "item_id"], :name => "index_versions_on_item_type_and_item_id"

end

0 comments on commit a912b47

Please sign in to comment.