mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: fixed gofmt issue and addd mock response feature
This commit is contained in:
@@ -22,8 +22,7 @@ func ValidateOrgAlert(c *middleware.Context) {
|
|||||||
if c.OrgId != query.Result.OrgId {
|
if c.OrgId != query.Result.OrgId {
|
||||||
c.JsonApiErr(403, "You are not allowed to edit/view alert", nil)
|
c.JsonApiErr(403, "You are not allowed to edit/view alert", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAlertStatesForDashboard(c *middleware.Context) Response {
|
func GetAlertStatesForDashboard(c *middleware.Context) Response {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {coreModule, JsonExplorer} from 'app/core/core';
|
|||||||
const template = `
|
const template = `
|
||||||
<div class="query-troubleshooter" ng-if="ctrl.isOpen">
|
<div class="query-troubleshooter" ng-if="ctrl.isOpen">
|
||||||
<div class="query-troubleshooter__header">
|
<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">
|
<a class="pointer" ng-click="ctrl.toggleExpand()" ng-hide="ctrl.allNodesExpanded">
|
||||||
<i class="fa fa-plus-square-o"></i> Expand All
|
<i class="fa fa-plus-square-o"></i> Expand All
|
||||||
</a>
|
</a>
|
||||||
@@ -15,10 +16,18 @@ const template = `
|
|||||||
</a>
|
</a>
|
||||||
<a class="pointer" clipboard-button="ctrl.getClipboardText()"><i class="fa fa-clipboard"></i> Copy to Clipboard</a>
|
<a class="pointer" clipboard-button="ctrl.getClipboardText()"><i class="fa fa-clipboard"></i> Copy to Clipboard</a>
|
||||||
</div>
|
</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>
|
<i class="fa fa-spinner fa-spin" ng-show="ctrl.isLoading"></i>
|
||||||
<div class="query-troubleshooter-json"></div>
|
<div class="query-troubleshooter-json"></div>
|
||||||
</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>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -32,6 +41,8 @@ export class QueryTroubleshooterCtrl {
|
|||||||
onRequestResponseEventListener: any;
|
onRequestResponseEventListener: any;
|
||||||
hasError: boolean;
|
hasError: boolean;
|
||||||
allNodesExpanded: boolean;
|
allNodesExpanded: boolean;
|
||||||
|
isMocking: boolean;
|
||||||
|
mockedResponse: string;
|
||||||
jsonExplorer: JsonExplorer;
|
jsonExplorer: JsonExplorer;
|
||||||
|
|
||||||
/** @ngInject **/
|
/** @ngInject **/
|
||||||
@@ -51,6 +62,10 @@ export class QueryTroubleshooterCtrl {
|
|||||||
appEvents.off('ds-request-error', this.onRequestErrorEventListener);
|
appEvents.off('ds-request-error', this.onRequestErrorEventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleMocking() {
|
||||||
|
this.isMocking = !this.isMocking;
|
||||||
|
}
|
||||||
|
|
||||||
onRequestError(err) {
|
onRequestError(err) {
|
||||||
// ignore if closed
|
// ignore if closed
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
@@ -76,12 +91,29 @@ export class QueryTroubleshooterCtrl {
|
|||||||
return '';
|
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) {
|
onRequestResponse(data) {
|
||||||
// ignore if closed
|
// ignore if closed
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isMocking) {
|
||||||
|
this.handleMocking(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
data = _.cloneDeep(data);
|
data = _.cloneDeep(data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user