├── .github └── FUNDING.yml ├── app ├── helpers │ └── like_helper.rb ├── models │ ├── like.rb │ ├── like_mailer.rb │ └── like_constants.rb ├── views │ ├── like_mailer │ │ ├── on_like.text.erb │ │ └── on_like.html.erb │ ├── issues │ │ ├── _issuesShowDetailsBottom.html.erb │ │ └── _issuesHistoryJournalBottom.html.erb │ ├── wiki │ │ └── _layoutsBaseContent.html.erb │ └── like │ │ ├── _likeIcon.html.erb │ │ └── index.html.erb └── controllers │ └── like_controller.rb ├── assets ├── images │ ├── like_total.png │ ├── icon_heart_on.png │ ├── icon_star_off.png │ ├── icon_star_on.png │ ├── issue_page_ss.png │ ├── summary_page.png │ ├── type_of_icons.png │ ├── wiki_page_ss.png │ ├── icon_heart_off.png │ ├── like_tooltip_ss.png │ ├── icon_thumbsup_off.png │ ├── icon_thumbsup_on.png │ ├── icon_heart_shadow_on.png │ ├── icon_star_shadow_off.png │ ├── icon_star_shadow_on.png │ ├── icon_heart_shadow_off.png │ ├── icon_thumbsup_shadow_on.png │ └── icon_thumbsup_shadow_off.png ├── stylesheets │ └── like.css └── javascripts │ └── like.js ├── test ├── test_helper.rb ├── unit │ ├── like_test.rb │ └── like_mailer_test.rb └── functional │ └── like_controller_test.rb ├── db └── migrate │ ├── 202204292130_add_author_id_to_likes.rb │ └── 001_create_likes.rb ├── config ├── routes.rb └── locales │ ├── ja.yml │ └── en.yml ├── init.rb ├── LICENSE ├── README.md └── lib └── like └── hooks.rb /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | liberapay: happy-se-life 2 | -------------------------------------------------------------------------------- /app/helpers/like_helper.rb: -------------------------------------------------------------------------------- 1 | module LikeHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/models/like.rb: -------------------------------------------------------------------------------- 1 | class Like < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/views/like_mailer/on_like.text.erb: -------------------------------------------------------------------------------- 1 | <%= @title %> 2 | <%= @content %> 3 | -------------------------------------------------------------------------------- /app/views/like_mailer/on_like.html.erb: -------------------------------------------------------------------------------- 1 |

<%= @title %>

2 |

<%= @content %>

3 | -------------------------------------------------------------------------------- /assets/images/like_total.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/like_total.png -------------------------------------------------------------------------------- /assets/images/icon_heart_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_heart_on.png -------------------------------------------------------------------------------- /assets/images/icon_star_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_star_off.png -------------------------------------------------------------------------------- /assets/images/icon_star_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_star_on.png -------------------------------------------------------------------------------- /assets/images/issue_page_ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/issue_page_ss.png -------------------------------------------------------------------------------- /assets/images/summary_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/summary_page.png -------------------------------------------------------------------------------- /assets/images/type_of_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/type_of_icons.png -------------------------------------------------------------------------------- /assets/images/wiki_page_ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/wiki_page_ss.png -------------------------------------------------------------------------------- /assets/images/icon_heart_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_heart_off.png -------------------------------------------------------------------------------- /assets/images/like_tooltip_ss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/like_tooltip_ss.png -------------------------------------------------------------------------------- /assets/images/icon_thumbsup_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_thumbsup_off.png -------------------------------------------------------------------------------- /assets/images/icon_thumbsup_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_thumbsup_on.png -------------------------------------------------------------------------------- /assets/images/icon_heart_shadow_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_heart_shadow_on.png -------------------------------------------------------------------------------- /assets/images/icon_star_shadow_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_star_shadow_off.png -------------------------------------------------------------------------------- /assets/images/icon_star_shadow_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_star_shadow_on.png -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Load the Redmine helper 2 | require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') 3 | -------------------------------------------------------------------------------- /assets/images/icon_heart_shadow_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_heart_shadow_off.png -------------------------------------------------------------------------------- /assets/images/icon_thumbsup_shadow_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_thumbsup_shadow_on.png -------------------------------------------------------------------------------- /assets/images/icon_thumbsup_shadow_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/happy-se-life/like/master/assets/images/icon_thumbsup_shadow_off.png -------------------------------------------------------------------------------- /app/views/issues/_issuesShowDetailsBottom.html.erb: -------------------------------------------------------------------------------- 1 | <%= render :partial => "like/likeIcon", :locals => { id: id, count: count, type: type, design: design, like_senders: like_senders} %> -------------------------------------------------------------------------------- /app/views/issues/_issuesHistoryJournalBottom.html.erb: -------------------------------------------------------------------------------- 1 | <%= render :partial => "like/likeIcon", :locals => { id: id, count: count, type: type, design: design, like_senders: like_senders} %> -------------------------------------------------------------------------------- /app/models/like_mailer.rb: -------------------------------------------------------------------------------- 1 | class LikeMailer < Mailer 2 | def on_like(user_to, title, content) 3 | @title = title 4 | @content = content 5 | mail to: user_to.mail, subject: @title 6 | end 7 | end -------------------------------------------------------------------------------- /test/unit/like_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../test_helper', __FILE__) 2 | 3 | class LikeTest < ActiveSupport::TestCase 4 | 5 | # Replace this with your real tests. 6 | def test_truth 7 | assert true 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/unit/like_mailer_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../test_helper', __FILE__) 2 | 3 | class LikeMailerTest < ActiveSupport::TestCase 4 | 5 | # Replace this with your real tests. 6 | def test_truth 7 | assert true 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/functional/like_controller_test.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../test_helper', __FILE__) 2 | 3 | class LikeControllerTest < ActionController::TestCase 4 | # Replace this with your real tests. 5 | def test_truth 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/202204292130_add_author_id_to_likes.rb: -------------------------------------------------------------------------------- 1 | class AddAuthorIdToLikes < ActiveRecord::Migration[4.2] 2 | def up 3 | add_column :likes, :author_id, :integer, :default => nil, :after => :like_id 4 | end 5 | 6 | def down 7 | remove_column :author_id 8 | end 9 | end -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | # Plugin's routes 2 | # See: http://guides.rubyonrails.org/routing.html 3 | Rails.application.routes.draw do 4 | resources :like 5 | post 'issues/update_like', to: 'like#update_like' 6 | post 'projects/:id/update_like', to: 'like#update_like' 7 | post 'projects/:id/wiki/update_like', to: 'like#update_like' 8 | end -------------------------------------------------------------------------------- /app/views/wiki/_layoutsBaseContent.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <%= javascript_include_tag "like", :plugin => "like" %> 3 | 4 | <%= stylesheet_link_tag "like", :plugin => "like" %> 5 | <% if is_wiki == true %> 6 | <%= render :partial => "like/likeIcon", :locals => { id: id, count: count, type: type, design: design, like_senders: like_senders} %> 7 | <% end %> -------------------------------------------------------------------------------- /db/migrate/001_create_likes.rb: -------------------------------------------------------------------------------- 1 | class CreateLikes < ActiveRecord::Migration[4.2] 2 | def change 3 | create_table :likes do |t| 4 | t.integer :user_id, :null => false 5 | t.integer :like_id, :null => false 6 | t.string :like_type, :null => false 7 | t.timestamps :null => false 8 | end 9 | add_index :likes, [:like_id, :like_type] 10 | add_index :likes, :user_id 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /config/locales/ja.yml: -------------------------------------------------------------------------------- 1 | # Japanese strings go here for Rails i18n 2 | ja: 3 | like_label_like: "いいね!" 4 | like_field_user: "名前" 5 | like_field_count_for_issue: "チケット" 6 | like_field_count_for_journal: "注記" 7 | like_field_count_for_wiki: "Wiki" 8 | like_field_count_total: "計" 9 | like_mail_title: "%{name}さんがあなたの%{kind}にいいね!しました" 10 | like_label_received_count: "受け取ったいいねの数" 11 | like_label_sent_count: "送ったいいねの数" 12 | -------------------------------------------------------------------------------- /app/models/like_constants.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Constant definition 3 | # 4 | class LikeConstants 5 | # 6 | # Choose an icon design 7 | # "icon_heart" 8 | # "icon_heart_shadow" 9 | # "icon_star" 10 | # "icon_star_shadow" 11 | # "icon_thumbsup" 12 | # "icon_thumbsup_shadow" 13 | # 14 | ICON_DESIGN = "icon_heart" 15 | # 16 | # Enable mail notification (1:on 0:off) 17 | ENABLE_MAIL_NOTIFICATION = 0 18 | end 19 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # English strings go here for Rails i18n 2 | en: 3 | like_label_like: "LIKE!" 4 | like_field_user: "Name" 5 | like_field_count_for_issue: "Ticket" 6 | like_field_count_for_journal: "Notes" 7 | like_field_count_for_wiki: "Wiki" 8 | like_field_count_total: "Total" 9 | like_mail_title: "%{name} liked your %{kind}" 10 | like_label_received_count: "Number of likes received" 11 | like_label_sent_count: "The number of likes sent" 12 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | Redmine::Plugin.register :like do 2 | name 'Like plugin' 3 | author 'Kohei Nomura' 4 | description 'This plug-in allows you to send the likes.' 5 | version '0.0.3' 6 | url 'https://github.com/happy-se-life/like' 7 | author_url 'mailto:kohei_nom@yahoo.co.jp' 8 | require_dependency File.expand_path('../lib/like/hooks', __FILE__) 9 | menu :application_menu, :like, { :controller => 'like', :action => 'index' }, :caption => :like_label_like, :if => Proc.new { User.current.logged? } 10 | end -------------------------------------------------------------------------------- /assets/stylesheets/like.css: -------------------------------------------------------------------------------- 1 | .like-icon-outer { 2 | width: 40px; 3 | margin-left: auto; 4 | text-align: right; 5 | cursor: pointer; 6 | } 7 | 8 | .like-side-by-side p{ 9 | display: inline-block; 10 | vertical-align: middle; 11 | } 12 | 13 | .like-sender-tooltip { 14 | position: relative; 15 | cursor: pointer; 16 | } 17 | .like-sender-tooltip p{ 18 | margin:0; 19 | padding:0; 20 | } 21 | .like-sender-content { 22 | display: none; 23 | position: absolute; 24 | padding: 10px; 25 | font-size: x-small; 26 | text-align: left; 27 | color: #fff; 28 | border-radius: 5px; 29 | background: #000; 30 | width: 100px; 31 | } 32 | .like-sender-content:before { 33 | content: ""; 34 | position: absolute; 35 | top: 0px; 36 | left: 120px; 37 | border: 15px solid transparent; 38 | border-top: 15px solid #000; 39 | margin-left: -5px; 40 | transform: rotateZ(270deg); 41 | } 42 | .like-sender-tooltip:hover .like-sender-content{ 43 | display: inline-block; 44 | top: -10px; 45 | left: -120px; 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 happy-se-life 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/views/like/_likeIcon.html.erb: -------------------------------------------------------------------------------- 1 | 2 | <% icon_off = design + "_off.png" %> 3 | <% icon_on = design + "_on.png" %> 4 | <% if count != 0 then %> 5 |
6 | <% else %> 7 |
8 | <% end %> 9 | 13 | 17 | 24 |
25 | 26 | -------------------------------------------------------------------------------- /app/views/like/index.html.erb: -------------------------------------------------------------------------------- 1 |

<%= I18n.t(:like_label_like) %>

2 |

<%= I18n.t(:like_label_received_count) %>

3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | <% @users.each{|user| %> 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | <% } %> 20 |
<%= I18n.t(:like_field_user) %>⁠<%= I18n.t(:like_field_count_for_issue) %><%= I18n.t(:like_field_count_for_journal) %><%= I18n.t(:like_field_count_for_wiki) %><%= I18n.t(:like_field_count_total) %>
<%= user.lastname %><%= @like_received_count_for_issue[user.id] %><%= @like_received_count_for_journal[user.id] %><%= @like_received_count_for_wiki[user.id] %><%= @like_received_count_total[user.id] %>
21 |
22 |

<%= I18n.t(:like_label_sent_count) %>

23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | <% @users.each{|user| %> 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | <% } %> 40 |
<%= I18n.t(:like_field_user) %>⁠<%= I18n.t(:like_field_count_for_issue) %><%= I18n.t(:like_field_count_for_journal) %><%= I18n.t(:like_field_count_for_wiki) %><%= I18n.t(:like_field_count_total) %>
<%= user.lastname %><%= @like_sent_count_for_issue[user.id] %><%= @like_sent_count_for_journal[user.id] %><%= @like_sent_count_for_wiki[user.id] %><%= @like_sent_count_total[user.id] %>
41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redmine like plugin 2 | This plugin allows you to send the like on Redmine. It is a very simple plugin, so please modify it freely. 3 | 4 | ## What's new 5 | * Started accepting donations using Liberapay. The donate button is in the right sidebar. 6 | * Add the number of likes received to the summary page #6 (Attention: need Migration) 7 |
 8 | bundle exec rake redmine:plugins:migrate RAILS_ENV=production
 9 | 
10 | * You can now view the person who liked it with a tooltip. #2 11 | * Added support for Redmine version 4.1 or later. #1 12 | * Added email notification settings (on or off). 13 | 14 | ## Features 15 | * You can like issues, notes and wikis. 16 | * e-mail notifications when someone likes you. 17 | * View the number of likes recieved/sent each user on the summary page. 18 | 19 | ## Screenshots 20 | 21 | ### Issues and notes 22 | 23 | 24 | ### Wiki 25 | 26 | 27 | ### Tooltip of the person who liked it 28 | 29 | 30 | ### 6 types of icons 31 | * To change the icon, you need to change ICON_DESIGN in models/like_constants.rb. 32 | 33 | 34 | 35 | ### Display of total number of likes 36 | 37 | 38 | ## Install 39 | 40 | 1. Move to plugins folder. 41 | 42 | 2. Put the code. 43 |
44 | git clone https://github.com/happy-se-life/like.git
45 | 
46 | 47 | 3. Run migration. 48 |
49 | bundle exec rake redmine:plugins:migrate NAME=like RAILS_ENV=production
50 | 
51 | 52 | 4. Edit models/LikeConstants.rb to chose icon type. 53 | 54 | 5. Restart redmine. 55 | 56 | ## Uninstall 57 | 58 | 1. Move to plugins folder. 59 | 60 | 2. Rollback migration. 61 |
62 | bundle exec rake redmine:plugins:migrate NAME=like VERSION=0 RAILS_ENV=production
63 | 
64 | 65 | 3. Remove plugins folder. 66 |
67 | rm -rf like
68 | 
69 | 70 | 4. Restart redmine. 71 | 72 | ## Limitation 73 | * Only supports English and Japanese. 74 | 75 | ## License 76 | * MIT Lisense 77 | -------------------------------------------------------------------------------- /assets/javascripts/like.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | $('[id^=heart-icon-main-]').click(function() { 3 | var arr = $(this).attr('id').split('-'); 4 | var like_id = arr[4]; 5 | var like_type = arr[3]; 6 | // AJAX 7 | $.ajax({ 8 | url:'./update_like', 9 | type:'POST', 10 | data:{ 11 | 'like_id' :like_id, 12 | 'like_type' :like_type, 13 | }, 14 | dataType: 'json', 15 | async: true 16 | }).done( (data) => { 17 | var count = Number(data.count); 18 | if (count == 0) { 19 | $('#heart-on-' + like_type + '-' + like_id).hide(); 20 | $('#heart-off-' + like_type + '-' + like_id).show(); 21 | $('#heart-off-count-' + like_type + '-' + like_id).text(count); 22 | $('#heart-icon-main-' + like_type + '-' + like_id).removeClass('like-sender-tooltip'); 23 | $('#heart-senders-' + like_type + '-' + like_id).html(''); 24 | } 25 | if (count > 0) { 26 | $('#heart-off-' + like_type + '-' + like_id).hide(); 27 | $('#heart-on-' + like_type + '-' + like_id).show(); 28 | $('#heart-on-count-' + like_type + '-' + like_id).text(count); 29 | $('#heart-icon-main-' + like_type + '-' + like_id).addClass('like-sender-tooltip'); 30 | $('#heart-senders-' + like_type + '-' + like_id).html(data.senders); 31 | } 32 | }).fail( (data) => { 33 | console.log("AJAX FAILED."); 34 | }); 35 | }); 36 | 37 | // Resolved an issue with duplicate icons in version 4.1 38 | 39 | if ($('#tab-properties').attr('class') == 'selected') { 40 | $('[id^=heart-icon-main-]').hide(); 41 | } 42 | 43 | $('#tab-history').click(function() { 44 | $('[id^=heart-icon-main-]').hide(); 45 | }); 46 | 47 | $('#tab-notes').click(function() { 48 | $('[id^=heart-icon-main-]').show(); 49 | }); 50 | 51 | $('#tab-properties').click(function() { 52 | $('[id^=heart-icon-main-]').hide(); 53 | }); 54 | 55 | $('#tab-time_entries').click(function() { 56 | $('[id^=heart-icon-main-]').hide(); 57 | }); 58 | 59 | $('#tab-changesets').click(function() { 60 | $('[id^=heart-icon-main-]').hide(); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /lib/like/hooks.rb: -------------------------------------------------------------------------------- 1 | module Like::Hooks 2 | class Hooks < Redmine::Hook::ViewListener 3 | # Like icon on issue 4 | def view_issues_show_details_bottom(context={}) 5 | like = Like.where(like_id: context[:issue].id).where(like_type: 'issue') 6 | like_count = like.length 7 | like_sender_ids = like.pluck(:user_id) 8 | like_senders = User.where(id: like_sender_ids) 9 | icon_design = LikeConstants::ICON_DESIGN 10 | context[:controller].send(:render_to_string, { 11 | :partial => "issues/issuesShowDetailsBottom", 12 | :locals => { id: context[:issue].id, count: like_count, type: 'issue', design: icon_design, like_senders: like_senders} 13 | }) 14 | end 15 | # Like icon on Journal 16 | def view_issues_history_journal_bottom(context={}) 17 | if context[:journal].notes.blank? then 18 | # Resolved an issue with duplicate icons in version 4.1 19 | return 20 | end 21 | like = Like.where(like_id: context[:journal].id).where(like_type: 'journal') 22 | like_count = like.length 23 | like_sender_ids = like.pluck(:user_id) 24 | like_senders = User.where(id: like_sender_ids) 25 | icon_design = LikeConstants::ICON_DESIGN 26 | context[:controller].send(:render_to_string, { 27 | :partial => "issues/issuesHistoryJournalBottom", 28 | :locals => { id: context[:journal].id, count: like_count, type: 'journal', design: icon_design, like_senders: like_senders} 29 | }) 30 | end 31 | # Like icon on Wiki 32 | def view_layouts_base_content(context={}) 33 | request = context[:request] 34 | if context[:controller].controller_name == 'wiki' && context[:controller].action_name == 'show' then 35 | wiki_title = URI.decode(request.path.split("/").last) 36 | str = URI.decode(request.path.split("/projects/").last) 37 | identifier = str.split("/wiki/").first 38 | wiki_pages = WikiPage.where(title: wiki_title) 39 | for wiki_page in wiki_pages do 40 | if wiki_page.project.identifier == identifier then 41 | wiki = wiki_page 42 | break 43 | else 44 | wiki = nil 45 | end 46 | end 47 | if wiki != nil then 48 | wiki_id = wiki.id 49 | like = Like.where(like_id: wiki_id).where(like_type: 'wiki') 50 | like_count = like.length 51 | like_sender_ids = like.pluck(:user_id) 52 | like_senders = User.where(id: like_sender_ids) 53 | is_wiki = true 54 | else 55 | wiki_id = 0 56 | like_count = 0 57 | is_wiki = false 58 | end 59 | else 60 | wiki_id = 0 61 | like_count = 0 62 | is_wiki = false 63 | end 64 | icon_design = LikeConstants::ICON_DESIGN 65 | context[:controller].send(:render_to_string, { 66 | :partial => "wiki/layoutsBaseContent", 67 | :locals => { id: wiki_id, count: like_count, type: 'wiki', is_wiki: is_wiki, design: icon_design, like_senders: like_senders} 68 | }) 69 | end 70 | end 71 | end -------------------------------------------------------------------------------- /app/controllers/like_controller.rb: -------------------------------------------------------------------------------- 1 | class LikeController < ApplicationController 2 | unloadable 3 | before_action :global_authorize 4 | 5 | # Display the totals of likes 6 | def index 7 | @like_sent_count_for_issue = {} 8 | @like_sent_count_for_journal = {} 9 | @like_sent_count_for_wiki = {} 10 | @like_sent_count_total = {} 11 | 12 | @like_received_count_for_issue = {} 13 | @like_received_count_for_journal = {} 14 | @like_received_count_for_wiki = {} 15 | @like_received_count_total = {} 16 | 17 | # Counting for each user 18 | @users = User.where(type: "User").where(status: 1) 19 | @users.each do |user| 20 | # The number of likes sent 21 | issue_count = Like.where(user_id: user.id).where(like_type: 'issue').length 22 | journal_count = Like.where(user_id: user.id).where(like_type: 'journal').length 23 | wiki_count = Like.where(user_id: user.id).where(like_type: 'wiki').length 24 | 25 | @like_sent_count_for_issue[user.id] = issue_count 26 | @like_sent_count_for_journal[user.id] = journal_count 27 | @like_sent_count_for_wiki[user.id] = wiki_count 28 | @like_sent_count_total[user.id] = issue_count + journal_count + wiki_count 29 | 30 | # Number of likes received 31 | issue_count = Like.where(author_id: user.id).where(like_type: 'issue').length 32 | journal_count = Like.where(author_id: user.id).where(like_type: 'journal').length 33 | wiki_count = Like.where(author_id: user.id).where(like_type: 'wiki').length 34 | 35 | @like_received_count_for_issue[user.id] = issue_count 36 | @like_received_count_for_journal[user.id] = journal_count 37 | @like_received_count_for_wiki[user.id] = wiki_count 38 | @like_received_count_total[user.id] = issue_count + journal_count + wiki_count 39 | end 40 | end 41 | 42 | # Update number of likes 43 | def update_like 44 | # Get post value 45 | like_id = params[:like_id] 46 | like_type = params[:like_type] 47 | 48 | # Referer 49 | referer = request.env['HTTP_REFERER'] 50 | 51 | # Get like 52 | like = Like.where(like_id: like_id).where(like_type: like_type) 53 | count = like.length 54 | own_like = like.where(user_id: User.current.id) 55 | own_count = own_like.length 56 | 57 | if own_count == 0 then 58 | # Get user to send 59 | case like_type 60 | when 'issue' then 61 | kind = I18n.t(:label_issue) 62 | issue = Issue.find(like_id) 63 | user_to = User.find(issue.author_id) 64 | author_id = issue.author_id 65 | when 'journal' then 66 | kind = I18n.t(:field_notes) 67 | journal = Journal.find(like_id) 68 | user_to = User.find(journal.user_id) 69 | author_id = journal.user_id 70 | when 'wiki' then 71 | kind = I18n.t(:label_wiki) 72 | wiki_content = WikiPage.find(like_id).content 73 | user_to = User.find(wiki_content.author_id) 74 | author_id = wiki_content.author_id 75 | else 76 | # nothing to do 77 | end 78 | # Add 79 | new_like = Like.new(user_id: User.current.id, like_id: like_id, author_id: author_id, like_type: like_type) 80 | new_like.save! 81 | # Send a mail 82 | if LikeConstants::ENABLE_MAIL_NOTIFICATION == 1 && defined? kind 83 | title = I18n.t(:like_mail_title, :name => User.current.lastname, :kind => kind) 84 | content = referer.to_s 85 | LikeMailer.on_like(user_to, title, content).deliver 86 | end 87 | count = count + 1 88 | else 89 | # Remove 90 | own_like.delete_all 91 | count = count - 1 92 | end 93 | 94 | # Create senders string 95 | latest_like = Like.where(like_id: like_id).where(like_type: like_type) 96 | latest_like_sender_ids = latest_like.pluck(:user_id) 97 | latest_like_senders = User.where(id: latest_like_sender_ids) 98 | senders = "" 99 | latest_like_senders.each {|user| 100 | senders += "

" + CGI.escapeHTML(user.name) + "

" 101 | } 102 | 103 | # Return json 104 | result_hash = {} 105 | result_hash["count"] = count 106 | result_hash["senders"] = senders 107 | render json: result_hash 108 | end 109 | 110 | def global_authorize 111 | @current_user ||= User.current 112 | render_403 unless @current_user.type == 'User' 113 | end 114 | end 115 | --------------------------------------------------------------------------------