Browse Source

Exemplo de produtos...

master
Eduardo Velasques 3 years ago
commit
674e963265
47 changed files with 55861 additions and 0 deletions
  1. +7
    -0
      .editor.config
  2. +24
    -0
      .gitignore
  3. +3
    -0
      config/_development.js
  4. +3
    -0
      config/_production.js
  5. BIN
      config/icon.png
  6. BIN
      public/images/logo-main.png
  7. BIN
      public/images/logo.png
  8. +55300
    -0
      public/scripts/main.js
  9. +1
    -0
      public/scripts/main.js.map
  10. +13
    -0
      public/styles/main.css
  11. +22
    -0
      server/core/_config.js
  12. +5
    -0
      server/core/_init.js
  13. +0
    -0
      server/core/_request_close.js
  14. +0
    -0
      server/core/_request_end.js
  15. +17
    -0
      server/core/_request_error.js
  16. +2
    -0
      server/core/_request_start.js
  17. +14
    -0
      server/core/_request_url.js
  18. +13
    -0
      server/core/_service_config.js
  19. +0
    -0
      server/core/_service_end.js
  20. +5
    -0
      server/core/_service_error.js
  21. +0
    -0
      server/core/_service_start.js
  22. +7
    -0
      server/package.json
  23. +11
    -0
      server/services/produto-salvar.js
  24. +13
    -0
      server/services/produtos-python.py
  25. +22
    -0
      server/services/produtos.js
  26. +0
    -0
      server/setup/_end.js
  27. +24
    -0
      server/templates/dashboard.html
  28. +31
    -0
      server/templates/dev/dashboard.html
  29. +1
    -0
      server/templates/scripts.html
  30. +0
    -0
      server/templates/scripts_dev.html
  31. +0
    -0
      server/templates/scripts_login.html
  32. +1
    -0
      server/templates/styles.html
  33. +1
    -0
      server/templates/styles_dev.html
  34. +0
    -0
      server/templates/styles_login.html
  35. +4
    -0
      storage/filesystem/private/info.txt
  36. +2
    -0
      storage/filesystem/public/info.txt
  37. +4
    -0
      storage/filesystem/server/info.txt
  38. +9
    -0
      ui/.babelrc
  39. +18
    -0
      ui/.gitignore
  40. +24
    -0
      ui/README.md
  41. +37
    -0
      ui/package.json
  42. +20
    -0
      ui/src/components/MyButton/index.js
  43. +59
    -0
      ui/src/containers/DashboardContainer/index.js
  44. +8
    -0
      ui/src/containers/DashboardContainer/index.less
  45. +49
    -0
      ui/src/index.js
  46. +3
    -0
      ui/src/styles/main.less
  47. +84
    -0
      ui/webpack.config.js

+ 7
- 0
.editor.config View File

@ -0,0 +1,7 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2

+ 24
- 0
.gitignore View File

@ -0,0 +1,24 @@
log.sh
server/setup/_start.js
server/setup/_end.js
node_modules/
.DS_Store
*.log
.idea/
.metadata/
.vscode
package-lock.json
/trash/*
.Trash
*~*
*#*
config/_development.json
config/_production.json

+ 3
- 0
config/_development.js View File

@ -0,0 +1,3 @@
/*
* Development dynamic configurations is here.
*/

+ 3
- 0
config/_production.js View File

@ -0,0 +1,3 @@
/*
* Production dynamic configurations is here.
*/

BIN
config/icon.png View File

Before After
Width: 1024  |  Height: 1024  |  Size: 68 KiB

BIN
public/images/logo-main.png View File

Before After
Width: 740  |  Height: 225  |  Size: 12 KiB

BIN
public/images/logo.png View File

Before After
Width: 600  |  Height: 180  |  Size: 22 KiB

+ 55300
- 0
public/scripts/main.js
File diff suppressed because it is too large
View File


+ 1
- 0
public/scripts/main.js.map
File diff suppressed because it is too large
View File


+ 13
- 0
public/styles/main.css View File

@ -0,0 +1,13 @@
/**
HERE YOUR CUSTOM CSS
**/
.navbar, .navbar-inverse {
background-color: #5b5ce1 !important;
}
.dev .navbar, .dev .navbar-inverse {
background-color: #333333 !important;
}

+ 22
- 0
server/core/_config.js View File

@ -0,0 +1,22 @@
_config.set("_lang", _config.get("_lang:default"))
if (_env.is("dev")
&& (_url.equals("/") || _url.equals("/Index.netuno"))) {
_config
.set("_login:user", "dev")
.set("_login:pass", "dev")
.set("_login:auto", _req.getString("action") != "logout")
}
/**
* DISABLE BROWSER CACHE
*/
if (_url.download.isDownloadable()) {
if (_env.is("dev") && _url.indexOf("/public/scripts/main.js") > 0) {
_header.noCache()
} else {
_header.cache(2628000)
}
}

+ 5
- 0
server/core/_init.js View File

@ -0,0 +1,5 @@
/**
* FIREBASE - Set your listeners
*/
// _firebase.listener("my-test", _header.baseURL() + "/services/firebase/listener/my-test.netuno")

+ 0
- 0
server/core/_request_close.js View File


+ 0
- 0
server/core/_request_end.js View File


+ 17
- 0
server/core/_request_error.js View File

@ -0,0 +1,17 @@
if (!_out.isClosed()) {
_out.print(
"### SERVER ERROR ###"
)
/*
// Is insecure but the code below will print errors with more details...
_out.print(
"SERVER ERROR # " +
_error.data().getString("file")
+":"+
_error.data().getString("line")
+" # "+
_error.data().getString("message")
)
*/
}

+ 2
- 0
server/core/_request_start.js View File

@ -0,0 +1,2 @@
_config.set("_script:_request_end", true)

+ 14
- 0
server/core/_request_url.js View File

@ -0,0 +1,14 @@
// _log.info(_url.url())
/**
* ALLOW CORS
*/
/*
_header.response.set("Access-Control-Allow-Origin", "https://www.netuno.org")
_header.response.set("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS")
_header.response.set("Access-Control-Allow-Headers", "content-type,x-requested-with,authorization")
_header.response.set("Access-Control-Allow-Credentials", true)
*/
_url.to(_url.request())

+ 13
- 0
server/core/_service_config.js View File

@ -0,0 +1,13 @@
/**
* When service need public access...
*/
if (_env.is("dev")) {
_service.allow()
}
/*
if (_service.path == 'samples/my-service') {
_service.allow()
}
*/

+ 0
- 0
server/core/_service_end.js View File


+ 5
- 0
server/core/_service_error.js View File

@ -0,0 +1,5 @@
/*
// Print error:
_log.fatal("Service "+ _service.path, _error.data().get("throwable"))
*/

+ 0
- 0
server/core/_service_start.js View File


+ 7
- 0
server/package.json View File

@ -0,0 +1,7 @@
{
"name": "server",
"version": "1.0.0",
"description": "Server modules dependencies.",
"author": "netuno.org",
"license": "ISC"
}

+ 11
- 0
server/services/produto-salvar.js View File

@ -0,0 +1,11 @@
const nome = _req.getString('nome')
_db.execute(`
INSERT INTO produto(nome, categoria_id)
VALUES(?, 1)
`, nome)
_out.println('<h1>Produto '+ nome +' salvo com sucesso!</h1>')

+ 13
- 0
server/services/produtos-python.py View File

@ -0,0 +1,13 @@
test = 2
if test == 2:
_out.json(
_db.query('SELECT nome FROM produto')
)
else:
_out.json(
_val.map().set('error', 'Ocorreu uma falha...')
)

+ 22
- 0
server/services/produtos.js View File

@ -0,0 +1,22 @@
// _exec.sleep(1000)
const dbProdutos = _db.query(`
SELECT
produto.nome AS "produto_nome",
categoria.nome AS "categoria_nome"
FROM produto
INNER JOIN categoria ON produto.categoria_id = categoria.id
`)
const produtos = _val.list()
for (const dbProduto of dbProdutos) {
produtos.add(
_val.map()
.set('produto', dbProduto.getString('produto_nome'))
.set('categoria', dbProduto.getString('categoria_nome'))
)
}
_out.json(produtos)

+ 0
- 0
server/setup/_end.js View File


+ 24
- 0
server/templates/dashboard.html View File

@ -0,0 +1,24 @@
<div class="row">
<div class="col-lg-12">
<div class="with-form">
<h1 class="page-header">
_{&lang=netuno.main.dashboard.title}
</h1>
</div>
<div class="no-form">
<h1 class="page-header">
_{&lang=netuno.main.dashboard.welcome_netuno}
</h1>
<p>_{&lang=netuno.main.dashboard.you_not_form}</p>
<p>_{&lang=netuno.main.dashboard.you_can_start_by_clicking_top_bar}</p>
<br>
<img src="_{netuno-config=url-styles}/build-button-tutorial.png" height="80">
</div>
</div>
</div>
<div id="app-dashboard"></div>

+ 31
- 0
server/templates/dev/dashboard.html View File

@ -0,0 +1,31 @@
<div class="row">
<div class="col-lg-12">
<div class="with-form">
<h1 class="page-header">
_{&lang=netuno.main.dashboard.title}
</h1>
<p>_{&lang=netuno.main.dashboard.description}</p>
</div>
<div class="no-form">
<h1 class="page-header">
_{&lang=netuno.main.dashboard.welcome_netuno}
</h1>
<p>_{&lang=netuno.dev.main.you_not_form}</p>
<p>_{&lang=netuno.dev.main.you_can_start_by_clicking_top_bar}</p>
<br>
<img src="_{netuno-config=url-styles}/build-button-tutorial-dev.png" height="200">
</div>
#macro(listFormItems $items)
<ul>
#foreach($item in $items)
<li>
<a href="#" netuno-dev-form="$item.getString('name')">$item.getString('text')</a>
#listFormItems($item.get('items'))
</li>
#end
</ul>
#end
#listFormItems($data.get('menu').get('forms'))
</div>
</div>

+ 1
- 0
server/templates/scripts.html View File

@ -0,0 +1 @@
<script src="_{netuno-config=url-app-scripts}/main.js?_{util=requestuuid}"></script>

+ 0
- 0
server/templates/scripts_dev.html View File


+ 0
- 0
server/templates/scripts_login.html View File


+ 1
- 0
server/templates/styles.html View File

@ -0,0 +1 @@
<link href='_{netuno-config=url-app-styles}/main.css' rel='stylesheet' />

+ 1
- 0
server/templates/styles_dev.html View File

@ -0,0 +1 @@
<link href='_{netuno-config=url-app-styles}/main.css' rel='stylesheet' />

+ 0
- 0
server/templates/styles_login.html View File


+ 4
- 0
storage/filesystem/private/info.txt View File

@ -0,0 +1,4 @@
Secure data files comes here...
Only accessible for logged users!

+ 2
- 0
storage/filesystem/public/info.txt View File

@ -0,0 +1,2 @@
Public storage files comes here...

+ 4
- 0
storage/filesystem/server/info.txt View File

@ -0,0 +1,4 @@
Secure data files comes here...
Only accessible through server side!

+ 9
- 0
ui/.babelrc View File

@ -0,0 +1,9 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
["import", { "libraryName": "antd", "style": "less" } ]
]
}

+ 18
- 0
ui/.gitignore View File

@ -0,0 +1,18 @@
node_modules/
.DS_Store
*.log
.idea/
.metadata/
.vscode
package-lock.json
yarn.lock
.Trash
*~*
*#*

+ 24
- 0
ui/README.md View File

@ -0,0 +1,24 @@
### Install Packages
`npm install`
### Watch changes and auto recompile
`npm run watch`
### Installation requirements
On Windows with an Administrator terminal, run:
```
npm install --global --production windows-build-tools
npm install --global node-gyp
```
With others Python version, then configure the Python 2.7 path:
```
node-gyp --python /path/to/python2.7
npm config set python /path/to/executable/python2.7
```

+ 37
- 0
ui/package.json View File

@ -0,0 +1,37 @@
{
"name": "ui",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode production",
"watch": "webpack --mode development --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"babel-loader": "^9.1.2",
"babel-plugin-import": "^1.13.6",
"css-loader": "^6.7.3",
"less": "^4.1.3",
"less-loader": "^11.1.0",
"prop-types": "^15.8.1",
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"@ant-design/icons": "^5.0.1",
"@netuno/service-client": "^1.2.0",
"@netuno/ws-client": "^1.0.8",
"antd": "^5.3.2",
"chart.js": "^4.2.0",
"react-chartjs-2": "^5.2.0"
}
}

+ 20
- 0
ui/src/components/MyButton/index.js View File

@ -0,0 +1,20 @@
import React from "react";
import PropTypes from "prop-types";
import { Button } from 'antd';
function MyButton({ text, onClick }) {
return (
<div>
<Button type="primary" onClick={ onClick }>
{ text }
</Button>
</div>
);
};
MyButton.propTypes = {
text: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired
};
export default MyButton;

+ 59
- 0
ui/src/containers/DashboardContainer/index.js View File

@ -0,0 +1,59 @@
import React, { useState, useEffect, useRef } from "react";
import { ConfigProvider, theme } from "antd";
import antLocale_enGB from "antd/lib/locale/en_GB";
import antLocale_enUS from "antd/lib/locale/en_US";
import antLocale_esES from "antd/lib/locale/es_ES";
import antLocale_ptBR from "antd/lib/locale/pt_BR";
import antLocale_ptPT from "antd/lib/locale/pt_PT";
import MyButton from "../../components/MyButton";
import "./index.less";
const antdVariables = {
colorPrimary: '#5b5ce1',
colorLink: '#5b5ce1',
borderRadius: 5,
};
function DashboardContainer() {
const [counter, setCounter] = useState(0);
const refButton = useRef();
useEffect(() => {
$(refButton.current).fadeOut(250).fadeIn(250);
}, [counter]);
const onClick = () => {
setCounter(counter + 1);
};
return (
<ConfigProvider
theme={{
token: antdVariables,
algorithm: theme.darkAlgorithm
}}
locale={
{
'en_us': antLocale_enUS,
'en_gb': antLocale_enGB,
'es_es': antLocale_esES,
'pt_br': antLocale_ptBR,
'pt_pt': antLocale_ptPT
}[netuno.config.langCode]
}
>
<div className="my-dashboard">
<div ref={refButton} className="my-dashboard__button">
<MyButton text={`ReactJS ⚡ Ant.Design 👉 Click me! ${counter}`} onClick={onClick} />
</div>
</div>
</ConfigProvider>
);
}
export default DashboardContainer;

+ 8
- 0
ui/src/containers/DashboardContainer/index.less View File

@ -0,0 +1,8 @@
.my-dashboard {
width: 100%;
&__button {
padding: 80px;
text-align: center;
}
}

+ 49
- 0
ui/src/index.js View File

@ -0,0 +1,49 @@
import React from "react";
import ReactDOM from "react-dom/client";
import _service from '@netuno/service-client';
import DashboardContainer from "./containers/DashboardContainer";
_service.config({
prefix: netuno.config.urlServices
});
const dashboardDiv = document.getElementById("app-dashboard");
const dashboardContainer = dashboardDiv ? ReactDOM.createRoot(dashboardDiv) : false;
if (dashboardContainer) {
dashboardContainer.render(<DashboardContainer/>);
}
netuno.addNavigationLoad(() => {
$('[netuno-navigation]').find('a').on('netuno:click', (e)=> {
const link = $(e.target);
if (dashboardContainer && link.is('[netuno-navigation-dashboard]')) {
// Menu > Dashboard > Clicked!
}
});
});
netuno.addContentLoad((container) => {
// When any content is loaded dinamically this is executed...
if (container.is('[netuno-form-search="YOUR_FORM_NAME"]')) {
// When search page is loaded...
} else if (container.is('[netuno-form-edit="YOUR_FORM_NAME"]')) {
// When form edit is loaded...
}
});
netuno.addPageLoad(() => {
// When page is loaded...
let modal = $('#app-dashboard-modal-form');
modal.on('hidden.bs.modal', ()=> {
modal.find('[netuno-form-edit]').empty();
});
$('#app-dashboard-modal-form-button').on('click', ()=> {
modal.modal('show');
netuno.loadFormEdit(modal.find('[netuno-form]'));
});
modal.find('[netuno-form]').on('netuno:save', ()=> {
modal.modal('hide');
});
});

+ 3
- 0
ui/src/styles/main.less View File

@ -0,0 +1,3 @@
/*** GLOBAL CSS ***/

+ 84
- 0
ui/webpack.config.js View File

@ -0,0 +1,84 @@
const path = require('path');
module.exports = {
entry: [ './src/index.js', './src/styles/main.less' ],
devtool: "source-map",
output: {
path: __dirname +'/../public/scripts',
filename: 'main.js'
},
module: {
rules: [
{
test: /\.jsx$/,
include: [
path.resolve(__dirname, 'src')
],
exclude: [/node_modules/],
use: [{
loader: 'babel-loader'
}]
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'src')
],
exclude: [/node_modules/],
use: [{
loader: 'babel-loader'
}]
},
{
test: /\.css$/,
include: [
path.resolve(__dirname, 'src')
],
exclude: [/node_modules/],
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.less$/,
include: [
path.resolve(__dirname, 'src')
],
exclude: [/node_modules/],
use: [
{
loader: 'style-loader' // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJ,
options: {
sourceMap: true
/*,
modules: {
mode: 'local',
localIdentName: "[local]___[hash:base64:5]",
context: path.resolve(__dirname, 'src'),
hashPrefix: 'app',
}*/
}
},
{
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: {
modifyVars: {
'@primary-color': '#5b5ce1',
'@link-color': '#5b5ce1',
'@border-radius-base': '5px'
},
javascriptEnabled: true
},
sourceMap: true
}
}
]
}
]
}
};

Loading…
Cancel
Save