BigW Consortium Gitlab

refs_controller.rb 1.45 KB
Newer Older
1
class Projects::RefsController < Projects::ApplicationController
2
  include ExtractsPath
gitlabhq committed
3 4 5

  # Authorize
  before_filter :authorize_read_project!
6
  before_filter :authorize_code_access!
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"
13
                     project_tree_path(@project, (@id))
14
                   elsif params[:destination] == "blob"
15
                     project_blob_path(@project, (@id))
16
                   elsif params[:destination] == "graph"
17
                     project_network_path(@project, @id, @options)
18
                   else
19
                     project_commits_path(@project, @id)
20
                   end
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 committed
31 32
  end

33
  def logs_tree
34 35 36 37 38 39
    @offset = if params[:offset].present?
             params[:offset].to_i
           else
             0
           end

40
    @limit = 25
41 42 43 44 45 46 47 48 49 50

    @path = params[:path]

    contents = []
    contents += tree.trees
    contents += tree.blobs
    contents += tree.submodules

    @logs = contents[@offset, @limit].to_a.map do |content|
      file = @path ? File.join(@path, content.name) : content.name
51
      last_commit = @repo.last_commit_for_path(@commit.id, file)
52
      {
53
        file_name: content.name,
54
        commit: last_commit
55 56 57
      }
    end
  end
gitlabhq committed
58
end