forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nebulab/bulk actions #91
Draft
DanielePalombo
wants to merge
10
commits into
nebulab:main
Choose a base branch
from
DanielePalombo:nebulab/bulk-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56f2417
Add Modal logic
DanielePalombo 312e7df
Add Spree::BatchAction::Base Object
DanielePalombo 5181505
Add Spree::Backend::Batch
DanielePalombo 672f7d8
Add modal Preview
DanielePalombo 4a08ee3
Open Preview Modal
DanielePalombo 162cfe2
Add Modal Batch Result
DanielePalombo c7ff27f
Add controller action to process BatchAction
DanielePalombo 202dac6
Execute BatchAction Process
DanielePalombo 3b1a45f
Add DestroyRecordAction
DanielePalombo df0d786
Add DestroyAction to ProductController
DanielePalombo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/app/assets/javascripts/spree/backend/components/modals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Use this file to retrieve and store the modal that should be global to the | ||
* site | ||
* | ||
* e.g. | ||
* Spree.ready(function() { | ||
* $('#batch-preview').each(function() { | ||
* Spree.Views.Modals.batchPreview($(this)) | ||
* }); | ||
* }); | ||
* | ||
*/ | ||
Spree.ready(function() { | ||
$('#batch-preview').each(function() { | ||
Spree.Views.Modals.batchPreview($(this)) | ||
}) | ||
|
||
$('#batch-result').each(function() { | ||
Spree.Views.Modals.batchResult($(this)) | ||
}) | ||
}); |
7 changes: 6 additions & 1 deletion
7
backend/app/assets/javascripts/spree/backend/components/selectable_table/summary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
Backbone.on('selectableTable:init', function(selectableTable){ | ||
if(selectableTable.$el.find('.selectable').length > 0) { | ||
var tr = document.createElement('tr') | ||
new Spree.Views.Tables.SelectableTable.Summary({el: tr, model: selectableTable.model , columns: selectableTable.maxColumns()}); | ||
new Spree.Views.Tables.SelectableTable.Summary({ | ||
el: tr, | ||
model: selectableTable.model, | ||
columns: selectableTable.maxColumns(), | ||
selectableTable: selectableTable | ||
}); | ||
selectableTable.$el.find('thead').prepend(tr); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ _.extend(window.Spree, { | |
Payment: {}, | ||
Promotions: {}, | ||
Stock: {}, | ||
Tables: {} | ||
Tables: {}, | ||
Modals: {} | ||
} | ||
}) |
1 change: 1 addition & 0 deletions
1
backend/app/assets/javascripts/spree/backend/templates/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
backend/app/assets/javascripts/spree/backend/templates/tables/actions.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{#if itemSelected}} | ||
{{#each actions}} | ||
{{{this}}} | ||
{{/each}} | ||
{{/if}} |
6 changes: 5 additions & 1 deletion
6
backend/app/assets/javascripts/spree/backend/templates/tables/selectable_label.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
<th> | ||
<input type="checkbox" {{#if all_items_selected}}checked="checked"{{/if}} name="select-all" class="selectAll" id="select-all" value="1"> | ||
</th> | ||
<th colspan="{{colspan}}"> | ||
<th colspan="{{colspan}}" class="label"> | ||
{{item_selected_label}} | ||
</th> | ||
{{#if actionable}} | ||
<th colspan="{{actionableColspan}}" class="actions"> | ||
</th> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/app/assets/javascripts/spree/backend/views/modals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Use this file to store the global modal | ||
* | ||
* e.g. | ||
* Spree.Views.Modals = { | ||
* myModal: function($el = null) { | ||
* if($el != null) { | ||
* this.myGlobalModal = new Spree.Views.Modals.MyModal({el: $el}) | ||
* } | ||
* | ||
* return this.myGlobalModal; | ||
* }, | ||
* } | ||
* | ||
*/ | ||
Spree.Views.Modals = { | ||
batchPreview: function($el = null) { | ||
if($el != null) { | ||
this.modalBatchPreview = new Spree.Views.Modals.Batch.Preview({el: $el}) | ||
} | ||
|
||
return this.modalBatchPreview; | ||
}, | ||
|
||
batchResult: function($el = null) { | ||
if($el != null) { | ||
this.modalBatchResult = new Spree.Views.Modals.Batch.Result({el: $el}) | ||
} | ||
|
||
return this.modalBatchResult; | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
backend/app/assets/javascripts/spree/backend/views/modals/batch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Spree.Views.Modals.Batch = {} |
37 changes: 37 additions & 0 deletions
37
backend/app/assets/javascripts/spree/backend/views/modals/batch/preview.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Spree.Views.Modals.Batch.Preview = Backbone.View.extend({ | ||
events: { | ||
'click #btn-process': 'process' | ||
}, | ||
|
||
show: function(options) { | ||
this.processBatchUrl = options.processBatchUrl; | ||
this.searchForm = options.searchForm; | ||
this.action = options.action; | ||
this.$el.modal('show'); | ||
}, | ||
|
||
process: function() { | ||
var inputAction = document.createElement('input'); | ||
inputAction.name = 'batch_action_type'; | ||
inputAction.value = this.action; | ||
this.searchForm.append(inputAction); | ||
|
||
this.$el.modal('hide'); | ||
|
||
Spree.ajax({ | ||
type: 'POST', | ||
url: this.processBatchUrl, | ||
data: this.searchForm.serialize(), | ||
success: function() { | ||
Spree.Views.Modals.batchResult().show() | ||
}, | ||
error: function(msg) { | ||
if (msg.responseJSON["error"]) { | ||
show_flash('error', msg.responseJSON["error"]); | ||
} else { | ||
show_flash('error', "There was a problem adding this coupon code."); | ||
} | ||
} | ||
}); | ||
} | ||
}) |
14 changes: 14 additions & 0 deletions
14
backend/app/assets/javascripts/spree/backend/views/modals/batch/result.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Spree.Views.Modals.Batch.Result = Backbone.View.extend({ | ||
events: { | ||
'click #btn-close': 'close' | ||
}, | ||
|
||
show: function() { | ||
this.$el.modal('show'); | ||
}, | ||
|
||
close: function() { | ||
this.$el.modal('hide'); | ||
document.location.reload(); | ||
} | ||
}) |
67 changes: 67 additions & 0 deletions
67
backend/app/assets/javascripts/spree/backend/views/tables/selectable_table/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Spree.Views.Tables.SelectableTable.Actions = Backbone.View.extend({ | ||
events: { | ||
'click a.batch-action': 'previewBatchAction' | ||
}, | ||
|
||
initialize: function(options) { | ||
this.listenTo(this.model, 'change', this.render); | ||
|
||
this.selectableTable = options.selectableTable; | ||
this.actions = this.selectableTable.$el.data('actions'); | ||
this.searchForm = $(this.selectableTable.$el.data('searchFormSelector')).clone(); | ||
this.previewBatchUrl = this.selectableTable.$el.data('previewBatchUrl'); | ||
this.processBatchUrl = this.selectableTable.$el.data('processBatchUrl'); | ||
|
||
this.render(); | ||
}, | ||
|
||
render: function() { | ||
var html = HandlebarsTemplates['tables/actions']({ | ||
itemSelected: this.model.get('selectedItems').length > 0 || this.model.get('allSelected'), | ||
actions: this.actions | ||
}); | ||
|
||
this.$el.html(html); | ||
}, | ||
|
||
previewBatchAction: function(e) { | ||
var self = this; | ||
|
||
var action = $(e.currentTarget).data('action'); | ||
var inputAction = document.createElement('input'); | ||
inputAction.name = 'batch_action_type'; | ||
inputAction.value = action; | ||
|
||
if(this.selectableTable.$el.find('.selectAll:checked').length == 0) { | ||
this.selectableTable.$el.find('.selectable:checked').each(function(_i, item){ | ||
self.searchForm.append($(item).clone()); | ||
}) | ||
} | ||
|
||
this.searchForm.append(inputAction); | ||
|
||
options = { | ||
processBatchUrl: this.processBatchUrl, | ||
searchForm: this.searchForm, | ||
action: action | ||
} | ||
|
||
Spree.ajax({ | ||
type: 'POST', | ||
url: this.previewBatchUrl, | ||
data: this.searchForm.serialize(), | ||
success: function() { | ||
Spree.Views.Modals.batchPreview().show(options); | ||
}, | ||
error: function(msg) { | ||
if (msg.responseJSON["error"]) { | ||
show_flash('error', msg.responseJSON["error"]); | ||
} else { | ||
show_flash('error', "There was a problem adding this coupon code."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we can change this to a more generic error message right? |
||
} | ||
} | ||
}); | ||
|
||
this.searchForm = $(this.selectableTable.$el.data('searchFormSelector')).clone(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
backend/app/assets/stylesheets/spree/backend/components/selectable_table.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.selectable-table .action-buttons { | ||
margin-right: 0px; | ||
float: right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
module Admin | ||
module ActionableHelper | ||
extend ActiveSupport::Concern | ||
|
||
def batch_action_buttons(batch_actions) | ||
batch_actions.map do |batch_action| | ||
link_to_batch_action(batch_action) | ||
end | ||
end | ||
|
||
def link_to_batch_action(icon:, label:, action:) | ||
options = {} | ||
options[:class] = "fa fa-#{icon} icon_link with-tip batch-action no-text" | ||
options[:title] = label | ||
options[:data] = { action: action } | ||
options.delete(:no_text) | ||
link_to('', '#', options) | ||
end | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
backend/app/views/spree/admin/batch_actions/_preview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="modal fade" id="<%= target %>" role="dialog" aria-labelledby="<%= target %>" aria-hidden="true"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="<%= target %>"><%= title %></h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<%= content %> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" id="btn-process" class="btn btn-primary">Process</button> | ||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
18 changes: 18 additions & 0 deletions
18
backend/app/views/spree/admin/batch_actions/_process.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="modal fade" id="<%= target %>" role="dialog" aria-labelledby="<%= target %>" aria-hidden="true"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="<%= target %>"><%= title %></h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<%= content %> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" id="btn-close" class="btn btn-primary">Close</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
1 change: 1 addition & 0 deletions
1
backend/app/views/spree/admin/batch_actions/destroy_record_action/_preview.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= t('spree.batch_actions.destroy_record_action.confirm', total_count: @batch_action_collection.total_count) %> |
1 change: 1 addition & 0 deletions
1
backend/app/views/spree/admin/batch_actions/destroy_record_action/_result.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= t('spree.batch_actions.destroy_record_action.result', total_count: @batch_action_collection.total_count) %> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as https://github.com/nebulab/solidus/pull/91/files#r607848489