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
35403c18
Commit
35403c18
authored
Jun 19, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: react panel makeover mini progress
parent
542da8dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
77 deletions
+102
-77
public/app/core/directives/dash_class.ts
+1
-3
public/app/features/dashboard/dashgrid/DashboardGrid.tsx
+1
-0
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
+73
-4
public/app/features/dashboard/panel_model.ts
+6
-0
public/app/features/dashboard/specs/AddPanelPanel.jest.tsx
+1
-6
public/app/features/dashboard/view_state_srv.ts
+20
-64
No files found.
public/app/core/directives/dash_class.ts
View file @
35403c18
...
...
@@ -10,9 +10,7 @@ coreModule.directive('dashClass', function($timeout) {
});
});
$scope
.
onAppEvent
(
'panel-fullscreen-exit'
,
function
()
{
elem
.
toggleClass
(
'panel-in-fullscreen'
,
false
);
});
elem
.
toggleClass
(
'panel-in-fullscreen'
,
$scope
.
ctrl
.
dashboard
.
meta
.
fullscreen
===
true
);
$scope
.
$watch
(
'ctrl.playlistSrv.isPlaying'
,
function
(
newValue
)
{
elem
.
toggleClass
(
'playlist-active'
,
newValue
===
true
);
...
...
public/app/features/dashboard/dashgrid/DashboardGrid.tsx
View file @
35403c18
...
...
@@ -175,6 +175,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
const
panelElements
=
[];
for
(
let
panel
of
this
.
dashboard
.
panels
)
{
console
.
log
(
'panel.fullscreen'
,
panel
.
fullscreen
);
const
panelClasses
=
classNames
({
panel
:
true
,
'panel--fullscreen'
:
panel
.
fullscreen
});
panelElements
.
push
(
<
div
key=
{
panel
.
id
.
toString
()
}
className=
{
panelClasses
}
>
...
...
public/app/features/dashboard/dashgrid/DashboardPanel.tsx
View file @
35403c18
import
React
from
'react'
;
import
$
from
'jquery'
;
import
config
from
'app/core/config'
;
import
classNames
from
'classnames'
;
import
{
PanelModel
}
from
'../panel_model'
;
...
...
@@ -7,6 +8,11 @@ import { AttachedPanel } from './PanelLoader';
import
{
DashboardRow
}
from
'./DashboardRow'
;
import
{
AddPanelPanel
}
from
'./AddPanelPanel'
;
import
{
importPluginModule
}
from
'app/features/plugins/plugin_loader'
;
import
{
store
}
from
'app/stores/store'
;
import
{
GRID_CELL_HEIGHT
,
GRID_CELL_VMARGIN
}
from
'app/core/constants'
;
const
TITLE_HEIGHT
=
27
;
const
PANEL_BORDER
=
2
;
export
interface
DashboardPanelProps
{
panel
:
PanelModel
;
...
...
@@ -61,13 +67,40 @@ export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
PanelComponent
=
this
.
pluginExports
.
PanelComponent
;
}
let
panelContentStyle
=
{
height
:
this
.
getPanelHeight
(),
};
return
(
<
div
className=
"panel-container"
>
<
PanelHeader
panel=
{
this
.
props
.
panel
}
dashboard=
{
this
.
props
.
dashboard
}
/>
<
div
className=
"panel-content"
>
{
PanelComponent
&&
<
PanelComponent
/>
}
</
div
>
<
div
>
<
div
className=
"panel-container"
>
<
PanelHeader
panel=
{
this
.
props
.
panel
}
dashboard=
{
this
.
props
.
dashboard
}
/>
<
div
className=
"panel-content"
style=
{
panelContentStyle
}
>
{
PanelComponent
&&
<
PanelComponent
/>
}
</
div
>
</
div
>
<
div
>
{
this
.
props
.
panel
.
isEditing
&&
<
PanelEditor
panel=
{
this
.
props
.
panel
}
dashboard=
{
this
.
props
.
dashboard
}
/>
}
</
div
>
</
div
>
);
}
getPanelHeight
()
{
const
panel
=
this
.
props
.
panel
;
let
height
=
0
;
if
(
panel
.
fullscreen
)
{
var
docHeight
=
$
(
window
).
height
();
var
editHeight
=
Math
.
floor
(
docHeight
*
0.4
);
var
fullscreenHeight
=
Math
.
floor
(
docHeight
*
0.8
);
height
=
panel
.
isEditing
?
editHeight
:
fullscreenHeight
;
}
else
{
height
=
panel
.
gridPos
.
h
*
GRID_CELL_HEIGHT
+
(
panel
.
gridPos
.
h
-
1
)
*
GRID_CELL_VMARGIN
;
}
return
height
-
PANEL_BORDER
+
TITLE_HEIGHT
;
}
}
interface
PanelHeaderProps
{
...
...
@@ -77,7 +110,11 @@ interface PanelHeaderProps {
export
class
PanelHeader
extends
React
.
Component
<
PanelHeaderProps
,
any
>
{
onEditPanel
=
()
=>
{
this
.
props
.
dashboard
.
setViewMode
(
this
.
props
.
panel
,
true
,
true
);
store
.
view
.
updateQuery
({
panelId
:
this
.
props
.
panel
.
id
,
edit
:
true
,
fullscreen
:
true
,
});
};
render
()
{
...
...
@@ -124,3 +161,35 @@ export class PanelHeader extends React.Component<PanelHeaderProps, any> {
);
}
}
interface
PanelEditorProps
{
panel
:
PanelModel
;
dashboard
:
DashboardModel
;
}
export
class
PanelEditor
extends
React
.
Component
<
PanelEditorProps
,
any
>
{
render
()
{
return
(
<
div
className=
"tabbed-view tabbed-view--panel-edit"
>
<
div
className=
"tabbed-view-header"
>
<
h3
className=
"tabbed-view-panel-title"
>
{
this
.
props
.
panel
.
type
}
</
h3
>
<
ul
className=
"gf-tabs"
>
<
li
className=
"gf-tabs-item"
>
<
a
className=
"gf-tabs-link active"
>
Queries
</
a
>
</
li
>
<
li
className=
"gf-tabs-item"
>
<
a
className=
"gf-tabs-link"
>
Visualization
</
a
>
</
li
>
</
ul
>
<
button
className=
"tabbed-view-close-btn"
ng
-
click=
"ctrl.exitFullscreen();"
>
<
i
className=
"fa fa-remove"
/>
</
button
>
</
div
>
<
div
className=
"tabbed-view-body"
>
testing
</
div
>
</
div
>
);
}
}
public/app/features/dashboard/panel_model.ts
View file @
35403c18
...
...
@@ -13,6 +13,7 @@ const notPersistedProperties: { [str: string]: boolean } = {
events
:
true
,
fullscreen
:
true
,
isEditing
:
true
,
editModeInitiated
:
true
,
};
export
class
PanelModel
{
...
...
@@ -36,6 +37,7 @@ export class PanelModel {
fullscreen
:
boolean
;
isEditing
:
boolean
;
events
:
Emitter
;
editModeInitiated
:
boolean
;
constructor
(
model
)
{
this
.
events
=
new
Emitter
();
...
...
@@ -91,6 +93,10 @@ export class PanelModel {
this
.
events
.
emit
(
'panel-size-changed'
);
}
initEditMode
()
{
this
.
events
.
emit
(
'panel-init-edit-mode'
);
}
destroy
()
{
this
.
events
.
removeAllListeners
();
}
...
...
public/app/features/dashboard/specs/AddPanelPanel.jest.tsx
View file @
35403c18
...
...
@@ -77,13 +77,8 @@ describe('AddPanelPanel', () => {
dashboardMock
=
{
toggleRow
:
jest
.
fn
()
};
getPanelContainer
=
jest
.
fn
().
mockReturnValue
({
getDashboard
:
jest
.
fn
().
mockReturnValue
(
dashboardMock
),
getPanelLoader
:
jest
.
fn
(),
});
panel
=
new
PanelModel
({
collapsed
:
false
});
wrapper
=
shallow
(<
AddPanelPanel
panel=
{
panel
}
getPanelContainer=
{
getPanelContainer
}
/>);
wrapper
=
shallow
(<
AddPanelPanel
panel=
{
panel
}
dashboard=
{
dashboardMock
}
/>);
});
it
(
'should fetch all panels sorted with core plugins first'
,
()
=>
{
...
...
public/app/features/dashboard/view_state_srv.ts
View file @
35403c18
...
...
@@ -33,10 +33,6 @@ export class DashboardViewState {
self
.
update
(
payload
);
});
$scope
.
onAppEvent
(
'panel-initialized'
,
function
(
evt
,
payload
)
{
self
.
registerPanel
(
payload
.
scope
);
});
// this marks changes to location during this digest cycle as not to add history item
// don't want url changes like adding orgId to add browser history
$location
.
replace
();
...
...
@@ -124,102 +120,62 @@ export class DashboardViewState {
}
syncState
()
{
if
(
this
.
panelScopes
.
length
===
0
)
{
return
;
}
if
(
this
.
dashboard
.
meta
.
fullscreen
)
{
var
panelScope
=
this
.
getPanelScope
(
this
.
state
.
panelId
);
if
(
!
panelScope
)
{
var
panel
=
this
.
dashboard
.
getPanelById
(
this
.
state
.
panelId
);
if
(
!
panel
)
{
return
;
}
if
(
this
.
fullscreenPanel
)
{
// if already fullscreen
if
(
this
.
fullscreenPanel
===
panel
Scope
&&
this
.
editStateChanged
===
false
)
{
if
(
this
.
fullscreenPanel
===
panel
&&
this
.
editStateChanged
===
false
)
{
return
;
}
else
{
this
.
leaveFullscreen
(
false
);
}
}
if
(
!
panelScope
.
ctrl
.
editModeInitiated
)
{
panelScope
.
ctrl
.
initEditMode
();
}
if
(
!
panelScope
.
ctrl
.
fullscreen
)
{
this
.
enterFullscreen
(
panelScope
);
if
(
!
panel
.
fullscreen
)
{
this
.
enterFullscreen
(
panel
);
}
}
else
if
(
this
.
fullscreenPanel
)
{
this
.
leaveFullscreen
(
true
);
}
}
getPanelScope
(
id
)
{
return
_
.
find
(
this
.
panelScopes
,
function
(
panelScope
)
{
return
panelScope
.
ctrl
.
panel
.
id
===
id
;
});
}
leaveFullscreen
(
render
)
{
var
self
=
this
;
var
ctrl
=
self
.
fullscreenPanel
.
ctrl
;
ctrl
.
editMode
=
false
;
ctrl
.
fullscreen
=
false
;
var
panel
=
this
.
fullscreenPanel
;
this
.
dashboard
.
setViewMode
(
ctrl
.
panel
,
false
,
false
);
this
.
$scope
.
appEvent
(
'panel-fullscreen-exit'
,
{
panelId
:
ctrl
.
panel
.
id
});
this
.
dashboard
.
setViewMode
(
panel
,
false
,
false
);
this
.
$scope
.
appEvent
(
'dash-scroll'
,
{
restore
:
true
});
if
(
!
render
)
{
return
false
;
}
this
.
$timeout
(
function
()
{
if
(
self
.
oldTimeRange
!==
ctrl
.
rang
e
)
{
self
.
$rootScope
.
$broadcast
(
'refresh'
);
this
.
$timeout
(
()
=>
{
if
(
this
.
oldTimeRange
!==
this
.
dashboard
.
tim
e
)
{
this
.
$rootScope
.
$broadcast
(
'refresh'
);
}
else
{
self
.
$rootScope
.
$broadcast
(
'render'
);
this
.
$rootScope
.
$broadcast
(
'render'
);
}
delete
self
.
fullscreenPanel
;
delete
this
.
fullscreenPanel
;
});
return
true
;
}
enterFullscreen
(
panelScope
)
{
var
ctrl
=
panelScope
.
ctrl
;
ctrl
.
editMode
=
this
.
state
.
edit
&&
this
.
dashboard
.
meta
.
canEdit
;
ctrl
.
fullscreen
=
true
;
enterFullscreen
(
panel
)
{
const
isEditing
=
this
.
state
.
edit
&&
this
.
dashboard
.
meta
.
canEdit
;
this
.
oldTimeRange
=
ctrl
.
rang
e
;
this
.
fullscreenPanel
=
panel
Scope
;
this
.
oldTimeRange
=
this
.
dashboard
.
tim
e
;
this
.
fullscreenPanel
=
panel
;
// Firefox doesn't return scrollTop position properly if 'dash-scroll' is emitted after setViewMode()
this
.
$scope
.
appEvent
(
'dash-scroll'
,
{
animate
:
false
,
pos
:
0
});
this
.
dashboard
.
setViewMode
(
ctrl
.
panel
,
true
,
ctrl
.
editMode
);
this
.
$scope
.
appEvent
(
'panel-fullscreen-enter'
,
{
panelId
:
ctrl
.
panel
.
id
});
}
registerPanel
(
panelScope
)
{
var
self
=
this
;
self
.
panelScopes
.
push
(
panelScope
);
if
(
!
self
.
dashboard
.
meta
.
soloMode
)
{
if
(
self
.
state
.
panelId
===
panelScope
.
ctrl
.
panel
.
id
)
{
if
(
self
.
state
.
edit
)
{
panelScope
.
ctrl
.
editPanel
();
}
else
{
panelScope
.
ctrl
.
viewPanel
();
}
}
}
var
unbind
=
panelScope
.
$on
(
'$destroy'
,
function
()
{
self
.
panelScopes
=
_
.
without
(
self
.
panelScopes
,
panelScope
);
unbind
();
});
console
.
log
(
'viewstatesrv.setViewMode'
);
this
.
dashboard
.
setViewMode
(
panel
,
true
,
isEditing
);
}
}
...
...
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