Class: RepositoriesController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

can_access?, permission_mappings, set_access_control

Instance Method Details

- (Object) create



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'frontend/app/controllers/repositories_controller.rb', line 37

def create
  generate_names(params[:repository])
  handle_crud(:instance => :repository,
              :model => JSONModel(:repository_with_agent),
              :on_invalid => ->(){
                if @exceptions[:errors]["repo_code"]
                  @exceptions[:errors]["repository/repo_code"] = @exceptions[:errors].delete("repo_code")
                end

                return render_aspace_partial :partial => "repositories/new" if inline?
                return render :action => :new
              },
              :on_valid => ->(id){
                MemoryLeak::Resources.refresh(:repository)

                return render :json => @repository.to_hash if inline?
          
                flash[:success] = I18n.t("repository._frontend.messages.created", JSONModelI18nWrapper.new(:repository => @repository))
                return redirect_to :controller => :repositories, :action => :new, :last_repo_id => id if params.has_key?(:plus_one)
          
                redirect_to :controller => :repositories, :action => :show, :id => id
              })
end

- (Object) delete



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'frontend/app/controllers/repositories_controller.rb', line 95

def delete
  repository = JSONModel(:repository).find(params[:id])
  begin
    repository.delete
  rescue ConflictException => e
    flash[:error] = I18n.t("repository._frontend.messages.cannot_delete_nonempty")
    return redirect_to(:controller => :repositories, :action => :show, :id => params[:id])
  end

  MemoryLeak::Resources.refresh(:repository)

  flash[:success] = I18n.t("repository._frontend.messages.deleted", JSONModelI18nWrapper.new(:repository => repository))
  redirect_to(:controller => :repositories, :action => :index, :deleted_uri => repository.uri)
end

- (Object) edit



61
62
63
# File 'frontend/app/controllers/repositories_controller.rb', line 61

def edit
  @repository = JSONModel(:repository_with_agent).find(params[:id])
end

- (Object) generate_names(repository_with_agent)



24
25
26
27
28
29
30
31
32
33
34
# File 'frontend/app/controllers/repositories_controller.rb', line 24

def generate_names(repository_with_agent)
  name = JSONModel(:name_corporate_entity).new
  name['primary_name'] = repository_with_agent['repository']['name'].blank? ? '<generated>' : repository_with_agent['repository']['name']
  name['source'] = 'local'
  name['sort_name'] = name['primary_name']

  repository_with_agent['agent_representation']['names'] = [name]
  if repository_with_agent['agent_representation']['agent_contacts']['0']['name'].blank?
    repository_with_agent['agent_representation']['agent_contacts']['0']['name'] = name['primary_name']
  end
end

- (Object) index



11
12
13
14
# File 'frontend/app/controllers/repositories_controller.rb', line 11

def index
  @search_data = Search.global(params_for_backend_search.merge({"facet[]" => []}),
                               "repositories")
end

- (Object) new



16
17
18
19
20
21
# File 'frontend/app/controllers/repositories_controller.rb', line 16

def new
  @repository = JSONModel(:repository_with_agent).new('repository' => {},
                                                      'agent_representation' => {
                                                        'agent_contacts' => [{}]
                                                      })._always_valid!
end

- (Object) run_transfer



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'frontend/app/controllers/repositories_controller.rb', line 117

def run_transfer
  old_uri = JSONModel(:repository).uri_for(params[:id])
  response = JSONModel::HTTP.post_form(JSONModel(:repository).uri_for(params[:id]) + "/transfer",
                                       "target_repo" => params[:ref])

  if response.code == '200'
    flash[:success] = I18n.t("actions.transfer_successful")
    redirect_to(:action => :index)
  else
    @transfer_errors = ASUtils.json_parse(response.body)['error']
    return transfer
  end

end

- (Object) select



85
86
87
88
89
90
91
92
93
# File 'frontend/app/controllers/repositories_controller.rb', line 85

def select
  selected = @repositories.find {|r| r.id.to_s == params[:id]}
  self.class.session_repo(session, selected.uri)
  set_user_repository_cookie selected.uri

  flash[:success] = I18n.t("repository._frontend.messages.changed", JSONModelI18nWrapper.new(:repository => selected))

  redirect_to :root
end

- (Object) show



80
81
82
83
# File 'frontend/app/controllers/repositories_controller.rb', line 80

def show
  @repository = JSONModel(:repository_with_agent).find(params[:id])
  flash.now[:info] = I18n.t("repository._frontend.messages.selected") if @repository.id === session[:repo_id]
end

- (Object) transfer



111
112
113
114
# File 'frontend/app/controllers/repositories_controller.rb', line 111

def transfer
  @repository = JSONModel(:repository_with_agent).find(params[:id])
  render :transfer
end

- (Object) update



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'frontend/app/controllers/repositories_controller.rb', line 65

def update
  generate_names(params[:repository])
  handle_crud(:instance => :repository,
              :model => JSONModel(:repository_with_agent),
              :replace => false,
              :obj => JSONModel(:repository_with_agent).find(params[:id]),
              :on_invalid => ->(){ return render :action => :edit },
              :on_valid => ->(id){
                MemoryLeak::Resources.refresh(:repository)

                flash[:success] = I18n.t("repository._frontend.messages.updated", JSONModelI18nWrapper.new(:repository => @repository))
                redirect_to :controller => :repositories, :action => :show, :id => id
              })
end