diff --git a/OTRS-Watch.xcodeproj/project.xcworkspace/xcuserdata/linnemann.xcuserdatad/UserInterfaceState.xcuserstate b/OTRS-Watch.xcodeproj/project.xcworkspace/xcuserdata/linnemann.xcuserdatad/UserInterfaceState.xcuserstate
index 2374a5b..d515c7f 100644
Binary files a/OTRS-Watch.xcodeproj/project.xcworkspace/xcuserdata/linnemann.xcuserdatad/UserInterfaceState.xcuserstate and b/OTRS-Watch.xcodeproj/project.xcworkspace/xcuserdata/linnemann.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/OTRS-Watch.xcodeproj/xcuserdata/linnemann.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/OTRS-Watch.xcodeproj/xcuserdata/linnemann.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index 364a590..bf8fb5d 100644
--- a/OTRS-Watch.xcodeproj/xcuserdata/linnemann.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/OTRS-Watch.xcodeproj/xcuserdata/linnemann.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -10,12 +10,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
- timestampString = "503411749.778027"
+ timestampString = "503498994.361076"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "48"
- endingLineNumber = "48"
- landmarkName = "get(forQue:)"
+ startingLineNumber = "58"
+ endingLineNumber = "58"
+ landmarkName = "reload(que:)"
landmarkType = "7">
@@ -26,12 +26,76 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
- timestampString = "503411749.778027"
+ timestampString = "503498994.361076"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "56"
- endingLineNumber = "56"
- landmarkName = "get(forQue:)"
+ startingLineNumber = "66"
+ endingLineNumber = "66"
+ landmarkName = "reload(que:)"
+ landmarkType = "7">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OTRS-Watch/AppDelegate.swift b/OTRS-Watch/AppDelegate.swift
index c0cb309..3281e6d 100644
--- a/OTRS-Watch/AppDelegate.swift
+++ b/OTRS-Watch/AppDelegate.swift
@@ -11,16 +11,26 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
-
-
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
+
+ OTRS.sharedInstance.configure(username_: UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.CREDENTIALS.USER)!, password_: UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.CREDENTIALS.PASSWORD)!)
+
+ getTicketsFromOTRS()
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
-
+
+ // MARK: OTRS
+
+ private func getTicketsFromOTRS() {
+
+ if let que:Int = Int(UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE)!) {
+ OTRS.sharedInstance.reload(que: que)
+ }
+ }
}
diff --git a/OTRS-Watch/Base.lproj/Main.storyboard b/OTRS-Watch/Base.lproj/Main.storyboard
index e4840e4..948fdae 100644
--- a/OTRS-Watch/Base.lproj/Main.storyboard
+++ b/OTRS-Watch/Base.lproj/Main.storyboard
@@ -1,8 +1,8 @@
-
+
-
+
@@ -795,7 +795,7 @@
-
+
diff --git a/OTRS-Watch/Extension/ViewControllerExtension.swift b/OTRS-Watch/Extension/ViewControllerExtension.swift
index 6ead55f..4b33aea 100644
--- a/OTRS-Watch/Extension/ViewControllerExtension.swift
+++ b/OTRS-Watch/Extension/ViewControllerExtension.swift
@@ -16,7 +16,7 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
}
func numberOfRows(in tableView: NSTableView) -> Int {
- return self.ticketDictionary.count
+ return OTRS.sharedInstance.ticketDictionary.count
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
@@ -25,20 +25,18 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
var text: String = ""
var cellIdentifier: String = ""
- print("row: \(row)")
-
- guard let item = ticketDictionary.first else {
+ guard let item:Ticket = OTRS.sharedInstance.ticketDictionary[row] else {
return nil
}
if tableColumn == self.ticketTableView.tableColumns[0] {
cellIdentifier = CellIdentifiers.OTRSTicketNumber
image = nil
- text = item.value.ticketNumber
+ text = item.ticketNumber
} else if tableColumn == self.ticketTableView.tableColumns[1] {
cellIdentifier = CellIdentifiers.OTRSTicketDetails
image = nil
- text = item.value.title
+ text = item.title
}
if let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
diff --git a/OTRS-Watch/OTRS.swift b/OTRS-Watch/OTRS.swift
index 552095b..bede9d2 100644
--- a/OTRS-Watch/OTRS.swift
+++ b/OTRS-Watch/OTRS.swift
@@ -10,15 +10,23 @@ import Foundation
class OTRS {
- var url : String;
- var username : String;
- var password : String;
+ class var sharedInstance: OTRS {
+ struct Singleton {
+ static let instance = OTRS()
+ }
+
+ return Singleton.instance
+ }
+
+ var username : String = "";
+ var password : String = "";
+
+ var ticketDictionary: Array = []
//MARK: init
- init(url_:String, username_:String, password_:String) {
- self.url = url_
+ func configure(username_:String, password_:String) {
self.username = username_
self.password = password_
}
@@ -26,11 +34,11 @@ class OTRS {
//MARK: REST
- func get(forQue:Int) {
+ func reload(que:Int) {
let config = URLSessionConfiguration.default // Session configuration
let session = URLSession(configuration: config) // Load configuration into session
- let url = URL(string: buildURLForGettingNew(queID: forQue))
+ let url = URL(string: buildURLForGettingNew(queID: que))
let task = session.dataTask(with: url!, completionHandler: {
(data, response, error) in
@@ -38,6 +46,8 @@ class OTRS {
if error != nil {
print(error!.localizedDescription)
} else {
+ self.ticketDictionary.removeAll()
+
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
// work with json ...
@@ -47,7 +57,7 @@ class OTRS {
for object in json {
let ticketIDs = object.value as! Array
- //print(ticketIDs)
+ print(ticketIDs)
for ticketID in ticketIDs {
if let tID:Int = Int(ticketID) {
@@ -91,6 +101,8 @@ class OTRS {
object: nil,
userInfo: ["message":ticket.id, "ticket":ticket])
+ self.ticketDictionary.append(ticket)
+
} catch SerializationError.missing(let marker) {
print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"")
} catch {
diff --git a/OTRS-Watch/ViewController.swift b/OTRS-Watch/ViewController.swift
index f75de83..98523ca 100644
--- a/OTRS-Watch/ViewController.swift
+++ b/OTRS-Watch/ViewController.swift
@@ -15,8 +15,6 @@ class ViewController: NSViewController {
@IBOutlet weak var txtQueue: NSTextField!
@IBOutlet weak var ticketTableView: NSTableView!
- var ticketDictionary: Dictionary = [:]
-
override func viewDidLoad() {
super.viewDidLoad()
@@ -44,9 +42,6 @@ class ViewController: NSViewController {
nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
object:nil, queue:nil,
using:catchTicketsUpdated)
-
-
- reload()
}
override var representedObject: Any? {
@@ -55,36 +50,29 @@ class ViewController: NSViewController {
}
}
+
+ // MARK: Actions
+
@IBAction func saveSettingsAction(_ sender: NSButton) {
UserDefaults.standard.setValue(txtUsername.stringValue, forKey: Constants.USER_SETTINGS.CREDENTIALS.USER)
UserDefaults.standard.setValue(txtPassword.stringValue, forKey: Constants.USER_SETTINGS.CREDENTIALS.PASSWORD)
UserDefaults.standard.setValue(txtQueue.stringValue, forKey: Constants.USER_SETTINGS.OTRS.QUEUE)
-
- reload()
}
- private func reload() {
- let otrs = OTRS(url_: "", username_: txtUsername.stringValue, password_: txtPassword.stringValue)
- if let que:Int = Int(txtQueue.stringValue) {
- otrs.get(forQue: que)
- }
- }
// MARK: Notification
func catchNewIncomingTicket(notification:Notification) -> Void {
guard let userInfo = notification.userInfo,
- let message:String = userInfo["message"] as? String,
- let ticket:Ticket = userInfo["ticket"] as? Ticket else {
+ let _:String = userInfo["message"] as? String,
+ let _:Ticket = userInfo["ticket"] as? Ticket else {
return
}
- self.ticketDictionary.updateValue(ticket, forKey: message)
-
- reload()
+ self.ticketTableView.reloadData()
}
func catchTicketsUpdated(notification:Notification) -> Void {