diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb index 4634625c11..deec9933fc 100644 --- a/app/serializers/api/admin/customer_serializer.rb +++ b/app/serializers/api/admin/customer_serializer.rb @@ -1,5 +1,5 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer - attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list + attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name def tag_list object.tag_list.join(",") diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index 98e8b3c414..f10214179b 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -37,6 +37,7 @@ %img.spinner{ src: "/assets/spinning-circles.svg" } %h1 =t :loading_customers + .row{ :class => "sixteen columns alpha", 'ng-show' => '!RequestMonitor.loading && filteredCustomers.length == 0'} %h1#no_results =t :no_customers_found @@ -48,8 +49,9 @@ %table.index#customers %col.email{ width: "20%", 'ng-show' => 'columns.email.visible' } + %col.name{ width: "20%", 'ng-show' => 'columns.code.visible' } %col.code{ width: "20%", 'ng-show' => 'columns.code.visible' } - %col.tags{ width: "50%", 'ng-show' => 'columns.tags.visible' } + %col.tags{ width: "30%", 'ng-show' => 'columns.tags.visible' } %col.actions{ width: "10%"} %thead %tr{ ng: { controller: "ColumnsCtrl" } } @@ -57,6 +59,8 @@ -# %input{ :type => "checkbox", :name => 'toggle_bulk', 'ng-click' => 'toggleAllCheckboxes()', 'ng-checked' => "allBoxesChecked()" } %th.email{ 'ng-show' => 'columns.email.visible' } %a{ :href => '', 'ng-click' => "predicate = 'customer.email'; reverse = !reverse" } Email + %th.name{ 'ng-show' => 'columns.name.visible' } + %a{ :href => '', 'ng-click' => "predicate = 'customer.name'; reverse = !reverse" } Name %th.code{ 'ng-show' => 'columns.code.visible' } %a{ :href => '', 'ng-click' => "predicate = 'customer.code'; reverse = !reverse" } Code %th.tags{ 'ng-show' => 'columns.tags.visible' } Tags @@ -67,6 +71,8 @@ -# %td.bulk -# %input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'customer.checked' } %td.email{ 'ng-show' => 'columns.email.visible', "ng-bind" => '::customer.email' } + %td.name{ 'ng-show' => 'columns.name.visible'} + %input{ type: 'text', name: 'name', ng: { model: 'customer.name' }, 'obj-for-update' => 'customer', 'attr-for-update' => 'name'} %td.code{ 'ng-show' => 'columns.code.visible' } %input{ type: 'text', name: 'code', ng: {model: 'customer.code', change: 'checkForDuplicateCodes()'}, "obj-for-update" => "customer", "attr-for-update" => "code" } %i.icon-warning-sign{ ng: {if: 'duplicate'} } diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb index 09dc197832..a6d7397b84 100644 --- a/lib/open_food_network/column_preference_defaults.rb +++ b/lib/open_food_network/column_preference_defaults.rb @@ -28,6 +28,7 @@ module OpenFoodNetwork node = 'admin.customers.index' { email: { name: I18n.t("admin.email"), visible: true }, + name: { name: I18n.t("admin.name"), visible: true }, code: { name: I18n.t("#{node}.code"), visible: true }, tags: { name: I18n.t("admin.tags"), visible: true } } diff --git a/spec/features/admin/customers_spec.rb b/spec/features/admin/customers_spec.rb index 89893860df..9e341ba61f 100644 --- a/spec/features/admin/customers_spec.rb +++ b/spec/features/admin/customers_spec.rb @@ -80,8 +80,10 @@ feature 'Customers' do within "tr#c_#{customer1.id}" do fill_in "code", with: "new-customer-code" expect(page).to have_css "input[name=code].update-pending" - end - within "tr#c_#{customer1.id}" do + + fill_in "name", with: "customer abc" + expect(page).to have_css "input[name=name].update-pending" + find(:css, "tags-input .tags input").set "awesome\n" expect(page).to have_css ".tag_watcher.update-pending" end @@ -89,18 +91,22 @@ feature 'Customers' do # Every says it updated expect(page).to have_css "input[name=code].update-success" + expect(page).to have_css "input[name=name].update-success" expect(page).to have_css ".tag_watcher.update-success" # And it actually did expect(customer1.reload.code).to eq "new-customer-code" + expect(customer1.reload.name).to eq "customer abc" expect(customer1.tag_list).to eq ["awesome"] # Clearing attributes within "tr#c_#{customer1.id}" do fill_in "code", with: "" expect(page).to have_css "input[name=code].update-pending" - end - within "tr#c_#{customer1.id}" do + + fill_in "name", with: "" + expect(page).to have_css "input[name=name].update-pending" + find("tags-input li.tag-item a.remove-button").trigger('click') expect(page).to have_css ".tag_watcher.update-pending" end @@ -108,10 +114,12 @@ feature 'Customers' do # Every says it updated expect(page).to have_css "input[name=code].update-success" + expect(page).to have_css "input[name=name].update-success" expect(page).to have_css ".tag_watcher.update-success" # And it actually did expect(customer1.reload.code).to be nil + expect(customer1.reload.name).to eq '' expect(customer1.tag_list).to eq [] end