Skip to content

Commit

Permalink
Added ability to manage groups from admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Zaporozhets committed Oct 3, 2012
1 parent 010ac2b commit 224fb57
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 7 deletions.
8 changes: 8 additions & 0 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def project_update
redirect_to :back, notice: 'Group was successfully updated.'
end

def remove_project
@project = Project.find(params[:project_id])
@project.group_id = nil
@project.save

redirect_to :back, notice: 'Group was successfully updated.'
end

def destroy
@group.destroy

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/groups/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
= f.text_field :code, placeholder: "example"

.form-actions
= f.submit 'Create group', class: "btn primary"
= f.submit 'Save group', class: "btn save-btn"
3 changes: 3 additions & 0 deletions app/views/admin/groups/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%h3.page_title Edit Group
%br
= render 'form'
1 change: 1 addition & 0 deletions app/views/admin/groups/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= render 'admin/shared/projects_head'
%h3.page_title
Groups
= link_to 'New Group', new_admin_group_path, class: "btn small right"
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/groups/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= render 'admin/shared/projects_head'
%h3.page_title
Group: #{@group.name}
= link_to edit_admin_group_path(@group), class: "btn right" do
Expand Down Expand Up @@ -38,6 +39,9 @@
%li.wll
%strong
= link_to project.name, [:admin, project]
.right
= link_to 'Remove from group', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Are you sure?', method: :delete, class: "btn danger small"
.clearfix

%br
%h3 Add new project
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/projects/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= render 'admin/shared/projects_head'
%h3.page_title
Projects
= link_to 'New Project', new_admin_project_path, class: "btn small right"
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/projects/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= render 'admin/shared/projects_head'
%h3.page_title
Project: #{@admin_project.name}
= link_to edit_admin_project_path(@admin_project), class: "btn right" do
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/shared/_projects_head.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%ul.nav.nav-tabs
= nav_link(controller: :projects) do
= link_to 'Projects', admin_projects_path, class: "tab"
= nav_link(controller: :groups) do
= link_to 'Groups', admin_groups_path, class: "tab"
5 changes: 0 additions & 5 deletions app/views/groups/_projects.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
Projects
%small
(#{projects.count})
- if current_user.can_create_project?
%span.right
= link_to new_project_path, class: "btn very_small info" do
%i.icon-plus
New Project
%ul.unstyled
- projects.each do |project|
%li.wll
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/admin.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%ul.main_menu
= nav_link(controller: :dashboard, html_options: {class: 'home'}) do
= link_to "Stats", admin_root_path
= nav_link(controller: :projects) do
= nav_link(controller: [:projects, :groups]) do
= link_to "Projects", admin_projects_path
= nav_link(controller: :users) do
= link_to "Users", admin_users_path
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
resources :groups, constraints: { id: /[^\/]+/ } do
member do
put :project_update
delete :remove_project
end
end
resources :projects, constraints: { id: /[^\/]+/ } do
Expand Down

0 comments on commit 224fb57

Please sign in to comment.