Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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

Rev 8 Rev 11
Línea 46... Línea 46...
46
    @State private var titleAlert : String = ""
46
    @State private var titleAlert : String = ""
47
    @State private var messageAlert : String = ""
47
    @State private var messageAlert : String = ""
Línea 48... Línea 48...
48
    
48
    
Línea 49... Línea 49...
49
    @State private var showProgressView : Bool = false
49
    @State private var showProgressView : Bool = false
Línea 50... Línea 50...
50
    
50
    
Línea 97... Línea 97...
97
             {
97
             {
98
                case .introduction :
98
                case .introduction :
99
                    CommentAndRatingIntroductionView(capsuleModel:  self.capsuleViewModel.capsule).padding(5)
99
                    CommentAndRatingIntroductionView(capsuleModel:  self.capsuleViewModel.capsule).padding(5)
Línea 100... Línea 100...
100
                
100
                
-
 
101
                case .comments :
-
 
102
                    if self.commentsViewModel.comments.count == 0 {
-
 
103
                        CommentAndRatingCommentListEmptyView()
-
 
104
                    } else {
-
 
105
                    
-
 
106
                        ScrollView {
-
 
107
                            LazyVStack  {
-
 
108
                                //ForEach(0..<self.comments.count) { index in
-
 
109
                                
-
 
110
                                ForEach(self.commentsViewModel.comments) { commentItem in
-
 
111
                                    CommentAndRatingCommentListItem(comment: commentItem)
-
 
112
                                }
-
 
113
                                
-
 
114
                            }
-
 
115
                        }
-
 
116
                    }
-
 
117
                    
101
                case .comments :
118
                    
Línea 102... Línea 119...
102
                    CommentAndRatingCommentListView(comments: self.commentsViewModel.comments, showProgressView: self.$showProgressView).border(Color.blue, width: 1)
119
                   // CommentAndRatingCommentListView(comments: self.commentsViewModel.comments, showProgressView: self.$showProgressView).border(Color.blue, width: 1)
103
          
120
          
104
                default :
121
                default :
Línea 109... Línea 126...
109
            
126
            
110
            Spacer()
127
            Spacer()
111
        }
128
        }
112
        .background(Color("color_picker_background"))
129
        .background(Color("color_picker_background"))
113
        .onAppear {
-
 
-
 
130
        .onAppear {
114
 
131
            let appData = appDao.selectOne()
Línea 115... Línea 132...
115
            self.capsuleViewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)
132
            self.capsuleViewModel.fetch(capsuleUuid: appData.capsuleUuidActive, userUuid: appData.userUuid)
116
 
133
 
117
            if self.capsuleViewModel.capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
134
            if self.capsuleViewModel.capsule.name.count > Constants.APP_BAR_TITLE_MAX_LENGTH {
Línea 134... Línea 151...
134
        { data in
151
        { data in
Línea 135... Línea 152...
135
        
152
        
136
 
153
 
-
 
154
            sendPostComment()
-
 
155
        }
-
 
156
        .onReceive(NotificationCenter.default.publisher(for: Constants.NOTIFICATION_NAME_COMMAND_DELETE_COMMENT))
-
 
157
          { data in
-
 
158
            if data.userInfo != nil {
-
 
159
                
-
 
160
                //print(data.userInfo)
-
 
161
                
-
 
162
                let id = data.userInfo?["id"]! as? String ?? ""
-
 
163
                let link_delete = data.userInfo?["link_delete"]! as? String ?? ""
-
 
164
                
-
 
165
                print("id = \(id)  link_delete = \(link_delete)")
-
 
166
                
-
 
167
                if !id.isEmpty || !link_delete.isEmpty {
-
 
168
                
-
 
169
                    deleteComment(id: id, linkDelete : link_delete)
-
 
170
                }
-
 
171
              
-
 
172
            }
-
 
173
 
137
            sendPostComment()
174
             
Línea 138... Línea 175...
138
        }
175
          }
139
    }
176
    }
140
    
177
    
Línea 141... Línea 178...
141
    func reloadComments()
178
    func reloadComments()
Línea -... Línea 179...
-
 
179
    {
142
    {
180
        self.commentsViewModel.comments.removeAll()
Línea 143... Línea 181...
143
        self.commentsViewModel.comments.removeAll()
181
        
144
        
182
        if !self.capsuleViewModel.capsule.linkComments.isEmpty && networkMonitor.status == .connected {
145
        if !self.capsuleViewModel.capsule.linkComments.isEmpty && networkMonitor.status == .connected {
183
            
146
            
184
            let appData = appDao.selectOne()
147
            let headerSecurity : HeaderSecurity = HeaderSecurity()
185
            let headerSecurity : HeaderSecurity = HeaderSecurity()
148
            
186
            
149
            let headers: HTTPHeaders = [
187
            let headers: HTTPHeaders = [
Línea 150... Línea 188...
150
                .init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),
188
                .init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),
-
 
189
                .init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),
-
 
190
                .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
Línea 151... Línea 191...
151
                .init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),
191
                .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
152
                .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
192
                .accept(Constants.HTTP_HEADER_ACCEPT)
153
                .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
193
            ]
154
                .accept(Constants.HTTP_HEADER_ACCEPT)
194
                
155
            ]
195
            //print("URL Comments: \(self.capsuleViewModel.capsule.linkComments)")
Línea 156... Línea 196...
156
                
196
            
Línea 157... Línea 197...
157
            print("URL Comments: \(self.capsuleViewModel.capsule.linkComments)")
197
            commentsViewModel.comments.removeAll()
158
                
-
 
Línea -... Línea 198...
-
 
198
                
-
 
199
            AF.request(self.capsuleViewModel.capsule.linkComments, method: .get, headers: headers).responseJSON{(response) in
-
 
200
                    self.showProgressView = false
-
 
201
                    switch response.result {
-
 
202
                        case .success:
-
 
203
                            let json = try? JSON(data: response.data!)
-
 
204
                            
-
 
205
                           // print("json : \(json)")
-
 
206
                            
-
 
207
                            if json?["success"] ?? "" != false {
-
 
208
                                
-
 
209
                                if json?["data"]["capsule"] != nil  {
-
 
210
                                    let sTotalComments = json?["data"]["capsule"]["total_comments"].string ?? ""
159
            AF.request(self.capsuleViewModel.capsule.linkComments, method: .get, headers: headers).responseJSON{(response) in
211
                                    
-
 
212
                                    let sTotalRating = json?["data"]["capsule"]["total_rating"].string ?? ""
-
 
213
                                  
-
 
214
                                    capsuleViewModel.capsule.totalComments = Int(sTotalComments) ?? 0
-
 
215
                                    capsuleViewModel.capsule.totalRating = Decimal(Double(sTotalRating) ?? 0)
-
 
216
                                    
-
 
217
                                    let capsuleDao = CapsuleDao.sharedInstance
-
 
218
                                    capsuleDao.update(capsule: capsuleViewModel.capsule)
-
 
219
                                }
-
 
220
                                
-
 
221
                                if json?["data"]["comments"] != nil  {
-
 
222
                                    var newComment : CommentAndRatingComment
-
 
223
                                    for jcomment in json!["data"]["comments"]
-
 
224
                                    {
-
 
225
                                        newComment = CommentAndRatingComment()
-
 
226
                                        newComment.date = jcomment.1["date"].string ?? ""
-
 
227
                                        newComment.rating = Decimal(Double(jcomment.1["rating"].string ??  "") ?? 0)
-
 
228
                                        newComment.fullname = jcomment.1["fullname"].string ?? ""
160
                    self.showProgressView = false
229
                                        newComment.comment = jcomment.1["comment"].string ?? ""
161
                    switch response.result {
230
                                        newComment.image = jcomment.1["image"].string ?? ""
162
                        case .success:
231
                                        newComment.link_delete = jcomment.1["link_delete"].string ?? ""
163
                            let json = try? JSON(data: response.data!)
232
                                        newComment.date = jcomment.1["date"].string ?? ""
164
                            
233
 
Línea 194... Línea 263...
194
    }
263
    }
Línea 195... Línea 264...
195
    
264
    
Línea -... Línea 265...
-
 
265
    func sendPostComment() {
-
 
266
        
196
    func sendPostComment() {
267
        
197
        
268
        
198
        
269
        let appData = appDao.selectOne()
199
        showProgressView = true
270
        showProgressView = true
200
        let parameters = [
271
        let parameters = [
Línea 201... Línea 272...
201
            Constants.POST_COMMENT_FIELD_COMMENT: "\(comment)",
272
            Constants.POST_COMMENT_FIELD_COMMENT: "\(comment)",
Línea 202... Línea 273...
202
            Constants.POST_COMMENT_FIELD_RATING: "\(rating)",
273
            Constants.POST_COMMENT_FIELD_RATING: "\(Int(rating))",
Línea 210... Línea 281...
210
            .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
281
            .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
211
            .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
282
            .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
212
            .accept(Constants.HTTP_HEADER_ACCEPT)
283
            .accept(Constants.HTTP_HEADER_ACCEPT)
213
        ]
284
        ]
Línea 214... Línea 285...
214
        
285
        
Línea 215... Línea 286...
215
        print("URL POST COMMENT : \(capsuleViewModel.capsule.linkComments)")
286
       // print("URL POST COMMENT : \(capsuleViewModel.capsule.linkComments)")
216
        
287
        
217
        self.showProgressView = true
288
        self.showProgressView = true
Línea 218... Línea 289...
218
        AF.request(capsuleViewModel.capsule.linkComments, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers).responseJSON{(response) in
289
        AF.request(capsuleViewModel.capsule.linkCommentAdd, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: headers).responseJSON{(response) in
219
            self.showProgressView = false
290
            self.showProgressView = false
-
 
291
            
220
            
292
            switch response.result {
Línea 221... Línea 293...
221
            switch response.result {
293
                case .success:
Línea 222... Línea 294...
222
                case .success:
294
            
Línea 232... Línea 304...
232
                            let now = Date()
304
                            let now = Date()
233
                            let dateFormatter = DateFormatter()
305
                            let dateFormatter = DateFormatter()
234
                            dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
306
                            dateFormatter.dateFormat = Constants.FORMAT_DATETIME_SERVICE
235
                            let dateOn = dateFormatter.string(from: now)
307
                            let dateOn = dateFormatter.string(from: now)
Línea 236... Línea 308...
236
      
308
      
-
 
309
                            let link_delete =  json?["data"]["comment"]["link_delete"].string ?? ""
Línea -... Línea 310...
-
 
310
 
-
 
311
                            
-
 
312
                            var newComment = CommentAndRatingComment()
-
 
313
                            newComment.date = dateOn
-
 
314
                            newComment.image = appData.userImage
-
 
315
                            newComment.fullname = "\(appData.userFirstname) \(appData.userLastname)"
-
 
316
                            newComment.rating = Decimal(rating)
-
 
317
                            newComment.comment = comment
-
 
318
                            newComment.link_delete = link_delete
-
 
319
                            
-
 
320
                            commentsViewModel.prepend(newComment: newComment)
-
 
321
                            
-
 
322
                            self.comment = ""
-
 
323
                            self.rating = 5
-
 
324
                            self.selectedType = .comments
-
 
325
                         }
-
 
326
                 
-
 
327
                        
Línea -... Línea 328...
-
 
328
                        if json?["data"]["capsule"] != nil  {
237
                            let link_delete =  json?["data"]["comment"]["comment"].string ?? ""
329
                            let sTotalComments = json?["data"]["capsule"]["total_comments"].string ?? ""
-
 
330
                            
-
 
331
                            let sTotalRating = json?["data"]["capsule"]["total_rating"].string ?? ""
-
 
332
                          
-
 
333
                            capsuleViewModel.capsule.totalComments = Int(sTotalComments) ?? 0
-
 
334
                            capsuleViewModel.capsule.totalRating = Decimal(Double(sTotalRating) ?? 0)
-
 
335
                            
-
 
336
                            let capsuleDao = CapsuleDao.sharedInstance
-
 
337
                            capsuleDao.update(capsule: capsuleViewModel.capsule)
-
 
338
                        }
-
 
339
                        
-
 
340
                        
-
 
341
                        
Línea -... Línea 342...
-
 
342
                        if json?["data"]["message"] != nil  {
-
 
343
                            let snackbar = TTGSnackbar(message: json?["data"]["message"].string ?? "", duration: .short)
-
 
344
                            snackbar.show()
-
 
345
                            
-
 
346
                        }
238
                            
347
                        
239
                            
348
   
240
                      
349
             
241
                            
350
                    } else {
242
                            let newComment = CommentAndRatingComment(date: dateOn,
351
                        let message = json?["data"].string ?? ""
243
                                image: appData.image,
352
                        if !message.isEmpty {
-
 
353
                            self.titleAlert = Config.LANG_ERROR_GENERIC_TITLE
-
 
354
                            self.messageAlert = message
-
 
355
                            self.presentAlert = true
Línea -... Línea 356...
-
 
356
                        }
244
                                fullname: "\(appData.firstName) \(appData.lastName)",
357
                    }
-
 
358
                    
-
 
359
                   return
-
 
360
                            
245
                                rating: Decimal(rating),
361
                case .failure :
-
 
362
                    self.titleAlert = Config.LANG_ERROR_COMMUNICATION_TITLE
-
 
363
                    self.messageAlert = Config.LANG_ERROR_COMMUNICATION_MESSAGE
-
 
364
                    self.presentAlert = true
-
 
365
                    
-
 
366
                    return
-
 
367
            }
-
 
368
        }
-
 
369
        
-
 
370
        
-
 
371
    }
-
 
372
    
-
 
373
    func deleteComment(id : String, linkDelete : String) {
-
 
374
        
-
 
375
        
-
 
376
        
-
 
377
        let appData = appDao.selectOne()
-
 
378
        showProgressView = true
-
 
379
 
-
 
380
        
-
 
381
        let headerSecurity : HeaderSecurity = HeaderSecurity()
-
 
382
        
-
 
383
        let headers: HTTPHeaders = [
-
 
384
            .init(name: Constants.HTTP_HEADER_SECURITY_TOKEN, value: appData.deviceUuid),
-
 
385
            .init(name: Constants.HTTP_HEADER_SECURITY_SECRET, value: headerSecurity.secret),
-
 
386
            .init(name: Constants.HTTP_HEADER_SECURITY_CREATED, value: String(headerSecurity.created)),
-
 
387
            .init(name: Constants.HTTP_HEADER_SECURITY_RAND, value: String(headerSecurity.rand)),
-
 
388
            .accept(Constants.HTTP_HEADER_ACCEPT)
-
 
389
        ]
-
 
390
 
-
 
391
        self.showProgressView = true
-
 
392
        AF.request(linkDelete, method: .post, encoding: URLEncoding.default, headers: headers).responseJSON{(response) in
-
 
393
            self.showProgressView = false
-
 
394
            
-
 
395
            switch response.result {
-
 
396
                case .success:
-
 
397
            
-
 
398
                    let json = try? JSON(data: response.data!)
-
 
399
                    
-
 
400
                   // print("json : \(json)")
Línea 246... Línea 401...
246
                                comment: comment, link_delete:
401
                    
247
                                    link_delete)
402
                    if json?["success"] ?? "" != false {
Línea 268... Línea 423...
268
                            let snackbar = TTGSnackbar(message: json?["data"]["message"].string ?? "", duration: .short)
423
                            let snackbar = TTGSnackbar(message: json?["data"]["message"].string ?? "", duration: .short)
269
                            snackbar.show()
424
                            snackbar.show()
Línea 270... Línea 425...
270
                            
425
                            
Línea -... Línea 426...
-
 
426
                        }
-
 
427
                        
Línea 271... Línea 428...
271
                        }
428
                        self.commentsViewModel.removeItem(id: id)
272
                        
429
                         
273
   
430