Skip to content

Commit

Permalink
Merge pull request #427 from marmelab/es6_queries
Browse files Browse the repository at this point in the history
[RFR] Move *Queries into separate files
  • Loading branch information
jeromemacias committed May 18, 2015
2 parents 8035564 + cb0dd09 commit b65f361
Show file tree
Hide file tree
Showing 39 changed files with 855 additions and 941 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"mocha": "^2.1.0",
"mocha-traceur": "^2.1.0",
"protractor": "~1.8.0",
"sinon": "~1.14.1",
"superagent": "^0.18.2"
},
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions src/javascripts/ng-admin/Crud/CrudModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ define(function (require) {

CrudModule.service('EntryFormatter', require('ng-admin/Crud/misc/EntryFormatter'));
CrudModule.service('PromisesResolver', require('ng-admin/Crud/misc/PromisesResolver'));
CrudModule.service('RetrieveQueries', require('ng-admin/Crud/repository/RetrieveQueries'));
CrudModule.service('CreateQueries', require('ng-admin/Crud/repository/CreateQueries'));
CrudModule.service('UpdateQueries', require('ng-admin/Crud/repository/UpdateQueries'));
CrudModule.service('DeleteQueries', require('ng-admin/Crud/repository/DeleteQueries'));
CrudModule.service('ReadQueries', require('ng-admin/Crud/repository/ReadQueries'));
CrudModule.service('WriteQueries', require('ng-admin/Crud/repository/WriteQueries'));

CrudModule.service('RestWrapper', require('ng-admin/Crud/misc/RestWrapper'));

CrudModule.directive('maJsonValidator', require('ng-admin/Crud/validator/maJsonValidator'));

Expand Down
6 changes: 3 additions & 3 deletions src/javascripts/ng-admin/Crud/button/maExportToCsvButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
define(function () {
'use strict';

function maExportToCsvButton ($stateParams, Papa, notification, entryFormatter, RetrieveQueries) {
function maExportToCsvButton ($stateParams, Papa, notification, entryFormatter, ReadQueries) {
return {
restrict: 'E',
scope: {
Expand All @@ -29,7 +29,7 @@ define(function () {

scope.exportToCsv = function () {

RetrieveQueries.getAll(exportView, -1, true, $stateParams.search, $stateParams.sortField, $stateParams.sortDir).then(function (response) {
ReadQueries.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--) {

Expand All @@ -49,7 +49,7 @@ define(function () {
};
}

maExportToCsvButton.$inject = ['$stateParams', 'Papa', 'notification', 'EntryFormatter', 'RetrieveQueries'];
maExportToCsvButton.$inject = ['$stateParams', 'Papa', 'notification', 'EntryFormatter', 'ReadQueries'];

return maExportToCsvButton;
});
10 changes: 5 additions & 5 deletions src/javascripts/ng-admin/Crud/delete/BatchDeleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
define(function () {
'use strict';

var BatchDeleteController = function ($scope, $state, $stateParams, $location, $window, DeleteQueries, notification, view) {
var BatchDeleteController = function ($scope, $state, $stateParams, $location, $window, WriteQueries, notification, view) {
this.$scope = $scope;
this.$state = $state;
this.$stateParams = $stateParams;
this.$location = $location;
this.$window = $window;
this.DeleteQueries = DeleteQueries;
this.WriteQueries = WriteQueries;
this.notification = notification;
this.view = view;
this.entity = view.getEntity();
Expand All @@ -29,7 +29,7 @@ define(function () {
$state = this.$state,
entityName = this.entity.name();

this.DeleteQueries.batchDelete(this.view, this.entityIds).then(function () {
this.WriteQueries.batchDelete(this.view, this.entityIds).then(function () {
$state.go($state.get('list'), { 'entity': entityName });
notification.log('Elements successfully deleted.', { addnCls: 'humane-flatty-success' });
}, function (response) {
Expand All @@ -53,10 +53,10 @@ define(function () {
this.$stateParams = undefined;
this.$location = undefined;
this.$window = undefined;
this.DeleteQueries = undefined;
this.WriteQueries = undefined;
};

BatchDeleteController.$inject = ['$scope', '$state', '$stateParams', '$location', '$window', 'DeleteQueries', 'notification', 'view'];
BatchDeleteController.$inject = ['$scope', '$state', '$stateParams', '$location', '$window', 'WriteQueries', 'notification', 'view'];

return BatchDeleteController;
});
10 changes: 5 additions & 5 deletions src/javascripts/ng-admin/Crud/delete/DeleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
define(function () {
'use strict';

var DeleteController = function ($scope, $location, DeleteQueries, notification, params, view, entry) {
var DeleteController = function ($scope, $location, WriteQueries, notification, params, view, entry) {
this.$scope = $scope;
this.$location = $location;
this.DeleteQueries = DeleteQueries;
this.WriteQueries = WriteQueries;
this.entityLabel = params.entity;
this.entityId = params.id;
this.view = view;
Expand All @@ -26,7 +26,7 @@ define(function () {
$location = this.$location,
entityLabel = this.entityLabel;

this.DeleteQueries.deleteOne(this.view, this.entityId).then(function () {
this.WriteQueries.deleteOne(this.view, this.entityId).then(function () {
$location.path(entityLabel + '/list');
notification.log('Element successfully deleted.', { addnCls: 'humane-flatty-success' });
}, function (response) {
Expand All @@ -47,12 +47,12 @@ define(function () {
DeleteController.prototype.destroy = function () {
this.$scope = undefined;
this.$location = undefined;
this.DeleteQueries = undefined;
this.WriteQueries = undefined;
this.view = undefined;
this.entity = undefined;
};

DeleteController.$inject = ['$scope', '$location', 'DeleteQueries', 'notification', 'params', 'view', 'entry'];
DeleteController.$inject = ['$scope', '$location', 'WriteQueries', 'notification', 'params', 'view', 'entry'];

return DeleteController;
});
14 changes: 6 additions & 8 deletions src/javascripts/ng-admin/Crud/form/FormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
define(function () {
'use strict';

var FormController = function ($scope, $state, CreateQueries, UpdateQueries, Configuration,
var FormController = function ($scope, $state, WriteQueries, Configuration,
progression, notification, view, dataStore) {

this.$scope = $scope;
this.$state = $state;
this.CreateQueries = CreateQueries;
this.UpdateQueries = UpdateQueries;
this.WriteQueries = WriteQueries;
this.dataStore = dataStore;
this.progression = progression;
this.notification = notification;
Expand Down Expand Up @@ -84,7 +83,7 @@ define(function () {
notification = this.notification,
$state = this.$state;
progression.start();
this.CreateQueries
this.WriteQueries
.createOne(this.view, entry)
.then(function (rawEntry) {
var entry = this.dataStore.mapEntry(entity.name(), this.view.identifier(), this.view.getFields(), rawEntry);
Expand All @@ -103,7 +102,7 @@ define(function () {
var progression = this.progression,
notification = this.notification;
progression.start();
this.UpdateQueries
this.WriteQueries
.updateOne(this.view, entry, this.originEntityId)
.then(function () {
progression.done();
Expand All @@ -126,14 +125,13 @@ define(function () {
FormController.prototype.destroy = function () {
this.$scope = undefined;
this.$state = undefined;
this.CreateQueries = undefined;
this.UpdateQueries = undefined;
this.WriteQueries = undefined;
this.dataStore = undefined;
this.view = undefined;
this.entity = undefined;
};

FormController.$inject = ['$scope', '$state', 'CreateQueries', 'UpdateQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore'];
FormController.$inject = ['$scope', '$state', 'WriteQueries', 'NgAdminConfiguration', 'progression', 'notification', 'view', 'dataStore'];

return FormController;
});
8 changes: 4 additions & 4 deletions src/javascripts/ng-admin/Crud/list/ListController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
define(function () {
'use strict';

var ListController = function ($scope, $stateParams, $location, $anchorScroll, RetrieveQueries, progression, view, dataStore, totalItems) {
var ListController = function ($scope, $stateParams, $location, $anchorScroll, ReadQueries, progression, view, dataStore, totalItems) {
this.$scope = $scope;
this.$stateParams = $stateParams;
this.$location = $location;
this.$anchorScroll = $anchorScroll;
this.RetrieveQueries = RetrieveQueries;
this.ReadQueries = ReadQueries;
this.progression = progression;
this.view = view;
this.entity = view.getEntity();
Expand Down Expand Up @@ -45,7 +45,7 @@ define(function () {

progression.start();

this.RetrieveQueries
this.ReadQueries
.getAll(this.view, page, true, filters, this.sortField, this.sortDir)
.then(function (nextData) {
progression.done();
Expand All @@ -68,7 +68,7 @@ define(function () {
this.dataStore = undefined;
};

ListController.$inject = ['$scope', '$stateParams', '$location', '$anchorScroll', 'RetrieveQueries', 'progression', 'view', 'dataStore', 'totalItems'];
ListController.$inject = ['$scope', '$stateParams', '$location', '$anchorScroll', 'ReadQueries', 'progression', 'view', 'dataStore', 'totalItems'];

return ListController;
});
70 changes: 70 additions & 0 deletions src/javascripts/ng-admin/Crud/misc/RestWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*global define*/
define(function () {
'use strict';

function RestWrapper(Restangular) {
this.Restangular = Restangular;

Restangular.setFullResponse(true);
}

/**
* Returns the promise of one resource by URL
*
* @param {String} entityName
* @param {String} url
*
* @returns {promise}
*/
RestWrapper.prototype.getOne = function(entityName, url) {
return this.Restangular
.oneUrl(entityName, url)
.get()
.then(function (response) {
return response.data;
});
};

/**
* Returns the promise of a list of resources
*
* @param {Object} params
* @param {String} entityName
* @param {String} url
*
* @returns {promise}
*/
RestWrapper.prototype.getList = function(params, entityName, url) {
return this.Restangular
.allUrl(entityName, url)
.getList(params);
};

RestWrapper.prototype.createOne = function(rawEntity, entityName, url) {
return this.Restangular
.oneUrl()
.customPOST(rawEntity)
.then(function (response) {
return response.data;
});
};

RestWrapper.prototype.updateOne = function(rawEntity, entityName, url) {
return this.Restangular
.oneUrl(entityName, url)
.customPUT(rawEntity)
.then(function (response) {
return response.data;
});
};

RestWrapper.prototype.deleteOne = function(entityName, url) {
return this.Restangular
.oneUrl(entityName, url)
.customDELETE();
};

RestWrapper.$inject = ['Restangular'];

return RestWrapper;
});
38 changes: 0 additions & 38 deletions src/javascripts/ng-admin/Crud/repository/CreateQueries.js

This file was deleted.

53 changes: 0 additions & 53 deletions src/javascripts/ng-admin/Crud/repository/DeleteQueries.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/javascripts/ng-admin/Crud/repository/Queries.js

This file was deleted.

Loading

0 comments on commit b65f361

Please sign in to comment.