From 89181ba182cccb5ffad58ce0c8274c444afd64f3 Mon Sep 17 00:00:00 2001 From: gabe283 Date: Fri, 22 Aug 2014 14:25:06 -0400 Subject: [PATCH] Recursively hide tree sub categories at deeper levels and update permissions for documents and categories --- Gemfile.lock | 2 +- app/assets/javascripts/categories.js | 27 ++++++++- app/assets/stylesheets/categories.css.scss | 1 - app/models/revision.rb | 2 + app/views/categories/_categories_nav.html.erb | 17 ++++-- app/views/categories/_form.html.erb | 56 +++++++++---------- app/views/categories/edit.html.erb | 4 +- app/views/categories/new.html.erb | 4 +- .../documents/_document_list_item.html.erb | 22 ++++---- app/views/documents/_document_tile.html.erb | 22 ++++---- app/views/documents/_form.html.erb | 4 +- app/views/layouts/application.html.erb | 2 +- lib/permissions.rb | 46 +++++++++++++-- 13 files changed, 143 insertions(+), 66 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f51a1fd..c923936 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -139,7 +139,7 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - turbolinks (2.2.2) + turbolinks (2.3.0) coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) diff --git a/app/assets/javascripts/categories.js b/app/assets/javascripts/categories.js index cc92544..e0de14e 100644 --- a/app/assets/javascripts/categories.js +++ b/app/assets/javascripts/categories.js @@ -1,5 +1,5 @@ // Show all descendant categories of the clicked parent category -function toggleDescendants(parent_id) { +function toggleDescendants(parent_id, position) { // Target class for the subcategories and their states (hidden or shown) target_class = '.parent-id-' + parent_id.toString(); target_class_state = $(target_class).attr("value"); @@ -19,5 +19,30 @@ function toggleDescendants(parent_id) { $(target_class).attr("value", "hidden"); // Change the orientation of the collapsible menu button $("." + button_class).attr("class", "fa fa-plus-square-o " + button_class); + // Recursively hide any remaining categories deeper in the tree + hideDescendantTree(parent_id + 1, position); + } +} + +function hideDescendantTree(parent_id, position) { + // Recursively hide any sub categories in the tree + target_class = '.parent-id-' + parent_id.toString() + ".order-" + position.toString(); + target_class_state = $(target_class).attr("value"); + button_class = "button-id-" + parent_id.toString(); + + // Check if the the target class exists + if ($(target_class).length) { + if ($(target_class_state == "shown")) { + // Hide the category + $(target_class).css("display", "none"); + $(target_class).attr("value", "hidden"); + // Change the toggle button + $("." + button_class).attr("class", "fa fa-plus-square-o " + button_class); + // Recurse + hideDescendantTree(parent_id + 1, position); + } + } else { + // We've reached the end of the tree, return + return; } } \ No newline at end of file diff --git a/app/assets/stylesheets/categories.css.scss b/app/assets/stylesheets/categories.css.scss index ad95f69..8d7cd3b 100644 --- a/app/assets/stylesheets/categories.css.scss +++ b/app/assets/stylesheets/categories.css.scss @@ -29,7 +29,6 @@ text-decoration: none; color: black; background: #E6E6E6; - border-radius: 5px; } } } diff --git a/app/models/revision.rb b/app/models/revision.rb index 27ed8ed..2051003 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -31,6 +31,8 @@ def extract_text end tempfile.unlink + # Get rid of utf-8 control characters + contents.gsub!(/\p{Cc}/, "") if !contents.blank? # Redundant line breaks are useless to us self.search_text = contents.gsub(/(\r?\n)+/,"\n") if !contents.blank? end diff --git a/app/views/categories/_categories_nav.html.erb b/app/views/categories/_categories_nav.html.erb index f9e1b5d..6f2a2e9 100644 --- a/app/views/categories/_categories_nav.html.erb +++ b/app/views/categories/_categories_nav.html.erb @@ -4,20 +4,27 @@ \ No newline at end of file diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index f14b64e..d61a5e8 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -1,31 +1,29 @@ -<%= form_for @category, url: category_path(@category), method: :patch do |f| %> -
-
-
- <%= f.label :name %> - <%= f.text_field :name, :class => "form-control"%> -
-
-
- <%= f.label :description %> - <%= f.text_field :description, :class => "form-control" %> -
- <%= f.label :owning_group %> - <%= f.select :group_id, @groups, {include_blank: true} %> -
- <%= f.label :parent_id %> - <%= f.select :parent_id, @categories, {include_blank: true} %> -
- <%= f.label :is_private %> - <%= f.check_box :is_private %> -
- <%= f.label :is_writable %> - <%= f.check_box :is_writable %> -
- <%= f.label :is_featured %> - <%= f.check_box :is_featured %> -
- <%= f.submit %> +
+
+
+ <%= f.label :name %> + <%= f.text_field :name, :class => "form-control"%>
+
+
+ <%= f.label :description %> + <%= f.text_field :description, :class => "form-control" %> +
+ <%= f.label :owning_group %> + <%= f.select :group_id, @groups, {include_blank: true} %> +
+ <%= f.label :parent_id %> + <%= f.select :parent_id, @categories, {include_blank: true} %> +
+ <%= f.label :is_private %> + <%= f.check_box :is_private %> +
+ <%= f.label :is_writable %> + <%= f.check_box :is_writable %> +
+ <%= f.label :is_featured %> + <%= f.check_box :is_featured %> +
+ <%= f.submit %>
-<% end %> +
\ No newline at end of file diff --git a/app/views/categories/edit.html.erb b/app/views/categories/edit.html.erb index f221966..9469b48 100644 --- a/app/views/categories/edit.html.erb +++ b/app/views/categories/edit.html.erb @@ -6,6 +6,8 @@
- <%= render partial: "form" %> + <%= form_for @category, url: category_path(@category), method: :patch do |f| %> + <%= render partial: "form", locals: {f: f} %> + <% end %>
\ No newline at end of file diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb index 49673e7..e685c5a 100644 --- a/app/views/categories/new.html.erb +++ b/app/views/categories/new.html.erb @@ -5,6 +5,8 @@
- <%= render partial: "form" %> + <%= form_for @category do |f| %> + <%= render partial: "form", locals: {f: f} %> + <% end %>
\ No newline at end of file diff --git a/app/views/documents/_document_list_item.html.erb b/app/views/documents/_document_list_item.html.erb index 96020dd..6a84e9b 100644 --- a/app/views/documents/_document_list_item.html.erb +++ b/app/views/documents/_document_list_item.html.erb @@ -1,11 +1,13 @@ -