|
|
@@ -7,6 +7,7 @@ import {coreModule, JsonExplorer} from 'app/core/core';
|
|
|
const template = `
|
|
|
<div class="query-troubleshooter" ng-if="ctrl.isOpen">
|
|
|
<div class="query-troubleshooter__header">
|
|
|
+ <a class="pointer" ng-click="ctrl.toggleMocking()">Mock Response</a>
|
|
|
<a class="pointer" ng-click="ctrl.toggleExpand()" ng-hide="ctrl.allNodesExpanded">
|
|
|
<i class="fa fa-plus-square-o"></i> Expand All
|
|
|
</a>
|
|
|
@@ -15,10 +16,18 @@ const template = `
|
|
|
</a>
|
|
|
<a class="pointer" clipboard-button="ctrl.getClipboardText()"><i class="fa fa-clipboard"></i> Copy to Clipboard</a>
|
|
|
</div>
|
|
|
- <div class="query-troubleshooter__body">
|
|
|
+ <div class="query-troubleshooter__body" ng-hide="ctrl.isMocking">
|
|
|
<i class="fa fa-spinner fa-spin" ng-show="ctrl.isLoading"></i>
|
|
|
<div class="query-troubleshooter-json"></div>
|
|
|
</div>
|
|
|
+ <div class="query-troubleshooter__body" ng-show="ctrl.isMocking">
|
|
|
+ <div class="gf-form p-l-1">
|
|
|
+ <div class="gf-form gf-form--v-stretch">
|
|
|
+ <span class="gf-form-label width-10">Response JSON</span>
|
|
|
+ <textarea class="gf-form-input width-25" rows="10" ng-model="ctrl.mockedResponse" placeholder="JSON"></textarea>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
|
@@ -32,6 +41,8 @@ export class QueryTroubleshooterCtrl {
|
|
|
onRequestResponseEventListener: any;
|
|
|
hasError: boolean;
|
|
|
allNodesExpanded: boolean;
|
|
|
+ isMocking: boolean;
|
|
|
+ mockedResponse: string;
|
|
|
jsonExplorer: JsonExplorer;
|
|
|
|
|
|
/** @ngInject **/
|
|
|
@@ -51,6 +62,10 @@ export class QueryTroubleshooterCtrl {
|
|
|
appEvents.off('ds-request-error', this.onRequestErrorEventListener);
|
|
|
}
|
|
|
|
|
|
+ toggleMocking() {
|
|
|
+ this.isMocking = !this.isMocking;
|
|
|
+ }
|
|
|
+
|
|
|
onRequestError(err) {
|
|
|
// ignore if closed
|
|
|
if (!this.isOpen) {
|
|
|
@@ -76,12 +91,29 @@ export class QueryTroubleshooterCtrl {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
+ handleMocking(data) {
|
|
|
+ var mockedData;
|
|
|
+ try {
|
|
|
+ mockedData = JSON.parse(this.mockedResponse);
|
|
|
+ } catch (err) {
|
|
|
+ appEvents.emit('alert-error', ['Failed to parse mocked response']);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ data.data = mockedData;
|
|
|
+ }
|
|
|
+
|
|
|
onRequestResponse(data) {
|
|
|
// ignore if closed
|
|
|
if (!this.isOpen) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ if (this.isMocking) {
|
|
|
+ this.handleMocking(data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
this.isLoading = false;
|
|
|
data = _.cloneDeep(data);
|
|
|
|