Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • portalmec/portalmec
  • rfhferreira/cleanning-portalmec
2 results
Show changes
Showing
with 257 additions and 34 deletions
......@@ -39,7 +39,8 @@
# thumbnail_content_type :string
# thumbnail_file_size :integer
# thumbnail_updated_at :datetime
#
# review_average: :float default("0.0")
# curator :string
class Collection < ApplicationRecord
include Reviewable
......@@ -67,6 +68,7 @@ class Collection < ApplicationRecord
validates :name, :owner, presence: true
validates_inclusion_of :privacy, in: %w(public private), message: 'Privacy must be public or private'
after_create :create_action
before_destroy :delete_index
scope :from_user, ->(user) { where(owner: user) }
......@@ -108,7 +110,7 @@ class Collection < ApplicationRecord
end
def should_index?
deleted_at.nil?
deleted_at.nil?
end
def delete_index
......@@ -173,4 +175,8 @@ class Collection < ApplicationRecord
def ignore_changes
super + %w(score views_count downloads_count likes_count shares_count follows_count)
end
def create_action
owner.complete_action(Action.find_by_name("Criar Coleção"))
end
end
......@@ -25,7 +25,7 @@
# collectionable_id :integer
# collectionable_type :string
# collection_id :integer
# order :integer
# position :integer
# created_at :datetime not null
# updated_at :datetime not null
#
......@@ -34,6 +34,8 @@ class CollectionItem < ApplicationRecord
# *current_user* add item *collectionable* to *collection*
include Trackable
after_create :create_action
belongs_to :collection
belongs_to :collectionable, polymorphic: true
......@@ -58,4 +60,9 @@ class CollectionItem < ApplicationRecord
collectionable_type == 'LearningObject' ? LearningObject.find(collectionable_id).default_thumbnail : Collection.find(collectionable_id).thumbnail
end
private
def create_action
collection.owner.complete_action(Action.find_by_name("Adicionar Recurso a Coleção")) if collectionable_type == "LearningObject"
end
end
......@@ -24,12 +24,12 @@
# id :integer not null, primary key
# description :text
# user_id :integer
# complainable_id :integer
# complainable_type :string
# complainable_id :integer
# complainable_type :string
# complaint_reason_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# state :integer default("0")
class Complaint < ApplicationRecord
# *current_user* create complaint about *complaint_reason* for *complaintable*
......
......@@ -25,7 +25,7 @@
# reason :text
# created_at :datetime not null
# updated_at :datetime not null
#
# status :integer default("0")
class ComplaintReason < ApplicationRecord
# *current_user* create complaint reason
......
......@@ -29,9 +29,9 @@ module Trackable
end
def new_update_activity
return nil if previous_changes.blank?
return nil if saved_changes.blank?
return new_activity(:update) if ignore_changes == %w(updated_at)
filtered = previous_changes.reject { |x| ignore_changes.include?(x) }
filtered = saved_changes.reject { |x| ignore_changes.include?(x.to_s) }
new_activity(:update) unless filtered.empty?
end
......
......@@ -25,6 +25,8 @@
# name :string
# email :string
# message :text
#
# created_at :datetime not null
# updated_at :datetime not null
class Contact < ApplicationRecord
end
......@@ -33,6 +33,8 @@ class Download < ApplicationRecord
# *current_user* download *downloadable*
include Trackable
after_create :create_action
belongs_to :downloadable, polymorphic: true, counter_cache: true
belongs_to :user, optional: true
......@@ -47,4 +49,8 @@ class Download < ApplicationRecord
def new_create_activity
new_activity(:create) unless user.nil?
end
def create_action
user.complete_action(Action.find_by_name("Fazer Download de um Recurso")) if !user.nil? && downloadable_type == "LearningObject"
end
end
......@@ -33,6 +33,8 @@ class Follow < ApplicationRecord
# *current_user* follows *followable*
include Trackable
after_create :create_action
belongs_to :followable, polymorphic: true, counter_cache: true
belongs_to :user
......@@ -42,4 +44,13 @@ class Follow < ApplicationRecord
def recipient
followable
end
private
def create_action
if followable_type == "User"
user.complete_action(Action.find_by_name("Seguir Usuário"))
followable.complete_action(Action.find_by_name("Ser Seguido"))
end
end
end
......@@ -21,15 +21,19 @@
#
# Table name: institutions
#
# id :integer not null, primary key
# name :string
# address :string
# city :string
# country :string
# description :text
# created_at :datetime not null
# updated_at :datetime not null
#
# id :integer not null, primary key
# name :string
# address :string
# city :string
# country :string
# description :text
# created_at :datetime not null
# updated_at :datetime not null
# avatar_file_name :string
# avatar_content_type :string
# avatar_file_size :integer
# avatar_updated_at :datetime
# learning_objects_count :integer default("0")
class Institution < ApplicationRecord
include Tagger
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: items
# id: integer
# name: string
# price: integer
# discount: integer
# description: string
# state: integer
# item_type: integer
# image_file_name: string
# image_content_type: string
# image_file_size: integer
# image_updated_at: datetime
# created_at: datetime
# updated_at: datetime
# this table has one foreign key: achievement_id.
class Item < ApplicationRecord
belongs_to :achievement, optional: true
has_many :user_items
has_many :users, through: :user_items
enum state: [:inactive, :active, :removed]
enum item_type: [:avatar_frame, :badge, :card_frame, :cover_frame]
validates_presence_of :name, :price, :description, :item_type
# Change to reasonable sizes after the decision by the designers.
# Use conditional size for each item_type accordingly to the design decision (https://github.com/thoughtbot/paperclip/wiki/Conditionally-resizing-images).
has_attached_file :image, styles: {:thumb => "100x100#", :small => "150x150>", :medium => "200x200"}
validates_attachment_content_type :image, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
validates_attachment_presence :image
def achievable?
achievement_id?
end
end
......@@ -28,9 +28,7 @@
# description :text
# published_at :datetime
# score :float default("0.0")
# school_level :integer
# metadata :jsonb default("{}")
# keywords :text
# publisher_id :integer
# publisher_type :string
# object_type_id :integer
......@@ -40,7 +38,16 @@
# downloads_count :integer default("0")
# likes_count :integer default("0")
# shares_count :integer default("0")
# state :string default("published")
# state :string default("0")
# license_id :integer
# link :string
# software :string
# review_average :float default("0.0")
# curator :string
# magnetlink :string
# terms_of_service :boolean
# submission_id :integer
# legacy_dspace_id :string
# thumbnail_file_name :string
# thumbnail_content_type :string
# thumbnail_file_size :integer
......@@ -92,18 +99,10 @@ class LearningObject < ApplicationRecord
default_scope { includes(:object_type, :attachment, :attachments) }
scope :missing_thumbnail, ->() { where(thumbnail_file_name: nil) }
searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author, :object_type, :tags, :subjects, :educational_stages, :languages], callbacks: :async, index_prefix: Socket.gethostname.downcase, merge_mappings: true, mappings: {
learning_object: {
properties: {
published_at: {
type: "date"
}
}
}
}
searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author, :object_type, :tags, :subjects, :educational_stages, :languages], callbacks: :async, index_prefix: Socket.gethostname.downcase, merge_mappings: true
{"mappings": {"_doc": {"properties": {"published_at": { "type": "date" }}}}}
acts_as_paranoid
scope :search_import, -> { includes(:object_type, :tags, :subjects, :educational_stages, :publisher) }
def search_data
......
......@@ -34,6 +34,8 @@ class Like < ApplicationRecord
# *current_user* unlikes *likeable*
include Trackable
after_create :create_action
belongs_to :likeable, polymorphic: true, counter_cache: true
belongs_to :user, counter_cache: true
......@@ -43,4 +45,10 @@ class Like < ApplicationRecord
def recipient
likeable
end
private
def create_action
user.complete_action(Action.find_by_name("Favoritar"))
end
end
......@@ -21,6 +21,7 @@
#
# Table name: packages
#
# id :integer not null, primary key
# package_items_id integer
# created_at datetime null: false
# updated_at datetime null: false
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: progresses
# t.belongs_to :user
# t.belongs_to :achievement
# t.belongs_to :progress_type
# t.integer :counter, default: 0
# t.datetime "created_at", null: false
# t.datetime "updated_at", null: false
class Progress < ApplicationRecord
belongs_to :requirement
belongs_to :user
validates_presence_of :user, :requirement
scope :user_progresses, -> (id) { where(user_id: id) }
end
......@@ -21,7 +21,7 @@
# Table name: questions
# t.string "description"
# t.integer "status", default: 0
# t.integer "status", default: 0
# t.datetime "created_at", null: false
# t.datetime "updated_at", null: false
......
......@@ -27,6 +27,7 @@
# review_id :integer
# created_at :datetime not null
# updated_at :datetime not null
class Rate < ApplicationRecord
# *current_user* rate a review *review*
include Trackable
......
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
# == Schema Information
#
# Table name: requirements
# t.belongs_to "action"
# t.belongs_to "achievement"
# t.string "description"
# t.integer "goal"
# t.boolean "repeatable"
# t.datetime "created_at"
# t.datetime "updated_at"
class Requirement < ApplicationRecord
belongs_to :action
has_many :progresses
has_many :users, through: :progresses
has_and_belongs_to_many :achievements
accepts_nested_attributes_for :progresses, allow_destroy: true
validates_presence_of :goal, :description, :action
def add_achievements(ids=[])
errors = []
ids.each do |achievement_id|
if !achievement_ids.include?(achievement_id)
achievement = Achievement.where(id: achievement_id).first
if !achievement.blank?
achievements << achievement
else
errors << {error_type:"inexistent", id: achievement_id}
end
else
errors << {error_type:"repeated", id: achievement_id}
end
end
return errors
end
def remove_achievements(ids=[])
ids.each do |achievement_id|
achievement = achievements.where(id: achievement_id).first
if !achievement.blank?
self.achievements.delete(achievement)
end
end
end
def update_achievements(ids)
ids ||= []
add_achievements(ids - achievement_ids)
remove_achievements(achievement_ids - ids)
end
end
......@@ -41,6 +41,7 @@ class Review < ApplicationRecord
after_save :calculate_review_rate
after_destroy :calculate_review_rate
after_create :create_action
belongs_to :reviewable, polymorphic: true
belongs_to :user
......@@ -96,4 +97,9 @@ class Review < ApplicationRecord
# ReviewAverageCalculatorWorker.perform_in(1.minutes, reviewable.id, reviewable.class.name)
end
def create_action
user.complete_action(Action.find_by_name("Avaliar"))
user.complete_action(Action.find_by_name("Comentar")) if !description.blank?
end
end
......@@ -31,6 +31,7 @@
class Role < ApplicationRecord
has_and_belongs_to_many :users
has_and_belongs_to_many :emails
has_and_belongs_to_many :achievements
validates :name, presence: true, uniqueness: true
......
......@@ -26,7 +26,9 @@
# link :string
# description :text
# status :integer
#
# created_at :datetime not null
# updated_at :datetime not null
class Suggestion < ApplicationRecord
enum status: { created: 0, accepted: 1, rejected: 2, loadded: 3 }
end