Class: ConceptsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ConceptsController
- Defined in:
- app/controllers/concepts_controller.rb
Overview
Copyright 2011 innoQ Deutschland GmbH
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Direct Known Subclasses
Concepts::AlphabeticalController, Concepts::HierarchicalController, Concepts::UntranslatedController
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/concepts_controller.rb', line 99 def create :create, Iqvoc::Concept.base_class @concept = Iqvoc::Concept.base_class.new(params[:concept]) if @concept.save flash[:notice] = 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
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/controllers/concepts_controller.rb', line 144 def destroy @new_concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last raise ActiveRecord::RecordNotFound unless @new_concept :destroy, @new_concept if @new_concept.destroy flash[:notice] = I18n.t("txt.controllers.concept_versions.delete") redirect_to dashboard_path else flash[:notice] = I18n.t("txt.controllers.concept_versions.delete_error") redirect_to concept_path(:published => 0, :id => @new_concept) end end |
#edit ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/controllers/concepts_controller.rb', line 112 def edit @concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last raise ActiveRecord::RecordNotFound unless @concept :update, @concept @association_objects_in_editing_mode = @concept.associated_objects_in_editing_mode if params[:full_consistency_check] @concept.valid_with_full_validation? 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 end |
#index ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/concepts_controller.rb', line 20 def index :read, Concept::Base respond_to do |format| format.json do # Search for widget @concepts = Iqvoc::Concept.base_class.editor_selectable.with_pref_labels.merge(Label::Base.by_query_value("#{params[:query]}%")).all response = [] @concepts.each { |concept| response << (concept)} render :json => response end format.all do # RDF full export :full_export, Concept::Base end end end |
#new ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/concepts_controller.rb', line 89 def new :create, Iqvoc::Concept.base_class @concept = Iqvoc::Concept.base_class.new 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 end |
#show ⇒ Object
37 38 39 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 |
# File 'app/controllers/concepts_controller.rb', line 37 def show scope = Iqvoc::Concept.base_class. by_origin(params[:id]). with_associations published = params[:published] == '1' || !params[:published] if published scope = scope.published @new_concept_version = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last else scope = scope.unpublished end @concept = scope.last raise ActiveRecord::RecordNotFound unless @concept :read, @concept respond_to do |format| format.html 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 :-) Concept::Base.send(:preload_associations, @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 :-) Concept::Base.send(:preload_associations, @concept, [:labels, { :relations => { :target => [:labelings, :relations] } }]) concept_data = { :origin => @concept.origin, :labels => @concept.labelings.map { |ln| labeling_as_json(ln) }, :relations => @concept.relations.map { |relation| concept = relation.target { :origin => concept.origin, :labels => concept.labelings.map { |ln| labeling_as_json(ln) }, :relations => concept.relations.length } } } render :json => concept_data end format.ttl end end |
#update ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/concepts_controller.rb', line 129 def update @concept = Iqvoc::Concept.base_class.by_origin(params[:id]).unpublished.last raise ActiveRecord::RecordNotFound unless @concept :update, @concept if @concept.update_attributes(params[:concept]) flash[:notice] = 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 |