Permalink
Browse files

Exchange system is working

Now it is possible to make all steps in an exchange process, including
the sniffers for knowledges, inputs, products and interests
  • Loading branch information...
1 parent 0c445a6 commit 16b26b2af14a3244b647580b184fe49109e763a8 @alantygel alantygel committed with brauliobo Mar 12, 2012
@@ -72,20 +72,49 @@ def console
#state machine for buttons and redirecting for evaluation
if (@exchange.state == "proposed") && (!@exchange.target?(profile))
@button = nil
+ @no_button_message = _('Waiting for the other to accept the exchange proposal')
+
elsif (@exchange.state == "conclusion_proposed_by_origin") && (!@exchange.target?(profile))
@button = nil
+ @no_button_message = _('Waiting for a response by the other part of the exchange')
+
elsif (@exchange.state == "conclusion_proposed_by_target") && (@exchange.target?(profile))
- @button = nil
+ @button = nil
+ @no_button_message = _('Waiting for a response by the other part of the exchange')
+
elsif (@exchange.state == "concluded")
redirect_to :action => "evaluate", :id => @exchange.id
+
elsif (@exchange.state == "evaluated_by_target") && (@exchange.target?(profile))
- redirect_to :action => "index"
+ ev = @exchange.evaluations.find_by_evaluator_id @exchange.enterprise_target_id
+ @origin_evaluation_score = ev.score
+ @origin_evaluation_desc = ev.text
+ @no_button_message = _('Waiting for evaluation by the other part of the exchange')
+
elsif (@exchange.state == "evaluated_by_target") && !(@exchange.target?(profile))
redirect_to :action => "evaluate", :id => @exchange.id
+
elsif (@exchange.state == "evaluated_by_origin") && !(@exchange.target?(profile))
- redirect_to :action => "index"
+ ev = @exchange.evaluations.find_by_evaluator_id @exchange.enterprise_origin_id
+ @origin_evaluation_score = ev.score
+ @origin_evaluation_desc = ev.text
+ @no_button_message = _('Waiting for evaluation by the other part of the exchange')
+
+
elsif (@exchange.state == "evaluated_by_origin") && (@exchange.target?(profile))
redirect_to :action => "evaluate", :id => @exchange.id
+
+ elsif (@exchange.state == "evaluated")
+ @no_button_message = _('Exchange finished and evaluated')
+
+ ev = @exchange.evaluations.find_by_evaluator_id @exchange.enterprise_origin_id
+ @origin_evaluation_score = ev.score
+ @origin_evaluation_desc = ev.text
+
+ ev = @exchange.evaluations.find_by_evaluator_id @exchange.enterprise_target_id
+ @target_evaluation_score = ev.score
+ @target_evaluation_desc = ev.text
+
end
end
@@ -13,7 +13,6 @@ def choose_target_offers
@enterprises = current_user.person.enterprises.find(:all, :conditions => ["profiles.id <> ?",profile.id])
@target_knowledges = CmsLearningPluginLearning.all.select{|k| k.profile.id == profile.id}
-
end
def choose_origin_offers
@@ -36,21 +35,41 @@ def choose_origin_offers
@target_knowledge_quantities = params[:target_knowledge_quantity]
end
- @matching_products = (Product.suppliers_products_specific @origin_enterprise, profile)
- matching_products_index = @matching_products.collect{|m| m.products_supplier_id.to_i}
- matching_inputs_index = @matching_products.collect{|m| m.input_id.to_i}
+ #offers
+ @matching_products_inputs = (Product.products_inputs @origin_enterprise, profile)
+ index_aux1 = @matching_products_inputs.collect{|m| m.products_supplier_id.to_i}
+ @matching_products_interests = (Product.products_interests @origin_enterprise, profile)
+ index_aux2 = @matching_products_interests.collect{|m| m.id.to_i}
+ matching_products_index = index_aux1 + index_aux2
- @origin_products_filtered = @origin_enterprise.products.reject{|p| matching_products_index.index(p.id)}
- @origin_knowledges_filtered = @origin_enterprise.articles.find(:all, :conditions => ["type = 'CmsLearningPluginLearning'"])
- @target_inputs_filtered = profile.inputs.reject{|i| matching_inputs_index.index(i.id)}
+ @matching_knowledges_interests = (Article.knowledges_interests @origin_enterprise, profile)
+ index_aux1 = @matching_knowledges_interests.collect{|m| m.id.to_i}
+ @matching_knowledges_inputs = (Product.knowledges_inputs @origin_enterprise, profile)
+ index_aux2 = @matching_knowledges_inputs.collect{|m| m.id.to_i}
+ matching_knowledges_index = index_aux1 + index_aux2
- @target_interests_filtered = SnifferPluginOpportunity.all.select{|i| i.profile_id == ((SnifferPluginProfile.find_by_profile_id profile.id).id)}
+ @origin_products_filtered = @origin_enterprise.products.reject{|p| matching_products_index.index(p.id)}
+ @origin_knowledges_filtered = @origin_enterprise.articles.find(:all, :conditions => ["type = 'CmsLearningPluginLearning'"]).reject{|p| matching_knowledges_index.index(p.id)}
+
+ #interests
+ index_aux1 = @matching_products_inputs.collect{|m| m.input_category_id.to_i}
+ index_aux2 = @matching_knowledges_inputs.collect{|m| m.input_cat.to_i}
+ matching_inputs_index = index_aux1 + index_aux2
+ @target_inputs_filtered = profile.inputs.reject{|i| matching_inputs_index.index(i.product_category_id)}
+
+ index_aux1 = @matching_products_interests.collect{|m| m.opportunity_id.to_i}
+ index_aux2 = @matching_knowledges_interests.collect{|m| m.interest_cat.to_i}
+ matching_interests_index = index_aux1 + index_aux2
+
+ target_interests = SnifferPluginOpportunity.all.select{|i| i.profile_id == ((SnifferPluginProfile.find_by_profile_id profile.id).id)}
+ @target_interests_filtered = target_interests.reject{|i| matching_interests_index.index(i.opportunity_id)}
@target_interests_names_filtered = @target_interests_filtered.collect{|i| (i.opportunity_type.constantize.find i.opportunity_id).name }
end
end
def conclude_exchange_proposal
+
if request.post?
@origin_products = (params[:origin_product_id] ? (Product.find params[:origin_product_id]) : nil )
@origin_quantities = params[:origin_quantity]
@@ -1,4 +1,6 @@
-<li id="<%= enterprise %>_element_<%= element.id %>"><%= (eval(element.element_type).find element.element_id).name %> | <%= text_field_tag "#{enterprise}_quantity[" +
- element.element_id.to_s + "]", element.quantity %><%= link_to_remote "[-]",
- :url => {:action => :remove_element, :enterprise => enterprise, :element_id => element.id, :exchange_id => @exchange.id} %></li>
-
+<li id="<%= enterprise %>_element_<%= element.id %>">
+<%= (eval(element.element_type).find element.element_id).name %> |
+<%= text_field_tag "#{enterprise}_quantity[" + element.element_id.to_s + "]", element.quantity,
+:onBlur => "jQuery.post('#{url_for :action => 'update_quantity', :element_id => element.id}', {quantity: jQuery(this).val()});" %>
+<%= link_to_remote "[-]", :url => {:action => :remove_element, :enterprise => enterprise, :element_id => element.id, :exchange_id => @exchange.id} %></li>
+
@@ -21,22 +21,28 @@
<ul>
<li><%= _('Proposer: %s') % @exchange.enterprise_origin.name %></li>
- <li><%= _('Exchange Elements:') %> <%if @edit_allowed %>[<%= link_to _('Edit'), :action => "edit", :id => @exchange.id %>] <% end %></li>
+ <% if @origin_evaluation_score %>
+ <li><%= _('Evaluation Score: %s') % @origin_evaluation_score %>
+ <li><%= _('Evaluation Description: %s') % @origin_evaluation_desc %>
+ <% end %>
+ <li><%= _('Exchange Elements:') %> <%if @edit_allowed %>[<%= link_to _('Edit'), :action => "edit", :id => @exchange.id %>] <% end %></li>
<ul>
- <% @exchange.exchange_elements.select{|e| e.enterprise_id == @exchange.enterprise_origin.id}.each do |x| %>
+ <% @exchange.exchange_elements.all (:conditions => {:enterprise_id => @exchange.enterprise_origin.id}).each do |x| %>
<li><%= "#{x.element.name} (#{x.quantity})"%></li>
<% end %>
</ul>
</li>
<li><%= _('Target: %s') % @exchange.enterprise_target.name %></li>
- <li><%= _('Exchange Elements:') %> [<%= link_to _('Edit'), :action => "edit", :id => @exchange.id %>]</li>
+ <% if @target_evaluation_score %>
+ <li><%= _('Evaluation Score: %s') % @target_evaluation_score %>
+ <li><%= _('Evaluation Description: %s') % @target_evaluation_desc %>
+ <% end %>
+ <li><%= _('Exchange Elements:') %> <%if @edit_allowed %>[<%= link_to _('Edit'), :action => "edit", :id => @exchange.id %>] <% end %></li>
<ul>
- <% @exchange.exchange_elements.select{|e| e.enterprise_id == @exchange.enterprise_target.id}.each do |x| %>
+ <% @exchange.exchange_elements.all (:conditions => {:enterprise_id => @exchange.enterprise_target.id}).each do |x| %>
<li><%= "#{x.element.name} (#{x.quantity})" %></li>
<% end %>
</ul>
-
-
<li><%= _('Exchange State:') %> <%= ExchangePlugin::Exchange.state[@exchange.state] %></li>
</ul>
@@ -47,7 +53,7 @@
<%= button_to @button[1][0], {:action => @button[1][1], :id => @exchange.id} %>
<% end %>
<% else%>
- <%= _('Waiting for a response by the other part of the exchange') %>
+ <%= @no_button_message %>
<% end %>
<%= button_to _('Back to my exchanges'), :action => "index" %>
</div>
@@ -41,60 +41,96 @@
<%= hidden_field_tag "target_knowledge_quantity[#{k.id}]", @target_knowledge_quantities["#{k.id}"] %>
<% end %>
<% end %>
-
- <% if @matching_products.count > 0 %>
+ <% if @matching_products_inputs.count + @matching_products_interests.count + @matching_knowledges_inputs.count + @matching_knowledges_interests.count > 0 %>
<h2><%= _("%{origin} offers that matches %{target} interests:") % {:target => @target_enterprise_name, :origin => @origin_enterprise.name} %></h2>
- <table style="background:#FF0000">
+ <table>
<tr>
<th> </th>
- <th><%= _("Product") %></th>
+ <th><%= _('Product/Service/Knowledge') %></th>
<th><%= _("Quantity") %></th>
<th><%= %></th>
</tr>
- <% @matching_products.each do |p| %>
+ <% @matching_products_inputs.each do |p| %>
<% input_name = (Input.find p.input_id).name %>
- <tr>
- <td><%= check_box_tag "origin_product_id[]", p.products_supplier_id %></td>
- <td><%= p.products_supplier_name %></td>
+ <% product_supplier_name = (p.products_supplier_name ? p.products_supplier_name : (Product.find p.products_supplier_id).product_category.name) %>
+ <% product_name = (!p.name_is_blank? ? p.name : (Product.find p.id).product_category.name) %>
+ <tr style="background:#00FFB7">
+ <td><%= check_box_tag "origin_product_id[]", p.products_supplier_id %></td>
+ <td><%= product_supplier_name %></td>
<td><%= text_field_tag "origin_quantity[#{p.products_supplier_id}]", nil, :class => "numbers-only" %></td>
<td><%= _("%{e_name} offers %{products_supplier_name} and %{profile_name} needs %{input_name} to make %{p_name} <br />") %
- {:products_supplier_name => p.products_supplier_name, :profile_name => profile.name, :input_name => input_name, :e_name => @origin_enterprise.name, :p_name => p.name} %>
+ {:products_supplier_name => product_supplier_name, :profile_name => profile.name, :input_name => input_name, :e_name => @origin_enterprise.name, :p_name => product_name} %>
+ </tr>
+ <% end %>
+ <% @matching_products_interests.each do |p| %>
+ <% interest_name = (Category.find p.product_category_id).name %>
+ <tr style="background:#00FFB7">
+ <td><%= check_box_tag "origin_product_id[]", p.id %></td>
+ <td><%= p.name %></td>
+ <td><%= text_field_tag "origin_quantity[#{p.id}]", nil, :class => "numbers-only" %></td>
+ <td><%= _("%{e_name} offers %{product_name} and %{profile_name} is interested in %{interest_name} <br />") %
+ {:product_name => p.name, :profile_name => profile.name, :interest_name => interest_name, :e_name => @origin_enterprise.name} %>
+ </tr>
+ <% end %>
+ <% @matching_knowledges_inputs.each do |k| %>
+ <% input_name = (Category.find k.input_cat).name %>
+ <% product_name = (!k.product.blank? ? k.product : (Category.find k.product_cat).name) %>
+ <tr style="background:#FFF690">
+ <td><%= check_box_tag "origin_knowledge_id[]", k.id %></td>
+ <td><%= k.knowledge_name %></td>
+ <td><%= text_field_tag "origin_knowledge_quantity[#{k.id}]", nil, :class => "numbers-only" %></td>
+ <td><%= _("%{e_name} knows %{knowledge_name} and %{profile_name} uses %{input_name} to make %{product_name}<br />") %
+ {:knowledge_name => k.knowledge_name, :profile_name => profile.name, :input_name => input_name,
+ :e_name => @origin_enterprise.name, :product_name => product_name} %>
+ </tr>
+ <% end %>
+ <% @matching_knowledges_interests.each do |k| %>
+ <% interest_name = (Category.find k.interest_cat).name %>
+ <tr style="background:#FFF690">
+ <td><%= check_box_tag "origin_knowledge_id[]", k.id %></td>
+ <td><%= k.knowledge_name %></td>
+ <td><%= text_field_tag "origin_knowledge_quantity[#{k.id}]", nil, :class => "numbers-only" %></td>
+ <td><%= _("%{e_name} knows %{knowledge_name} and %{profile_name} is interested in %{interest_name}<br />") %
+ {:knowledge_name => k.knowledge_name, :profile_name => profile.name, :interest_name => interest_name, :e_name => @origin_enterprise.name} %>
</tr>
<% end %>
</table>
<% else %>
<p><%= _("There are no offers by %{origin} that matches %{target} interests.") % {:target => @target_enterprise_name, :origin => @origin_enterprise.name} %></p>
<% end %>
- <% if @origin_products_filtered.count > 0 %>
- <h2><%= _("%{origin} offers:") % {:origin => @origin_enterprise.name} %></h2>
- <table style="background:#00FF00">
- <tr>
- <th></th>
- <th><%= _("Product") %></th>
- <th><%= _("Quantity") %></th>
- </tr>
- <% @origin_products_filtered.each do |p| %>
+ <% if ((@origin_products_filtered.count > 0) || (@origin_knowledges_filtered.count > 0)) %>
+ <h2><%= _("%{origin} offers:") % {:origin => @origin_enterprise.name} %></h2>
+ <table>
<tr>
- <td><%= check_box_tag "origin_product_id[]", p.id %></td>
- <td><%= p.name %></td>
- <td><%= text_field_tag "origin_quantity[#{p.id}]", nil, :class => "numbers-only" %></td>
+ <th></th>
+ <th><%= _('Product/Service/Knowledge') %></th>
+ <th><%= _("Quantity") %></th>
</tr>
- <% end %>
- <% if @origin_knowledges_filtered.count > 0%>
- <% @origin_knowledges_filtered.each do |k| %>
- <tr>
- <td><%= check_box_tag "origin_knowledge_id[]", k.id %></td>
- <td><%= k.name %></td>
- <td><%= text_field_tag "origin_knowledge_quantity[#{k.id}]", nil, :class => "numbers-only" %></td>
+ <% if @origin_products_filtered.count > 0 %>
+ <% @origin_products_filtered.each do |p| %>
+ <tr style="background:#00FFB7">
+ <td><%= check_box_tag "origin_product_id[]", p.id %></td>
+ <td><%= p.name %></td>
+ <td><%= text_field_tag "origin_quantity[#{p.id}]", nil, :class => "numbers-only" %></td>
</tr>
<% end %>
+ <% end %>
+ <% if @origin_knowledges_filtered.count > 0%>
+ <% @origin_knowledges_filtered.each do |k| %>
+ <tr style="background:#FFF690">
+ <td><%= check_box_tag "origin_knowledge_id[]", k.id %></td>
+ <td><%= k.name %></td>
+ <!--<td><%= text_field_tag "origin_knowledge_quantity[#{k.id}]", nil, :class => "numbers-only" %></td>-->
+ </tr>
<% end %>
- </table>
<% end %>
-
+ </table>
+ <% else %>
+ <p><%= _('You dont have any offers registered. Please register products or knowledges and try again.') %></p>
+ <% end %>
<% if @target_inputs_filtered.count > 0 %>
- <h2><%= _("%{target} inputs:") % {:target => profile.name} %></h2>
+ <h2><%= _("Other inputs of %{target}:") % {:target => profile.name} %></h2>
<table style="background:#00FFFF">
<tr>
<th></th>
@@ -112,7 +148,7 @@
<% end %>
<% if @target_interests_filtered.count > 0 %>
- <h2><%= _("%{target} interests:") % {:target => profile.name} %></h2>
+ <h2><%= _("Other interests of %{target}:") % {:target => profile.name} %></h2>
<table style="background:#00DDFF">
<tr>
<th></th>
Oops, something went wrong.

0 comments on commit 16b26b2

Please sign in to comment.