From 3b5d012b57774420049408b96aa64282f0d34609 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 9 Apr 2014 16:52:04 +0200 Subject: fix user settings request --- app/news.php | 2 +- appinfo/routes.php | 4 +- js/app/services/persistence.coffee | 80 ++++++++------------------ js/public/app.js | 97 ++++++++++---------------------- js/tests/services/persistenceSpec.coffee | 45 ++++----------- 5 files changed, 71 insertions(+), 157 deletions(-) diff --git a/app/news.php b/app/news.php index 8b886f61d..aa71fc4fc 100644 --- a/app/news.php +++ b/app/news.php @@ -188,7 +188,7 @@ class News extends App { $c['ItemMapper'], $c['API'], $c['TimeFactory'], - $c['Config'] + $c['Config'], $c['Enhancer'], $c['HTMLPurifier'] ); diff --git a/appinfo/routes.php b/appinfo/routes.php index d5d40c1a4..118cbac54 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -108,9 +108,9 @@ $app->registerRoutes(array( array('name' => 'item_api#star', 'url' => '/api/v1-2/feeds/{feedId}/{guidHash}/star', 'verb' => 'PUT'), // FIXME: POST would be more correct array('name' => 'item_api#unstar', 'url' => '/api/v1-2/feeds/{feedId}/{guidHash}/unstar', 'verb' => 'PUT'), // FIXME: POST would be more correct array('name' => 'item_api#star_multiple', 'url' => '/api/v1-2/feeds/star/multiple', 'verb' => 'PUT'), // FIXME: POST would be more correct - array('name' => 'item_api#unstar_multiple', 'url' => '/api/v1-2/feeds/unstar/multiple', 'verb' => 'PUT'), // FIXME: POST would be more correct + array('name' => 'item_api#unstar_multiple', 'url' => '/api/v1-2/feeds/unstar/multiple', 'verb' => 'PUT') // FIXME: POST would be more correct ) -); +)); /* TODO: FIX CORS $this->create('news_api_cors', '/api/v1-2/{path}')->method('options')->action( diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index bd44d15d1..cdd389909 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -37,19 +37,21 @@ $rootScope, $q) -> ### Loads the initial data from the server ### - + successCount = 0 @deferred = $q.defer() @getAllFolders() successCallback = => - @deferred.resolve() + if successCount == 1 + @deferred.resolve() + else + successCount++ @getAllFeeds(successCallback) - @userSettingsRead() - @userSettingsLanguage() - @userSettingsIsCompact() + @getSettings(successCallback) + # items can only be loaded after the active feed is known @getActiveFeed => @@ -442,34 +444,13 @@ $rootScope, $q) -> ### USERSETTINGS CONTROLLER ### - userSettingsRead: (onSuccess=null) -> - ### - Gets the configs for read settings - ### - onSuccess or= -> - - # loading sign handling - @_feedLoading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_feedLoading.decrease() - failureCallbackWrapper = (data) => - @_feedLoading.decrease() - - params = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - - @_request.get '/apps/news/usersettings/read', params - - userSettingsReadShow: (callback) -> ### Sets the reader mode to show all ### data = - onSuccess: callback - @_request.post '/apps/news/usersettings/read/show', data + showAll: true + @setSettings data, callback userSettingsReadHide: (callback) -> @@ -477,41 +458,30 @@ $rootScope, $q) -> Sets the reader mode to show only unread ### data = - onSuccess: callback - @_request.post '/apps/news/usersettings/read/hide', data - - - userSettingsLanguage: (onSuccess=null) -> - onSuccess or= -> + showAll: false + @setSettings data, callback - # loading sign handling - @_feedLoading.increase() - successCallbackWrapper = (data) => - onSuccess() - @_feedLoading.decrease() - failureCallbackWrapper = (data) => - @_feedLoading.decrease() + userSettingsSetCompact: (isCompact) -> + ### + sets all items of a folder as read + ### data = - onSuccess: successCallbackWrapper - onFailure: failureCallbackWrapper - - @_request.get '/apps/news/usersettings/language', data + compact: isCompact + @setSettings data - userSettingsIsCompact: -> - @_request.get '/apps/news/usersettings/compact' + setSettings: (settings, onSuccess) -> + onSuccess or= -> + data = + onSuccess: onSuccess + data: settings + @_request.post '/apps/news/settings', data - userSettingsSetCompact: (isCompact) -> - ### - sets all items of a folder as read - ### - params = - data: - compact: isCompact - @_request.post '/apps/news/usersettings/compact', params + getSettings: -> + @_request.get '/apps/news/settings' _triggerHideRead: -> diff --git a/js/public/app.js b/js/public/app.js index 49c88e11c..8aac72b38 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -1,3 +1,4 @@ + /** * ownCloud News App - v0.0.1 * @@ -3386,17 +3387,20 @@ License along with this library. If not, see . Loads the initial data from the server */ - var successCallback, + var successCallback, successCount, _this = this; + successCount = 0; this.deferred = $q.defer(); this.getAllFolders(); successCallback = function() { - return _this.deferred.resolve(); + if (successCount === 1) { + return _this.deferred.resolve(); + } else { + return successCount++; + } }; this.getAllFeeds(successCallback); - this.userSettingsRead(); - this.userSettingsLanguage(); - this.userSettingsIsCompact(); + this.getSettings(successCallback); this.getActiveFeed(function() { return _this.getItems(_this._activeFeed.getType(), _this._activeFeed.getId()); }); @@ -3890,94 +3894,54 @@ License along with this library. If not, see . */ - Persistence.prototype.userSettingsRead = function(onSuccess) { - var failureCallbackWrapper, params, successCallbackWrapper, - _this = this; - if (onSuccess == null) { - onSuccess = null; - } + Persistence.prototype.userSettingsReadShow = function(callback) { /* - Gets the configs for read settings + Sets the reader mode to show all */ - onSuccess || (onSuccess = function() {}); - this._feedLoading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._feedLoading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._feedLoading.decrease(); - }; - params = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper + var data; + data = { + showAll: true }; - return this._request.get('/apps/news/usersettings/read', params); + return this.setSettings(data, callback); }; - Persistence.prototype.userSettingsReadShow = function(callback) { + Persistence.prototype.userSettingsReadHide = function(callback) { /* - Sets the reader mode to show all + Sets the reader mode to show only unread */ var data; data = { - onSuccess: callback + showAll: false }; - return this._request.post('/apps/news/usersettings/read/show', data); + return this.setSettings(data, callback); }; - Persistence.prototype.userSettingsReadHide = function(callback) { + Persistence.prototype.userSettingsSetCompact = function(isCompact) { /* - Sets the reader mode to show only unread + sets all items of a folder as read */ var data; data = { - onSuccess: callback + compact: isCompact }; - return this._request.post('/apps/news/usersettings/read/hide', data); + return this.setSettings(data); }; - Persistence.prototype.userSettingsLanguage = function(onSuccess) { - var data, failureCallbackWrapper, successCallbackWrapper, - _this = this; - if (onSuccess == null) { - onSuccess = null; - } + Persistence.prototype.setSettings = function(settings, onSuccess) { + var data; onSuccess || (onSuccess = function() {}); - this._feedLoading.increase(); - successCallbackWrapper = function(data) { - onSuccess(); - return _this._feedLoading.decrease(); - }; - failureCallbackWrapper = function(data) { - return _this._feedLoading.decrease(); - }; data = { - onSuccess: successCallbackWrapper, - onFailure: failureCallbackWrapper + onSuccess: onSuccess, + data: settings }; - return this._request.get('/apps/news/usersettings/language', data); + return this._request.post('/apps/news/settings', data); }; - Persistence.prototype.userSettingsIsCompact = function() { - return this._request.get('/apps/news/usersettings/compact'); - }; - - Persistence.prototype.userSettingsSetCompact = function(isCompact) { - /* - sets all items of a folder as read - */ - - var params; - params = { - data: { - compact: isCompact - } - }; - return this._request.post('/apps/news/usersettings/compact', params); + Persistence.prototype.getSettings = function() { + return this._request.get('/apps/news/settings'); }; Persistence.prototype._triggerHideRead = function() { @@ -5172,3 +5136,4 @@ License along with this library. If not, see . }); }).call(this); + diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee index 083ce0f5d..a38668f4c 100644 --- a/js/tests/services/persistenceSpec.coffee +++ b/js/tests/services/persistenceSpec.coffee @@ -420,58 +420,36 @@ describe 'Persistence', -> ### USERSETTINGS CONTROLLER ### - it 'should do a proper get user settings read request', => - - params = - onSuccess: -> - - @Persistence.userSettingsRead(params.onSuccess) - - expected = - onSuccess: jasmine.any(Function) - onFailure: jasmine.any(Function) - - expect(@req.get).toHaveBeenCalledWith('/apps/news/usersettings/read', expected) - - - it 'should do a proper user settings read show request', => params = onSuccess: -> + data: + showAll: true @Persistence.userSettingsReadShow(params.onSuccess) - expect(@req.post).toHaveBeenCalledWith('/apps/news/usersettings/read/show', + expect(@req.post).toHaveBeenCalledWith('/apps/news/settings', params) it 'should do a proper user settings read hide request', => params = onSuccess: -> + data: + showAll: false + @Persistence.userSettingsReadHide(params.onSuccess) - expect(@req.post).toHaveBeenCalledWith('/apps/news/usersettings/read/hide', + expect(@req.post).toHaveBeenCalledWith('/apps/news/settings', params) - it 'should do a proper user settings language request', => - params = - onSuccess: -> - - @Persistence.userSettingsLanguage(params.onSuccess) - - expected = - onSuccess: jasmine.any(Function) - onFailure: jasmine.any(Function) - - expect(@req.get).toHaveBeenCalledWith('/apps/news/usersettings/language', - expected) - it 'should send a get compact view request', => - @Persistence.userSettingsIsCompact() + it 'should send a get settings request', => + @Persistence.getSettings() - expect(@req.get).toHaveBeenCalledWith('/apps/news/usersettings/compact') + expect(@req.get).toHaveBeenCalledWith('/apps/news/settings') it 'should send a set compact view request', => @@ -480,8 +458,9 @@ describe 'Persistence', -> expected = data: compact: true + onSuccess: jasmine.any(Function) - expect(@req.post).toHaveBeenCalledWith('/apps/news/usersettings/compact', + expect(@req.post).toHaveBeenCalledWith('/apps/news/settings', expected) -- cgit v1.2.3