Class: OpenehrRails::TemplatesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- OpenehrRails::TemplatesController
- Defined in:
- app/controllers/openehr_rails/templates_controller.rb
Overview
Template management UI: lists registered templates, accepts drag & drop OPT uploads and triggers runtime scaffolding ("Generate UI").
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/controllers/openehr_rails/templates_controller.rb', line 13 def create record = params[:url].present? ? TemplateImporter.call(url: params[:url]) : upload_template return unless record render json: { template_id: record.template_id, name: record.name }, status: :created rescue TemplateUploader::InvalidTemplate, TemplateImporter::InvalidTemplate, ActiveRecord::RecordInvalid => e render json: { error: e. }, status: :unprocessable_entity end |
#destroy ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/controllers/openehr_rails/templates_controller.rb', line 37 def destroy template = ::OpenehrTemplate.find(params[:id]) remove_stored_opt(template) template.destroy redirect_to root_path, notice: "Removed template #{template.template_id} (generated code is kept).", status: :see_other end |
#generate ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/openehr_rails/templates_controller.rb', line 22 def generate template = ::OpenehrTemplate.find(params[:id]) scaffolder = RuntimeScaffolder.new(template, root: ::Rails.root) if scaffolder.scaffolded? redirect_to root_path, notice: "UI already exists at /#{scaffolder.model_name.pluralize}" else result = scaffolder.call redirect_to root_path, notice: "Generated UI at /#{result.route_path}" end rescue StandardError => e log_openehr_error(e) redirect_to root_path, alert: "Generation failed: #{e.}" end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/openehr_rails/templates_controller.rb', line 9 def index @templates = ::OpenehrTemplate.order(:template_id) end |