Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AdFabConnect/abejs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 28, 2016
2 parents 563ef71 + 7b5fbfc commit d41ae86
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 254 deletions.
14 changes: 7 additions & 7 deletions src/cli/cms/editor/handlebars/listPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function listPage(file, index, text) {
res += '<tr>'
res += `<td>${math(index, '+', 1)}</td>
<td>
<a href="/abe/${file.abe_meta.template}?filePath=${file.abe_meta.link}" class="file-path">
<a href="/abe${file.abe_meta.link}" class="file-path">
${file.abe_meta.link}
</a>
</td>`
Expand Down Expand Up @@ -42,19 +42,19 @@ export default function listPage(file, index, text) {
if(file.draft != null) {
if((file.publish == null)
|| (file.publish && file.publish.date < file.draft.date)) {
workflow += `<a href="/abe/${file.abe_meta.template}?filePath=${file.draft.html}" class="label label-default label-draft" title="${file.draft.cleanDate}">draft</a>`
workflow += `<a href="/abe${file.draft.html}" class="label label-default label-draft" title="${file.draft.cleanDate}">draft</a>`
}else {
workflow += `<a href="/abe/${file.abe_meta.template}?filePath=${file.draft.html}" class="hidden label label-default label-draft" title="${file.draft.cleanDate}">draft</a>`
workflow += `<a href="/abe${file.draft.html}" class="hidden label label-default label-draft" title="${file.draft.cleanDate}">draft</a>`
}
}else {
workflow += `<a href="/abe/${file.abe_meta.template}?filePath=${file.abe_meta.link}" class="hidden label label-default label-draft" title="${file.cleanDate}">draft</a>`
workflow += `<a href="/abe${file.abe_meta.link}" class="hidden label label-default label-draft" title="${file.cleanDate}">draft</a>`
}

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

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

Expand All @@ -65,15 +65,15 @@ export default function listPage(file, index, text) {
<div class="row icons-action">`

if(file.publish != null) {
res += `<a href="/abe/unpublish/?filePath=${file.abe_meta.link}"
res += `<a href="/abe/unpublish${file.abe_meta.link}"
title="${text.unpublish}"
class="icon" data-unpublish="true" data-text="${text.confirmUnpublish} ${file.abe_meta.link}"
title="unpublish">
<span class="glyphicon glyphicon-eye-close"></span>
</a>`
}

res += `<a href="/abe/delete/?filePath=${file.abe_meta.link}"
res += `<a href="/abe/delete${file.abe_meta.link}"
title="${text.delete}"
class="icon"
data-delete="true"
Expand Down
31 changes: 31 additions & 0 deletions src/cli/cms/operations/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@ import {
Manager
} from '../../'

export function draft(filePath, tplPath, json, workflow = 'draft', type = 'draft') {
var p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforeDraft', json, filePath, tplPath)
cmsOperations.save.save(
path.join(config.root, config.draft.url, filePath.replace(config.root)),
tplPath,
json,
'',
workflow,
null,
type)
.then((resSave) => {
var result
if(typeof resSave.error !== 'undefined' && resSave.error !== null ){
result = {error: resSave.error}
}else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){
result = resSave
}else if(typeof resSave.json !== 'undefined' && resSave.json !== null){
Manager.instance.updateList()
result = {
success: 1,
json: resSave.json
}
}
resolve(result)
})
})

return p
}

export function publish(filePath, tplPath, json) {
var p = new Promise((resolve, reject) => {
abeExtend.hooks.instance.trigger('beforePublish', json, filePath, tplPath)
Expand Down
18 changes: 9 additions & 9 deletions src/cli/cms/operations/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function checkRequired(text, json) {
return Math.round((requiredValue > 0) ? complete * 100 / requiredValue : 100)
}

export function save(url, tplPath, json = null, text = '', type = '', previousSave = null, realType = 'draft', publishAll = false) {
export function save(url, tplPath = null, json = null, text = '', type = '', previousSave = null, realType = 'draft', publishAll = false) {
url = coreUtils.slug.clean(url)

var p = new Promise((resolve) => {
Expand All @@ -69,17 +69,18 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa
pathIso.htmlPath = path.join(config.root, previousSave.htmlPath.replace(config.root, '')).replace(/-abe-d/, `-abe-${realType[0]}`)
}

if (tplPath.indexOf('.') > -1) {
if(typeof json === 'undefined' || json === null) {
json = cmsData.file.get(tplUrl.json.path)
}

if (tplPath == null) {
tplPath = json.abe_meta.template
}else if (tplPath.indexOf('.') > -1) {
tplPath = tplPath.replace(/\..+$/, '')
}
var tpl = tplPath.replace(config.root, '')

var fullTpl = path.join(config.root, config.templates.url, tpl) + '.' + config.files.templates.extension

if(typeof json === 'undefined' || json === null) {
json = cmsData.file.get(tplUrl.json.path)
}

var ext = {
template: tpl.replace(/^\/+/, ''),
link: tplUrl.publish.link,
Expand Down Expand Up @@ -110,7 +111,6 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa

cmsData.source.getDataList(path.dirname(tplUrl.publish.link), text, json)
.then(() => {

json = abeExtend.hooks.instance.trigger('afterGetDataListOnSave', json)
for(var prop in json){
if(typeof json[prop] === 'object' && Array.isArray(json[prop]) && json[prop].length === 1){
Expand Down Expand Up @@ -151,7 +151,7 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa
if (isRejectedDoc) {
res.reject = cmsData.fileAttr.delete(url).replace(path.join(config.root, config.draft.url), '')
}

abeExtend.hooks.instance.trigger('afterSave', obj)

cmsTemplates.assets.copy()
Expand Down
6 changes: 3 additions & 3 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ cmsTemplates.assets.copy()
let publish = path.join(config.root, config.publish.url)
app.use(express.static(publish))

// This static path is mandatory for relative path to statics in templates
app.use('/abe', express.static(publish))

if(config.partials !== '') {
if (coreUtils.file.exist(path.join(config.root, config.partials))) {
app.use(express.static(path.join(config.root, config.partials)))
Expand Down Expand Up @@ -204,3 +201,6 @@ if (coreUtils.file.exist(path.join(config.root, 'cert.pem'))) {
// important : require here so config.root is defined
var controllers = require('./controllers')
app.use(controllers.default)

// This static path is mandatory for relative path to statics in templates
app.use('/abe', express.static(publish))
26 changes: 13 additions & 13 deletions src/server/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function editor(fileName, jsonPath, documentLink) {
if(coreUtils.file.exist(jsonPath)) {
json = cmsData.file.get(jsonPath, 'utf8')
}

text = cmsTemplates.template.getTemplate(fileName)

cmsData.source.getDataList(path.dirname(documentLink), text, json)
Expand All @@ -241,18 +241,18 @@ export function editor(fileName, jsonPath, documentLink) {
arrayBlock = []
each(text, json, util, arrayBlock)

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
var tpl = json.abe_meta.template.split('/')
tpl = tpl.pop()
json.abe_meta.cleanTemplate = tpl.replace(/\..+$/, '')
}

if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
var links = json.abe_meta.link.split('/')
var link = links.pop()
json.abe_meta.cleanName = link.replace(/\..+$/, '')
json.abe_meta.cleanFilename = links.join('/').replace(/\..+$/, '')
}
// if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
// var tpl = json.abe_meta.template.split('/')
// tpl = tpl.pop()
// json.abe_meta.cleanTemplate = tpl.replace(/\..+$/, '')
// }

// if(typeof json.abe_meta !== 'undefined' && json.abe_meta !== null) {
// var links = json.abe_meta.link.split('/')
// var link = links.pop()
// json.abe_meta.cleanName = link.replace(/\..+$/, '')
// json.abe_meta.cleanFilename = links.join('/').replace(/\..+$/, '')
// }

// HOOKS beforeEditorFormBlocks
json = abeExtend.hooks.instance.trigger('beforeEditorFormBlocks', json)
Expand Down
15 changes: 6 additions & 9 deletions src/server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
getCreate
,getDuplicate
,getUpdate
,getLogs
,getListUrl
,getListHooks
,getDeleteLogs
,getMain
,getPage
,postPage
Expand All @@ -31,21 +29,19 @@ var router = express.Router()
abeExtend.hooks.instance.trigger('afterHandlebarsHelpers', Handlebars)
abeExtend.hooks.instance.trigger('beforeAddRoute', router)

router.get('/abe/logs*', getLogs)
router.get('/abe/delete-logs*', getDeleteLogs)
router.get('/abe/create*', getCreate)
router.get('/abe/duplicate*', getDuplicate)
router.get('/abe/update*', getUpdate)
router.post('/abe/sql-request*', postSqlRequest)
router.post('/abe/page/*', postPage)
router.get('/abe/page/*', getPage)
router.post('/abe/publish', postPublish)
router.post('/abe/publish*', postPublish)
router.get('/abe/republish', getRepublish)
router.post('/abe/reject', postReject)
router.post('/abe/draft', postDraft)
router.post('/abe/reject*', postReject)
router.post('/abe/draft*', postDraft)
router.get('/abe/save-config', getSaveConfig)
router.get('/abe/unpublish', getUnpublish)
router.get('/abe/delete', getDelete)
router.get('/abe/unpublish*', getUnpublish)
router.get('/abe/delete*', getDelete)
router.post('/abe/upload/*', postUpload)
router.get('/abe/list-url*', function (req, res, next) {
getListUrl(router, req, res, next)
Expand Down Expand Up @@ -90,6 +86,7 @@ Array.prototype.forEach.call(routes, (route) => {
}
})
router.get('/abe*', getMain)
// router.get('/abe*', getMain)

abeExtend.hooks.instance.trigger('afterAddRoute', router)

Expand Down
6 changes: 4 additions & 2 deletions src/server/helpers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ var page = function (req, res, next) {
}
}

if(typeof req.query.filePath !== 'undefined' && req.query.filePath !== null) {
var filepath = req.originalUrl.replace('/abe/page', '')

if(typeof filepath !== 'undefined' && filepath !== null) {
var jsonPath = null
var linkPath = null

var filePathTest = cmsData.revision.getDocumentRevision(req.query.filePath)
var filePathTest = cmsData.revision.getDocumentRevision(filepath)
if(typeof filePathTest !== 'undefined' && filePathTest !== null) {
jsonPath = filePathTest.path
linkPath = filePathTest.abe_meta.link
Expand Down
1 change: 0 additions & 1 deletion src/server/public/scripts/modules/EditorAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ export default class EditorAutocomplete {
sourceString: target.getAttribute('data-autocomplete-refresh-sourcestring'),
prefillQuantity: target.getAttribute('data-autocomplete-refresh-prefill-quantity'),
key: target.getAttribute('data-autocomplete-refresh-key'),
folder: CONFIG.FOLDERPATH,
json: jsonPost
})

Expand Down
7 changes: 4 additions & 3 deletions src/server/public/scripts/modules/EditorJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ export default class Json {
delete json.abe_source
}

tplPath = (tplPath != null) ? tplPath : CONFIG.TPLPATH
filePath = (filePath != null) ? filePath : CONFIG.FILEPATH

var toSave = qs.stringify({
tplPath: (tplPath) ? tplPath : CONFIG.TPLPATH,
filePath: (filePath) ? filePath : CONFIG.FILEPATH,
json: jsonSave
})

this.headersSaving._fire({url: document.location.origin + '/' + type})

this._ajax(
{
url: document.location.origin + '/abe/' + type,
url: document.location.origin + '/abe/' + type + filePath,
body: toSave,
headers: this._headers,
method: 'post'
Expand Down
5 changes: 4 additions & 1 deletion src/server/public/scripts/modules/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export default class EditorManager {
Array.prototype.forEach.call(this._btnVisitSite, (btnVisitSite) => {
btnVisitSite.addEventListener('click', this._handleBtnVisitClick)
})
this._btnManager.addEventListener('click', this._handleBtnManagerClick)

if (this._btnManager != null) {
this._btnManager.addEventListener('click', this._handleBtnManagerClick)
}

if(typeof this._btnRepublish !== 'undefined' && this._btnRepublish !== null) {
this._btnRepublish.addEventListener('click', this._handleBtnRepublishClick)
Expand Down
4 changes: 2 additions & 2 deletions src/server/public/scripts/modules/EditorReload.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export default class Reload {
str = template(json)
doc.open()
doc.write(str)
doc.close()
doc.close()

setTimeout(function () {
var iframeDoc = IframeDocument('#page-template')
if(typeof iframeDoc !== 'undefined' && iframeDoc !== null
Expand Down
23 changes: 0 additions & 23 deletions src/server/public/scripts/modules/EditorSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,7 @@ export default class EditorSave {
.then((result) => {
target.classList.add('done')
// this._populateFromJson(this._json.data)
if(result.success === 1) {
CONFIG.TPLNAME = result.json.abe_meta.latest.abeUrl
if(CONFIG.TPLNAME[0] === '/') CONFIG.TPLNAME = CONFIG.TPLNAME.slice(1)
}

var tplNameParam = '?tplName='
var filePathParam = '&filePath='

var getParams = window.location.search.slice(1).split('&')
getParams.forEach(function (getParam) {
var param = getParam.split('=')
if(param[0] === 'filePath'){
if(param[1].indexOf('-abe-') > -1){
filePathParam += CONFIG.TPLNAME
}
else{
filePathParam += param[1]
}
}
})
var ext = filePathParam.split('.')
ext = ext[ext.length - 1]
filePathParam = filePathParam.replace(new RegExp('-abe-(.+?)(?=\.' + ext + ')'), '')

target.classList.remove('loading')
target.classList.remove('done')
target.removeAttribute('disabled')
Expand Down
3 changes: 2 additions & 1 deletion src/server/public/scripts/modules/FormCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class FormCreate {
values[input.getAttribute('name')] = input.value
})
var toSave = qs.stringify(values)

this._ajax(
{
url: document.location.origin + '/abe/' + type + '/?' + toSave,
Expand All @@ -144,7 +145,7 @@ export default class FormCreate {
(code, responseText) => {
var jsonRes = JSON.parse(responseText)
if (jsonRes.success == 1 && typeof jsonRes.json.abe_meta !== 'undefined' && jsonRes.json.abe_meta !== null) {
window.location.href = window.location.origin + '/abe/' + jsonRes.json.abe_meta.template + '?filePath=' + jsonRes.json.abe_meta.link
window.location.href = window.location.origin + '/abe' + jsonRes.json.abe_meta.link
}else {
alert('error')
btn.classList.remove('disable')
Expand Down
33 changes: 0 additions & 33 deletions src/server/routes/get-delete-logs.js

This file was deleted.

Loading

0 comments on commit d41ae86

Please sign in to comment.