From 6f303a524459ffb3c511ed1f730cb22c862dadee Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 27 Jun 2022 12:22:30 +0200 Subject: [PATCH 1/3] Add tags interface for a producer only order cycle Add tags for first (and unique) outgoing exchange for a simple OC Order Cycle can have tags --- app/views/admin/order_cycles/_simple_form.html.haml | 4 ++++ config/locales/en.yml | 1 + 2 files changed, 5 insertions(+) diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 3c828d7777..8b8ac6f200 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -19,6 +19,10 @@ %tr.products %td{ ng: { include: "'admin/panels/exchange_products_simple.html'" } } +%br += label_tag t('.tags') +%tags-with-translation{ object: 'order_cycle.outgoing_exchanges[0]', form: 'order_cycle_form' } + %br/ = label_tag t('.fees') = render 'coordinator_fees', f: f diff --git a/config/locales/en.yml b/config/locales/en.yml index f86de538be..917f1cce64 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1218,6 +1218,7 @@ en: customer_instructions_placeholder: Pick-up or delivery notes products: Products fees: Fees + tags: Tags destroy_errors: orders_present: That order cycle has been selected by a customer and cannot be deleted. To prevent customers from accessing it, please close it instead. schedule_present: That order cycle is linked to a schedule and cannot be deleted. Please unlink or delete the schedule first. From fdba33baa3ccb9c502d8a57f287d93ba97b7b4ea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 28 Jun 2022 15:03:51 +0200 Subject: [PATCH 2/3] Pass the form, and re-init() on object change I can't make angularjs directive synchronized to scope object, this seems to be a hack, but it works. Also add form in the scope (which was not added...) --- .../utils/directives/tags_with_translation.js.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee b/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee index ef84570f5e..5ab68c43e1 100644 --- a/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/tags_with_translation.js.coffee @@ -3,6 +3,7 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) -> templateUrl: "admin/tags_input.html" scope: object: "=" + form: "=" tagsAttr: "@?" tagListAttr: "@?" findTags: "&" @@ -18,7 +19,15 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) -> scope.limitReached = scope.object[scope.tagsAttr].length >= scope.max if scope.max != undefined scope.object[scope.tagListAttr] = (tag.text for tag in scope.object[scope.tagsAttr]).join(",") + scope.$watch "object", (newObject) -> + scope.object = newObject + init() + $timeout -> + init() + + init = -> + return unless scope.object # Initialize properties if necessary scope.tagsAttr ||= "tags" scope.tagListAttr ||= "tag_list" From 77d12a3e547a41e630da9a22186b5f6765a10e13 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 29 Jun 2022 09:51:15 +0200 Subject: [PATCH 3/3] Can add tags on simple order_cycle: specs Simple order cycle: enterprise users selling only their own produce --- spec/system/admin/order_cycles/simple_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/system/admin/order_cycles/simple_spec.rb b/spec/system/admin/order_cycles/simple_spec.rb index c3c84f18e5..7f275f493d 100644 --- a/spec/system/admin/order_cycles/simple_spec.rb +++ b/spec/system/admin/order_cycles/simple_spec.rb @@ -635,6 +635,13 @@ describe ' check "order_cycle_incoming_exchange_0_variants_#{v3.id}" uncheck "order_cycle_incoming_exchange_0_variants_#{v3.id}" + # Add tags + expect(page).to have_content "TAGS" + + within "tags-with-translation" do + find(:css, "tags-input .tags input").set "wholesale\n" + end + # And I select some fees and update click_link 'order_cycle_coordinator_fee_0_remove' expect(page).not_to have_select 'order_cycle_coordinator_fee_0_id' @@ -669,6 +676,9 @@ describe ' ex = oc.exchanges.outgoing.first expect(ex.pickup_time).to eq('xy') expect(ex.pickup_instructions).to eq('yyz') + + # And it should have the tags + expect(ex.tag_list).to eq ['wholesale'] end end