Skip to content

Commit

Permalink
Select data become a first class citizen in Manager => perf X50 on pa…
Browse files Browse the repository at this point in the history
…ge display including templates with select statements
  • Loading branch information
gregorybesson committed Sep 23, 2016
1 parent ce267eb commit e5b7b95
Show file tree
Hide file tree
Showing 23 changed files with 1,413 additions and 1,281 deletions.
7 changes: 6 additions & 1 deletion dist/cli/config/abe-config.js
Expand Up @@ -101,7 +101,12 @@ var config = {
partials: 'templates/partials',
custom: 'custom',
siteUrl: false,
sitePort: false
sitePort: false,
redis: {
enable: false,
port: '6379',
host: '127.0.0.1'
}
};

exports.default = config;
8 changes: 7 additions & 1 deletion dist/cli/controllers/Save.js
Expand Up @@ -86,12 +86,14 @@ function save(url, tplPath) {
url = (0, _.cleanSlug)(url);

var p = new _es6Promise.Promise(function (resolve, reject) {
var isRejectedDoc = false;
if (type === 'reject') {
isRejectedDoc = true;
url = _.Hooks.instance.trigger('beforeReject', url);
type = 'draft';
realType = 'draft';
url = _.Hooks.instance.trigger('afterReject', url);
resolve({ reject: _.fileAttr.delete(url).replace(_path2.default.join(_.config.root, _.config.draft.url), '') });
// resolve({reject: fileAttr.delete(url).replace(path.join(config.root, config.draft.url), '')})
}
var tplUrl = _.FileParser.getFileDataFromUrl(url);
type = type || _.FileParser.getType(url);
Expand Down Expand Up @@ -174,6 +176,9 @@ function save(url, tplPath) {
text = _.Util.removeDataList(text);

var res = saveJsonAndHtml(tpl.replace(/^\/+/, ''), obj, text, type);
if (isRejectedDoc) {
res.reject = _.fileAttr.delete(url).replace(_path2.default.join(_.config.root, _.config.draft.url), '');
}

obj = _.Hooks.instance.trigger('afterSave', obj);

Expand Down Expand Up @@ -234,6 +239,7 @@ function saveJson(url, json) {
space: 2,
encoding: 'utf-8'
});
return true;
}

function saveHtml(url, html) {
Expand Down
7 changes: 6 additions & 1 deletion dist/cli/handlebars/abe/compileAbe.js
Expand Up @@ -33,7 +33,12 @@ function compileAbe() {
key = key[key.length - 1];
var hash = arguments[0].hash;
hash.key = hash.key.replace(/\{\{@index\}\}/, '[{{@index}}]');
var value = content ? content[hash['dictionnary']][arguments[0].data.index][key] : hash.key;
var value;
try {
value = content ? content[hash['dictionnary']][arguments[0].data.index][key] : hash.key;
} catch (e) {
value = '';
}
if (typeof value === 'undefined' || typeof value === 'function' || value === null) {
value = '';
}
Expand Down
18 changes: 8 additions & 10 deletions dist/cli/handlebars/abe/listPage.js
Expand Up @@ -3,9 +3,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

exports.default = listPage;

var _handlebars = require('handlebars');
Expand All @@ -26,6 +23,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function listPage(file, index, text) {
var res = '';

file = _.Hooks.instance.trigger('beforeListPage', file, index, text);

res += '<tr>';
Expand All @@ -48,17 +46,17 @@ function listPage(file, index, text) {
var workflow = '';

workflow += '<td align="center" class="draft">';
if (_typeof(file.published) !== undefined && file.published !== null && !file.published || file.published && file.draft && file.published.date < file.draft.date) {
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="label label-default label-draft">draft</a>';
if (typeof file.publish === "undefined" || file.publish === null || file.publish && file.draft && file.publish.date < file.draft.date) {
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.draft.html + '" class="label label-default label-draft">draft</a>';
} else {
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="hidden label label-default label-draft"></a>';
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.draft.html + '" class="hidden label label-default label-draft">draft</a>';
}

workflow += '</td>';
workflow += '<td align="center" class="publish">';

if (file.published) {
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.published.filePath + '" class="checkmark label-published">&#10004;</a>';
if (file.publish) {
workflow += '<a href="/abe/' + file.abe_meta.template + '?filePath=' + file.abe_meta.link + '" class="checkmark label-published">&#10004;</a>';
}
workflow += '</td>';

Expand All @@ -67,11 +65,11 @@ function listPage(file, index, text) {

res += '<td align="center">\n <div class="row icons-action">';

if (this.published) {
if (typeof file.publish !== 'undefined' && file.publish !== null) {
res += '<a href="/unpublish/?filePath=' + file.abe_meta.link + '"\n title="' + text.unpublish + '"\n class="icon" data-unpublish="true" data-text="' + text.confirmUnpublish + ' ' + file.abe_meta.link + '">\n <span class="glyphicon glyphicon-eye-close"></span>\n </a>';
}

res += '<a href="/delete/?filePath=' + this.path + '"\n title="' + text.delete + '"\n class="icon"\n data-delete="true"\n data-text="' + text.confirmDelete + ' ' + file.abe_meta.link + '">\n <span class="glyphicon glyphicon-trash"></span>\n </a>';
res += '<a href="/delete/?filePath=' + file.abe_meta.link + '"\n title="' + text.delete + '"\n class="icon"\n data-delete="true"\n data-text="' + text.confirmDelete + ' ' + file.abe_meta.link + '">\n <span class="glyphicon glyphicon-trash"></span>\n </a>';

res += '\n </div>\n </td>\n </tr>';

Expand Down
44 changes: 19 additions & 25 deletions dist/cli/helpers/abe-duplicate.js
Expand Up @@ -18,39 +18,33 @@ var duplicate = function duplicate(oldFilePath, template, newPath, name, req) {
var p = new Promise(function (resolve, reject) {
_cli.Hooks.instance.trigger('beforeDuplicate', oldFilePath, template, newPath, name, req, isUpdate);

var json = {};
var revisions = [];
if (typeof oldFilePath !== 'undefined' && oldFilePath !== null) {
var url = _path2.default.join(_cli.config.root, _cli.config.draft.url, oldFilePath);
var revisions = [];

if (!_cli.fileAttr.test(url)) {
var folderFilePath = url.split('/');
folderFilePath.pop();
folderFilePath = _cli.fileUtils.pathWithRoot(folderFilePath.join('/'));

var files = _cli.FileParser.getFiles(folderFilePath, true, 2);
revisions = _cli.fileAttr.getFilesRevision(files, url);
var latest = _cli.fileAttr.filterLatestVersion(revisions, 'draft');
if (latest.length) {
url = latest[0].path;
var files = _cli.Manager.instance.getList();
var fileWithoutExtension = oldFilePath.replace('.' + _cli.config.files.templates.extension, '');

var doc = null;
Array.prototype.forEach.call(files, function (file) {
if (file.path.indexOf(fileWithoutExtension) > -1) {
doc = file;
}
});

if (typeof doc.revisions !== 'undefined' && doc.revisions !== null) {
revisions = doc.revisions;

if (typeof revisions !== 'undefined' && revisions !== null && typeof revisions[0] !== 'undefined' && revisions[0] !== null) {
json = _cli.FileParser.getJson(revisions[0].path);
}
} else if (isUpdate) {
files = _cli.FileParser.getFiles(folderFilePath, true, 2);
revisions = _cli.fileAttr.getFilesRevision(files, url);
}

var tplUrl = _cli.FileParser.getFileDataFromUrl(url);
if (!_cli.fileUtils.isFile(tplUrl.json.path)) {} else {}
var json = _cli.FileParser.getJson(tplUrl.json.path);
delete json.abe_meta;
}

if (isUpdate) {
_cli.Hooks.instance.trigger('beforeUpdate', json, oldFilePath, template, newPath, name, req, isUpdate);
Array.prototype.forEach.call(revisions, function (revision) {
if (typeof revision.path !== 'undefined' && revision.path !== null) {
_cli.FileParser.deleteFile(revision.path);
}
});
_cli.FileParser.deleteFile(oldFilePath);
}
_cli.Hooks.instance.trigger('afterDuplicate', json, oldFilePath, template, newPath, name, req, isUpdate);

Expand All @@ -60,7 +54,7 @@ var duplicate = function duplicate(oldFilePath, template, newPath, name, req) {
}, function () {
reject();
}).catch(function (e) {
console.error(e);
console.error('[ERROR] abe-duplicate.js', e);
reject();
});
});
Expand Down
49 changes: 19 additions & 30 deletions dist/cli/helpers/abe-sql.js
Expand Up @@ -365,23 +365,14 @@ var Sql = function () {

var list = _.Manager.instance.getList();
var files_array = list.filter(function (element, index, arr) {
if (element.published) {
if (element.publish) {
if (element.path.indexOf(fromDirectory) > -1) {
return true;
}
}
return false;
});
return files_array;

// if(folderUtils.isFolder(fromDirectory)) {
// // we'll get only published files which don't contain "-abe-"
// files = FileParser.getFiles(fromDirectory, true, recursive, fileRegex, true)
// }
// console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
// console.log('files', files)

// return files
}
}, {
key: 'execQuery',
Expand Down Expand Up @@ -449,28 +440,26 @@ var Sql = function () {
var file = _step.value;

if (limit < maxLimit || maxLimit === -1) {
if (file.published === true) {
var doc = Sql.executeWhereClauseOnDocument(file, wheres, jsonPage);

if (doc) {
var json = JSON.parse(JSON.stringify(doc));
var jsonValues = {};

if (typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {

Array.prototype.forEach.call(columns, function (column) {
if (typeof json[column] !== 'undefined' && json[column] !== null) {
jsonValues[column] = json[column];
}
});
jsonValues[_.config.meta.name] = json[_.config.meta.name];
} else {
jsonValues = json;
}
var doc = Sql.executeWhereClauseOnDocument(file.publish, wheres, jsonPage);

if (doc) {
var json = JSON.parse(JSON.stringify(doc));
var jsonValues = {};

res.push(jsonValues);
limit++;
if (typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {

Array.prototype.forEach.call(columns, function (column) {
if (typeof json[column] !== 'undefined' && json[column] !== null) {
jsonValues[column] = json[column];
}
});
jsonValues[_.config.meta.name] = json[_.config.meta.name];
} else {
jsonValues = json;
}

res.push(jsonValues);
limit++;
}
} else {
break;
Expand Down
52 changes: 51 additions & 1 deletion dist/cli/helpers/file-attr.js
Expand Up @@ -35,7 +35,6 @@ var Attr = function () {
* @param {String} str string to work with
* @return {void}
*/

function Attr(str) {
_classCallCheck(this, Attr);

Expand Down Expand Up @@ -202,6 +201,57 @@ var FileAttr = function () {
});
return res;
}
}, {
key: 'sortByDateDesc',
value: function sortByDateDesc(a, b) {
var dateA = new Date(a.date);
var dateB = new Date(b.date);
if (dateA < dateB) {
return 1;
} else if (dateA > dateB) {
return -1;
}
return 0;
}

/**
* Filter and array of file path and return the latest version of those files
* @param {Object} urls object with path to file, filename etc ...
* @param {String} type (draft|waiting|valid)
* @return {Object} urls object filtered
*/

}, {
key: 'getVersions',
value: function getVersions(docPath) {
var files = _.Manager.instance.getList();
var fileWithoutExtension = docPath.replace('.' + _.config.files.templates.extension, '');

var result = [];
Array.prototype.forEach.call(files, function (file) {
if (file.path.indexOf(fileWithoutExtension) > -1) {
result = file.revisions;
}
});
return result;
}

/**
* Filter and array of file path and return the latest version of those files
* @param {Object} urls object with path to file, filename etc ...
* @param {String} type (draft|waiting|valid)
* @return {Object} urls object filtered
*/

}, {
key: 'getLatestVersion',
value: function getLatestVersion(docPath) {
var sameFiles = FileAttr.getVersions(docPath);
if (sameFiles.length > 0) {
return sameFiles[sameFiles.length - 1];
}
return null;
}

/**
* Filter and array of file path and return the latest version of those files
Expand Down
24 changes: 13 additions & 11 deletions dist/cli/helpers/file-parser.js
Expand Up @@ -113,7 +113,7 @@ var FileParser = function () {
date: date,
cleanDate: fileDate.format("YYYY/MM/DD HH:MM:ss"),
duration: duration,
status: status,
// status: status,
cleanName: cleanName,
cleanNameNoExt: cleanNameNoExt,
cleanFilePath: cleanFilePath,
Expand Down Expand Up @@ -277,7 +277,7 @@ var FileParser = function () {
};

var extension = _.config.files.templates.extension;
if (typeof url !== 'undefined' && url !== null && url.indexOf('.' + extension) > -1) {
if (typeof url !== 'undefined' && url !== null) {

var dir = _.fileUtils.removeLast(url).replace(_.config.root, '');
var filename = _.fileUtils.filename(url);
Expand Down Expand Up @@ -454,9 +454,16 @@ var FileParser = function () {
var json = FileParser.getJson(file.path);

if (typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
cleanFile.abe_meta = json.abe_meta;
cleanFile.abe_meta = {
date: typeof json.abe_meta.date !== 'undefined' && json.abe_meta.date !== null ? json.abe_meta.date : null,
type: typeof json.abe_meta.type !== 'undefined' && json.abe_meta.type !== null ? json.abe_meta.type : null,
link: typeof json.abe_meta.link !== 'undefined' && json.abe_meta.link !== null ? json.abe_meta.link : null,
template: typeof json.abe_meta.template !== 'undefined' && json.abe_meta.template !== null ? json.abe_meta.template : null,
status: typeof json.abe_meta.status !== 'undefined' && json.abe_meta.status !== null ? json.abe_meta.status : null,
cleanName: typeof json.abe_meta.cleanName !== 'undefined' && json.abe_meta.cleanName !== null ? json.abe_meta.cleanName : null,
cleanFilename: typeof json.abe_meta.cleanFilename !== 'undefined' && json.abe_meta.cleanFilename !== null ? json.abe_meta.cleanFilename : null
};
}

Array.prototype.forEach.call(withKeys, function (key) {
var keyFirst = key.split('.')[0];
cleanFile[keyFirst] = json[keyFirst];
Expand Down Expand Up @@ -505,18 +512,13 @@ var FileParser = function () {
value: function deleteFile(filePath) {
filePath = _.Hooks.instance.trigger('beforeDeleteFile', filePath);

var tplUrl = FileParser.getFileDataFromUrl(_path2.default.join(_.config.draft.url, filePath));
var files = FileParser.getFiles(tplUrl.draft.dir, true, 1, new RegExp("\\." + _.config.files.templates.extension));
var revisions = _.fileAttr.getFilesRevision(files, tplUrl.publish.file);
var revisions = _.fileAttr.getVersions(filePath);

Array.prototype.forEach.call(revisions, function (revision) {
var revisionUrl = FileParser.getFileDataFromUrl(revision.path);
FileParser.removeFile(revision.path, revisionUrl.json.path);
FileParser.removeFile(revision.path, revision.htmlPath);
});

FileParser.removeFile(tplUrl.publish.path, tplUrl.publish.json);
_.Manager.instance.updateList();
tplUrl.publish.path = _.Hooks.instance.trigger('afterDeleteFile', tplUrl.publish.path, tplUrl.publish.json);
}
}, {
key: 'deleteFileFromName',
Expand Down

0 comments on commit e5b7b95

Please sign in to comment.