Skip to content
Snippets Groups Projects
Commit 2977485e authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'update-arrays' into 'master'

Update arrays

See merge request portalmec/portalmec!490
parents 4618adf7 116059ab
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,7 @@ class V1::LearningObjectsController < ApplicationController
change_object_type_id = true
end
if @learning_object.update(learning_object_params)
learning_object_associations(@learning_object, change_object_type_id)
update_learning_object_associations(@learning_object, change_object_type_id)
publisher = LearningObjectPublisher.new(DspaceService.create_client)
publisher.update_dspace(@learning_object)
......@@ -160,6 +160,16 @@ class V1::LearningObjectsController < ApplicationController
end
end
def update_learning_object_associations(learning_object, change_object_type_id=false)
current_user.update_tags(learning_object, with: extra_params[:tags].map { |t| t['name'] }) unless extra_params[:tags].nil?
learning_object.update_subjects(ids: extra_params[:subjects]) unless extra_params[:subjects].nil?
learning_object.update_educational_stages(ids: extra_params[:educational_stages]) unless extra_params[:educational_stages].nil?
if change_object_type_id
learning_object.link = nil
end
end
def authorize!
authorize @learning_object
end
......
......@@ -45,4 +45,11 @@ module Stageable
StageRelation.where(educational_stage: educational_stage, stageable: self).destroy_all
end
end
def update_educational_stages(ids: [])
stageable = self
old_ids = stageable.educational_stages.map {|es| es.id }
add_educational_stages(ids: ids - old_ids)
remove_educational_stages(ids: old_ids - ids)
end
end
......@@ -45,4 +45,11 @@ module Subjectable
SubjectRelation.where(subject: subject, subjectable: self).destroy_all
end
end
def update_subjects(ids: [])
subjectable = self
old_ids = subjectable.subjects.map { |su| su.id }
add_subjects(ids: ids - old_ids)
remove_subjects(ids: old_ids - ids)
end
end
......@@ -45,4 +45,10 @@ module Tagger
Tagging.where(tagger: self, tag: tag, taggable: taggable).destroy_all
end
end
def update_tags(taggable, with: [])
old_tags = taggable.tags.map { |t| t.name }
tag(taggable, with: with - old_tags)
untag(taggable, with: old_tags - with)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment