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 1ef9e49..f54f233 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 25fc655..70cbc95 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 = "504524069.32379" + timestampString = "504687476.967865" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "47" - endingLineNumber = "47" - landmarkName = "reload(que:)" + startingLineNumber = "46" + endingLineNumber = "46" + landmarkName = "reload(queues:)" landmarkType = "7"> + + + + diff --git a/OTRS-Watch/AppDelegate.swift b/OTRS-Watch/AppDelegate.swift index 24bb1cd..45fcd51 100644 --- a/OTRS-Watch/AppDelegate.swift +++ b/OTRS-Watch/AppDelegate.swift @@ -41,8 +41,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { private func getTicketsFromOTRS() { - if let que:Int = Int(UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE)!) { - OTRS.sharedInstance.reload(que: que) + if let queues:String = UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE) { + OTRS.sharedInstance.reload(queues: queues) } } diff --git a/OTRS-Watch/Constants.swift b/OTRS-Watch/Constants.swift index 032cdaa..6a3fe49 100644 --- a/OTRS-Watch/Constants.swift +++ b/OTRS-Watch/Constants.swift @@ -43,6 +43,12 @@ struct Constants { static let ERROR = "nf::ticket::action::error" } } + + struct TABLE { + struct TICKTS { + static let GET_COUNT = "nf::ticket::table::tickets::get::count" + } + } } struct TABS { diff --git a/OTRS-Watch/Extension/ViewControllerExtension.swift b/OTRS-Watch/Extension/ViewControllerExtension.swift index afda35a..177bfbe 100644 --- a/OTRS-Watch/Extension/ViewControllerExtension.swift +++ b/OTRS-Watch/Extension/ViewControllerExtension.swift @@ -18,6 +18,9 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate { } func numberOfRows(in tableView: NSTableView) -> Int { + NotificationCenter.default.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TABLE.TICKTS.GET_COUNT), + object: nil, + userInfo: ["message":OTRS.sharedInstance.ticketDictionary.count]) return OTRS.sharedInstance.ticketDictionary.count } @@ -27,11 +30,16 @@ extension ViewController: NSTableViewDataSource, NSTableViewDelegate { var text: String = "" var cellIdentifier: String = "" - guard row < OTRS.sharedInstance.ticketDictionary.count else { + let tickets:Array = OTRS.sharedInstance.ticketDictionary + let ticketCount = tickets.count + + //print("🖥 Compare row \(row) with ticket count \(ticketCount) for displaying cell for row") + + guard row < ticketCount else { return nil } - if let item:Ticket = OTRS.sharedInstance.ticketDictionary[row] as Ticket { + if let item:Ticket = tickets[row] as Ticket { if tableColumn == self.ticketTableView.tableColumns[0] { cellIdentifier = CellIdentifiers.OTRSTicketNumber image = nil diff --git a/OTRS-Watch/OTRS.swift b/OTRS-Watch/OTRS.swift index b4d3b1b..c2440d5 100644 --- a/OTRS-Watch/OTRS.swift +++ b/OTRS-Watch/OTRS.swift @@ -41,16 +41,15 @@ class OTRS { //MARK: REST - func reload(que:Int) { - let nc = NotificationCenter.default + func reload(queues:String) { let config = URLSessionConfiguration.default // Session configuration let session = URLSession(configuration: config) // Load configuration into session - let urlNew = URL(string: buildURLForGettingNew(queID: que)) - let urlOpen = URL(string: buildURLForGettingOpen(queID: que)) + let urlNew = URL(string: buildURLForGettingNew(queues: queues)) + let urlOpen = URL(string: buildURLForGettingOpen(queues: queues)) self.ticketDictionary.removeAll() - nc.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.ACTION.CONNECTED), + NotificationCenter.default.post(name:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.ACTION.CONNECTED), object: nil, userInfo: ["message":""]) @@ -154,16 +153,18 @@ class OTRS { //MARK: Build urls - private func buildURLForGettingNew(queID:Int) -> String { - return buildURLForGettingListByState(forState: "new", queID: queID) + private func buildURLForGettingNew(queues:String) -> String { + return buildURLForGettingListByState(forState: "new", queues: queues) } - private func buildURLForGettingOpen(queID:Int) -> String { - return buildURLForGettingListByState(forState: "open", queID: queID) + private func buildURLForGettingOpen(queues:String) -> String { + return buildURLForGettingListByState(forState: "open", queues: queues) } - private func buildURLForGettingListByState(forState:String, queID:Int) -> String { - return self.baseURL.appending("Ticket?UserLogin=\(self.username)&Password=\(self.password)&QueueIDs=\(queID)&States=\(forState)") + private func buildURLForGettingListByState(forState:String, queues:String) -> String { + let queuesQueryStr = queues.replacingOccurrences(of: ",", with: "&QueueIDs=") + let requestURL = self.baseURL.appending("Ticket?UserLogin=\(self.username)&Password=\(self.password)&QueueIDs=\(queuesQueryStr)&States=\(forState)") + return requestURL } private func buildURLForGettingTicketInfo(ticketID:Int) -> String { diff --git a/OTRS-Watch/WindowController.swift b/OTRS-Watch/WindowController.swift index 2ec642c..eb0a2e4 100644 --- a/OTRS-Watch/WindowController.swift +++ b/OTRS-Watch/WindowController.swift @@ -40,14 +40,17 @@ class WindowController: NSWindowController { nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.LIST.UPDATED), object:nil, queue:nil, using:catchUpdateFinished) + nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TABLE.TICKTS.GET_COUNT), + object:nil, queue:nil, + using:catchTableCountRequested) nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.ACTION.ERROR), object:nil, queue:nil, using:catchError) } @IBAction func toolbarActionReload(_ sender: NSToolbarItem) { - if let que:Int = Int(UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE)!) { - OTRS.sharedInstance.reload(que: que) + if let queues:String = UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE) { + OTRS.sharedInstance.reload(queues: queues) } self.viewController.tabView.selectTabViewItem(at: Constants.TABS.TAB.OTRS) @@ -94,17 +97,19 @@ class WindowController: NSWindowController { self.activity.stringValue = "" }) + debugStatusBarContent() + } + + func catchTableCountRequested(notification:Notification) -> Void { guard let userInfo = notification.userInfo else { return } - + DispatchQueue.main.async(execute: { - if let ticketCount:Int = userInfo["count"] as? Int { + if let ticketCount:Int = userInfo["message"] as? Int { self.ticketCount.title = "\(ticketCount)" } }) - - debugStatusBarContent() } func catchError(notification:Notification) -> Void {