Added groups representation.

This commit is contained in:
George Vinogradov 2011-10-17 00:39:45 +04:00
parent 91cc89d31c
commit f76a3aee39
14 changed files with 277 additions and 1 deletions

View File

@ -0,0 +1,50 @@
# coding: UTF-8
class GroupsController < ApplicationController
before_filter :authenticate_user!
before_filter :find_group, :only => [:show, :edit, :update, :destroy]
def index
@groups = Group.paginate(:page => params[:page], :per_page => 15)
end
def show
@platforms = @group.platforms.paginate(:page => params[:platform_page], :per_page => 10)
@repositories = @group.repositories.paginate(:page => params[:repository_page], :per_page => 10)
@projects = @group.projects.paginate(:page => params[:project_page], :per_page => 10)
end
def edit
end
def destroy
@user.destroy
flash[:notice] = t("flash.group.destroyed")
redirect_to groups_path
end
def new
@group = Group.new
end
def create
@group = Group.new params[:group]
@group.owner = current_user
@group.members << current_user
if @group.save
flash[:notice] = t('flash.group.saved')
redirect_to edit_group_path(@group)
else
flash[:error] = t('flash.group.save_error')
render :action => :new
end
end
private
def find_group
@group = Group.find(params[:id])
end
end

View File

@ -1,11 +1,29 @@
class Group < ActiveRecord::Base
validates :name, :uname, :owner_id, :presence => true
validates :name, :uname, :uniqueness => true
belongs_to :owner, :class_name => 'User'
has_many :objects, :as => :target, :class_name => 'Relation'
has_many :targets, :as => :object, :class_name => 'Relation'
has_many :users, :through => :objects, :source => :object, :source_type => 'User', :autosave => true
has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true
has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true
has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true
def roles_of(user)
objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?}
end
def add_role(user, role)
roles = objects.where(:object_id => user.id, :object_type => user.class).map {|rel| rel.role}.reject {|r| r.nil?}
unless roles.include? role
rel = Relation.create(:object_type => user.class.to_s, :object_id => user.id,
:target_type => self.class.to_s, :target_id => id)
rel.role = role
rel.save
end
end
end

View File

@ -0,0 +1,13 @@
.group
= f.label :name, t("activerecord.attributes.group.name"), :class => :label
= f.text_field :name, :class => 'text_field'
.group
= f.label :uname, t("activerecord.attributes.group.uname"), :class => :label
= f.text_field :uname, :class => 'text_field'
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save"))
= t("layout.save")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), users_path, :class => "text_button_padding link_button"

View File

@ -0,0 +1,24 @@
.content
%h2.title
= t("layout.groups.list_header")
.inner
%table.table
%tr
%th.first ID
%th= t("activerecord.attributes.group.name")
%th= t("activerecord.attributes.group.owner")
%th.last &nbsp;
- @groups.each do |group|
%tr{:class => cycle("odd", "even")}
%td
= group.id
%td
= link_to group.name, group_path(group)
%td
= link_to group.owner.name, user_path(group.owner)
%td.last
#{link_to t("layout.show"), group_path(group)} | #{link_to t("layout.edit"), edit_group_path(group)} | #{link_to t("layout.delete"), group_path(group), :method => :delete, :confirm => t("layout.groups.confirm_delete")}
.actions-bar.wat-cf
.actions
- if !!paginate
= paginate

View File

@ -0,0 +1,5 @@
.block.notice
%h3= t("layout.groups.members")
.content
- @group.members.uniq.each do |member|
%p= link_to member.name + " (#{@group.roles_of(member).map{|r| r.name}.join(', ')})", user_path(member)

View File

@ -0,0 +1,12 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.groups.list"), groups_path
%li= link_to t("layout.groups.new"), new_group_path
%li.active= link_to t("layout.groups.edit"), edit_group_path
.content
%h2.title= t("layout.groups.edit_header")
.inner
= form_for @group, :url => group_path(@group), :html => { :class => :form } do |f|
= render :partial => "form", :locals => {:f => f}
- content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,7 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.groups.list"), users_path
%li= link_to t("layout.groups.new"), new_group_path
=render :partial => 'list', :object => @groups, :locals => {:paginate => will_paginate(@groups)}
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,11 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.groups.list"), groups_path
%li.active= link_to t("layout.groups.new"), new_group_path
.content
%h2.title= t("layout.groups.new_header")
.inner
= form_for :group, :url => groups_path, :html => { :class => :form } do |f|
= render :partial => "form", :locals => {:f => f}
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,39 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.groups.list"), groups_path
%li= link_to t("layout.groups.new"), new_group_path
%li.active= link_to t("layout.groups.show"), group_path
.content
.inner
%p
%b
Id
\:
= @group.id
%p
%b
= t("activerecord.attributes.group.name")
\:
= @group.name
%p
%b
= t("activerecord.attributes.group.owner")
\:
= link_to @group.owner.name, user_path(@group.owner)
%p
%b
= t("activerecord.attributes.group.created_at")
\:
= @group.created_at
.wat-cf
= link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_group_path(@group), :class => "button"
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), group_path(@group), :method => "delete", :class => "button", :confirm => t("layout.groups.confirm_delete")
= render :partial => 'platforms/list', :object => @platforms
= render :partial => 'repositories/list', :object => @repositories
= render :partial => 'projects/list', :object => @projects
- content_for :sidebar, render(:partial => 'sidebar')

View File

@ -13,11 +13,15 @@
#user-navigation
%ul.wat-cf
%li
= t("layout.logged_in_as") + ' ' + current_user.name
&nbsp; | &nbsp;
= link_to t('layout.logout'), destroy_user_session_path, :class => "logout"
#main-navigation
%ul.wat-cf
%li{:class => controller.controller_path == 'users' ? 'active' : '' }
%a{:href => users_path}= t("layout.menu.users")
%li{:class => controller.controller_path == 'groups' ? 'active' : '' }
%a{:href => groups_path}= t("layout.menu.groups")
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
%a{:href => platforms_path}= t("layout.menu.platforms")
#wrapper.wat-cf

View File

@ -0,0 +1,28 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.platforms.list"), platforms_path
%li= link_to t("layout.platforms.new"), new_platform_path
.content
%h2.title
= t("layout.platforms.list_header")
.inner
= form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do
.group
= label_tag :query, t("layout.search_by_name"), :class => :label
= text_field_tag :query
%button.search{:type => "submit"}
= t("layout.search")
%table.table
%tr
%th.first= t("activerecord.attributes.platform.name")
%th.last &nbsp;
- @platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td
= link_to platform.name, platform_path(platform)
%td.last
#{link_to t("layout.show"), platform_path(platform)} | #{link_to t("layout.delete"), platform_path(platform), :method => :delete, :confirm => t("layout.platforms.confirm_delete")}
.actions-bar.wat-cf
.actions
= will_paginate @platforms, :param_name => :platform_page

View File

@ -0,0 +1,28 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.projects.list"), '#'#platform_repository_path(@platform, @repository) + "#projects"
%li= link_to t("layout.projects.new"), '#'#new_platform_repository_project_path(@platform, @repository)
.content
%h2.title
= t("layout.projects.list_header")
.inner
= form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do
.group
= label_tag :query, t("layout.search_by_name"), :class => :label
= text_field_tag :query
%button.search{:type => "submit"}
= t("layout.search")
%table.table
%tr
%th.first= t("activerecord.attributes.project.name")
%th.last &nbsp;
- @projects.each do |project|
%tr{:class => cycle("odd", "even")}
%td
= link_to project.name, project_path(project)
%td.last
#{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.delete"), project_path(project), :method => :delete, :confirm => t("layout.projects.confirm_delete")}
.actions-bar.wat-cf
.actions
= will_paginate @projects, :param_name => :project_page

View File

@ -0,0 +1,28 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.repositories.list"), '#'#platform_path(@platform) + "#repositories"
%li= link_to t("layout.repositories.new"), '#' #new_platform_repository_path(@platform)
.content
%h2.title
= t("layout.repositories.list_header")
.inner
= form_tag '#', :method => :get do#platform_repository_path(@platform, @repository), :method => :get do
.group
= label_tag :query, t("layout.search_by_name"), :class => :label
= text_field_tag :query
%button.search{:type => "submit"}
= t("layout.search")
%table.table
%tr
%th.first= t("activerecord.attributes.repository.name")
%th.last &nbsp;
- @repositories.each do |repository|
%tr{:class => cycle("odd", "even")}
%td
= link_to repository.name, repository_path(repository)
%td.last
#{link_to t("layout.show"), repository_path(repository)} | #{link_to t("layout.delete"), repository_path(repository), :method => :delete, :confirm => t("layout.repositories.confirm_delete")}
.actions-bar.wat-cf
.actions
= will_paginate @repositories, :param_name => :repository_page

View File

@ -0,0 +1,9 @@
class AddUnameToGroups < ActiveRecord::Migration
def self.up
add_column :groups, :uname, :string
end
def self.down
remove_column :groups, :uname
end
end