From 5eb1632166e00d1df92abf383c6786ac83cd7069 Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Fri, 2 Dec 2016 10:10:18 +0100 Subject: [PATCH 1/4] refactoring: make thumblist stateful inside manager fixes #43 --- src/cli/cms/media/image.js | 5 +---- src/cli/core/manager/Manager.js | 8 +++++++- src/server/routes/get-thumbs.js | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cli/cms/media/image.js b/src/cli/cms/media/image.js index a5b56f60..fc4af235 100644 --- a/src/cli/cms/media/image.js +++ b/src/cli/cms/media/image.js @@ -167,11 +167,8 @@ export function createMediaFolder(req) { return folderFilePath } -var thumbsList - export function getThumbsList() { - if(thumbsList != null) return thumbsList - thumbsList = [] + var thumbsList = [] var pathToThumbs = path.join(config.root, config.publish.url, config.upload.image) var files = coreUtils.file.getFilesSync(pathToThumbs, true) Array.prototype.forEach.call(files, (pathFile) => { diff --git a/src/cli/core/manager/Manager.js b/src/cli/core/manager/Manager.js index 8f5a78be..6d2d1838 100644 --- a/src/cli/core/manager/Manager.js +++ b/src/cli/core/manager/Manager.js @@ -9,7 +9,8 @@ import { cmsData, config, cmsTemplates, - cmsReference + cmsReference, + cmsMedia } from '../../' let singleton = Symbol() @@ -197,6 +198,11 @@ class Manager { this._structureAndTemplates = cmsTemplates.template.getStructureAndTemplates() } + getThumbsList() { + if(typeof this._thumbs === 'undefined' || this._thumbs === null) this._thumbs = cmsMedia.image.getThumbsList() + return this._thumbs + } + getReferences() { if(typeof this._references === 'undefined' || this._references === null) this.updateReferences() return this._references diff --git a/src/server/routes/get-thumbs.js b/src/server/routes/get-thumbs.js index e2f77763..d67cdc1e 100644 --- a/src/server/routes/get-thumbs.js +++ b/src/server/routes/get-thumbs.js @@ -1,10 +1,10 @@ import { - cmsMedia + Manager } from '../../cli' var route = function(req, res){ res.set('Content-Type', 'application/json') - res.send(JSON.stringify({thumbs: cmsMedia.image.getThumbsList()})) + res.send(JSON.stringify({thumbs: Manager.instance.getReferences()})) } export default route From 1f01ad2d582849001af9b76b3916bd602579e23d Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Fri, 2 Dec 2016 15:46:19 +0100 Subject: [PATCH 2/4] refactoring: printInput helper + UT --- src/cli/cms/editor/handlebars/printBlock.js | 2 +- src/cli/cms/editor/handlebars/printInput.js | 402 +++++++++----------- src/cli/cms/editor/index.js | 26 +- src/tasks/nodemon.js | 2 +- test/cms/editor/handlebars/folders.js | 20 + test/cms/editor/handlebars/printInput.js | 169 ++++++++ test/editor.js | 62 --- test/fixtures/editor/index.json | 327 +++++++++++++++- test/image.js | 1 - 9 files changed, 720 insertions(+), 291 deletions(-) create mode 100644 test/cms/editor/handlebars/folders.js create mode 100644 test/cms/editor/handlebars/printInput.js delete mode 100644 test/editor.js diff --git a/src/cli/cms/editor/handlebars/printBlock.js b/src/cli/cms/editor/handlebars/printBlock.js index ebf6fae7..1972cb98 100755 --- a/src/cli/cms/editor/handlebars/printBlock.js +++ b/src/cli/cms/editor/handlebars/printBlock.js @@ -1,4 +1,4 @@ -import printInput from './printInput' +import {printInput} from './printInput' import abeEngine from './abeEngine' import { diff --git a/src/cli/cms/editor/handlebars/printInput.js b/src/cli/cms/editor/handlebars/printInput.js index 3822420c..679d7ad3 100755 --- a/src/cli/cms/editor/handlebars/printInput.js +++ b/src/cli/cms/editor/handlebars/printInput.js @@ -5,244 +5,208 @@ import { ,User } from '../../../' -/** - * Print form input based on input data type {Textarea | text | meta | link | image | ...} - * && add appropriate attributs / data-attributs - * @return {String|html} input / input group ... - */ -export default function printInput (params, root) { - // var params = arguments[0] - params = abeExtend.hooks.instance.trigger('beforeEditorInput', params) +export function getAttributes(params) { + var attributes = '' + if(params.key != null) attributes += `id="${params.key}" data-id="${params.key}"` + if(params.value != null) attributes += ` value="${params.value}"` + if(params['max-length'] != null) attributes += ` maxlength="${params['max-length']}" data-maxlength="${params['max-length']}"` + if(params.reload != null) attributes += ` reload="${params.reload}"` + if(params.order != null) attributes += ` tabIndex="${params.order}"` + if(params.required != null) attributes += ` data-required="${params.required}"` + if(params.display != null) attributes += ` data-display="${params.display}"` + if(params.visible != null) attributes += ` data-visible="${params.visible}"` + if(params.autocomplete != null) attributes += ` data-autocomplete="${params.autocomplete}"` + if(params.placeholder != null) attributes += ` placeholder="${params.placeholder}"` + if(params.thumbs != null) attributes += ` data-size="${params.thumbs}"` + if(params.multiple != null) attributes += ` ${params.multiple}` + if(params.disabled != null) attributes += ` ${params.disabled}` + return attributes +} +export function getLabel(params) { var desc = params.desc + ((params.required) ? ' *' : '') + return `` +} - var res = `
- ` - var disabled = '' - - if(!params.placeholder) { - params.placeholder = '' - } - - if(params.value == null) { - params.value = '' - } - - if(typeof params.value === 'string') params.value = params.value.replace(/\"/g, '"') - - var userWorkflow = '' - if (root.user != null) { - userWorkflow = root.user.role.workflow - } - - var disabled = '' - if (!User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/${params.status}/edit`)) { - disabled = 'disabled="disabled"' - } - if (params.tab == 'slug') { - disabled = '' - } - var inputClass = 'form-control form-abe' - var commonParams = `id="${params.key}" - data-id="${params.key}" - value="${params.value}" - maxlength="${params['max-length']}" - reload="${params.reload}" - tabIndex="${params.order}" - data-required="${params.required}" - data-display="${params.display}" - data-visible="${params.visible}" - data-autocomplete="${params.autocomplete}" - placeholder="${params.placeholder}" - ${disabled}` - - if(params.source != null) { - commonParams = `id="${params.key}" - data-id="${params.key}" - data-maxlength="${params['max-length']}" - reload="${params.reload}" - tabIndex="${params.order}" - data-required="${params.required}" - data-display="${params.display}" - data-visible="${params.visible}" - data-autocomplete="${params.autocomplete}" - placeholder="${params.placeholder}" - ${disabled}` - - var multiple = '' - disabled = '' - if(params['max-length'] == null && params.source.length > 0 || (params['max-length'] > 1 && params.source.length > 0)) { - multiple = 'multiple' - } - if(params.source.length <= 0) { - disabled = 'disabled' +export function createInputSource(attributes, inputClass, params) { + var inputSource = '' + var lastValues + if(params.autocomplete != null && params.autocomplete === 'true') { + if(params.source.indexOf('http') === 0) lastValues = params.source + else lastValues = JSON.stringify(params.source).replace(/\'/g, '"e;') + inputSource += '
' + if(params.autocomplete != null && params.autocomplete === 'true' && params.prefill === 'true') { + inputSource += `
+ +
` } + Array.prototype.forEach.call(params.value, (val) => { + inputSource += sourceAutocomplete(val, params) + }) + inputSource += `
` + } + else { + lastValues = JSON.stringify(params.value).replace(/\'/g, '"e;') + inputSource += `` - }else { - - lastValues = JSON.stringify(params.value).replace(/\'/g, '"e;') - res += `' + } + return inputSource +} - if (!params.required) { - res += '' - } - - if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') { - Array.prototype.forEach.call(params.source, (val) => { - res += sourceOption(val, params) - }) +export function createInputRich(attributes, inputClass, params) { + return `` +} - }else { - res += sourceOption(params.source, params) - } +export function createInputFile(attributes, inputClass, params) { + return ` + + ` +} - res += '' +export function createInputTextarea(attributes, inputClass, params) { + return `` +} - } - }else if (params.type.indexOf('rich') >= 0){ - commonParams = `id="${params.key}" - data-id="${params.key}" - maxlength="${params['max-length']}" - reload="${params.reload}" - tabIndex="${params.order}" - data-required="${params.required}" - data-display="${params.display}" - data-visible="${params.visible}" - data-autocomplete="${params.autocomplete}" - placeholder="${params.placeholder}" - ${disabled}` - - res += `` - } - else if (params.type.indexOf('file') >= 0){ - res += ` - - ` - } - else if (params.type.indexOf('textarea') >= 0){ - res += `` - } - else if (params.type.indexOf('link') >= 0){ - res += `
+export function createInputLink(attributes, inputClass, params) { + return `
- +
` - } - else if (params.type.indexOf('image') >= 0){ - if(params.thumbs != null) commonParams += `data-size="${params.thumbs}"` - res += `
-
- -
- -
- - - - -
+} + +export function createInputImage(attributes, inputClass, params) { + return `
+
+ +
+ +
+ + + + +
+
+
` +} + +export function createInputText(attributes, inputClass, params) { + return `
+
+
-
` + +
` +} + +/** + * Print form input based on input data type {Textarea | text | meta | link | image | ...} + * && add appropriate attributs / data-attributs + * @return {String|html} input / input group ... + */ +export function printInput (params, root) { + params = abeExtend.hooks.instance.trigger('beforeEditorInput', params) + var userWorkflow = (root.user != null) ? root.user.role.workflow : '' + var res = `
` + var inputClass = 'form-control form-abe' + res += getLabel(params) + + params.placeholder = params.placeholder || '' + params.value = params.value || '' + + if(typeof params.value === 'string') params.value = params.value.replace(/\"/g, '"') + + params.disabled = '' + if (params.tab !== 'slug' && !User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/${params.status}/edit`)) { + params.disabled = 'disabled="disabled"' } - else { - res += `
-
- -
- -
` + var attributes = getAttributes(params) + + if(params.source != null) { + params.multiple = ((params['max-length'] == null || params['max-length'] > 1) && params.source.length > 0) ? 'multiple' : '' + params.disabled = (params.source.length <= 0) ? 'disabled' : '' + res += createInputSource(getAttributes(params), inputClass, params) } + else if (params.type.indexOf('rich') >= 0) res += createInputRich(attributes, inputClass, params) + else if (params.type.indexOf('file') >= 0) res += createInputFile(attributes, inputClass, params) + else if (params.type.indexOf('textarea') >= 0) res += createInputTextarea(attributes, inputClass, params) + else if (params.type.indexOf('link') >= 0) res += createInputLink(attributes, inputClass, params) + else if (params.type.indexOf('image') >= 0) res += createInputImage(attributes, inputClass, params) + else res += createInputText(attributes, inputClass, params) res += '
' - res = abeExtend.hooks.instance.trigger('afterEditorInput', res, params) return res diff --git a/src/cli/cms/editor/index.js b/src/cli/cms/editor/index.js index cba545d6..3c32d49a 100755 --- a/src/cli/cms/editor/index.js +++ b/src/cli/cms/editor/index.js @@ -10,13 +10,24 @@ import folders from './handlebars/folders' import listPage from './handlebars/listPage' import printBlock from './handlebars/printBlock' import printConfig from './handlebars/printConfig' -import printInput from './handlebars/printInput' import recursiveFolder from './handlebars/recursiveFolder' import recursivePrintConfig from './handlebars/recursivePrintConfig' import sourceAttr from './handlebars/sourceAttr' import sourceAutocomplete from './handlebars/sourceAutocomplete' import sourceOption from './handlebars/sourceOption' import raw from './handlebars/raw' +import { + printInput, + getAttributes, + getLabel, + createInputSource, + createInputRich, + createInputFile, + createInputTextarea, + createInputLink, + createInputImage, + createInputText +} from './handlebars/printInput' Handlebars.registerHelper('abeImport', abeImport) Handlebars.registerHelper('abe', compileAbe) @@ -38,12 +49,21 @@ export { listPage, printBlock, printConfig, - printInput, recursiveFolder, recursivePrintConfig, sourceAttr, sourceAutocomplete, sourceOption, - raw + raw, + printInput, + getAttributes, + getLabel, + createInputSource, + createInputRich, + createInputFile, + createInputTextarea, + createInputLink, + createInputImage, + createInputText } diff --git a/src/tasks/nodemon.js b/src/tasks/nodemon.js index 0b336cc6..788ff451 100755 --- a/src/tasks/nodemon.js +++ b/src/tasks/nodemon.js @@ -19,7 +19,7 @@ nodemon({ 'NODE_ENV': 'development' }, ignore: [ - 'docs/*' + // 'docs/*' ], watch: [ 'src/cli/*', diff --git a/test/cms/editor/handlebars/folders.js b/test/cms/editor/handlebars/folders.js new file mode 100644 index 00000000..0c3d6bfe --- /dev/null +++ b/test/cms/editor/handlebars/folders.js @@ -0,0 +1,20 @@ +import chai from 'chai' +import path from 'path' +import { + cmsEditor, + config +} from '../../../../src/cli' +config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) + +describe('cmsEditor.folders', function() { + + /** + * cmsEditor.folders + */ + it('cmsEditor.folders()', function() { + var result = cmsEditor.folders([{path: ''}], 1, null, {'level-1': 'my wording'}) + var wordingExist = result.indexOf('my wording') + chai.expect(result).to.be.a('string') + chai.expect(wordingExist).to.equal(110) + }); +}); diff --git a/test/cms/editor/handlebars/printInput.js b/test/cms/editor/handlebars/printInput.js new file mode 100644 index 00000000..97aa1401 --- /dev/null +++ b/test/cms/editor/handlebars/printInput.js @@ -0,0 +1,169 @@ +import chai from 'chai' +import path from 'path' +import sinonChai from'sinon-chai' +chai.use(sinonChai) +import sinon from 'sinon' + +import { + cmsEditor, + abeExtend, + config +} from '../../../../src/cli' +config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) + +import data from '../../../fixtures/editor/index' + +var classAttr = 'form-control form-abe' + +describe('printInput', function() { + + // getAttributes, + // getLabel, + // createInputSource, + // createInputRich, + // createInputFile, + // createInputTextarea, + // createInputLink, + // createInputImage, + // createInputText + + /** + * cmsEditor.getLabel + * + */ + it('cmsEditor.getLabel()', function() { + var result = cmsEditor.getLabel(data.label) + chai.expect(result).to.be.a('string') + var label = //.test(result) + chai.expect(label).to.be.true + }) + + /** + * cmsEditor.getAttributes + * + */ + it('cmsEditor.getAttributes()', function() { + var result = cmsEditor.getAttributes(data.attributes) + chai.expect(result).to.be.a('string') + chai.expect(result).to.be.equal('id="key" data-id="key" value="value" maxlength="max-length" data-maxlength="max-length" reload="reload" tabIndex="order" data-required="required" data-display="display" data-visible="visible" data-autocomplete="autocomplete" placeholder="placeholder" data-size="thumbs" multiple disabled') + }) + + /** + * cmsEditor.createInputSource + * + */ + it('cmsEditor.createInputSource()', function() { + var result0 = cmsEditor.createInputSource(data.source[0].attributes, classAttr, data.source[0].params) + var select = //.test(result0) + chai.expect(result0).to.be.a('string') + chai.expect(select).to.be.true + + var result1 = cmsEditor.createInputSource(data.source[1].attributes, classAttr, data.source[1].params) + var test1 = result1.indexOf('multiple') + chai.expect(test1).to.be.above(-1) + + var result2 = cmsEditor.createInputSource(data.source[2].attributes, classAttr, data.source[2].params) + var test2 = result2.indexOf('data-autocomplete') + chai.expect(test2).to.be.above(-1) + + var result3 = cmsEditor.createInputSource(data.source[3].attributes, classAttr, data.source[3].params) + var test3 = result3.indexOf('{"id":1,"name":"test 1","lang":"de"}') + chai.expect(test3).to.be.above(-1) + }) + + /** + * cmsEditor.createInputRich + * + */ + it('cmsEditor.createInputRich()', function() { + var result = cmsEditor.createInputRich(data.rich.attributes, classAttr, data.rich.params) + chai.expect(result).to.be.a('string') + }) + + /** + * cmsEditor.createInputFile + * + */ + it('cmsEditor.createInputFile()', function() { + var result = cmsEditor.createInputFile(data.file.attributes, classAttr, data.file.params) + var input = //.test(result) + chai.expect(result).to.be.a('string') + chai.expect(input).to.be.true + }) + + /** + * cmsEditor.createInputTextarea + * + */ + it('cmsEditor.createInputTextarea()', function() { + var result = cmsEditor.createInputTextarea(data.textarea.attributes, classAttr, data.textarea.params) + var textarea = //.test(result) + chai.expect(result).to.be.a('string') + chai.expect(textarea).to.be.true + }) + + /** + * cmsEditor.createInputLink + * + */ + it('cmsEditor.createInputLink()', function() { + var result = cmsEditor.createInputLink(data.link.attributes, classAttr, data.link.params) + var link = result.indexOf('glyphicon glyphicon-link') + chai.expect(result).to.be.a('string') + chai.expect(link).to.be.above(-1) + }) + + /** + * cmsEditor.createInputImage + * + */ + it('cmsEditor.createInputImage()', function() { + var result = cmsEditor.createInputImage(data.image.attributes, classAttr, data.image.params) + var image = result.indexOf('glyphicon glyphicon-picture') + chai.expect(result).to.be.a('string') + chai.expect(image).to.be.above(-1) + }) + + /** + * cmsEditor.createInputText + * + */ + it('cmsEditor.createInputText()', function() { + var result = cmsEditor.createInputText(data.txt.attributes, classAttr, data.txt.params) + var txt = result.indexOf('glyphicon glyphicon-font') + chai.expect(result).to.be.a('string') + chai.expect(txt).to.be.above(-1) + }) + + /** + * cmsEditor.printInput + * + */ + it('cmsEditor.printInput()', function() { + var val = data.text; + this.sinon = sinon.sandbox.create(); + this.sinon.stub(abeExtend.hooks.instance, 'trigger', function(param, html){ + return (param === 'beforeEditorInput') ? val : html; + }) + var result = cmsEditor.printInput(val, {}) + chai.expect(result).to.be.a('string') + var value = result.match(/value="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(value).to.equal('value="val2"') + var reload = result.match(/reload="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(reload).to.equal('reload="val3"') + var tabIndex = result.match(/tabIndex="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(tabIndex).to.equal('tabIndex="val4"') + var dataRequired = result.match(/data-required="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(dataRequired).to.equal('data-required="val5"') + var dataDisplay = result.match(/data-display="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(dataDisplay).to.equal('data-display="val6"') + var dataVisible = result.match(/data-visible="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(dataVisible).to.equal('data-visible="val7"') + var dataAutocomplete = result.match(/data-autocomplete="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(dataAutocomplete).to.equal('data-autocomplete="val8"') + var placeholder = result.match(/placeholder="[a-zA-Z0-9-]*"/ig)[0] + chai.expect(placeholder).to.equal('placeholder="val9"') + + this.sinon.restore() + }); +}); diff --git a/test/editor.js b/test/editor.js deleted file mode 100644 index 65cc39ba..00000000 --- a/test/editor.js +++ /dev/null @@ -1,62 +0,0 @@ -import chai from 'chai' -import path from 'path' -import sinonChai from'sinon-chai' -chai.use(sinonChai) -import sinon from 'sinon' -import {config} from '../src/cli' -config.set({root: path.join(__dirname,'fixtures')}) - -import { - cmsEditor, - abeExtend -} from '../src/cli' - -import data from './fixtures/editor/index' - -describe('Editor', function() { - - /** - * cmsEditor.printInput - * - */ - it('cmsEditor.printInput()', function() { - var val = data.text; - this.sinon = sinon.sandbox.create(); - this.sinon.stub(abeExtend.hooks.instance, 'trigger', function(param, html){ - return (param === 'beforeEditorInput') ? val : html; - }) - - var result = cmsEditor.printInput(val, {}) - chai.expect(result).to.be.a('string') - var value = result.match(/value="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(value).to.equal('value="val2"') - var reload = result.match(/reload="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(reload).to.equal('reload="val3"') - var tabIndex = result.match(/tabIndex="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(tabIndex).to.equal('tabIndex="val4"') - var dataRequired = result.match(/data-required="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(dataRequired).to.equal('data-required="val5"') - var dataDisplay = result.match(/data-display="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(dataDisplay).to.equal('data-display="val6"') - var dataVisible = result.match(/data-visible="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(dataVisible).to.equal('data-visible="val7"') - var dataAutocomplete = result.match(/data-autocomplete="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(dataAutocomplete).to.equal('data-autocomplete="val8"') - var placeholder = result.match(/placeholder="[a-zA-Z0-9-]*"/ig)[0] - chai.expect(placeholder).to.equal('placeholder="val9"') - - this.sinon.restore() - }); - - /** - * cmsEditor.folders - * - */ - it('cmsEditor.folders()', function() { - var result = cmsEditor.folders([{path: ''}], 1, null, {'level-1': 'my wording'}) - var wordingExist = result.indexOf('my wording') - chai.expect(result).to.be.a('string') - chai.expect(wordingExist).to.equal(110) - }); - -}); diff --git a/test/fixtures/editor/index.json b/test/fixtures/editor/index.json index 0af2682b..77c95685 100644 --- a/test/fixtures/editor/index.json +++ b/test/fixtures/editor/index.json @@ -11,7 +11,326 @@ "autocomplete": "val8", "placeholder": "val9" }, - "image": {}, - "file": {}, - "rich": {} -} \ No newline at end of file + "label": { + "desc": "desc label", + "required": true, + "key": "keylabel" + }, + "attributes": { + "key": "key", + "value": "value", + "max-length": "max-length", + "reload": "reload", + "order": "order", + "required": "required", + "display": "display", + "visible": "visible", + "autocomplete": "autocomplete", + "placeholder": "placeholder", + "thumbs": "thumbs", + "multiple": "multiple", + "disabled": "disabled" + }, + "source": { + "0": { + "params": { + "autocomplete": null, + "block": "", + "desc": "Color single", + "display": null, + "editable": true, + "key": "colors_single", + "max-length": "1", + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": "true", + "required": false, + "source": ["rouge", "vert", "bleu"], + "tab": "colors", + "type": "data", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": "[\"rouge\", \"vert\", \"bleu\"]", + "status": "draft", + "disabled": "", + "multiple": "" + }, + "attributes": "id=\"colors_single data-id=\"colors_single\" value=\"\" maxlength=\"1\" data-maxlength=\"1\" reload=\"true\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "1": { + "params": { + "autocomplete": null, + "block": "", + "desc": "Color select", + "display": null, + "editable": true, + "key": "colors_select", + "max-length": null, + "order": "1", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": "true", + "required": false, + "source": ["rouge", "vert", "bleu"], + "tab": "colors", + "type": "data", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": "[\"rouge\", \"vert\", \"bleu\"]", + "status": "draft", + "disabled": "", + "multiple": "multiple" + }, + "attributes": "id=\"colors_select data-id=\"colors_select\" value=\"\" reload=\"true\" tabIndex=\"1\" data-required=\"false\" data-visible=\"true\" placeholder=\"\" multiple" + }, + "2": { + "params": { + "autocomplete": "true", + "block": "", + "desc": "Color autocomplete (enter \"rouge\")", + "display": null, + "editable": true, + "key": "colors_autocomplete", + "max-length": null, + "order": "2", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": "true", + "required": false, + "source": ["rouge", "vert", "bleu"], + "tab": "colors", + "type": "data", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": "[\"rouge\", \"vert\", \"bleu\"]", + "status": "draft", + "disabled": "", + "multiple": "multiple" + }, + "attributes": "id=\"colors_autocomplete data-id=\"colors_autocomplete\" value=\"\" reload=\"true\" tabIndex=\"2\" data-required=\"false\" data-visible=\"true\" data-autocomplete=\"true\" placeholder=\"\" multiple" + }, + "3": { + "params": { + "autocomplete": null, + "block": "", + "desc": "Data ref single", + "display": "name", + "editable": true, + "key": "data_reference_single", + "max-length": "1", + "order": "3", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": "true", + "required": false, + "source": [ + {"id": 1,"name": "test 1","lang": "de"}, + {"id": 2,"name": "test 2","lang": "fr"}, + {"id": 3,"name": "test 3","lang": "es"} + ], + "tab": "references", + "type": "data", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": "reference/data.json", + "status": "draft", + "disabled": "", + "multiple": "" + }, + "attributes": "id=\"data_reference_single data-id=\"data_reference_single\" value=\"\" maxlength=\"1\" data-maxlength=\"1\" reload=\"true\" tabIndex=\"3\" data-required=\"false\" data-display=\"name\" data-visible=\"true\" placeholder=\"\"" + } + }, + "rich": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "rich_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "rich", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"rich_key\" data-id=\"rich_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "file": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "file_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "file", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "filetype": "file_type", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"file_key\" data-id=\"file_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "textarea": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "textarea_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "textarea", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"textarea_key\" data-id=\"textarea_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "link": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "link_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "link", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "title": "html title", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"link_key\" data-id=\"link_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "image": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "image_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "image", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"image_key\" data-id=\"image_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + }, + "txt": { + "params": { + "autocomplete": null, + "block": "", + "desc": "give some tips", + "display": null, + "editable": true, + "key": "text_key", + "max-length": null, + "order": "0", + "placeholder": "", + "prefill": false, + "prefill-quantity": null, + "reload": false, + "required": false, + "source": null, + "tab": "default", + "type": "text", + "value": "", + "visible": true, + "precontribTemplate": "", + "min-length": 0, + "file": "", + "sourceString": null, + "status": "publish", + "disabled": "" + }, + "attributes": "id=\"text_key\" data-id=\"text_key\" value=\"\" reload=\"false\" tabIndex=\"0\" data-required=\"false\" data-visible=\"true\" placeholder=\"\"" + } +} diff --git a/test/image.js b/test/image.js index fa98481a..c4b13ff5 100644 --- a/test/image.js +++ b/test/image.js @@ -130,7 +130,6 @@ describe('image', function() { var stub = sinon.stub(coreUtils.file, 'getFilesSync') stub.returns(imagesListInFolder) var result = cmsMedia.image.getAssociatedImageFileFromThumb(path.join(path.sep, 'unitimage', 'img_thumb.jpg')) - console.log(result) chai.expect(result).to.not.be.undefined chai.expect(result).to.have.property('originalFile').to.equal(path.join(path.sep, 'unitimage', 'img.jpg')) chai.expect(result).to.have.property('thumbFile').to.equal(path.join(path.sep, 'unitimage', 'img_thumb.jpg')) From d0e50c572415c3839aebb597f0bb182052a6470f Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Fri, 2 Dec 2016 16:44:08 +0100 Subject: [PATCH 3/4] uncomment docs --- src/tasks/nodemon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/nodemon.js b/src/tasks/nodemon.js index 788ff451..0b336cc6 100755 --- a/src/tasks/nodemon.js +++ b/src/tasks/nodemon.js @@ -19,7 +19,7 @@ nodemon({ 'NODE_ENV': 'development' }, ignore: [ - // 'docs/*' + 'docs/*' ], watch: [ 'src/cli/*', From 5412d5fb4cf6d81e1fb64d5930b7b87f21afd67e Mon Sep 17 00:00:00 2001 From: wonknu10 Date: Mon, 5 Dec 2016 16:03:48 +0100 Subject: [PATCH 4/4] remove log & fix thumb instead of references --- src/cli/cms/data/source.js | 2 +- src/cli/cms/media/image.js | 6 ------ src/cli/core/manager/Manager.js | 4 ++++ src/server/routes/get-thumbs.js | 2 +- src/server/routes/post-upload.js | 7 ++++++- src/tasks/nodemon.js | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cli/cms/data/source.js b/src/cli/cms/data/source.js index 995314b1..b3dd3f2f 100644 --- a/src/cli/cms/data/source.js +++ b/src/cli/cms/data/source.js @@ -94,7 +94,7 @@ export function urlList(obj, tplPath, match, jsonPage) { } var body = '' -console.log(options) + var localReq = httpUse.request(options, (localRes) => { localRes.setEncoding('utf8') localRes.on('data', (chunk) => { diff --git a/src/cli/cms/media/image.js b/src/cli/cms/media/image.js index fc4af235..a6475081 100644 --- a/src/cli/cms/media/image.js +++ b/src/cli/cms/media/image.js @@ -74,12 +74,6 @@ export function generateThumbnail(file) { var cropThumb = smartCropAndSaveFile([250, 250], file, thumbFileName) cropThumb.then(function (result) { var stderr = result.stderr - if(thumbsList != null) { - thumbsList.push({ - originalFile: file.replace(path.join(config.root, config.publish.url), ''), - thumbFile: thumbFileNameRelative - }) - } if(stderr) { cropAndSaveFile([250, 250], file, thumbFileName).then(function () { resolve({thumb: thumbFileNameRelative}) diff --git a/src/cli/core/manager/Manager.js b/src/cli/core/manager/Manager.js index 54358cc0..7694c42d 100644 --- a/src/cli/core/manager/Manager.js +++ b/src/cli/core/manager/Manager.js @@ -203,6 +203,10 @@ class Manager { return this._thumbs } + addThumbsToList(thumb) { + if(this._thumbs) this._thumbs.push(thumb) + } + getReferences() { if(typeof this._references === 'undefined' || this._references === null) this.updateReferences() return this._references diff --git a/src/server/routes/get-thumbs.js b/src/server/routes/get-thumbs.js index d67cdc1e..b5f1cdc0 100644 --- a/src/server/routes/get-thumbs.js +++ b/src/server/routes/get-thumbs.js @@ -4,7 +4,7 @@ import { var route = function(req, res){ res.set('Content-Type', 'application/json') - res.send(JSON.stringify({thumbs: Manager.instance.getReferences()})) + res.send(JSON.stringify({thumbs: Manager.instance.getThumbsList()})) } export default route diff --git a/src/server/routes/post-upload.js b/src/server/routes/post-upload.js index 78d2b398..66ea159b 100644 --- a/src/server/routes/post-upload.js +++ b/src/server/routes/post-upload.js @@ -1,6 +1,7 @@ import { abeExtend, - cmsMedia + cmsMedia, + Manager } from '../../cli' var route = function(req, res, next){ @@ -10,6 +11,10 @@ var route = function(req, res, next){ var image = cmsMedia.image.saveFile(req) image.then(function (resp) { + Manager.instance.addThumbsToList({ + originalFile: resp.filePath, + thumbFile: resp.thumbnail + }) res.set('Content-Type', 'application/json') res.send(JSON.stringify(resp)) }).catch(function(e) { diff --git a/src/tasks/nodemon.js b/src/tasks/nodemon.js index 788ff451..a692c402 100755 --- a/src/tasks/nodemon.js +++ b/src/tasks/nodemon.js @@ -19,7 +19,7 @@ nodemon({ 'NODE_ENV': 'development' }, ignore: [ - // 'docs/*' + // 'docs/*' //TODO: find out why in dev mode this line uncommented break server reload on file change ], watch: [ 'src/cli/*',