<commit_before>//
//  EditorViewController.swift
//  pi-chan
//
//  Created by <NAME> on 2016/04/14.
//  Copyright © 2016年 star__hoshi. All rights reserved.
//

import UIKit
import Font_Awesome_Swift
import UITextView_Placeholder
import SVProgressHUD

class EditorViewController: UIViewController {
  var post: Post?
  
  @IBOutlet weak var navigationBar: UINavigationBar!
  @IBOutlet weak var cancelButton: UIButton!
  @IBOutlet weak var sendButton: UIButton!
  @IBOutlet weak var textView: UITextView!
  @IBOutlet weak var textField: UITextField!
  override func viewDidLoad() {
    super.viewDidLoad()
    sendButton.setFAIcon(.FASend, iconSize: 22, forState: .Normal)
    cancelButton.setFAIcon(.FAClose, iconSize: 22, forState: .Normal)
    setStatusBarBackground()
    setTextViewStyle()
    textView.text = post?.bodyMd
    textField.text = post?.fullName
  }
  
  func setTextViewStyle(){
    textView.placeholder = "# Input with Markdown"
    textView.layer.borderWidth = 1
    textView.layer.borderColor = UIColor.grayUITextFieldBorderColor().CGColor
    textView.layer.cornerRadius = 6
  }
  
  func setStatusBarBackground(){
    let statusBarBackground = UIView(frame: CGRectMake(0 , 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(UIApplication.sharedApplication().statusBarFrame)))
    statusBarBackground.backgroundColor = UIColor.esaGreen()
    self.view.addSubview(statusBarBackground)
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }
  
  @IBAction func post(sender: AnyObject) {
    SVProgressHUD.showWithStatus("Loading...")
    Esa(token: KeychainManager.getToken()!, currentTeam: KeychainManager.getTeamName()!).patchPost(post!){ result in<commit_msg>new post when before post is nil<commit_after>//
//  EditorViewController.swift
//  pi-chan
//
//  Created by <NAME> on 2016/04/14.
//  Copyright © 2016年 star__hoshi. All rights reserved.
//

import UIKit
import Font_Awesome_Swift
import UITextView_Placeholder
import SVProgressHUD

class EditorViewController: UIViewController {
  var post: Post?
  var client:Esa!
  
  @IBOutlet weak var navigationBar: UINavigationBar!
  @IBOutlet weak var cancelButton: UIButton!
  @IBOutlet weak var sendButton: UIButton!
  @IBOutlet weak var textView: UITextView!
  @IBOutlet weak var textField: UITextField!
  override func viewDidLoad() {
    super.viewDidLoad()
    sendButton.setFAIcon(.FASend, iconSize: 22, forState: .Normal)
    cancelButton.setFAIcon(.FAClose, iconSize: 22, forState: .Normal)
    setStatusBarBackground()
    setTextViewStyle()
    textView.text = post?.bodyMd
    textField.text = post?.fullName
    client = Esa(token: KeychainManager.getToken()!, currentTeam: KeychainManager.getTeamName()!)
  }
  
  func setTextViewStyle(){
    textView.placeholder = "# Input with Markdown"
    textView.layer.borderWidth = 1
    textView.layer.borderColor = UIColor.grayUITextFieldBorderColor().CGColor
    textView.layer.cornerRadius = 6
  }
  
  func setStatusBarBackground(){
    let statusBarBackground = UIView(frame: CGRectMake(0 , 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(UIApplication.sharedApplication().statusBarFrame)))
    statusBarBackground.backgroundColor = UIColor.esaGreen()
    self.view.addSubview(statusBarBackground)
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }
  
  @IBAction func post(sender: AnyObject) {
    SVProgressHUD.showWithStatus("Loading...")
    if let _ = post{
      patch()
    }else{
      newPost()
    }
  }
  
  func newPost(){
    client.newPost(post!){ result in
      switch result {
      case .Success(let posts):
        SVProgressHUD.showSuccessWithStatus("Success!")
        log?.info("\(posts)")
      case .Failure(let error):
        SVProgressHUD.showErrorWithStatus("Error!")
        log?.error("\(error)")
      }
    }
  }
  
  func patch(){
    client.patchPost(post!){ result in
{'fraction_non_alphanumeric': 0.10620372734235384, 'fraction_numerical': 0.010211896859841715, 'mean_word_length': 3.984732824427481, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5524259', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1217, 'n_words': 260}