Class: ConceptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ConceptsController
- Includes:
- DatasetInitialization
- Defined in:
- app/controllers/concepts_controller.rb
Direct Known Subclasses
Concepts::AlphabeticalController, Concepts::HierarchicalController, Concepts::UntranslatedController
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #glance ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from DatasetInitialization
#datasets_as_json, #init_datasets
Instance Method Details
#create ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/controllers/concepts_controller.rb', line 146 def create :create, Iqvoc::Concept.base_class @concept = Iqvoc::Concept.base_class.new @concept.reverse_match_service = Services::ReverseMatchService.new(request.host, request.protocol) if match_sync_enabled? @concept.assign_attributes(concept_params) @datasets = datasets_as_json @concept.lock_by_user(current_user.id) if @concept.save flash[:success] = I18n.t('txt.controllers.versioned_concept.success') redirect_to concept_path(published: 0, id: @concept.origin) else flash.now[:error] = I18n.t('txt.controllers.versioned_concept.error') render :new end end |
#destroy ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/controllers/concepts_controller.rb', line 204 def destroy @new_concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last! :destroy, @new_concept if @new_concept.destroy published_concept = Iqvoc::Concept.base_class.published.by_origin(@new_concept.origin).first flash[:success] = I18n.t('txt.controllers.concept_versions.delete') redirect_to published_concept.present? ? concept_path(id: published_concept.origin) : dashboard_path else flash[:success] = I18n.t('txt.controllers.concept_versions.delete_error') redirect_to concept_path(published: 0, id: @new_concept) end end |
#edit ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'app/controllers/concepts_controller.rb', line 165 def edit @concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last! :update, @concept @association_objects_in_editing_mode = @concept.associated_objects_in_editing_mode if params[:full_consistency_check] @concept.publishable? end Iqvoc::Concept.note_class_names.each do |note_class_name| @concept.send(note_class_name.to_relation_name).build if @concept.send(note_class_name.to_relation_name).empty? end @concept.notations.build if @concept.notations.none? @datasets = datasets_as_json end |
#glance ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/controllers/concepts_controller.rb', line 109 def glance get_concept :read, @concept respond_to do |format| format.html do @view = ConceptView.new(@concept, self) render layout: false end end end |
#index ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/concepts_controller.rb', line 23 def index :read, Concept::Base respond_to do |format| format.html do redirect_to hierarchical_concepts_url end format.json do # Search for widget scope = Iqvoc::Concept.base_class.editor_selectable.with_pref_labels. merge(Label::Base.by_query_value("%#{params[:query]}%")) scope = scope.where(top_term: false) if params[:exclude_top_terms] @concepts = scope.all.map { |concept| (concept) } render json: @concepts end end end |
#new ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/concepts_controller.rb', line 121 def new :create, Iqvoc::Concept.base_class @concept = Iqvoc::Concept.base_class.new # initial created-ChangeNote creation @concept.send(Iqvoc::change_note_class_name.to_relation_name).new do |change_note| change_note.value = I18n.t('txt.views.versioning.initial_version') change_note.language = I18n.locale.to_s change_note.position = 1 change_note.annotations_attributes = [ { namespace: 'dct', predicate: 'creator', value: current_user.name }, { namespace: 'dct', predicate: 'created', value: DateTime.now.to_s } ] end Iqvoc::Concept.note_class_names.each do |note_class_name| @concept.send(note_class_name.to_relation_name).build if @concept.send(note_class_name.to_relation_name).empty? end @concept.notations.build if @concept.notations.none? @datasets = datasets_as_json end |
#show ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/concepts_controller.rb', line 40 def show get_concept :read, @concept @datasets = datasets_as_json respond_to do |format| format.html do jobs = @concept.jobs if jobs.any? match_classes = Iqvoc::Concept.reverse_match_class_names @jobs = jobs.map do |j| handler = YAML.load(j.handler) match_class_name = match_classes.key(handler.match_class) reverse_match_class_name = match_class_name.constantize.reverse_match_class_name reverse_match_class_label = reverse_match_class_name.constantize.rdf_predicate.camelize if reverse_match_class_name result = {response_error: j.} result[:subject] = handler.subject result[:type] = handler.type result[:match_class] = reverse_match_class_label || reverse_match_class_name result end end # When in single query mode, AR handles ALL includes to be loaded by that # one query. We don't want that! So let's do it manually :-) ActiveRecord::Associations::Preloader.new.preload(@concept, Iqvoc::Concept.base_class.default_includes + [collection_members: { collection: :labels }, broader_relations: { target: [:pref_labels, :broader_relations] }, narrower_relations: { target: [:pref_labels, :narrower_relations] }]) @published ? render('show_published') : render('show_unpublished') end format.json do # When in single query mode, AR handles ALL includes to be loaded by that # one query. We don't want that! So let's do it manually :-) ActiveRecord::Associations::Preloader.new.preload(@concept, [:labels, { relations: { target: [:labelings, :relations] } }]) published_relations = lambda { |concept| return concept.relations.includes(:target). merge(Iqvoc::Concept.base_class.published).references(:concepts) } concept_data = { origin: @concept.origin, labels: @concept.labelings.map { |ln| labeling_as_json(ln) }, relations: published_relations.call(@concept).map { |relation| concept = relation.target { origin: concept.origin, labels: concept.labelings.map { |ln| labeling_as_json(ln) }, relations: published_relations.call(concept).count } }, links: [ { rel: 'self', href: concept_url(@concept, format: nil), method: 'get' }, { rel: 'add_match', href: add_match_url(@concept, lang: nil), method: 'patch' }, { rel: 'remove_match', href: remove_match_url(@concept, lang: nil), method: 'patch' } ] } # FIXME: use jbuilder instead??? render json: concept_data end format.any(:ttl, :rdf, :nt) end end |
#update ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'app/controllers/concepts_controller.rb', line 185 def update @concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last! :update, @concept @concept.reverse_match_service = Services::ReverseMatchService.new(request.host, request.protocol) if match_sync_enabled? @datasets = datasets_as_json # set to_review to false if someone edits a concepts concept_params["to_review"] = "false" if @concept.update(concept_params) flash[:success] = I18n.t('txt.controllers.versioned_concept.update_success') redirect_to concept_path(published: 0, id: @concept) else flash.now[:error] = I18n.t('txt.controllers.versioned_concept.update_error') render action: :edit end end |