refs_controller.rb 1.2 KB
Newer Older
1
class Projects::RefsController < Projects::ApplicationController
Sato Hiroyuki's avatar
Sato Hiroyuki committed
2
  include ExtractsPath
gitlabhq's avatar
gitlabhq committed
3 4 5

  # Authorize
  before_filter :authorize_read_project!
6
  before_filter :authorize_code_access!
gitlabhq's avatar
gitlabhq committed
7 8
  before_filter :require_non_empty_project

9 10 11
  def switch
    respond_to do |format|
      format.html do
12
        new_path = if params[:destination] == "tree"
Sato Hiroyuki's avatar
Sato Hiroyuki committed
13
                     project_tree_path(@project, (@id))
14
                   elsif params[:destination] == "blob"
Sato Hiroyuki's avatar
Sato Hiroyuki committed
15
                     project_blob_path(@project, (@id))
16
                   elsif params[:destination] == "graph"
17
                     project_network_path(@project, @id, @options)
18
                   else
Sato Hiroyuki's avatar
Sato Hiroyuki committed
19
                     project_commits_path(@project, @id)
20
                   end
gitlabhq's avatar
gitlabhq committed
21

22
        redirect_to new_path
23
      end
24
      format.js do
25 26
        @ref = params[:ref]
        define_tree_vars
27
        tree
28 29 30
        render "tree"
      end
    end
gitlabhq's avatar
gitlabhq committed
31 32
  end

33
  def logs_tree
34
    contents = tree.entries
35 36
    @logs = contents.map do |content|
      file = params[:path] ? File.join(params[:path], content.name) : content.name
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
37
      last_commit = @repo.commits(@commit.id, file, 1).last
38
      {
39
        file_name: content.name,
40
        commit: last_commit
41 42 43
      }
    end
  end
gitlabhq's avatar
gitlabhq committed
44
end