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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/**
* Nextcloud - 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.controller('ContentController', function (Publisher, FeedResource, ItemResource, SettingsResource, data, $route,
$routeParams, $location, FEED_TYPE, ITEM_AUTO_PAGE_SIZE, Loading) {
'use strict';
var self = this;
ItemResource.clear();
// distribute data to models based on key
Publisher.publishAll(data);
var getOrdering = function () {
var ordering = SettingsResource.get('oldestFirst');
if (self.isFeed()) {
var feed = FeedResource.getById($routeParams.id);
if (feed && feed.ordering === 1) {
ordering = true;
} else if (feed && feed.ordering === 2) {
ordering = false;
}
}
return ordering;
};
this.getFirstItem = function () {
var orderedItems = this.getItems();
var item = orderedItems[orderedItems.length - 1];
var firstItem = orderedItems[0];
// If getOrdering == 1, then the sorting is set to
// newest first. So, item should be the first item
//
if (getOrdering()) {
item = firstItem;
}
if (item === undefined) {
return undefined;
}
else {
return item.id;
}
};
this.isAutoPagingEnabled = true;
// the interface should show a hint if there are not enough items sent
// it's assumed that theres nothing to autpage
this.isNothingMoreToAutoPage = ItemResource.size() < ITEM_AUTO_PAGE_SIZE;
this.getItems = function () {
return ItemResource.getAll();
};
this.isItemActive = function (id) {
return this.activeItem === id;
};
this.setItemActive = function (id) {
this.activeItem = id;
};
this.toggleStar = function (itemId) {
ItemResource.toggleStar(itemId);
};
this.toggleItem = function (item) {
// TODO: unittest
if (this.isCompactView()) {
item.show = !item.show;
}
};
this.isShowAll = function () {
return SettingsResource.get('showAll');
};
this.markRead = function (itemId) {
var item = ItemResource.get(itemId);
if (!item.keepUnread && item.unread === true) {
ItemResource.markItemRead(itemId);
FeedResource.markItemOfFeedRead(item.feedId);
}
};
this.getFeed = function (feedId) {
return FeedResource.getById(feedId);
};
this.toggleKeepUnread = function (itemId) {
var item = ItemResource.get(itemId);
if (!item.unread) {
ItemResource.markItemRead(itemId, false);
FeedResource.markItemOfFeedUnread(item.feedId);
}
item.keepUnread = !item.keepUnread;
};
this.sortIds = function(first, second) {
var firstInt = parseInt(first.value);
var secondInt = parseInt(second.value);
return (firstInt < secondInt) ? 1 : -1;
};
this.isCompactView = function () {
return SettingsResource.get('compact');
};
this.isCompactExpand = function () {
return SettingsResource.get('compactExpand');
};
this.autoPagingEnabled = function () {
return this.isAutoPagingEnabled;
};
this.markReadEnabled = function () {
return !SettingsResource.get('preventReadOnScroll');
};
this.scrollRead = function (itemIds) {
var ids = [];
var feedIds = [];
itemIds.forEach(function (itemId) {
var item = ItemResource.get(itemId);
if (!item.keepUnread) {
ids.push(itemId);
feedIds.push(item.feedId);
}
});
if (ids.length > 0) {
FeedResource.markItemsOfFeedsRead(feedIds);
ItemResource.markItemsRead(ids);
}
};
this.isFeed = function () {
return $route.current.$$route.type === FEED_TYPE.FEED;
};
this.oldestFirst = getOrdering();
this.autoPage = function () {
if (this.isNothingMoreToAutoPage) {
return;
}
// in case a subsequent autopage request comes in wait until
// the current one finished and execute a request immediately
// afterwards
if (!this.isAutoPagingEnabled) {
this.autoPageAgain = true;
return;
}
this.isAutoPagingEnabled = false;
this.autoPageAgain = false;
var type = $route.current.$$route.type;
var id = $routeParams.id;
var showAll = SettingsResource.get('showAll');
var self = this;
var search = $location.search().search;
Loading.setLoading('autopaging', true);
ItemResource.autoPage(type, id, this.oldestFirst, showAll, search).then(function (response) {
Publisher.publishAll(response.data);
if (response.data.items.length >= ITEM_AUTO_PAGE_SIZE) {
self.isAutoPagingEnabled = true;
} else {
self.isNothingMoreToAutoPage = true;
}
if (self.isAutoPagingEnabled && self.autoPageAgain) {
self.autoPage();
}
return response.data;
}, function () {
self.isAutoPagingEnabled = true;
}).finally(function () {
Loading.setLoading('autopaging', false);
});
};
this.getRelativeDate = function (timestamp) {
if (timestamp !== undefined && timestamp !== '') {
var languageCode = SettingsResource.get('language');
return moment.unix(timestamp).locale(languageCode).fromNow() + '';
} else {
return '';
}
};
this.refresh = function () {
$route.reload();
};
this.getMediaType = function (type) {
if (type && type.indexOf('audio') === 0) {
return 'audio';
} else if (type && type.indexOf('video') === 0) {
return 'video';
} else {
return undefined;
}
};
this.activeItem = this.getFirstItem();
});
|