From f347b78432c72ee7671db74665c3969c886f46b4 Mon Sep 17 00:00:00 2001 From: msdundar Date: Fri, 13 Jul 2018 20:05:23 +0300 Subject: [PATCH 01/11] rename yoksis:import_departments rake task --- .../{import_countries.rake => import_yoksis_country_codes.rake} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename lib/tasks/yoksis/{import_countries.rake => import_yoksis_country_codes.rake} (92%) diff --git a/lib/tasks/yoksis/import_countries.rake b/lib/tasks/yoksis/import_yoksis_country_codes.rake similarity index 92% rename from lib/tasks/yoksis/import_countries.rake rename to lib/tasks/yoksis/import_yoksis_country_codes.rake index 24645cc62..461f7d4fb 100644 --- a/lib/tasks/yoksis/import_countries.rake +++ b/lib/tasks/yoksis/import_yoksis_country_codes.rake @@ -2,7 +2,7 @@ namespace :yoksis do desc 'import country codes from YOKSIS' - task import_countries: :environment do + task import_yoksis_country_codes: :environment do file = File.open(Rails.root.join('db', 'static_data', 'yoksis_countries.yml')) rescue Errno::ENOENT => e puts "File/path not found! #{e}" From a66f6ecb47afb8bbc50ad19a13247c4645d786c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 01:46:12 +0300 Subject: [PATCH 02/11] Add chartkick and groupdate for charts --- Gemfile | 2 ++ Gemfile.lock | 5 +++++ app/assets/javascripts/application.js | 2 ++ app/jobs/yoksis/articles_create_job.rb | 1 - 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 3f5df2bc3..ed8bc48cb 100644 --- a/Gemfile +++ b/Gemfile @@ -24,8 +24,10 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # view helpers: tools for forms, views, etc. +gem 'chartkick' gem 'cocoon' gem 'font-awesome-rails' +gem 'groupdate' # for chartkick gem 'pagy' gem 'simple_form' diff --git a/Gemfile.lock b/Gemfile.lock index b19da1c0e..b66e3bfeb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,7 @@ GEM rack (>= 1.6.0) rack-test (>= 0.6.3) xpath (~> 3.1) + chartkick (2.3.5) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) chromedriver-helper (1.2.0) @@ -126,6 +127,8 @@ GEM activerecord (>= 4.0.0) globalid (0.4.1) activesupport (>= 4.2.0) + groupdate (4.0.1) + activesupport (>= 4.2) gyoku (1.3.1) builder (>= 2.1.2) httpi (2.4.3) @@ -337,6 +340,7 @@ DEPENDENCIES bundler-audit byebug capybara (>= 2.15, < 4.0) + chartkick chromedriver-helper cocoon codacy-coverage @@ -346,6 +350,7 @@ DEPENDENCIES email_address font-awesome-rails friendly_id (~> 5.1.0) + groupdate jbuilder (~> 2.5) letter_opener listen (>= 3.0.5, < 3.2) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1f9a777e0..449d167bb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -9,3 +9,5 @@ //= require perfect-scrollbar/dist/perfect-scrollbar.min //= require select2/dist/js/select2.min //= require jquery.maskedinput/src/jquery.maskedinput +//= require Chart.bundle +//= require chartkick \ No newline at end of file diff --git a/app/jobs/yoksis/articles_create_job.rb b/app/jobs/yoksis/articles_create_job.rb index 32d69837d..82933953d 100644 --- a/app/jobs/yoksis/articles_create_job.rb +++ b/app/jobs/yoksis/articles_create_job.rb @@ -10,7 +10,6 @@ def perform(user) end # callbacks - # rubocop:disable Metrics/BlockLength after_perform do |job| user = job.arguments.first From a6d7ae5a4c56211a388025958524ed4e47f751d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 01:48:35 +0300 Subject: [PATCH 03/11] Add article and project counter caches to User --- .../20180713221157_add_articles_count_to_users.rb | 5 +++++ .../20180713222542_add_projects_count_to_users.rb | 5 +++++ db/schema.rb | 2 ++ lib/tasks/counter_cache/update_counter_cache.rake | 11 +++++++++++ 4 files changed, 23 insertions(+) create mode 100644 db/migrate/20180713221157_add_articles_count_to_users.rb create mode 100644 db/migrate/20180713222542_add_projects_count_to_users.rb create mode 100644 lib/tasks/counter_cache/update_counter_cache.rake diff --git a/db/migrate/20180713221157_add_articles_count_to_users.rb b/db/migrate/20180713221157_add_articles_count_to_users.rb new file mode 100644 index 000000000..6fbc6af38 --- /dev/null +++ b/db/migrate/20180713221157_add_articles_count_to_users.rb @@ -0,0 +1,5 @@ +class AddArticlesCountToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :articles_count, :integer + end +end diff --git a/db/migrate/20180713222542_add_projects_count_to_users.rb b/db/migrate/20180713222542_add_projects_count_to_users.rb new file mode 100644 index 000000000..1c16a764e --- /dev/null +++ b/db/migrate/20180713222542_add_projects_count_to_users.rb @@ -0,0 +1,5 @@ +class AddProjectsCountToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :projects_count, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 64d77b525..fe04cf17c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -401,6 +401,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "password_changed_at", default: -> { "CURRENT_TIMESTAMP" }, null: false + t.integer "articles_count" + t.integer "projects_count" t.index ["email"], name: "index_users_on_email", unique: true t.index ["id_number"], name: "index_users_on_id_number", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true diff --git a/lib/tasks/counter_cache/update_counter_cache.rake b/lib/tasks/counter_cache/update_counter_cache.rake new file mode 100644 index 000000000..f1934f767 --- /dev/null +++ b/lib/tasks/counter_cache/update_counter_cache.rake @@ -0,0 +1,11 @@ +desc 'Counter cache for number of articles/projects a user have' + +namespace :update_counter_cache do + task article_counter: :environment do + User.find_each { |user| User.reset_counters(user.id, :articles) } + end + + task project_counter: :environment do + User.find_each { |user| User.reset_counters(user.id, :projects) } + end +end From 6be268f02b19524bf781658f086cb0bdd0d97fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 01:49:11 +0300 Subject: [PATCH 04/11] Add created_at timestamp to publishings --- db/migrate/20180713224006_add_timestamps_to_publishings.rb | 7 +++++++ db/schema.rb | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180713224006_add_timestamps_to_publishings.rb diff --git a/db/migrate/20180713224006_add_timestamps_to_publishings.rb b/db/migrate/20180713224006_add_timestamps_to_publishings.rb new file mode 100644 index 000000000..e8d248fe9 --- /dev/null +++ b/db/migrate/20180713224006_add_timestamps_to_publishings.rb @@ -0,0 +1,7 @@ +class AddTimestampsToPublishings < ActiveRecord::Migration[5.2] + def change + add_column :articles, :created_at, :datetime + add_column :projects, :created_at, :datetime + add_column :certifications, :created_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index fe04cf17c..259caee78 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_07_12_130547) do +ActiveRecord::Schema.define(version: 2018_07_13_224006) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -85,6 +85,7 @@ t.integer "type" t.float "incentive_point" t.bigint "user_id" + t.datetime "created_at" t.index ["user_id"], name: "index_articles_on_user_id" end @@ -134,6 +135,7 @@ t.float "incentive_point" t.integer "status" t.bigint "user_id" + t.datetime "created_at" t.index ["user_id"], name: "index_certifications_on_user_id" end @@ -258,6 +260,7 @@ t.integer "unit_id" t.float "incentive_point" t.bigint "user_id" + t.datetime "created_at" t.index ["user_id"], name: "index_projects_on_user_id" end From 15ac9994e7efaf5730b2e6a6af83c90a124eaf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 02:22:39 +0300 Subject: [PATCH 05/11] Added routes and initial controllers for publications --- app/controllers/studies/articles_controller.rb | 9 +++++++++ app/controllers/studies/certifications_controller.rb | 7 +++++++ app/controllers/studies/dashboard_controller.rb | 7 +++++++ app/controllers/studies/projects_controller.rb | 7 +++++++ app/views/layouts/shared/_sidebar.html.erb | 6 ++++++ app/views/studies/certifications/index.html.erb | 0 app/views/studies/projects/index.html.erb | 0 config/locales/layouts/shared/sidebar_en.yml | 1 + config/locales/layouts/shared/sidebar_tr.yml | 1 + config/routes.rb | 7 +++++++ lib/tasks/counter_cache/update_counter_cache.rake | 2 ++ 11 files changed, 47 insertions(+) create mode 100644 app/controllers/studies/articles_controller.rb create mode 100644 app/controllers/studies/certifications_controller.rb create mode 100644 app/controllers/studies/dashboard_controller.rb create mode 100644 app/controllers/studies/projects_controller.rb create mode 100644 app/views/studies/certifications/index.html.erb create mode 100644 app/views/studies/projects/index.html.erb diff --git a/app/controllers/studies/articles_controller.rb b/app/controllers/studies/articles_controller.rb new file mode 100644 index 000000000..6cd9b83b9 --- /dev/null +++ b/app/controllers/studies/articles_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Studies + class ArticlesController < ApplicationController + include Pagy::Backend + + def index; end + end +end diff --git a/app/controllers/studies/certifications_controller.rb b/app/controllers/studies/certifications_controller.rb new file mode 100644 index 000000000..9202c5a68 --- /dev/null +++ b/app/controllers/studies/certifications_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Studies + class CertificationsController < ApplicationController + def index; end + end +end diff --git a/app/controllers/studies/dashboard_controller.rb b/app/controllers/studies/dashboard_controller.rb new file mode 100644 index 000000000..485d39463 --- /dev/null +++ b/app/controllers/studies/dashboard_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Studies + class DashboardController < ApplicationController + def index; end + end +end diff --git a/app/controllers/studies/projects_controller.rb b/app/controllers/studies/projects_controller.rb new file mode 100644 index 000000000..6574c700d --- /dev/null +++ b/app/controllers/studies/projects_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Studies + class ProjectsController < ApplicationController + def index; end + end +end diff --git a/app/views/layouts/shared/_sidebar.html.erb b/app/views/layouts/shared/_sidebar.html.erb index 256db3a70..e76f2fa80 100644 --- a/app/views/layouts/shared/_sidebar.html.erb +++ b/app/views/layouts/shared/_sidebar.html.erb @@ -53,6 +53,7 @@ <%= link_to users_path, class: 'nav-link' do %> <%= fa_icon('user', text: t('.users'), class: 'nav-icon') %> <% end %> + + diff --git a/app/views/studies/certifications/index.html.erb b/app/views/studies/certifications/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/studies/projects/index.html.erb b/app/views/studies/projects/index.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/locales/layouts/shared/sidebar_en.yml b/config/locales/layouts/shared/sidebar_en.yml index a03006c8d..71fb4f5a8 100644 --- a/config/locales/layouts/shared/sidebar_en.yml +++ b/config/locales/layouts/shared/sidebar_en.yml @@ -26,3 +26,4 @@ en: unit_statuses: Unit Statuses unit_types: Unit Types university_types: University Types + studies: Academic Studies diff --git a/config/locales/layouts/shared/sidebar_tr.yml b/config/locales/layouts/shared/sidebar_tr.yml index 88e5f36ff..22aa46c2a 100644 --- a/config/locales/layouts/shared/sidebar_tr.yml +++ b/config/locales/layouts/shared/sidebar_tr.yml @@ -26,3 +26,4 @@ tr: unit_statuses: Aktiflik Durumları unit_types: Birim Türleri university_types: Üniversite Türleri + studies: Akademik Çalışmalar diff --git a/config/routes.rb b/config/routes.rb index aea2ef890..f18707308 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,4 +71,11 @@ resources :unit_types, except: :show resources :university_types, except: :show end + + scope module: :studies do + get '/studies', to: 'dashboard#index' + get '/studies/articles', to: 'articles#index' + get '/studies/projects', to: 'projects#index' + get '/studies/certifications', to: 'certifications#index' + end end diff --git a/lib/tasks/counter_cache/update_counter_cache.rake b/lib/tasks/counter_cache/update_counter_cache.rake index f1934f767..123a85550 100644 --- a/lib/tasks/counter_cache/update_counter_cache.rake +++ b/lib/tasks/counter_cache/update_counter_cache.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + desc 'Counter cache for number of articles/projects a user have' namespace :update_counter_cache do From 112c4d58c30d845b53fad6f5b6a9d2198dac74f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 02:24:06 +0300 Subject: [PATCH 06/11] Add uniqueness validations and counter_caches to models --- app/models/academic_studies/article.rb | 6 +++--- app/models/academic_studies/certification.rb | 4 ++-- app/models/academic_studies/project.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/academic_studies/article.rb b/app/models/academic_studies/article.rb index 859adafbf..66f72d460 100644 --- a/app/models/academic_studies/article.rb +++ b/app/models/academic_studies/article.rb @@ -4,10 +4,10 @@ class Article < ApplicationRecord self.inheritance_column = nil # relations - belongs_to :user + belongs_to :user, counter_cache: true # validations - validates :yoksis_id, presence: true + validates :yoksis_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :title, presence: true # enums @@ -49,7 +49,7 @@ class Article < ApplicationRecord abstract: 6, book_review: 7, research_note: 8, - export_report: 9, + expert_report: 9, review_article: 10, short_article: 11 } diff --git a/app/models/academic_studies/certification.rb b/app/models/academic_studies/certification.rb index 2d4f697bc..262375786 100644 --- a/app/models/academic_studies/certification.rb +++ b/app/models/academic_studies/certification.rb @@ -7,9 +7,9 @@ class Certification < ApplicationRecord belongs_to :user # validations - validates :yoksis_id, presence: true - validates :type, presence: true + validates :yoksis_id, presence: true, uniqueness: { scope: %i[user_id status] } validates :title, presence: true + validates :type, presence: true # enums enum type: { diff --git a/app/models/academic_studies/project.rb b/app/models/academic_studies/project.rb index de9abf306..0788eda70 100644 --- a/app/models/academic_studies/project.rb +++ b/app/models/academic_studies/project.rb @@ -4,10 +4,10 @@ class Project < ApplicationRecord self.inheritance_column = nil # relations - belongs_to :user + belongs_to :user, counter_cache: true # validations - validates :yoksis_id, presence: true + validates :yoksis_id, presence: true, uniqueness: { scope: %i[user_id status] } # enums enum status: { From 9ade82ddba24d63d6232d924f680a65dcb05ba7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 02:34:44 +0300 Subject: [PATCH 07/11] Add some class methods to use in views --- app/models/academic_studies/article.rb | 8 ++++++++ app/models/unit.rb | 1 + app/models/user.rb | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/app/models/academic_studies/article.rb b/app/models/academic_studies/article.rb index 66f72d460..d281affb8 100644 --- a/app/models/academic_studies/article.rb +++ b/app/models/academic_studies/article.rb @@ -53,4 +53,12 @@ class Article < ApplicationRecord review_article: 10, short_article: 11 } + + def self.unique_count + active.group_by(&:yoksis_id).count + end + + def self.most_recent + order(created_at: :desc).first(10) + end end diff --git a/app/models/unit.rb b/app/models/unit.rb index 3907d23f2..4c5185638 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -20,6 +20,7 @@ class Unit < ApplicationRecord has_many :duties, dependent: :destroy has_many :employees, through: :duties has_many :students, dependent: :nullify + has_many :users, through: :employees has_many :positions, through: :duties has_many :administrative_functions, through: :duties diff --git a/app/models/user.rb b/app/models/user.rb index 73719eaf8..d4e5bb498 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,4 +49,8 @@ def build_identity_information def accounts (students + employees).flatten end + + def self.most_publishing + order('articles_count desc').first(10) + end end From b9f0996c2279d309ed46a68d7b64bd1d20debc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 02:35:08 +0300 Subject: [PATCH 08/11] Added APA helper for APA-like citations --- app/helpers/apa_helper.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/helpers/apa_helper.rb diff --git a/app/helpers/apa_helper.rb b/app/helpers/apa_helper.rb new file mode 100644 index 000000000..24a4cc29a --- /dev/null +++ b/app/helpers/apa_helper.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module ApaHelper + def apa_citation(article) + title = article.title.capitalize_all + + "#{authors_in_apa_format(article)}. #{title}. #{article.journal}, #{article.volume}(#{article.issue}), \ + #{article.first_page}-#{article.last_page}" + end + + def authors_in_apa_format(article) + apa_authors = [] + + article.authors.split(',').each do |author| + last_name = author.split(' ')[0].capitalize_all + first_name = author.split(' ')[1..-1].map! { |a| a[0] }.join('. ') + + apa_authors << ["#{last_name}, #{first_name}"] + end + + apa_authors.join(' & ') + end +end From f8cc19369727b0785609a3cef878bfbb46878797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Serhat=20D=C3=BCndar?= Date: Sat, 14 Jul 2018 02:35:25 +0300 Subject: [PATCH 09/11] Completed articles dashboard --- app/views/studies/articles/index.html.erb | 100 +++++++++++++++++++++ app/views/studies/dashboard/index.html.erb | 19 ++++ config/locales/models/studies/en.yml | 17 ++++ config/locales/models/studies/tr.yml | 17 ++++ 4 files changed, 153 insertions(+) create mode 100644 app/views/studies/articles/index.html.erb create mode 100644 app/views/studies/dashboard/index.html.erb create mode 100644 config/locales/models/studies/en.yml create mode 100644 config/locales/models/studies/tr.yml diff --git a/app/views/studies/articles/index.html.erb b/app/views/studies/articles/index.html.erb new file mode 100644 index 000000000..e7f23f0e3 --- /dev/null +++ b/app/views/studies/articles/index.html.erb @@ -0,0 +1,100 @@ +
+
+
+
+ +
+
<%= Article.unique_count %>
+
<%= t('.article') %>
+
+
+
+
+
+ +
+
+
+
+ <%= t('.top_publishers') %> +
+
+
    + <% User.most_publishing.each do |user| %> +
  • <%= user.identities.first.try(:first_name) %>
  • + <% end %> +
+
+
+
+ +
+
+
+ <%= t('.recently_added') %> +
+
+
    + <% Article.most_recent.each do |article| %> +
  • <%= apa_citation(article) %>
  • + <% end %> +
+
+
+
+ +
+
+
+ <%= t('.number_of_articles_by_years') %> +
+
+ <%= line_chart Article.active.group(:year).count %> +
+
+
+ + +
+
+
+ <%= t('.publications_by_index_types') %> +
+
+ <%= column_chart Article.active.group(:index).count %> +
+
+
+
+
+
+ <%= t('.publications_by_publication_types') %> +
+
+ <%= column_chart Article.active.group(:type).count %> +
+
+
+ +
+
+
+ <%= t('.publications_by_language') %> +
+
+ <%= pie_chart Article.active.group(:language_of_publication).count %> +
+
+
+ +
+
+
+ <%= t('.publications_by_number_of_authors') %> +
+
+ <%= bar_chart Article.active.group(:number_of_authors).count %> +
+
+
+
diff --git a/app/views/studies/dashboard/index.html.erb b/app/views/studies/dashboard/index.html.erb new file mode 100644 index 000000000..128744b50 --- /dev/null +++ b/app/views/studies/dashboard/index.html.erb @@ -0,0 +1,19 @@ +
+
+
+
+ +
+
+
+
diff --git a/config/locales/models/studies/en.yml b/config/locales/models/studies/en.yml new file mode 100644 index 000000000..53245dbef --- /dev/null +++ b/config/locales/models/studies/en.yml @@ -0,0 +1,17 @@ +en: + studies: + dashboard: + index: + articles: Articles + projects: Projects + certifications: Certifications + articles: + index: + article: Article + top_publishers: Top Publishing Academics + recently_added: Recently Added Articles + number_of_articles_by_years: Number of Articles by Years + publications_by_index_types: Publications by Index Types + publications_by_publication_types: Publications by Publication Types + publications_by_language: Publications by Publication Language + publications_by_number_of_authors: Publications by Number of Authors diff --git a/config/locales/models/studies/tr.yml b/config/locales/models/studies/tr.yml new file mode 100644 index 000000000..8d64426e8 --- /dev/null +++ b/config/locales/models/studies/tr.yml @@ -0,0 +1,17 @@ +tr: + studies: + dashboard: + index: + articles: Makaleler + projects: Projeler + certifications: Sertifikalar + articles: + index: + article: Makale + top_publishers: En Çok Makalesi Olanlar + recently_added: En Son Eklenen Makaleler + number_of_articles_by_years: Yıllara Göre Makale Sayısı + publications_by_index_types: Index Türüne Göre Makaleler + publications_by_publication_types: Yayın Türüne Göre Makaleler + publications_by_language: Yayın Dili Göre Makaleler + publications_by_number_of_authors: Yazar Sayısına Göre Makaleler From 1bacc1c71398864111422a830ebcaa8a0f1c3ef9 Mon Sep 17 00:00:00 2001 From: msdundar Date: Sat, 14 Jul 2018 19:36:06 +0300 Subject: [PATCH 10/11] . --- app/helpers/apa_helper.rb | 20 ++++++++------------ app/models/academic_studies/article.rb | 2 +- app/models/user.rb | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/helpers/apa_helper.rb b/app/helpers/apa_helper.rb index 24a4cc29a..a4a1b0ab7 100644 --- a/app/helpers/apa_helper.rb +++ b/app/helpers/apa_helper.rb @@ -4,20 +4,16 @@ module ApaHelper def apa_citation(article) title = article.title.capitalize_all - "#{authors_in_apa_format(article)}. #{title}. #{article.journal}, #{article.volume}(#{article.issue}), \ - #{article.first_page}-#{article.last_page}" + "#{authors_in_apa_format(article)}. (#{article.year}). #{title}. #{article.journal}, \ + #{article.volume}(#{article.issue}), #{article.first_page}-#{article.last_page}" end def authors_in_apa_format(article) - apa_authors = [] - - article.authors.split(',').each do |author| - last_name = author.split(' ')[0].capitalize_all - first_name = author.split(' ')[1..-1].map! { |a| a[0] }.join('. ') - - apa_authors << ["#{last_name}, #{first_name}"] - end - - apa_authors.join(' & ') + article.authors.split(',').map do |author| + names = author.split + last_name = names.shift.capitalize_all + first_name = names.map(&:first).join('. ') + "#{last_name}, #{first_name}" + end.join(' & ') end end diff --git a/app/models/academic_studies/article.rb b/app/models/academic_studies/article.rb index d281affb8..c2d963431 100644 --- a/app/models/academic_studies/article.rb +++ b/app/models/academic_studies/article.rb @@ -59,6 +59,6 @@ def self.unique_count end def self.most_recent - order(created_at: :desc).first(10) + order(created_at: :desc).limit(10) end end diff --git a/app/models/user.rb b/app/models/user.rb index d4e5bb498..740819aa3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,6 +51,6 @@ def accounts end def self.most_publishing - order('articles_count desc').first(10) + order('articles_count desc').limit(10) end end From 001e0d3d97e22fe145916c8c735b0e18e56d0a8f Mon Sep 17 00:00:00 2001 From: msdundar Date: Sat, 14 Jul 2018 19:37:20 +0300 Subject: [PATCH 11/11] . --- app/helpers/apa_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/apa_helper.rb b/app/helpers/apa_helper.rb index a4a1b0ab7..828130252 100644 --- a/app/helpers/apa_helper.rb +++ b/app/helpers/apa_helper.rb @@ -12,7 +12,7 @@ def authors_in_apa_format(article) article.authors.split(',').map do |author| names = author.split last_name = names.shift.capitalize_all - first_name = names.map(&:first).join('. ') + first_name = names.map(&:first).join('. ') "#{last_name}, #{first_name}" end.join(' & ') end