OTRS Singleton
This commit is contained in:
parent
84138a8b49
commit
1adbfd973a
Binary file not shown.
@ -10,12 +10,12 @@
|
|||||||
ignoreCount = "0"
|
ignoreCount = "0"
|
||||||
continueAfterRunningActions = "No"
|
continueAfterRunningActions = "No"
|
||||||
filePath = "OTRS-Watch/OTRS.swift"
|
filePath = "OTRS-Watch/OTRS.swift"
|
||||||
timestampString = "503411749.778027"
|
timestampString = "503498994.361076"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "48"
|
startingLineNumber = "58"
|
||||||
endingLineNumber = "48"
|
endingLineNumber = "58"
|
||||||
landmarkName = "get(forQue:)"
|
landmarkName = "reload(que:)"
|
||||||
landmarkType = "7">
|
landmarkType = "7">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
@ -26,12 +26,76 @@
|
|||||||
ignoreCount = "0"
|
ignoreCount = "0"
|
||||||
continueAfterRunningActions = "No"
|
continueAfterRunningActions = "No"
|
||||||
filePath = "OTRS-Watch/OTRS.swift"
|
filePath = "OTRS-Watch/OTRS.swift"
|
||||||
timestampString = "503411749.778027"
|
timestampString = "503498994.361076"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "56"
|
startingLineNumber = "66"
|
||||||
endingLineNumber = "56"
|
endingLineNumber = "66"
|
||||||
landmarkName = "get(forQue:)"
|
landmarkName = "reload(que:)"
|
||||||
|
landmarkType = "7">
|
||||||
|
</BreakpointContent>
|
||||||
|
</BreakpointProxy>
|
||||||
|
<BreakpointProxy
|
||||||
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
|
<BreakpointContent
|
||||||
|
shouldBeEnabled = "No"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
filePath = "OTRS-Watch/OTRS.swift"
|
||||||
|
timestampString = "503498994.361076"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "43"
|
||||||
|
endingLineNumber = "43"
|
||||||
|
landmarkName = "reload(que:)"
|
||||||
|
landmarkType = "7">
|
||||||
|
<Locations>
|
||||||
|
<Location
|
||||||
|
shouldBeEnabled = "No"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
symbolName = "OTRS_Watch.OTRS.reload (que : Swift.Int) -> ()"
|
||||||
|
moduleName = "OTRS-Watch"
|
||||||
|
usesParentBreakpointCondition = "Yes"
|
||||||
|
urlString = "file:///Users/linnemann/Documents/dev/xcode/OTRS-Watch/OTRS-Watch/OTRS.swift"
|
||||||
|
timestampString = "503498802.79459"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "45"
|
||||||
|
endingLineNumber = "45"
|
||||||
|
offsetFromSymbolStart = "387">
|
||||||
|
</Location>
|
||||||
|
<Location
|
||||||
|
shouldBeEnabled = "No"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
symbolName = "OTRS_Watch.OTRS.(reload (que : Swift.Int) -> ()).(closure #1)"
|
||||||
|
moduleName = "OTRS-Watch"
|
||||||
|
usesParentBreakpointCondition = "Yes"
|
||||||
|
urlString = "file:///Users/linnemann/Documents/dev/xcode/OTRS-Watch/OTRS-Watch/OTRS.swift"
|
||||||
|
timestampString = "503498802.797104"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "48"
|
||||||
|
endingLineNumber = "48"
|
||||||
|
offsetFromSymbolStart = "53">
|
||||||
|
</Location>
|
||||||
|
</Locations>
|
||||||
|
</BreakpointContent>
|
||||||
|
</BreakpointProxy>
|
||||||
|
<BreakpointProxy
|
||||||
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
|
<BreakpointContent
|
||||||
|
shouldBeEnabled = "No"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
filePath = "OTRS-Watch/OTRS.swift"
|
||||||
|
timestampString = "503498201.457531"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "30"
|
||||||
|
endingLineNumber = "30"
|
||||||
|
landmarkName = "configure(username_:password_:)"
|
||||||
landmarkType = "7">
|
landmarkType = "7">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
|
|||||||
@ -11,10 +11,12 @@ import Cocoa
|
|||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
// Insert code here to initialize your application
|
// 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) {
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
@ -22,5 +24,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: OTRS
|
||||||
|
|
||||||
|
private func getTicketsFromOTRS() {
|
||||||
|
|
||||||
|
if let que:Int = Int(UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE)!) {
|
||||||
|
OTRS.sharedInstance.reload(que: que)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="15G1108" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1108" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="macosx"/>
|
<deployment identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
|
||||||
<capability name="box content view" minToolsVersion="7.0"/>
|
<capability name="box content view" minToolsVersion="7.0"/>
|
||||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -795,7 +795,7 @@
|
|||||||
</subviews>
|
</subviews>
|
||||||
</clipView>
|
</clipView>
|
||||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="yAG-0l-MrF">
|
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="yAG-0l-MrF">
|
||||||
<rect key="frame" x="1" y="119" width="223" height="15"/>
|
<rect key="frame" x="1" y="-16" width="0.0" height="16"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
</scroller>
|
</scroller>
|
||||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="0Mc-1B-cqp">
|
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="0Mc-1B-cqp">
|
||||||
|
|||||||
@ -16,7 +16,7 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
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? {
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||||
@ -25,20 +25,18 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
|
|||||||
var text: String = ""
|
var text: String = ""
|
||||||
var cellIdentifier: String = ""
|
var cellIdentifier: String = ""
|
||||||
|
|
||||||
print("row: \(row)")
|
guard let item:Ticket = OTRS.sharedInstance.ticketDictionary[row] else {
|
||||||
|
|
||||||
guard let item = ticketDictionary.first else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if tableColumn == self.ticketTableView.tableColumns[0] {
|
if tableColumn == self.ticketTableView.tableColumns[0] {
|
||||||
cellIdentifier = CellIdentifiers.OTRSTicketNumber
|
cellIdentifier = CellIdentifiers.OTRSTicketNumber
|
||||||
image = nil
|
image = nil
|
||||||
text = item.value.ticketNumber
|
text = item.ticketNumber
|
||||||
} else if tableColumn == self.ticketTableView.tableColumns[1] {
|
} else if tableColumn == self.ticketTableView.tableColumns[1] {
|
||||||
cellIdentifier = CellIdentifiers.OTRSTicketDetails
|
cellIdentifier = CellIdentifiers.OTRSTicketDetails
|
||||||
image = nil
|
image = nil
|
||||||
text = item.value.title
|
text = item.title
|
||||||
}
|
}
|
||||||
|
|
||||||
if let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
|
if let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
|
||||||
|
|||||||
@ -10,15 +10,23 @@ import Foundation
|
|||||||
|
|
||||||
class OTRS {
|
class OTRS {
|
||||||
|
|
||||||
var url : String;
|
class var sharedInstance: OTRS {
|
||||||
var username : String;
|
struct Singleton {
|
||||||
var password : String;
|
static let instance = OTRS()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Singleton.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
var username : String = "";
|
||||||
|
var password : String = "";
|
||||||
|
|
||||||
|
var ticketDictionary: Array<Ticket> = []
|
||||||
|
|
||||||
|
|
||||||
//MARK: init
|
//MARK: init
|
||||||
|
|
||||||
init(url_:String, username_:String, password_:String) {
|
func configure(username_:String, password_:String) {
|
||||||
self.url = url_
|
|
||||||
self.username = username_
|
self.username = username_
|
||||||
self.password = password_
|
self.password = password_
|
||||||
}
|
}
|
||||||
@ -26,11 +34,11 @@ class OTRS {
|
|||||||
|
|
||||||
//MARK: REST
|
//MARK: REST
|
||||||
|
|
||||||
func get(forQue:Int) {
|
func reload(que:Int) {
|
||||||
|
|
||||||
let config = URLSessionConfiguration.default // Session configuration
|
let config = URLSessionConfiguration.default // Session configuration
|
||||||
let session = URLSession(configuration: config) // Load configuration into session
|
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: {
|
let task = session.dataTask(with: url!, completionHandler: {
|
||||||
(data, response, error) in
|
(data, response, error) in
|
||||||
@ -38,6 +46,8 @@ class OTRS {
|
|||||||
if error != nil {
|
if error != nil {
|
||||||
print(error!.localizedDescription)
|
print(error!.localizedDescription)
|
||||||
} else {
|
} else {
|
||||||
|
self.ticketDictionary.removeAll()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
|
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
|
||||||
// work with json ...
|
// work with json ...
|
||||||
@ -47,7 +57,7 @@ class OTRS {
|
|||||||
|
|
||||||
for object in json {
|
for object in json {
|
||||||
let ticketIDs = object.value as! Array<String>
|
let ticketIDs = object.value as! Array<String>
|
||||||
//print(ticketIDs)
|
print(ticketIDs)
|
||||||
|
|
||||||
for ticketID in ticketIDs {
|
for ticketID in ticketIDs {
|
||||||
if let tID:Int = Int(ticketID) {
|
if let tID:Int = Int(ticketID) {
|
||||||
@ -91,6 +101,8 @@ class OTRS {
|
|||||||
object: nil,
|
object: nil,
|
||||||
userInfo: ["message":ticket.id, "ticket":ticket])
|
userInfo: ["message":ticket.id, "ticket":ticket])
|
||||||
|
|
||||||
|
self.ticketDictionary.append(ticket)
|
||||||
|
|
||||||
} catch SerializationError.missing(let marker) {
|
} catch SerializationError.missing(let marker) {
|
||||||
print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"")
|
print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"")
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@ -15,8 +15,6 @@ class ViewController: NSViewController {
|
|||||||
@IBOutlet weak var txtQueue: NSTextField!
|
@IBOutlet weak var txtQueue: NSTextField!
|
||||||
@IBOutlet weak var ticketTableView: NSTableView!
|
@IBOutlet weak var ticketTableView: NSTableView!
|
||||||
|
|
||||||
var ticketDictionary: Dictionary<String, Ticket> = [:]
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
@ -44,9 +42,6 @@ class ViewController: NSViewController {
|
|||||||
nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
|
nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
|
||||||
object:nil, queue:nil,
|
object:nil, queue:nil,
|
||||||
using:catchTicketsUpdated)
|
using:catchTicketsUpdated)
|
||||||
|
|
||||||
|
|
||||||
reload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override var representedObject: Any? {
|
override var representedObject: Any? {
|
||||||
@ -55,36 +50,29 @@ class ViewController: NSViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: Actions
|
||||||
|
|
||||||
@IBAction func saveSettingsAction(_ sender: NSButton) {
|
@IBAction func saveSettingsAction(_ sender: NSButton) {
|
||||||
UserDefaults.standard.setValue(txtUsername.stringValue, forKey: Constants.USER_SETTINGS.CREDENTIALS.USER)
|
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(txtPassword.stringValue, forKey: Constants.USER_SETTINGS.CREDENTIALS.PASSWORD)
|
||||||
|
|
||||||
UserDefaults.standard.setValue(txtQueue.stringValue, forKey: Constants.USER_SETTINGS.OTRS.QUEUE)
|
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
|
// MARK: Notification
|
||||||
|
|
||||||
func catchNewIncomingTicket(notification:Notification) -> Void {
|
func catchNewIncomingTicket(notification:Notification) -> Void {
|
||||||
|
|
||||||
guard let userInfo = notification.userInfo,
|
guard let userInfo = notification.userInfo,
|
||||||
let message:String = userInfo["message"] as? String,
|
let _:String = userInfo["message"] as? String,
|
||||||
let ticket:Ticket = userInfo["ticket"] as? Ticket else {
|
let _:Ticket = userInfo["ticket"] as? Ticket else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ticketDictionary.updateValue(ticket, forKey: message)
|
self.ticketTableView.reloadData()
|
||||||
|
|
||||||
reload()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func catchTicketsUpdated(notification:Notification) -> Void {
|
func catchTicketsUpdated(notification:Notification) -> Void {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user