Skip to content

Commit

Permalink
Add feature for view issue telegram messages and publish selected of its
Browse files Browse the repository at this point in the history
  • Loading branch information
arturtr committed Mar 23, 2016
1 parent e063d65 commit 7c4cfde
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/controllers/telegram_messages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class TelegramMessagesController < ApplicationController
unloadable


def index
@issue = Issue.visible.find(params[:id])
@telegram_messages = @issue.telegram_messages
end

def publish
@issue = Issue.visible.find(params[:id])
@telegram_messages = @issue.telegram_messages.where(id: params[:telegram_message_ids])
@issue.init_journal(User.current, @telegram_messages.as_text)
@issue.save
redirect_to @issue
end
end
2 changes: 2 additions & 0 deletions app/helpers/telegram_messages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TelegramMessagesHelper
end
17 changes: 17 additions & 0 deletions app/models/telegram_message.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
class TelegramMessage < ActiveRecord::Base
unloadable

include Redmine::I18n

def self.as_text
all.map(&:as_text).join("\n\n")
end

def as_text
format_time(sent_at) + ' ' + author_name + ': ' + message
end

def author_name
full_name = [from_first_name, from_last_name].join(' ')
full_name.present? ? full_name : from_username
end


end
2 changes: 2 additions & 0 deletions app/views/telegram_group_chats/_link_or_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<%= image_tag '/plugin_assets/redmine_chat_telegram/images/telegram-icon.png' %>
Войти в чат Telegram
<% end %>
<br>
<%= link_to 'Архив сообщений из чата', issue_telegram_messages_path(@issue.id) %>
<% else %>
<%= link_to telegram_group_chats_path(issue_id: @issue.id), method: :post, remote: true do %>
<%= image_tag '/plugin_assets/redmine_chat_telegram/images/telegram-icon.png' %>
Expand Down
9 changes: 9 additions & 0 deletions app/views/telegram_messages/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_tag publish_issue_telegram_messages_path do %>
<% @telegram_messages.each do |message| %>
<%= check_box_tag 'telegram_message_ids[]', message.id %>
<time><%= format_time message.sent_at %></time>
<strong><%= message.author_name %>:</strong>
<%= simple_format message.message %>
<% end %>
<%= submit_tag 'Сохранить в задаче' %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
resources :telegram_group_chats, only: :create
get 'issues/:id/telegram_messages' => 'telegram_messages#index', as: 'issue_telegram_messages'
post 'issues/:id/telegram_messages/publish' => 'telegram_messages#publish', as: 'publish_issue_telegram_messages'
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

require 'redmine'
require_dependency 'redmine_chat_telegram/hook_listener'
require_dependency 'redmine_chat_telegram/issue_patch'

Redmine::Plugin.register :redmine_chat_telegram do
name 'Redmine Chat Telegram plugin'
url 'https://github.com/centosadmin/redmine_chat_telegram'
description 'This is a plugin for Redmine which adds Telegram Group Chat to Redmine Issue'
version '0.0.6'
version '0.1.0'
author 'Centos-admin.ru'
author_url 'http://centos-admin.ru'

Expand Down
13 changes: 13 additions & 0 deletions lib/redmine_chat_telegram/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ChatTelegram
module IssuePatch
def self.included(base) # :nodoc:
base.class_eval do
unloadable

has_many :telegram_messages
end
end

end
end
Issue.send(:include, ChatTelegram::IssuePatch)
8 changes: 8 additions & 0 deletions test/functional/telegram_messages_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)

class TelegramMessagesControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

0 comments on commit 7c4cfde

Please sign in to comment.