-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js-10): Handle single alarm (xml) result properly
- Loading branch information
Markus von Rüden
committed
Aug 1, 2017
1 parent
5806aa6
commit 544c174
Showing
7 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Helper to transform a json string to an json object. | ||
*/ | ||
export class JsonTransformer { | ||
/** | ||
* A convenience method for implementers to use to turn JSON into a javascript object. | ||
* Use this to process a JSON response before returning it in an [[OnmsResult]] object. | ||
*/ | ||
public transform(data: any) { | ||
if (typeof data === 'string') { | ||
if (data.length < 1) { | ||
return {}; | ||
} else { | ||
return JSON.parse(data); | ||
} | ||
} else { | ||
// assume it's already parsed | ||
return data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
if (global && !global.window) { | ||
global.window = {} as Window; | ||
if (!global.window.DOMParser) { | ||
// tslint:disable-next-line | ||
global.window.DOMParser = require('xmldom').DOMParser; | ||
} | ||
} | ||
|
||
/** @hidden */ | ||
// tslint:disable-next-line | ||
const X2JS = require('x2js'); | ||
|
||
/** @hidden */ | ||
const xmlParser = new X2JS({ | ||
arrayAccessForm: 'property', | ||
attributePrefix: '', | ||
ignoreRoot: true, | ||
}); | ||
|
||
/** | ||
* Helper class to transform any xml string to a javascript object. | ||
*/ | ||
export class XmlTransformer { | ||
/** | ||
* A convenience method for implementers to use to turn XML into a javascript object. | ||
* Use this to process an XML response before returning it in an [[OnmsResult]] object. | ||
*/ | ||
public transform(data: any) { | ||
if (typeof data === 'string') { | ||
return xmlParser.xml2js(data); | ||
} else { | ||
// assume it's already parsed | ||
return data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters