-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ee51d6
commit 44f14a0
Showing
20 changed files
with
371 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class MindmapsController < ApplicationController | ||
before_action :authenticate_request, only: :create | ||
|
||
def show | ||
@mm = MindMap.find(params[:id]) | ||
end | ||
|
||
def index | ||
@mmaps = MindMap.all | ||
end | ||
|
||
def create | ||
# TBD | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Edge < ApplicationRecord | ||
belongs_to :from_node, class_name: 'Node' | ||
belongs_to :to_node, class_name: 'Node' | ||
|
||
validates :from_node_id, presence: true | ||
validates :to_node_id, presence: true | ||
|
||
scope :between, ->(from, to) { where(from_node_id: from.id, to_node_id: to.id) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class MindMap < ApplicationRecord | ||
belongs_to :category | ||
has_many :nodes, foreign_key: 'graph_id' | ||
|
||
scope :for_category, ->(category) { where(category_id: category.id) } | ||
|
||
def add_node(node) | ||
node.update!(graph_id: self.id) | ||
end | ||
|
||
def remove_node(node) | ||
node.update!(graph_id: nil) | ||
end | ||
|
||
def connect_nodes(from, to) | ||
Edge.create(from_node: from, to_node: to) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class Node < ApplicationRecord | ||
belongs_to :nodeable, polymorphic: true | ||
belongs_to :graph, class_name: 'MindMap', foreign_key: 'graph_id', optional: true | ||
|
||
has_many :edges, dependent: :destroy | ||
has_many :edges, foreign_key: 'to_node_id' | ||
|
||
validates :nodeable_type, presence: true | ||
validates :nodeable_id, presence: true | ||
|
||
scope :related_to_exam, ->(exam) { where(nodeable_type: 'Exam', nodeable_id: exam.id) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
json.array! @mmaps do |map| | ||
json.id map.id | ||
json.name map.name | ||
json.owner_id map.user_id | ||
json.node_count map.node_ids.count | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
json.message 'Your mind map' | ||
json.name @mm.name | ||
json.category @mm.category.title | ||
json.nodes @mm.node_ids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateMindMaps < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :mind_maps do |t| | ||
t.string :name | ||
t.references :category, null: false, foreign_key: true | ||
t.references :user, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateNodes < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :nodes do |t| | ||
t.references :nodeable, polymorphic: true, null: false | ||
t.integer :position | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :nodes, %i[nodeable_type nodeable_id], name: 'index_nodes_on_nodeable_type_and_nodeable_id', unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateEdges < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :edges do |t| | ||
t.references :from_node, null: false, foreign_key: { to_table: :nodes } | ||
t.references :to_node, null: false, foreign_key: { to_table: :nodes } | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :edges, %i[from_node_id to_node_id], name: 'index_edges_on_from_node_id_and_to_node_id', unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddGraphIdToNodes < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :nodes, :graph_id, :integer | ||
end | ||
end |
Oops, something went wrong.