From a3c78541d7dd72c143e7997a9e5978a7ff6ce10e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 8 Apr 2014 22:29:12 +0200 Subject: use generate url, fix #496 --- js/app/services/request.coffee | 37 +----- js/app/services/router.coffee | 26 ---- js/app/services/services.coffee | 6 +- js/public/app.js | 145 ++++++----------------- js/tests/services/notimplementederrorSpec.coffee | 2 +- js/tests/services/requestSpec.coffee | 76 +++--------- js/tests/services/routerSpec.coffee | 33 ------ 7 files changed, 59 insertions(+), 266 deletions(-) delete mode 100644 js/app/services/router.coffee delete mode 100644 js/tests/services/routerSpec.coffee diff --git a/js/app/services/request.coffee b/js/app/services/request.coffee index e0e24bb44..ec8ccf70c 100644 --- a/js/app/services/request.coffee +++ b/js/app/services/request.coffee @@ -26,14 +26,7 @@ angular.module('News').factory '_Request', -> class Request - constructor: (@_$http, @_publisher, @_router) -> - @_initialized = false - @_shelvedRequests = [] - - @_router.registerLoadedCallback => - @_initialized = true - @_executeShelvedRequests() - @_shelvedRequests = [] + constructor: (@_$http, @_publisher, @_utils) -> request: (route, data={}) -> @@ -58,12 +51,7 @@ angular.module('News').factory '_Request', -> angular.extend(defaultData, data) - # if routes are not ready yet, save the request - if not @_initialized - @_shelveRequest(route, defaultData) - return - - url = @_router.generate(route, defaultData.routeParams) + url = @_utils.generateUrl(route, defaultData.routeParams) defaultConfig = url: url @@ -126,25 +114,4 @@ angular.module('News').factory '_Request', -> @request(route, data) - _shelveRequest: (route, data) -> - ### - Saves requests for later if the routes have not been loaded - ### - request = - route: route - data: data - - @_shelvedRequests.push(request) - - - _executeShelvedRequests: -> - ### - Run all saved requests that were done before routes were fully - loaded - ### - for r in @_shelvedRequests - @request(r.route, r.data) - - - return Request diff --git a/js/app/services/router.coffee b/js/app/services/router.coffee deleted file mode 100644 index 49c87c112..000000000 --- a/js/app/services/router.coffee +++ /dev/null @@ -1,26 +0,0 @@ -### - -ownCloud - News - -@author Bernhard Posselt -@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -License as published by the Free Software Foundation; either -version 3 of the License, or any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU AFFERO GENERAL PUBLIC LICENSE for more details. - -You should have received a copy of the GNU Affero General Public -License along with this library. If not, see . - -### - - -# Inject router into angular to make testing easier -angular.module('News').factory 'Router', -> - return OC.Router \ No newline at end of file diff --git a/js/app/services/services.coffee b/js/app/services/services.coffee index 1a7633d42..bc9c32cd2 100644 --- a/js/app/services/services.coffee +++ b/js/app/services/services.coffee @@ -23,9 +23,9 @@ License along with this library. If not, see . # request related stuff angular.module('News').factory 'Request', -['_Request', '$http', 'Publisher', 'Router', -(_Request, $http, Publisher, Router) -> - return new _Request($http, Publisher, Router) +['_Request', '$http', 'Publisher', 'Utils', +(_Request, $http, Publisher, Utils) -> + return new _Request($http, Publisher, Utils) ] diff --git a/js/public/app.js b/js/public/app.js index 1c45a5394..7b80f1efd 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -3452,7 +3452,7 @@ License along with this library. If not, see . onFailure: failureCallbackWrapper }; if (!this._preventUselessAutoPageRequest) { - return this._request.get('news_items', params); + return this._request.get('/apps/news/items', params); } else { onSuccess(); return loading.decrease(); @@ -3471,7 +3471,7 @@ License along with this library. If not, see . onSuccess: onSuccess, onFailure: onSuccess }; - return this._request.get('news_items_new', params); + return this._request.get('/apps/news/items/new', params); }; Persistence.prototype.starItem = function(feedId, guidHash) { @@ -3486,7 +3486,7 @@ License along with this library. If not, see . guidHash: guidHash } }; - return this._request.post('news_items_star', params); + return this._request.post('/apps/news/items/{feedId}/{guidHash}/star', params); }; Persistence.prototype.unstarItem = function(feedId, guidHash) { @@ -3501,7 +3501,7 @@ License along with this library. If not, see . guidHash: guidHash } }; - return this._request.post('news_items_unstar', params); + return this._request.post('/apps/news/items/{feedId}/{guidHash}/unstar', params); }; Persistence.prototype.readItem = function(itemId) { @@ -3515,7 +3515,7 @@ License along with this library. If not, see . itemId: itemId } }; - return this._request.post('news_items_read', params); + return this._request.post('/apps/news/items/{itemId}/read', params); }; Persistence.prototype.unreadItem = function(itemId) { @@ -3529,7 +3529,7 @@ License along with this library. If not, see . itemId: itemId } }; - return this._request.post('news_items_unread', params); + return this._request.post('/apps/news/items/{itemId}/unread', params); }; Persistence.prototype.setAllRead = function(highestItemId) { @@ -3543,7 +3543,7 @@ License along with this library. If not, see . highestItemId: highestItemId } }; - return this._request.post('news_items_all_read', params); + return this._request.post('/apps/news/items/read', params); }; /* @@ -3577,7 +3577,7 @@ License along with this library. If not, see . onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; - return this._request.get('news_feeds', params); + return this._request.get('/apps/news/feeds', params); }; Persistence.prototype.getActiveFeed = function(onSuccess) { @@ -3595,7 +3595,7 @@ License along with this library. If not, see . onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; - return this._request.get('news_feeds_active', params); + return this._request.get('/apps/news/feeds/active', params); }; Persistence.prototype.createFeed = function(url, parentFolderId, onSuccess, onFailure) { @@ -3616,7 +3616,7 @@ License along with this library. If not, see . onSuccess: onSuccess, onFailure: onFailure }; - return this._request.post('news_feeds_create', params); + return this._request.post('/apps/news/feeds', params); }; Persistence.prototype.deleteFeed = function(feedId) { @@ -3626,7 +3626,7 @@ License along with this library. If not, see . feedId: feedId } }; - return this._request["delete"]('news_feeds_delete', params); + return this._request["delete"]('/apps/news/feeds/{feedId}', params); }; Persistence.prototype.restoreFeed = function(feedId, onSuccess) { @@ -3641,7 +3641,7 @@ License along with this library. If not, see . feedId: feedId } }; - return this._request.post('news_feeds_restore', params); + return this._request.post('/apps/news/feeds/{feedId}/restore', params); }; Persistence.prototype.moveFeed = function(feedId, folderId) { @@ -3658,7 +3658,7 @@ License along with this library. If not, see . parentFolderId: folderId } }; - return this._request.post('news_feeds_move', params); + return this._request.post('/apps/news/feeds/{feedId}/move', params); }; Persistence.prototype.renameFeed = function(feedId, feedTitle) { @@ -3675,7 +3675,7 @@ License along with this library. If not, see . feedTitle: feedTitle } }; - return this._request.post('news_feeds_rename', params); + return this._request.post('/apps/news/feeds/{feedId}/rename', params); }; Persistence.prototype.setFeedRead = function(feedId, highestItemId) { @@ -3692,7 +3692,7 @@ License along with this library. If not, see . highestItemId: highestItemId } }; - return this._request.post('news_feeds_read', params); + return this._request.post('/apps/news/feeds/{feedId}/read', params); }; Persistence.prototype.updateFeed = function(feedId) { @@ -3706,7 +3706,7 @@ License along with this library. If not, see . feedId: feedId } }; - return this._request.post('news_feeds_update', params); + return this._request.post('/apps/news/feeds/{feedId}/update', params); }; Persistence.prototype.importArticles = function(json, onSuccess) { @@ -3721,7 +3721,7 @@ License along with this library. If not, see . return onSuccess(); } }; - return this._request.post('news_feeds_import_articles', params); + return this._request.post('/apps/news/feeds/import/articles', params); }; /* @@ -3755,7 +3755,7 @@ License along with this library. If not, see . onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; - return this._request.get('news_folders', params); + return this._request.get('/apps/news/folders', params); }; Persistence.prototype.openFolder = function(folderId) { @@ -3769,7 +3769,7 @@ License along with this library. If not, see . folderId: folderId } }; - return this._request.post('news_folders_open', params); + return this._request.post('/apps/news/folders/{folderId}/open', params); }; Persistence.prototype.collapseFolder = function(folderId) { @@ -3783,7 +3783,7 @@ License along with this library. If not, see . folderId: folderId } }; - return this._request.post('news_folders_collapse', params); + return this._request.post('/apps/news/folders/{folderId}/collapse', params); }; Persistence.prototype.createFolder = function(folderName, parentFolderId, onSuccess, onFailure) { @@ -3807,7 +3807,7 @@ License along with this library. If not, see . onSuccess: onSuccess, onFailure: onFailure }; - return this._request.post('news_folders_create', params); + return this._request.post('/apps/news/folders/create', params); }; Persistence.prototype.deleteFolder = function(folderId) { @@ -3821,7 +3821,7 @@ License along with this library. If not, see . folderId: folderId } }; - return this._request["delete"]('news_folders_delete', params); + return this._request["delete"]('/apps/news/folders/{folderId}', params); }; Persistence.prototype.restoreFolder = function(folderId, onSuccess) { @@ -3836,7 +3836,7 @@ License along with this library. If not, see . folderId: folderId } }; - return this._request.post('news_folders_restore', params); + return this._request.post('/apps/news/folders/{folderId}/restore', params); }; Persistence.prototype.renameFolder = function(folderId, folderName) { @@ -3853,7 +3853,7 @@ License along with this library. If not, see . folderName: folderName } }; - return this._request.post('news_folders_rename', params); + return this._request.post('/apps/news/folders/{folderId}/rename', params); }; Persistence.prototype.setFolderRead = function(folderId, highestItemId) { @@ -3870,7 +3870,7 @@ License along with this library. If not, see . highestItemId: highestItemId } }; - return this._request.post('news_folders_read', params); + return this._request.post('/apps/news/folders/{folderId}/read', params); }; /* @@ -3883,7 +3883,7 @@ License along with this library. If not, see . Prompts for an OPML download */ - return this._request.get('news_export_opml'); + return this._request.get('/apps/news/export/opml'); }; /* @@ -3914,7 +3914,7 @@ License along with this library. If not, see . onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; - return this._request.get('news_usersettings_read', params); + return this._request.get('/apps/news/usersettings/read', params); }; Persistence.prototype.userSettingsReadShow = function(callback) { @@ -3926,7 +3926,7 @@ License along with this library. If not, see . data = { onSuccess: callback }; - return this._request.post('news_usersettings_read_show', data); + return this._request.post('/apps/news/usersettings/read/show', data); }; Persistence.prototype.userSettingsReadHide = function(callback) { @@ -3938,7 +3938,7 @@ License along with this library. If not, see . data = { onSuccess: callback }; - return this._request.post('news_usersettings_read_hide', data); + return this._request.post('/apps/news/usersettings/read/hide', data); }; Persistence.prototype.userSettingsLanguage = function(onSuccess) { @@ -3960,11 +3960,11 @@ License along with this library. If not, see . onSuccess: successCallbackWrapper, onFailure: failureCallbackWrapper }; - return this._request.get('news_usersettings_language', data); + return this._request.get('/apps/news/usersettings/language', data); }; Persistence.prototype.userSettingsIsCompact = function() { - return this._request.get('news_usersettings_iscompact'); + return this._request.get('/apps/news/usersettings/compact'); }; Persistence.prototype.userSettingsSetCompact = function(isCompact) { @@ -3978,7 +3978,7 @@ License along with this library. If not, see . compact: isCompact } }; - return this._request.post('news_usersettings_setcompact', params); + return this._request.post('/apps/news/usersettings/compact', params); }; Persistence.prototype._triggerHideRead = function() { @@ -4791,18 +4791,10 @@ License along with this library. If not, see . angular.module('News').factory('_Request', function() { var Request; Request = (function() { - function Request(_$http, _publisher, _router) { - var _this = this; + function Request(_$http, _publisher, _utils) { this._$http = _$http; this._publisher = _publisher; - this._router = _router; - this._initialized = false; - this._shelvedRequests = []; - this._router.registerLoadedCallback(function() { - _this._initialized = true; - _this._executeShelvedRequests(); - return _this._shelvedRequests = []; - }); + this._utils = _utils; } Request.prototype.request = function(route, data) { @@ -4832,11 +4824,7 @@ License along with this library. If not, see . config: {} }; angular.extend(defaultData, data); - if (!this._initialized) { - this._shelveRequest(route, defaultData); - return; - } - url = this._router.generate(route, defaultData.routeParams); + url = this._utils.generateUrl(route, defaultData.routeParams); defaultConfig = { url: url, data: defaultData.data @@ -4909,35 +4897,6 @@ License along with this library. If not, see . return this.request(route, data); }; - Request.prototype._shelveRequest = function(route, data) { - /* - Saves requests for later if the routes have not been loaded - */ - - var request; - request = { - route: route, - data: data - }; - return this._shelvedRequests.push(request); - }; - - Request.prototype._executeShelvedRequests = function() { - /* - Run all saved requests that were done before routes were fully - loaded - */ - - var r, _i, _len, _ref, _results; - _ref = this._shelvedRequests; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - r = _ref[_i]; - _results.push(this.request(r.route, r.data)); - } - return _results; - }; - return Request; })(); @@ -4969,40 +4928,10 @@ License along with this library. If not, see . */ -(function() { - angular.module('News').factory('Router', function() { - return OC.Router; - }); - -}).call(this); - -// Generated by CoffeeScript 1.6.3 -/* - -ownCloud - News - -@author Bernhard Posselt -@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -License as published by the Free Software Foundation; either -version 3 of the License, or any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU AFFERO GENERAL PUBLIC LICENSE for more details. - -You should have received a copy of the GNU Affero General Public -License along with this library. If not, see . -*/ - - (function() { angular.module('News').factory('Request', [ - '_Request', '$http', 'Publisher', 'Router', function(_Request, $http, Publisher, Router) { - return new _Request($http, Publisher, Router); + '_Request', '$http', 'Publisher', 'Utils', function(_Request, $http, Publisher, Utils) { + return new _Request($http, Publisher, Utils); } ]); diff --git a/js/tests/services/notimplementederrorSpec.coffee b/js/tests/services/notimplementederrorSpec.coffee index 539f7e0c7..0edc696ae 100644 --- a/js/tests/services/notimplementederrorSpec.coffee +++ b/js/tests/services/notimplementederrorSpec.coffee @@ -1,6 +1,6 @@ ### -ownCloud - News +ownCloud - News @author Bernhard Posselt @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com diff --git a/js/tests/services/requestSpec.coffee b/js/tests/services/requestSpec.coffee index 30c09efc4..c1dfc1327 100644 --- a/js/tests/services/requestSpec.coffee +++ b/js/tests/services/requestSpec.coffee @@ -25,66 +25,22 @@ describe '_Request', -> beforeEach module 'News' beforeEach inject (_Request, _Publisher) => - @router = - generate: (route, values) -> + @utils = + generateUrl: (route, values) -> return 'url' - registerLoadedCallback: (callback) -> - callback() @publisher = new _Publisher() @request = _Request - - it 'should not send requests if not initialized', => - http = jasmine.createSpy('http') - @router.registerLoadedCallback = -> - req = new @request(http, @publisher, @router) - - req.request('route') - - expect(http).not.toHaveBeenCalled() - - - it 'should send requests if initialized', => - success = - success: -> - error: -> - - @router.registerLoadedCallback = (callback) -> - @callback = callback - @router.call = -> - @callback() - - http = jasmine.createSpy('http').andReturn(success) - - config = - route: 'route' - data: - data: - abc: 'test' - - called = - url: 'url' - data: config.data.data - - req = new @request(http, @publisher, @router) - req.request(config.route, config.data) - - @router.call() - - expect(http).toHaveBeenCalledWith(called) - expect(http.callCount).toBe(1) - - - it 'should should call router', => + it 'should should call utils', => success = success: -> error: -> http = jasmine.createSpy('http').andReturn(success) - router = - generate: jasmine.createSpy('router').andReturn('url') - registerLoadedCallback: @router.registerLoadedCallback + utils = + generateUrl: jasmine.createSpy('utils').andReturn('url') + registerLoadedCallback: @utils.registerLoadedCallback config = route: 'route' @@ -92,10 +48,10 @@ describe '_Request', -> routeParams: test: 'test' - req = new @request(http, @publisher, router) + req = new @request(http, @publisher, utils) req.request(config.route, config.data) - expect(router.generate).toHaveBeenCalledWith(config.route, + expect(utils.generateUrl).toHaveBeenCalledWith(config.route, config.data.routeParams) @@ -112,7 +68,7 @@ describe '_Request', -> onSuccess = jasmine.createSpy('onSucces') onFailure = jasmine.createSpy('onFailure') - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) data = onSuccess: onSuccess onFailure: onFailure @@ -139,7 +95,7 @@ describe '_Request', -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, publisher, @router) + req = new @request(http, publisher, @utils) req.request(null) expect(publisher.publishDataTo).toHaveBeenCalledWith( @@ -154,7 +110,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) defaultConfig = config: @@ -174,7 +130,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) defaultConfig = config: @@ -193,7 +149,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) defaultConfig = config: @@ -214,7 +170,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) data = config: @@ -239,7 +195,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) defaultConfig = config: @@ -259,7 +215,7 @@ describe '_Request', -> error: -> http = jasmine.createSpy('http').andReturn(success) - req = new @request(http, @publisher, @router) + req = new @request(http, @publisher, @utils) defaultConfig = config: diff --git a/js/tests/services/routerSpec.coffee b/js/tests/services/routerSpec.coffee deleted file mode 100644 index 1d9873106..000000000 --- a/js/tests/services/routerSpec.coffee +++ /dev/null @@ -1,33 +0,0 @@ -### - -ownCloud - News - -@author Bernhard Posselt -@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -License as published by the Free Software Foundation; either -version 3 of the License, or any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU AFFERO GENERAL PUBLIC LICENSE for more details. - -You should have received a copy of the GNU Affero General Public -License along with this library. If not, see . - -### - -describe 'Router', -> - - beforeEach module 'News' - - beforeEach => - inject (Router) => - @router = Router - - - it 'should have a defined router', => - expect(@router).toBeDefined() -- cgit v1.2.3