From 9995d815f93b47446e6b10085197f0637ba9d955 Mon Sep 17 00:00:00 2001 From: Javi Gallego Date: Thu, 6 Oct 2016 15:27:02 +0200 Subject: [PATCH 1/3] crud add --- @salix/app/src/routes.js | 2 +- @salix/crud/src/crud.js | 3 ++- @salix/crud/src/customer/index/add.html | 1 + @salix/crud/src/customer/index/add.js | 16 ++++++++++++++++ @salix/crud/src/customer/index/index.html | 2 +- @salix/crud/src/customer/index/index.js | 7 +++---- 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 @salix/crud/src/customer/index/add.html create mode 100644 @salix/crud/src/customer/index/add.js diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index 4259fcd639..25d5fd78da 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -9,7 +9,7 @@ core.module.config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('index', { url: "/index", - template :'', + template :'', resolve: { loader: function($ocLazyLoad, $q){ return $q((resolve) => { diff --git a/@salix/crud/src/crud.js b/@salix/crud/src/crud.js index 7d4627b16d..806f1c41a7 100644 --- a/@salix/crud/src/crud.js +++ b/@salix/crud/src/crud.js @@ -1,4 +1,5 @@ export * from './module'; export * from './customer/routes'; -export {NAME as CUSTOMER_INDEX, COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index' \ No newline at end of file +export {NAME as CUSTOMER_INDEX, COMPONENT as CUSTOMER_INDEX_COMPONENT} from './customer/index' +export {NAME as CUSTOMER_ADD, COMPONENT as CUSTOMER_ADD_COMPONENT} from './customer/index/add' \ No newline at end of file diff --git a/@salix/crud/src/customer/index/add.html b/@salix/crud/src/customer/index/add.html new file mode 100644 index 0000000000..3081979344 --- /dev/null +++ b/@salix/crud/src/customer/index/add.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/@salix/crud/src/customer/index/add.js b/@salix/crud/src/customer/index/add.js new file mode 100644 index 0000000000..903b4606f0 --- /dev/null +++ b/@salix/crud/src/customer/index/add.js @@ -0,0 +1,16 @@ +import template from './add.html'; +import {module} from '../../module'; + +export const NAME = 'customerAdd'; + +export const COMPONENT = { + template: template, + bindings :{ + users: '<' + }, + controller :function($scope, $element, $attrs){ + console.log(this.users); + } +}; + +module.component(NAME, COMPONENT); \ No newline at end of file diff --git a/@salix/crud/src/customer/index/index.html b/@salix/crud/src/customer/index/index.html index bf833f5d0c..1f45f7a818 100644 --- a/@salix/crud/src/customer/index/index.html +++ b/@salix/crud/src/customer/index/index.html @@ -1 +1 @@ -
index from component
\ No newline at end of file + \ No newline at end of file diff --git a/@salix/crud/src/customer/index/index.js b/@salix/crud/src/customer/index/index.js index 3f404ca5af..31b48466b1 100644 --- a/@salix/crud/src/customer/index/index.js +++ b/@salix/crud/src/customer/index/index.js @@ -1,14 +1,13 @@ import template from './index.html'; import {module} from '../../module'; -export const NAME = 'customerAdd'; +export const NAME = 'customerIndex'; export const COMPONENT = { template: template, - controller: function() { - this.user = {name: 'world'}; + controller :function(){ + this.users = {id:10,name:"xxxx"}; } }; - module.component(NAME, COMPONENT); From 86a19c47ee265f8284813a742090c300742e5e7c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 6 Oct 2016 15:32:03 +0200 Subject: [PATCH 2/3] CORS en servidor express, cargador de rutas --- @salix/app/src/app.js | 1 - @salix/app/src/routes.js | 3 +-- @salix/compras/routing.json | 4 ---- @salix/core/src/core.js | 5 ++++- @salix/core/src/routesLoader.js | 29 +++++++++++++++++++++++++++++ @salix/ventas/routing.json | 4 ---- gulpfile.js | 2 +- index.html | 7 ++++++- package.json | 1 + server.js | 5 +++-- 10 files changed, 45 insertions(+), 16 deletions(-) delete mode 100644 @salix/compras/routing.json create mode 100644 @salix/core/src/routesLoader.js delete mode 100644 @salix/ventas/routing.json diff --git a/@salix/app/src/app.js b/@salix/app/src/app.js index 6f2c434cc1..b3ac02fdd1 100644 --- a/@salix/app/src/app.js +++ b/@salix/app/src/app.js @@ -2,5 +2,4 @@ import {bootstrap} from './bootstrap'; import * as spliting from './spliting'; import * as routes from './routes'; - bootstrap(); diff --git a/@salix/app/src/routes.js b/@salix/app/src/routes.js index 4259fcd639..bd99611731 100644 --- a/@salix/app/src/routes.js +++ b/@salix/app/src/routes.js @@ -1,7 +1,6 @@ import * as core from '@salix/core'; import * as spliting from './spliting'; - core.module.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/"); @@ -17,5 +16,5 @@ core.module.config(function($stateProvider, $urlRouterProvider) { }); } } - }) + }) }); diff --git a/@salix/compras/routing.json b/@salix/compras/routing.json deleted file mode 100644 index ac6307544f..0000000000 --- a/@salix/compras/routing.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "route": "buys", - "template": "buys.template" -} diff --git a/@salix/core/src/core.js b/@salix/core/src/core.js index 244e3735ae..d6049004e5 100644 --- a/@salix/core/src/core.js +++ b/@salix/core/src/core.js @@ -3,8 +3,11 @@ */ export * from './module'; export * from './util'; + export {NAME as RESOLVEDEFAULTCOMPONENT, ResolveDefaultComponent} from './resolveDefaultComponents' export {NAME as INTERPOLATE,Interpolate} from './interpolate' +export {NAME as ROUTESLOADER, RoutesLoader} from './routesLoader' + export {NAME as BUTTON,directive as ButtonDirective} from './button/button' export {NAME as BUTTONMT,factory as buttonmt} from './button/button.mt' export {NAME as BUTTONBT,factory as buttonbt} from './button/button.bt' @@ -19,4 +22,4 @@ export {NAME as TEXTFIELDMT,factory as textfieldmt} from './textfield/textfield. export {NAME as TEXTFIELDBT,factory as textfieldbt} from './textfield/textfield.bt' export {NAME as LABEL,directive as LabelDirective} from './label/label' export {NAME as LABELMT,factory as labelmt} from './label/label.mt' -export {NAME as LABELBT,factory as labelbt} from './label/label.bt' \ No newline at end of file +export {NAME as LABELBT,factory as labelbt} from './label/label.bt' diff --git a/@salix/core/src/routesLoader.js b/@salix/core/src/routesLoader.js new file mode 100644 index 0000000000..9fb6657216 --- /dev/null +++ b/@salix/core/src/routesLoader.js @@ -0,0 +1,29 @@ + +import {module as _module} from './module' +import * as util from './util' + +export const NAME = util.getProviderName ('RoutesLoader') + +export class RoutesLoader +{ + constructor () {} + + $get ($http) + { + let script = document.currentScript || (() => { + let scripts = document.getElementsByTagName ('script'); + return scripts[scripts.length - 1]; + }) (); + + let routesCdn = script.getAttribute ('routes-cdn'); + + return $http + ({ + method: 'GET', + url: routesCdn + }) + } +} + +_module.provider (NAME, () => new RoutesLoader ()) + diff --git a/@salix/ventas/routing.json b/@salix/ventas/routing.json deleted file mode 100644 index ef776755ee..0000000000 --- a/@salix/ventas/routing.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "route": "sales", - "template": "sales.template" -} diff --git a/gulpfile.js b/gulpfile.js index 6fbf8aebc2..eecadce9c5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ function combineFunc (data) gulp.task ('default', function () { - var json = gulp.src ('./@salix/**/routing.json') + var json = gulp.src ('./@salix/**/routes.json') .pipe (jsoncombine ('salix.routes.json', combineFunc)) .pipe (gulp.dest ('./build')); }); diff --git a/index.html b/index.html index b506e8e602..e9699e82c3 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,11 @@ edit delete - + diff --git a/package.json b/package.json index df20f4e4b1..8cc3727e6b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "angular": "^1.5.8", "angular-ui-router": "^1.0.0-beta.3", + "cors": "^2.8.1", "express": "^4.14.0", "material-design-lite": "^1.2.1", "oclazyload": "^0.6.3" diff --git a/server.js b/server.js index cee4df2ea1..e5a13d32ca 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ var express = require ('express'); +var cors = require ('cors'); function getRoutes (req, res) { @@ -18,7 +19,7 @@ function onListen () } var app = express (); -app.get ('/routes.json', getRoutes); -app.all (/.*/, getDefault); +app.get ('/routes', cors (), getRoutes); +app.all (/.*/, cors (), getDefault); app.listen (8080, onListen); From 5a4a41d630b9956f24891264f436dd7dd50eac72 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 7 Oct 2016 11:44:24 +0200 Subject: [PATCH 3/3] Concat de rutas JS con Gulp, servidor express sirve routes.js --- @salix/app/index.js | 2 +- @salix/compras/index.js | 2 +- gulpfile.js | 15 ++++++--------- index.html | 7 +++---- npm-debug.log | 27 --------------------------- package.json | 26 +++++++++++++++----------- server.js | 13 +++++-------- webpack.config.js | 7 ++++--- 8 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 npm-debug.log diff --git a/@salix/app/index.js b/@salix/app/index.js index 4d375b31f6..cb9a3f1789 100644 --- a/@salix/app/index.js +++ b/@salix/app/index.js @@ -1 +1 @@ -export * from './src/app' \ No newline at end of file +export * from './src/app' diff --git a/@salix/compras/index.js b/@salix/compras/index.js index 8f9f546294..133f88ede6 100644 --- a/@salix/compras/index.js +++ b/@salix/compras/index.js @@ -1,4 +1,4 @@ import * as core from '@salix/core' import * as vendors from '@salix/vendor' import * as crud from '@salix/crud' -console.log('compras'); \ No newline at end of file +console.log('compras'); diff --git a/gulpfile.js b/gulpfile.js index eecadce9c5..e17bbfd1e0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,16 +1,13 @@ var gulp = require ('gulp'); -var jsoncombine = require ('gulp-jsoncombine'); - -function combineFunc (data) -{ - return new Buffer (JSON.stringify (data)); -} +var concat = require ('gulp-concat'); +var babel = require ('gulp-babel'); gulp.task ('default', function () { - var json = gulp.src ('./@salix/**/routes.json') - .pipe (jsoncombine ('salix.routes.json', combineFunc)) - .pipe (gulp.dest ('./build')); + var js = gulp.src ('./@salix/crud/**/routes.js') + .pipe (concat ('salix.routes.js')) + .pipe (babel ({presets: ['es2015']})) + .pipe (gulp.dest ('./build/private')); }); diff --git a/index.html b/index.html index e9699e82c3..e093cae628 100644 --- a/index.html +++ b/index.html @@ -13,9 +13,8 @@ + src="build/public/salix.app.js" + selector="#app"> + diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 9d648ec6bc..0000000000 --- a/npm-debug.log +++ /dev/null @@ -1,27 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.3.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'dev' ] -2 info using npm@3.10.3 -3 info using node@v6.3.1 -4 verbose stack Error: missing script: dev -4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) -4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 -4 verbose stack at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) -4 verbose stack at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) -4 verbose stack at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12 -4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 -4 verbose stack at tryToString (fs.js:455:3) -4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12) -5 verbose cwd /Users/nelo/Documents/node/salix -6 error Darwin 16.0.0 -7 error argv "/usr/local/Cellar/node/6.3.1/bin/node" "/usr/local/bin/npm" "run" "dev" -8 error node v6.3.1 -9 error npm v3.10.3 -10 error missing script: dev -11 error If you need help, you may report this error at: -11 error -12 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 8cc3727e6b..d1fb870451 100644 --- a/package.json +++ b/package.json @@ -11,24 +11,28 @@ "dependencies": { "angular": "^1.5.8", "angular-ui-router": "^1.0.0-beta.3", - "cors": "^2.8.1", "express": "^4.14.0", "material-design-lite": "^1.2.1", "oclazyload": "^0.6.3" }, "devDependencies": { - "gulp": "^3.9.1", - "gulp-jsoncombine": "^1.0.3", - "webpack": "*", - "webpack-dev-server": "*", - "raw-loader": "*", - "css-loader": "^0.25.0", - "style-loader": "^0.13.1", - "babel-loader": "*", "babel-core": "*", - "babel-preset-es2015": "*" + "babel-loader": "*", + "babel-preset-es2015": "*", + "cors": "^2.8.1", + "css-loader": "^0.25.0", + "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", + "gulp-concat": "^2.6.0", + "raw-loader": "*", + "style-loader": "^0.13.1", + "webpack": "*", + "webpack-dev-server": "*" }, "scripts": { - "build": "webpack --progress --colors --watch" + "build": "webpack --progress --colors --watch", + "dev": "webpack-dev-server --progress --colors --inline --hot", + "gulp": "gulp", + "express": "node server.js" } } diff --git a/server.js b/server.js index e5a13d32ca..04801bb911 100644 --- a/server.js +++ b/server.js @@ -2,11 +2,8 @@ var express = require ('express'); var cors = require ('cors'); -function getRoutes (req, res) -{ - var routes = require ('./build/salix.routes.json'); - res.send (JSON.stringify (routes)); -} +var port = 3000; +var routesUrl = '/private/salix.routes.js'; function getDefault (res, res) { @@ -15,11 +12,11 @@ function getDefault (res, res) function onListen () { - console.log ('HTTP server started.'); + console.log ('HTTP server started on port '+ port); } var app = express (); -app.get ('/routes', cors (), getRoutes); +app.use ('/private', cors (), express.static (__dirname +'/build/private')); app.all (/.*/, cors (), getDefault); -app.listen (8080, onListen); +app.listen (port, onListen); diff --git a/webpack.config.js b/webpack.config.js index 6ff905c056..f6de35fb7a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -8,9 +8,9 @@ module.exports = 'salix.app': ['@salix/app'] }, output: { - path: path.join(__dirname, 'build'), + path: path.join(__dirname, 'build', 'public'), filename: '[name].js', - publicPath: 'build/', + publicPath: 'build/public/', chunkFilename: "[name].js" }, module: { @@ -39,5 +39,6 @@ module.exports = __dirname, 'node_modules' ] - } + }, + devtool: 'cheap-module-eval-source-map' // 'source-map' };