Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 26 | Rev 44 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 26 Rev 31
Línea 6... Línea 6...
6
//
6
//
Línea 7... Línea 7...
7
 
7
 
8
import Foundation
8
import Foundation
Línea 9... Línea -...
9
import SwiftUI
-
 
10
 
-
 
11
 
-
 
12
struct UserNotificationGroupModel :Identifiable {
-
 
13
    var id : String = UUID().uuidString
-
 
14
    var label : String =  ""
-
 
15
    var notifications = [UserNotificationModel]()
-
 
16
}
-
 
17
 
-
 
18
 
9
import SwiftUI
19
 
10
 
20
class NotificationListViewModel: ObservableObject
11
class NotificationListViewModel: ObservableObject
21
{
12
{
Línea 22... Línea 13...
22
    @Published public var groups = [UserNotificationGroupModel]()
13
    @Published public var notifications = [UserNotificationModel]()
Línea 42... Línea 33...
42
        
33
        
43
        let showFormatter = DateFormatter()
34
        let showFormatter = DateFormatter()
Línea -... Línea 35...
-
 
35
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
Línea -... Línea 36...
-
 
36
        
-
 
37
        
-
 
38
        let userNotificationDao = UserNotificationDao.sharedInstance
-
 
39
        
-
 
40
        notifications.removeAll()
-
 
41
        notifications = userNotificationDao.selectAllByUserUuid(userUuid: appData.userUuid)
-
 
42
 
-
 
43
        var i : Int = 0
-
 
44
        while i  < notifications.count {
-
 
45
            
-
 
46
            
-
 
47
            switch notifications[i].dateOn
-
 
48
            {
-
 
49
                case sToday :
-
 
50
                    notifications[i].dateOn = Config.LANG_COMMON_TODAY
-
 
51
                    break
-
 
52
                
-
 
53
                case sYesterday :
-
 
54
                    notifications[i].dateOn = Config.LANG_COMMON_YESTERDAY
-
 
55
                    break
-
 
56
                
-
 
57
                default :
-
 
58
                    let d = dateFormatter.date(from: notifications[i].dateOn) ?? Date()
-
 
59
                    notifications[i].dateOn = showFormatter.string(from: d)
-
 
60
                    break
-
 
61
                
Línea 44... Línea 62...
44
        showFormatter.dateFormat = Constants.FORMAT_DATE_DMY
62
            }
45
        
-
 
46
        
-
 
47
        
-
 
48
        
63
            
Línea 49... Línea 64...
49
        groups.removeAll()
64
            i += 1
Línea 85... Línea 100...
85
            groups.append(userNotificationGroupModel)
100
            groups.append(userNotificationGroupModel)
Línea 86... Línea 101...
86
            
101
            
Línea 87... Línea 102...
87
            i += 1
102
            i += 1
-
 
103
            
88
            
104
        }
Línea 89... Línea 105...
89
        }
105
         */
90
    }
106
    }
91
    
107
    
Línea -... Línea 108...
-
 
108
 
92
 
109
    
93
    
110
    public func removeItem(id: Int) {
94
    public func removeItem(id: Int) {
111
        let userNotificationDao = UserNotificationDao.sharedInstance
Línea 95... Línea 112...
95
        let userNotificationDao = UserNotificationDao.sharedInstance
112
        userNotificationDao.remove(id: id)
96
        userNotificationDao.remove(id: id)
113
        
Línea 97... Línea 114...
97
        
114
        /*
-
 
115
        var i : Int = 0
-
 
116
        while i < groups.count {
-
 
117
            groups[i].notifications.remove(at:  groups[i].notifications.firstIndex(where: {  $0.id == id })!)
Línea 98... Línea 118...
98
        var i : Int = 0
118
        
Línea 99... Línea 119...
99
        while i < groups.count {
119
            i += 1
100
            groups[i].notifications.remove(at:  groups[i].notifications.firstIndex(where: {  $0.id == id })!)
120
        }
101
        
121
        
Línea -... Línea 122...
-
 
122
        groups.remove(at:  groups.firstIndex(where: {  $0.notifications.count == 0 })!)
-
 
123
         */
-
 
124
        
-
 
125
        notifications.remove(at: notifications.firstIndex(where: {  $0.id == id })!)
-
 
126
        
-
 
127
       
-
 
128
    }
-
 
129
    
-
 
130
    public func markForViewedById(id: Int) {
-
 
131
        let userNotificationDao = UserNotificationDao.sharedInstance
102
            i += 1
132
        userNotificationDao.markViewed(id: id)
103
        }
133
        
104
        
134
        
105
        groups.remove(at:  groups.firstIndex(where: { $0.notifications.count == 0})! )
135
        var i : Int = 0
Línea 122... Línea 152...
122
                
152
                
123
                j += 1
153
                j += 1
Línea 124... Línea 154...
124
            }
154
            }
125
        
155
        
126
            i += 1
156
            i += 1
Línea 127... Línea 157...
127
        }
157
        }*/
128
    }
158
    }
129
    
159
    
Línea 130... Línea 160...
130
    public func markAllForViewedByType(command : String) {
160
    public func markAllForViewedByType(command : String) {
-
 
161
        let notificationDao = UserNotificationDao()
-
 
162
        notificationDao.markViewedAllPendingByUserUuidAndCommand(userUuid: appData.userUuid, command: command)
-
 
163
        
-
 
164
        var i : Int = 0
-
 
165
        while i < notifications.count  {
-
 
166
            
-
 
167
            if notifications[i].command == command  {
-
 
168
                notifications[i].viewed = 1
-
 
169
            }
-
 
170
            i += 1
131
        let notificationDao = UserNotificationDao()
171
        }
132
        notificationDao.markViewedAllPendingByUserUuidAndCommand(userUuid: appData.userUuid, command: command)
172
        
133
        
173
        /*
Línea 134... Línea 174...
134
        var i : Int = 0
174
        var i : Int = 0
Línea 142... Línea 182...
142
                
182
                
143
                j += 1
183
                j += 1
Línea 144... Línea 184...
144
            }
184
            }
145
        
185
        
146
            i += 1
186
            i += 1
Línea 147... Línea 187...
147
        }
187
        }*/