Skip to content

Commit

Permalink
refactor select
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Sep 21, 2016
1 parent 0d82a4c commit d5b5ab2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/cli/helpers/abe-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ export default class Sql {

var dateStart = new Date()

console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('executeFromClause')
var list = Manager.instance.getList()
var files_array = list.filter((element, index, arr) => {
if(element.published) {
Expand All @@ -334,7 +332,6 @@ export default class Sql {
}
return false
})
console.log(((new Date().getTime() - dateStart.getTime()) / 1000) + 'sec')
return files_array

// if(folderUtils.isFolder(fromDirectory)) {
Expand Down
37 changes: 37 additions & 0 deletions src/cli/helpers/abe-time-mesure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import clc from 'cli-color'

export default class TimeMesure {

constructor(str) {
this._name = str
console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
if(typeof str !== 'undefined' && str !== null) {
console.log('start: ' + clc.green(str))
}
this._dateStart = new Date()
}

_msToTime(duration) {
var milliseconds = parseInt((duration%1000)/100)
, seconds = parseInt((duration/1000)%60)
, minutes = parseInt((duration/(1000*60))%60)
, hours = parseInt((duration/(1000*60*60))%24);

hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}

/**
* Get all input from a template
* @return {Array} array of input form
*/
duration(str) {
var d = new Date(new Date().getTime() - this._dateStart.getTime()).getTime()
console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('d', d)
console.log((this._name ? 'end ' + this._name : "") + "(" + clc.green(this._msToTime(d)) + ") " + (str ? str : ""))
}
}
15 changes: 6 additions & 9 deletions src/cli/helpers/abe-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
,getAttr
,Hooks
,Plugins
,TimeMesure
} from '../'

export default class Utils {
Expand Down Expand Up @@ -446,15 +447,13 @@ export default class Utils {

static performDataList(tplPath, text, jsonPage, matches, cb) {
var match = matches.shift()
var dateStart = new Date()
var t = new TimeMesure('performDataList')

console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('performDataList')
console.log(match)
console.log(match[0])

Utils.nextDataList(tplPath, text, jsonPage, match)
Utils.nextDataList(tplPath, text, jsonPage, match[0])
.then(() => {
console.log(((new Date().getTime() - dateStart.getTime()) / 1000) + 'sec')
t.duration()
if (matches.length > 0) {
Utils.performDataList(tplPath, text, jsonPage, matches, cb)
}else {
Expand All @@ -472,9 +471,7 @@ export default class Utils {
var promises = []
let util = new Utils()
var matches = util.dataRequest(text)
console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('matches', matches)
Utils.performDataList(tplPath, text, jsonPage, matches[0], () => {
Utils.performDataList(tplPath, text, jsonPage, matches, () => {
resolve()
})
// Array.prototype.forEach.call(matches, (match) => {
Expand Down
19 changes: 19 additions & 0 deletions src/cli/helpers/file-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
,Manager
,set_deep_value
,deep_value
,TimeMesure
} from '../'

export default class FileParser {
Expand Down Expand Up @@ -397,13 +398,20 @@ export default class FileParser {

var files = FileParser.getFiles(path.join(config.root, config.data.url), true, 99, /\.json/)
var filesArr = []

var i = 0

var t2 = new TimeMesure('files.forEach')
files.forEach(function (file) {
// var t = new TimeMesure('add files')
var cleanFile = file
var json = FileParser.getJson(file.path)

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
cleanFile.abe_meta = json.abe_meta
}
/**
* OLD
Array.prototype.forEach.call(withKeys, (key) => {
// console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
// console.log(key, key.split('.').reduce((o,i)=>o[i], json))
Expand All @@ -414,8 +422,19 @@ export default class FileParser {
set_deep_value(cleanFile, key, deep_value(json, key))
}
})
*/
Array.prototype.forEach.call(withKeys, (key) => {
var current = json
key.split('.').forEach(function(p){ current = current[p] })

console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('current', current)
})
filesArr.push(cleanFile)
// t.duration()
})
t2.duration()

console.log('* * * * * * * * * * * * * * * * * * * * * * * * * * * * *')
console.log('filesArr[0]', filesArr[0])
var merged = fileUtils.getFilesMerged(filesArr)
Expand Down
2 changes: 2 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import Plugins from './helpers/abe-plugins'
import Locales from './helpers/abe-locales'

import getSelectTemplateKeys from './helpers/abe-get-select-template-keys'
import TimeMesure from './helpers/abe-time-mesure'

export {
fileAttr
Expand Down Expand Up @@ -112,6 +113,7 @@ export {
,Manager
,Page
,getSelectTemplateKeys
,TimeMesure
}

export {compileAbe as compileAbe}
1 change: 1 addition & 0 deletions src/cli/models/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FileParser,
fileUtils,
folderUtils,
TimeMesure,
getSelectTemplateKeys
} from '../../cli'

Expand Down

0 comments on commit d5b5ab2

Please sign in to comment.