|
|
@ -1,40 +1,137 @@ |
|
|
|
var BNPChrome = angular |
|
|
|
.module("BNPChrome", []) |
|
|
|
.factory("parse", function () { |
|
|
|
const parser = function (input, level, depthOverride) { |
|
|
|
const depth = depthOverride || 3; |
|
|
|
if (level > depth) return input; |
|
|
|
|
|
|
|
if (!input || typeof input === "number" || typeof input === "boolean") { |
|
|
|
return input; |
|
|
|
function convertToJSON(input) { |
|
|
|
let jsonString; |
|
|
|
|
|
|
|
// Try to parse the input as JSON
|
|
|
|
try { |
|
|
|
jsonString = JSON.parse(input); |
|
|
|
return jsonString; |
|
|
|
} catch (error) { |
|
|
|
// Parsing failed, assume input is a query string
|
|
|
|
} |
|
|
|
|
|
|
|
if (Array.isArray(input)) { |
|
|
|
// loop and parse each node
|
|
|
|
for (var i = 0; i < input.length; i++) { |
|
|
|
input[i] = parser(input[i], level ? level + 1 : 1, depth); |
|
|
|
} |
|
|
|
return input; |
|
|
|
|
|
|
|
// Decode URL-encoded string n times until no more encoding is found
|
|
|
|
let decodedInput = decodeURIComponent(input); |
|
|
|
while (decodedInput !== input) { |
|
|
|
input = decodedInput; |
|
|
|
decodedInput = decodeURIComponent(input); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof input === "string") { |
|
|
|
|
|
|
|
// Convert the query string to a JSON object
|
|
|
|
const keyValuePairs = input.split('&'); |
|
|
|
const jsonObject = {}; |
|
|
|
|
|
|
|
keyValuePairs.forEach(keyValuePair => { |
|
|
|
const [key, value] = keyValuePair.split('='); |
|
|
|
jsonObject[key] = value; |
|
|
|
}); |
|
|
|
|
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
function queryStringToJson(queryString) { |
|
|
|
let decoded = decodeURIComponent(queryString); |
|
|
|
let pairs = decoded.split('&'); |
|
|
|
let result = {}; |
|
|
|
pairs.forEach(function(pair) { |
|
|
|
pair = pair.split('='); |
|
|
|
let name = pair[0]; |
|
|
|
let value = pair[1]; |
|
|
|
if (name.length > 0) { |
|
|
|
name = name.replace(/\[([^\]]*)\]/g, function($0, $1) { |
|
|
|
if ($1.length > 0) { |
|
|
|
return "." + $1; |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
}); |
|
|
|
try { |
|
|
|
input = parser(JSON.parse(input), level ? level + 1 : 1, depth); |
|
|
|
return input; |
|
|
|
value = decodeURIComponent(value); |
|
|
|
} catch (e) { |
|
|
|
// not a stringified node
|
|
|
|
return input; |
|
|
|
// Do nothing, use the original value instead
|
|
|
|
} |
|
|
|
} else if (typeof input === "object") { |
|
|
|
Object.keys(input).forEach(function (item) { |
|
|
|
input[item] = parser(input[item], level ? level + 1 : 1, depth); |
|
|
|
return item; |
|
|
|
}); |
|
|
|
} else { |
|
|
|
// unless there is a datatype I'm not checking for....
|
|
|
|
// console.log('shouldnt get here')
|
|
|
|
} |
|
|
|
let keys = name.split('.'); |
|
|
|
let obj = result; |
|
|
|
let key; |
|
|
|
while ((key = keys.shift())) { |
|
|
|
if (keys.length === 0) { |
|
|
|
if (obj[key] === undefined) { |
|
|
|
obj[key] = value; |
|
|
|
} else if (Array.isArray(obj[key])) { |
|
|
|
obj[key].push(value); |
|
|
|
} else { |
|
|
|
obj[key] = [obj[key], value]; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (obj[key] === undefined) { |
|
|
|
obj[key] = {}; |
|
|
|
} |
|
|
|
obj = obj[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
const parseQueryParams = function(queryString) { |
|
|
|
// Extract query params using a regular expression
|
|
|
|
const params = queryString.split('&'); |
|
|
|
if (params.length == 0) return queryString; |
|
|
|
|
|
|
|
const queryParams = {}; |
|
|
|
for (let i = 0; i < params.length; i++) { |
|
|
|
let [key, value] = params[i].split('='); |
|
|
|
let decodedInput = decodeURIComponent(value); |
|
|
|
while (decodedInput !== value) { |
|
|
|
value = decodedInput; |
|
|
|
decodedInput = decodeURIComponent(value); |
|
|
|
} |
|
|
|
queryParams[key] = decodedInput; |
|
|
|
} |
|
|
|
return queryParams; |
|
|
|
}; |
|
|
|
const parser = function (input, depth, maxDepth) { |
|
|
|
// If the input is a string, try to parse it as JSON
|
|
|
|
if (typeof input === 'string') { |
|
|
|
try { |
|
|
|
return parser(JSON.parse(input), depth + 1, maxDepth); |
|
|
|
} catch (err) { |
|
|
|
// If the input is not valid JSON return the input
|
|
|
|
return input |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// If the input is an array, recursively parse each item in the array
|
|
|
|
if (Array.isArray(input)) { |
|
|
|
return input.map(item => parser(item, depth + 1, maxDepth)); |
|
|
|
} |
|
|
|
|
|
|
|
// If the input is an object, recursively parse each value in the object
|
|
|
|
if (typeof input === 'object') { |
|
|
|
const parsedJson = {}; |
|
|
|
for (const [key, value] of Object.entries(input)) { |
|
|
|
if (typeof value === 'string') { |
|
|
|
// If the value is a string, then it might be a serialized JSON string, so try to parse it
|
|
|
|
try { |
|
|
|
parsedJson[key] = parser(JSON.parse(value), depth + 1, maxDepth); |
|
|
|
} catch (err) { |
|
|
|
if (value.includes("&") && value.includes("=")) |
|
|
|
parsedJson[key] = parser(convertToJSON(value), depth + 1, maxDepth); |
|
|
|
else |
|
|
|
parsedJson[key] = value; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// If the value is not a string, recursively parse it
|
|
|
|
parsedJson[key] = parser(value, depth + 1, maxDepth); |
|
|
|
} |
|
|
|
} |
|
|
|
return parsedJson; |
|
|
|
} |
|
|
|
|
|
|
|
// If the input is not a string, array, or object, return it unchanged
|
|
|
|
return input; |
|
|
|
}; |
|
|
|
|
|
|
@ -74,7 +171,7 @@ var BNPChrome = angular |
|
|
|
} |
|
|
|
}; |
|
|
|
}) |
|
|
|
.directive("resizableColumns", function ($parse) { |
|
|
|
.directive("resizableColumns", function () { |
|
|
|
return { |
|
|
|
link: function (scope, element, attrs) { |
|
|
|
const options = { minWidth: 5 }; |
|
|
@ -116,7 +213,7 @@ var BNPChrome = angular |
|
|
|
} |
|
|
|
}; |
|
|
|
}) |
|
|
|
.directive("scrollToNew", function ($parse) { |
|
|
|
.directive("scrollToNew", function () { |
|
|
|
return function (scope, element, attrs) { |
|
|
|
if (scope.scrollToNew && scope.$last) { |
|
|
|
const $container = $(element).parents(".data-container").first(); |
|
|
@ -137,7 +234,7 @@ var BNPChrome = angular |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
}).directive('ngRightClick', function($parse) { |
|
|
|
}).directive('ngRightClick', function() { |
|
|
|
return function(scope, element, attrs) { |
|
|
|
element.bind('contextmenu', function(event) { |
|
|
|
scope.$apply(function() { |
|
|
|