Commit 77bcef1e by Olzhas Aldabergenov

chat bot open knowledge and service links as respective view controllers

parent a3dbd190
...@@ -41,38 +41,6 @@ ...@@ -41,38 +41,6 @@
shouldBeEnabled = "No" shouldBeEnabled = "No"
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/BotLeftMessageCell.swift"
timestampString = "522067560.634483"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "bind(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/Cabinet/MainKnowedgeViewController.swift"
timestampString = "527420051.899478"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "47"
endingLineNumber = "47"
landmarkName = "tableView(tableView:cellForRowAtIndexPath:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/Service/CallbackViewController.swift" filePath = "kt/ViewControllers/Service/CallbackViewController.swift"
timestampString = "528032989.334432" timestampString = "528032989.334432"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
...@@ -182,16 +150,16 @@ ...@@ -182,16 +150,16 @@
<BreakpointProxy <BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint"> BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent <BreakpointContent
shouldBeEnabled = "Yes" shouldBeEnabled = "No"
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/Service/ServiceItemScrollViewController.swift" filePath = "kt/ViewControllers/FastPay/UIFastPayViewController.swift"
timestampString = "530767730.950769" timestampString = "530168698.751804"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "287" startingLineNumber = "89"
endingLineNumber = "287" endingLineNumber = "89"
landmarkName = "prepareForSegue(segue:sender:)" landmarkName = "createCellsData()"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
...@@ -201,13 +169,29 @@ ...@@ -201,13 +169,29 @@
shouldBeEnabled = "No" shouldBeEnabled = "No"
ignoreCount = "0" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/FastPay/UIFastPayViewController.swift" filePath = "kt/ViewControllers/BotLeftMessageCell.swift"
timestampString = "530168698.751804" timestampString = "531209142.403686"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "89" startingLineNumber = "67"
endingLineNumber = "89" endingLineNumber = "67"
landmarkName = "createCellsData()" landmarkName = "bind(nodes:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/BotViewController.swift"
timestampString = "531222126.771091"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "190"
endingLineNumber = "190"
landmarkName = "processService(_:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
......
...@@ -30,6 +30,8 @@ extension Facade { ...@@ -30,6 +30,8 @@ extension Facade {
botNode.text = n["text"].string botNode.text = n["text"].string
botNode.expanded = n["expanded"].int botNode.expanded = n["expanded"].int
botNode.isLink = n["isLink"].int botNode.isLink = n["isLink"].int
botNode.entityId = n["entity_id"].string
botNode.type = n["type"].string
botNodes.append(botNode) botNodes.append(botNode)
} }
let res = BotResult() let res = BotResult()
......
...@@ -55,7 +55,7 @@ class BotManager { ...@@ -55,7 +55,7 @@ class BotManager {
return nil return nil
} }
func saveStoreFastPay(botResults : [BotResult]) { func saveBotResults(botResults : [BotResult]) {
let archivedItems = archiveAll(botResults) let archivedItems = archiveAll(botResults)
NSUserDefaults.standardUserDefaults().setObject(archivedItems, forKey: UserDefaultsBotResultsKey + UserManager.sharedInstance().login!) NSUserDefaults.standardUserDefaults().setObject(archivedItems, forKey: UserDefaultsBotResultsKey + UserManager.sharedInstance().login!)
NSUserDefaults.standardUserDefaults().synchronize() NSUserDefaults.standardUserDefaults().synchronize()
...@@ -67,7 +67,11 @@ class BotManager { ...@@ -67,7 +67,11 @@ class BotManager {
items = [] items = []
} }
items!.append(botResult) items!.append(botResult)
saveStoreFastPay(items!) saveBotResults(items!)
}
func addAll(items: [BotResult]) {
saveBotResults(items)
} }
} }
...@@ -17,6 +17,8 @@ class BotNode: NSObject, NSCoding { ...@@ -17,6 +17,8 @@ class BotNode: NSObject, NSCoding {
var text : String? var text : String?
var expanded : Int? var expanded : Int?
var isLink : Int? var isLink : Int?
var entityId : String?
var type : String?
override init() { override init() {
super.init() super.init()
...@@ -30,6 +32,12 @@ class BotNode: NSObject, NSCoding { ...@@ -30,6 +32,12 @@ class BotNode: NSObject, NSCoding {
text = aDecoder.decodeObjectForKey("text") as! String? text = aDecoder.decodeObjectForKey("text") as! String?
expanded = aDecoder.decodeObjectForKey("expanded") as! Int? expanded = aDecoder.decodeObjectForKey("expanded") as! Int?
isLink = aDecoder.decodeObjectForKey("isLink") as! Int? isLink = aDecoder.decodeObjectForKey("isLink") as! Int?
if ( aDecoder.containsValueForKey("entityId") ) {
entityId = aDecoder.decodeObjectForKey("entityId") as! String?
}
if ( aDecoder.containsValueForKey("type") ) {
type = aDecoder.decodeObjectForKey("type") as! String?
}
} }
func encodeWithCoder(aCoder: NSCoder) { func encodeWithCoder(aCoder: NSCoder) {
...@@ -40,6 +48,8 @@ class BotNode: NSObject, NSCoding { ...@@ -40,6 +48,8 @@ class BotNode: NSObject, NSCoding {
aCoder.encodeObject(text, forKey: "text") aCoder.encodeObject(text, forKey: "text")
aCoder.encodeObject(expanded, forKey: "expanded") aCoder.encodeObject(expanded, forKey: "expanded")
aCoder.encodeObject(isLink, forKey: "isLink") aCoder.encodeObject(isLink, forKey: "isLink")
aCoder.encodeObject(entityId, forKey: "entityId")
aCoder.encodeObject(type, forKey: "type")
} }
} }
...@@ -621,4 +621,5 @@ ...@@ -621,4 +621,5 @@
"registration_placeholder_login" = "Придумайте Ваш логин"; "registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль"; "registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
...@@ -620,4 +620,5 @@ ...@@ -620,4 +620,5 @@
"registration_placeholder_login" = "Придумайте Ваш логин"; "registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль"; "registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
...@@ -623,4 +623,4 @@ ...@@ -623,4 +623,4 @@
"registration_placeholder_login" = "Придумайте Ваш логин"; "registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль"; "registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import UIKit import UIKit
class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate { class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate, UITextViewDelegate {
@IBOutlet weak var container: UIView! @IBOutlet weak var container: UIView!
@IBOutlet weak var stackView: UIStackView! @IBOutlet weak var stackView: UIStackView!
...@@ -43,7 +43,7 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD ...@@ -43,7 +43,7 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
self.showAbonentForm(UITapGestureRecognizer()) self.showAbonentForm(UITapGestureRecognizer())
} }
} else { } else {
let label = UITextView(frame: CGRectMake(0, 0, 0, 0)) let label = BotNodeUITextView(frame: CGRectMake(0, 0, 0, 0))
label.textAlignment = NSTextAlignment.Left label.textAlignment = NSTextAlignment.Left
let attrStr = try! NSAttributedString(data: text.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) let attrStr = try! NSAttributedString(data: text.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
label.attributedText = attrStr label.attributedText = attrStr
...@@ -59,7 +59,13 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD ...@@ -59,7 +59,13 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
label.textColor = Color.ButtonBlueDefaultColor label.textColor = Color.ButtonBlueDefaultColor
} }
label.tag = Int(id)! label.tag = Int(id)!
label.botNode = node
label.delegate = self
self.stackView.addArrangedSubview(label) self.stackView.addArrangedSubview(label)
if id == "27" {
print(text)
}
} }
} }
} }
...@@ -169,6 +175,27 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD ...@@ -169,6 +175,27 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
} }
} }
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
if let textLabel = textView as? BotNodeUITextView {
if textLabel.botNode != nil {
if ( textLabel.botNode?.type == "1" ) {
if let pc = parentViewController as? BotViewController {
pc.processKnowledge(textLabel.botNode!)
}
return false
} else if ( textLabel.botNode?.type == "2" ) {
if let pc = parentViewController as? BotViewController {
pc.processService(textLabel.botNode!)
}
return false
}
}
}
return true;
}
func getBalanceButtonTap(sender:UITapGestureRecognizer) { func getBalanceButtonTap(sender:UITapGestureRecognizer) {
if typeForm == 0 { if typeForm == 0 {
if let phoneText = phoneTextField.text { if let phoneText = phoneTextField.text {
...@@ -220,4 +247,10 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD ...@@ -220,4 +247,10 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
textField.resignFirstResponder() textField.resignFirstResponder()
return true return true
} }
}
class BotNodeUITextView : UITextView, UITextViewDelegate {
var botNode : BotNode?
} }
...@@ -126,20 +126,21 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel ...@@ -126,20 +126,21 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
} }
func addMessage(botResult: BotResult) { func addMessage(botResult: BotResult) {
self.tableView.beginUpdates() // self.tableView.beginUpdates()
self.messagesList.append(botResult) // self.messagesList.append(botResult)
// let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0)
let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0) // self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top) // self.tableView.endUpdates()
self.tableView.endUpdates()
self.messagesList.append(botResult)
self.tableView.reloadData()
self.tableView.scrollToBottom(true) self.tableView.scrollToBottom(true)
self.persist(botResult) self.persist()
} }
func persist(botResult: BotResult) { func persist() {
BotManager.sharedInstance().add(botResult) BotManager.sharedInstance().addAll(self.messagesList)
} }
func reloadTable() { func reloadTable() {
...@@ -166,6 +167,37 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel ...@@ -166,6 +167,37 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
} }
} }
func processKnowledge(botNode : BotNode ) {
print(botNode.text)
let vc = self.storyboard!.instantiateViewControllerWithIdentifier("KnowedgeQuestionsViewController") as! KnowedgeQuestionsViewController
vc.id = Int(botNode.entityId!)!
vc.screenName = LS("help")
self.navigationController!.pushViewController(vc, animated: true)
}
func processService(botNode: BotNode) {
let params: [String: AnyObject] = ["service_id": Int(botNode.entityId!)!, "type": "landing" ]
Facade.sharedInstance().getLanding(params, onSuccess: { (serviceItem) in
serviceItem.type = "landing"
let destination = self.storyboard!.instantiateViewControllerWithIdentifier("ServiceItemScrollViewController") as! ServiceItemScrollViewController
destination.serviceItemForLoading = serviceItem
self.navigationController!.pushViewController(destination, animated: true)
}, onError: { (error) in
print(error)
}, onFinish: {
})
// let serviceItem = ServiceItem();
// serviceItem.id = Int(botNode.entityId!)!
// let destination = self.storyboard!.instantiateViewControllerWithIdentifier("ServiceItemScrollViewController") as! ServiceItemScrollViewController
// destination.serviceItemForLoading = serviceItem
// self.navigationController!.pushViewController(destination, animated: true)
}
func getChildNodes(id: Int) { func getChildNodes(id: Int) {
Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in
if botResult.count != 0 { if botResult.count != 0 {
...@@ -200,7 +232,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel ...@@ -200,7 +232,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
} }
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = self.heightAtIndexPath.objectForKey(indexPath) let height = self.heightAtIndexPath.objectForKey(indexPath.row)
if ((height) != nil) { if ((height) != nil) {
return CGFloat(height!.floatValue) return CGFloat(height!.floatValue)
} else { } else {
...@@ -210,7 +242,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel ...@@ -210,7 +242,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let height = cell.frame.size.height let height = cell.frame.size.height
self.heightAtIndexPath.setObject(height, forKey: indexPath) self.heightAtIndexPath.setObject(height, forKey: indexPath.row)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment