From 978901ca9bc2fad07045348a7a3d3a6f3b0f10c9 Mon Sep 17 00:00:00 2001 From: man13 <man13@inf.ufpr.br> Date: Thu, 28 Jan 2016 11:14:46 -0200 Subject: [PATCH] adding language repository and builders, adding language associations with learning object, fixing form and controller to create learning objects properly Signed-off-by: man13 <man13@inf.ufpr.br> --- app/builders/language_builder.rb | 22 +++++++++++++++++++ .../learning_objects_controller.rb | 1 + app/models/language.rb | 8 +++++++ .../associations/languages_association.rb | 14 ++++++++++++ .../learning_object_associations.rb | 3 ++- .../orient_db/language_repository.rb | 14 ++++++++++++ app/views/learning_objects/_form.html.erb | 4 ++-- config/initializers/repositories.rb | 1 + 8 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 app/builders/language_builder.rb create mode 100644 app/models/language.rb create mode 100644 app/repositories/orient_db/associations/languages_association.rb create mode 100644 app/repositories/orient_db/language_repository.rb diff --git a/app/builders/language_builder.rb b/app/builders/language_builder.rb new file mode 100644 index 00000000..7263a195 --- /dev/null +++ b/app/builders/language_builder.rb @@ -0,0 +1,22 @@ +class LanguageBuilder < Builder + ## + # receive a list of ids and return a list of languages + # useful for create a new learning object + # + def self.build(objects = []) + super(language_repository, objects, true, 'rid') + end + + def self.build_from_orientdb(args = {}) + super(args) do + obj = Language.new( + id: args['@rid'], + name: args['name'], + code: args['code'] + ) + obj + end + end + + private +end diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 2d009d4e..281440f0 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -23,6 +23,7 @@ class LearningObjectsController < ApplicationController @school_levels = ['EducaçÃĢo Infantil', 'Ensino Fundamental', 'Ensino MÃĐdio'] @subjects = Subject.default_list @types = learning_object_repository.types + @languages = language_repository.all end # GET /learning_objects/1/edit diff --git a/app/models/language.rb b/app/models/language.rb new file mode 100644 index 00000000..7f310cdc --- /dev/null +++ b/app/models/language.rb @@ -0,0 +1,8 @@ +class Language + include ActiveModel::Model + include RepositoriesProxy + include OrientDbSerializable + include Metadatable + + attr_accessor :id, :name, :code +end \ No newline at end of file diff --git a/app/repositories/orient_db/associations/languages_association.rb b/app/repositories/orient_db/associations/languages_association.rb new file mode 100644 index 00000000..a84ad8f1 --- /dev/null +++ b/app/repositories/orient_db/associations/languages_association.rb @@ -0,0 +1,14 @@ +class OrientDb::Associations::LanguagesAssociation < OrientDb::Association + + def can_create? + true + end + + protected + + def execute + create_edge("HasLang", @object.id, @object.language) + end + +end + diff --git a/app/repositories/orient_db/associations/learning_object_associations.rb b/app/repositories/orient_db/associations/learning_object_associations.rb index 888f4cdd..f6ef6223 100644 --- a/app/repositories/orient_db/associations/learning_object_associations.rb +++ b/app/repositories/orient_db/associations/learning_object_associations.rb @@ -4,7 +4,8 @@ class OrientDb::Associations::LearningObjectAssociations < OrientDb::Association [ OrientDb::Associations::SubjectsAssociation.new(object, connection), OrientDb::Associations::AttributesAssociation.new(object, connection), - OrientDb::Associations::PublisherAssociation.new(object, connection) + OrientDb::Associations::PublisherAssociation.new(object, connection), + OrientDb::Associations::LanguagesAssociation.new(object, connection) ] end diff --git a/app/repositories/orient_db/language_repository.rb b/app/repositories/orient_db/language_repository.rb new file mode 100644 index 00000000..33b4b222 --- /dev/null +++ b/app/repositories/orient_db/language_repository.rb @@ -0,0 +1,14 @@ +require 'json' +module OrientDb + class LanguageRepository < Base + include OrientDb::Methods::SocialMethods + include OrientDb::Methods::EdgeMethods + include OrientDb::Methods::CountableMethods + include RepositoriesProxy + + def all + result = connection.query("Select from Language") + build_objects result + end + end +end diff --git a/app/views/learning_objects/_form.html.erb b/app/views/learning_objects/_form.html.erb index c8233050..0cdfb9ee 100644 --- a/app/views/learning_objects/_form.html.erb +++ b/app/views/learning_objects/_form.html.erb @@ -27,8 +27,8 @@ <%= f.label :description, "Descreva seu objeto" %> <%= f.text_area :description, class: "form-control" %><br> - <%= f.label :language, "Idioma do objeto" %> - <%= f.text_field :language, class: "form-control" %><br> + <%= f.label :language, "Idioma do objeto" %><br> + <%= f.collection_select(:language, @languages, :id, :name, prompt: "Por favor informe o idioma do objeto ") %><br> <%= f.label :author, "Autor" %> <%= f.text_field :author, class: "form-control" %><br> diff --git a/config/initializers/repositories.rb b/config/initializers/repositories.rb index 73115d23..2220f03b 100644 --- a/config/initializers/repositories.rb +++ b/config/initializers/repositories.rb @@ -4,6 +4,7 @@ orientdb_client = OrientdbService.create_client repositories = { learning_object: OrientDb::LearningObjectRepository.new(orientdb_client), + language: OrientDb::LanguageRepository.new(orientdb_client), user: UserRepositoryProxy.new(OrientDb::UserRepository.new(orientdb_client)), subject: OrientDb::SubjectRepository.new(orientdb_client), institution: OrientDb::InstitutionRepository.new(orientdb_client), -- GitLab