diff --git a/Cartfile.resolved b/Cartfile.resolved index c52741f..df222f7 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ github "Alamofire/Alamofire" "4.5.1" -github "SwiftyJSON/SwiftyJSON" "3.1.4" +github "SwiftyJSON/SwiftyJSON" "4.0.0" github "Swinject/Swinject" "2.1.1" github "Swinject/SwinjectStoryboard" "1.1.2" github "xmartlabs/Eureka" "4.0.1" diff --git a/NavigationForiOS.xcodeproj/xcshareddata/xcschemes/NavigationForiOS.xcscheme b/NavigationForiOS.xcodeproj/xcshareddata/xcschemes/NavigationForiOS.xcscheme index fc0bb08..9f95f27 100644 --- a/NavigationForiOS.xcodeproj/xcshareddata/xcschemes/NavigationForiOS.xcscheme +++ b/NavigationForiOS.xcodeproj/xcshareddata/xcschemes/NavigationForiOS.xcscheme @@ -92,7 +92,7 @@ - - + + - + @@ -14,7 +14,7 @@ - + @@ -23,14 +23,14 @@ - + - + @@ -39,9 +39,9 @@ - + - + @@ -50,65 +50,22 @@ - + - - - - - - - - - - - - - - - - - + - + - + @@ -117,112 +74,32 @@ - + - + - + - + - - - - - - - - - - - - - - + + - - - - - - - - + @@ -233,7 +110,7 @@ - + @@ -313,7 +190,7 @@ - + @@ -324,15 +201,15 @@ - + - + - + - + @@ -373,21 +250,21 @@ - + - + - + - - + + @@ -396,7 +273,7 @@ - + @@ -407,15 +284,15 @@ - + - + - - + + @@ -423,84 +300,76 @@ + - - - - - - - - - - - - - - - + + + + + @@ -512,7 +381,7 @@ - + @@ -520,7 +389,7 @@ - + @@ -530,11 +399,10 @@ - + - - + diff --git a/NavigationForiOS/Const.swift b/NavigationForiOS/Const.swift index 82636e8..9ff72fc 100644 --- a/NavigationForiOS/Const.swift +++ b/NavigationForiOS/Const.swift @@ -14,7 +14,7 @@ class Const : NSObject { #if DEBUG let URL_API = "http://localhost/api" #else - let URL_API = "http://210.140.71.132/api" + let URL_API = "https://mizugorou.site/api" #endif } diff --git a/NavigationForiOS/EventEntity.swift b/NavigationForiOS/EventEntity.swift index e76eeef..dac9203 100644 --- a/NavigationForiOS/EventEntity.swift +++ b/NavigationForiOS/EventEntity.swift @@ -11,15 +11,15 @@ import Foundation class EventEntity { var id: String? var name: String? - var info: String? + var description: String? var startDate: String? var endDate: String? var location: String? - init(id: String, name: String, info: String, startDate: String, endDate: String, location: String) { + init(id: String, name: String, description: String, startDate: String, endDate: String, location: String) { self.id = id self.name = name - self.info = info + self.description = description self.startDate = startDate self.endDate = endDate self.location = location diff --git a/NavigationForiOS/EventInfoViewController.swift b/NavigationForiOS/EventInfoViewController.swift index 1b92449..0f9b097 100644 --- a/NavigationForiOS/EventInfoViewController.swift +++ b/NavigationForiOS/EventInfoViewController.swift @@ -6,37 +6,67 @@ // Copyright © 2017年 UmeSystems. All rights reserved. // -import Foundation import UIKit +import Eureka -class EventInfoViewController: UIViewController { - - @IBOutlet weak var eventName: UILabel! - - @IBOutlet weak var eventInfo: UILabel! - - @IBOutlet weak var eventDate: UILabel! - - @IBOutlet weak var eventLocation: UILabel! - - @IBOutlet weak var eventEndDate: UILabel! +class EventInfoViewController: FormViewController { var event: EventEntity? = nil - + var eventName: String! + var eventDescription: String! + var eventDate: String! + var eventEndDate: String! + var eventLocation: String! + override func viewDidLoad() { super.viewDidLoad() - + let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate self.event = appDelegate.eventInfo! - self.eventName.text = self.event?.name - self.eventInfo.text = self.event?.info - self.eventDate.text = self.event?.startDate - self.eventEndDate.text = self.event?.endDate - self.eventLocation.text = self.event?.location + self.eventName = self.event?.name + self.eventDescription = self.event?.description + self.eventDate = self.event?.startDate + self.eventEndDate = self.event?.endDate + self.eventLocation = self.event?.location + + form + +++ Section() + <<< LabelRow(){ + $0.title = "イベント名" + $0.value = self.eventName + } + + +++ Section(self.eventDescription) + + +++ Section() + <<< LabelRow(){ + $0.title = "開始日時" + $0.value = self.eventDate + } + <<< LabelRow(){ + $0.title = "終了日時" + $0.value = self.eventEndDate + } + + +++ Section() + <<< LabelRow(){ + $0.title = "場所" + $0.value = self.eventLocation + } + + // Button + +++ Section() + <<< ButtonRow(){ + $0.title = "ナビゲーションルートの選択" + $0.onCellSelection{ [unowned self] cell, row in + let vc = self.storyboard!.instantiateViewController(withIdentifier: "RouteStoryboard") + let navigationController = UINavigationController(rootViewController: vc) + self.present(navigationController, animated: true, completion: nil) + } + } + } - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - } } + diff --git a/NavigationForiOS/EventService.swift b/NavigationForiOS/EventService.swift index f661f21..9cf3af8 100644 --- a/NavigationForiOS/EventService.swift +++ b/NavigationForiOS/EventService.swift @@ -17,18 +17,18 @@ enum ResponseStatus{ } class EventService { - /// イベントの名前を取得 + /// イベントの名前とidを取得 /// /// - Returns: イベントを含む配列 func getEvents(responseEvents: @escaping ([String]) -> Void){ - Alamofire.request("https://gist.githubusercontent.com/ferretdayo/b5743089f2d5f5468cca58ed9cf96b81/raw/2a6b2ca3937a61ab5b3a01ee30ecddb28103e41b/eventList.json") + Alamofire.request("\(Const().URL_API)/events") .responseJSON { response in var events: [String] = [] switch response.result { case .success(let response): let eventJson = JSON(response) - eventJson["events"].forEach{(_, data) in - events.append(data.string!) + eventJson["data"].forEach{(_, data) in + events.append(data["name"].string!) } break case .failure(let error): @@ -44,8 +44,9 @@ class EventService { /// /// - Parameter responseEvents: イベント情報 func searchEvents(eventIdInputFormText: String, responseEvents: @escaping (EventEntity?, ResponseStatus) -> Void){ - Alamofire.request("\(Const().URL_API)/events/\(eventIdInputFormText)") - .responseJSON { response in +// Alamofire.request("\(Const().URL_API)/events/\(eventIdInputFormText)") + Alamofire.request("\(Const().URL_API)/events/bcvph") + .responseJSON { response in var events: EventEntity? = nil var responseStatus: ResponseStatus = ResponseStatus.Success switch response.result { @@ -57,13 +58,13 @@ class EventService { break; } let data = eventJson["data"] - if data["id"].string != eventIdInputFormText { + if data["name"].string != eventIdInputFormText { responseStatus = ResponseStatus.DontMatchEventId } else { let formatter = DateFormatter() formatter.timeZone = NSTimeZone(name: "GMT")! as TimeZone! formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - events = EventEntity(id: data["id"].string!, name: data["name"].string!, info: data["description"].string!, startDate: formatter.string(from: Date(timeIntervalSince1970: TimeInterval(data["startDate"].int!)/1000)), endDate: formatter.string(from: Date(timeIntervalSince1970: TimeInterval(data["endDate"].int!)/1000)), location: data["location"].string!) + events = EventEntity(id: data["id"].string!, name: data["name"].string!, description: data["description"].string!, startDate: formatter.string(from: Date(timeIntervalSince1970: TimeInterval(data["startDate"].int!)/1000)), endDate: formatter.string(from: Date(timeIntervalSince1970: TimeInterval(data["endDate"].int!)/1000)), location: data["location"].string!) responseStatus = ResponseStatus.Success } break diff --git a/NavigationForiOS/HomeViewController.swift b/NavigationForiOS/HomeViewController.swift index 021c804..f3bf1c3 100644 --- a/NavigationForiOS/HomeViewController.swift +++ b/NavigationForiOS/HomeViewController.swift @@ -7,103 +7,91 @@ // import UIKit +import Eureka -class HomeViewController: UIViewController, UITextFieldDelegate/*, UITableViewDelegate, UITableViewDataSource*/ { - -// @IBOutlet weak var tableView: UITableView! - @IBOutlet weak var eventIdInputForm: UITextField! - - @IBOutlet weak var errorLabel: UILabel! - +class HomeViewController: FormViewController { var events: [String] = [] - var searchedEvent: EventEntity? = nil - - // DI + var event: String = "" var eventService: EventService? - + override func viewDidLoad() { super.viewDidLoad() - self.errorLabel.text = "" -// eventService?.getEvents{ response in -// self.events = response -// self.tableView.reloadData() -// } - self.eventIdInputForm.delegate = self - } + + // API的に対象のイベントを取得し,Formの選択データにセット + eventService?.getEvents{ responseEvents in + self.events = responseEvents + + if let EventRow = self.form.rowBy(tag: "SourceEvents") { + EventRow.updateCell() + } + } + + form + +++ Section() + <<< PushRow("SourceEvents"){ + $0.title = "イベントを選択" + $0.selectorTitle = "イベント" + $0.options = self.events + $0.onChange{[unowned self] row in + self.event = row.value ?? self.events[0] + } + }.cellUpdate { cell, row in + row.options = self.events + } - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() + // Button + +++ Section() + <<< ButtonRow(){ + $0.title = "イベントの表示" + $0.onCellSelection{ [unowned self] cell, row in + if self.isSuccessLocationInput(event: self.event) { + self.eventService?.searchEvents(eventIdInputFormText: self.event, responseEvents: { (searchedEvent, responseStatus) in + let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate + if searchedEvent != nil { + appDelegate.eventInfo = searchedEvent + let vc = self.storyboard!.instantiateViewController(withIdentifier: "EventInfoStoryboard") + let navigationController = UINavigationController(rootViewController: vc) + self.present(navigationController, animated: true, completion: nil) + } + }) + } + } + } } - func textFieldShouldReturn(_ eventIdInputForm: UITextField) -> Bool { - // キーボードを閉じる - eventIdInputForm.resignFirstResponder() - return true + /// 入力された場所が正しい入力かどうかの判定を行う関数 + /// + /// - Parameters: + /// - event: 選択したイベント + /// - Returns: 入力が正しければtrue,正しくなければfalse + func isSuccessLocationInput(event: String) -> Bool { + var success: Bool = true + if event == "" { + self.makeAlert(title: "エラー", message: "イベントを選択してください") + success = false + } + return success } - @IBAction func searchEvent(_ sender: Any) { - if !self.eventIdInputForm.hasText { - self.errorLabel.text = "イベントIDを入力してください" - return - } + /// アラートを作る関数 + /// + /// - Parameters: + /// - title: アラートのタイトル + /// - message: アラートのメッセージ + func makeAlert(title: String, message: String) -> Void { + // アラートを作成 + let alert = UIAlertController( + title: title, + message: message, + preferredStyle: .alert) - // リクエストして,対象のイベントIDが存在するかのチェック - eventService?.searchEvents( eventIdInputFormText: self.eventIdInputForm.text!, responseEvents: { (searchedEvent, responseStatus) in - - if responseStatus == ResponseStatus.DontMatchEventId { - self.errorLabel.text = "内部的なエラー" - } else if responseStatus == ResponseStatus.NotFound { - self.errorLabel.text = "指定されたのイベントは存在しません" - } else if responseStatus == ResponseStatus.Success { - let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate - self.searchedEvent = searchedEvent - if self.searchedEvent != nil { - // おk - self.errorLabel.text = "" - - let alert = UIAlertController(title:"イベント確認", message: (self.searchedEvent?.name)! + " でよろしいですか?", preferredStyle: UIAlertControllerStyle.actionSheet) - - let ok = UIAlertAction(title: "YES", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in - - appDelegate.eventInfo = self.searchedEvent - - let next = self.storyboard!.instantiateViewController(withIdentifier: "EventViewStoryboard") - self.present(next,animated: true, completion: nil) - }) - - let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: { (action: UIAlertAction!) in - self.errorLabel.text = "" - }) - - alert.addAction(ok) - alert.addAction(cancel) - self.present(alert, animated: true, completion: nil) - } - } - }) + // アラートにボタンをつける + alert.addAction(UIAlertAction(title: "OK", style: .default)) + + // アラート表示 + self.present(alert, animated: true, completion: nil) } - -// /// セルの個数を指定するデリゲートメソッド(必須) -// func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { -// return self.events.count -// } -// -// // セクションヘッダーの高さ -// public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { -// return 50 -// } -// -// /// セルに値を設定するデータソースメソッド(必須) -// func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { -// -// // セルを取得する -// let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "LocationCell", for: indexPath as IndexPath) -// -// // セルに表示する値を設定する -// cell.textLabel!.text = self.events[indexPath.row] -// -// return cell -// } + } diff --git a/NavigationForiOS/RouteViewController.swift b/NavigationForiOS/RouteViewController.swift index 1df0b02..35151cf 100644 --- a/NavigationForiOS/RouteViewController.swift +++ b/NavigationForiOS/RouteViewController.swift @@ -32,10 +32,10 @@ class RouteViewController: FormViewController { } form - +++ Section("Source") + +++ Section() <<< PushRow("SourceLocations"){ - $0.title = "現在地" - $0.selectorTitle = "現在地の選択" + $0.title = "現在地を選択" + $0.selectorTitle = "現在地" $0.options = self.point $0.onChange{[unowned self] row in self.departure = row.value ?? self.point[0] @@ -43,24 +43,21 @@ class RouteViewController: FormViewController { }.cellUpdate { cell, row in row.options = self.point } - - - +++ Section("Destination") <<< PushRow("DestinationLocations"){ - $0.title = "目的地" - $0.selectorTitle = "目的地の選択" + $0.title = "目的地を選択" + $0.selectorTitle = "目的地" $0.options = self.point $0.onChange{[unowned self] row in self.destination = row.value ?? self.point[0] } - }.cellUpdate { cell, row in - row.options = self.point + }.cellUpdate { cell, row in + row.options = self.point } - + // Button +++ Section() <<< ButtonRow(){ - $0.title = "Start Navigation" + $0.title = "ナビゲーションの開始" $0.onCellSelection{ [unowned self] cell, row in if self.isSuccessLocationInput(source: self.departure, destination: self.destination) { //次のビュー(NavigationViewController)用に目的地の値を保持する @@ -87,10 +84,10 @@ class RouteViewController: FormViewController { func isSuccessLocationInput(source: String, destination: String) -> Bool { var success: Bool = true if source == "" || destination == "" { - self.makeAlert(title: "Error", message: "現在地または目的地に場所を入れてください") + self.makeAlert(title: "エラー", message: "現在地または目的地に場所を入れてください") success = false } else if source == destination { - self.makeAlert(title: "Error", message: "現在地と目的地は異なる場所を入れてください") + self.makeAlert(title: "エラー", message: "現在地と目的地は異なる場所を入れてください") success = false } return success diff --git a/NavigationForiOS/SwinjectStoryboard.swift b/NavigationForiOS/SwinjectStoryboard.swift index 1fa4450..bb31e12 100644 --- a/NavigationForiOS/SwinjectStoryboard.swift +++ b/NavigationForiOS/SwinjectStoryboard.swift @@ -42,9 +42,12 @@ extension SwinjectStoryboard { } // HomeViewControllerのDIの設定 - container.storyboardInitCompleted(HomeViewController.self) { (r, vc) in +// container.storyboardInitCompleted(HomeViewController.self) { (r, vc) in +// vc.eventService = r.resolve(EventService.self)! +// } +// + defaultContainer.storyboardInitCompleted(HomeViewController.self) { (r, vc) in vc.eventService = r.resolve(EventService.self)! } - } }