summaryrefslogtreecommitdiffstats
path: root/js/app
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-19 02:22:02 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-19 02:22:02 +0200
commit90584316b8f275fcad904b644676544eb0322636 (patch)
tree35ead28e8f0cdccc1771464442bb83ce5b558cc6 /js/app
parentded252d29e99e068ea341506129e47a05e053a24 (diff)
add test for firstrun page
Diffstat (limited to 'js/app')
-rw-r--r--js/app/App.js (renamed from js/app/app.js)0
-rw-r--r--js/app/Config.js65
-rw-r--r--js/app/Run.js78
-rw-r--r--js/app/config.js41
-rw-r--r--js/app/run.js36
5 files changed, 143 insertions, 77 deletions
diff --git a/js/app/app.js b/js/app/App.js
index 947a68a2e..947a68a2e 100644
--- a/js/app/app.js
+++ b/js/app/App.js
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 <dev@bernhard-posselt.com>
+ * @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 <dev@bernhard-posselt.com>
+ * @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/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 <dev@bernhard-posselt.com>
- * @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 <dev@bernhard-posselt.com>
- * @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