Class: Admin::ProjectsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/projects_controller.rb

Instance Method Summary collapse

Instance Method Details

#deprecatedObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/admin/projects_controller.rb', line 30

def deprecated
  @search = Project.search('deprecated', filters: {
    platform: params[:platform]
  }, sort: params[:sort], order: params[:order])

  @projects = @search.records.where("status IS ? OR status = ''", nil).order('rank DESC, name DESC').paginate(page: params[:page])

  if @projects.empty?
    repo_ids = GithubRepository.with_projects.where("github_repositories.description ilike '%deprecated%'").pluck(:id)
    @projects = Project.where("status IS ? OR status = ''", nil).where(github_repository_id: repo_ids).order('rank DESC, name DESC').paginate(page: params[:page])
  end
end

#indexObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/admin/projects_controller.rb', line 18

def index
  scope = Project.maintained.without_repository_url.without_repo.most_dependents.where('latest_release_published_at > ?', 2.years.ago)
  if params[:platform].present?
    @platform = Project.platform(params[:platform].downcase).first.try(:platform)
    raise ActiveRecord::RecordNotFound if @platform.nil?
    scope = scope.platform(@platform)
  end

  @platforms = Project.without_repository_url.most_dependents.pluck('platform').compact.uniq
  @projects = scope.paginate(page: params[:page])
end

#showObject



2
3
4
# File 'app/controllers/admin/projects_controller.rb', line 2

def show
  @project = Project.find(params[:id])
end

#unmaintainedObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/admin/projects_controller.rb', line 43

def unmaintained
  @search = Project.search('maintained', filters: {
    platform: params[:platform]
  }, sort: params[:sort], order: params[:order])

  @projects = @search.records.where("status IS ? OR status = ''", nil).order('rank DESC, name DESC').paginate(page: params[:page])

  if @projects.empty?
    repo_ids = GithubRepository.with_projects.where("github_repositories.description ilike '%maintained%'").pluck(:id)
    @projects = Project.where("status IS ? OR status = ''", nil).where(github_repository_id: repo_ids).order('rank DESC, name DESC').paginate(page: params[:page])
  end
end

#updateObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/admin/projects_controller.rb', line 6

def update
  @project = Project.find(params[:id])
  if @project.update_attributes(project_params)
    @project.normalize_licenses
    @project.update_github_repo_async
    @project.github_repository.try(:update_all_info_async)
    redirect_to project_path(@project.to_param)
  else
    redirect_to admin_project_path(@project.id)
  end
end