Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
308 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as structure from './structure' | ||
|
||
export { | ||
structure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import path from 'path' | ||
import fse from 'fs-extra' | ||
import mkdirp from 'mkdirp' | ||
import execPromise from 'child-process-promise' | ||
|
||
import { | ||
coreUtils, | ||
cmsData, | ||
config | ||
} from '../../' | ||
|
||
export function addFolder(folderPath) { | ||
mkdirp(path.join(config.root, folderPath), function (err) { | ||
if (err) console.error(err) | ||
}); | ||
return folderPath | ||
} | ||
|
||
export function removeFolder(folderPath) { | ||
execPromise.exec("rm -rf " + path.join(config.root, folderPath)).then(function (result) { | ||
var stdout = result.stdout | ||
var stderr = result.stderr | ||
if(stdout) console.log('stdout: ', stdout) | ||
if(stderr) console.log('stderr: ', stderr) | ||
}) | ||
return folderPath | ||
} | ||
|
||
export function editStructure(type, folderPath) { | ||
if(type === 'add') addFolder(folderPath) | ||
else removeFolder(folderPath) | ||
|
||
return folderPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Handlebars from 'handlebars' | ||
|
||
/** | ||
* Handlebars helper, remove config.root from array of path | ||
*/ | ||
export default function removeRootPath(obj, url, formater) { | ||
obj = JSON.parse(JSON.stringify(obj).replace(new RegExp(JSON.parse(url).root, 'g'), '')) | ||
obj = Handlebars.helpers[formater](obj); | ||
|
||
return obj | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/*global document */ | ||
|
||
import Handlebars from 'handlebars' | ||
import Nanoajax from 'nanoajax' | ||
import qs from 'qs' | ||
|
||
export default class EditorStructures { | ||
constructor() { | ||
this._ajax = Nanoajax.ajax | ||
this.datas = JSON.parse(document.querySelector('.structure-json').value) | ||
this.structureWrapper = document.querySelector('.structure-wrapper') | ||
this.folderName = document.querySelector('input.folder-name') | ||
|
||
var lvl_0 = this.createFolder('structure/', 0, '', 'main', '') | ||
|
||
this.createStructure(lvl_0, this.datas) | ||
this.structureWrapper.appendChild(lvl_0) | ||
this.rebind() | ||
} | ||
|
||
createFolder(path, level, daddy, folderName, hidden = 'hidden') { | ||
var folder = document.createElement('div') | ||
if(hidden && hidden !== '') folder.classList.add(hidden) | ||
folder.classList.add('structure-folder') | ||
folder.setAttribute('data-path', path.replace(/\/+$/, "") + '/') | ||
folder.setAttribute('data-level', level) | ||
folder.setAttribute('data-daddy', daddy) | ||
|
||
var span = document.createElement('span') | ||
span.innerHTML = `<span class="glyphicon glyphicon-chevron-right arrow" aria-hidden="true"></span> | ||
${folderName} | ||
<div class="structure-tool"> | ||
<span class="glyphicon glyphicon-plus-sign folder-action" data-init="0" data-action="add" aria-hidden="true"></span> | ||
<span class="glyphicon glyphicon-remove-circle folder-action" data-init="0" data-action="remove" aria-hidden="true"></span> | ||
</div> | ||
` | ||
folder.appendChild(span) | ||
|
||
this.bindArrow(span.querySelector('.arrow')) | ||
|
||
return folder | ||
} | ||
|
||
toggleFolder(daddy, forceState = ''){ | ||
var folders = daddy.querySelectorAll('[data-level="' + (parseInt(daddy.getAttribute('data-level')) + 1) + '"]') | ||
if(folders) { | ||
if(!daddy.classList.contains('open') || forceState === 'open'){ | ||
daddy.classList.add('open') | ||
Array.prototype.forEach.call(folders, (folder) => { | ||
folder.classList.remove('hidden') | ||
}) | ||
} | ||
else{ | ||
daddy.classList.remove('open') | ||
Array.prototype.forEach.call(folders, (folder) => { | ||
folder.classList.add('hidden') | ||
}) | ||
} | ||
} | ||
} | ||
|
||
bindArrow(arrow) { | ||
arrow.addEventListener('click', (e) => { | ||
this.toggleFolder(arrow.parentNode.parentNode) | ||
}) | ||
} | ||
|
||
createStructure(daddy, datas) { | ||
Array.prototype.forEach.call(datas, (data) => { | ||
var folderName = data['path'].split('/') | ||
var folder = this.createFolder( | ||
data['path'], | ||
(parseInt(daddy.getAttribute('data-level')) + 1), | ||
daddy.getAttribute('data-daddy'), | ||
folderName[folderName.length - 1] | ||
) | ||
daddy.appendChild(folder) | ||
|
||
if(data.folders && data.folders.length > 0) this.createStructure(folder, data.folders) | ||
}) | ||
} | ||
|
||
add(element){ | ||
this.toggleFolder(element, 'open') | ||
this.folderName.removeAttribute('disabled') | ||
this.folderName.focus() | ||
this.folderName.setAttribute('data-folder', `[data-path="${element.getAttribute('data-path')}"]`) | ||
|
||
var writeFolderName = (e) => { | ||
var value = this.folderName.value | ||
if(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/.test(value)) this.folderName.classList.remove('error') | ||
else this.folderName.classList.add('error') | ||
if(e.keyCode === 13) { | ||
if(/^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$/.test(value)){ | ||
this.folderName.removeEventListener('keyup', writeFolderName) | ||
this.folderName.setAttribute('disabled', 1) | ||
var newFolderDaddy = document.querySelector(this.folderName.getAttribute('data-folder')) | ||
var path = newFolderDaddy.getAttribute('data-path').split('/') | ||
path.pop() | ||
path = path.concat(value).join('/') | ||
var folder = this.createFolder( | ||
newFolderDaddy.getAttribute('data-path') + value, | ||
(parseInt(newFolderDaddy.getAttribute('data-level')) + 1), | ||
newFolderDaddy.getAttribute('data-daddy'), | ||
value, | ||
'' | ||
) | ||
newFolderDaddy.appendChild(folder) | ||
this.rebind() | ||
this.save(qs.stringify({type: 'add', folderPath: (newFolderDaddy.getAttribute('data-path') + value)})) | ||
this.folderName.value = '' | ||
} | ||
} | ||
} | ||
|
||
this.folderName.removeEventListener('keyup', writeFolderName) | ||
this.folderName.addEventListener('keyup', writeFolderName) | ||
} | ||
|
||
remove(element){ | ||
this.save(qs.stringify({type: 'remove', folderPath: element.getAttribute('data-path')})) | ||
element.parentNode.removeChild(element) | ||
} | ||
|
||
save(body){ | ||
this._ajax({url: '/abe/structure/', body: body, cors: true, method: 'post'}, () => { | ||
|
||
}) | ||
} | ||
|
||
rebind(){ | ||
var folderActions = document.querySelectorAll('.folder-action') | ||
Array.prototype.forEach.call(folderActions, (folderAction) => { | ||
if(parseInt(folderAction.getAttribute('data-init')) === 0){ | ||
folderAction.setAttribute('data-init', 1) | ||
folderAction.addEventListener('click', (e) => { | ||
var target = e.target | ||
this[target.getAttribute('data-action')](target.parentNode.parentNode.parentNode) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { | ||
cmsStructure | ||
} from '../../cli' | ||
|
||
var route = function(req, res){ | ||
if(typeof res._header !== 'undefined' && res._header !== null) return | ||
cmsStructure.structure.editStructure(req.body.type, req.body.folderPath) | ||
res.set('Content-Type', 'application/json') | ||
res.send(JSON.stringify({success: 1})) | ||
} | ||
|
||
export default route |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
.structure-editor{ | ||
display: inline-block; | ||
} | ||
.folder-name{ | ||
transition: all 350ms ease-in-out; | ||
display: inline-block; | ||
width: 100%; | ||
opacity: 1; | ||
&[disabled]{ | ||
opacity: 0.4; | ||
} | ||
&.error{ | ||
border-color: red; | ||
} | ||
} | ||
.structure-folder{ | ||
margin: 5px; | ||
position: relative; | ||
> span:hover{ | ||
cursor: pointer; | ||
} | ||
.glyphicon-chevron-right{ | ||
transition: all 100ms ease-in-out; | ||
font-size: 10px; | ||
} | ||
&.open{ | ||
> span .glyphicon-chevron-right{ | ||
transform: rotate(45deg); | ||
} | ||
&:before{ | ||
background: #eee; | ||
content: " "; | ||
position: absolute; | ||
bottom: 3px; | ||
left: 6px; | ||
width: 1px; | ||
height: calc(100% - 34px); | ||
} | ||
} | ||
.structure-folder{ | ||
margin-left: 20px; | ||
} | ||
.glyphicon-remove-circle, | ||
.glyphicon-plus-sign{ | ||
transition: all 100ms ease-in-out; | ||
font-size: 15px; | ||
opacity: 0.5; | ||
&:hover{ | ||
opacity: 1; | ||
} | ||
} | ||
.structure-tool{ | ||
display: inline-block; | ||
transition: all 100ms ease-in-out; | ||
opacity: 0; | ||
padding: 0px 5px; | ||
&:hover{ | ||
opacity: 1; | ||
} | ||
} | ||
.glyphicon-remove-circle{ | ||
color: #ff1371; | ||
margin-left: 5px; | ||
} | ||
.glyphicon-plus-sign{ | ||
color: #47b8e0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.