Class: WcoEmail::ConversationsController
- Inherits:
-
ApplicationController
- Object
- Wco::ApplicationController
- ApplicationController
- WcoEmail::ConversationsController
- Defined in:
- app/controllers/wco_email/conversations_controller.rb
Instance Method Summary collapse
-
#addtag ⇒ Object
many tags to many convs.
- #edit ⇒ Object
- #index ⇒ Object
-
#merge ⇒ Object
merge conv1 into conv2, and delete conv1.
- #rmtag ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#addtag ⇒ Object
many tags to many convs
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 10 def addtag :addtag, WcoEmail::Conversation inbox = Wco::Tag.inbox outs = @convs.map do |conv| conv..push @tags conv..delete( inbox ) if params[:is_move] conv.save end flash_notice "Outcomes: #{outs}" render json: { status: 'ok' } # redirect_to request.referrer # || root_path end |
#edit ⇒ Object
25 26 27 28 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 25 def edit @conversation = ::WcoEmail::Conversation.find( params[:id] ) :edit, @conversation end |
#index ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 30 def index :index, WcoEmail::Conversation @conversations = WcoEmail::Conversation.all if params[:tagname] @tag = Wco::Tag.find_by slug: params[:tagname] @conversations = @conversations.where( :tag_ids.in => [ @tag.id ] ) end if params[:tagname_not] @tag_not = Wco::Tag.find_by slug: params[:tagname_not] @conversations = @conversations.where( :tag_ids.nin => [ @tag_not.id ] ) end if params[:subject].present? @conversations = @conversations.where({ subject: /.*#{params[:subject]}.*/i }) end if params[:from_email].present? @conversations = @conversations.where({ from_emails: /.*#{params[:from_email]}.*/i }) end if params[:lead_id].present? @conversations = @conversations.where( lead_ids: params[:lead_id] ) end @conversations = @conversations.where( ).includes( :leads, :messages, :tags ).order_by( latest_at: :desc ).page( params[:conv_page] ).per( current_profile.per_page ) conversation_ids = @conversations.map &:id @messages_hash = {} = WcoEmail::Message.where( :conversation_id.in => conversation_ids, read_at: nil, ) .map do |msg| @messages_hash[msg.id.to_s] = msg end end |
#merge ⇒ Object
merge conv1 into conv2, and delete conv1
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 73 def merge :merge, WcoEmail::Conversation conv1 = WcoEmail::Conversation.find params[:id1] conv2 = WcoEmail::Conversation.find params[:id2] conv1..map do |msg| msg.update conversation: conv2 end conv1..map do |tag| conv2..push tag end conv1.leads.map do |lead| conv2.leads.push lead end conv2.save! conv1.delete flash_notice "Probably ok" redirect_to action: :show, id: conv2.id end |
#rmtag ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 93 def rmtag :addtag, WcoEmail::Conversation outs = @convs.map do |conv| @tags.map do |tag| conv..delete( tag ) end conv.save end flash_notice "Outcomes: #{outs}" render json: { status: 'ok' } # redirect_to request.referrer || root_path end |
#show ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 107 def show @conversation = ::WcoEmail::Conversation.find( params[:id] ) :show, @conversation @messages = @conversation.( ).order_by( date: :asc ).page( params[:messages_page ] ).per( @current_profile.per_page ) @conversation.update_attributes({ status: Conv::STATUS_READ }) @conversation..unread.update_all({ read_at: Time.now }) # @other_convs = WcoEmail::Message.where( :message_id.in => @messages.map( &:in_reply_to_id ) # ).where( :conversation_id.ne => @conversation.id # ).map( &:conversation_id ).uniq # other_convs_by_subj = WcoEmail::Conversation.where( subject: @conversation.subject # ).where( :conversation_id.ne => @conversation.id # ).map( &:id ) # if @other_convs.present? || other_convs_by_subj.present? # @other_convs = WcoEmail::Conversation.find( @other_convs + other_convs_by_subj ) # end end |
#update ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/wco_email/conversations_controller.rb', line 130 def update @conversation = ::WcoEmail::Conversation.find( params[:id] ) :update, @conversation if @conversation.update( params[:conversation].permit! ) flash_notice 'ok' else flash_alert @conversation end redirect_to action: 'show', id: @conversation.id end |