From 11f0246acd0daab1067eb32099fa26f05a26ea21 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 19 May 2014 15:51:26 +0200 Subject: subscribe to more channels and fetch more feeds on init --- js/app/Config.js | 72 ++++++++++++++++++++++++++++++++++++++++++++------------ js/app/Run.js | 41 ++++++++++++++++++++++++-------- 2 files changed, 88 insertions(+), 25 deletions(-) (limited to 'js/app') diff --git a/js/app/Config.js b/js/app/Config.js index 290726343..5581af0e4 100644 --- a/js/app/Config.js +++ b/js/app/Config.js @@ -9,19 +9,22 @@ */ app.config(function ($routeProvider, $provide, $httpProvider) { 'use strict'; + var getResolve, + feedType; - // constants - $provide.constant('CONFIG', { - REFRESH_RATE: 60 // refresh feeds every 60 seconds - }); - $provide.constant('BASE_URL', OC.generateUrl('/apps/news')); - $provide.constant('FEED_TYPE', { + feedType = { FEED: 0, FOLDER: 1, STARRED: 2, SUBSCRIPTIONS: 3, SHARED: 4 - }); + }; + + // constants + $provide.constant('REFRESH_RATE', 60); // seconds, how often feeds and folders shoudl be refreshed + $provide.constant('ITEM_BATCH_SIZE', 50); // how many items to autopage by + $provide.constant('BASE_URL', OC.generateUrl('/apps/news')); + $provide.constant('FEED_TYPE', feedType); // make sure that the CSRF header is only sent to the ownCloud domain $provide.factory('CSRFInterceptor', function ($q, BASE_URL) { @@ -38,26 +41,65 @@ app.config(function ($routeProvider, $provide, $httpProvider) { $httpProvider.interceptors.push('CSRFInterceptor'); // routing + getResolve = function (type) { + return { + // request to items also returns feeds + data: [ + '$http', + '$route', + '$q', + 'BASE_URL', + 'ITEM_BATCH_SIZE', + function ($http, $route, $q, BASE_URL, ITEM_BATCH_SIZE) { + + var parameters, + deferred; + + parameters = { + type: type, + limit: ITEM_BATCH_SIZE + }; + + if ($route.current.params.id !== undefined) { + parameters.id = $route.current.params.id; + } + + deferred = $q.defer(); + + $http({ + url: BASE_URL + '/items', + method: 'GET', + params: parameters + }).success(function (data) { + deferred.resolve(data); + }); + + return deferred.promise; + } + ] + }; + }; + $routeProvider .when('/items', { - controller: 'ItemController', + controller: 'ContentController', templateUrl: 'content.html', - resolve: {} + resolve: getResolve(feedType.SUBSCRIPTIONS) }) .when('/items/starred', { - controller: 'StarredController', + controller: 'ContentController', templateUrl: 'content.html', - resolve: {} + resolve: getResolve(feedType.STARRED) }) .when('/items/feeds/:id', { - controller: 'FeedController', + controller: 'ContentController', templateUrl: 'content.html', - resolve: {} + resolve: getResolve(feedType.FEED) }) .when('/items/folders/:id', { - controller: 'FolderController', + controller: 'ContentController', templateUrl: 'content.html', - resolve: {} + resolve: getResolve(feedType.FOLDER) }) .otherwise({ redirectTo: '/items' diff --git a/js/app/Run.js b/js/app/Run.js index ad5d80ca1..829c9666c 100644 --- a/js/app/Run.js +++ b/js/app/Run.js @@ -9,7 +9,7 @@ */ app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, Feed, Folder, Settings, Publisher, BASE_URL, FEED_TYPE, - CONFIG) { + REFRESH_RATE) { 'use strict'; // show Loading screen @@ -17,23 +17,25 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, // listen to keys in returned queries to automatically distribute the // incoming values to models - Publisher.subscribe(Item).toChannel('items'); - Publisher.subscribe(Folder).toChannel('folders'); - Publisher.subscribe(Feed).toChannel('feeds'); - Publisher.subscribe(Settings).toChannel('settings'); + Publisher.subscribe(Item).toChannels('items', 'newestItemId', 'starred'); + Publisher.subscribe(Folder).toChannels('folders'); + Publisher.subscribe(Feed).toChannels('feeds'); + Publisher.subscribe(Settings).toChannels('settings'); // load feeds, settings and last read feed var settingsDeferred, - activeFeedDeferred; + activeFeedDeferred, + folderDeferred, + feedDeferred; settingsDeferred = $q.defer(); - $http.get(BASE_URL + '/settings').then(function (data) { + $http.get(BASE_URL + '/settings').success(function (data) { Publisher.publishAll(data); settingsDeferred.resolve(); }); activeFeedDeferred = $q.defer(); - $http.get(BASE_URL + '/feeds/active').then(function (data) { + $http.get(BASE_URL + '/feeds/active').success(function (data) { var url; switch (data.type) { @@ -58,8 +60,27 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, activeFeedDeferred.resolve(); }); + folderDeferred = $q.defer(); + $http.get(BASE_URL + '/folders').success(function (data) { + Publisher.publishAll(data); + folderDeferred.resolve(); + }); + + feedDeferred = $q.defer(); + $http.get(BASE_URL + '/feeds').success(function (data) { + Publisher.publishAll(data); + feedDeferred.resolve(); + }); + // disable loading if all initial requests finished - $q.all([settingsDeferred.promise, activeFeedDeferred.promise]) + $q.all( + [ + settingsDeferred.promise, + activeFeedDeferred.promise, + feedDeferred.promise, + folderDeferred.promise + ] + ) .then(function () { Loading.setLoading('global', false); }); @@ -68,7 +89,7 @@ app.run(function ($rootScope, $location, $http, $q, $interval, Loading, Item, $interval(function () { $http.get(BASE_URL + '/feeds'); $http.get(BASE_URL + '/folders'); - }, CONFIG.REFRESH_RATE * 1000); + }, REFRESH_RATE * 1000); $rootScope.$on('$routeChangeStart', function () { -- cgit v1.2.3