SingleFormViewController.swift 3.45 KB
Newer Older
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
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
//
//  SingleFormViewController.swift
//  App16
//
//  Created by Grigor Aghabalyan on 3/29/20.
//  Copyright © 2020 X-TECH. All rights reserved.
//

import UIKit

class SingleFormViewController: UIViewController {
    
    // MARK: - IBOutlets
    @IBOutlet weak var outDateTimeTextLabel: UILabel!
    @IBOutlet weak var outAddressTextLabel: UILabel!
    @IBOutlet weak var destinationAddressTextLabel: UILabel!
    @IBOutlet weak var planneDateTimeTextLabel: UILabel!
    @IBOutlet weak var destinationTypeTextLabel: UILabel!
    
    @IBOutlet weak var outDateTimeLabel: UILabel!
    @IBOutlet weak var outAddressLabel: UILabel!
    @IBOutlet weak var destinationAddressLabel: UILabel!
    @IBOutlet weak var planneDateTimeLabel: UILabel!
    @IBOutlet weak var destinationTypeLabel: UILabel!
    
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
26
    @IBOutlet weak var nameLabel: UILabel!
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
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
    @IBOutlet weak var curentDateLabel: UILabel!
    @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
    
    // MARK: - Variables
    var formData: FormResponse?
    
    // MARK: - LifeCycle
    override func viewDidLoad() {
        super.viewDidLoad()

        setUI()
        if let data = formData {
            setData(response: data)
        }else {
             retriveCurentForm()
        }
    }
    
    private func setUI() {
        
        self.title = "FORM".localized()
        
        outDateTimeTextLabel.text = "OUT_ADDRESS".localized()
        outAddressTextLabel.text = "OUT_DATETIME".localized()
        destinationAddressTextLabel.text = "Address of the place of visit/Title".localized()
        planneDateTimeTextLabel.text = "Estimated Return Time".localized()
        destinationTypeTextLabel.text = "Purpose of the visit".localized()
    }
    
    private func setData(response: FormResponse?) {
        
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
58
59
60
61
62
63
64
        if let firstName = response?.firstName,
            let lastName = response?.lastName,
            let middleName = response?.middleName {
            nameLabel.text = "\(firstName) \(lastName) \(middleName)"
        }else {
            nameLabel.text = nil
        }
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
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
        
        outDateTimeLabel.text = response?.outDatetime
        outAddressLabel.text = response?.outAddress
        destinationAddressLabel.text = response?.visitingAddressAndName
        planneDateTimeLabel.text = response?.plannedReturnDatetime
        destinationTypeLabel.text = response?.visitingReason
        curentDateLabel.text = response?.createdAt
    }
    
    private func retriveCurentForm() {
        
        activityIndicator.isHidden = false
        activityIndicator.startAnimating()
        
        let form = CurentFormRequestForm(deviceToken: UIDevice.current.identifierForVendor?.uuidString)
        
        CurrentFormService.shered.retrive(data: form) { (responseData) in
            switch responseData {
            case .base(response: let baseResposne):
                
                self.activityIndicator.stopAnimating()
                CheckBaseHelper.checkBaseResponse(baseResposne, viewController: self)
            case .success(let response):
                
                self.activityIndicator.stopAnimating()
                DispatchQueue.main.async {
                    self.setData(response: response.data )
                }
            case .isOffline:
                
                self.activityIndicator.stopAnimating()
                return
            case .conflict:
                
                self.activityIndicator.stopAnimating()
                return
            }
        }
    }
}