refs_controller.rb 1.77 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 6
  before_action :require_non_empty_project
  before_action :assign_ref_vars
  before_action :authorize_download_code!
gitlabhq's avatar
gitlabhq committed
7

8 9 10
  def switch
    respond_to do |format|
      format.html do
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
        new_path =
          case params[:destination]
          when "tree"
            namespace_project_tree_path(@project.namespace, @project, @id)
          when "blob"
            namespace_project_blob_path(@project.namespace, @project, @id)
          when "graph"
            namespace_project_network_path(@project.namespace, @project, @id, @options)
          when "graphs"
            namespace_project_graph_path(@project.namespace, @project, @id)
          when "graphs_commits"
            commits_namespace_project_graph_path(@project.namespace, @project, @id)
          else
            namespace_project_commits_path(@project.namespace, @project, @id)
          end
gitlabhq's avatar
gitlabhq committed
26

27
        redirect_to new_path
28
      end
29
      format.js do
30 31
        @ref = params[:ref]
        define_tree_vars
32
        tree
33 34 35
        render "tree"
      end
    end
gitlabhq's avatar
gitlabhq committed
36 37
  end

38
  def logs_tree
39
    @offset = if params[:offset].present?
40 41 42 43
                params[:offset].to_i
              else
                0
              end
44

45
    @limit = 25
46 47 48 49

    @path = params[:path]

    contents = []
50 51 52
    contents.push(*tree.trees)
    contents.push(*tree.blobs)
    contents.push(*tree.submodules)
53 54 55

    @logs = contents[@offset, @limit].to_a.map do |content|
      file = @path ? File.join(@path, content.name) : content.name
56
      last_commit = @repo.last_commit_for_path(@commit.id, file)
57
      {
58
        file_name: content.name,
59
        commit: last_commit
60 61
      }
    end
62 63 64 65 66

    respond_to do |format|
      format.html { render_404 }
      format.js
    end
67
  end
gitlabhq's avatar
gitlabhq committed
68
end