Class: ConceptsMovementController

Inherits:
ApplicationController show all
Includes:
DatasetInitialization
Defined in:
app/controllers/concepts_movement_controller.rb

Overview

Copyright 2011-2015 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.

Instance Method Summary collapse

Methods included from DatasetInitialization

#datasets_as_json, #init_datasets

Instance Method Details

#moveObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/concepts_movement_controller.rb', line 20

def move
  moved_concept = Iqvoc::Concept.base_class.find(params.require(:moved_node_id))

  if moved_concept.published?
    authorize! :branch, moved_concept
  else
    authorize! :update, moved_concept
  end

  moved_concept_version = concept_version(moved_concept)

  ActiveRecord::Base.transaction do
    if moved_concept_version.top_term?
      # we move a top term deeper into the tree
      moved_concept_version.update_attribute(:top_term, false)
      new_parent_concept = Iqvoc::Concept.base_class.find(params.require(:new_parent_node_id))
      create_new_relations(moved_concept_version, new_parent_concept)
    elsif params['new_parent_node_id'].nil?
      # we move a tree node to the top
      moved_concept_version.update_attribute(:top_term, true)
      old_parent_concept = Iqvoc::Concept.base_class.find(params.require(:old_parent_node_id))
      destroy_relations(old_parent_concept, moved_concept_version)
    else
      # regular inner tree node movement
      if params[:tree_action] == 'move' && Iqvoc::Concept.root_class.instance.mono_hierarchy?
        old_parent_concept = Iqvoc::Concept.base_class.find(params.require(:old_parent_node_id))
        destroy_relations(old_parent_concept, moved_concept_version)
      end

      new_parent_concept = Iqvoc::Concept.base_class.find(params.require(:new_parent_node_id))
      # add new relations to concept version
      create_new_relations(moved_concept_version, new_parent_concept)
    end
  end

  render json: {new_node_id: moved_concept_version.id}
end