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
60f700a1
Commit
60f700a1
authored
Feb 02, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: dashboard react
parent
9e33f8b7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
149 additions
and
9 deletions
+149
-9
public/app/features/dashboard/containers/DashboardCtrl.ts
+0
-6
public/app/features/dashboard/containers/DashboardPage.tsx
+138
-0
public/app/features/dashboard/state/initDashboard.ts
+5
-0
public/app/routes/routes.ts
+6
-3
No files found.
public/app/features/dashboard/containers/DashboardCtrl.ts
View file @
60f700a1
...
...
@@ -31,12 +31,6 @@ export class DashboardCtrl {
// temp hack due to way dashboards are loaded
// can't use controllerAs on route yet
$scope
.
ctrl
=
this
;
// TODO: break out settings view to separate view & controller
this
.
editTab
=
0
;
// funcs called from React component bindings and needs this binding
this
.
getPanelContainer
=
this
.
getPanelContainer
.
bind
(
this
);
}
setupDashboard
(
data
)
{
...
...
public/app/features/dashboard/containers/DashboardPage.tsx
0 → 100644
View file @
60f700a1
// Libraries
import
React
,
{
Component
}
from
'react'
;
import
{
hot
}
from
'react-hot-loader'
;
import
{
connect
}
from
'react-redux'
;
// Utils & Services
import
locationUtil
from
'app/core/utils/location_util'
;
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
createErrorNotification
}
from
'app/core/copy/appNotification'
;
// Components
import
{
LoadingPlaceholder
}
from
'@grafana/ui'
;
// Redux
import
{
updateLocation
}
from
'app/core/actions'
;
import
{
notifyApp
}
from
'app/core/actions'
;
// Types
import
{
StoreState
}
from
'app/types'
;
import
{
DashboardModel
}
from
'app/features/dashboard/state'
;
interface
Props
{
panelId
:
string
;
urlUid
?:
string
;
urlSlug
?:
string
;
urlType
?:
string
;
$scope
:
any
;
$injector
:
any
;
updateLocation
:
typeof
updateLocation
;
notifyApp
:
typeof
notifyApp
;
}
interface
State
{
dashboard
:
DashboardModel
|
null
;
notFound
:
boolean
;
}
export
class
DashboardPage
extends
Component
<
Props
,
State
>
{
state
:
State
=
{
dashboard
:
null
,
notFound
:
false
,
};
async
componentDidMount
()
{
const
{
$injector
,
urlUid
,
urlType
,
urlSlug
}
=
this
.
props
;
// handle old urls with no uid
if
(
!
urlUid
&&
!
(
urlType
===
'script'
||
urlType
===
'snapshot'
))
{
this
.
redirectToNewUrl
();
return
;
}
const
loaderSrv
=
$injector
.
get
(
'dashboardLoaderSrv'
);
const
dashDTO
=
await
loaderSrv
.
loadDashboard
(
urlType
,
urlSlug
,
urlUid
);
try
{
this
.
initDashboard
(
dashDTO
);
}
catch
(
err
)
{
this
.
props
.
notifyApp
(
createErrorNotification
(
'Failed to init dashboard'
,
err
.
toString
()));
console
.
log
(
err
);
}
}
redirectToNewUrl
()
{
getBackendSrv
()
.
getDashboardBySlug
(
this
.
props
.
urlSlug
)
.
then
(
res
=>
{
if
(
res
)
{
const
url
=
locationUtil
.
stripBaseFromUrl
(
res
.
meta
.
url
.
replace
(
'/d/'
,
'/d-solo/'
));
this
.
props
.
updateLocation
(
url
);
}
});
}
initDashboard
(
dashDTO
:
any
)
{
const
dashboard
=
new
DashboardModel
(
dashDTO
.
dashboard
,
dashDTO
.
meta
);
// init services
this
.
timeSrv
.
init
(
dashboard
);
this
.
annotationsSrv
.
init
(
dashboard
);
// template values service needs to initialize completely before
// the rest of the dashboard can load
this
.
variableSrv
.
init
(
dashboard
)
// template values failes are non fatal
.
catch
(
this
.
onInitFailed
.
bind
(
this
,
'Templating init failed'
,
false
))
// continue
.
finally
(()
=>
{
this
.
dashboard
=
dashboard
;
this
.
dashboard
.
processRepeats
();
this
.
dashboard
.
updateSubmenuVisibility
();
this
.
dashboard
.
autoFitPanels
(
window
.
innerHeight
);
this
.
unsavedChangesSrv
.
init
(
dashboard
,
this
.
$scope
);
// TODO refactor ViewStateSrv
this
.
$scope
.
dashboard
=
dashboard
;
this
.
dashboardViewState
=
this
.
dashboardViewStateSrv
.
create
(
this
.
$scope
);
this
.
keybindingSrv
.
setupDashboardBindings
(
this
.
$scope
,
dashboard
);
this
.
setWindowTitleAndTheme
();
appEvents
.
emit
(
'dashboard-initialized'
,
dashboard
);
})
.
catch
(
this
.
onInitFailed
.
bind
(
this
,
'Dashboard init failed'
,
true
));
this
.
setState
({
dashboard
});
}
render
()
{
const
{
notFound
,
dashboard
}
=
this
.
state
;
if
(
notFound
)
{
return
<
div
className=
"alert alert-error"
>
Dashboard not found
</
div
>;
}
if
(
!
dashboard
)
{
return
<
LoadingPlaceholder
text=
"Loading dashboard"
/>;
}
return
<
div
>
title:
{
dashboard
.
title
}
</
div
>;
}
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
({
urlUid
:
state
.
location
.
routeParams
.
uid
,
urlSlug
:
state
.
location
.
routeParams
.
slug
,
urlType
:
state
.
location
.
routeParams
.
type
,
panelId
:
state
.
location
.
query
.
panelId
,
});
const
mapDispatchToProps
=
{
updateLocation
,
notifyApp
,
};
export
default
hot
(
module
)(
connect
(
mapStateToProps
,
mapDispatchToProps
)(
DashboardPage
));
public/app/features/dashboard/state/initDashboard.ts
0 → 100644
View file @
60f700a1
export
function
initDashboard
(
dashboard
:
DashboardModel
,
$injector
:
any
,
$scope
:
any
)
{
}
public/app/routes/routes.ts
View file @
60f700a1
...
...
@@ -20,6 +20,7 @@ import DataSourceDashboards from 'app/features/datasources/DataSourceDashboards'
import
DataSourceSettingsPage
from
'../features/datasources/settings/DataSourceSettingsPage'
;
import
OrgDetailsPage
from
'../features/org/OrgDetailsPage'
;
import
SoloPanelPage
from
'../features/dashboard/containers/SoloPanelPage'
;
import
DashboardPage
from
'../features/dashboard/containers/DashboardPage'
;
import
config
from
'app/core/config'
;
/** @ngInject */
...
...
@@ -34,10 +35,12 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
pageClass
:
'page-dashboard'
,
})
.
when
(
'/d/:uid/:slug'
,
{
templateUrl
:
'public/app/partials/dashboard.html'
,
controller
:
'LoadDashboardCtrl'
,
reloadOnSearch
:
false
,
template
:
'<react-container />'
,
pageClass
:
'page-dashboard'
,
reloadOnSearch
:
false
,
resolve
:
{
component
:
()
=>
DashboardPage
,
},
})
.
when
(
'/d/:uid'
,
{
templateUrl
:
'public/app/partials/dashboard.html'
,
...
...
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