Add categories and apply basic CRUD actions. Add category link and description to project. Apply category assign to project. Apply categorization with platforms. Integrate to common design and layout. Import basic categories structure. Refs #1858

This commit is contained in:
Pavel Chipiga 2011-10-19 23:58:31 +03:00
parent 099120e71b
commit 5291752419
24 changed files with 413 additions and 2 deletions

View File

@ -55,3 +55,5 @@ gem 'delayed_job'
gem 'paperclip', "~> 2.3"
gem 'jammit'
gem 'ancestry', '~> 1.2.4'

View File

@ -31,6 +31,8 @@ GEM
airbrake (3.0.4)
activesupport
builder
ancestry (1.2.4)
activerecord (>= 2.2.2)
arel (2.0.9)
bcrypt-ruby (2.1.4)
builder (2.1.2)
@ -148,6 +150,7 @@ PLATFORMS
DEPENDENCIES
airbrake
ancestry (~> 1.2.4)
capistrano
capistrano-ext
compass (>= 0.10.6)

View File

@ -0,0 +1,71 @@
class CategoriesController < ApplicationController
before_filter :authenticate_user!
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
before_filter :find_platform, :only => [:show, :index]
def platforms
@platforms = Platform.all
@platforms_count = Platform.joins(:repositories => :projects).group('platforms.id').count
end
def index
if @platform
@categories = Category.joins(:projects => :repositories).where('repositories.platform_id = ?', @platform.id).
having('count(projects.id) > 0').group('categories.id').default_order
@categories_count = @categories.count
render 'index2'
else
@categories = Category.default_order.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

9
app/models/category.rb Normal file
View File

@ -0,0 +1,9 @@
class Category < ActiveRecord::Base
has_many :projects, :dependent => :nullify
validates :name, :presence => true
scope :default_order, order('categories.name')
has_ancestry
end

View File

@ -1,4 +1,5 @@
class Project < ActiveRecord::Base
belongs_to :category, :counter_cache => true
belongs_to :owner, :polymorphic => true
has_many :build_lists, :dependent => :destroy

View File

@ -0,0 +1,9 @@
%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

@ -0,0 +1,15 @@
= 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("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"), categories_path, :class => "text_button_padding link_button"

View File

View File

@ -0,0 +1,11 @@
.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

@ -0,0 +1,17 @@
.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

@ -0,0 +1,14 @@
.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= @categories_count[category.id].to_i

View File

@ -0,0 +1,9 @@
.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

@ -0,0 +1,13 @@
.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")
.inner
%table.table
- @platforms.each do |platform|
%tr{:class => cycle("odd", "even")}
%td= link_to platform.name, platform_categories_path(platform)
%td.last= @platforms_count[platform.id].to_i

View File

@ -0,0 +1,15 @@
.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

@ -24,6 +24,9 @@
%a{:href => groups_path}= t("layout.menu.groups")
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
%a{:href => platforms_path}= t("layout.menu.platforms")
%li{:class => controller.controller_path == 'categories' ? 'active' : '' }
%a{:href => categories_path}= t("layout.menu.categories")
#wrapper.wat-cf
= render :partial => "layouts/flashes"
#main

View File

@ -1,9 +1,15 @@
.group
= f.label :category_id, t("activerecord.attributes.project.category_id"), :class => :label
= f.grouped_collection_select :category_id, Category.roots, :children, :name, :id, :name, :include_blank => true
.group
= f.label :name, t("activerecord.attributes.project.name"), :class => :label
= f.text_field :name, :class => 'text_field'
.group
= f.label :unixname, t("activerecord.attributes.project.unixname"), :class => :label
= f.text_field :unixname, :class => 'text_field'
.group
= f.label :description, t("activerecord.attributes.project.description"), :class => :label
= f.text_area :description, :class => 'text_field', :cols => 80
.group.navform.wat-cf
%button.button{:type => "submit"}

View File

@ -0,0 +1,4 @@
%tr{:class => cycle("odd", "even")}
%td= link_to project.name, project_path(project)
%td= project.unixname
%td= project.description

View File

@ -35,10 +35,21 @@ ru:
users: Пользователи
platforms: Платформы
groups: Группы
categories: Категории
sessions:
sign_in_header: Вход в систему
categories:
list: Список
new: Создать
edit: Редактировать
platforms: По платформам
list_header: Категории
new_header: Новая категория
edit_header: Редактировать категорию
confirm_delete: Вы уверены, что хотите удалить эту категорию?
platforms:
list: Список
new: Создать
@ -189,6 +200,11 @@ ru:
branch_not_found: бранч не найден
flash:
category:
saved: Категория успешно сохранена
save_error: Не удалось сохранить категорию
destroyed: Категория успешно удалена
project:
saved: Проект успешно сохранен
save_error: Не удалось сохранить проект
@ -242,6 +258,7 @@ ru:
activerecord:
models:
category: Категория
repository: Репозиторий
arch: Arch
container: Container
@ -255,6 +272,10 @@ ru:
build_list_item: Элемент сборочного листа
attributes:
category:
parent_id: Родитель
name: Название
repository:
name: Название
platform_id: Платформа
@ -304,8 +325,10 @@ ru:
updated_at: Обновлена
project:
category_id: Категория
name: Название
unixname: Unixname
description: Описание
owner: Владелец
visibility: Видимость
repository_id: Репозиторий

View File

@ -1,6 +1,10 @@
Rosa::Application.routes.draw do
devise_for :users
resources :categories do
get :platforms, :on => :collection
end
# resources :platforms do
# member do
# get 'freeze'
@ -53,6 +57,8 @@ Rosa::Application.routes.draw do
resources :repositories do
end
resources :categories, :only => [:index, :show]
end
resources :projects do

View File

@ -0,0 +1,15 @@
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.string :ancestry
t.integer :projects_count, :default => 0, :null => false
t.timestamps
end
end
def self.down
drop_table :categories
end
end

View File

@ -0,0 +1,14 @@
class AddCategoryIdAndDescriptionToProjects < ActiveRecord::Migration
def self.up
change_table :projects do |t|
t.references :category
t.text :description
end
add_index :projects, :category_id
end
def self.down
remove_column :projects, :description
remove_column :projects, :category_id
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111016225240) do
ActiveRecord::Schema.define(:version => 20111017172701) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -50,6 +50,14 @@ ActiveRecord::Schema.define(:version => 20111016225240) 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 "containers", :force => true do |t|
t.string "name", :null => false
t.integer "project_id", :null => false
@ -137,9 +145,13 @@ ActiveRecord::Schema.define(:version => 20111016225240) do
t.datetime "updated_at"
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
t.string "visibility", :default => "open"
t.integer "category_id"
t.text "description"
end
add_index "projects", ["category_id"], :name => "index_projects_on_category_id"
create_table "relations", :force => true do |t|
t.integer "object_id"
t.string "object_type"

View File

@ -37,3 +37,137 @@ ARCHES = %w(i586 i686 x86_64 mips powerpc)
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

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Category do
pending "add some examples to (or delete) #{__FILE__}"
end