diff --git a/app/controllers/super_admin/themes_controller.rb b/app/controllers/super_admin/themes_controller.rb index 75532fe..df1fa4f 100644 --- a/app/controllers/super_admin/themes_controller.rb +++ b/app/controllers/super_admin/themes_controller.rb @@ -64,6 +64,12 @@ end redirect_to(action: :index) end + + def extract + @theme = Theme.find(params[:id]) + render format: :json + end + # Private instance methods private diff --git a/app/models/theme.rb b/app/models/theme.rb index 4f0738e..d13ca7b 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -4,6 +4,7 @@ # Associations has_and_belongs_to_many :questions, join_table: "questions_themes" has_and_belongs_to_many :guidances, join_table: "themes_in_guidance" + has_many :answers, through: :questions ## # Possibly needed for active_admin diff --git a/app/views/super_admin/themes/extract.jbuilder b/app/views/super_admin/themes/extract.jbuilder new file mode 100644 index 0000000..6f061ef --- /dev/null +++ b/app/views/super_admin/themes/extract.jbuilder @@ -0,0 +1,14 @@ +json.theme @theme.title +json.answers @theme.answers do |a| + json.id a.id + json.answer a.text + json.question do + json.id a.question.id + json.title a.question.text + json.type a.question.question_format.title + end + json.plan do + json.id a.plan.id + json.title a.plan.title + end +end diff --git a/config/routes.rb b/config/routes.rb index b5599fe..c817bf5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -270,25 +270,25 @@ patch 'publish', action: :publish, constraints: {format: [:json]} patch 'unpublish', action: :unpublish, constraints: {format: [:json]} end - + # Used for the organisational and customizable views of index collection do get 'organisational' get 'customisable' end - + resources :phases, only: [:show, :edit, :new, :create, :edit, :update, :destroy] do member do get 'preview' end - + resources :sections, only: [:index, :show, :edit, :update, :create, :destroy] do resources :questions, only: [:show, :edit, :new, :update, :create, :destroy] do end end end end - + resources :annotations, only: [:create, :destroy, :update] do ; end get 'template_options' => 'templates#template_options', constraints: {format: [:json]} @@ -297,7 +297,11 @@ namespace :super_admin do resources :orgs, only: [:index, :new, :create, :edit, :update, :destroy] - resources :themes, only: [:index, :new, :create, :edit, :update, :destroy] + resources :themes, only: [:index, :new, :create, :edit, :update, :destroy] do + member do + get 'extract' => 'themes#extract' + end + end resources :users, only: [:edit, :update] resources :notifications end