Skip to content

Commit

Permalink
Merged branch refactor-selec-2 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 22, 2016
2 parents 2e88135 + dc5e0c6 commit c44d23e
Show file tree
Hide file tree
Showing 16 changed files with 617 additions and 470 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ src/server/public/css/styles.css
cli/config/*-local.js

# debug
abe-logs/*
test/*
abe-logs/*
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"url": "git://github.com/AdFabConnect/abejs.git"
},
"scripts": {
"test": "mocha --compilers js:babel-core/register",
"start": "node --debug --harmony ./dist/server/index.js",
"startpm2": "pm2 startOrRestart ./processes.json",
"babel": "babelify src/server/public/scripts/template-engine.js -o src/server/public/scripts/template-engine-compiled.js",
Expand Down Expand Up @@ -82,7 +83,9 @@
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"chai": "^3.5.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"node-sass": "^3.6.0",
"nodemon": "^1.8.1",
"parallelshell": "^2.0.0",
Expand Down
14 changes: 7 additions & 7 deletions src/cli/handlebars/abe/listPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function listPage(file, index, text) {
res += `<tr>`
res += `<td>${math(index, '+', 1)}</td>
<td>
<a href="/abe/${file.template}?filePath=${file.fileUrl}" class="file-path">
${file.fileUrl}
<a href="/abe/${file.template}?filePath=${file.abe_meta.link}" class="file-path">
${file.abe_meta.link}
</a>
</td>`

Expand All @@ -37,9 +37,9 @@ export default function listPage(file, index, text) {

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.template}?filePath=${file.fileUrl}" class="label label-default label-draft">draft</a>`
workflow += `<a href="/abe/${file.template}?filePath=${file.abe_meta.link}" class="label label-default label-draft">draft</a>`
}else {
workflow += `<a href="/abe/${file.template}?filePath=${file.fileUrl}" class="hidden label label-default label-draft"></a>`
workflow += `<a href="/abe/${file.template}?filePath=${file.abe_meta.link}" class="hidden label label-default label-draft"></a>`
}

workflow += `</td>`
Expand All @@ -57,9 +57,9 @@ export default function listPage(file, index, text) {
<div class="row icons-action">`

if (this.published){
res += `<a href="/unpublish/?filePath=${file.fileUrl}"
res += `<a href="/unpublish/?filePath=${file.abe_meta.link}"
title="${text.unpublish}"
class="icon" data-unpublish="true" data-text="${text.confirmUnpublish} ${file.fileUrl}">
class="icon" data-unpublish="true" data-text="${text.confirmUnpublish} ${file.abe_meta.link}">
<span class="glyphicon glyphicon-eye-close"></span>
</a>`
}
Expand All @@ -68,7 +68,7 @@ export default function listPage(file, index, text) {
title="${text.delete}"
class="icon"
data-delete="true"
data-text="${text.confirmDelete} ${file.fileUrl}">
data-text="${text.confirmDelete} ${file.abe_meta.link}">
<span class="glyphicon glyphicon-trash"></span>
</a>`

Expand Down
35 changes: 22 additions & 13 deletions src/cli/handlebars/abe/sourceAttr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,38 @@ export default function sourceAttr(val, params) {
if(typeof hiddenVal === 'object' && Object.prototype.toString.call(hiddenVal) === '[object Object]') {
hiddenVal = JSON.stringify(hiddenVal).replace(/'/g, "&apos;")

var displayVal = Sql.deep_value_array(val, params.display)
if(typeof params.display !== 'undefined' && params.display !== null
&& typeof displayVal !== 'undefined' && displayVal !== null) {
val = displayVal
}else {
try {
var displayVal = eval('val.' + params.display)
if(typeof params.display !== 'undefined' && params.display !== null
&& typeof displayVal !== 'undefined' && displayVal !== null) {
val = displayVal
}else {
val = val[Object.keys(val)[0]]
}
}catch(e) {
val = val[Object.keys(val)[0]]
}
}

if(typeof params.value === 'object' && Object.prototype.toString.call(params.value) === '[object Array]') {
Array.prototype.forEach.call(params.value, (v) => {
var item = v
var displayV = Sql.deep_value_array(item, params.display)
if(typeof params.display !== 'undefined' && params.display !== null
&& typeof displayV !== 'undefined' && displayV !== null) {
item = displayV
}else {
if(typeof v === 'string') {
item = v
try {
var displayV = eval('item.' + params.display)
if(typeof params.display !== 'undefined' && params.display !== null
&& typeof displayV !== 'undefined' && displayV !== null) {
item = displayV
}else {
item = v[Object.keys(v)[0]]
if(typeof v === 'string') {
item = v
}else {
item = v[Object.keys(v)[0]]
}
}
}catch(e) {
item = v[Object.keys(v)[0]]
}

if(typeof val === 'object' && Object.prototype.toString.call(val) === '[object Array]'
&& typeof item === 'object' && Object.prototype.toString.call(item) === '[object Array]') {

Expand Down
33 changes: 0 additions & 33 deletions src/cli/helpers/abe-deep-val.js

This file was deleted.

53 changes: 35 additions & 18 deletions src/cli/helpers/abe-get-select-template-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,49 @@ import {
Manager
} from '../../cli'

var traverseFileSystem = function (currentPath, arr) {
var res = []
var files = fse.readdirSync(currentPath);
for (var i in files) {
var currentFile = currentPath + '/' + files[i]
var stats = fse.statSync(currentFile)
if (stats.isFile()) {
if (currentFile.indexOf(config.files.templates.extension) > -1) {
res.push(currentFile)
}
}
else if (stats.isDirectory()) {
res = res.concat(traverseFileSystem(currentFile))
}
}
return res
};

var findTemplates = function(templatesPath) {
var p = new Promise((resolve, reject) => {
execFile('find', [ templatesPath ], (err, stdout, stderr) => {
if (err) reject(err)

var file_list = stdout.split('\n')
var file_list_with_extention = []
Array.prototype.forEach.call(file_list, (file) => {
if (file.indexOf(config.files.templates.extension) > -1) {
file_list_with_extention.push(file)
}
})

resolve(file_list_with_extention)
});
let templatesList = traverseFileSystem(templatesPath)
resolve(templatesList)
})

return p
}

var findRequestKeys = function(file_list_with_extention) {
/**
* Get columns and where.left ids of a select statement
*
* select title, image from ../ where template=""
*
* return [title, image, template]
*
* @param {Array} templatesList ["article.html", "other.html"]
* @return {Promise}
*/
var findRequestColumns = function(templatesList) {
var whereKeysCheck = {}
var whereKeys = []
var p = new Promise((resolve, reject) => {
let util = new Util()
Array.prototype.forEach.call(file_list_with_extention, (file) => {
Array.prototype.forEach.call(templatesList, (file) => {
var template = fse.readFileSync(file, 'utf8')
var matches = util.dataRequest(template)

Expand Down Expand Up @@ -78,15 +95,15 @@ var findRequestKeys = function(file_list_with_extention) {
var getSelectTemplateKeys = function(templatesPath) {
var p = new Promise((resolve, reject) => {
findTemplates(templatesPath)
.then((file_list_with_extention) => {
.then((templatesList) => {

findRequestKeys(file_list_with_extention)
findRequestColumns(templatesList)
.then((whereKeys) => {

resolve(whereKeys)
},
() => {
console.log('findRequestKeys reject')
console.log('findRequestColumns reject')
reject()
})
.catch((e) => {
Expand Down
12 changes: 0 additions & 12 deletions src/cli/helpers/abe-set-deep-value.js

This file was deleted.

Loading

0 comments on commit c44d23e

Please sign in to comment.