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
2f78584c
Commit
2f78584c
authored
Feb 01, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
poc(plugin editors): experimential test for plugin editors
parent
3f945e88
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
216 additions
and
128 deletions
+216
-128
public/app/core/plugins/directive.ts
+0
-0
public/app/features/panel/panel.ts
+1
-38
public/app/features/panel/panel_directive.ts
+122
-84
public/app/features/panel/query_editor.ts
+77
-3
public/app/partials/metrics.html
+2
-2
public/app/plugins/datasource/grafana/module.ts
+14
-1
No files found.
public/app/core/plugins/directive.ts
0 → 100644
View file @
2f78584c
public/app/features/panel/panel.ts
View file @
2f78584c
...
@@ -4,44 +4,7 @@ import config from 'app/core/config';
...
@@ -4,44 +4,7 @@ import config from 'app/core/config';
import
{
PanelCtrl
}
from
'./panel_ctrl'
;
import
{
PanelCtrl
}
from
'./panel_ctrl'
;
import
{
MetricsPanelCtrl
}
from
'./metrics_panel_ctrl'
;
import
{
MetricsPanelCtrl
}
from
'./metrics_panel_ctrl'
;
import
{
PanelDirective
}
from
'./panel_directive'
;
export
class
DefaultPanelCtrl
extends
PanelCtrl
{
constructor
(
$scope
,
$injector
)
{
super
(
$scope
,
$injector
);
}
}
class
PanelDirective
{
template
:
string
;
templateUrl
:
string
;
bindToController
:
boolean
;
scope
:
any
;
controller
:
any
;
controllerAs
:
string
;
getDirective
()
{
if
(
!
this
.
controller
)
{
this
.
controller
=
DefaultPanelCtrl
;
}
return
{
template
:
this
.
template
,
templateUrl
:
this
.
templateUrl
,
controller
:
this
.
controller
,
controllerAs
:
'ctrl'
,
bindToController
:
true
,
scope
:
{
dashboard
:
"="
,
panel
:
"="
,
row
:
"="
},
link
:
(
scope
,
elem
,
attrs
,
ctrl
)
=>
{
ctrl
.
init
();
this
.
link
(
scope
,
elem
,
attrs
,
ctrl
);
}
};
}
link
(
scope
,
elem
,
attrs
,
ctrl
)
{
return
null
;
}
}
export
{
export
{
PanelCtrl
,
PanelCtrl
,
...
...
public/app/features/panel/panel_directive.
j
s
→
public/app/features/panel/panel_directive.
t
s
View file @
2f78584c
define
([
///<reference path="../../headers/common.d.ts" />
'angular'
,
'jquery'
,
],
function
(
angular
,
$
)
{
'use strict'
;
var
module
=
angular
.
module
(
'grafana.directives'
);
import
angular
from
'angular'
;
import
$
from
'jquery'
;
import
{
PanelCtrl
}
from
'./panel_ctrl'
;
export
class
DefaultPanelCtrl
extends
PanelCtrl
{
constructor
(
$scope
,
$injector
)
{
super
(
$scope
,
$injector
);
}
}
export
class
PanelDirective
{
template
:
string
;
templateUrl
:
string
;
bindToController
:
boolean
;
scope
:
any
;
controller
:
any
;
controllerAs
:
string
;
getDirective
()
{
if
(
!
this
.
controller
)
{
this
.
controller
=
DefaultPanelCtrl
;
}
module
.
directive
(
'grafanaPanel'
,
function
()
{
return
{
return
{
restrict
:
'E'
,
template
:
this
.
template
,
templateUrl
:
'app/features/panel/partials/panel.html'
,
templateUrl
:
this
.
templateUrl
,
transclude
:
true
,
controller
:
this
.
controller
,
scope
:
{
ctrl
:
"="
},
controllerAs
:
'ctrl'
,
link
:
function
(
scope
,
elem
)
{
bindToController
:
true
,
var
panelContainer
=
elem
.
find
(
'.panel-container'
);
scope
:
{
dashboard
:
"="
,
panel
:
"="
,
row
:
"="
},
var
ctrl
=
scope
.
ctrl
;
link
:
(
scope
,
elem
,
attrs
,
ctrl
)
=>
{
scope
.
$watchGroup
([
'ctrl.fullscreen'
,
'ctrl.height'
,
'ctrl.panel.height'
,
'ctrl.row.height'
],
function
()
{
ctrl
.
init
();
panelContainer
.
css
({
minHeight
:
ctrl
.
height
||
ctrl
.
panel
.
height
||
ctrl
.
row
.
height
,
display
:
'block'
});
this
.
link
(
scope
,
elem
,
attrs
,
ctrl
);
elem
.
toggleClass
(
'panel-fullscreen'
,
ctrl
.
fullscreen
?
true
:
false
);
});
}
}
};
};
});
}
link
(
scope
,
elem
,
attrs
,
ctrl
)
{
return
null
;
}
}
var
module
=
angular
.
module
(
'grafana.directives'
);
module
.
directive
(
'grafanaPanel'
,
function
()
{
return
{
restrict
:
'E'
,
templateUrl
:
'app/features/panel/partials/panel.html'
,
transclude
:
true
,
scope
:
{
ctrl
:
"="
},
link
:
function
(
scope
,
elem
)
{
var
panelContainer
=
elem
.
find
(
'.panel-container'
);
var
ctrl
=
scope
.
ctrl
;
scope
.
$watchGroup
([
'ctrl.fullscreen'
,
'ctrl.height'
,
'ctrl.panel.height'
,
'ctrl.row.height'
],
function
()
{
panelContainer
.
css
({
minHeight
:
ctrl
.
height
||
ctrl
.
panel
.
height
||
ctrl
.
row
.
height
,
display
:
'block'
});
elem
.
toggleClass
(
'panel-fullscreen'
,
ctrl
.
fullscreen
?
true
:
false
);
});
}
};
});
module
.
directive
(
'panelResizer'
,
function
(
$rootScope
)
{
module
.
directive
(
'panelResizer'
,
function
(
$rootScope
)
{
return
{
return
{
restrict
:
'E'
,
restrict
:
'E'
,
template
:
'<span class="resize-panel-handle"></span>'
,
template
:
'<span class="resize-panel-handle"></span>'
,
link
:
function
(
scope
,
elem
)
{
link
:
function
(
scope
,
elem
)
{
var
resizing
=
false
;
var
resizing
=
false
;
var
lastPanel
=
false
;
var
lastPanel
;
var
ctrl
=
scope
.
ctrl
;
var
ctrl
=
scope
.
ctrl
;
var
handleOffset
;
var
handleOffset
;
var
originalHeight
;
var
originalHeight
;
var
originalWidth
;
var
originalWidth
;
var
maxWidth
;
var
maxWidth
;
function
dragStartHandler
(
e
)
{
function
dragStartHandler
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
resizing
=
true
;
resizing
=
true
;
handleOffset
=
$
(
e
.
target
).
offset
();
handleOffset
=
$
(
e
.
target
).
offset
();
originalHeight
=
parseInt
(
ctrl
.
row
.
height
);
originalHeight
=
parseInt
(
ctrl
.
row
.
height
);
originalWidth
=
ctrl
.
panel
.
span
;
originalWidth
=
ctrl
.
panel
.
span
;
maxWidth
=
$
(
document
).
width
();
maxWidth
=
$
(
document
).
width
();
lastPanel
=
ctrl
.
row
.
panels
[
ctrl
.
row
.
panels
.
length
-
1
];
lastPanel
=
ctrl
.
row
.
panels
[
ctrl
.
row
.
panels
.
length
-
1
];
$
(
'body'
).
on
(
'mousemove'
,
moveHandler
);
$
(
'body'
).
on
(
'mousemove'
,
moveHandler
);
$
(
'body'
).
on
(
'mouseup'
,
dragEndHandler
);
$
(
'body'
).
on
(
'mouseup'
,
dragEndHandler
);
}
}
function
moveHandler
(
e
)
{
function
moveHandler
(
e
)
{
ctrl
.
row
.
height
=
originalHeight
+
(
e
.
pageY
-
handleOffset
.
top
);
ctrl
.
row
.
height
=
originalHeight
+
(
e
.
pageY
-
handleOffset
.
top
);
ctrl
.
panel
.
span
=
originalWidth
+
(((
e
.
pageX
-
handleOffset
.
left
)
/
maxWidth
)
*
12
);
ctrl
.
panel
.
span
=
originalWidth
+
(((
e
.
pageX
-
handleOffset
.
left
)
/
maxWidth
)
*
12
);
ctrl
.
panel
.
span
=
Math
.
min
(
Math
.
max
(
ctrl
.
panel
.
span
,
1
),
12
);
ctrl
.
panel
.
span
=
Math
.
min
(
Math
.
max
(
ctrl
.
panel
.
span
,
1
),
12
);
var
rowSpan
=
ctrl
.
dashboard
.
rowSpan
(
ctrl
.
row
);
var
rowSpan
=
ctrl
.
dashboard
.
rowSpan
(
ctrl
.
row
);
// auto adjust other panels
// auto adjust other panels
if
(
Math
.
floor
(
rowSpan
)
<
14
)
{
if
(
Math
.
floor
(
rowSpan
)
<
14
)
{
// last panel should not push row down
// last panel should not push row down
if
(
lastPanel
===
ctrl
.
panel
&&
rowSpan
>
12
)
{
if
(
lastPanel
===
ctrl
.
panel
&&
rowSpan
>
12
)
{
lastPanel
.
span
-=
rowSpan
-
12
;
lastPanel
.
span
-=
rowSpan
-
12
;
}
}
else
if
(
lastPanel
!==
ctrl
.
panel
)
{
// reduce width of last panel so total in row is 12
// reduce width of last panel so total in row is 12
else
if
(
lastPanel
!==
ctrl
.
panel
)
{
lastPanel
.
span
=
lastPanel
.
span
-
(
rowSpan
-
12
);
lastPanel
.
span
=
lastPanel
.
span
-
(
rowSpan
-
12
);
lastPanel
.
span
=
Math
.
min
(
Math
.
max
(
lastPanel
.
span
,
1
),
12
);
lastPanel
.
span
=
Math
.
min
(
Math
.
max
(
lastPanel
.
span
,
1
),
12
);
}
}
}
scope
.
$apply
(
function
()
{
scope
.
$broadcast
(
'render'
);
});
}
}
function
dragEndHandler
()
{
scope
.
$apply
(
function
()
{
// if close to 12
scope
.
$broadcast
(
'render'
);
var
rowSpan
=
ctrl
.
dashboard
.
rowSpan
(
ctrl
.
row
);
});
if
(
rowSpan
<
12
&&
rowSpan
>
11
)
{
}
lastPanel
.
span
+=
12
-
rowSpan
;
}
scope
.
$apply
(
function
()
{
$rootScope
.
$broadcast
(
'render'
);
});
$
(
'body'
).
off
(
'mousemove'
,
moveHandler
);
function
dragEndHandler
()
{
$
(
'body'
).
off
(
'mouseup'
,
dragEndHandler
);
// if close to 12
var
rowSpan
=
ctrl
.
dashboard
.
rowSpan
(
ctrl
.
row
);
if
(
rowSpan
<
12
&&
rowSpan
>
11
)
{
lastPanel
.
span
+=
12
-
rowSpan
;
}
}
elem
.
on
(
'mousedown'
,
dragStartHandler
);
scope
.
$apply
(
function
()
{
$rootScope
.
$broadcast
(
'render'
);
scope
.
$on
(
"$destroy"
,
function
()
{
elem
.
off
(
'mousedown'
,
dragStartHandler
);
});
});
$
(
'body'
).
off
(
'mousemove'
,
moveHandler
);
$
(
'body'
).
off
(
'mouseup'
,
dragEndHandler
);
}
}
};
});
elem
.
on
(
'mousedown'
,
dragStartHandler
);
scope
.
$on
(
"$destroy"
,
function
()
{
elem
.
off
(
'mousedown'
,
dragStartHandler
);
});
}
};
});
});
public/app/features/panel/query_editor.ts
View file @
2f78584c
///<reference path="../../headers/common.d.ts" />
///<reference path="../../headers/common.d.ts" />
import
angular
from
'angular'
;
import
angular
from
'angular'
;
import
_
from
'lodash'
;
var
directivesModule
=
angular
.
module
(
'grafana.directives'
);
function
pluginDirectiveLoader
(
$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
=>
{
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
};
});
});
}
}
}
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
);
directivesModule
.
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
);
});
}
};
}
/** @ngInject */
/** @ngInject */
function
metricsQueryEditor
(
dynamicDirectiveSrv
,
datasourceSrv
)
{
function
metricsQueryEditor
(
dynamicDirectiveSrv
,
datasourceSrv
)
{
...
@@ -43,6 +117,6 @@ function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
...
@@ -43,6 +117,6 @@ function metricsQueryOptions(dynamicDirectiveSrv, datasourceSrv) {
});
});
}
}
angular
.
module
(
'grafana.directives'
)
directivesModule
.
directive
(
'pluginDirectiveLoader'
,
pluginDirectiveLoader
);
.
directive
(
'metricsQueryEditor'
,
metricsQueryEditor
)
directivesModule
.
directive
(
'metricsQueryEditor'
,
metricsQueryEditor
);
.
directive
(
'metricsQueryOptions'
,
metricsQueryOptions
);
directivesModule
.
directive
(
'metricsQueryOptions'
,
metricsQueryOptions
);
public/app/partials/metrics.html
View file @
2f78584c
<div
class=
"editor-row"
>
<div
class=
"editor-row"
>
<div
class=
"tight-form-container"
>
<div
class=
"tight-form-container"
>
<
metrics-query-editor
ng-repeat=
"target in ctrl.panel.targets"
ng-class=
"{'tight-form-disabled': target.hide}"
>
<
plugin-directive-loader
type=
"metrics-query-editor"
ng-repeat=
"target in ctrl.panel.targets"
ng-class=
"{'tight-form-disabled': target.hide}"
>
</
metrics-query-edito
r>
</
plugin-directive-loade
r>
</div>
</div>
<div
style=
"margin: 20px 0 0 0"
>
<div
style=
"margin: 20px 0 0 0"
>
...
...
public/app/plugins/datasource/grafana/module.ts
View file @
2f78584c
...
@@ -9,10 +9,23 @@ function grafanaMetricsQueryEditor() {
...
@@ -9,10 +9,23 @@ function grafanaMetricsQueryEditor() {
return
{
templateUrl
:
'app/plugins/datasource/grafana/partials/query.editor.html'
};
return
{
templateUrl
:
'app/plugins/datasource/grafana/partials/query.editor.html'
};
}
}
export
class
MetricsQueryEditor
{
panelCtrl
:
any
;
target
:
any
;
}
class
GrafanaMetricsQueryEditor
extends
MetricsQueryEditor
{
static
templateUrl
=
'app/plugins/datasource/grafana/partials/query.editor.html'
;
constructor
()
{
super
();
console
.
log
(
'this is a metrics editor'
,
this
.
panelCtrl
,
this
.
target
);
}
}
export
{
export
{
GrafanaDatasource
,
GrafanaDatasource
,
GrafanaDatasource
as
Datasource
,
GrafanaDatasource
as
Datasource
,
grafanaMetricsQueryEditor
as
metricsQueryEditor
GrafanaMetricsQueryEditor
as
MetricsQueryEditor
,
};
};
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