Adding projects to repositories.

This commit is contained in:
George Vinogradov 2011-10-19 17:16:29 +04:00
parent 7ef909afbb
commit ee9af32fa6
9 changed files with 177 additions and 32 deletions

View File

@ -1,8 +1,8 @@
class RepositoriesController < ApplicationController
before_filter :authenticate_user!
# before_filter :find_platform, :except => [:index, :new, :create]
before_filter :find_repository, :only => [:show, :destroy]
before_filter :get_paths, :only => [:new, :create]
#before_filter :find_platform, :except => [:index, :new, :create]
before_filter :find_repository, :only => [:show, :destroy, :add_project, :remove_project]
before_filter :get_paths, :only => [:show, :new, :create, :add_project, :remove_project]
before_filter :find_platforms, :only => [:new, :create]
def index
@ -11,9 +11,9 @@ class RepositoriesController < ApplicationController
def show
if params[:query]
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:page], :per_page => 30
@projects = @repository.projects.recent.by_name(params[:query]).paginate :page => params[:project_page], :per_page => 30
else
@projects = @repository.projects.recent.paginate :page => params[:page], :per_page => 30
@projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30
end
end
@ -40,6 +40,50 @@ class RepositoriesController < ApplicationController
end
end
def add_project
if params[:project_id]
@project = Project.find(params[:project_id])
params[:project_id] = nil
unless @repository.projects.include? @project
@repository.projects << @project
# if @repository.save
flash[:notice] = t('flash.repository.project_added')
redirect_to platform_repository_path(@repository.platform, @repository)
# else
# flash[:error] = t('flash.repository.project_not_added')
# redirect_to url_for(:action => :add_project)
# end
else
flash[:error] = t('flash.repository.project_not_added')
redirect_to url_for(:action => :add_project)
end
else
@projects = (Project.all - @repository.projects).paginate(:page => params[:project_page])
render 'projects_list'
end
end
def remove_project
if params[:project_id]
@project = Project.find(params[:project_id])
params[:project_id] = nil
if @repository.projects.include? @project
@repository.projects.delete @project
# if @repository.save
flash[:notice] = t('flash.repository.project_removed')
redirect_to platform_repository_path(@repository.platform, @repository)
# else
# flash[:error] = t('flash.repository.project_not_removed')
# redirect_to url_for(:action => :remove_project)
# end
else
redirect_to url_for(:action => :remove_project)
end
else
redirect_to platform_repository_path(@repository.platform, @repository)
end
end
protected
def get_paths
@ -61,6 +105,10 @@ class RepositoriesController < ApplicationController
end
end
def find_platform
@platform = @repository.platform
end
def find_platforms
@platforms = Platform.all
end

View File

@ -0,0 +1,11 @@
%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.owner.name + '/' + project.name, project_path(project)
%td.last
#{link_to t("layout.show"), project_path(project)} | #{link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id)}

View File

@ -0,0 +1,10 @@
%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"), url_for (:action => :remove_project, :project_id => project.id), :confirm => t("layout.projects.confirm_delete")}

View File

@ -2,10 +2,10 @@
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.repositories.list"), repositories_path
%li= link_to t("layout.platforms.new"), new_repository_path
%li= link_to t("layout.repositories.new"), new_repository_path
.content
%h2.title
= t("layout.platforms.list_header")
= t("layout.repositories.list_header")
.inner
= render :partial => 'shared/search_form'
= render :partial => 'list', :object => @repositories

View File

@ -0,0 +1,60 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.repositories.list"), @repositories_path + "#repositories"
%li= link_to t("layout.repositories.new"), @new_repository_path
%li.active= link_to t("layout.repositories.show"), repository_path(@repository)
.content
.inner
%p
%b
= t("activerecord.attributes.repository.name")
\:
= @repository.name
%p
%b
= t("activerecord.attributes.repository.unixname")
\:
= @repository.unixname
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @repository.platform.name, url_for(@repository.platform)
%p
%b
= t("activerecord.attributes.repository.owner")
\:
= link_to @repository.owner.name, url_for(@repository.owner)
%p
%b
= t("activerecord.attributes.repository.visibility")
\:
= @repository.visibility
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @repository.platform.name, platform_path(@platform)
.wat-cf
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete")
%a{ :name => "projects" }
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.projects.list"), repository_path(@repository) + "#projects"
%li.active= link_to t("layout.projects.add"), url_for(:controller => :repositories, :action => :add_project)
.content
%h2.title
= t("layout.projects.list_header")
.inner
= render :partial => 'shared/search_form'
= render :partial => 'proj_list', :object => @projects
.actions-bar.wat-cf
.actions
= will_paginate @projects, :param_name => :project_page
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -1,9 +1,9 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.repositories.list"), platform_path(@platform) + "#repositories"
%li= link_to t("layout.repositories.new"), new_platform_repository_path(@platform)
%li.active= link_to t("layout.repositories.show"), platform_repository_path(@platform, @repository)
%li.first= link_to t("layout.repositories.list"), @repositories_path + "#repositories"
%li= link_to t("layout.repositories.new"), @new_repository_path
%li.active= link_to t("layout.repositories.show"), repository_path(@repository)
.content
.inner
%p
@ -16,42 +16,44 @@
= t("activerecord.attributes.repository.unixname")
\:
= @repository.unixname
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @repository.platform.name, url_for(@repository.platform)
%p
%b
= t("activerecord.attributes.repository.owner")
\:
= link_to @repository.owner.name, url_for(@repository.owner)
%p
%b
= t("activerecord.attributes.repository.visibility")
\:
= @repository.visibility
%p
%b
= t("activerecord.attributes.repository.platform")
\:
= link_to @repository.platform.name, platform_path(@platform)
.wat-cf
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_repository_path(@platform, @repository), :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete")
= link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete")
%a{ :name => "projects" }
.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_project_path(@platform, @repository)
%li.first.active= link_to t("layout.projects.list"), repository_path(@repository) + "#projects"
%li= link_to t("layout.projects.add"), url_for(:controller => :repositories, :action => :add_project)
.content
%h2.title
= t("layout.projects.list_header")
.inner
= form_tag 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, platform_repository_project_path(@platform, @repository, project)
%td.last
#{link_to t("layout.show"), platform_repository_project_path(@platform, @repository, project)} | #{link_to t("layout.delete"), platform_repository_project_path(@platform, @repository, project), :method => :delete, :confirm => t("layout.projects.confirm_delete")}
= render :partial => 'shared/search_form'
= render :partial => 'proj_list1', :object => @projects
.actions-bar.wat-cf
.actions
= will_paginate @projects
= will_paginate @projects, :param_name => :project_page
- content_for :sidebar, render(:partial => 'sidebar')
-# content_for :sidebar, render(:partial => 'sidebar')

View File

@ -0,0 +1,4 @@
# Load extensions to existing classes.
Dir["lib/ext/**/*.rb"].each do |fn|
require File.expand_path( fn )
end

View File

@ -104,6 +104,7 @@ ru:
weekdays: Дни недели
projects:
add: Добавить
list: Список
list_header: Проекты
show: Проект
@ -208,6 +209,10 @@ ru:
saved: Репозиторий успешно добавлен
save_error: Не удалось добавить репозиторий
destroyed: Репозиторий успешно удален
project_added: Проект добавлен к репозиторию
project_not_added: Не удалось добавить проект
project_removed: Проект удален из репозитория
project_not_removed: Не удалось удалить проект из репозитория
product:
saved: Продукт успешно сохранен

View File

@ -67,7 +67,12 @@ Rosa::Application.routes.draw do
end
end
resources :repositories
resources :repositories do
member do
get :add_project
get :remove_project
end
end
resources :users, :groups do
resources :platforms, :only => [:new, :create]