diff --git a/react/src/components/dashboard/settings/settings.js b/react/src/components/dashboard/settings/settings.js index 7e18e49..9ee9613 100644 --- a/react/src/components/dashboard/settings/settings.js +++ b/react/src/components/dashboard/settings/settings.js @@ -473,19 +473,131 @@ class Settings extends React.Component { ); } +/* + if (_cliResponse) { + let _cliResponseParsed; + let __cliResponseParsed; + let errorObj = { + code: null, + message: null, + }; + + if (_cliResponse.result.indexOf('"code":')) { + errorObj.code = _cliResponse.result.match(/"code":(.*?),/i)[1]; + errorObj.message = _cliResponse.result.substr(_cliResponse.result.indexOf('"message":') + 11, _cliResponse.result.length - _cliResponse.result.indexOf('"message":') - 15); + if (errorObj.message.indexOf('\n') > -1) { + errorObj.message.replace('\n', '----'); + } + console.log(errorObj.message.toString().match(/\n/g)); + } + + // console.log(errorObj); + if (errorObj.code && + errorObj.message) { + _cliResponseParsed = 'error code: '+ errorObj.code + ' message: ' + errorObj.message; + if (_cliResponseParsed.indexOf('\n') > -1) { + __cliResponseParsed = _cliResponseParsed.split('\n'); + console.log(__cliResponseParsed); + } + if (_cliResponseParsed.indexOf('\r\n') > -1) { + __cliResponseParsed = _cliResponseParsed.split('\r\n'); + console.log(__cliResponseParsed); + } + } else { + try { + _cliResponseParsed = JSON.parse(_cliResponse); + } catch(e) { + _cliResponseParsed = _cliResponse.result; + } + } + + if (!__cliResponseParsed) { + if (typeof _cliResponseParsed !== 'object' && + typeof _cliResponseParsed !== 'number' && + _cliResponseParsed !== 'wrong cli string format' && + _cliResponseParsed.indexOf('\r\n') > -1) { + _cliResponseParsed = _cliResponseParsed.split('\r\n') ; + } else if ( + typeof _cliResponseParsed !== 'object' && + typeof _cliResponseParsed !== 'number' && + _cliResponseParsed !== 'wrong cli string format' && + _cliResponseParsed.indexOf('\n') > -1 + ) { + __cliResponseParsed = _cliResponseParsed.split('\n'); + } else { + __cliResponseParsed = _cliResponseParsed; + } + } + + let _items = []; + + if (__cliResponseParsed && + __cliResponseParsed.length && + __cliResponseParsed !== 'wrong cli string format') { + for (let i = 0; i < __cliResponseParsed.length; i++) { + _items.push( +
{ typeof __cliResponseParsed[i] === 'object' ? JSON.stringify(__cliResponseParsed[i], null, '\t') : __cliResponseParsed[i] }
+ ); + } + } else { + if (typeof __cliResponseParsed === 'object') { + _items.push( +
{ JSON.stringify(__cliResponseParsed, null, '\t') }
+ ); + } else if (typeof __cliResponseParsed === 'string' || typeof __cliResponseParsed === 'number' || __cliResponseParsed === 'wrong cli string format') { + _items.push( +
{ __cliResponseParsed }
+ ); + } else { + _items.push( +
{ translate('INDEX.NO_DATA_AVAILABLE') }
+ ); + } + } + + return ( +
+
+ CLI response: +
+ { _items } +
+ ); + } else { + return null; + } +*/ + renderCliResponse() { const _cliResponse = this.props.Settings.cli; + let _items = []; if (_cliResponse) { let _cliResponseParsed; try { - _cliResponseParsed = JSON.parse(_cliResponse); + _cliResponseParsed = JSON.parse(_cliResponse.result); } catch(e) { _cliResponseParsed = _cliResponse.result; } - let __cliResponseParsed; + if (Object.prototype.toString.call(_cliResponseParsed) === '[object Array]') { + for (let i = 0; i < _cliResponseParsed.length; i++) { + _items.push( +
{ _cliResponseParsed[i] }
+ ); + } + } + if (_cliResponseParsed.indexOf('\n') > -1) { + _cliResponseParsed = _cliResponseParsed.split('\n'); + console.log( _cliResponseParsed.split('\n')); + for (let i = 0; i < _cliResponseParsed.length; i++) { + _items.push( +
{ _cliResponseParsed[i] }
+ ); + } + } + /*let __cliResponseParsed; if (typeof _cliResponseParsed !== 'object' && typeof _cliResponseParsed !== 'number' && _cliResponseParsed !== 'wrong cli string format' && @@ -502,14 +614,9 @@ class Settings extends React.Component { __cliResponseParsed = _cliResponseParsed; } - if (!__cliResponseParsed) { - __cliResponseParsed = _cliResponseParsed; - } - let _items = []; - if (__cliResponseParsed && - __cliResponseParsed.length && + if (__cliResponseParsed.length && __cliResponseParsed !== 'wrong cli string format') { for (let i = 0; i < __cliResponseParsed.length; i++) { _items.push( @@ -517,11 +624,11 @@ class Settings extends React.Component { ); } } else { - if (typeof __cliResponseParsed === 'object') { + if (typeof _cliResponseParsed === 'object') { _items.push(
{ JSON.stringify(__cliResponseParsed, null, '\t') }
); - } else if (typeof __cliResponseParsed === 'string' || typeof __cliResponseParsed === 'number' || __cliResponseParsed === 'wrong cli string format') { + } else if (typeof _cliResponseParsed === 'string' || typeof _cliResponseParsed === 'number' || _cliResponseParsed === 'wrong cli string format') { _items.push(
{ __cliResponseParsed }
); @@ -529,8 +636,8 @@ class Settings extends React.Component { _items.push(
{ translate('INDEX.NO_DATA_AVAILABLE') }
); - } - } + }*/ + //} return (