mongoid-forums 0.0.5 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/mongoid_forums/admin/users.js +2 -0
  3. data/app/assets/stylesheets/mongoid_forums/admin/users.css +4 -0
  4. data/app/controllers/mongoid_forums/admin/categories_controller.rb +5 -5
  5. data/app/controllers/mongoid_forums/admin/forums_controller.rb +2 -2
  6. data/app/controllers/mongoid_forums/admin/users_controller.rb +34 -0
  7. data/app/controllers/mongoid_forums/application_controller.rb +1 -1
  8. data/app/controllers/mongoid_forums/forums_controller.rb +8 -8
  9. data/app/controllers/mongoid_forums/topics_controller.rb +0 -1
  10. data/app/helpers/mongoid_forums/admin/users_helper.rb +4 -0
  11. data/app/models/mongoid_forums/category.rb +2 -1
  12. data/app/models/mongoid_forums/forum.rb +2 -1
  13. data/app/views/mongoid_forums/admin/base/index.haml +1 -0
  14. data/app/views/mongoid_forums/admin/categories/edit.haml +1 -0
  15. data/app/views/mongoid_forums/admin/categories/new.haml +1 -0
  16. data/app/views/mongoid_forums/admin/forums/edit.haml +1 -0
  17. data/app/views/mongoid_forums/admin/forums/new.haml +1 -0
  18. data/app/views/mongoid_forums/admin/groups/show.haml +11 -4
  19. data/app/views/mongoid_forums/admin/users/index.haml +24 -0
  20. data/app/views/mongoid_forums/forums/index.haml +1 -1
  21. data/config/routes.rb +5 -0
  22. data/lib/mongoid_forums/version.rb +1 -1
  23. data/lib/mongoid_forums.rb +1 -1
  24. data/test/controllers/mongoid_forums/admin/users_controller_test.rb +11 -0
  25. data/test/dummy/app/assets/javascripts/application.js +2 -0
  26. data/test/dummy/log/development.log +5273 -0
  27. data/test/dummy/tmp/cache/assets/development/sprockets/0308248096d701ded90989b48340878a +0 -0
  28. data/test/dummy/tmp/cache/assets/development/sprockets/1d095746458aab3bdb955bf59c96ca33 +0 -0
  29. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  30. data/test/dummy/tmp/cache/assets/development/sprockets/6f9939c59875c2394301c1b6b1bceca3 +0 -0
  31. data/test/dummy/tmp/cache/assets/development/sprockets/c8a43f513a945814918a659ead2dac85 +0 -0
  32. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  33. data/test/dummy/tmp/cache/assets/development/sprockets/e1436ddb13bf91383110676cf21fbe14 +0 -0
  34. data/test/dummy/tmp/cache/assets/development/sprockets/e65def7db46175dc13f1bf5cc4f2f870 +0 -0
  35. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  36. metadata +35 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73b738bfa58a6743dcb67ec79b38604287d6f666
4
- data.tar.gz: 3999f2852e03a0bfddf5e24d0e788e61e4c891f0
3
+ metadata.gz: 9bdf3c71e24211880b870d5f17158a1dbfd49005
4
+ data.tar.gz: 75379a0a853b6ef2db67c24e25e77dc42fb872ad
5
5
  SHA512:
6
- metadata.gz: c49e8ef5e09919a913a55bc7ff9ae13761004b0efa788aac080b8fe05ffae95fad4c9c6ac2123230977bdbd47746cc612982e5e81fb659c8dfd425115e2c60c0
7
- data.tar.gz: 43cfa20eda79aec5f0985b5d046bea08fbc3a59dd3f52c712df888c39fb376fb8dff9c5d65809d36ec970309f1aabb9d493a346627f0870a7c36d886ac6d32ab
6
+ metadata.gz: 40ef04419c68fd0bcba32664e6a908bd3110a86e25d3d74be920e75d2cf5d6411fc948b93e292753bb6f0e7dbd518f90a4bfcf7d516ed08f6512f7ed880d2374
7
+ data.tar.gz: 2f48f9a3800cd093463a8d8cd42ac97e3ab40a72dab696070d5e060e47b8d2fb0afbd568137f0354621e642d4b744455dff863c9d8e5d7e460b6a785ae8cbf13
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -6,13 +6,13 @@ module MongoidForums
6
6
  before_action :set_category, only: [:add_group, :remove_group]
7
7
 
8
8
  def index
9
- @forums = Forum.all
10
- @categories = Category.all
9
+ @forums = Forum.asc(:position)
10
+ @categories = Category.asc(:position)
11
11
  end
12
12
 
13
13
  def show
14
14
  @category = Category.find(params[:id])
15
- @groups = Group.all.where(moderator: true).select{ |group| !@category.moderator_groups.include?(group) }
15
+ @groups = Group. all.where(moderator: true).select{ |group| !@category.moderator_groups.include?(group) }
16
16
  end
17
17
 
18
18
  def new
@@ -20,7 +20,7 @@ module MongoidForums
20
20
  end
21
21
 
22
22
  def create
23
- if @category = Category.create(name: params[:category][:name])
23
+ if @category = Category.create(category_params)
24
24
  flash[:notice] = "Category created successfully"
25
25
  redirect_to admin_categories_path
26
26
  else
@@ -76,7 +76,7 @@ module MongoidForums
76
76
  private
77
77
 
78
78
  def category_params
79
- params.require(:category).permit(:name)
79
+ params.require(:category).permit(:name, :position)
80
80
  end
81
81
 
82
82
  def set_category
@@ -14,7 +14,7 @@ module MongoidForums
14
14
  end
15
15
 
16
16
  def create
17
- @forum = Forum.new(name: params[:forum][:name], category: params[:forum][:category])
17
+ @forum = Forum.new(forum_params)
18
18
  if @forum.save
19
19
  flash[:notice] = "Forum created successfully"
20
20
  redirect_to [:admin, @forum]
@@ -76,7 +76,7 @@ module MongoidForums
76
76
  private
77
77
 
78
78
  def forum_params
79
- params.require(:forum).permit(:name, :category)
79
+ params.require(:forum).permit(:name, :category, :position)
80
80
  end
81
81
 
82
82
  def set_forum
@@ -0,0 +1,34 @@
1
+ require_dependency "mongoid_forums/application_controller"
2
+
3
+ module MongoidForums
4
+ module Admin
5
+ class UsersController < BaseController
6
+
7
+ before_action :set_user, only: [:add_admin, :remove_admin]
8
+
9
+ def index
10
+ @admins = User.where(mongoid_admin: true)
11
+ @non_admins = User.where(mongoid_admin: false)
12
+ end
13
+
14
+ def add_admin
15
+ @user.mongoid_admin = true
16
+ @user.save
17
+ redirect_to admin_users_path
18
+ end
19
+
20
+ def remove_admin
21
+ @user.mongoid_admin = false
22
+ @user.save
23
+ redirect_to admin_users_path
24
+ end
25
+
26
+ private
27
+
28
+ def set_user
29
+ @user = User.find(params[:user][:id])
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -23,7 +23,7 @@ class MongoidForums::ApplicationController < ApplicationController
23
23
  end
24
24
 
25
25
  def set_categories
26
- @categories = MongoidForums::Category.all
26
+ @categories = MongoidForums::Category.asc(:position)
27
27
  end
28
28
 
29
29
  def authenticate_mongoid_forums_user
@@ -6,7 +6,7 @@ module MongoidForums
6
6
  before_filter :authenticate_mongoid_forums_user, :only => [:create, :new]
7
7
 
8
8
  def index
9
- @categories = Category.all.order_by([:order, :asc])
9
+ @categories = Category.asc(:position)
10
10
  end
11
11
 
12
12
  def show
@@ -51,15 +51,15 @@ module MongoidForums
51
51
  end
52
52
  end
53
53
 
54
- private
54
+ private
55
55
 
56
- def register_view
57
- @forum.register_view_by(mongoid_forums_user)
58
- end
56
+ def register_view
57
+ @forum.register_view_by(mongoid_forums_user)
58
+ end
59
59
 
60
- def topic_params
61
- params.require(:topic).permit(:name, :posts => [:text])
62
- end
60
+ def topic_params
61
+ params.require(:topic).permit(:name, :posts => [:text])
62
+ end
63
63
 
64
64
 
65
65
  end
@@ -5,7 +5,6 @@ module MongoidForums
5
5
  before_filter :find_forum, :except => [:my_subscriptions, :my_posts, :my_topics]
6
6
 
7
7
  def show
8
-
9
8
  if find_topic
10
9
  register_view
11
10
 
@@ -0,0 +1,4 @@
1
+ module MongoidForums
2
+ module Admin::UsersHelper
3
+ end
4
+ end
@@ -9,7 +9,8 @@ module MongoidForums
9
9
  field :name
10
10
  validates :name, :presence => true
11
11
 
12
- field :order, :type => Integer, :default => 0
12
+ field :position, :type => Integer, :default => 0
13
+ validates :position, numericality: { only_integer: true }
13
14
 
14
15
  def moderator?(user)
15
16
  return false unless user
@@ -16,7 +16,8 @@ module MongoidForums
16
16
 
17
17
  has_and_belongs_to_many :moderator_groups, :class_name => "MongoidForums::Group", inverse_of: nil
18
18
 
19
- field :order, :type => Integer, :default => 0
19
+ field :position, :type => Integer, :default => 0
20
+ validates :position, numericality: { only_integer: true }
20
21
 
21
22
  def unread_topic_count(user)
22
23
  view = View.where(:viewable_id => id, :user_id => user.id).first
@@ -3,3 +3,4 @@
3
3
  =link_to "Manage Categories", admin_categories_path
4
4
  =link_to "Manage Forums", admin_forums_path
5
5
  =link_to "Manage Groups", admin_groups_path
6
+ =link_to "Manage Users", admin_users_path
@@ -1,3 +1,4 @@
1
1
  = simple_form_for [:admin, @category] do |f|
2
2
  = f.input :name
3
+ = f.input :position
3
4
  = f.submit "Update Category", :class => "btn", :disable_with => "Updating..."
@@ -1,3 +1,4 @@
1
1
  = simple_form_for [:admin, @category] do |f|
2
2
  = f.input :name
3
+ = f.input :position
3
4
  = f.submit "Create Category", :class => "btn", :disable_with => "Creating..."
@@ -1,4 +1,5 @@
1
1
  = simple_form_for [:admin, @forum] do |f|
2
2
  = f.input :name
3
3
  = f.input :category, collection: MongoidForums::Category.all
4
+ = f.input :position
4
5
  = f.submit "Update Forum", :class => "btn", :disable_with => "Updating..."
@@ -1,4 +1,5 @@
1
1
  = simple_form_for [:admin, @forum] do |f|
2
2
  = f.input :name
3
3
  = f.input :category, collection: MongoidForums::Category.all
4
+ = f.input :position
4
5
  = f.submit "Create Forum", :class => "btn", :disable_with => "Creating..."
@@ -13,7 +13,14 @@
13
13
  %td
14
14
  = button_to "Remove", admin_group_rem_user_path(group_id: @group.id, user: {id: member}), method: :post, data: { confirm: 'Are you certain you want to delete this?' }
15
15
 
16
- = form_tag admin_group_add_user_path(@group), :method => :post do
17
- = collection_select(:user, :id, @users, :id, :email, {:prompt => true})
18
- %button
19
- Add
16
+ = form_tag admin_group_add_user_path(@group), :method => :post, :id => "form_add_user" do
17
+ %input{:id => "userinput", :list => "users", :name => "[user][id]"}/
18
+ %datalist#users
19
+ - @users.each do |user|
20
+ %option{:id => user.id, :value => user.forum_display_name}
21
+ = submit_tag("Add User")
22
+
23
+ :javascript
24
+ $("#form_add_user").submit(function(){
25
+ $("#userinput").val($('#users').find('option[value="' + $('#userinput').val() + '"]').attr('id'));
26
+ });
@@ -0,0 +1,24 @@
1
+ %h3 Listing all admins
2
+ %table{:border => "1"}
3
+ %tr
4
+ %th
5
+ Name
6
+
7
+ - @admins.each do |admin|
8
+ %tr
9
+ %td
10
+ = admin.forum_display_name
11
+ %td
12
+ = button_to "Remove", admin_user_remove_admin_path("dummy", user: {id: admin.id}), method: :post, data: { confirm: 'Are you certain you want to delete this?' }
13
+
14
+ = form_tag admin_user_add_admin_path("dummy"), :method => :post, :id => "form_add_user" do
15
+ %input{:id => "userinput", :list => "users", :name => "[user][id]"}/
16
+ %datalist#users
17
+ - @non_admins.each do |user|
18
+ %option{:id => user.id, :value => user.forum_display_name}
19
+ = submit_tag("Add Admin")
20
+
21
+ :javascript
22
+ $("#form_add_user").submit(function(){
23
+ $("#userinput").val($('#users').find('option[value="' + $('#userinput').val() + '"]').attr('id'));
24
+ });
@@ -21,7 +21,7 @@
21
21
  %th
22
22
  Views
23
23
 
24
- - category.forums.order_by([:order, :asc]).each do |forum|
24
+ - category.forums.asc(:position).each do |forum|
25
25
  %tr
26
26
  %td
27
27
  = link_to forum.name, forum
data/config/routes.rb CHANGED
@@ -22,6 +22,11 @@ MongoidForums::Engine.routes.draw do
22
22
  get 'toggle_pin' => 'topics#toggle_pin', :as => 'toggle_pin'
23
23
  end
24
24
  end
25
+
26
+ resources :users do
27
+ post '/add' => 'users#add_admin', as: 'add_admin'
28
+ post '/remove' => 'users#remove_admin', as: 'remove_admin'
29
+ end
25
30
  end
26
31
 
27
32
  root :to => "forums#index"
@@ -1,3 +1,3 @@
1
1
  module MongoidForums
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -18,7 +18,7 @@ module MongoidForums
18
18
  has_many :mongoid_forums_posts, :class_name => "MongoidForums::Post", :foreign_key => "user_id"
19
19
  has_many :mongoid_forums_topics, :class_name => "MongoidForums::Topic", :foreign_key => "user_id"
20
20
 
21
- field :mongoid_admin, type: Boolean
21
+ field :mongoid_admin, type: Boolean, default: false
22
22
 
23
23
  def mongoid_forums_admin?
24
24
  mongoid_admin
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ module MongoidForums
4
+ class Admin::UsersControllerTest < ActionController::TestCase
5
+ test "should get index" do
6
+ get :index
7
+ assert_response :success
8
+ end
9
+
10
+ end
11
+ end
@@ -10,4 +10,6 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require jquery
14
+ //= require jquery_ujs
13
15
  //= require_tree .