Class: ProjectsController

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

Instance Method Summary collapse

Instance Method Details

#aboutObject



104
105
106
107
108
# File 'app/controllers/projects_controller.rb', line 104

def about
  find_project
  find_version
  send_data render_to_string(:about, layout: false), filename: "#{@project.platform.downcase}-#{@project}.ABOUT", type: 'application/text', disposition: 'attachment'
end

#bus_factorObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/projects_controller.rb', line 20

def bus_factor
  if params[:language].present?
    @language = Project.language(params[:language].downcase).first.try(:language)
    raise ActiveRecord::RecordNotFound if @language.nil?
    scope = Project.language(@language)
  else
    scope = Project
  end

  @languages = Project.bus_factor.group('projects.language').count.sort_by(&:last).reverse.first(20)
  @projects = scope.bus_factor.order('github_repositories.github_contributions_count ASC, projects.rank DESC, projects.created_at DESC').paginate(page: page_number, per_page: 20)
end

#dependent_reposObject



117
118
119
120
# File 'app/controllers/projects_controller.rb', line 117

def dependent_repos
  find_project
  @dependent_repos = @project.dependent_repositories.open_source.paginate(page: page_number)
end

#dependentsObject



110
111
112
113
114
115
# File 'app/controllers/projects_controller.rb', line 110

def dependents
  find_project
  @dependents = WillPaginate::Collection.create(page, 30, @project.dependents_count) do |pager|
    pager.replace(@project.dependent_projects(page: page_number))
  end
end

#deprecatedObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/projects_controller.rb', line 47

def deprecated
  if params[:platform].present?
    find_platform(:platform)
    raise ActiveRecord::RecordNotFound if @platform_name.nil?
    scope = Project.platform(@platform_name)
  else
    scope = Project
  end

  @platforms = Project.deprecated.group('platform').count.sort_by(&:last).reverse
  @projects = scope.deprecated.order('dependents_count DESC, rank DESC, projects.created_at DESC').paginate(page: page_number, per_page: 20)
end

#indexObject



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

def index
  if current_user
    muted_ids = params[:include_muted].present? ? [] : current_user.muted_project_ids
    @versions = current_user.all_subscribed_versions.where.not(project_id: muted_ids).where.not(published_at: nil).newest_first.includes(:project).paginate(per_page: 20, page: page_number)
    @projects = current_user.recommended_projects.limit(7)
    render 'dashboard/home'
  else
    facets = Project.facets(:facet_limit => 30)

    @languages = facets[:languages][:terms]
    @platforms = facets[:platforms][:terms]
    @licenses = facets[:licenses][:terms].reject{ |t| t.term.downcase == 'other' }
    @keywords = facets[:keywords][:terms]
  end
end

#muteObject



157
158
159
160
161
# File 'app/controllers/projects_controller.rb', line 157

def mute
  find_project
  current_user.mute(@project)
  redirect_to_back_or_default project_path(@project.to_param)
end

#removedObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/projects_controller.rb', line 60

def removed
  if params[:platform].present?
    find_platform(:platform)
    raise ActiveRecord::RecordNotFound if @platform_name.nil?
    scope = Project.platform(@platform_name)
  else
    scope = Project
  end

  @platforms = Project.removed.group('platform').count.sort_by(&:last).reverse
  @projects = scope.removed.order('dependents_count DESC, rank DESC, projects.created_at DESC').paginate(page: page_number, per_page: 20)
end

#showObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/projects_controller.rb', line 86

def show
  find_project
  if incorrect_case?
    if params[:number].present?
      return redirect_to(version_path(@project.to_param.merge(number: params[:number])), :status => :moved_permanently)
    else
      return redirect_to(project_path(@project.to_param), :status => :moved_permanently)
    end
  end
  find_version
  @dependencies = (@versions.length > 0 ? (@version || @versions.first).dependencies.includes(:project).order('project_name ASC').limit(100) : [])
  @contributors = @project.contributors.order('count DESC').visible.limit(20)
end

#sourcerankObject



100
101
102
# File 'app/controllers/projects_controller.rb', line 100

def sourcerank
  find_project
end

#tagsObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/controllers/projects_controller.rb', line 140

def tags
  find_project
  if incorrect_case?
    return redirect_to(project_tags_path(@project.to_param), :status => :moved_permanently)
  else
    if @project.github_repository.nil?
      @tags = []
    else
      @tags = @project.github_tags.published.order('published_at DESC').paginate(page: page_number)
    end
    respond_to do |format|
      format.html
      format.atom
    end
  end
end

#unlicensedObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/projects_controller.rb', line 33

def unlicensed
  if params[:platform].present?
    find_platform(:platform)
    raise ActiveRecord::RecordNotFound if @platform_name.nil?
    scope = Project.platform(@platform_name)
  else
    scope = Project
  end

  @platforms = Project.unlicensed.group('platform').count.sort_by(&:last).reverse
  order = params[:newest] ? 'projects.created_at DESC' : 'dependents_count DESC, rank DESC, projects.created_at DESC'
  @projects = scope.unlicensed.order(order).paginate(page: page_number, per_page: 20)
end

#unmaintainedObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/projects_controller.rb', line 73

def unmaintained
  if params[:platform].present?
    find_platform(:platform)
    raise ActiveRecord::RecordNotFound if @platform_name.nil?
    scope = Project.platform(@platform_name)
  else
    scope = Project
  end

  @platforms = Project.unmaintained.group('platform').count.sort_by(&:last).reverse
  @projects = scope.unmaintained.order('dependents_count DESC, rank DESC, projects.created_at DESC').paginate(page: page_number, per_page: 20)
end

#unmuteObject



163
164
165
166
167
# File 'app/controllers/projects_controller.rb', line 163

def unmute
  find_project
  current_user.unmute(@project)
  redirect_to_back_or_default project_path(@project.to_param)
end

#versionsObject



127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/controllers/projects_controller.rb', line 127

def versions
  find_project
  if incorrect_case?
    return redirect_to(project_versions_path(@project.to_param), :status => :moved_permanently)
  else
    @versions = @project.versions.newest_first.sort.paginate(page: page_number)
    respond_to do |format|
      format.html
      format.atom
    end
  end
end

#your_dependent_reposObject



122
123
124
125
# File 'app/controllers/projects_controller.rb', line 122

def your_dependent_repos
  find_project
  @dependent_repos = current_user.your_dependent_repos(@project).paginate(page: page_number)
end