Add messaging to order (closes #327) #350

Merged
merged 1 commit into from Apr 10, 2015

Projects

None yet

2 participants

@paroga
Contributor
paroga commented Feb 18, 2015

No description provided.

@wvengen
Member
wvengen commented Feb 18, 2015

Yay, very good idea!

Messaging is done in a plugin, so this would need to go into a deface override. See this example.

@wvengen wvengen commented on an outdated diff Feb 18, 2015
plugins/messages/app/models/message.rb
@@ -40,6 +40,15 @@ def group_id=(group_id)
add_recipients Group.find(group_id).users unless group_id.blank?
end
+ def order_id=(order_id)
+ @order_id = order_id
+ unless order_id.blank?
@wvengen
wvengen Feb 18, 2015 Member

why this check?

@paroga
Contributor
paroga commented Feb 18, 2015

ad deface) i know, but I wasn't able to get it working :-/
ad check) yes, it's not necessary any more

@wvengen
Member
wvengen commented Feb 18, 2015

What did you try with deface?

@paroga
Contributor
paroga commented Feb 18, 2015

create a file in orders/show folder with similar content of your example

@wvengen
Member
wvengen commented Feb 18, 2015

Ok, I'm trying now with deface - and run into the old bug where :javascript in the original breaks it - spree/deface#125. Solution would be to move the javascript in orders/show.html.haml to a separate file. I'm on it.

@wvengen
Member
wvengen commented Feb 18, 2015

Oh, and why not making the "x Ordergroups" a messaging link instead of the mail button? This would be in-line with other user names being a link to send a message.

@paroga
Contributor
paroga commented Feb 18, 2015

Yes, that was exactly the error I got.
The "x Ordergroups" "expands" to the list of Ordergroups. How do you want to handle that then?

@wvengen
Member
wvengen commented Feb 18, 2015

That's the title attribute, a hyperlink could go to the messaging screen.

@paroga
Contributor
paroga commented Feb 18, 2015

If I do it that way I get some kind of "layering problem": a create_mail_link_for_ordergroups function should only need a list of order groups as parameter. The message page requires the order_id instead and passing a list of order groups/users via URL does not seam like a perfect solution for me either.

@wvengen
Member
wvengen commented Feb 18, 2015

I like the design pattern that info displayed on the screen is also a way to interact with it. In this way: seeing the ordergroups allows one to do something with it - sending them a message.

I think the technical problem of how to create the link is solvable. We can still use the order_id (since that can be used to get the same list of ordergroups).

@wvengen
Member
wvengen commented Apr 3, 2015

Thanks for your work! Testing this, I'm a bit confused on the message page, since it shows no addressee. I see a number of options:

  • Include all recipients in the recipients field
  • Add a special field "Order ..." to the Groups field
  • Replace the "Order ..." (and recipients?) fields with "Order: ...."
  • Allow to put members, groups and orders in the recipients input field (something I'd like to do in the future).
@paroga
Contributor
paroga commented Apr 9, 2015

at least on my installation it adds all recipients to the recipients field. any idea? i had some "browser caching" problems at the beginning too, but they were gone later :-/

@wvengen
Member
wvengen commented Apr 10, 2015

Ok, I'll try again. The code looks ok in that respect.
If you feel like it, you might want to git pull && git rebase master

@wvengen wvengen commented on the diff Apr 10, 2015
plugins/messages/app/models/message.rb
@@ -40,6 +40,13 @@ def group_id=(group_id)
add_recipients Group.find(group_id).users unless group_id.blank?
end
+ def order_id=(order_id)
+ @order_id = order_id
+ for ordergroup in Order.find(order_id).ordergroups
+ add_recipients ordergroup.users
+ end
@wvengen
wvengen Apr 10, 2015 Member

This would be shorter and more performant

add_recipients Order.find(order_id).ordergroups unless order_id.blank?
@wvengen
wvengen Apr 10, 2015 Member

Silly me, that wouldn't work at all. Perhaps another has_many :through in Order would work, but let's leave it this way :o

@wvengen
wvengen Apr 10, 2015 Member

Ok, I couldn't resist. If you like:

# in app/models/order.rb
has_many :ordergroups, :through => :group_orders
has_many :users_ordered, :through => :ordergroups, :source => :users
# in plugins/messages/app/models/message.rb#order_id=
add_recipients Order.find(order_id).users_ordered if order_id
@wvengen wvengen merged commit 124f77f into foodcoops:master Apr 10, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@paroga paroga deleted the foodcoop1040:order_message branch Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment