[Refs #263] Delete Categories

This commit is contained in:
Vladimir Sharshov 2012-03-29 23:00:44 +04:00
parent 5db485a4c0
commit 0c2d0f4612
24 changed files with 21 additions and 413 deletions

View File

@ -1,78 +0,0 @@
# -*- encoding : utf-8 -*-
class CategoriesController < ApplicationController
before_filter :authenticate_user!
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
before_filter :find_platform, :only => [:show, :index]
load_and_authorize_resource
def platforms
@all_platforms = Platform.all
@all_platforms_count = Platform.joins(:repositories => :projects).group('platforms.id').count
@personal_platforms = Platform.personal
@personal_platforms_count = Platform.personal.joins(:repositories => :projects).group('platforms.id').count
@main_platforms = Platform.main
@main_platforms_count = Platform.main.joins(:repositories => :projects).group('platforms.id').count
end
def index
if @platform
@categories = Category.select('categories.id, categories.name, categories.ancestry, count(projects.id) projects_count').
joins(:projects => :repositories).where('repositories.platform_id = ?', @platform.id).
having('count(projects.id) > 0').group('categories.id, categories.name, categories.ancestry, projects_count')
render 'index2'
else
@categories = Category.paginate(:page => params[:page])
end
end
def show
@projects = @category.projects
@projects = @projects.joins(:repositories).where("repositories.platform_id = ?", @platform.id) if @platform
@projects = @projects.paginate :page => params[:page]
end
def new
@category = Category.new
end
def edit
end
def destroy
@category.destroy
flash[:notice] = t("flash.category.destroyed")
redirect_to categories_path
end
def create
@category = Category.new params[:category]
if @category.save
flash[:notice] = t('flash.category.saved')
redirect_to categories_path
else
flash[:error] = t('flash.category.save_error')
render :action => :new
end
end
def update
if @category.update_attributes(params[:category])
flash[:notice] = t('flash.category.saved')
redirect_to categories_path
else
flash[:error] = t('flash.category.save_error')
render :action => :edit
end
end
protected
def find_category
@category = Category.find(params[:id])
end
def find_platform
@platform = Platform.find(params[:platform_id]) if params[:platform_id]
end
end

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
module ApplicationHelper
def choose_title
title = if ['categories', 'personal_repositories', 'downloads'].include?(controller.controller_name)
title = if ['personal_repositories', 'downloads'].include?(controller.controller_name)
APP_CONFIG['repo_project_name']
else
APP_CONFIG['project_name']

View File

@ -1,10 +0,0 @@
# -*- encoding : utf-8 -*-
class Category < ActiveRecord::Base
has_many :projects, :dependent => :nullify
validates :name, :presence => true
default_scope order('categories.name')
has_ancestry
end

View File

@ -3,7 +3,6 @@ class Project < ActiveRecord::Base
VISIBILITIES = ['open', 'hidden']
MAX_OWN_PROJECTS = 32000
belongs_to :category, :counter_cache => true
belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count
has_many :issues, :dependent => :destroy
@ -21,7 +20,7 @@ class Project < ActiveRecord::Base
validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/}
validates :owner, :presence => true
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
# validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?}
validates_attachment_size :srpm, :less_than => 500.megabytes
validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type')

View File

@ -1,9 +0,0 @@
%tr{:class => cycle("odd", "even")}
%td
= link_to category.name, category
(#{category.projects_count})
%td= category.parent.try(:name)
%td.last
= link_to t("layout.edit"), edit_category_path(category)
|
= link_to t("layout.delete"), category_path(category), :method => :delete, :confirm => t("layout.categories.confirm_delete")

View File

@ -1,15 +0,0 @@
= form_for @category, :html => { :class => :form } do |f|
.group
= f.label :parent_id, :class => :label
= f.collection_select :parent_id, Category.roots, :id, :name, :include_blank => true
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("choose.png", :alt => t("layout.save"))
= t("layout.save")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), categories_path, :class => "text_button_padding link_button"

View File

@ -1,11 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.categories.list"), categories_path
%li= link_to t("layout.categories.platforms"), platforms_categories_path
%li= link_to t("layout.categories.new"), new_category_path
%li.active= link_to t("layout.categories.edit"), edit_category_path
.content
%h2.title= t("layout.categories.edit_header")
.inner= render "form"
- content_for :sidebar, render('sidebar')

View File

@ -1,17 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first.active= link_to t("layout.categories.list"), categories_path
%li= link_to t("layout.categories.platforms"), platforms_categories_path
%li= link_to t("layout.categories.new"), new_category_path
.content
%h2.title= t("layout.categories.list_header")
.inner
%table.table
%tr
%th= t("activerecord.attributes.category.name")
%th= t("activerecord.attributes.category.parent_id")
%th.last &nbsp;
= render @categories
.actions-bar.wat-cf
.actions= will_paginate @categories

View File

@ -1,14 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.categories.list"), categories_path
%li.active= link_to t("layout.categories.platforms"), platforms_categories_path
.content
%h2.title= @platform.name
.inner
%table.table
- @categories.each do |category|
%tr{:class => cycle("odd", "even")}
%td= link_to category.name, [@platform, category]
%td= category.parent.name
%td.last= category.projects_count

View File

@ -1,9 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to "#{t("layout.categories.list")}", @categories_path
%li= link_to t("layout.categories.platforms"), platforms_categories_path
%li.active= link_to "#{t("layout.categories.new")}", @new_category_path
.content
%h2.title= t("layout.categories.new_header")
.inner= render "form"

View File

@ -1,31 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.categories.list"), categories_path
%li.active= link_to t("layout.categories.platforms"), platforms_categories_path
.content
%h2.title= t("layout.platforms.list_header")
%br
.inner
%h3.title= t("layout.platforms.list_header_main")
%table.table
- @main_platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td= link_to platform.name, platform_categories_path(platform)
%td.last= @main_platforms_count[platform.id].to_i
%br
.inner
%h3.title= t("layout.platforms.list_header_personal")
%table.table
- @personal_platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td= link_to platform.name, platform_categories_path(platform)
%td.last= @personal_platforms_count[platform.id].to_i
%br
.inner
%h3.title= t("layout.platforms.list_header_all")
%table.table
- @all_platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td= link_to platform.name, platform_categories_path(platform)
%td.last= @all_platforms_count[platform.id].to_i

View File

@ -1,15 +0,0 @@
.block
.secondary-navigation
%ul.wat-cf
%li.first= link_to t("layout.categories.list"), categories_path
%li= link_to t("layout.categories.platforms"), platforms_categories_path
- if @platform
%li.active= link_to @platform.name, platform_categories_path(@platform)
.content
%h2.title
= @category.name
(#{@category.parent.name})
.inner
%table.table= render @projects
.actions-bar.wat-cf
.actions= will_paginate @projects

View File

@ -21,10 +21,7 @@
- else
= hidden_field_tag :who_owns, :me
.both
-#- if [:new, :create].include? act
-# .leftlist= f.label :category_id, t("activerecord.attributes.project.category_id"), :class => :label
-# .rightlist= f.grouped_collection_select :category_id, Category.roots, :children, :name, :id, :name, :include_blank => true
-# .both
.leftlist= f.label :visibility, t("activerecord.attributes.project.visibility"), :class => :label
.rightlist
=# f.select :visibility, Project::VISIBILITIES

View File

@ -93,16 +93,6 @@ en:
regenerate_btn: Regenerate
warning_message: Warning - Old data set as invalid when new data obtaining
categories:
list: List
new: Create
edit: Edit
platforms: By platform
list_header: Catalogue
new_header: New category
edit_header: Edit category
confirm_delete: Are you sure to delete this category?
collaborators:
back_to_proj: Back to project
edit: Edit list
@ -166,11 +156,6 @@ en:
successfully_added: Member %s successfully added
error_in_adding: Member %s adding error
category:
saved: Category saved
save_error: Category saves error
destroyed: Category deleted
blob:
successfully_updated: File '%{name}' successfully updated
updating_error: Error updating file '%{name}'
@ -192,7 +177,6 @@ en:
can_have_less_or_equal: You cannot have more than %{count} projects.
models:
category: Category
arch: Arch
container: Container
rpm: RPM
@ -216,10 +200,6 @@ en:
login: Login
password: Password
category:
parent_id: Parent
name: Name
arch:
name: Name
created_at: Created

View File

@ -3,7 +3,6 @@ en:
repositories: Repositories
personal_repository: My repository
products: Products
categories: Catalogue
downloads: Statistics
top_menu:
platforms: Platforms

View File

@ -1,6 +1,5 @@
ru:
menu:
categories: Каталог
products: Продукты
repositories: Репозитории
personal_repository: Мой репозиторий

View File

@ -60,7 +60,6 @@ en:
project: Project
attributes:
project:
category_id: Category
name: Name
description: Descripton
owner: Owner

View File

@ -60,7 +60,6 @@ ru:
project: Проект
attributes:
project:
category_id: Категория
name: Название
description: Описание
owner: Владелец

View File

@ -93,16 +93,6 @@ ru:
regenerate_btn: Перегенерировать
warning_message: Примечание - При получении новых данных старые становятся недействительными
categories:
list: Список
new: Создать
edit: Редактировать
platforms: По платформам
list_header: Каталог
new_header: Новая категория
edit_header: Редактировать категорию
confirm_delete: Вы уверены, что хотите удалить эту категорию?
collaborators:
back_to_proj: Вернуться к проекту
edit: Редактировать список
@ -166,11 +156,6 @@ ru:
successfully_added: Участник %s успешно добавлен
error_in_adding: Ошибка при добавлении участника %s
category:
saved: Категория успешно сохранена
save_error: Не удалось сохранить категорию
destroyed: Категория успешно удалена
blob:
successfully_updated: Файл '%{name}' успешно обновлен
updating_error: Ошибка обновления файла '%{name}'
@ -192,7 +177,6 @@ ru:
can_have_less_or_equal: Нельзя иметь больше, чем %{count} проектов.
models:
category: Категория
arch: Arch
container: Container
rpm: RPM
@ -217,10 +201,6 @@ ru:
login: Логин
password: Пароль
category:
parent_id: Родитель
name: Название
arch:
name: Название
created_at: Создана

View File

@ -44,10 +44,6 @@ Rosa::Application.routes.draw do
match 'statistics/refresh' => 'downloads#refresh', :as => :downloads_refresh
match 'statistics/test_sudo' => 'downloads#test_sudo', :as => :test_sudo_downloads
resources :categories do
get :platforms, :on => :collection
end
match '/private/:platform_name/*file_path' => 'privates#show'
match 'build_lists/publish_build', :to => "build_lists#publish_build"
@ -101,8 +97,6 @@ Rosa::Application.routes.draw do
end
resources :repositories
resources :categories, :only => [:index, :show]
end
resources :projects, :except => [:show] do
@ -198,8 +192,6 @@ Rosa::Application.routes.draw do
resources :search, :only => [:index]
match '/catalogs', :to => 'categories#platforms', :as => :catalogs
match 'product_status', :to => 'product_build_lists#status_build'
# Tree

View File

@ -0,0 +1,17 @@
class DeleteCategories < ActiveRecord::Migration
def self.up
remove_column :projects, :category_id
drop_table :categories
end
def self.down
create_table :categories, :force => true do |t|
t.string "name"
t.string "ancestry"
t.integer "projects_count", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
add_column :projects, :category_id, :integer
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120329181830) do
ActiveRecord::Schema.define(:version => 20120329182602) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -81,14 +81,6 @@ ActiveRecord::Schema.define(:version => 20120329181830) do
add_index "build_lists", ["bs_id"], :name => "index_build_lists_on_bs_id", :unique => true
add_index "build_lists", ["project_id"], :name => "index_build_lists_on_project_id"
create_table "categories", :force => true do |t|
t.string "name"
t.string "ancestry"
t.integer "projects_count", :default => 0, :null => false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "comments", :force => true do |t|
t.string "commentable_type"
t.integer "user_id"
@ -273,7 +265,6 @@ ActiveRecord::Schema.define(:version => 20120329181830) do
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
t.integer "category_id"
t.text "description"
t.string "ancestry"
t.boolean "has_issues", :default => true
@ -286,7 +277,6 @@ ActiveRecord::Schema.define(:version => 20120329181830) do
t.boolean "is_rpm", :default => true
end
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
create_table "register_requests", :force => true do |t|

View File

@ -3,137 +3,3 @@ ARCHES = %w(i386 i586 x86_64)
ARCHES.each do |arch|
Arch.find_or_create_by_name arch
end
CATEGORIES = {
:mandriva =>
%(Accessibility
Archiving/Backup
Archiving/Cd burning
Archiving/Compression
Archiving/Other
Books/Computer books
Books/Faqs
Books/Howtos
Books/Literature
Books/Other
Communications
Databases
Development/C
Development/C++
Development/Databases
Development/GNOME and GTK+
Development/Java
Development/KDE and Qt
Development/Kernel
Development/Other
Development/Perl
Development/PHP
Development/Python
Development/Ruby
Development/X11
Editors
Education
Emulators
File tools
Games/Adventure
Games/Arcade
Games/Boards
Games/Cards
Games/Other
Games/Puzzles
Games/Sports
Games/Strategy
Graphical desktop/Enlightenment
Graphical desktop/FVWM based
Graphical desktop/GNOME
Graphical desktop/Icewm
Graphical desktop/KDE
Graphical desktop/Other
Graphical desktop/Sawfish
Graphical desktop/WindowMaker
Graphical desktop/Xfce
Graphics
Monitoring
Networking/Chat
Networking/File transfer
Networking/Instant messaging
Networking/IRC
Networking/Mail
Networking/News
Networking/Other
Networking/Remote access
Networking/WWW
Office
Publishing
Sciences/Astronomy
Sciences/Biology
Sciences/Chemistry
Sciences/Computer science
Sciences/Geosciences
Sciences/Mathematics
Sciences/Other
Sciences/Physics
Shells
Sound
System/Base
System/Cluster
System/Configuration/Boot and Init
System/Configuration/Hardware
System/Configuration/Networking
System/Configuration/Other
System/Configuration/Packaging
System/Configuration/Printing
System/Fonts/Console
System/Fonts/True type
System/Fonts/Type1
System/Fonts/X11 bitmap
System/Internationalization
System/Kernel and hardware
System/Libraries
System/Printing
System/Servers
System/X11
Terminals
Text tools
Toys
Video),
:naulinux =>
%(Amusements/Games
Amusements/Graphics
Applications/Archiving
Applications/Communications
Applications/Databases
Applications/Editors
Applications/Emulators
Applications/Engineering
Applications/File
Applications/Internet
Applications/Multimedia
Applications/Productivity
Applications/Publishing
Applications/System
Applications/Text
Development/Debuggers
Development/Languages
Development/Libraries
Development/System
Development/Tools
Documentation
System Environment/Base
System Environment/Daemons
System Environment/Kernel
System Environment/Libraries
System Environment/Shells
User Interface/Desktops
User Interface/X
User Interface/X Hardware Support)
}
CATEGORIES.each do |platform_type, categories|
parent = Category.roots.find_or_create_by_name(platform_type)
categories.split("\n").each do |category|
Category.find_or_create_by_name(category) do |c|
c.parent = parent
end
end
end