-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
265 additions
and
7 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
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,31 @@ | ||
import path from 'path' | ||
import mkdirp from 'mkdirp' | ||
import fse from 'fs-extra' | ||
|
||
import { | ||
abeExtend, | ||
coreUtils, | ||
cmsData, | ||
config | ||
} from '../../' | ||
|
||
export function getFiles() { | ||
var arr = [] | ||
var res = [] | ||
arr = cmsData.file.read( | ||
path.join(config.root, config.reference.url), | ||
path.join(config.root, config.reference.url), | ||
'files', | ||
true, | ||
/(.json*?)/ | ||
) | ||
|
||
arr.forEach(function (el) { | ||
res.push({ | ||
name: el.name, | ||
data: cmsData.file.get(el.path) | ||
}) | ||
}) | ||
|
||
return res | ||
} |
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,84 @@ | ||
/*global document, FormData, CONFIG, XMLHttpRequest */ | ||
|
||
import Nanoajax from 'nanoajax' | ||
import EditorUtils from '../modules/EditorUtils' | ||
import {IframeNode} from '../utils/iframe' | ||
import on from 'on' | ||
import qs from 'qs' | ||
|
||
export default class EditorFiles { | ||
constructor() { | ||
this._ajax = Nanoajax.ajax | ||
this.referenceLinks = document.querySelectorAll('[data-ref-json]') | ||
this.textArea = document.querySelector('.display-json') | ||
this.jsonError = document.querySelector('.json-error') | ||
if(this.referenceLinks) this.rebind() | ||
} | ||
|
||
rebind() { | ||
Array.prototype.forEach.call(this.referenceLinks, (referenceLink) => { | ||
referenceLink.addEventListener('click', (e) => { | ||
e.preventDefault() | ||
this.textArea.style.opacity = 1; | ||
Array.prototype.forEach.call(this.referenceLinks, (referenceLink) => { | ||
this.textArea.classList.remove('error') | ||
this.jsonError.style.opacity = 0 | ||
referenceLink.classList.remove('active') | ||
}); | ||
e.target.classList.add('active') | ||
if(parseInt(e.target.getAttribute('data-error')) === 1) { | ||
this.textArea.classList.add('error') | ||
this.jsonError.style.opacity = 1 | ||
} | ||
this.displayReference(e.target) | ||
}) | ||
}) | ||
|
||
this.textArea.addEventListener('blur', () => { | ||
this.save() | ||
}) | ||
} | ||
|
||
save(){ | ||
var selectedElement = document.querySelector('.references-files-wrapper .list-group-item.active') | ||
var isValidJson = true | ||
this.textArea.classList.remove('error') | ||
this.jsonError.style.opacity = 0 | ||
try{ | ||
(typeof JSON.parse(this.textArea.value)) // validate json | ||
var data = qs.stringify({json: this.textArea.value, url: this.textArea.getAttribute('data-file')}) | ||
selectedElement.setAttribute('data-ref-json', this.textArea.value) | ||
selectedElement.setAttribute('data-error', 0) | ||
} | ||
catch(e){ | ||
this.jsonError.textContent = e | ||
isValidJson = false | ||
selectedElement.setAttribute('data-error', 1) | ||
} | ||
if(isValidJson){ | ||
this._ajax( | ||
{ | ||
url: `/abe/write-json/`, | ||
body: data, | ||
cors: true, | ||
method: 'post' | ||
}, | ||
(code, responseText) => { | ||
this.textArea.classList.add('saved') | ||
setTimeout(() => { | ||
this.textArea.classList.remove('saved') | ||
}, 400) | ||
}) | ||
} | ||
else { | ||
this.textArea.classList.add('error') | ||
this.jsonError.style.opacity = 1 | ||
} | ||
} | ||
|
||
displayReference(element) { | ||
this.textArea.value = JSON.stringify(JSON.parse(element.getAttribute('data-ref-json')), null, '\t') | ||
this.textArea.setAttribute('data-file', element.getAttribute('data-href')) | ||
} | ||
|
||
} |
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,21 @@ | ||
import path from 'path' | ||
import fse from 'fs-extra' | ||
import mkdirp from 'mkdirp' | ||
|
||
import { | ||
config, | ||
abeExtend, | ||
Manager | ||
} from '../../cli' | ||
|
||
var route = function(req, res, next){ | ||
if(typeof res._header !== 'undefined' && res._header !== null) return | ||
fse.writeJson(path.join(config.root, req.body.url), JSON.parse(req.body.json), function (err) { | ||
if(err) console.log("write-json reference error: ", err) | ||
Manager.instance.updateReferences() | ||
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
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,26 @@ | ||
{{#if manager.home}} | ||
<div class="manager-tab references-files visible"> | ||
<div class="page-header"> | ||
<div class="text-uppercase"> | ||
edit references | ||
</div> | ||
</div> | ||
<div class="references-files-wrapper"> | ||
<ul class="list-group"> | ||
{{#each manager.home.references}} | ||
<li class="list-group-item" data-error="0" data-href="{{@root.config.reference.url}}/{{name}}" data-ref-json='{{printJson data}}'> | ||
{{name}} | ||
</li> | ||
{{/each}} | ||
</ul> | ||
<div class="display-json-wrapper"> | ||
<textarea class="form-control display-json"></textarea> | ||
<div class="text-saved">✔ saved</div> | ||
<div class="json-error"> | ||
| ||
</div> | ||
</div> | ||
</div> | ||
<br /> | ||
</div> | ||
{{/if}} |