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

5 6 7
  before_action :require_non_empty_project
  before_action :assign_ref_vars
  before_action :authorize_download_code!
gitlabhq's avatar
gitlabhq committed
8

9 10 11
  def switch
    respond_to do |format|
      format.html do
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
        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
27

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

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

46
    @limit = 25
47 48 49 50

    @path = params[:path]

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

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

64 65 66 67 68
    if @logs.present?
      @log_url = namespace_project_tree_url(@project.namespace, @project, tree_join(@ref, @path || '/'))
      @more_log_url = logs_file_namespace_project_ref_path(@project.namespace, @project, @ref, @path || '', offset: (@offset +  @limit))
    end

69 70 71 72
    respond_to do |format|
      format.html { render_404 }
      format.js
    end
73
  end
gitlabhq's avatar
gitlabhq committed
74
end