Commit d6363e93 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Admin Group scaffold -> new, show, index

parent d683ce5c
class Admin::GroupsController < AdminController
before_filter :group, only: [:edit, :show, :update, :destroy, :project_update]
def index
@groups = Group.scoped
@groups = @groups.search(params[:name]) if params[:name].present?
@groups = @groups.page(params[:page]).per(20)
end
def show
@projects = Project.scoped
@projects = @projects.not_in_group(@group) if @group.projects.present?
@projects = @projects.all
end
def new
@group = Group.new
end
def edit
end
def create
@group = Group.new(params[:group])
@group.owner = current_user
if @group.save
redirect_to [:admin, @group], notice: 'Group was successfully created.'
else
render action: "new"
end
end
def update
owner_id = params[:group].delete(:owner_id)
if owner_id
@group.owner = User.find(owner_id)
end
if @group.update_attributes(params[:group])
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
else
render action: "edit"
end
end
def project_update
project_ids = params[:project_ids]
Project.where(id: project_ids).update_all(group_id: @group.id)
redirect_to :back, notice: 'Group was successfully updated.'
end
def destroy
@group.destroy
redirect_to groups_url, notice: 'Group was successfully deleted.'
end
private
def group
@group = Group.find_by_code(params[:id])
end
end
......@@ -19,4 +19,10 @@ class Group < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
validates :code, presence: true, uniqueness: true
validates :owner_id, presence: true
delegate :name, to: :owner, allow_nil: true, prefix: true
def to_param
code
end
end
......@@ -26,9 +26,12 @@ class Project < ActiveRecord::Base
has_many :wikis, dependent: :destroy
has_many :protected_branches, dependent: :destroy
delegate :name, to: :owner, allow_nil: true, prefix: true
# Scopes
scope :public_only, where(private_flag: false)
scope :without_user, lambda { |user| where("id not in (:ids)", ids: user.projects.map(&:id) ) }
scope :without_user, ->(user) { where("id not in (:ids)", ids: user.projects.map(&:id) ) }
scope :not_in_group, ->(group) { where("id not in (:ids)", ids: group.project_ids ) }
def self.active
joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
......
= form_for [:admin, @group] do |f|
- if @group.errors.any?
.alert-message.block-message.error
%span= @group.errors.full_messages.first
.clearfix.group_name_holder
= f.label :name do
Group name is
.input
= f.text_field :name, placeholder: "Example Group", class: "xxlarge"
.clearfix
= f.label :code do
URL
.input
.input-prepend
%span.add-on= web_app_url
= f.text_field :code, placeholder: "example"
.form-actions
= f.submit 'Create group', class: "btn primary"
%h3.page_title
Groups
= link_to 'New Group', new_admin_group_path, class: "btn small right"
%br
= form_tag admin_groups_path, method: :get, class: 'form-inline' do
= text_field_tag :name, params[:name], class: "xlarge"
= submit_tag "Search", class: "btn submit primary"
%table
%thead
%th Name
%th Path
%th Projects
%th Edit
%th.cred Danger Zone!
- @groups.each do |group|
%tr
%td= link_to group.name, [:admin, group]
%td= group.path
%td= group.projects.count
%td= link_to 'Edit', edit_admin_group_path(group), id: "edit_#{dom_id(group)}", class: "btn small"
%td.bgred= link_to 'Destroy', [:admin, group], confirm: "REMOVE #{group.name}? Are you sure?", method: :delete, class: "btn small danger"
= paginate @groups, theme: "admin"
%h3.page_title New Group
%br
= render 'form'
%h3.page_title
Group: #{@group.name}
= link_to edit_admin_group_path(@group), class: "btn right" do
%i.icon-edit
Edit
%br
%table.zebra-striped
%thead
%tr
%th Group
%th
%tr
%td
%b
Name:
%td
= @group.name
%tr
%td
%b
Code:
%td
= @group.code
%tr
%td
%b
Owner:
%td
= @group.owner_name
.ui-box
%h5
Projects
%small
(#{@group.projects.count})
%ul.unstyled
- @group.projects.each do |project|
%li.wll
%strong
= link_to project.name, [:admin, project]
%br
%h3 Add new project
%br
= form_tag project_update_admin_group_path(@group), class: "bulk_import", method: :put do
= select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5'
.form-actions
= submit_tag 'Add', class: "btn primary"
......@@ -43,6 +43,11 @@ Gitlab::Application.routes.draw do
put :unblock
end
end
resources :groups, constraints: { id: /[^\/]+/ } do
member do
put :project_update
end
end
resources :projects, constraints: { id: /[^\/]+/ } do
member do
get :team
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment