-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature for view issue telegram messages and publish selected of its
- Loading branch information
Showing
9 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module TelegramMessagesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |