From 90584316b8f275fcad904b644676544eb0322636 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 19 May 2014 02:22:02 +0200 Subject: add test for firstrun page --- js/app/App.js | 10 ++++++++ js/app/Config.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++ js/app/Run.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ js/app/app.js | 10 -------- js/app/config.js | 41 ----------------------------- js/app/run.js | 36 -------------------------- 6 files changed, 153 insertions(+), 87 deletions(-) create mode 100644 js/app/App.js create mode 100644 js/app/Config.js create mode 100644 js/app/Run.js delete mode 100644 js/app/app.js delete mode 100644 js/app/config.js delete mode 100644 js/app/run.js (limited to 'js/app') diff --git a/js/app/App.js b/js/app/App.js new file mode 100644 index 000000000..947a68a2e --- /dev/null +++ b/js/app/App.js @@ -0,0 +1,10 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +var app = angular.module('News', ['ngRoute', 'ngSanitize', 'ngAnimate']); \ No newline at end of file diff --git a/js/app/Config.js b/js/app/Config.js new file mode 100644 index 000000000..67a5e7215 --- /dev/null +++ b/js/app/Config.js @@ -0,0 +1,65 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +app.config(function ($routeProvider, $provide, $httpProvider) { + 'use strict'; + + // constants + $provide.constant('BASE_URL', OC.generateUrl('/apps/news')); + + $provide.constant('FEED_TYPE', { + FEED: 0, + FOLDER: 1, + STARRED: 2, + SUBSCRIPTIONS: 3, + SHARED: 4 + }); + + // make sure that the CSRF header is only sent to the ownCloud domain + $provide.factory('CSRFInterceptor', function ($q, BASE_URL) { + return { + request: function (config) { + if (config.url.indexOf(BASE_URL) === 0) { + config.headers.requesttoken = oc_requesttoken; + } + + return config || $q.when(config); + } + }; + }); + $httpProvider.interceptors.push('CSRFInterceptor'); + + // routing + $routeProvider + .when('/items', { + controller: 'ItemsController', + templateUrl: 'content.html', + resolve: {} + }) + .when('/items/starred', { + controller: 'StarredController', + templateUrl: 'content.html', + resolve: {} + }) + .when('/items/feeds/:id', { + controller: 'FeedController', + templateUrl: 'content.html', + resolve: {} + }) + .when('/items/folders/:id', { + controller: 'FolderController', + templateUrl: 'content.html', + resolve: {} + }) + .otherwise({ + redirectTo: '/items' + }); + +}); + diff --git a/js/app/Run.js b/js/app/Run.js new file mode 100644 index 000000000..936a03b9d --- /dev/null +++ b/js/app/Run.js @@ -0,0 +1,78 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +app.run(function ($rootScope, $location, $http, $q, Loading, Item, Feed, Folder, + Settings, Publisher, BASE_URL, FEED_TYPE) { + 'use strict'; + + // show Loading screen + Loading.setLoading('global', true); + + // 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'); + + // load feeds, settings and last read feed + var settingsDeferred, + activeFeedDeferred; + + settingsDeferred = $q.defer(); + $http.get(BASE_URL + '/settings').then(function (data) { + Publisher.publishAll(data); + settingsDeferred.resolve(); + }); + + activeFeedDeferred = $q.defer(); + $http.get(BASE_URL + '/feeds/active').then(function (data) { + var url; + + switch (data.type) { + + case FEED_TYPE.FEED: + url = '/items/feeds/' + data.id; + break; + + case FEED_TYPE.FOLDER: + url = '/items/folders/' + data.id; + break; + + case FEED_TYPE.STARRED: + url = '/items/starred'; + break; + + default: + url = '/items'; + } + + $location.path(url); + activeFeedDeferred.resolve(); + }); + + + $q.all([settingsDeferred.promise, activeFeedDeferred.promise]).then(function () { + Loading.setLoading('global', false); + }); + + + $rootScope.$on('$routeChangeStart', function () { + Loading.setLoading('content', true); + }); + + $rootScope.$on('$routeChangeSuccess', function () { + Loading.setLoading('content', false); + }); + + // in case of wrong id etc show all items + $rootScope.$on('$routeChangeError', function () { + $location.path('/items'); + }); +}); \ No newline at end of file diff --git a/js/app/app.js b/js/app/app.js deleted file mode 100644 index 947a68a2e..000000000 --- a/js/app/app.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2014 - */ -var app = angular.module('News', ['ngRoute', 'ngSanitize', 'ngAnimate']); \ No newline at end of file diff --git a/js/app/config.js b/js/app/config.js deleted file mode 100644 index 776f4ee92..000000000 --- a/js/app/config.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2014 - */ -app.config(function ($routeProvider, $provide) { - 'use strict'; - - $provide.constant('baseUrl', OC.generateUrl('')); - - $routeProvider - .when('/items', { - controller: 'AllItemsController', - templateUrl: 'content.html', - resolve: {} - }) - .when('/items/starred', { - controller: 'StarredItemsController', - templateUrl: 'content.html', - resolve: {} - }) - .when('/items/feeds/:id', { - controller: 'FeedItemsController', - templateUrl: 'content.html', - resolve: {} - }) - .when('/items/folders/:id', { - controller: 'FolderItemsController', - templateUrl: 'content.html', - resolve: {} - }) - .otherwise({ - redirectTo: '/items' - }); - -}); - diff --git a/js/app/run.js b/js/app/run.js deleted file mode 100644 index f91d908f2..000000000 --- a/js/app/run.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2014 - */ -app.run(function ($rootScope, $location, Loading, Setup, Item, Feed, Folder, - Publisher, Settings) { - 'use strict'; - - // 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'); - - // load feeds, settings and last read feed - Setup.load(); - - $rootScope.$on('$routeChangeStart', function () { - Loading.setLoading('content', true); - }); - - $rootScope.$on('$routeChangeSuccess', function () { - Loading.setLoading('content', false); - }); - - // in case of wrong id etc show all items - $rootScope.$on('$routeChangeError', function () { - $location.path('/items'); - }); -}); \ No newline at end of file -- cgit v1.2.3