@@ -44,17 +44,17 @@ export const addPageThunk = () => (dispatch: any, getState: any) => {
4444
4545export const loadDashboardThunk = ( text ) => ( dispatch : any , getState : any ) => {
4646 try {
47- if ( text . length == 0 ) {
48- throw ( "No dashboard file specified. Did you select a file?" )
47+ if ( text . length == 0 ) {
48+ throw ( "No dashboard file specified. Did you select a file?" )
4949 }
50- if ( text . trim ( ) == "{}" ) {
50+ if ( text . trim ( ) == "{}" ) {
5151 dispatch ( resetDashboardState ( ) ) ;
52- return
52+ return
5353 }
5454 const dashboard = JSON . parse ( text ) ;
55-
55+
5656 // Attempt upgrade
57- if ( dashboard [ "version" ] == "1.1" ) {
57+ if ( dashboard [ "version" ] == "1.1" ) {
5858 const upgradedDashboard = { } ;
5959 upgradedDashboard [ "title" ] = dashboard [ "title" ] ;
6060 upgradedDashboard [ "version" ] = "2.0" ;
@@ -69,10 +69,10 @@ export const loadDashboardThunk = (text) => (dispatch: any, getState: any) => {
6969 const newPageReports = [ ] ;
7070 p [ "reports" ] . forEach ( r => {
7171 // only migrate value report types.
72- if ( [ "table" , "graph" , "bar" , "line" , "map" , "value" , "json" , "select" , "iframe" , "text" ] . indexOf ( r [ "type" ] ) == - 1 ) {
72+ if ( [ "table" , "graph" , "bar" , "line" , "map" , "value" , "json" , "select" , "iframe" , "text" ] . indexOf ( r [ "type" ] ) == - 1 ) {
7373 return
7474 }
75- if ( r [ "type" ] == "select" ) {
75+ if ( r [ "type" ] == "select" ) {
7676 r [ "query" ] = "" ;
7777 }
7878 const newPageReport = {
@@ -83,9 +83,9 @@ export const loadDashboardThunk = (text) => (dispatch: any, getState: any) => {
8383 parameters : r [ "parameters" ] ,
8484 query : r [ "query" ] ,
8585 selection : { } ,
86- settings : { }
86+ settings : { }
8787 }
88-
88+
8989 newPageReports . push ( newPageReport ) ;
9090 } )
9191 newPage [ "reports" ] = newPageReports ;
@@ -95,38 +95,60 @@ export const loadDashboardThunk = (text) => (dispatch: any, getState: any) => {
9595
9696 dispatch ( setDashboard ( upgradedDashboard ) )
9797 dispatch ( createNotificationThunk ( "Successfully upgraded dashboard" , "Your old dashboard was migrated to version 2.0. You might need to refresh this page." ) ) ;
98- return
98+ return
9999 }
100- if ( dashboard [ "version" ] != "2.0" ) {
101- throw ( "Invalid dashboard version: " + dashboard . version ) ;
100+ if ( dashboard [ "version" ] != "2.0" ) {
101+ throw ( "Invalid dashboard version: " + dashboard . version ) ;
102102 }
103-
103+
104104 dispatch ( setDashboard ( dashboard ) )
105105
106106 } catch ( e ) {
107107 dispatch ( createNotificationThunk ( "Unable to load dashboard" , e ) ) ;
108108 }
109109}
110110
111- export const saveDashboardToNeo4jThunk = ( dashboard , date , user ) => ( dispatch : any , getState : any ) => {
111+ export const saveDashboardToNeo4jThunk = ( driver , dashboard , date , user ) => ( dispatch : any , getState : any ) => {
112112 try {
113113 const uuid = createUUID ( ) ;
114114 const title = dashboard . title ;
115115 // const user = user;
116116 // const date = date;
117117 const version = dashboard . version ;
118118 const content = dashboard ;
119- console . log ( uuid ) ;
120- dispatch ( createNotificationThunk ( "Unable to save dashboard to Neo4j" , "" ) ) ;
119+ runCypherQuery ( driver , getState ( ) . application . connection . database ,
120+ "CREATE (n:_Neodash_Dashboard) SET n.uuid = $uuid, n.title = $title, n.version = $version, n.user = $user, n.content = $content, n.date = datetime($date) RETURN $uuid as uuid" ,
121+ { uuid : uuid , title : title , version : version , user : user , content : JSON . stringify ( dashboard , null , 2 ) , date : date } ,
122+ { } , [ "uuid" ] , 1 , ( ) => { return } , ( records ) => {
123+ console . log ( records ) ;
124+ dispatch ( createNotificationThunk ( "🎉 Success!" , "Your current dashboard was saved to Neo4j." ) )
125+ } ) ;
126+
121127 } catch ( e ) {
122128 dispatch ( createNotificationThunk ( "Unable to save dashboard to Neo4j" , e ) ) ;
123129 }
124130}
125131
126132export const loadDashboardFromNeo4jThunk = ( driver , uuid , callback ) => ( dispatch : any , getState : any ) => {
127133 try {
128- runCypherQuery ( driver , getState ( ) . application . connection . database , "RETURN $uuid as dashboard" , { uuid : uuid } , { } , [ "dashboard" ] , 1 , ( ) => { return } , ( records ) => callback ( records [ 0 ] [ '_fields' ] [ 0 ] ) )
134+ runCypherQuery ( driver , getState ( ) . application . connection . database , "MATCH (n:_Neodash_Dashboard) WHERE n.uuid = $uuid RETURN n.content as dashboard" , { uuid : uuid } , { } , [ "dashboard" ] , 1 , ( ) => { return } , ( records ) => callback ( records [ 0 ] [ '_fields' ] [ 0 ] ) )
129135 } catch ( e ) {
130136 dispatch ( createNotificationThunk ( "Unable to load dashboard to Neo4j" , e ) ) ;
131137 }
132- }
138+ }
139+
140+ export const loadDashboardListFromNeo4jThunk = ( driver , callback ) => ( dispatch : any , getState : any ) => {
141+ try {
142+ runCypherQuery ( driver , getState ( ) . application . connection . database ,
143+ "MATCH (n:_Neodash_Dashboard) RETURN n.uuid as id, n.title as title, toString(n.date) as date, n.user as author ORDER BY date DESC" ,
144+ { } , { } , [ "id, title, date, user" ] , 1000 , ( ) => { return } , ( records ) => {
145+ const result = records . map ( r => {
146+ return { id : r [ "_fields" ] [ 0 ] , title : r [ "_fields" ] [ 1 ] , date : r [ "_fields" ] [ 2 ] , author : r [ "_fields" ] [ 3 ] } ;
147+ } ) ;
148+ callback ( result ) ;
149+ } )
150+ } catch ( e ) {
151+ dispatch ( createNotificationThunk ( "Unable to load dashboard list from Neo4j" , e ) ) ;
152+ }
153+ }
154+
0 commit comments