Class: Sipity::Controllers::DoisController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sipity/controllers/dois_controller.rb

Overview

The controller for creating sips.

Instance Method Summary collapse

Methods inherited from ApplicationController

#message_for, #repository

Instance Method Details

#assign_a_doiObject


33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 33

def assign_a_doi
  run(sip_id: sip_id, identifier: doi) do |on|
    on.success do |sip, identifier|
      redirect_to sip_path(sip), notice: message_for(:success, doi: identifier, title: sip.title)
    end
    on.failure do |sip|
      @model = sip
      respond_with(@model)
    end
  end
end

#doiObject (private)


71
72
73
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 71

def doi
  params.require(:doi).fetch(:identifier)
end

#doi_not_assigned_response(sip) ⇒ Object (private)


23
24
25
26
27
28
29
30
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 23

def doi_not_assigned_response(sip)
  sip = Decorators::SipDecorator.decorate(sip)
  @model = Forms::AssignADoiForm.new(sip: sip)
  respond_with(@model) do |wants|
    flash.now.alert = message_for(:doi_not_assigned, title: sip.title)
    wants.html { render action: 'doi_not_assigned' }
  end
end

#request_a_doiObject


45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 45

def request_a_doi
  run(sip_id: sip_id, attributes: request_a_doi_attributes) do |on|
    on.success do |sip|
      redirect_to sip_path(sip), notice: message_for(:success, title: sip.title)
    end
    on.failure do |model|
      @model = model
      respond_with(@model)
    end
  end
end

#request_a_doi_attributesObject (private)


63
64
65
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 63

def request_a_doi_attributes
  params.require(:doi)
end

#showObject


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 9

def show
  run(sip_id: sip_id) do |on|
    on.doi_not_assigned do |sip|
      doi_not_assigned_response(sip)
    end
    on.doi_already_assigned do |sip|
      redirect_to sip_path(sip), notice: message_for(:doi_already_assigned, title: sip.title)
    end
    on.doi_request_is_pending do |sip, _doi_request|
      redirect_to sip_path(sip), notice: message_for(:doi_request_is_pending, title: sip.title)
    end
  end
end

#sip_idObject (private)


67
68
69
# File 'app/controllers/sipity/controllers/dois_controller.rb', line 67

def sip_id
  params.require(:sip_id)
end