From ee9af32fa6f74de9b699b84547c7b815f30fc218 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 19 Oct 2011 17:16:29 +0400 Subject: [PATCH] Adding projects to repositories. --- app/controllers/repositories_controller.rb | 58 ++++++++++++++++-- app/views/repositories/_proj_list.html.haml | 11 ++++ app/views/repositories/_proj_list1.html.haml | 10 ++++ app/views/repositories/index.html.haml | 4 +- .../repositories/projects_list.html.haml | 60 +++++++++++++++++++ app/views/repositories/show.html.haml | 50 ++++++++-------- config/initializers/ext.rb | 4 ++ config/locales/ru.yml | 5 ++ config/routes.rb | 7 ++- 9 files changed, 177 insertions(+), 32 deletions(-) create mode 100644 app/views/repositories/_proj_list.html.haml create mode 100644 app/views/repositories/_proj_list1.html.haml create mode 100644 app/views/repositories/projects_list.html.haml create mode 100644 config/initializers/ext.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 07e5c6c03..dad3a6e0e 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/views/repositories/_proj_list.html.haml b/app/views/repositories/_proj_list.html.haml new file mode 100644 index 000000000..cb3745999 --- /dev/null +++ b/app/views/repositories/_proj_list.html.haml @@ -0,0 +1,11 @@ +%table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @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)} + diff --git a/app/views/repositories/_proj_list1.html.haml b/app/views/repositories/_proj_list1.html.haml new file mode 100644 index 000000000..c37d33bf7 --- /dev/null +++ b/app/views/repositories/_proj_list1.html.haml @@ -0,0 +1,10 @@ +%table.table + %tr + %th.first= t("activerecord.attributes.project.name") + %th.last   + - @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")} diff --git a/app/views/repositories/index.html.haml b/app/views/repositories/index.html.haml index 3ee0282ab..00a1677f9 100644 --- a/app/views/repositories/index.html.haml +++ b/app/views/repositories/index.html.haml @@ -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 diff --git a/app/views/repositories/projects_list.html.haml b/app/views/repositories/projects_list.html.haml new file mode 100644 index 000000000..ed5120d3c --- /dev/null +++ b/app/views/repositories/projects_list.html.haml @@ -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') + diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 1237c8ab7..d96f8b62a 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -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   - - @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') diff --git a/config/initializers/ext.rb b/config/initializers/ext.rb new file mode 100644 index 000000000..26cb643b3 --- /dev/null +++ b/config/initializers/ext.rb @@ -0,0 +1,4 @@ +# Load extensions to existing classes. +Dir["lib/ext/**/*.rb"].each do |fn| + require File.expand_path( fn ) +end diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 40ffe378f..cde7e816e 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -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: Продукт успешно сохранен diff --git a/config/routes.rb b/config/routes.rb index 54d8d0a3f..d969fa059 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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]