Tickets will be shown on startup

This commit is contained in:
Gerrit Linnemann 2016-12-16 10:20:23 +01:00
parent 88163e3e53
commit d89f34ea6b
6 changed files with 39 additions and 17 deletions

View File

@ -26,11 +26,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503499740.022029"
timestampString = "503572546.154236"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "68"
endingLineNumber = "68"
startingLineNumber = "71"
endingLineNumber = "71"
landmarkName = "reload(que:)"
landmarkType = "7">
</BreakpointContent>

View File

@ -81,6 +81,12 @@
ReferencedContainer = "container:OTRS-Watch.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.CoreData.SyntaxColoredLogging YES"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>

View File

@ -52,4 +52,15 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
return nil
}
func tableViewSelectionDidChange(_ notification: Notification) {
updateViewAfterSelectionDidChange()
}
private func updateViewAfterSelectionDidChange() {
let selectedRow = ticketTableView.selectedRow
print(selectedRow)
}
}

View File

@ -18,7 +18,7 @@ class OTRS {
return Singleton.instance
}
var baseURL : String = "";
var baseURL : String = ""; // example base url: http://saeotrs01.sae.intra/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/
var username : String = "";
var password : String = "";
@ -62,17 +62,15 @@ class OTRS {
print(ticketIDs)
for ticketID in ticketIDs {
if let tID:Int = Int(ticketID) {
self.fetch(ticket: tID, session: session)
cnt = cnt+1;
}
}
}
cnt += 1;
let isLast = (cnt == ticketIDs.count)
let nc = NotificationCenter.default
nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
object: nil,
userInfo: ["count":cnt])
if let tID:Int = Int(ticketID) {
self.fetch(ticket: tID, session: session, isLast: isLast)
}
}
}
}
} catch {
print("Error in JSONSerialization")
@ -83,7 +81,7 @@ class OTRS {
task.resume()
}
func fetch(ticket:Int, session:URLSession) {
func fetch(ticket:Int, session:URLSession, isLast:Bool) {
let url = URL(string: buildURLForGettingTicketInfo(ticketID: ticket))
let task = session.dataTask(with: url!, completionHandler: { // see: https://developer.apple.com/swift/blog/?id=37
@ -98,12 +96,19 @@ class OTRS {
let ticket = try Ticket(source: ticketData)
//print(ticket)
self.ticketDictionary.append(ticket)
let nc = NotificationCenter.default
nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.IN),
object: nil,
userInfo: ["message":ticket.id, "ticket":ticket])
self.ticketDictionary.append(ticket)
if isLast {
let nc = NotificationCenter.default
nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
object: nil,
userInfo: ["count":self.ticketDictionary.count])
}
} catch SerializationError.missing(let marker) {
print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"")
@ -128,7 +133,6 @@ class OTRS {
}
private func buildURLForGettingListByState(forState:String, queID:Int) -> String {
// example base url: http://saeotrs01.sae.intra/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/
return self.baseURL.appending("Ticket?UserLogin=\(self.username)&Password=\(self.password)&QueueIDs=\(queID)&States=\(forState)")
}

View File

@ -78,12 +78,13 @@ class ViewController: NSViewController {
let _:Ticket = userInfo["ticket"] as? Ticket else {
return
}
self.ticketTableView.reloadData()
}
func catchTicketsUpdated(notification:Notification) -> Void {
DispatchQueue.main.async{
print("\(OTRS.sharedInstance.ticketDictionary.count) tickets to be shown")
self.ticketTableView.reloadData()
}
}
}