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
|
###
# ownCloud news app
#
# @author Alessandro Cosentino
# @author Bernhard Posselt
# Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
# Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
#
# This file is licensed under the Affero General Public License version 3 or
# later.
#
# See the COPYING-README file
#
###
angular.module('News').factory '_ItemController', ['Controller', (Controller) ->
class ItemController extends Controller
constructor: (@$scope, @itemModel, @activeFeed, @persistence, @feedModel,
@starredCount, @garbageRegistry, @showAll, @loading
@$rootScope, @feedType) ->
@batchSize = 4
@loaderQueue = 0
@$scope.getItems = (type, id) =>
return @itemModel.getItemsByTypeAndId(type, id)
@$scope.items = @itemModel.getItems()
@$scope.loading = @loading
@$scope.scroll = =>
@$scope.activeFeed = @activeFeed
@$scope.$on 'read', (scope, params) =>
@$scope.markRead(params.id, params.feed)
@$scope.loadFeed = (feedId) =>
params =
id: feedId
type: @feedType.Feed
@$rootScope.$broadcast 'loadFeed', params
@$scope.markRead = (itemId, feedId) =>
item = @itemModel.getItemById(itemId)
feed = @feedModel.getItemById(feedId)
if not item.keptUnread && !item.isRead
item.isRead = true
feed.unreadCount -= 1
# this item will be completely deleted if showAll is false
if not @showAll.showAll
@garbageRegistry.register(item)
@persistence.markRead(itemId, true)
@$scope.keepUnread = (itemId, feedId) =>
item = @itemModel.getItemById(itemId)
feed = @feedModel.getItemById(feedId)
item.keptUnread = !item.keptUnread
if item.isRead
item.isRead = false
feed.unreadCount += 1
@persistence.markRead(itemId, false)
@$scope.isKeptUnread = (itemId) =>
return @itemModel.getItemById(itemId).keptUnread
@$scope.toggleImportant = (itemId) =>
item = @itemModel.getItemById(itemId)
# cache
@itemModel.setImportant(itemId, !item.isImportant)
if item.isImportant
@starredCount.count += 1
else
@starredCount.count -= 1
@persistence.setImportant(itemId, item.isImportant)
return ItemController
]
|