Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
Expand Down
4 changes: 1 addition & 3 deletions NavigationForiOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

var eventInfo: EventEntity?

//RouteViewControllerでdestinationの値を保持するために利用する
var destination: String?
var departure: String?
Expand Down Expand Up @@ -46,6 +45,5 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

292 changes: 80 additions & 212 deletions NavigationForiOS/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion NavigationForiOS/Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
6 changes: 3 additions & 3 deletions NavigationForiOS/EventEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 52 additions & 22 deletions NavigationForiOS/EventInfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

17 changes: 9 additions & 8 deletions NavigationForiOS/EventService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 {
Expand All @@ -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
Expand Down
158 changes: 73 additions & 85 deletions NavigationForiOS/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>("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
// }

}

Loading