modify project model, add project controller for project page

This commit is contained in:
duratarskeyk 2015-12-12 18:19:02 +00:00
parent ad21c2146f
commit bdb6458393
29 changed files with 127 additions and 177 deletions

View File

@ -102,6 +102,10 @@ end
gem 'rack-utf8_sanitizer'
gem 'web-console', '~> 2.0'
#github api
gem 'github_api'
gem 'faraday-http-cache'
group :production do
gem 'airbrake'
#gem 'bluepill', '~> 0.0.60', require: false

View File

@ -164,6 +164,8 @@ GEM
creole (0.5.0)
daemons (1.2.2)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.5.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@ -188,6 +190,8 @@ GEM
railties (>= 3.0.0)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
faraday-http-cache (1.2.2)
faraday (~> 0.8)
ffi (1.9.8)
font-awesome-rails (4.3.0.0)
railties (>= 3.2, < 5.0)
@ -205,6 +209,14 @@ GEM
rugged (~> 0.21.0)
github-markup (1.1.2)
posix-spawn (~> 0.3.8)
github_api (0.13.0)
addressable (~> 2.3)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.4)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.6)
oauth2
gitlab-grit (2.6.12)
charlock_holmes (~> 0.6)
diff-lcs (~> 1.1)
@ -637,6 +649,11 @@ GEM
rack (>= 1.0.0)
warden (1.2.3)
rack (>= 1.0)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
webmock (1.21.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
@ -681,11 +698,13 @@ DEPENDENCIES
devise
diff-display
factory_girl_rails
faraday-http-cache
ffi
font-awesome-rails
friendly_id
gemoji
github-linguist (= 3.1.5)
github_api
gollum-lib (~> 3.0)
grack!
grit!
@ -756,8 +775,12 @@ DEPENDENCIES
timecop
uglifier
underscore-rails
web-console (~> 2.0)
webmock
whenever
wikicloth
will_paginate
zeroclipboard-rails
BUNDLED WITH
1.10.6

View File

@ -36,53 +36,6 @@ class HomeController < ApplicationController
activity(true)
end
def issues
@created_issues = current_user.issues
@assigned_issues = Issue.where(assignee_id: current_user.id)
@all_issues = ProjectPolicy::Scope.new(current_user, Issue).membered.uniq.joins(:project)
@created_issues, @assigned_issues, @all_issues =
if action_name == 'issues'
[@created_issues.without_pull_requests,
@assigned_issues.without_pull_requests,
@all_issues.without_pull_requests]
else
[@created_issues.joins(:pull_request),
@assigned_issues.joins(:pull_request),
@all_issues.joins(:pull_request)]
end
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
params[:filter] = 'all' # default
@issues = @all_issues
end
@filter = params[:filter]
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
@status = params[:status] == 'closed' ? :closed : :open
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
@sort = params[:sort] == 'updated' ? :updated : :created
@direction = params[:direction] == 'asc' ? :asc : :desc
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
.includes(:assignee, :user, :pull_request).uniq
.paginate page: current_page
respond_to do |format|
format.html { render 'activity' }
format.json { render 'issues' }
end
end
def pull_requests
issues
end
def get_owners_list
if params[:term].present?
users = User.opened.search(params[:term]).first(5)

View File

@ -19,8 +19,8 @@ class Projects::BaseController < ApplicationController
def init_statistics
if @project
@opened_issues_count = @project.issues.without_pull_requests.not_closed_or_merged.count
@opened_pull_requests_count = @project.issues.joins(:pull_request).not_closed_or_merged.count
#@opened_issues_count = @project.issues.without_pull_requests.not_closed_or_merged.count
#@opened_pull_requests_count = @project.issues.joins(:pull_request).not_closed_or_merged.count
end
end
end

View File

@ -14,6 +14,7 @@ class Projects::BuildListsController < Projects::BaseController
def index
authorize :build_list
params[:filter].each{|k,v| params[:filter].delete(k) if v.blank? } if params[:filter]
@project.fetch_github_repo_data unless not @project
respond_to do |format|
format.html
@ -42,6 +43,7 @@ class Projects::BuildListsController < Projects::BaseController
def new
authorize @build_list = @project.build_lists.build
@project.fetch_github_repo_data unless not @project
if params[:show] == 'inline' && params[:build_list_id].present?
render json: new_build_list_data(@build_list, @project, params), layout: false
else
@ -66,7 +68,6 @@ class Projects::BuildListsController < Projects::BaseController
@build_list.user = current_user
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
flash_options = { project_version: @build_list.project_version, arch: arch.name, build_for_platform: build_for_platform.name }
authorize @build_list
if @build_list.save

View File

@ -1,5 +1,6 @@
class Projects::Project::ProjectController < Projects::Project::BaseController
def index
console
authorize @project
(render :error_github) if not @project.github_data
end
end

View File

@ -7,6 +7,7 @@ class Projects::ProjectsController < Projects::BaseController
def index
authorize :project
Project.fetch_github_data_on_find = false
@projects = ProjectPolicy::Scope.new(current_user, Project).membered.search(params[:search])
respond_to do |format|
format.html {

View File

@ -87,6 +87,12 @@ class BuildList < ActiveRecord::Base
before_validation :prepare_extra_build_lists, on: :create
before_validation :prepare_extra_params, on: :create
before_validation :prepare_auto_publish_status, on: :create
after_validation -> {
errors.each do |x, y|
puts x
puts y
end
}
LIVE_TIME = 4.week # for unpublished
MAX_LIVE_TIME = 3.month # for published

View File

@ -19,22 +19,13 @@ class Project < ActiveRecord::Base
belongs_to :owner, polymorphic: true, counter_cache: :own_projects_count
belongs_to :maintainer, class_name: 'User'
belongs_to :alias_from, class_name: 'Project'
has_many :aliases, class_name: 'Project', foreign_key: 'alias_from_id'
has_many :issues, dependent: :destroy
has_many :pull_requests, dependent: :destroy, foreign_key: 'to_project_id'
has_many :labels, dependent: :destroy
has_many :build_scripts, dependent: :destroy
has_many :project_imports, dependent: :destroy
has_many :project_to_repositories, dependent: :destroy
has_many :repositories, through: :project_to_repositories
has_many :project_tags, dependent: :destroy
has_many :project_statistics, dependent: :destroy
has_many :build_lists, dependent: :destroy
has_many :hooks, dependent: :destroy
has_many :relations, as: :target, dependent: :destroy
has_many :collaborators, through: :relations, source: :actor, source_type: 'User'
@ -69,13 +60,23 @@ class Project < ActiveRecord::Base
before_create :set_maintainer
after_save :attach_to_personal_repository
after_update -> { update_path_to_project(name_was) }, if: :name_changed?
after_find :fetch_github_repo_data
attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id
attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id, :github_data
def init_mass_import
Project.perform_later :low, :run_mass_import, url, srpms_list, visibility, owner, add_to_repository_id
end
def fetch_github_repo_data
org = github_organization || APP_CONFIG["github_organization"]
begin
@github_data = Github.repos.get user: org, repo: name
rescue
@github_data = nil
end
end
def name_with_owner
"#{owner_uname || owner.uname}/#{name}"
end
@ -104,6 +105,12 @@ class Project < ActiveRecord::Base
@platforms ||= repositories.map(&:platform).uniq
end
def in_main_platform?
platforms.map do |platform|
platform.platform_type
end.include?('main')
end
def admins
admins = self.collaborators.where("relations.role = 'admin'")
grs = self.groups.where("relations.role = 'admin'")
@ -166,20 +173,6 @@ class Project < ActiveRecord::Base
build_list.save
end
def fork(new_owner, new_name: nil, is_alias: false)
new_name = new_name.presence || name
dup.tap do |c|
c.name = new_name
c.parent_id = id
c.alias_from_id = is_alias ? (alias_from_id || id) : nil
c.owner = new_owner
c.updated_at = nil; c.created_at = nil # :id = nil
# Hack to call protected method :)
c.send :set_maintainer
c.save
end
end
def get_project_tag_sha1(tag, format)
format_id = ProjectTag::FORMATS["#{tag_file_format(format)}"]
project_tag = project_tags.where(tag_name: tag.name, format_id: format_id).first

View File

@ -77,6 +77,7 @@ class ProjectPolicy < ApplicationPolicy
def permitted_attributes
%i(
add_to_repository_id
github_organization
architecture_dependent
autostart_status
default_branch

View File

@ -5,10 +5,6 @@ ul.nav.nav-tabs.nav-justified.boffset10[ role = 'tablist' ]
- if policy(@project).edit?
li[ class = "#{(act == :edit && contr == :projects) ? 'active' : ''}" ]
= link_to t("layout.projects.edit"), edit_project_path(@project)
li[ class = "#{(act == :sections && contr == :projects) ? 'active' : ''}" ]
= link_to t("layout.projects.sections"), sections_project_path(@project)
li[ class = "#{(contr == :hooks) ? 'active' : ''}" ]
= link_to t("layout.projects.hooks"), project_hooks_path(@project)
- if policy(@project).manage_collaborators?
li[ class = "#{(act == :index && contr == :collaborators) ? 'active' : ''}" ]
= link_to t("layout.projects.edit_collaborators"), project_collaborators_path(@project)

View File

@ -1,5 +1,7 @@
- content_for :submenu do
- act = action_name.to_sym; contr = controller_name.to_sym; treeish = @project.default_head(params[:treeish])
- github_success = @project.github_data != nil
- github_base_url = @project.github_data.html_url unless not github_success
nav.navbar.navbar-default role='navigation'
.container-fluid ng-cloak = true
/ Brand and toggle get grouped for better mobile display
@ -17,38 +19,31 @@
/ Collect the nav links, forms, and other content for toggling
#submenu-navbar-collapse.collapse.navbar-collapse
ul.nav.navbar-nav.left-border
- if @project.parent
- is_alias = @project.alias_from_id.present?
- tooltip_title = t(".tooltips.#{is_alias ? 'alias' : 'fork' }", name: @project.parent.name_with_owner)
li data-toggle='tooltip' data-placement='bottom' title=tooltip_title
= link_to project_path(@project.parent), class: 'small' do
- if is_alias
= fa_icon 'share-alt'
- else
= fa_icon 'code-fork'
=< @project.parent.name_with_owner
li class=('active' if act.in?([:show, :edit, :branches, :tags]) && contr.in?([:trees, :blobs]) || contr == :commits)
a href=tree_path(@project, treeish)
li class=('active' if act == :index && contr == :project)
a href=("/"+@project.name_with_owner)
i.fa.fa-files-o>
= t('project_menu.code')
= t("project_menu.project")
- if @project.is_package
li class=('active' if contr == :build_lists)
a href=project_build_lists_path(@project)
i.fa.fa-cogs>
= t('project_menu.builds')
- if @project.has_issues
li class=('active' if contr == :issues && act == :index)
a href=project_issues_path(@project)
- if github_success and @project.github_data.has_issues
li
a href=(github_base_url + "/issues") target="_blank"
i.fa.fa-exclamation-circle>
= t('project_menu.tracker', count: @opened_issues_count)
li class=('active' if contr == :issues && act == :pull_requests)
a href=project_pull_requests_path(@project)
= t('project_menu.tracker', count: @project.github_data.open_issues_count)
- if github_success
li
a href=(github_base_url + "/pulls") target="_blank"
i.fa.fa-tasks>
= t('project_menu.pull_requests', count: @opened_pull_requests_count)
- if @project.has_wiki
li class=('active' if contr == :wiki)
= link_to t('project_menu.wiki'), project_wiki_index_path(@project)
= t('project_menu.pull_requests')
- if github_success and @project.github_data.has_wiki
li
a href=(github_base_url + "/wiki") target="_blank"
i.fa.fa-book>
= t('project_menu.wiki')
/ li
/ = link_to t('project_menu.readme'), '#' #pending
- if policy(@project).update?

View File

@ -118,7 +118,7 @@ row[ ng-controller='BuildListController'
tr
td= t('activerecord.attributes.build_list.project_version')
td= link_to @build_list.project_version, tree_path(@build_list.project, @build_list.project_version)
-# td= link_to @build_list.project_version, tree_path(@build_list.project, @build_list.project_version)
tr
td= t('diff')

View File

@ -1,5 +0,0 @@
%ol.breadcrumb
%li= link_to @project.name, tree_path(@project, treeish: @treeish), 'ng-click' => "getTree($event, '')"
%li{ 'ng-repeat' => 'el in breadcrumb.paths' }
%a{ href: '#', 'ng-click' => 'getTree($event, el.path)' } {{el.name}}
%li.active {{breadcrumb.last}}

View File

@ -4,5 +4,3 @@
description: truncate(@project.description, length: 255) }
- set_meta_tags twitter: { title: title,
description: truncate(@project.description, length: 200) }
== render partial: "show", layout: 'layout'

View File

@ -1 +0,0 @@
hello world

View File

@ -0,0 +1,4 @@
=render 'submenu'
.col-xs-12.col-md-10.col-md-offset-1
.row
.alert.alert-danger.text-center=t('layout.projects.no_github_repo_error', organization:@project.github_data || APP_CONFIG['github_organization'])

View File

@ -0,0 +1,3 @@
.container
.row
.alert.alert-danger.text-center=t('layout.projects.only_personal_error')

View File

@ -0,0 +1,14 @@
-title = title_object(@project)
-set_meta_tags title: "#{title}"
-set_meta_tags og: { title: title,
description: truncate(@project.github_data.description, length: 255) }
-set_meta_tags twitter: { title: title,
description: truncate(@project.github_data.description, length: 200) }
=render 'submenu'
.col-xs-12.col-md-10.col-md-offset-1
.row
%h3=@project.name
%a{:href => @project.github_data.html_url, :target => "_blank"}=t("layout.projects.github_link")
%hr
=@project.github_data.description

View File

@ -2,6 +2,7 @@
div ng-controller = 'ProjectFromController' ng-cloak = 'true'
= f.input :name
= f.input :description, as: :text
= f.input :github_organization
- if [:new, :create].include? act
= render 'owner', f: f
@ -10,11 +11,6 @@ div ng-controller = 'ProjectFromController' ng-cloak = 'true'
collection: project_visibility_options,
include_blank: false
- if [:edit, :update].include? act
= f.input :default_branch,
collection: @project.repo.branches.map(&:name),
selected: @project.default_branch
= f.input :is_package, as: :boolean,
input_html: { 'ng-model' => 'project.is_package',
'ng-change' => 'project.publish_i686_into_x86_64 = false' }

View File

@ -11,9 +11,6 @@
== render "form", f: f
== render 'build_schedule'
- if @project_aliases.present?
hr.col-sm-12
== render 'aliases'
hr.col-sm-12
.col-sm-9.col-sm-offset-3

View File

@ -67,6 +67,6 @@ module Rosa
config.log_redis = false
config.angular_templates.ignore_prefix = 'angularjs/templates/'
config.web_console.whitelisted_ips = '192.168.0.0/16'
config.web_console.whitelisted_ips = '127.0.0.0/24'
end
end

View File

@ -2,7 +2,7 @@ Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
config.cache_classes = false
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers

View File

@ -25,7 +25,7 @@ en:
abf_blog_url: http://abf-blog.rosalinux.ru
abf_ideas: ABF Ideas
project_menu:
code: Code
project: Project
files: Files
commits: Commits
branches: Branches (%{count})
@ -35,7 +35,7 @@ en:
wiki: Wiki
readme: Readme
settings: Settings
pull_requests: Pull Requests (%{count})
pull_requests: Pull Requests
activity_menu:
activity_feed: Activity Feed
tracker: Tracker

View File

@ -25,7 +25,7 @@ ru:
abf_blog_url: http://abf-blog.rosalinux.ru
abf_ideas: Идеи для ABF
project_menu:
code: Код
project: Проект
files: Файлы
commits: Коммиты
branches: Ветки (%{count})
@ -35,7 +35,7 @@ ru:
wiki: Wiki
readme: Readme
settings: Настройки
pull_requests: Пул реквесты (%{count})
pull_requests: Пул реквесты
activity_menu:
activity_feed: Лента активности
tracker: Трекер

View File

@ -70,6 +70,9 @@ en:
create_repository: Create Repository
move_files_to_folder: Move files you need to the project or create them.
existing_git_repo: Git repo already exist?
only_personal_error: This project doesn't belong to any main architecture
no_github_repo_error: This project doesn't exist in %{organization} on github
github_link: Link on Github
git_help:
cloning: Cloning the repository

View File

@ -71,6 +71,9 @@ ru:
create_repository: Создание репозитория
move_files_to_folder: Переместите нужные файлы в проект или создайте их.
existing_git_repo: Git репозиторий уже существует?
only_personal_error: Этот проект не принадлежит никакой основной архитектуре
no_github_repo_error: Этот проект не существует в %{organization} на
github_link: Ссылка на Гитхабе
diff_show_header: "%{files} с %{additions} и %{deletions}."
about_subheader: "О проекте"

View File

@ -302,55 +302,12 @@ Rails.application.routes.draw do
end
scope '*name_with_owner', name_with_owner: Project::OWNER_AND_NAME_REGEXP do # project
scope as: 'project' do
resources :wiki do
collection do
match '_history' => 'wiki#wiki_history', as: :history, via: :get
match '_access' => 'wiki#git', as: :git, via: :get
match '_revert/:sha1/:sha2' => 'wiki#revert_wiki', as: :revert, via: [:get, :post]
match '_compare' => 'wiki#compare_wiki', as: :compare, via: :post
#match '_compare/:versions' => 'wiki#compare_wiki', versions: /.*/, as: :compare_versions, via: :get
match '_compare/:versions' => 'wiki#compare_wiki', versions: /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, as: :compare_versions, via: :get
post :preview
get :search
get :pages
end
member do
get :history
get :edit
match 'revert/:sha1/:sha2' => 'wiki#revert', as: :revert_page, via: [:get, :post]
match ':ref' => 'wiki#show', as: :versioned, via: :get
post :compare
#match 'compare/*versions' => 'wiki#compare', as: :compare_versions, via: :get
match 'compare/:versions' => 'wiki#compare', versions: /([a-f0-9\^]{6,40})(\.\.\.[a-f0-9\^]{6,40})/, as: :compare_versions, via: :get
end
end
resources :issues, except: [:destroy, :edit] do
resources :comments, only: [:edit, :create, :update, :destroy]
post '/subscribe' => "subscribes#create", as: :subscribe
delete '/unsubscribe' => "subscribes#destroy", as: :unsubscribe
collection do
post :create_label
get :search_collaborators
end
end
get 'pull_requests' => 'issues#pull_requests', as: :pull_requests
get 'labels' => 'issues#labels', as: :labels
post 'labels/:label_id' => 'issues#destroy_label', as: :issues_delete_label
post 'labels/:label_id/update' => 'issues#update_label', as: :issues_update_label
resources :build_lists, only: [:index, :new, :create] do
get :list, on: :collection
end
resources :collaborators do
get :find, on: :collection
end
resources :hooks, except: :show
resources :pull_requests, except: [:index, :destroy] do
get :autocomplete_to_project, on: :collection
put :merge, on: :member
end
post '/preview' => 'projects#preview', as: 'md_preview'
post 'refs_list' => 'projects#refs_list', as: 'refs_list'
put 'schedule' => 'projects#schedule'
@ -362,14 +319,16 @@ Rails.application.routes.draw do
patch '/' => 'projects#update'
delete '/' => 'projects#destroy'
# Member
post '/fork' => 'projects#fork', as: :fork_project
post '/alias' => 'projects#alias', as: :alias_project
get '/possible_forks' => 'projects#possible_forks', as: :possible_forks_project
get '/sections' => 'projects#sections', as: :sections_project
patch '/sections' => 'projects#sections'
delete '/remove_user' => 'projects#remove_user', as: :remove_user_project
get '/' => 'project/project#index'
get '/' => 'project/project#index', as: :project
get '/tree' => 'project/project#index', as: :tree
get '/tree2' => 'project/project#index', as: :project_issues
get '/tree3' => 'project/project#index', as: :project_pull_requests
get '/tree4' => 'project/project#index', as: :archive
get '/tree5' => 'project/project#index', as: :commits
get '/tree6' => 'project/project#index', as: :branch
get '/tree7' => 'project/project#index', as: :tags
end
end

View File

@ -0,0 +1,5 @@
class AddGithubOrganizationToProjects < ActiveRecord::Migration
def change
add_column :projects, :github_organization, :string
end
end