URL via settings

This commit is contained in:
Gerrit Linnemann 2016-12-15 14:12:23 +01:00
parent 38212fa196
commit 88163e3e53
7 changed files with 51 additions and 19 deletions

View File

@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503498994.361076"
timestampString = "503499740.022029"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "58"
endingLineNumber = "58"
startingLineNumber = "60"
endingLineNumber = "60"
landmarkName = "reload(que:)"
landmarkType = "7">
</BreakpointContent>
@ -26,11 +26,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503498994.361076"
timestampString = "503499740.022029"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "66"
endingLineNumber = "66"
startingLineNumber = "68"
endingLineNumber = "68"
landmarkName = "reload(que:)"
landmarkType = "7">
</BreakpointContent>
@ -42,11 +42,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503498994.361076"
timestampString = "503499740.022029"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "43"
endingLineNumber = "43"
startingLineNumber = "45"
endingLineNumber = "45"
landmarkName = "reload(que:)"
landmarkType = "7">
<Locations>
@ -90,12 +90,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "OTRS-Watch/OTRS.swift"
timestampString = "503498201.457531"
timestampString = "503499740.022029"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "30"
endingLineNumber = "30"
landmarkName = "configure(username_:password_:)"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "configure(baseURL_:username_:password_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>

View File

@ -14,10 +14,12 @@ 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)!)
if let baseURL = UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.BASE_URL) {
OTRS.sharedInstance.configure(baseURL_: baseURL, 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

View File

@ -933,6 +933,24 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="J3Z-8V-Igs">
<rect key="frame" x="148" y="23" width="508" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="1zj-BK-0pr">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="mkK-OH-aIw">
<rect key="frame" x="18" y="26" width="30" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="URL" id="3PK-C3-jeV">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
</box>
@ -945,6 +963,7 @@
</view>
<connections>
<outlet property="ticketTableView" destination="uqq-D2-JrZ" id="Csb-WI-8ex"/>
<outlet property="txtBaseURL" destination="J3Z-8V-Igs" id="MNC-l0-bgU"/>
<outlet property="txtPassword" destination="dBq-YZ-1Lb" id="zcP-17-bRV"/>
<outlet property="txtQueue" destination="l3M-cB-NAW" id="ljI-tu-VOS"/>
<outlet property="txtUsername" destination="CWI-hQ-L71" id="3oJ-D0-5fl"/>

View File

@ -22,6 +22,7 @@ struct Constants {
}
struct OTRS {
static let BASE_URL = "user::setting::otrs::url::base"
static let QUEUE = "user::setting::otrs::queue"
}
}

View File

@ -18,6 +18,7 @@ class OTRS {
return Singleton.instance
}
var baseURL : String = "";
var username : String = "";
var password : String = "";
@ -26,7 +27,8 @@ class OTRS {
//MARK: init
func configure(username_:String, password_:String) {
func configure(baseURL_:String, username_:String, password_:String) {
self.baseURL = baseURL_
self.username = username_
self.password = password_
}
@ -126,10 +128,11 @@ class OTRS {
}
private func buildURLForGettingListByState(forState:String, queID:Int) -> String {
return "http://saeotrs01.sae.intra/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket?UserLogin=\(self.username)&Password=\(self.password)&QueueIDs=\(queID)&States=\(forState)"
// 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)")
}
private func buildURLForGettingTicketInfo(ticketID:Int) -> String {
return "http://saeotrs01.sae.intra/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/\(ticketID)?UserLogin=\(self.username)&Password=\(self.password)"
return self.baseURL.appending("Ticket/\(ticketID)?UserLogin=\(self.username)&Password=\(self.password)")
}
}

View File

@ -13,6 +13,7 @@ class ViewController: NSViewController {
@IBOutlet weak var txtUsername: NSTextField!
@IBOutlet weak var txtPassword: NSSecureTextField!
@IBOutlet weak var txtQueue: NSTextField!
@IBOutlet weak var txtBaseURL: NSTextField!
@IBOutlet weak var ticketTableView: NSTableView!
override func viewDidLoad() {
@ -35,6 +36,10 @@ class ViewController: NSViewController {
txtQueue.stringValue = UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.QUEUE)!
}
if UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.BASE_URL) != nil {
txtBaseURL.stringValue = UserDefaults.standard.string(forKey: Constants.USER_SETTINGS.OTRS.BASE_URL)!
}
let nc = NotificationCenter.default
nc.addObserver(forName:Notification.Name(rawValue:Constants.NOTIFICATION.TICKET.IN),
object:nil, queue:nil,
@ -59,6 +64,8 @@ class ViewController: NSViewController {
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(txtBaseURL.stringValue, forKey: Constants.USER_SETTINGS.OTRS.BASE_URL)
}