Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AllgemeinViewController.swift
- // PCMobile
- //
- // Created by SITF Pr on 7/3/18.
- // Copyright © 2018 SITF Pr. All rights reserved.
- //
- import UIKit
- import Eureka
- import Alamofire
- import SwiftyJSON
- class AllgemeinViewController: FormViewController {
- var bukrsString = "110"
- var btnBUKRS:UIButton = UIButton(type: UIButtonType.infoLight)
- var btnPRCTR:UIButton = UIButton(type: UIButtonType.infoLight)
- var currentCell: UITableViewCell!
- var fieldType:PCOFieldType!
- let localTablesURL = "http://212.4.68.34:50002/sitf/values/?url=http://sitfsed.sitf.local:8000/mobile/pco/loctables"
- var prctrArray:[PRCTR] = [PRCTR]()
- var bukrsArray:[BUKRS] = [BUKRS]()
- override func viewDidLoad() {
- super.viewDidLoad()
- login(withUsername: "SHAXHIJA", andPassword: "sitfsw1ss")
- form +++ Section("PROJEKT COCKPIT - PROJEKTDATEN BEARBEITEN")
- <<< TextRow() {
- $0.title = "Projekt ID"
- $0.tag = "txtProjectID"
- $0.placeholder = "SITF-Projekt Einz"
- var ruleSet = RuleSet<String>()
- ruleSet.add(rule: RuleRequired())
- $0.add(ruleSet: ruleSet)
- $0.validationOptions = .validatesOnChangeAfterBlurred
- }
- <<< TextRow() {
- $0.title = "Projektbescheibung"
- }
- <<< TextAreaRow() {
- $0.placeholder = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Fusce diapibus,tellus ac cursus commodo,tortor mauris condimentum"
- var ruleSet = RuleSet<String>()
- ruleSet.add(rule: RuleRequired())
- $0.add(ruleSet: ruleSet)
- $0.validationOptions = .validatesOnChangeAfterBlurred
- $0.tag = "notes"
- }
- <<< TextRow() {
- $0.title = "PSP-Element"
- $0.placeholder = "2839599"
- $0.tag = "txtPSPElement"
- $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
- var ruleSet = RuleSet<String>()
- ruleSet.add(rule: RuleRequired())
- $0.add(ruleSet: ruleSet)
- $0.validationOptions = .validatesOnChangeAfterBlurred
- }
- <<< TextRow() {
- $0.title = "Statusnr. Projekt"
- $0.placeholder = "00095948333"
- $0.tag = "txtStatusNr"
- $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
- }
- +++ Section(){ section in
- section.footer =
- {
- var footer = HeaderFooterView<UIView>(.callback({
- let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
- let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
- label.text = "Giancarlo Bernardini"
- label.font = label.font.withSize(14)
- label.textColor = .gray
- label.textAlignment = .right
- view.addSubview(label)
- return view
- }))
- footer.height = { 45 }
- return footer
- }()
- section.header = HeaderFooterView(title: "")
- }
- <<< TextRow() {
- $0.title = "Verantwortlich Nr"
- $0.placeholder = "343882"
- $0.tag = "txtResponsibleNr"
- $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
- }
- +++ Section(){ section in
- section.footer =
- {
- var footer = HeaderFooterView<UIView>(.callback({
- let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
- let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
- label.text = "Guisepe Panati"
- label.font = label.font.withSize(14)
- label.textColor = .gray
- label.textAlignment = .right
- view.addSubview(label)
- return view
- }))
- footer.height = { 55 }
- return footer
- }()
- section.header = HeaderFooterView(title: "")
- }
- <<< TextRow() {
- $0.title = "Kalkulator Nr"
- $0.placeholder = "767584"
- $0.tag = "txtCalculatorNr"
- // let btnSearch = UIButton(type: UIButtonType.infoLight)
- $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
- }
- +++ Section("PROJEKT ADRESSE")
- <<< TextRow() {
- $0.title = "Strasse"
- }
- <<< TextAreaRow("notes2") {
- $0.placeholder = "Lorzenparkstrasse 9"
- $0.tag = "txtStrasse"
- $0.textAreaHeight = .dynamic(initialTextViewHeight: 25)
- }
- <<< TextRow() {
- $0.title = "Postleitzahl"
- $0.placeholder = "8700"
- $0.tag = "txtPLZ"
- }
- <<< TextRow() {
- $0.title = "Ort"
- $0.placeholder = "Cham"
- $0.tag = "txtOrt"
- }
- <<< TextRow() {
- $0.title = "Land"
- $0.placeholder = "Switzerland"
- $0.tag = "txtLand"
- }
- <<< TextRow() {
- $0.title = "Region"
- $0.placeholder = "Zug"
- $0.tag = "txtRegion"
- }
- +++ Section(){ section in
- section.footer =
- {
- var footer = HeaderFooterView<UIView>(.callback({
- let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
- let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
- label.text = "swiss IT-Factory CH AG"
- label.font = label.font.withSize(14)
- label.textColor = .gray
- label.textAlignment = .right
- view.addSubview(label)
- // view.backgroundColor = .red
- return view
- }))
- footer.height = { 40 }
- return footer
- }()
- section.header = HeaderFooterView(title: "ORGANISATION")
- }
- <<< LabelRow ("bukrsRow") {
- LabelRow.defaultCellUpdate = { cell, row in cell.detailTextLabel?.textColor = .lightGray }
- currentCell = $0.cell
- $0.title = "Buchungskreiss"
- $0.value = bukrsString
- $0.cell.accessoryView = btnBUKRS
- btnBUKRS.addTarget(self, action: #selector(bukrsPressed), for: .touchUpInside)
- }
- +++ Section() { section in
- section.footer =
- {
- var footer = HeaderFooterView<UIView>(.callback({
- let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
- let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
- label.text = "IBU ST.Gallen"
- label.font = label.font.withSize(14)
- label.textColor = .gray
- label.textAlignment = .right
- view.addSubview(label)
- return view
- }))
- footer.height = { 70 }
- return footer
- }()
- section.header = HeaderFooterView(title: "")
- }
- <<< LabelRow ("prctrRow") {
- LabelRow.defaultCellUpdate = { cell, row in cell.detailTextLabel?.textColor = .lightGray }
- $0.title = "Profitcenter"
- $0.value = "1020"
- $0.cell.accessoryView = btnPRCTR
- btnPRCTR.addTarget(self, action: #selector(profitCenterPressed), for: .touchUpInside)
- }
- }
- @objc func bukrsPressed() {
- fieldType = .bukrs
- self.performSegue(withIdentifier: "segue", sender: nil)
- }
- @objc func profitCenterPressed() {
- fieldType = .prctr
- self.performSegue(withIdentifier: "segue", sender: nil)
- //printoma vleren qe e ka bukrs-ja ne cell print(vleraBUKRS)
- //
- // let textRow: TextAreaRow? = form.rowBy(tag: "notes")
- // let value = textRow?.value
- // print(value!)
- // fieldType = .prctr
- // self.performSegue(withIdentifier: "segue", sender: nil)
- }
- //MARK: Login
- func login(withUsername username: String, andPassword password: String) {
- // startLoading()
- let credentials: String! = "Basic \("\(username):\(password)".data(using: String.Encoding.utf8)?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0)) ?? "")"
- //basic parameteres
- // let params = [
- // "email": username,
- // "password": password
- // ] as [String: Any]
- //prepare for sending in SAP
- // let project:PRCTR = PRCTR(object: Any.self)
- // project.pRCTR = "Gzim"
- // project.kTEXT = "21.02.2018"
- // project.kOKRS = "42"
- //
- // convert it to dictionary to be able to send in parameters (ALAMOFIRE)
- // let dictionary = project.dictionaryRepresentation()
- //Base64 Authorization Header
- let loginHeaders = [
- "Authorization": "\(credentials!)"
- ]
- Alamofire.request(localTablesURL, method: .get, parameters: [:], headers: loginHeaders).responseJSON { response in
- if response.response?.statusCode == 200 {
- do {
- let json = try JSON(data: response.data!) //SwiftJSON
- let localTablesBase = LOCALTABLESBase(json: json)
- // let localTables = localTablesBase.lOCALTABLES
- if let arrayPRCTR = localTablesBase.lOCALTABLES?.pRCTR {
- self.prctrArray = arrayPRCTR
- }
- if let arrayBUKRS = localTablesBase.lOCALTABLES?.bUKRS {
- self.bukrsArray = arrayBUKRS
- }
- //here you reload table, stop loading or whatever you want to do with the data after received them
- self.tableView.reloadData()
- //stopLoading
- } catch {
- print("diqka nuk o n'rregëll")
- }
- } else {
- print("error with code \(response.response?.statusCode ?? 0)")
- }
- }
- }
- //MARK: - Prepare For Segue
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if segue.identifier == "segue" {
- let vc:AllgemeinTblViewController = segue.destination as! AllgemeinTblViewController
- vc.delegate = self
- vc.fieldType = fieldType
- vc.prctrArray = prctrArray
- vc.bukrsArray = bukrsArray
- }
- }
- }
- //MARK: - Allgemein Table Delegate
- extension AllgemeinViewController: AllgemeinTableDelegate {
- func getValue(value: String,description: String, forType type: PCOFieldType) {
- if type == .bukrs {
- if let myRow: LabelRow = form.rowBy(tag: "bukrsRow") {
- myRow.value = value
- myRow.reload()
- }
- } else if type == .prctr {
- if let myRow: LabelRow = form.rowBy(tag: "prctrRow") {
- myRow.value = value.removeLeadingZeros()
- myRow.reload()
- }
- } else {
- //status nr
- }
- }
- }
- extension String {
- func removeLeadingZeros() -> String {
- var newString = self
- let prefix = "0"
- while newString.hasPrefix(prefix) {
- newString.remove(at: newString.startIndex)
- }
- return newString
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement