Class: Admin::DocumentDataDictionariesController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/document_data_dictionaries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /document_data_dictionaries or /document_data_dictionaries.json



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 42

def create
  @document_data_dictionary = DocumentDataDictionary.new(document_data_dictionary_params)

  respond_to do |format|
    if @document_data_dictionary.save
      format.html { redirect_to admin_document_document_data_dictionaries_path(@document), notice: "Document data dictionary was successfully created." }
      format.json { render :show, status: :created, location: @document_data_dictionary }
    else
      logger.debug("Document data dictionary could not be created. #{@document_data_dictionary.errors.full_messages}")
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @document_data_dictionary.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /document_data_dictionaries/1 or /document_data_dictionaries/1.json



71
72
73
74
75
76
77
78
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 71

def destroy
  @document_data_dictionary.destroy!

  respond_to do |format|
    format.html { redirect_to admin_document_document_data_dictionaries_path(@document), status: :see_other, notice: "Document data dictionary was successfully destroyed." }
    format.json { head :no_content }
  end
end

#destroy_allObject

DELETE /admin/document_data_dictionaries/destroy_all

Destroys all document data dictionaries provided in the file parameter. If successful, redirects with a success notice. Otherwise, redirects with an error notice.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 84

def destroy_all
  return if request.get?

  logger.debug("Destroy Data Dictionaries")
  unless params.dig(:document_data_dictionary, :data_dictionaries, :file)
    raise ArgumentError, "File does not exist or is invalid."
  end

  respond_to do |format|
    if DocumentDataDictionary.destroy_all(params.dig(:document_data_dictionary, :data_dictionaries, :file))
      format.html { redirect_to admin_document_document_data_dictionaries_path, notice: "Data dictionaries were destroyed." }
    else
      format.html { redirect_to admin_document_document_data_dictionaries_path, notice: "Data dictionaries could not be destroyed." }
    end
  rescue => e
    format.html { redirect_to admin_document_document_data_dictionaries_path, notice: "Data dictionaries could not be destroyed. #{e}" }
  end
end

#editObject

GET /document_data_dictionaries/1/edit



38
39
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 38

def edit
end

#indexObject

GET /document_data_dictionaries or /document_data_dictionaries.json



13
14
15
16
17
18
19
20
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 13

def index
  @document_data_dictionaries = DocumentDataDictionary.all
  if params[:document_id]
    @document_data_dictionaries = DocumentDataDictionary.where(friendlier_id: @document.friendlier_id).order(position: :asc)
  else
    @pagy, @document_data_dictionaries = pagy(DocumentDataDictionary.all.order(friendlier_id: :asc, updated_at: :desc), items: 20)
  end
end

#newObject

GET /document_data_dictionaries/new



33
34
35
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 33

def new
  @document_data_dictionary = DocumentDataDictionary.new
end

#showObject

GET /document_data_dictionaries/1 or /document_data_dictionaries/1.json



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

def show
  @pagy, @document_data_dictionary_entries = pagy(@document_data_dictionary.document_data_dictionary_entries.order(position: :asc), items: 100)

  respond_to do |format|
    format.html
    format.csv { render plain: @document_data_dictionary.to_csv }
  end
end

#updateObject

PATCH/PUT /document_data_dictionaries/1 or /document_data_dictionaries/1.json



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/admin/document_data_dictionaries_controller.rb', line 58

def update
  respond_to do |format|
    if @document_data_dictionary.update(document_data_dictionary_params)
      format.html { redirect_to admin_document_document_data_dictionaries_path(@document), notice: "Document data dictionary was successfully updated." }
      format.json { render :show, status: :ok, location: @document_data_dictionary }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @document_data_dictionary.errors, status: :unprocessable_entity }
    end
  end
end