Skip to content

Commit

Permalink
Merge pull request #386 from marmelab/export_view
Browse files Browse the repository at this point in the history
[RFR] Export view
  • Loading branch information
jpetitcolas committed Apr 8, 2015
2 parents 66898f7 + 354435d commit eca341d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 74 deletions.
7 changes: 4 additions & 3 deletions src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ define(function () {
scope: {
entity: '&'
},
template: '<button class="btn btn-default" ng-click="exportToCsv()"><span class="glyphicon glyphicon-download" aria-hidden="true"></span>&nbsp;Export</button>',
template: '<button ng-if="view" 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();
var formatEntry = entryFormater.getFormatter(scope.entity.listView().exportFields());
scope.view = scope.entity.exportView();
var formatEntry = entryFormater.getFormatter(scope.view.fields());

scope.exportToCsv = function () {

RetrieveQueries.getAll(scope.entity.listView(), -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) {
RetrieveQueries.getAll(scope.view, -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
9 changes: 9 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Entity/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import EditView from '../View/EditView';
import DeleteView from '../View/DeleteView';
import ShowView from '../View/ShowView';
import BatchDeleteView from '../View/BatchDeleteView';
import ExportView from '../View/ExportView';

class Entity {
constructor(name) {
Expand Down Expand Up @@ -98,6 +99,13 @@ class Entity {
return this._views["BatchDeleteView"];
}

/**
* @deprecated Use .views["ExportView"] instead
*/
exportView() {
return this._views["ExportView"];
}

/**
* @deprecated Use .views["ShowView"] instead
*/
Expand All @@ -120,6 +128,7 @@ class Entity {
"EditView": new EditView().setEntity(this),
"DeleteView": new DeleteView().setEntity(this),
"BatchDeleteView": new BatchDeleteView().setEntity(this),
"ExportView": new ExportView().setEntity(this),
"ShowView": new ShowView().setEntity(this)
};
}
Expand Down
15 changes: 0 additions & 15 deletions src/javascripts/ng-admin/es6/lib/Utils/fieldsUtils.js

This file was deleted.

10 changes: 10 additions & 0 deletions src/javascripts/ng-admin/es6/lib/View/ExportView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ListView from './ListView';

class ExportView extends ListView {
constructor(name) {
super(name);
this._type = 'ExportView';
}
}

export default ExportView;
12 changes: 0 additions & 12 deletions src/javascripts/ng-admin/es6/lib/View/ListView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import View from './View';
import fieldsUtils from '../Utils/fieldsUtils';

class ListView extends View {
constructor(name) {
Expand All @@ -11,7 +10,6 @@ class ListView extends View {
this._listActions = [];
this._batchActions = ['delete'];
this._filters = [];
this._exportFields = [];

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

exportFields() {
if (!arguments.length) {
return this._exportFields.length === 0 ? this._fields : this._exportFields;
}
var fields = fieldsUtils.fieldsLiteralToArray(arguments[0]);

this._exportFields = fields;

return this;
}
}

export default ListView;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Entity', function() {
'EditView',
'DeleteView',
'BatchDeleteView',
'ExportView',
'ShowView'
], Object.keys(entity.views));
});
Expand Down
44 changes: 0 additions & 44 deletions src/javascripts/ng-admin/es6/tests/lib/Utils/fieldsUtilsTest.js

This file was deleted.

0 comments on commit eca341d

Please sign in to comment.