Skip to content
Snippets Groups Projects
Commit f6733fa6 authored by Ryan Bateman's avatar Ryan Bateman
Browse files

view configuration page done - pretty printed json output

parent 04ed85fa
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,6 @@ prettyprint:
version: 1.x
js:
js/prettyprint.js: {}
dependencies:
- core/jquery
- core/jquery.once
(function ($, Drupal) {
Drupal.behaviors.fetchAndSetConfig = {
attach: function (context, settings) {
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
$(document).ready(function() {
jQuery
.get('/rest/session/token')
.done(function (data) {
var csrfToken = data;
jQuery.ajax({
url: '/admin/backstop_generator/backstop_configuration/export?_format=json',
method: 'GET',
headers: {
'Content-Type': 'application/hal+json',
'X-CSRF-Token': csrfToken,
},
success: function (node) {
console.log(node);
var str = syntaxHighlight(JSON.stringify(node, null, 2));
$('#configuration-preview').html(str);
}
});
});
});
// url (required), options (optional)
/*var responseBody;
fetch('/admin/backstop_generator/backstop_configuration/export?_format=json', {
method: 'get'
}).then(function(response) {
responseBody = response;
console.log(response);
console.log(response.json);
}).catch(function(err) {
throw(err);
console.log(err);
});
});
*/
// Using once() to apply the myCustomBehaviour effect when you want to run just one function.
/*$('input.myCustomBehavior', context).once('myCustomBehavior').addClass('processed');
$('input.myCustom', context).once('mySecondBehavior').each(function () {
if ($(this).visible()) {
$(this).css('background', 'green');
}
else {
$(this).css('background', 'yellow').show();
}
});
*/
}
};
})(jQuery, Drupal);
......@@ -89,9 +89,9 @@ class BackstopConfigurationRest extends ResourceBase {
// You must to implement the logic of your REST Resource here.
// Use current user after pass authentication to validate access.
if (!$this->currentUser->hasPermission('access content')) {
/*if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
}*/
$entity = $this->backstopConfigRetrieverService->getConfigurationObject();
//we don't want to cache cache, so we need modifiedresourceresponse
return new ModifiedResourceResponse($entity, 200);
......
<marquee>YO DAWG, HOLD UP</marquee>
{{ attach_library('backstop_generator/prettyprint') }}
<pre id="configuration-preview">Loading...</pre>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment