Skip to content

Commit 9dba1d8

Browse files
author
Tommaso Giachi
committed
Added on NoSqlConnector (FindAllGenericEntities)
Little dev of frontend
1 parent 5df240b commit 9dba1d8

23 files changed

+510
-667
lines changed

Neon.Api/Interfaces/NoSql/INoSqlConnector.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface INoSqlConnector
1515

1616
List<TEntity> List<TEntity>(string collectionName) where TEntity : class, INeonEntity;
1717

18+
List<object> FindAllGeneric(string collectionName);
19+
1820
IQueryable<TEntity> Query<TEntity>(string collectionName) where TEntity : class, INeonEntity;
1921

2022
TEntity Insert<TEntity>(string collectionName, TEntity obj) where TEntity : class, INeonEntity;

Neon.Api/Interfaces/Services/IIoTService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IIoTService : INeonService
2222

2323
T GetEntityByType<T>(string name, string type) where T : NeonIoTBaseEntity;
2424

25-
List<INeonIoTEntity> GetEntities();
25+
List<object> GetEntities();
2626

2727
List<T> GetEntitiesByType<T>() where T : class, INeonIoTEntity;
2828

Neon.Engine/NoSqlConnector/FlatJsonDbConnector.cs

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public List<TEntity> List<TEntity>(string collectionName) where TEntity : class,
5656
return _dataStore.GetCollection<TEntity>(collectionName).AsQueryable().ToList();
5757
}
5858

59+
public List<object> FindAllGeneric(string collectionName)
60+
{
61+
return _dataStore.GetCollection<object>(collectionName).AsQueryable().ToList();
62+
}
63+
5964
public IQueryable<TEntity> Query<TEntity>(string collectionName) where TEntity : class, INeonEntity
6065
{
6166
return _dataStore.GetCollection<TEntity>(collectionName).AsQueryable().AsQueryable();

Neon.Engine/NoSqlConnector/LiteDbConnector.cs

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public List<TEntity> List<TEntity>(string collectionName) where TEntity :class,
7676

7777
}
7878

79+
public List<object> FindAllGeneric(string collectionName)
80+
{
81+
return _liteDatabase.GetCollection<object>(collectionName).FindAll().ToList();
82+
}
83+
7984
public IQueryable<TEntity> Query<TEntity>(string collectionName) where TEntity : class,INeonEntity
8085
{
8186
lock (_databaseLock)

Neon.Engine/NoSqlConnector/MongoDbConnector.cs

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public List<TEntity> List<TEntity>(string collectionName) where TEntity : class,
5252
return _mongoDatabase.GetCollection<TEntity>(collectionName).FindSync(entity => true).ToList();
5353
}
5454

55+
public List<object> FindAllGeneric(string collectionName)
56+
{
57+
return _mongoDatabase.GetCollection<object>(collectionName).FindSync(o => true).ToList();
58+
}
59+
5560
public IQueryable<TEntity> Query<TEntity>(string collectionName) where TEntity : class, INeonEntity
5661
{
5762
return _mongoDatabase.GetCollection<TEntity>(collectionName).AsQueryable();

Neon.Engine/Services/IoTService.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,10 @@ public T GetEntityByType<T>(string name, string type) where T : NeonIoTBaseEntit
159159
document.Name == name && document.EntityType == type);
160160
}
161161

162-
public List<INeonIoTEntity> GetEntities()
162+
public List<object> GetEntities()
163163
{
164-
var entities = _entitiesConnector.Query<NeonIoTBaseEntity>(EntitiesCollectionName).ToList();
164+
return _entitiesConnector.FindAllGeneric(EntitiesCollectionName);
165165

166-
return new List<INeonIoTEntity>();
167166
}
168167

169168
public List<T> GetEntitiesByType<T>() where T : class, INeonIoTEntity

Neon.WebApi/Controllers/EntitiesController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public EntitiesController(IIoTService ioTService)
2020

2121
[HttpGet]
2222
[Route("all")]
23-
public ActionResult<List<INeonIoTEntity>> GetEntities()
23+
public ActionResult<List<object>> GetEntities()
2424
{
2525
return _ioTService.GetEntities();
2626
}

Neon.WebApi/Controllers/ScriptEngineController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ActionResult<List<ScriptEngineVariable>> GetAvailableVariables()
3434

3535
[HttpPost]
3636
[Route("execute/script")]
37-
public ActionResult<ScriptExecutionResult> ExecuteScript([FromBody] string script)
37+
public ActionResult<ScriptExecutionResult> ExecuteScript(string script)
3838
{
3939
var result = new ScriptExecutionResult();
4040
result.Script = script;

neon-frontend/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@babel/core": "7.5.5",
7-
"@chakra-ui/core": "^0.2.8",
8-
"@emotion/core": "^10.0.17",
9-
"@emotion/styled": "^10.0.17",
107
"@svgr/webpack": "4.3.2",
118
"@typescript-eslint/eslint-plugin": "1.13.0",
129
"@typescript-eslint/parser": "1.13.0",
@@ -20,7 +17,6 @@
2017
"css-loader": "2.1.1",
2118
"dotenv": "6.2.0",
2219
"dotenv-expand": "4.2.0",
23-
"emotion-theming": "^10.0.19",
2420
"eslint": "^6.1.0",
2521
"eslint-config-react-app": "^5.0.1",
2622
"eslint-loader": "2.2.1",
@@ -34,11 +30,13 @@
3430
"html-webpack-plugin": "4.0.0-beta.5",
3531
"identity-obj-proxy": "3.0.0",
3632
"is-wsl": "^1.1.0",
33+
"javascript-terminal": "^1.0.3",
3734
"jest": "24.8.0",
3835
"jest-environment-jsdom-fourteen": "0.1.0",
3936
"jest-resolve": "24.8.0",
4037
"jest-watch-typeahead": "0.3.1",
4138
"mini-css-extract-plugin": "0.5.0",
39+
"moment": "^2.24.0",
4240
"monaco-editor": "^0.18.1",
4341
"monaco-editor-webpack-plugin": "^1.7.0",
4442
"optimize-css-assets-webpack-plugin": "5.0.3",
@@ -52,12 +50,17 @@
5250
"react-app-polyfill": "^1.0.2",
5351
"react-dev-utils": "^9.0.3",
5452
"react-dom": "^16.9.0",
53+
"react-moment": "^0.9.2",
5554
"react-monaco-editor": "^0.31.0",
55+
"react-redux": "^7.1.1",
5656
"react-router-dom": "^5.0.1",
57+
"react-terminal-component": "^1.4.1",
5758
"react-websocket": "^2.0.2",
59+
"redux": "^4.0.4",
5860
"resolve": "1.12.0",
5961
"resolve-url-loader": "3.1.0",
6062
"sass-loader": "7.2.0",
63+
"semantic-ui-react": "^0.88.1",
6164
"semver": "6.3.0",
6265
"style-loader": "1.0.0",
6366
"terminal-in-react": "^4.3.1",

neon-frontend/public/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
content="Web site created using create-react-app"
1111
/>
1212
<link rel="apple-touch-icon" href="logo192.png" />
13+
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css" />
1314
<!--
1415
manifest.json provides metadata used when your web app is installed on a
1516
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/

neon-frontend/src/App.js

+52-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,67 @@
11
import React from 'react';
22
import './App.css';
3-
import { ThemeProvider, ColorModeProvider, CSSReset } from "@chakra-ui/core";
43
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
5-
import { Box } from "@chakra-ui/core";
6-
import HomeView from "./views/home"
7-
import JsEditorComponent from "./components/js_editor";
4+
import { Container, Header, Menu, Dropdown, Icon } from "semantic-ui-react"
5+
import HomeView from "./views/home"
6+
import ScriptTerminalView from "./views/script_terminal_view"
7+
import EditorView from "./views/editor_view"
8+
import EventsView from "./views/event_view"
89
import WebSocketComponent from './components/websocket';
9-
import ScriptTerminalComponent from "./components/script_terminal";
10+
import { Provider } from 'react-redux';
11+
import store from './store';
1012

1113

1214

1315
function App() {
1416
return (
15-
<ThemeProvider>
16-
<CSSReset />
17-
<ColorModeProvider>
17+
<div>
18+
<Provider store={store} >
1819
<Router>
1920
<WebSocketComponent />
20-
<div>
21-
<Box w="90%">
22-
<JsEditorComponent />
23-
</Box>
24-
<Box w="90%">
25-
<ScriptTerminalComponent />
26-
</Box>
27-
<Route exact path="/" component={HomeView} />
28-
</div>
21+
<Menu fixed='top' inverted>
22+
<Container>
23+
24+
<Menu.Item as='a' header>
25+
Neon
26+
</Menu.Item>
27+
<Menu.Item as='a'>
28+
<Icon name="home" />
29+
<Link to='/'>
30+
Home
31+
</Link>
32+
</Menu.Item>
33+
<Menu.Item as='a'>
34+
<Icon name="terminal" />
35+
<Link to='/script'>
36+
Terminal
37+
</Link>
38+
</Menu.Item>
39+
<Menu.Item as='a'>
40+
<Icon name="write" />
41+
<Link to='/editor'>
42+
Editor
43+
</Link>
44+
</Menu.Item>
45+
<Menu.Item as='a'>
46+
<Icon name="eye" />
47+
<Link to='/events'>
48+
Events
49+
</Link>
50+
</Menu.Item>
51+
52+
</Container>
53+
</Menu>
54+
<Container style={{marginTop: '100px'}}>
55+
<Route path="/" exact component={HomeView} />
56+
<Route path="/script/" component={ScriptTerminalView} />
57+
<Route path="/editor/" component={EditorView} />
58+
<Route path="/events/" component={EventsView} />
59+
</Container>
2960
</Router>
30-
</ColorModeProvider>
31-
</ThemeProvider>
61+
</Provider>
62+
</div>
63+
64+
3265
);
3366
}
3467

neon-frontend/src/actions/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { EVENT_RECEIVED } from "../constants"
2+
3+
export function onEventReceived(event) {
4+
return {type: EVENT_RECEIVED, payload: event};
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { connect } from 'react-redux';
3+
import { Table } from "semantic-ui-react"
4+
import Moment from 'react-moment';
5+
6+
7+
function mapStateToProps(state) {
8+
return {
9+
events: state.events
10+
}
11+
}
12+
13+
const EventViewer = ({events}) => (
14+
<Table celled>
15+
<Table.Header>
16+
<Table.Row>
17+
<Table.HeaderCell>Name</Table.HeaderCell>
18+
<Table.HeaderCell>Group name</Table.HeaderCell>
19+
<Table.HeaderCell>Entity type</Table.HeaderCell>
20+
<Table.HeaderCell>Date time</Table.HeaderCell>
21+
</Table.Row>
22+
</Table.Header>
23+
<Table.Body>
24+
{events.map((event, index) => {
25+
return (
26+
<Table.Row key={index}>
27+
<Table.Cell>{event.data.name}</Table.Cell>
28+
<Table.Cell>{event.data.group_name}</Table.Cell>
29+
<Table.Cell>{event.data.entity_type}</Table.Cell>
30+
<Table.Cell>
31+
<Moment> {event.data.event_date_time} </Moment>
32+
</Table.Cell>
33+
</Table.Row>
34+
);
35+
})}
36+
</Table.Body>
37+
</Table>
38+
)
39+
40+
export default connect(mapStateToProps)(EventViewer);

neon-frontend/src/components/js_editor.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
import { React, useState, Component } from 'react';
1+
import React from 'react';
22
import MonacoEditor from 'react-monaco-editor';
33
//https://jsfiddle.net/hec12da1/
44

5-
6-
7-
class JsEditorComponent extends Component {
5+
class JsEditorComponent extends React.Component {
86

97
constructor(props) {
108
super(props);
119
this.code = "substr";
1210
}
1311

14-
15-
12+
editorDidMount(editor, monaco) {
13+
console.log('editorDidMount', editor);
14+
editor.focus();
15+
}
1616

1717

1818
render() {
19-
20-
return "";
19+
20+
return (
21+
<div style={{ width: 100 }}>
22+
<MonacoEditor
23+
width="800"
24+
height="600"
25+
language="javascript"
26+
theme="vs-dark"
27+
/>
28+
</div>
29+
30+
);
2131

2232
}
2333
}

0 commit comments

Comments
 (0)