vendor/pimcore/data-hub/src/Resources/views/Feature/explorer.html.twig line 1

Open in your IDE?
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <style>
  5.         body {
  6.             height: 100%;
  7.             margin: 0;
  8.             width: 100%;
  9.             overflow: hidden;
  10.         }
  11.         #graphiql {
  12.             height: 100vh;
  13.         }
  14.         .token-button {
  15.             position: absolute;
  16.             left: 250px;
  17.             top: 12px;
  18.             background: -webkit-linear-gradient(#fbfbfb, #f8f8f8);
  19.             background:         linear-gradient(#fbfbfb, #f8f8f8);
  20.             border-width: 1px;
  21.             border-style: solid;
  22.             border-color: #d3d3d3 #d0d0d0 #bababa;
  23.             border-radius: 4px;
  24.             box-shadow: 0 1px 1px -1px rgba(0, 0, 0, 0.13), inset 0 1px #fff;
  25.             color: #444;
  26.             cursor: pointer;
  27.             display: inline-block;
  28.             margin: 0 5px 0;
  29.             padding: 2px 8px 4px;
  30.             text-decoration: none;
  31.             height: 26px;
  32.             font-family: system, -apple-system, 'San Francisco', '.SFNSDisplay-Regular', 'Segoe UI', Segoe, 'Segoe WP', 'Helvetica Neue', helvetica, 'Lucida Grande', arial, sans-serif;
  33.             font-size: 14px;
  34.         }
  35.         #token-input {
  36.             display: none;
  37.             position: absolute;
  38.             left: 250px;
  39.             top: 12px;
  40.             width: 350px;
  41.             font-size: 13px;
  42.             line-height: 20px;
  43.             height: 20px;
  44.             padding: 2px 10px;
  45.             border: 1px solid #ccc;
  46.             border-radius: 2px;
  47.         }
  48.     </style>
  49.     <link rel="stylesheet" href="{{ asset('bundles/pimcoredatahub/graphiql.css') }}"/>
  50.     <script src="{{ asset('bundles/pimcoredatahub/react/react-15.0.1.min.js') }}"></script>
  51.     <script src="{{ asset('bundles/pimcoredatahub/react/react-dom-15.0.1.min.js') }}"></script>
  52.     <script src="{{ asset('bundles/pimcoredatahub/react/fetch.min.js') }}"></script>
  53.     <script src="{{ asset('bundles/pimcoredatahub/graphiql.min.js') }}"></script>
  54. </head>
  55. <body>
  56. <button class="token-button">Enter Token</button>
  57. <input type="text" placeholder="AccessToken" id="token-input">
  58. <div id="graphiql">Loading...</div>
  59. <script>
  60.     /**
  61.      * This GraphiQL example illustrates how to use some of GraphiQL's props
  62.      * in order to enable reading and updating the URL parameters, making
  63.      * link sharing of queries a little bit easier.
  64.      *
  65.      * This is only one example of this kind of feature, GraphiQL exposes
  66.      * various React params to enable interesting integrations.
  67.      */
  68.             // Parse the search string to get url parameters.
  69.     var search     = window.location.search;
  70.     var parameters = {};
  71.     search.substr(1).split('&').forEach(function (entry) {
  72.         var eq = entry.indexOf('=');
  73.         if (eq >= 0) {
  74.             parameters[decodeURIComponent(entry.slice(0, eq))] =
  75.                     decodeURIComponent(entry.slice(eq + 1));
  76.         }
  77.     });
  78.     // if variables was provided, try to format it.
  79.     if (parameters.variables) {
  80.         try {
  81.             parameters.variables =
  82.                     JSON.stringify(JSON.parse(parameters.variables), null, 2);
  83.         } catch (e) {
  84.             // Do nothing, we want to display the invalid JSON as a string, rather
  85.             // than present an error.
  86.         }
  87.     }
  88.     // When the query and variables string is edited, update the URL bar so
  89.     // that it can be easily shared
  90.     function onEditQuery(newQuery) {
  91.         parameters.query = newQuery;
  92.         updateURL();
  93.     }
  94.     function onEditVariables(newVariables) {
  95.         parameters.variables = newVariables;
  96.         updateURL();
  97.     }
  98.     function onEditOperationName(newOperationName) {
  99.         parameters.operationName = newOperationName;
  100.         updateURL();
  101.     }
  102.     function updateURL() {
  103.         var newSearch = '?' + Object.keys(parameters).filter(function (key) {
  104.                     return Boolean(parameters[key]);
  105.                 }).map(function (key) {
  106.                     return encodeURIComponent(key) + '=' +
  107.                            encodeURIComponent(parameters[key]);
  108.                 }).join('&');
  109.         history.replaceState(null, null, newSearch);
  110.     }
  111.     function getCookie(name) {
  112.         var value = "; " + document.cookie;
  113.         var parts = value.split("; " + name + "=");
  114.         if (parts.length == 2) return parts.pop().split(";").shift();
  115.     }
  116.     // Defines a GraphQL fetcher using the fetch API.
  117.     function graphQLFetcher(graphQLParams) {
  118.         var headers = {
  119.             'Accept':       'application/json',
  120.             'Content-Type': 'application/json',
  121.         };
  122.         if (window.tokenInput) {
  123.             headers['{{ tokenHeader }}'] = tokenInput.value;
  124.         }
  125.         var cookie = getCookie('XSRF-TOKEN');
  126.         if (cookie != undefined) {
  127.             headers['X-XSRF-TOKEN'] = cookie;
  128.         }
  129.         return fetch("{{ graphQLUrl }}", {
  130.             method:      'post',
  131.             headers:     headers,
  132.             body:        JSON.stringify(graphQLParams),
  133.             credentials: 'include'
  134.         }).then(function (response) {
  135.             return response.text();
  136.         }).then(function (responseBody) {
  137.             try {
  138.                 return JSON.parse(responseBody);
  139.             } catch (error) {
  140.                 return responseBody;
  141.             }
  142.         });
  143.     }
  144.     // Render <GraphiQL /> into the body.
  145.     ReactDOM.render(
  146.             React.createElement(GraphiQL, {
  147.                 fetcher:             graphQLFetcher,
  148.                 query:               parameters.query,
  149.                 variables:           parameters.variables,
  150.                 operationName:       parameters.operationName,
  151.                 onEditQuery:         onEditQuery,
  152.                 onEditVariables:     onEditVariables,
  153.                 onEditOperationName: onEditOperationName
  154.             }),
  155.             document.getElementById('graphiql')
  156.     );
  157. </script>
  158. <script>
  159.     var button     = document.querySelector('.token-button');
  160.     var tokenInput = document.querySelector('#token-input');
  161.     button.addEventListener('click', function() {
  162.         button.style.display     = 'none';
  163.         tokenInput.style.display = 'inline-block';
  164.     });
  165.     tokenInput.addEventListener('change', function() {
  166.         if (window.localStorage) {
  167.             window.localStorage.setItem('api-token', tokenInput.value);
  168.         }
  169.     });
  170.     if (window.localStorage) {
  171.         var tokenValue = window.localStorage.getItem('api-token');
  172.         if (tokenValue) {
  173.             tokenInput.value = tokenValue;
  174.         }
  175.     }
  176. </script>
  177. </body>
  178. </html>