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" ignoreCount = "0"
continueAfterRunningActions = "No" continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift" filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503499740.022029" timestampString = "503572546.154236"
startingColumnNumber = "9223372036854775807" startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807"
startingLineNumber = "68" startingLineNumber = "71"
endingLineNumber = "68" endingLineNumber = "71"
landmarkName = "reload(que:)" landmarkName = "reload(que:)"
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>

View File

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

View File

@ -52,4 +52,15 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate {
return nil 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 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 username : String = "";
var password : String = ""; var password : String = "";
@ -62,17 +62,15 @@ class OTRS {
print(ticketIDs) print(ticketIDs)
for ticketID in ticketIDs { for ticketID in ticketIDs {
cnt += 1;
let isLast = (cnt == ticketIDs.count)
if let tID:Int = Int(ticketID) { if let tID:Int = Int(ticketID) {
self.fetch(ticket: tID, session: session) self.fetch(ticket: tID, session: session, isLast: isLast)
cnt = cnt+1;
} }
} }
} }
let nc = NotificationCenter.default
nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED),
object: nil,
userInfo: ["count":cnt])
} }
} catch { } catch {
print("Error in JSONSerialization") print("Error in JSONSerialization")
@ -83,7 +81,7 @@ class OTRS {
task.resume() task.resume()
} }
func fetch(ticket:Int, session:URLSession) { func fetch(ticket:Int, session:URLSession, isLast:Bool) {
let url = URL(string: buildURLForGettingTicketInfo(ticketID: ticket)) let url = URL(string: buildURLForGettingTicketInfo(ticketID: ticket))
let task = session.dataTask(with: url!, completionHandler: { // see: https://developer.apple.com/swift/blog/?id=37 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) let ticket = try Ticket(source: ticketData)
//print(ticket) //print(ticket)
self.ticketDictionary.append(ticket)
let nc = NotificationCenter.default let nc = NotificationCenter.default
nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.IN), nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.IN),
object: nil, object: nil,
userInfo: ["message":ticket.id, "ticket":ticket]) 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) { } catch SerializationError.missing(let marker) {
print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"") print("Error in JSONSerialization for ticket #\(ticket) at \"\(marker)\"")
@ -128,7 +133,6 @@ class OTRS {
} }
private func buildURLForGettingListByState(forState:String, queID:Int) -> String { 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)") 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 { let _:Ticket = userInfo["ticket"] as? Ticket else {
return return
} }
self.ticketTableView.reloadData()
} }
func catchTicketsUpdated(notification:Notification) -> Void { func catchTicketsUpdated(notification:Notification) -> Void {
DispatchQueue.main.async{
print("\(OTRS.sharedInstance.ticketDictionary.count) tickets to be shown")
self.ticketTableView.reloadData()
}
} }
} }