1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/**
* 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, $interval, Loading, Item,
Feed, Folder, Settings, Publisher, BASE_URL, FEED_TYPE,
CONFIG) {
'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();
});
// disable loading if all initial requests finished
$q.all([settingsDeferred.promise, activeFeedDeferred.promise])
.then(function () {
Loading.setLoading('global', false);
});
// refresh feeds and folders
$interval(function () {
$http.get(BASE_URL + '/feeds');
$http.get(BASE_URL + '/folders');
}, CONFIG.REFRESH_RATE * 1000);
$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');
});
});
|