WIP open file for a while
This commit is contained in:
parent
f937019e42
commit
d280fb9af3
122 changed files with 5702 additions and 10 deletions
54
lib/plugin/auto/auto-tenable.js
Normal file
54
lib/plugin/auto/auto-tenable.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var autoFieldEnable = function(tfield,type) {
|
||||
if (type === undefined) {
|
||||
throw new Error('no type');
|
||||
}
|
||||
if (tfield[type] === undefined) {
|
||||
tfield[type] = {}; // todo rm this
|
||||
}
|
||||
if (tfield[type].tenable !== null) {
|
||||
return;
|
||||
}
|
||||
var fieldKey = tfield.tid;
|
||||
var result = true;
|
||||
if ('tlist' === type) {
|
||||
var name = fieldKey.toLowerCase();
|
||||
if (fieldKey.indexOf('description') >= 0) {
|
||||
result = false;
|
||||
} else if (fieldKey.indexOf('comment') >= 0) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
tfield[type].tenable = result;
|
||||
}
|
||||
|
||||
return function AutoTEnablePlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTEnable';
|
||||
ctx.description='Auto enables to true if undefined.';
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tenable === null || ctx.tentity.tenable === undefined) {
|
||||
ctx.tentity.tenable = true;
|
||||
}
|
||||
autoFieldEnable(ctx.tentity,'tlist');
|
||||
autoFieldEnable(ctx.tentity,'tread');
|
||||
autoFieldEnable(ctx.tentity,'tedit');
|
||||
autoFieldEnable(ctx.tentity,'tcreate');
|
||||
autoFieldEnable(ctx.tentity,'tdelete');
|
||||
autoFieldEnable(ctx.tentity,'tcount');
|
||||
autoFieldEnable(ctx.tentity,'tverify');
|
||||
}
|
||||
|
||||
this.fillTField = function(ctx) {
|
||||
autoFieldEnable(ctx.tfield,'tlist');
|
||||
autoFieldEnable(ctx.tfield,'tread');
|
||||
autoFieldEnable(ctx.tfield,'tedit');
|
||||
autoFieldEnable(ctx.tfield,'tcreate');
|
||||
}
|
||||
};
|
||||
})();
|
||||
45
lib/plugin/auto/auto-tmenu.js
Normal file
45
lib/plugin/auto/auto-tmenu.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
return function AutoTMenuPlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTMenu';
|
||||
ctx.description='Auto enables menu items.';
|
||||
ctx.dependencies.push('autoTEntityTPlural');
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tparent === null) {
|
||||
return; // root node
|
||||
}
|
||||
if (ctx.tentity.tmeta.tmodel.tid === null) {
|
||||
ctx.tentity.tmeta.tmenu.titem = false; // auto menu for items
|
||||
}
|
||||
|
||||
if (ctx.tentity.tmeta.tmenu.tenable === null || ctx.tentity.tmeta.tmenu.tenable === undefined) {
|
||||
ctx.tentity.tmeta.tmenu.tenable = true;
|
||||
}
|
||||
if (ctx.tentity.tmeta.tmenu.titem === null || ctx.tentity.tmeta.tmenu.titem === undefined) {
|
||||
ctx.tentity.tmeta.tmenu.titem = true;
|
||||
}
|
||||
if (ctx.tentity.tmeta.tmenu.tname === null || ctx.tentity.tmeta.tmenu.tname === undefined) {
|
||||
ctx.tentity.tmeta.tmenu.tname = ctx.tentity.tplural.substring(0,1).toUpperCase()+ctx.tentity.tplural.substring(1);
|
||||
}
|
||||
if (ctx.tentity.tmeta.tmenu.tkey === null || ctx.tentity.tmeta.tmenu.tkey === undefined) {
|
||||
if (ctx.tentity.tmeta.tmenu.titem) {
|
||||
ctx.tentity.tmeta.tmenu.tkey = ctx.tentity.tparent.tid;
|
||||
} else {
|
||||
ctx.tentity.tmeta.tmenu.tkey = ctx.tentity.tid;
|
||||
}
|
||||
}
|
||||
if (ctx.tentity.tmeta.tmenu.ticon === null || ctx.tentity.tmeta.tmenu.ticon === undefined) {
|
||||
if (ctx.tentity.tmeta.tmenu.titem) {
|
||||
ctx.tentity.tmeta.tmenu.ticon = 'fa fa-table';
|
||||
} else {
|
||||
ctx.tentity.tmeta.tmenu.ticon = 'fa fa-cubes';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
50
lib/plugin/auto/auto-tname.js
Normal file
50
lib/plugin/auto/auto-tname.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var createName = function (fieldKey,fieldName) {
|
||||
if (fieldKey === undefined) {
|
||||
throw new Error('no fieldKey');
|
||||
}
|
||||
if (fieldName && fieldName.length !== 0) {
|
||||
return fieldName;
|
||||
}
|
||||
var result = '';
|
||||
var names = fieldKey.split('_');
|
||||
for (var i in names) {
|
||||
var name = names[i];
|
||||
if (name.length > 1) {
|
||||
name = name.substring(0,1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
result = result + ' ' + name;
|
||||
}
|
||||
return result.substring(1); // remove first space
|
||||
};
|
||||
|
||||
var filterName = function(ctx,value) {
|
||||
return ctx.filterValue(value,['_','-','.',','],' ', function (part) {
|
||||
return part.substring(0,1).toUpperCase()+part.substring(1).toLowerCase();
|
||||
});
|
||||
};
|
||||
|
||||
return function AutoTNamePlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTName';
|
||||
ctx.description='Auto fills and checks the tname fields.';
|
||||
};
|
||||
|
||||
this.fillTField = function(ctx) {
|
||||
if (ctx.tfield.tname === null) {
|
||||
ctx.tfield.tname = createName(ctx.tfield.tid);
|
||||
} else {
|
||||
//ctx.tfield.tname = filterName(ctx,ctx.tfield.tname);
|
||||
}
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tname === null) {
|
||||
ctx.tentity.tname = ctx.tentity.tid;//
|
||||
}
|
||||
};
|
||||
};
|
||||
})();
|
||||
47
lib/plugin/auto/auto-tslug.js
Normal file
47
lib/plugin/auto/auto-tslug.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var filterSlug = function(ctx,value) {
|
||||
return ctx.filterValue(value,['.',',','/','=','&','?',' '],'', function (part) {
|
||||
return part; // todo use fully correct uri removeal and escaping.
|
||||
})
|
||||
};
|
||||
|
||||
var createTViewSlug = function(tentity) {
|
||||
var uriViewSlash = '/';
|
||||
var slug = uriViewSlash + tentity.tslug;
|
||||
if (!tentity.tenable || !tentity.tparent) {
|
||||
slug = '';
|
||||
}
|
||||
if (tentity.tparent) {
|
||||
return createTViewSlug(tentity.tparent)+slug;
|
||||
}
|
||||
return slug;
|
||||
};
|
||||
|
||||
return function AutoTSlugPlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTSlug';
|
||||
ctx.description='Auto fills and checks the tslug fields.';
|
||||
};
|
||||
|
||||
this.fillTField = function(ctx) {
|
||||
if (ctx.tfield.tslug === undefined || ctx.tfield.tslug === null) {
|
||||
ctx.tfield.tslug = ctx.tfield.tid;
|
||||
}
|
||||
ctx.tfield.tslug = filterSlug(ctx,ctx.tfield.tslug);
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tslug === null) {
|
||||
ctx.tentity.tslug = ctx.tentity.tid;
|
||||
}
|
||||
ctx.tentity.tslug = filterSlug(ctx,ctx.tentity.tslug);
|
||||
};
|
||||
|
||||
this.fillTView = function(ctx) {
|
||||
ctx.tview.tslug = createTViewSlug(ctx.tentity).substring(1);
|
||||
}
|
||||
};
|
||||
})();
|
||||
24
lib/plugin/auto/tentity/auto-tentity-tcode.js
Normal file
24
lib/plugin/auto/tentity/auto-tentity-tcode.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var filterCode = function(ctx,value) {
|
||||
return ctx.filterValue(value,[' ','_','-','.',','],'',function (part) {
|
||||
return part.toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
return function AutoTEntityTCodePlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTEntityTCode';
|
||||
ctx.description='Fills and filters tcode to be code-safe for generating variables/functions.';
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tcode === null || ctx.tentity.tcode === null) {
|
||||
ctx.tentity.tcode = ctx.tentity.tid;
|
||||
}
|
||||
ctx.tentity.tcode = filterCode(ctx,ctx.tentity.tcode);
|
||||
};
|
||||
};
|
||||
})();
|
||||
29
lib/plugin/auto/tentity/auto-tentity-tkey.js
Normal file
29
lib/plugin/auto/tentity/auto-tentity-tkey.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var makeTKey = function(ctx) {
|
||||
var keySlug = '';
|
||||
for (var i = 0; i < ctx.tentity.tmeta.tmodel.tkeys.length; i++) {
|
||||
var key = ctx.tentity.tmeta.tmodel.tkeys[i];
|
||||
keySlug += ':'+key;
|
||||
if (i < (ctx.tentity.tmeta.tmodel.tkeys.length - 1)) {
|
||||
keySlug += '/';
|
||||
}
|
||||
}
|
||||
return keySlug;
|
||||
};
|
||||
|
||||
return function AutoTEntityTKeyPlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTEntityTKey';
|
||||
ctx.description='Auto creates the tmode.tkey parameter slug.';
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tmeta.tmodel.tkey === null) {
|
||||
ctx.tentity.tmeta.tmodel.tkey = makeTKey(ctx);
|
||||
}
|
||||
};
|
||||
};
|
||||
})();
|
||||
32
lib/plugin/auto/tentity/auto-tentity-tplural.js
Normal file
32
lib/plugin/auto/tentity/auto-tentity-tplural.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
var makePlural = function(name) {
|
||||
if (name.slice(-1) === 's') {
|
||||
return name;
|
||||
}
|
||||
if (name.slice(-1) === 'y') {
|
||||
name = name.slice(0,-1) + 'ie';
|
||||
}
|
||||
return name + 's';
|
||||
}
|
||||
|
||||
return function AutoTEntityTPluralPlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTEntityTPlural';
|
||||
ctx.description='Auto create tplurals from the tname/tid field.';
|
||||
ctx.dependencies.push('autoTName');
|
||||
};
|
||||
|
||||
this.fillTEntity = function(ctx) {
|
||||
if (ctx.tentity.tplural === null) {
|
||||
if (ctx.tentity.tname === null) {
|
||||
ctx.tentity.tplural = makePlural(ctx.tentity.tid);
|
||||
} else {
|
||||
ctx.tentity.tplural = makePlural(ctx.tentity.tname);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})();
|
||||
53
lib/plugin/auto/tview/auto-tview-ftl.js
Normal file
53
lib/plugin/auto/tview/auto-tview-ftl.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
module.exports = (function () {
|
||||
|
||||
function forceLookupTFields(tview) {
|
||||
var keys = Object.keys(tview.tmeta.tfields);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
var keyNew = 'FTL_' +forceLookupKeySimple() + '_' + key.substring(key.length/3,key.length/3*2); // no....its; Force template lookup
|
||||
var tfield = tview.tmeta.tfields[key];
|
||||
tview.tmeta.tfields[key] = undefined;
|
||||
tview.tmeta.tfields[keyNew] = tfield;
|
||||
|
||||
var ckeys = Object.keys(tview);
|
||||
for (var ii = 0; ii < ckeys.length; ii++) {
|
||||
var ckey = ckeys[ii];
|
||||
if (ckey === 'tmeta') {
|
||||
continue;
|
||||
}
|
||||
var obj = tview[ckey];
|
||||
if (obj && obj.tfields) {
|
||||
var tfieldsNew = [];
|
||||
for (var iii = 0; iii < obj.tfields.length; iii++) {
|
||||
var tkey = obj.tfields[iii];
|
||||
if (tkey === key) {
|
||||
tfieldsNew.push(keyNew);
|
||||
} else {
|
||||
tfieldsNew.push(tkey);
|
||||
}
|
||||
}
|
||||
obj.tfields = tfieldsNew;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function forceLookupKeySimple() {
|
||||
var low = 100000;
|
||||
var high = 999999;
|
||||
return Math.floor(Math.random() * (high - low + 1) + low).toString(16).toUpperCase();
|
||||
}
|
||||
|
||||
return function AutoTViewFTLPlugin() {
|
||||
|
||||
this.configPlugin = function (ctx) {
|
||||
ctx.key='autoTViewFTL';
|
||||
ctx.description='Automatic tview tfields key change to force table lookup.';
|
||||
};
|
||||
|
||||
this.fillTView = function(ctx) {
|
||||
forceLookupTFields(ctx.tview);
|
||||
};
|
||||
};
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue