You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

90 lines
2.7 KiB

//
// TransactionHistoryPresenter.swift
// GMERemittance
//
// Created by gme_2 on 28/09/2018.
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
class TransactionHistoryPresenter {
// MARK: Properties
var models: [TransactionModel] = []
var filteredModels: [TransactionModel] = [] {
didSet {
self.view?.show(models: filteredModels)
}
}
weak var view: TransactionHistoryViewInterface?
var interactor: TransactionHistoryInteractorInput?
var wireframe: TransactionHistoryWireframeInput?
// MARK: Converting entities
}
// MARK: TransactionHistory module interface
extension TransactionHistoryPresenter: TransactionHistoryModuleInterface {
func fetchTransactionHistories(fromDate: String?, toDate: String?) {
self.view?.showLoading()
interactor?.fetchTransactionHistories(fromDate: fromDate, toDate: toDate)
}
func viewIsReady() {
self.fetchTransactionHistories(fromDate: nil, toDate: nil)
}
func filterTransaction(type: TransactionModelType) {
switch type {
case .all:
self.filteredModels = models
case .paid:
self.filteredModels = models.filter({
($0.payStatus ?? "" ) == type.rawValue.lowercased()
})
case .received:
self.filteredModels = models.filter({
($0.payStatus ?? "" ) != TransactionModelType.paid.rawValue.lowercased()
})
}
}
func showDetailOf(index: Int) {
let element = self.models.elementAt(index: index)
guard let id = element?.transactionId, let controlNo = element?.controlNumber else {return}
wireframe?.openReciept(transactionId: id, control: controlNo)
}
func search(text: String) {
let searchText = text.lowercased()
self.filteredModels = (models).filter({
model in
return searchText.isEmpty || (model.controlNumber ?? "").contains(searchText)
})
// self.filteredModels = (models).filter({
// model in
// return searchText.isEmpty || (model.user ?? "").lowercased().contains(searchText)
// }).sorted(by: { (model, _) -> Bool in
// return (model.user ?? "").hasPrefix(searchText)
// })
}
}
// MARK: TransactionHistory interactor output interface
extension TransactionHistoryPresenter: TransactionHistoryInteractorOutput {
func show(error: Error) {
self.view?.hideLoading()
self.view?.show(error: error.localizedDescription)
}
func show(models: [TransactionModel]) {
self.view?.hideLoading()
self.models = models
self.filteredModels = self.models
}
}