Skip to content
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

[RFR] Re-add listView.exportFields() to configure export button #389

Merged
merged 1 commit into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
.description('List of posts with infinite pagination') // description appears under the title
.infinitePagination(true) // load pages as the user scrolls
.fields([
nga.field('id').label('ID'), // The default displayed name is the camelCase field name. label() overrides id
nga.field('id').label('id'), // The default displayed name is the camelCase field name. label() overrides id
nga.field('title'), // the default list field type is "string", and displays as a string
nga.field('published_at', 'date'), // Date field type allows date formatting
nga.field('views', 'number'),
Expand Down
17 changes: 13 additions & 4 deletions src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ define(function () {
scope: {
entity: '&'
},
template: '<button ng-if="view" class="btn btn-default" ng-click="exportToCsv()"><span class="glyphicon glyphicon-download" aria-hidden="true"></span>&nbsp;Export</button>',
template: '<button ng-if="has_export" class="btn btn-default" ng-click="exportToCsv()"><span class="glyphicon glyphicon-download" aria-hidden="true"></span>&nbsp;Export</button>',
link: function(scope) {
scope.entity = scope.entity();
scope.view = scope.entity.exportView();
var formatEntry = entryFormater.getFormatter(scope.view.fields());
var exportView = scope.entity.exportView();
var listView = scope.entity.listView();
if (exportView.fields().length === 0) {
var exportFields = listView.exportFields();
if (exportFields === null) {
exportFields = listView.fields();
}
exportView.fields(exportFields);
}
scope.has_export = exportView.fields().length > 0;
var formatEntry = entryFormater.getFormatter(exportView.fields());

scope.exportToCsv = function () {

RetrieveQueries.getAll(scope.view, -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) {
RetrieveQueries.getAll(exportView, -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) {
var results = [], entries = response.entries;
for (var i = entries.length - 1; i >= 0; i--) {
results[i] = formatEntry(entries[i]);
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/es6/lib/View/ExportView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ListView from './ListView';
class ExportView extends ListView {
constructor(name) {
super(name);
this._fields = [];
this._type = 'ExportView';
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/javascripts/ng-admin/es6/lib/View/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ListView extends View {
this._listActions = [];
this._batchActions = ['delete'];
this._filters = [];
this._exportFields = null;

this._sortField = 'id';
this._sortDir = 'DESC';
Expand Down Expand Up @@ -64,6 +65,16 @@ class ListView extends View {
return this;
}

exportFields(exportFields) {
if (!arguments.length) {
return this._exportFields;
}

this._exportFields = exportFields;

return this;
}

batchActions(actions) {
if (!arguments.length) {
return this._batchActions;
Expand Down