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] Export view #386

Merged
merged 3 commits 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
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.