Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
efdd4a66
Commit
efdd4a66
authored
Feb 02, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugins): more work on plugin editors,prometheus query editor is working
parent
eaaf9246
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
128 deletions
+42
-128
public/app/core/directives/plugin_component.ts
+2
-2
public/app/core/directives/plugin_directive_loader.ts
+0
-92
public/app/features/datasources/partials/edit.html
+2
-2
public/app/features/panel/query_editor.ts
+3
-4
public/app/plugins/datasource/prometheus/partials/query.editor.html
+15
-15
public/app/plugins/datasource/prometheus/query_ctrl.ts
+20
-13
No files found.
public/app/core/directives/plugin_component.ts
View file @
efdd4a66
...
...
@@ -35,8 +35,8 @@ function pluginDirectiveLoader($compile, datasourceSrv) {
return
System
.
import
(
ds
.
meta
.
module
).
then
(
dsModule
=>
{
return
{
name
:
'metrics-query-editor-'
+
ds
.
meta
.
id
,
bindings
:
{
target
:
"="
,
panelCtrl
:
"="
},
attrs
:
{
"target"
:
"target"
,
"panel-ctrl"
:
"ctrl"
},
bindings
:
{
target
:
"="
,
panelCtrl
:
"="
,
datasource
:
"="
},
attrs
:
{
"target"
:
"target"
,
"panel-ctrl"
:
"ctrl"
,
datasource
:
"datasource"
},
Component
:
dsModule
.
MetricsQueryEditor
};
});
...
...
public/app/core/directives/plugin_directive_loader.ts
deleted
100644 → 0
View file @
eaaf9246
///<reference path="../../headers/common.d.ts" />
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
coreModule
from
'../core_module'
;
/** @ngInject */
function
pluginComponentLoader
(
$compile
,
datasourceSrv
)
{
function
getPluginComponentDirective
(
options
)
{
return
function
()
{
return
{
templateUrl
:
options
.
Component
.
templateUrl
,
restrict
:
'E'
,
controller
:
options
.
Component
,
controllerAs
:
'ctrl'
,
bindToController
:
true
,
scope
:
options
.
bindings
,
link
:
(
scope
,
elem
,
attrs
,
ctrl
)
=>
{
if
(
ctrl
.
link
)
{
ctrl
.
link
(
scope
,
elem
,
attrs
,
ctrl
);
}
}
};
};
}
function
getModule
(
scope
,
attrs
)
{
switch
(
attrs
.
type
)
{
case
"metrics-query-editor"
:
let
datasource
=
scope
.
target
.
datasource
||
scope
.
ctrl
.
panel
.
datasource
;
return
datasourceSrv
.
get
(
datasource
).
then
(
ds
=>
{
if
(
!
scope
.
target
.
refId
)
{
scope
.
target
.
refId
=
'A'
;
}
return
System
.
import
(
ds
.
meta
.
module
).
then
(
dsModule
=>
{
return
{
name
:
'metrics-query-editor-'
+
ds
.
meta
.
id
,
bindings
:
{
target
:
"="
,
panelCtrl
:
"="
},
attrs
:
{
"target"
:
"target"
,
"panel-ctrl"
:
"ctrl"
},
Component
:
dsModule
.
MetricsQueryEditor
};
});
});
case
'datasource-config-view'
:
return
System
.
import
(
scope
.
datasourceMeta
.
module
).
then
(
function
(
dsModule
)
{
return
{
name
:
'ds-config-'
+
scope
.
datasourceMeta
.
id
,
bindings
:
{
meta
:
"="
,
current
:
"="
},
attrs
:
{
meta
:
"datasourceMeta"
,
current
:
"current"
},
Component
:
dsModule
.
ConfigView
,
};
});
}
}
function
appendAndCompile
(
scope
,
elem
,
componentInfo
)
{
var
child
=
angular
.
element
(
document
.
createElement
(
componentInfo
.
name
));
_
.
each
(
componentInfo
.
attrs
,
(
value
,
key
)
=>
{
child
.
attr
(
key
,
value
);
});
$compile
(
child
)(
scope
);
elem
.
empty
();
elem
.
append
(
child
);
}
function
registerPluginComponent
(
scope
,
elem
,
attrs
,
componentInfo
)
{
if
(
!
componentInfo
.
Component
.
registered
)
{
var
directiveName
=
attrs
.
$normalize
(
componentInfo
.
name
);
var
directiveFn
=
getPluginComponentDirective
(
componentInfo
);
coreModule
.
directive
(
directiveName
,
directiveFn
);
componentInfo
.
Component
.
registered
=
true
;
}
appendAndCompile
(
scope
,
elem
,
componentInfo
);
}
return
{
restrict
:
'E'
,
link
:
function
(
scope
,
elem
,
attrs
)
{
getModule
(
scope
,
attrs
).
then
(
function
(
componentInfo
)
{
registerPluginComponent
(
scope
,
elem
,
attrs
,
componentInfo
);
});
}
};
}
coreModule
.
directive
(
'pluginComponent'
,
pluginComponentLoader
);
public/app/features/datasources/partials/edit.html
View file @
efdd4a66
...
...
@@ -42,8 +42,8 @@
</div>
<div
rebuild-on-change=
"datasourceMeta.id"
>
<plugin-
directive-loader
type=
"datasource-config-view"
>
</plugin-
directive-loader
>
<plugin-
component
type=
"datasource-config-view"
>
</plugin-
component
>
</div>
<div
ng-if=
"testing"
style=
"margin-top: 25px"
>
...
...
public/app/features/panel/query_editor.ts
View file @
efdd4a66
...
...
@@ -9,9 +9,8 @@ export class QueryEditorCtrl {
panelCtrl
:
any
;
panel
:
any
;
constructor
(
p
rivate
$scope
,
private
$injector
)
{
constructor
(
p
ublic
$scope
,
private
$injector
)
{
this
.
panel
=
this
.
panelCtrl
.
panel
;
this
.
datasource
=
$scope
.
datasource
;
if
(
!
this
.
target
.
refId
)
{
this
.
target
.
refId
=
this
.
getNextQueryLetter
();
...
...
@@ -44,8 +43,8 @@ export class QueryEditorCtrl {
_
.
move
(
this
.
panel
.
targets
,
index
,
index
+
direction
);
}
toggleHideQuery
(
target
)
{
t
arget
.
hide
=
!
target
.
hide
;
toggleHideQuery
()
{
t
his
.
target
.
hide
=
!
this
.
target
.
hide
;
this
.
panelCtrl
.
refresh
();
}
}
...
...
public/app/plugins/datasource/prometheus/partials/query.editor.html
View file @
efdd4a66
<div
class=
"tight-form"
>
<ul
class=
"tight-form-list pull-right"
>
<li
class=
"tight-form-item small"
ng-show=
"target.datasource"
>
<li
class=
"tight-form-item small"
ng-show=
"
ctrl.
target.datasource"
>
<em>
{{ctrl.target.datasource}}
</em>
</li>
<li
class=
"tight-form-item"
>
...
...
@@ -27,7 +27,7 @@
{{ctrl.target.refId}}
</li>
<li>
<a
class=
"tight-form-item"
ng-click=
"ctrl.toggleHideQuery(
ctrl.target
);"
role=
"menuitem"
>
<a
class=
"tight-form-item"
ng-click=
"ctrl.toggleHideQuery();"
role=
"menuitem"
>
<i
class=
"fa fa-eye"
></i>
</a>
</li>
...
...
@@ -40,12 +40,12 @@
<li>
<input
type=
"text"
class=
"input-xxlarge tight-form-input"
ng-model=
"target.expr"
ng-model=
"
ctrl.
target.expr"
spellcheck=
'false'
placeholder=
"query expression"
data-min-length=
0
data-items=
100
ng-model-onblur
ng-change=
"refreshMetricData()"
>
ng-change=
"
ctrl.
refreshMetricData()"
>
</li>
<li
class=
"tight-form-item"
>
Metric
...
...
@@ -53,9 +53,9 @@
<li>
<input
type=
"text"
class=
"input-medium tight-form-input"
ng-model=
"target.metric"
ng-model=
"
ctrl.
target.metric"
spellcheck=
'false'
bs-typeahead=
"suggestMetrics"
bs-typeahead=
"
ctrl.
suggestMetrics"
placeholder=
"metric name"
data-min-length=
0
data-items=
100
>
</li>
...
...
@@ -70,9 +70,9 @@
Legend format
</li>
<li>
<input
type=
"text"
class=
"tight-form-input input-xxlarge"
ng-model=
"target.legendFormat"
<input
type=
"text"
class=
"tight-form-input input-xxlarge"
ng-model=
"
ctrl.
target.legendFormat"
spellcheck=
'false'
placeholder=
"legend format"
data-min-length=
0
data-items=
1000
ng-model-onblur
ng-change=
"refreshMetricData()"
>
ng-model-onblur
ng-change=
"
ctrl.
refreshMetricData()"
>
</input>
</li>
</ul>
...
...
@@ -86,14 +86,14 @@
Step
</li>
<li>
<input
type=
"text"
class=
"input-mini tight-form-input"
ng-model=
"target.interval"
<input
type=
"text"
class=
"input-mini tight-form-input"
ng-model=
"
ctrl.
target.interval"
bs-tooltip=
"'Leave blank for auto handling based on time range and panel width'"
data-placement=
"right"
spellcheck=
'false'
placeholder=
"{{interval}}"
placeholder=
"{{
ctrl.panelCtrl.
interval}}"
data-min-length=
0
data-items=
100
ng-model-onblur
ng-change=
"refreshMetricData()"
ng-change=
"
ctrl.
refreshMetricData()"
/>
</input>
</li>
...
...
@@ -102,13 +102,13 @@
Resolution
</li>
<li>
<select
ng-model=
"target.intervalFactor"
class=
"tight-form-input input-mini"
ng-options=
"r.factor as r.label for r in resolutions"
ng-change=
"refreshMetricData()"
>
<select
ng-model=
"
ctrl.
target.intervalFactor"
class=
"tight-form-input input-mini"
ng-options=
"r.factor as r.label for r in
ctrl.
resolutions"
ng-change=
"
ctrl.
refreshMetricData()"
>
</select>
</li>
<li
class=
"tight-form-item"
>
<a
href=
"{{
linkToPrometheus()
}}"
target=
"_blank"
bs-tooltip=
"'Link to Graph in Prometheus'"
>
<a
href=
"{{
ctrl.linkToPrometheus
}}"
target=
"_blank"
bs-tooltip=
"'Link to Graph in Prometheus'"
>
<i
class=
"fa fa-share-square-o"
></i>
</a>
</li>
...
...
public/app/plugins/datasource/prometheus/query_ctrl.ts
View file @
efdd4a66
...
...
@@ -13,6 +13,8 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
metric
:
any
;
resolutions
:
any
;
oldTarget
:
any
;
suggestMetrics
:
any
;
linkToPrometheus
:
any
;
constructor
(
$scope
,
$injector
,
private
templateSrv
)
{
super
(
$scope
,
$injector
);
...
...
@@ -27,28 +29,33 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
});
$scope
.
$on
(
'typeahead-updated'
,
()
=>
{
$scope
.
$apply
(
this
.
inputMetric
);
this
.
$scope
.
$apply
(()
=>
{
this
.
target
.
expr
+=
this
.
target
.
metric
;
this
.
metric
=
''
;
this
.
refreshMetricData
();
});
});
// called from typeahead so need this
// here in order to ensure this ref
this
.
suggestMetrics
=
(
query
,
callback
)
=>
{
console
.
log
(
this
);
this
.
datasource
.
performSuggestQuery
(
query
).
then
(
callback
);
};
this
.
updateLink
();
}
refreshMetricData
()
{
if
(
!
_
.
isEqual
(
this
.
oldTarget
,
this
.
target
))
{
this
.
oldTarget
=
angular
.
copy
(
this
.
target
);
this
.
panelCtrl
.
refresh
();
this
.
updateLink
();
}
}
inputMetric
()
{
this
.
target
.
expr
+=
this
.
target
.
metric
;
this
.
metric
=
''
;
}
suggestMetrics
(
query
,
callback
)
{
this
.
datasource
.
performSuggestQuery
(
query
).
then
(
callback
);
}
linkToPrometheus
()
{
updateLink
()
{
var
range
=
this
.
panelCtrl
.
range
;
var
rangeDiff
=
Math
.
ceil
((
range
.
to
.
valueOf
()
-
range
.
from
.
valueOf
())
/
1000
);
var
endTime
=
range
.
to
.
utc
().
format
(
'YYYY-MM-DD HH:mm'
);
...
...
@@ -61,8 +68,8 @@ class PrometheusQueryCtrl extends QueryEditorCtrl {
tab
:
0
};
var
hash
=
encodeURIComponent
(
JSON
.
stringify
([
expr
]));
return
this
.
datasource
.
directUrl
+
'/graph#'
+
hash
;
}
;
this
.
linkToPrometheus
=
this
.
datasource
.
directUrl
+
'/graph#'
+
hash
;
}
}
export
{
PrometheusQueryCtrl
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment