From 56c236390958b6a1fa4dc0a6060466f86c5963dc Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 21 Dec 2016 16:23:00 +1300 Subject: [PATCH] Implement feedback fixes Enhancement Fix ModelAdmin import form not POSTing to correct form --- admin/client/dist/js/bundle.js | 5 +- admin/client/dist/styles/bundle.css | 4 ++ .../components/GridField/GridFieldAction.js | 3 -- admin/client/src/legacy/GridField.js | 12 ++--- .../src/state/records/RecordsReducer.js | 4 -- admin/client/src/styles/_chosen.scss | 4 ++ admin/code/ModelAdmin.php | 49 ++++++++++--------- .../Admin/Includes/ModelAdmin_Content.ss | 16 +++++- .../Admin/Includes/ModelAdmin_Tools.ss | 2 +- src/Forms/GridField/GridFieldImportButton.php | 12 ++--- 10 files changed, 62 insertions(+), 49 deletions(-) diff --git a/admin/client/dist/js/bundle.js b/admin/client/dist/js/bundle.js index 780c46554..6d6129bef 100644 --- a/admin/client/dist/js/bundle.js +++ b/admin/client/dist/js/bundle.js @@ -666,7 +666,7 @@ i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Obj function t(e){r(this,t) var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)) return n.handleClick=n.handleClick.bind(n),n}return o(t,e),s(t,[{key:"render",value:function n(){return u["default"].createElement("button",{className:"grid-field__icon-action font-icon-"+this.props.icon+" btn--icon-large", -onClick:this.handleClick})}},{key:"handleClick",value:function i(e){return console.log("handle click"),!1}}]),t}(d["default"]) +onClick:this.handleClick})}},{key:"handleClick",value:function i(e){this.props.handleClick(e,this.props.record.ID)}}]),t}(d["default"]) p.PropTypes={handleClick:u["default"].PropTypes.func.isRequired},t["default"]=p},function(e,t,n){"use strict" function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){var n=["id"] return n.reduce(function(e,n){return e.replace(":"+n,t[n])},e)}function a(e,t,n){var i={recordType:e},a={Accept:"text/json"},o=t.toLowerCase() @@ -2156,8 +2156,7 @@ var s=n(108),l=i(s),u=n(33),c=i(u),d=(0,l["default"])({})},function(e,t,n){"use function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(){var e=arguments.length<=0||void 0===arguments[0]?d:arguments[0],t=arguments[1],n=null,i=null,a=null,s={} -switch(t.type){case"APOLLO_QUERY_RESULT":return e -case c["default"].CREATE_RECORD:return(0,l["default"])(o({},e,{})) +switch(t.type){case c["default"].CREATE_RECORD:return(0,l["default"])(o({},e,{})) case c["default"].UPDATE_RECORD:return(0,l["default"])(o({},e,{})) case c["default"].DELETE_RECORD:return(0,l["default"])(o({},e,{})) case c["default"].FETCH_RECORDS_REQUEST:return e diff --git a/admin/client/dist/styles/bundle.css b/admin/client/dist/styles/bundle.css index 3609d690f..7af3774f3 100644 --- a/admin/client/dist/styles/bundle.css +++ b/admin/client/dist/styles/bundle.css @@ -855,6 +855,10 @@ body .ui-tooltip{ border-width:2px; } top:6px; cursor:pointer; } +.chosen-container-multi .chosen-choices{ + padding:4px 5px; +} + /*! * Bootstrap v4.0.0-alpha.2 (http://getbootstrap.com) * Copyright 2011-2015 Twitter, Inc. diff --git a/admin/client/src/components/GridField/GridFieldAction.js b/admin/client/src/components/GridField/GridFieldAction.js index 7bccdfc9a..f92505e7c 100644 --- a/admin/client/src/components/GridField/GridFieldAction.js +++ b/admin/client/src/components/GridField/GridFieldAction.js @@ -18,9 +18,6 @@ class GridFieldAction extends SilverStripeComponent { } handleClick(event) { - console.log('handle click'); - - return false; this.props.handleClick(event, this.props.record.ID); } } diff --git a/admin/client/src/legacy/GridField.js b/admin/client/src/legacy/GridField.js index 77088e5e7..3a1ce55d3 100644 --- a/admin/client/src/legacy/GridField.js +++ b/admin/client/src/legacy/GridField.js @@ -147,17 +147,15 @@ $.entwine('ss', function($) { backdrop.addClass('fade in').fadeIn(); } - $(this.data('target')).addClass('in'); + var modal = $(this.data('target')); - // workaround until GridField rewritten into react. - var self = this; - - $(this.data('target')).find('[data-dismiss]').on('click', function() { + modal.addClass('in'); + modal.find('[data-dismiss]').on('click', function() { backdrop.fadeOut(function() { - $(this).removeClass('in'); + backdrop.removeClass('in'); }); - $(self.data('target')).removeClass('in'); + modal.removeClass('in'); }) } }); diff --git a/admin/client/src/state/records/RecordsReducer.js b/admin/client/src/state/records/RecordsReducer.js index b228c496c..5bd80a27b 100644 --- a/admin/client/src/state/records/RecordsReducer.js +++ b/admin/client/src/state/records/RecordsReducer.js @@ -10,10 +10,6 @@ function recordsReducer(state = initialState, action) { let apolloRecordRelation = {}; switch (action.type) { - case 'APOLLO_QUERY_RESULT': - - return state; - case ACTION_TYPES.CREATE_RECORD: return deepFreeze(Object.assign({}, state, {})); diff --git a/admin/client/src/styles/_chosen.scss b/admin/client/src/styles/_chosen.scss index 69fe6417e..e35288b72 100644 --- a/admin/client/src/styles/_chosen.scss +++ b/admin/client/src/styles/_chosen.scss @@ -1 +1,5 @@ @import "../../../../node_modules/chosen-js/chosen.css"; + +.chosen-container-multi .chosen-choices { + padding: 4px 5px; +} diff --git a/admin/code/ModelAdmin.php b/admin/code/ModelAdmin.php index f7a210f95..c1404c5e0 100644 --- a/admin/code/ModelAdmin.php +++ b/admin/code/ModelAdmin.php @@ -521,28 +521,33 @@ abstract class ModelAdmin extends LeftAndMain $results = $loader->load($_FILES['_CsvFile']['tmp_name']); $message = ''; - if ($results->CreatedCount()) { - $message .= _t( - 'ModelAdmin.IMPORTEDRECORDS', - "Imported {count} records.", - array('count' => $results->CreatedCount()) - ); - } - if ($results->UpdatedCount()) { - $message .= _t( - 'ModelAdmin.UPDATEDRECORDS', - "Updated {count} records.", - array('count' => $results->UpdatedCount()) - ); - } - if ($results->DeletedCount()) { - $message .= _t( - 'ModelAdmin.DELETEDRECORDS', - "Deleted {count} records.", - array('count' => $results->DeletedCount()) - ); - } - if (!$results->CreatedCount() && !$results->UpdatedCount()) { + + if($results) { + if ($results->CreatedCount()) { + $message .= _t( + 'ModelAdmin.IMPORTEDRECORDS', + "Imported {count} records.", + array('count' => $results->CreatedCount()) + ); + } + if ($results && $results->UpdatedCount()) { + $message .= _t( + 'ModelAdmin.UPDATEDRECORDS', + "Updated {count} records.", + array('count' => $results->UpdatedCount()) + ); + } + if ($results->DeletedCount()) { + $message .= _t( + 'ModelAdmin.DELETEDRECORDS', + "Deleted {count} records.", + array('count' => $results->DeletedCount()) + ); + } + if (!$results->CreatedCount() && !$results->UpdatedCount()) { + $message .= _t('ModelAdmin.NOIMPORT', "Nothing to import"); + } + } else { $message .= _t('ModelAdmin.NOIMPORT', "Nothing to import"); } diff --git a/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Content.ss b/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Content.ss index 418563c77..f2df0e70d 100644 --- a/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Content.ss +++ b/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Content.ss @@ -16,7 +16,7 @@
- <% if $SearchForm || $ImportForm %> + <% if $SearchForm %> <% end_if %>
diff --git a/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Tools.ss b/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Tools.ss index b565aa6b2..0cd453f72 100644 --- a/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Tools.ss +++ b/admin/templates/SilverStripe/Admin/Includes/ModelAdmin_Tools.ss @@ -1,4 +1,4 @@ -<% if $SearchForm || $ImportForm %> +<% if $SearchForm %>
<% if $SearchForm %>

<%t ModelAdmin_Tools_ss.FILTER 'Filter' %>

diff --git a/src/Forms/GridField/GridFieldImportButton.php b/src/Forms/GridField/GridFieldImportButton.php index 4fda478b6..be7c2245d 100644 --- a/src/Forms/GridField/GridFieldImportButton.php +++ b/src/Forms/GridField/GridFieldImportButton.php @@ -46,21 +46,17 @@ class GridFieldImportButton implements GridField_HTMLProvider null ); $button->addExtraClass('btn btn-secondary no-ajax font-icon-upload btn--icon-large action_import'); + + // means that you can only have 1 import per page $button ->setAttribute('data-toggle', "modal") - ->setAttribute('data-target', "#". $gridField->ID() . ' .grid-field-import'); + ->setAttribute('data-target', "#". $gridField->getForm()->getHTMLID() . '_ImportModal'); $button->setForm($gridField->getForm()); $extra = null; - if($this->importFormField) { - $extra = ($this->importFormField instanceof Form) - ? $this->importFormField->forTemplate() - : $this->importFormField->Field(); - } - return array( - $this->targetFragment => ($extra) ? '

' . $button->Field() . '

'.$extra : '', + $this->targetFragment => '

'. $button->Field() . '

' ); }