WIP open file for a while
This commit is contained in:
parent
f937019e42
commit
d280fb9af3
122 changed files with 5702 additions and 10 deletions
45
example/example-config.json
Normal file
45
example/example-config.json
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"winston": {
|
||||
"console": {
|
||||
"level": "debug",
|
||||
"silent": false,
|
||||
"colorize": true,
|
||||
"timestamp": null
|
||||
},
|
||||
"file": {
|
||||
"level": "debug",
|
||||
"silent": false,
|
||||
"colorize": false,
|
||||
"timestamp": null,
|
||||
"json": false,
|
||||
"filename": "www_logs/server.log"
|
||||
}
|
||||
},
|
||||
"server": {
|
||||
"httpPort": 8008,
|
||||
"httpTrustProxy": true,
|
||||
"sessionSecret": "tcrudIDKEy",
|
||||
"sessionTTL": "14 * 24 * 60 * 60"
|
||||
},
|
||||
"application": {
|
||||
"name": "TCrud Example Server",
|
||||
"index": {
|
||||
"pageTitle": "TCrud Example Server",
|
||||
"pageKeywords": "node,crud,api,json,xml,views"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"static": {
|
||||
"maxAge": 86400000
|
||||
},
|
||||
"cookieParser": {
|
||||
"secretKey": "test88test"
|
||||
},
|
||||
"rss": {
|
||||
"link": "http://localhost:8008",
|
||||
"author": "TCrud",
|
||||
"options": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
example/example.js
Normal file
61
example/example.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
var config = require('./example-config.json');
|
||||
var favicon = require('static-favicon');
|
||||
var cookieParser = require('cookie-parser')
|
||||
var path = require('path');
|
||||
var winston = require('winston');
|
||||
winston.loggers.add('main',config.winston);
|
||||
var log = winston.loggers.get('main');
|
||||
var expressWinston = require('express-winston');
|
||||
var tcrud = require('../lib/node-ff-tcrud');
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
// PHASE_1: load extra plugins
|
||||
//tcrud.setup.pluginLoad(new MyPlugin());
|
||||
require('./lib/pg-moviedb').load(tcrud);
|
||||
require('./lib/pg-pagila').load(tcrud);
|
||||
|
||||
// PHASE_2: enable plugins
|
||||
tcrud.setup.pluginEnableAll();
|
||||
|
||||
// PHASE_3: start config
|
||||
tcrud.setup.phaseConfig();
|
||||
tcrud.config.getRootTEntity().tmeta.tplugin.formatXML.tslug = 'xml_is_free';
|
||||
tcrud.config.getRootTEntity().tmeta.tplugin.formatCSV.tslug = 'csv4all';
|
||||
var tPostgresDB = tcrud.config.createTEntityNode(tcrud.config.getRootTEntity(),'pg');
|
||||
var tMongoose = tcrud.config.createTEntityNode(tcrud.config.getRootTEntity(),'mongoose');
|
||||
require('./lib/pg-moviedb').setup(tcrud,tPostgresDB);
|
||||
require('./lib/pg-pagila').setup(tcrud,tPostgresDB);
|
||||
//require('./lib/mongoose-blog').setup(tcrud,tMongoose);
|
||||
|
||||
// PHASE_4: finalize config
|
||||
tcrud.setup.phaseServer();
|
||||
//tcrud.setup.expressSimple(); or complex;
|
||||
|
||||
var server = tcrud.setup.expressCreate();
|
||||
server.use(expressWinston.logger({
|
||||
transports: [new winston.transports.Console({json: false,colorize: true})],
|
||||
meta: false,
|
||||
expressFormat: true
|
||||
}));
|
||||
|
||||
var buildOptions = {
|
||||
viewsDir: path.join(__dirname, 'www_views')
|
||||
}
|
||||
tcrud.setup.expressBuild(buildOptions);
|
||||
|
||||
server.use(favicon());
|
||||
server.use(cookieParser(config.options.cookieParser.secretKey));
|
||||
|
||||
//server.get('/ui/thtml/*', tcrud.setup.express.renderTemplatePath('thtml/'));
|
||||
|
||||
server.use(expressWinston.errorLogger({
|
||||
transports: [new winston.transports.Console({json: false,colorize: true})]
|
||||
}));
|
||||
|
||||
tcrud.setup.expressListen();
|
||||
|
||||
//PHASE_6: post boot to from self.
|
||||
tcrud.setup.phaseServerUp();
|
||||
26
example/lib/ldapjs-example.js
Normal file
26
example/lib/ldapjs-example.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
var ldap = require('ldapjs');
|
||||
|
||||
module.exports = {
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
var client = ldap.createClient({
|
||||
url: 'ldap://127.0.0.1:389'
|
||||
});
|
||||
|
||||
// Create backend with id and uri
|
||||
tcrud.plugin.backend.ldapjs.registrate('ldapjs/main',client);
|
||||
|
||||
// Create tcrud models
|
||||
var tc = tcrud.config;
|
||||
var t = tc.createTEntityNode(tcrudModel,'ldapjs');
|
||||
t.tmeta.tmodel.tbackend = 'ldapjs/main';
|
||||
|
||||
// Define model and columns
|
||||
var tUser = tc.createTEntity(t,'cn=foo, o=example','cn');
|
||||
var tUserId = tc.createTField(tUser,'uid');
|
||||
var tUserName = tc.createTField(tUser,'sn');
|
||||
var tUserEmail = tc.createTField(tUser,'email');
|
||||
}
|
||||
153
example/lib/mongoose-blog.js
Normal file
153
example/lib/mongoose-blog.js
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
var mongoose = require('mongoose');
|
||||
var log = require('winston').loggers.get('main');
|
||||
var tcrud = require('../../lib/node-ff-tcrud');
|
||||
|
||||
module.exports = {
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
var mongoUrl = 'mongodb://localhost:27017/blog';
|
||||
var mongoOptions = {
|
||||
db: {
|
||||
fsync: false,
|
||||
journal: false,
|
||||
native_parser: true,
|
||||
forceServerObjectId: true
|
||||
},
|
||||
server: {
|
||||
poolSize: 4,
|
||||
socketOptions: {
|
||||
connectTimeoutMS: 500,
|
||||
keepAlive: 1,
|
||||
auto_reconnect: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
log.info('Connecting to: ' + mongoUrl);
|
||||
var conn = mongoose.createConnection(mongoUrl,mongoOptions);
|
||||
|
||||
tcrud.plugin.backend.mongoose.registrate('mongoose/blog',conn);
|
||||
conn.model('blog-state', modelSchemaBlogState, 'blog_state');
|
||||
|
||||
var tc = tcrud.config;
|
||||
var crudAdmin = tc.createTEntityNode(tcrudModel,'admin');
|
||||
crudAdmin.troles.push('admin');
|
||||
|
||||
var crudAdminModels = tcrud.plugin.backend.mongoose.buildTEntityModels(conn,crudAdmin);
|
||||
log.info('crud admin models created: '+crudAdminModels.length);
|
||||
crudAdminModels.forEach(function(model) {
|
||||
model.tmeta.tmodel.tbackend = 'mongoose/blog';
|
||||
});
|
||||
}
|
||||
|
||||
var modelMetaBlogState = {
|
||||
name: {
|
||||
type: String,
|
||||
trim: true,
|
||||
index: { unique: true },
|
||||
tfield: {
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
trim: true,
|
||||
index: { unique: false },
|
||||
tfield: {
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
trim: true,
|
||||
tfield: {
|
||||
xtype: 'textarea',
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
trim: true,
|
||||
tfield: {
|
||||
ttype: 'textarea',
|
||||
tvalidate: { io: 'string' },
|
||||
},
|
||||
},
|
||||
changed_date: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
tfield: {
|
||||
tlist: { tenable: false },
|
||||
},
|
||||
},
|
||||
created_date: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
tfield: {
|
||||
tlist: { tenable: false },
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var modelSchemaBlogState = new mongoose.Schema(modelMetaBlogState);
|
||||
modelSchemaBlogState.statics = tcrud.plugin.backend.mongoose.buildStaticsModelValidated(modelMetaBlogState,modelSchemaBlogState, {
|
||||
findLastChangedLimit5: function (callback) {
|
||||
log.debug(modelBackend+'.findLastChangedLimit5');
|
||||
this.find({}).sort('-changed_date').limit(5).exec(callback);
|
||||
},
|
||||
findOneByName: function (name, callback) {
|
||||
log.debug(modelBackend+'.findByName name='+name);
|
||||
this.findOne({name:name}).exec(callback);
|
||||
},
|
||||
ensureExcists: function (name, type, defaultValue, description, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
if (xprop == null) {
|
||||
log.debug(modelBackend+'.getByName create name='+name+' defaultValue='+defaultValue);
|
||||
var model = mongoose.model('blog-state');
|
||||
xprop = new model();
|
||||
xprop.name = name;
|
||||
xprop.type = type;
|
||||
xprop.value = defaultValue;
|
||||
xprop.description = description;
|
||||
xprop.save(function(err,xprop) {
|
||||
if (callback) {
|
||||
callback(err, xprop);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log.debug(modelBackend+'.getByName fetched name='+name);
|
||||
if (callback) {
|
||||
callback(null, xprop);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
setByName: function (name, value, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) { throw err }
|
||||
log.debug(modelBackend+'.setByName name='+name+' valueNew='+value+' valueOld='+xprop.value);
|
||||
xprop.value = value;
|
||||
xprop.save(function(err) {
|
||||
callback(err, xprop);
|
||||
});
|
||||
});
|
||||
},
|
||||
incByName: function (name, callback) {
|
||||
this.findOneByName(name, function(err, xprop) {
|
||||
if (err) { throw err }
|
||||
xprop.value++;
|
||||
log.debug(modelBackend+'.incByName name='+name+' value='+xprop.value);
|
||||
xprop.save(function(err) {
|
||||
callback(err, xprop);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
60
example/lib/pg-moviedb.js
Normal file
60
example/lib/pg-moviedb.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
var pgDB = require('pg');
|
||||
var pgDBNamed = require('node-postgres-named');
|
||||
|
||||
module.exports = {
|
||||
setup: setup,
|
||||
load: load
|
||||
};
|
||||
|
||||
function load(tcrud) {
|
||||
|
||||
// Create backend with id and uri
|
||||
tcrud.backend.database.loadPostgres('pg/moviedb','postgres://postgres:postgresql@localhost/moviedb',pgDB,pgDBNamed);
|
||||
}
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
// Create tcrud models
|
||||
var tc = tcrud.config;
|
||||
var t = tc.createTEntityNode(tcrudModel,'moviedb');
|
||||
t.tmeta.tmodel.tbackend = 'pg/moviedb';
|
||||
|
||||
// Define model and columns
|
||||
var tCompany = tc.createTEntity(t,'company','company_id');
|
||||
var tCompanyId = tc.createTField(tCompany,'company_id');
|
||||
var tCompanyName = tc.createTField(tCompany,'name');
|
||||
var tCompanyDateEst = tc.createTField(tCompany,'date_est');
|
||||
var tCompanyRemarks = tc.createTField(tCompany,'remarks');
|
||||
var tCompanyCountryId = tc.createTField(tCompany,'country_id');
|
||||
|
||||
var tCountry = tc.createTEntity(t,'country','country_id');
|
||||
|
||||
var tCountryCompany = tc.createTEntity(tCountry,'company','company_id');
|
||||
var tCountryCompanyId = tc.createTField(tCountryCompany,'company_id');
|
||||
var tCountryCompanyName = tc.createTField(tCountryCompany,'name');
|
||||
var tCountryCompanyDateEst = tc.createTField(tCountryCompany,'date_est');
|
||||
var tCountryCompanyRemarks = tc.createTField(tCountryCompany,'remarks');
|
||||
var tCountryCompanyCountryId = tc.createTField(tCountryCompany,'country_id');
|
||||
|
||||
var tCountryId = tc.createTField(tCountry,'country_id');
|
||||
var tCountryCode = tc.createTField(tCountry,'code');
|
||||
var tCountryName = tc.createTField(tCountry,'name');
|
||||
|
||||
var tDirector = tc.createTEntity(t,'director','director_id');
|
||||
var tDirectorId = tc.createTField(tDirector,'director_id');
|
||||
var tDirectorDateBorn = tc.createTField(tDirector,'date_born');
|
||||
var tDirectorDateDied = tc.createTField(tDirector,'date_died');
|
||||
var tDirectorFirstName = tc.createTField(tDirector,'first_name');
|
||||
var tDirectorLastName = tc.createTField(tDirector,'last_name');
|
||||
|
||||
var tGenre = tc.createTEntity(t,'genre','genre_id');
|
||||
var tGenreId = tc.createTField(tGenre,'genre_id');
|
||||
var tGenreCode = tc.createTField(tGenre,'code');
|
||||
var tGenreName = tc.createTField(tGenre,'name');
|
||||
|
||||
tCompany.tmeta.tmenu.ticon='fa fa-building';
|
||||
//tCountryCompany.tmeta.tmenu.ticon='fa fa-building';
|
||||
tCountry.tmeta.tmenu.ticon='fa fa-globe';
|
||||
tDirector.tmeta.tmenu.ticon='fa fa-cogs';
|
||||
tGenre.tmeta.tmenu.ticon='fa fa-star';
|
||||
}
|
||||
31
example/lib/pg-pagila.js
Normal file
31
example/lib/pg-pagila.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
var pgDB = require('pg');
|
||||
var pgDBNamed = require('node-postgres-named');
|
||||
|
||||
module.exports = {
|
||||
load: load,
|
||||
setup: setup
|
||||
};
|
||||
|
||||
function load(tcrud) {
|
||||
// Create backend with id and uri
|
||||
tcrud.backend.database.loadPostgres('pg/pagila','postgres://postgres:postgresql@localhost/pagila',pgDB,pgDBNamed);
|
||||
}
|
||||
|
||||
function setup(tcrud,tcrudModel) {
|
||||
|
||||
// Create tcrud models
|
||||
var tc = tcrud.config;
|
||||
var t = tc.createTEntityNode(tcrudModel,'pagila');
|
||||
t.tmeta.tmodel.tbackend = 'pg/pagila';
|
||||
|
||||
// Define model and columns
|
||||
var tLanguage = tc.createTEntity(t,'language','language_id');
|
||||
var tLanguageId = tc.createTField(tLanguage,'language_id');
|
||||
var tLanguageName = tc.createTField(tLanguage,'name');
|
||||
var tLanguageLastUpdate = tc.createTField(tLanguage,'last_update');
|
||||
|
||||
var tCountry = tc.createTEntity(t,'country','country_id');
|
||||
var tCountryId = tc.createTField(tCountry,'country_id');
|
||||
var tCountryCountry = tc.createTField(tCountry,'country');
|
||||
var tCountryLastUpdate = tc.createTField(tCountry,'last_update');
|
||||
}
|
||||
21
example/package.json
Normal file
21
example/package.json
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "node-ff-tcrud-example",
|
||||
"description": "node-ff-tcrud-example",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node example.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie-parser": "^1.0.1",
|
||||
"debug": "^2.2.0",
|
||||
"express-winston": "0.3.1",
|
||||
"static-favicon": "~1.0.0",
|
||||
"winston": "~0.7.3",
|
||||
"node-postgres-named": "^2.2.0",
|
||||
"pg": "^4.4.0",
|
||||
"mssql": "^2.1.6",
|
||||
"mysql2": "^0.15.8",
|
||||
"mongoose": "~3.8.13"
|
||||
}
|
||||
}
|
||||
10
example/www_views/js/page-bar.ejs
Normal file
10
example/www_views/js/page-bar.ejs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
pageRouteInit.push(function ($routeProvider, $locationProvider) {
|
||||
$routeProvider.when('/ui/bar', {
|
||||
templateUrl: '/ui/thtml/bar',
|
||||
controller: PageFoo
|
||||
});
|
||||
});
|
||||
|
||||
function PageFoo($scope, $http) {
|
||||
}
|
||||
10
example/www_views/js/page-foo.ejs
Normal file
10
example/www_views/js/page-foo.ejs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
pageRouteInit.push(function ($routeProvider, $locationProvider) {
|
||||
$routeProvider.when('/ui/foo', {
|
||||
templateUrl: '/ui/thtml/foo',
|
||||
controller: PageFoo
|
||||
});
|
||||
});
|
||||
|
||||
function PageFoo($scope, $http) {
|
||||
}
|
||||
10
example/www_views/js/page-home.ejs
Normal file
10
example/www_views/js/page-home.ejs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
pageRouteInit.push(function ($routeProvider, $locationProvider) {
|
||||
$routeProvider.when('/ui', {
|
||||
templateUrl: '/ui/thtml/home',
|
||||
controller: PageHome
|
||||
});
|
||||
});
|
||||
|
||||
function PageHome($scope, $http) {
|
||||
}
|
||||
4
example/www_views/thtml/bar.ejs
Normal file
4
example/www_views/thtml/bar.ejs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<h2>Bar</h2>
|
||||
<p>Welcome to the bar.</p>
|
||||
</div>
|
||||
4
example/www_views/thtml/foo.ejs
Normal file
4
example/www_views/thtml/foo.ejs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<h2>Foo</h2>
|
||||
<p>Welcome to the foo.</p>
|
||||
</div>
|
||||
4
example/www_views/thtml/home.ejs
Normal file
4
example/www_views/thtml/home.ejs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<h2>Example UI Index</h2>
|
||||
<p>Welcome make yourself at home.</p>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue