Commit 77bcef1e by Olzhas Aldabergenov

chat bot open knowledge and service links as respective view controllers

parent a3dbd190
......@@ -41,38 +41,6 @@
shouldBeEnabled = "No"
ignoreCount = "0"
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"
timestampString = "528032989.334432"
startingColumnNumber = "9223372036854775807"
......@@ -182,16 +150,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/Service/ServiceItemScrollViewController.swift"
timestampString = "530767730.950769"
filePath = "kt/ViewControllers/FastPay/UIFastPayViewController.swift"
timestampString = "530168698.751804"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "287"
endingLineNumber = "287"
landmarkName = "prepareForSegue(segue:sender:)"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "createCellsData()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
......@@ -201,13 +169,29 @@
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/FastPay/UIFastPayViewController.swift"
timestampString = "530168698.751804"
filePath = "kt/ViewControllers/BotLeftMessageCell.swift"
timestampString = "531209142.403686"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "createCellsData()"
startingLineNumber = "67"
endingLineNumber = "67"
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">
</BreakpointContent>
</BreakpointProxy>
......
......@@ -30,6 +30,8 @@ extension Facade {
botNode.text = n["text"].string
botNode.expanded = n["expanded"].int
botNode.isLink = n["isLink"].int
botNode.entityId = n["entity_id"].string
botNode.type = n["type"].string
botNodes.append(botNode)
}
let res = BotResult()
......
......@@ -55,7 +55,7 @@ class BotManager {
return nil
}
func saveStoreFastPay(botResults : [BotResult]) {
func saveBotResults(botResults : [BotResult]) {
let archivedItems = archiveAll(botResults)
NSUserDefaults.standardUserDefaults().setObject(archivedItems, forKey: UserDefaultsBotResultsKey + UserManager.sharedInstance().login!)
NSUserDefaults.standardUserDefaults().synchronize()
......@@ -67,7 +67,11 @@ class BotManager {
items = []
}
items!.append(botResult)
saveStoreFastPay(items!)
saveBotResults(items!)
}
func addAll(items: [BotResult]) {
saveBotResults(items)
}
}
......@@ -17,6 +17,8 @@ class BotNode: NSObject, NSCoding {
var text : String?
var expanded : Int?
var isLink : Int?
var entityId : String?
var type : String?
override init() {
super.init()
......@@ -30,6 +32,12 @@ class BotNode: NSObject, NSCoding {
text = aDecoder.decodeObjectForKey("text") as! String?
expanded = aDecoder.decodeObjectForKey("expanded") 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) {
......@@ -40,6 +48,8 @@ class BotNode: NSObject, NSCoding {
aCoder.encodeObject(text, forKey: "text")
aCoder.encodeObject(expanded, forKey: "expanded")
aCoder.encodeObject(isLink, forKey: "isLink")
aCoder.encodeObject(entityId, forKey: "entityId")
aCoder.encodeObject(type, forKey: "type")
}
}
......@@ -621,4 +621,5 @@
"registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
......@@ -620,4 +620,5 @@
"registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
......@@ -623,4 +623,4 @@
"registration_placeholder_login" = "Придумайте Ваш логин";
"registration_placeholder_password" = "Придумайте Ваш пароль";
"help" = "Помощь";
......@@ -8,7 +8,7 @@
import UIKit
class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate {
class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate, UITextViewDelegate {
@IBOutlet weak var container: UIView!
@IBOutlet weak var stackView: UIStackView!
......@@ -43,7 +43,7 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
self.showAbonentForm(UITapGestureRecognizer())
}
} else {
let label = UITextView(frame: CGRectMake(0, 0, 0, 0))
let label = BotNodeUITextView(frame: CGRectMake(0, 0, 0, 0))
label.textAlignment = NSTextAlignment.Left
let attrStr = try! NSAttributedString(data: text.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
label.attributedText = attrStr
......@@ -59,7 +59,13 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
label.textColor = Color.ButtonBlueDefaultColor
}
label.tag = Int(id)!
label.botNode = node
label.delegate = self
self.stackView.addArrangedSubview(label)
if id == "27" {
print(text)
}
}
}
}
......@@ -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) {
if typeForm == 0 {
if let phoneText = phoneTextField.text {
......@@ -220,4 +247,10 @@ class BotLeftMessageCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewD
textField.resignFirstResponder()
return true
}
}
class BotNodeUITextView : UITextView, UITextViewDelegate {
var botNode : BotNode?
}
......@@ -126,20 +126,21 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
}
func addMessage(botResult: BotResult) {
self.tableView.beginUpdates()
self.messagesList.append(botResult)
let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
self.tableView.endUpdates()
// self.tableView.beginUpdates()
// self.messagesList.append(botResult)
// let indexPath = NSIndexPath(forRow: (self.messagesList.count - 1), inSection: 0)
// self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
// self.tableView.endUpdates()
self.messagesList.append(botResult)
self.tableView.reloadData()
self.tableView.scrollToBottom(true)
self.persist(botResult)
self.persist()
}
func persist(botResult: BotResult) {
BotManager.sharedInstance().add(botResult)
func persist() {
BotManager.sharedInstance().addAll(self.messagesList)
}
func reloadTable() {
......@@ -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) {
Facade.sharedInstance().childBot(String(id), onSuccess: { (botResult) in
if botResult.count != 0 {
......@@ -200,7 +232,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = self.heightAtIndexPath.objectForKey(indexPath)
let height = self.heightAtIndexPath.objectForKey(indexPath.row)
if ((height) != nil) {
return CGFloat(height!.floatValue)
} else {
......@@ -210,7 +242,7 @@ class BotViewController: UIViewController, UITableViewDataSource, UITableViewDel
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
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