Skip to content

Commit

Permalink
change all abe url
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Oct 26, 2016
1 parent b6a5829 commit 6ae83d9
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 109 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
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
5 changes: 3 additions & 2 deletions src/server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ router.get('/abe/republish', getRepublish)
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 +90,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
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
6 changes: 4 additions & 2 deletions src/server/routes/get-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ var route = function(req, res, next){
abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
if(typeof res._header !== 'undefined' && res._header !== null) return

cmsOperations.remove.remove(req.query.filePath)
var filepath = req.originalUrl.replace('/abe/delete', '')

cmsOperations.remove.remove(filepath)

var result = {
success: 1,
file: req.query.filePath
file: filepath
}
res.set('Content-Type', 'application/json')
res.send(JSON.stringify(result))
Expand Down
63 changes: 23 additions & 40 deletions src/server/routes/get-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,39 @@ import {editor} from '../controllers/editor'
import locale from '../helpers/abe-locale'

var route = function(req, res, next) {
if(req.query.filePath){
var testXSS = xss(req.query.filePath, {
var filePath = req.originalUrl.replace('/abe', '')
if (filePath === '' || filePath === '/') {
filePath = null
}

if(filePath != null){
var testXSS = xss(filePath, {
whiteList: [],
stripIgnoreTag: true
})
if(testXSS !== req.query.filePath){
res.redirect(`/abe/${req.params[0]}?filePath=${testXSS}`)
return
if(testXSS !== filePath){
filePath = testXSS
}
}

abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
if(typeof res._header !== 'undefined' && res._header !== null) return

var templatePath = req.params[0]

var filePath = null
if(typeof req.query.filePath !== 'undefined' && req.query.filePath !== null) {
filePath = path.join(config.root, config.draft.url, req.query.filePath.replace(config.root))
}
var debugJson = (req.query.debugJson && req.query.debugJson == 'true' ) ? true : false
var debugJsonKey = (req.query.key) ? req.query.key : false
var debugHtml = (req.query.debugHtml && req.query.debugHtml == 'true' ) ? true : false

var isHome = true
var jsonPath = null
var linkPath = null
var templatePath = null

let p = new Promise((resolve) => {

if(templatePath !== null && filePath !== null) {
var jsonPath = null
var linkPath = null
if(filePath != null) {
isHome = false

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
templatePath = filePathTest.abe_meta.template
}

if(jsonPath === null || !coreUtils.file.exist(jsonPath)) {
Expand Down Expand Up @@ -89,23 +86,24 @@ var route = function(req, res, next) {

var _hasBlock = (obj) ? obj.hasBlock : false
var _hasSingleBlock = (obj) ? obj.hasSingleBlock : false
var _template = (filePath) ? '/page/' + req.params[0] + `?filePath=${req.query.filePath}` : false
var _template = (filePath) ? '/page/' + req.params[0] + `?filePath=${filePath}` : false
var _form = (obj) ? obj.form : false
var _json = (obj) ? obj.json : false
var _text = (obj) ? obj.text : false
// var _file = (tplUrl) ? tplUrl.draft.file : false
var _filePath = (req.query.filePath) ? req.query.filePath : false
var _filePath = (filePath) ? filePath : false
if (_filePath) {
_filePath = '/' + _filePath.replace(/^\/+/, '')
}

var pageHtml = ''
var pageHtml = ''
if(typeof _json !== 'undefined' && _json !== null
&& typeof _json.abe_meta !== 'undefined' && _json.abe_meta !== null) {
&& typeof _json.abe_meta !== 'undefined' && _json.abe_meta !== null) {

var text = cmsTemplates.template.getTemplate(_json.abe_meta.template)
var page = new Page(_json.abe_meta.template, text, _json, false)
pageHtml = page.html.replace(/"/g, '"').replace(/'/g, '\'').replace(/<!--/g, '<ABE!--').replace(/-->/g, '--ABE>')
}
}

var EditorVariables = {
pageHtml: pageHtml,
Expand All @@ -118,9 +116,6 @@ var route = function(req, res, next) {
hasSingleBlock: _hasSingleBlock,
hasBlock: _hasBlock,
form: _form,
urlToSaveFile: _filePath,
folderToSaveFile: (_filePath) ? path.dirname(_filePath) : '',
// tplName: _file,
json: _json,
config: config,
Locales: coreUtils.locales.instance.i18n,
Expand All @@ -134,19 +129,7 @@ var route = function(req, res, next) {
}
EditorVariables = abeExtend.hooks.instance.trigger('afterVariables', EditorVariables)

if (debugJson) {
var dj = _json
if(debugJsonKey && typeof dj[debugJsonKey] !== 'undefined' && dj[debugJsonKey] !== null) {
dj = dj[debugJsonKey]
}
res.set('Content-Type', 'application/json')
res.send(JSON.stringify(dj))
}else if (debugHtml) {
res.set('Content-Type', 'text/plain')
res.send(_text)
}else {
res.render(config.abeEngine, EditorVariables)
}
res.render(config.abeEngine, EditorVariables)
}).catch((e) => {
console.log('error', e)
})
Expand Down
5 changes: 3 additions & 2 deletions src/server/routes/get-unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ var route = function(req, res, next){
abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
if(typeof res._header !== 'undefined' && res._header !== null) return

cmsOperations.post.unpublish(req.query.filePath)
var filepath = req.originalUrl.replace('/abe/unpublish', '')
cmsOperations.post.unpublish(filepath)

var result = {
success: 1,
file: req.query.filePath
file: filepath
}
res.set('Content-Type', 'application/json')
res.send(JSON.stringify(result))
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/create-form-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{#if isHome}}
<option value="{{cleanPath}}" clean-value="{{website}}">{{cleanPath}}</option>
{{else}}
{{#ifCond @root.json.abe_meta.cleanTemplate cleanNameNoExt}}
{{#ifCond @root.json.abe_meta.template cleanNameNoExt}}
<option value="{{cleanPath}}" clean-value="{{website}}" selected="selected">{{cleanPath}}</option>
{{else}}
<option value="{{cleanPath}}" clean-value="{{website}}">{{cleanPath}}</option>
Expand Down
Loading

0 comments on commit 6ae83d9

Please sign in to comment.