diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 2a5d095..24ad35d 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -45,6 +45,9 @@ 7A27ADF5249FD2F90035F39E /* FileManagerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A27ADF4249FD2F90035F39E /* FileManagerExt.swift */; }; 7A27ADF7249FEF690035F39E /* Recorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A27ADF6249FEF690035F39E /* Recorder.swift */; }; 7A27ADF924A09CAD0035F39E /* CocoaError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A27ADF824A09CAD0035F39E /* CocoaError.swift */; }; + 7A2DE69825868AC800A113FC /* VehicleAd.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69725868AC800A113FC /* VehicleAd.swift */; }; + 7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69A25869ABD00A113FC /* AdsController.swift */; }; + 7A2DE69E2589606A00A113FC /* ImageGridRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */; }; 7A33381124990DAE00D878F1 /* FiltersController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A33381024990DAE00D878F1 /* FiltersController.swift */; }; 7A333814249A532400D878F1 /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A333813249A532400D878F1 /* Filter.swift */; }; 7A3F07AB24360DC800E59687 /* Dated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3F07AA24360DC800E59687 /* Dated.swift */; }; @@ -141,6 +144,9 @@ 7A27ADF4249FD2F90035F39E /* FileManagerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileManagerExt.swift; sourceTree = ""; }; 7A27ADF6249FEF690035F39E /* Recorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recorder.swift; sourceTree = ""; }; 7A27ADF824A09CAD0035F39E /* CocoaError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CocoaError.swift; sourceTree = ""; }; + 7A2DE69725868AC800A113FC /* VehicleAd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehicleAd.swift; sourceTree = ""; }; + 7A2DE69A25869ABD00A113FC /* AdsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsController.swift; sourceTree = ""; }; + 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGridRow.swift; sourceTree = ""; }; 7A33381024990DAE00D878F1 /* FiltersController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FiltersController.swift; sourceTree = ""; }; 7A333813249A532400D878F1 /* Filter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filter.swift; sourceTree = ""; }; 7A3F07AA24360DC800E59687 /* Dated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dated.swift; sourceTree = ""; }; @@ -252,6 +258,7 @@ isa = PBXGroup; children = ( 7A0B969F257D6D4B000B39AD /* MultilineLabelRow.swift */, + 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */, ); path = eureka; sourceTree = ""; @@ -315,6 +322,7 @@ 7A33381024990DAE00D878F1 /* FiltersController.swift */, 7A27ADC6249D43210035F39E /* RegionsController.swift */, 7A27ADF2249F8B650035F39E /* RecordsController.swift */, + 7A2DE69A25869ABD00A113FC /* AdsController.swift */, ); path = Controllers; sourceTree = ""; @@ -360,6 +368,7 @@ 7A659B5824A2B1BA0043A0F2 /* AudioRecord.swift */, 7AAE6AD224CDDF950023860B /* VehicleEvent.swift */, 7A0420A925619AEC00034941 /* Osago.swift */, + 7A2DE69725868AC800A113FC /* VehicleAd.swift */, ); path = Models; sourceTree = ""; @@ -565,6 +574,7 @@ 7ADF6C9D250FA96000F237B2 /* SwiftMaskTextfield.swift in Sources */, 7A27ADF924A09CAD0035F39E /* CocoaError.swift in Sources */, 7A813DC9250B5C9700CC93B9 /* LocationRow.swift in Sources */, + 7A2DE69B25869ABD00A113FC /* AdsController.swift in Sources */, 7A6DD90824329144009DE740 /* CenterTextLayer.swift in Sources */, 7A813DC32508EE4F00CC93B9 /* EventCell.swift in Sources */, 7A3F07AD2436350B00E59687 /* SearchController.swift in Sources */, @@ -574,6 +584,7 @@ 7A659B5924A2B1BA0043A0F2 /* AudioRecord.swift in Sources */, 7A6DD90C24335A6D009DE740 /* FlagLayer.swift in Sources */, 7AE26A3524F31B0700625033 /* EventsController.swift in Sources */, + 7A2DE69E2589606A00A113FC /* ImageGridRow.swift in Sources */, 7AB67E8C2435C38700258F61 /* CustomTextField.swift in Sources */, 7A0420B62568650C00034941 /* DkbmController.swift in Sources */, 7A27ADF5249FD2F90035F39E /* FileManagerExt.swift in Sources */, @@ -604,6 +615,7 @@ 7A0420B12561A0E100034941 /* OsagoAddController.swift in Sources */, 7A11474723FF2AA500B424AF /* User.swift in Sources */, 7A11471623FDEB2A00B424AF /* MainSplitController.swift in Sources */, + 7A2DE69825868AC800A113FC /* VehicleAd.swift in Sources */, 7A813DC5250AAF3C00CC93B9 /* LocationEditController.swift in Sources */, 7A43F9F8246C8A6200BA5B49 /* JWT.swift in Sources */, 7A6DD903242BF4A5009DE740 /* PlateView.swift in Sources */, diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index d3ce803..beb21d8 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -25,7 +25,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( - schemaVersion: 26, + schemaVersion: 27, migrationBlock: { migration, oldSchemaVersion in if oldSchemaVersion <= 3 { var numbers: [String] = [] diff --git a/AutoCat/Controllers/AdsController.swift b/AutoCat/Controllers/AdsController.swift new file mode 100644 index 0000000..db15673 --- /dev/null +++ b/AutoCat/Controllers/AdsController.swift @@ -0,0 +1,64 @@ +import UIKit +import Eureka + +class AdsController: FormViewController { + + var ads: [VehicleAd] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + let formatter = DateFormatter() + formatter.dateStyle = .long + formatter.timeStyle = .none + + for ad in ads { + let date = Date(timeIntervalSince1970: ad.date) + let section = Section(formatter.string(from: date)) + + self.form +++ section + + if let price = ad.price { + section <<< LabelRow() { row in + row.title = NSLocalizedString("Price", comment: "") + row.value = price + } + } + + if let mileage = ad.mileage, mileage != "0" { + section <<< LabelRow() { row in + row.title = NSLocalizedString("Mileage", comment: "") + row.value = mileage + } + } + + if let region = ad.region { + section <<< LabelRow() { row in + row.title = NSLocalizedString("Region", comment: "") + row.value = region + } + } + + if let city = ad.city { + section <<< LabelRow() { row in + row.title = NSLocalizedString("City", comment: "") + row.value = city + } + } + + if let description = ad.adDescription { + section <<< MultilineLabelRow() { row in + row.title = NSLocalizedString("Description", comment: "") + row.value = description + } + } + +// if let url = URL(string: ad.url) { +// section <<< URLRow() { row in +// row.title = NSLocalizedString("Link", comment: "") +// row.value = url +// } +// } + } + } +} diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 6f46ff7..9079492 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -114,6 +114,17 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource self.present(mediaBrowser, animated: true, completion: nil) } } + + <<< LabelRow("Ads") { row in + row.title = NSLocalizedString("Ads", comment: "") + row.disabled = "$Ads == '0'" + } + .cellUpdate { cell, _ in cell.accessoryType = .disclosureIndicator } + .onCellSelection { _, row in + let controller = AdsController() + controller.ads = self.vehicle?.ads.toArray() ?? [] + self.navigationController?.pushViewController(controller, animated: true) + } } func row(_ tag: String) -> LabelRow? { @@ -146,6 +157,7 @@ class ReportController: FormViewController, MediaBrowserViewControllerDataSource self.row("OSAGO")?.value = String(self.vehicle?.osagoContracts.count ?? 0) self.row("Owners")?.value = String(self.vehicle?.ownershipPeriods.count ?? 0) self.row("Photos")?.value = String(self.vehicle?.photos.count ?? 0) + self.row("Ads")?.value = String(self.vehicle?.ads.count ?? 0) } func stringFromBool(_ value: Bool?, yes: String, no: String) -> String { diff --git a/AutoCat/Models/Vehicle.swift b/AutoCat/Models/Vehicle.swift index d8c38a3..3af05df 100644 --- a/AutoCat/Models/Vehicle.swift +++ b/AutoCat/Models/Vehicle.swift @@ -120,6 +120,7 @@ class Vehicle: Object, Decodable, Identifiable, Differentiable { let ownershipPeriods = List() let events = List() let osagoContracts = List() + let ads = List() var identifier: String = "" var id: String { @@ -156,6 +157,7 @@ class Vehicle: Object, Decodable, Identifiable, Differentiable { case ownershipPeriods case events case osagoContracts + case ads } required init(from decoder: Decoder) throws { @@ -199,6 +201,10 @@ class Vehicle: Object, Decodable, Identifiable, Differentiable { self.osagoContracts.append(objectsIn: osago) } + if let ads = try container.decodeIfPresent([VehicleAd].self, forKey: .ads) { + self.ads.append(objectsIn: ads) + } + self.identifier = self.number } diff --git a/AutoCat/Models/VehicleAd.swift b/AutoCat/Models/VehicleAd.swift new file mode 100644 index 0000000..ee859e5 --- /dev/null +++ b/AutoCat/Models/VehicleAd.swift @@ -0,0 +1,14 @@ +import Foundation +import RealmSwift + +class VehicleAd: Object, Decodable { + @objc dynamic var id: Int = 0 + @objc dynamic var url: String = "" + @objc dynamic var price: String? + @objc dynamic var date: TimeInterval = Date().timeIntervalSince1970 + @objc dynamic var mileage: String? + @objc dynamic var region: String? + @objc dynamic var city: String? + @objc dynamic var adDescription: String? + var photos = List() +} diff --git a/AutoCat/Utils/Constants.swift b/AutoCat/Utils/Constants.swift index fd8bd02..34e7169 100644 --- a/AutoCat/Utils/Constants.swift +++ b/AutoCat/Utils/Constants.swift @@ -3,9 +3,9 @@ import Foundation enum Constants { static var baseUrl: String { #if DEBUG - //return "http://127.0.0.1:3000/" + return "http://127.0.0.1:3000/" //return "http://192.168.1.67:3000/" - return "https://vps.aliencat.pro:8443/" + //return "https://vps.aliencat.pro:8443/" #else return "https://vps.aliencat.pro:8443/" #endif diff --git a/AutoCat/Views/eureka/ImageGridRow.swift b/AutoCat/Views/eureka/ImageGridRow.swift new file mode 100644 index 0000000..fbf2875 --- /dev/null +++ b/AutoCat/Views/eureka/ImageGridRow.swift @@ -0,0 +1,2 @@ +import Foundation +