summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/style.css12
-rw-r--r--app/controllers/nodes_controller.rb35
-rw-r--r--app/helpers/nodes_helper.rb12
-rw-r--r--app/views/nodes/edit.html.erb21
-rw-r--r--app/views/nodes/index.html.erb27
-rw-r--r--app/views/nodes/show.html.erb3
6 files changed, 97 insertions, 13 deletions
diff --git a/app/assets/stylesheets/style.css b/app/assets/stylesheets/style.css
index d779fce..965bbd1 100644
--- a/app/assets/stylesheets/style.css
+++ b/app/assets/stylesheets/style.css
@@ -2,3 +2,15 @@ body {
background-color: black;
color: white;
}
+
+.indent {
+ padding: 1px;
+ margin-left: 15px;
+}
+
+div.indent {
+ display : list-item;
+ list-style-type: disc;
+ list-style-position: inside;
+ padding-left: 0.2em;
+}
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index f603f52..826be55 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -12,8 +12,12 @@ class NodesController < ApplicationController
@node = Node.new
@nodes = Node.all
end
+ def edit
+ @node = Node.find(params[:id])
+ @nodes = Node.all
+ end
def create
- unless params[:node][:parent].to_i == 0
+ unless params[:node][:parent] == ""
@parent = Node.find(params[:node][:parent])
@node = @parent.children.build(title: params[:node][:title], content: params[:node][:content], parent: @parent)
else
@@ -21,13 +25,38 @@ class NodesController < ApplicationController
@node = Node.new(params.require(:node).permit(:parent,:title,:content))
end
-
@node.save
redirect_to @node
end
+ def update
+ @node = Node.find(params[:id])
+ unless params[:node][:parent] == "" #if user doesnt want to not have parent
+ unless params[:id] == params[:node][:parent] # if the user didnt select a child to be its own parent(error handling)
+ @parent = Node.find(params[:node][:parent])
+ if @node.update(title: params[:node][:title], content: params[:node][:content], parent: @parent)
+ @parent.children << @node # assign new parent
+ redirect_to @node
+ else
+ @nodes = Node.all #makes dropdown work in render
+ render 'edit'
+ end
+ else
+ @nodes = Node.all #makes dropdown work in render
+ render 'edit'
+ end
+ else # save node without parent
+ if @node.update(title: params[:node][:title], content: params[:node][:content], parent: nil)
+ redirect_to @node
+ else
+ @nodes = Node.all # makes dropdown work in render
+ render 'edit'
+ end
+ end
+ end
+
private
def node_params
-
+
end
end
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb
index 673b561..2141bfc 100644
--- a/app/helpers/nodes_helper.rb
+++ b/app/helpers/nodes_helper.rb
@@ -1,2 +1,14 @@
module NodesHelper
+ def showNestedChildren(node, level)
+ puts node.children.to_yaml
+ if node.children.any?
+ returnme = "<details class=\"indent\"><summary>#{node.title}</summary>".html_safe
+ node.children.each do |nestednode|
+ returnme += (showNestedChildren(nestednode, level + 1)).html_safe
+ end
+ returnme += "</details>".html_safe
+ else
+ returnme = "<div class=\"indent\">#{node.title}</div>".html_safe
+ end
+ end
end
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb
new file mode 100644
index 0000000..0b64046
--- /dev/null
+++ b/app/views/nodes/edit.html.erb
@@ -0,0 +1,21 @@
+<h1>edit wiki page</h1>
+<%= form_with(model: @node, local: true) do |form| %>
+ <p>
+ <%= form.label :title %><br>
+ <%= form.text_field :title %>
+ </p>
+
+ <p>
+ <%= form.label :content %><br>
+ <%= form.text_area :content %>
+ </p>
+
+ <%= form.collection_select :parent, @nodes, :id, :title, include_blank: true, :selected => @node&.parent&.id %>
+
+
+ <p>
+ <%= form.submit %>
+ </p>
+<% end %>
+
+<% link_to 'Back', nodes_path %>
diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb
index 2a14880..d787727 100644
--- a/app/views/nodes/index.html.erb
+++ b/app/views/nodes/index.html.erb
@@ -1,15 +1,22 @@
<h1> suh </h1>
+<p>
<% @rootnodes.each do |rootnode| %>
- <tr>
- <td>PARENT: <%= rootnode.title %></td>
- </tr><br>
- <em>
- <% rootnode.children.each do |node| %>
- <tr>
- <td>CHILD: <%= node[:title] %></td>
- </tr><br>
- <% end %>
- </em>
+ <% if rootnode.children.any? %>
+ <details class="indent">
+ <summary><%= rootnode.title %></summary>
+ <% rootnode.children.each do |node| %>
+ <%= showNestedChildren(node, 1) %>
+ <% end %>
+ </details>
+ <% else %>
+ <div class="indent"><%= rootnode.title %></div>
+ <% end %>
<% end %>
+</p>
+
+<details>
+ <summary>See More</summary>
+ This text will be hidden if your browser supports it.
+</details>
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb
index c933d1e..ccca323 100644
--- a/app/views/nodes/show.html.erb
+++ b/app/views/nodes/show.html.erb
@@ -6,4 +6,7 @@
<p>
<strong>Content:</strong>
<%= @node.content %>
+<% @node.children.each do |child| %>
+ <%= child.id %>
+<% end %>
</p>