Commit 37b5b89d authored by Caleb Weeks's avatar Caleb Weeks

allowing documentatio in Tools section. vast changes to support UI showing...

allowing documentatio in Tools section. vast changes to support UI showing queries that are processing.
parent cbee1c31
......@@ -48,25 +48,30 @@ module.exports.process = (params, cb)=>{
};
/**************************
* Removing all of this code around touching for now.
* I think it's ultimiately overkill now that there's a 100ms
* delay between posts.
*/
//we only want to go with the touch approach when we're under or on a page
if(_.includes(targetPath, "/jcr:content")){
//do a 'touch' to ensure there are no current conflicts
let jcrPath = targetPath.split('/jcr:content')[0] + '/jcr:content';
//first ensure the path exists
sc.getSling(`/bin/exists.json?path=${jcrPath}`, (err, data) => {
if (!data || !data.exists) {
log.debug(`${jcrPath} doesn't exist. Not touching.`);
//page doesn't exst, can't touch
submitRequest();
}else{
log.debug(`${jcrPath} exists. Touching.`);
//make sure all is good before proceeding
module.exports.touch(sc, jcrPath, submitRequest);
}
});
}else{
// if(_.includes(targetPath, "/jcr:content")){
// //do a 'touch' to ensure there are no current conflicts
// let jcrPath = targetPath.split('/jcr:content')[0] + '/jcr:content';
// //first ensure the path exists
// sc.getSling(`/bin/exists.json?path=${jcrPath}`, (err, data) => {
// if (!data || !data.exists) {
// log.debug(`${jcrPath} doesn't exist. Not touching.`);
// //page doesn't exst, can't touch
// submitRequest();
// }else{
// log.debug(`${jcrPath} exists. Touching.`);
// //make sure all is good before proceeding
// module.exports.touch(sc, jcrPath, submitRequest);
// }
// });
// }else{
submitRequest();
}
// }
}
......
const _ = require('lodash');
const fs = require('fs');
var _path=require("path");
module.exports.process=function(data, $, cb){
var sc=$.sc;
......@@ -12,8 +13,10 @@ module.exports.process=function(data, $, cb){
mainPath = mainPath.substring(0, mainPath.indexOf('/-'));
}
let tagsMode = /^\/etc\/tags/.test(mainPath);
let mediaMode = /^\/content\/(dam|media)\//.test(mainPath);
let routesMode = /^\/alt\/apps\//.test(mainPath);
let sendError = (errorMessage)=>{
......@@ -21,51 +24,80 @@ module.exports.process=function(data, $, cb){
cb(null,false);
}
let sendSuccess = (html) => {
res.setHeader('Content-Type', "text/html; charset=utf-8");
res.end(html);
cb(null,false);
};
let loadDocumentationPath = (documentationPath, pageMode, success, fail) => {
fs.access(documentationPath, (accessError)=>{
if(accessError){
fail({exists: false});
}else{
//read in the file
fs.readFile(documentationPath, 'utf-8', (err, mdFile)=>{
if(err){
fail({exists: true});
}else{
var html=$.templates["doc-page"]({body : global.bl.marked(mdFile), blConfig:$.blConfig, includePreviewControls: pageMode, path : mainPath});
success(html);
}
});
}
});
};
if(sc.mode === 'author'){
if(tagsMode || mediaMode){
sendError("Documentation not supported here.");
}else{
let pageMode = mainPath.indexOf('jcr:content') < 0;
let slingPath = (pageMode ? mainPath + "/jcr:content" : mainPath) + ".1.json";
sc.getSling(slingPath, {leaveMangledNames: true},function(err, slingData){
if(err){
sendError("No page found. Documentation not supported here.")
}else{
let rtype=slingData["sling:resourceType"];
if(routesMode){
const appsRoot =_path.join(global.bl.appRoot, "apps");
let documentationPath = appsRoot + mainPath.replace('/alt/apps/', '/').replace('/tools/', '/routes/tools/') + '/' + _.last(mainPath.split('/')) + '.md';
loadDocumentationPath(documentationPath, false, sendSuccess, (fail)=>{
if(fail.exists){
sendError(`Route '${mainPath}' : Error reading documentation file.`);
}else{
sendError(`Route '${mainPath}' has no documentation.`);
}
} );
}else{
let pageMode = mainPath.indexOf('jcr:content') < 0;
let slingPath = (pageMode ? mainPath + "/jcr:content" : mainPath) + ".1.json";
if(!rtype){
sendError("No resource type found. Documentation not supported here.");
sc.getSling(slingPath, {leaveMangledNames: true},function(err, slingData){
if(err){
sendError("No page found. Documentation not supported here.")
}else{
let comp =$.componentRegistry.get(rtype);
let rtype=slingData["sling:resourceType"];
if(!comp){
sendError(`Invalid resource type found: ${rtype} Documentation not supported here.`);
if(!rtype){
sendError("No resource type found. Documentation not supported here.");
}else{
//does this type have an md file
let documentationPath = comp.path + '/' + _.last(comp.path.split('/')) + '.md';
fs.access(documentationPath, (accessError)=>{
if(accessError){
sendError(`Component '${comp.title ? comp.title : ''} (${rtype})' has no documentation.`);
}else{
//read in the file
fs.readFile(documentationPath, 'utf-8', (err, mdFile)=>{
if(err){
sendError(`Component '${comp.title ? comp.title :''} (${rtype})' : Error reading documentation file.`);
}else{
var html=$.templates["doc-page"]({body : global.bl.marked(mdFile), blConfig:$.blConfig, includePreviewControls: pageMode, path : mainPath});
res.setHeader('Content-Type', "text/html; charset=utf-8");
res.end(html);
cb(null,false);
}
});
}
});
let comp =$.componentRegistry.get(rtype);
if(!comp){
sendError(`Invalid resource type found: ${rtype} Documentation not supported here.`);
}else{
//does this type have an md file
let documentationPath = comp.path + '/' + _.last(comp.path.split('/')) + '.md';
loadDocumentationPath(documentationPath, pageMode, sendSuccess, (fail)=>{
if(fail.exists){
sendError(`Component '${comp.title ? comp.title :''} (${rtype})' : Error reading documentation file.`);
}else{
sendError(`Component '${comp.title ? comp.title : ''} (${rtype})' has no documentation.`);
}
} );
}
}
}
}
});
});
}
}
}else{
res.status(404).send('Unavailable');
......
......@@ -11,7 +11,8 @@ module.exports.process=function(data, $, cb){
// This is where the main framed HTML page is loaded.
data.blConfig = $.blConfig;
data.blConfig.modes={
view:{icon:"visibility"}
view:{icon:"visibility"},
documentation : {icon : "library_books", title: "Documentation", prefix: global.bl.appsMount + "blacklight/edit/documentation/"}
}
data.config.breadcrumb.push({name:"Tools", link:data.blConfig.appsMount + "blacklight/edit/tools"})
global.bl.modules.modelHelpers.blacklight.edit.setFrameScripts(data);
......
......@@ -81,7 +81,7 @@
{{/if}}
</h5>
</div>
{{#unless bl:map.bl:q.bl:processing}}
{{#unless bl:map.bl:queryProcessing}}
<div class="collapsible-body" style="background-color:#fafafa;">
{{> page.component-body bl:key=@component.key bl:fromTopLevel=true}}
</div>
......
......@@ -41,7 +41,7 @@
</div>
</div>
{{#unless bl:map.bl:q.bl:processing}}
{{#unless bl:map.bl:queryProcessing}}
{{increment "bl:inner-li-depth"}}
<div class="collapsible-body inner-li-content" style="overflow-x:scroll;padding:12px; {{#if bl:parentIsECC}}padding-left:24px;{{/if}} {{#ifOp @root.bl:inner-li-depth "iseven"}}background-color:#ededed{{/ifOp}}">
{{> page.component-body .}}
......
......@@ -578,11 +578,11 @@ module.exports=function($, window, page, editDialog){
var thisProcessor = $(this);
var localKey = thisProcessor.data('component-key') ? ("/" +thisProcessor.data('component-key')) : "";
var blQPath = page.blProxyPrefix + page.getButtonSlingPath(thisProcessor) + localKey + "/bl:map/bl:q";
var blQPath = page.blProxyPrefix + page.getButtonSlingPath(thisProcessor) + localKey;
var checkProcessing = function(){
$.get(blQPath + '.json', function(data){
if(!data || data['bl:processing']){
$.get(blQPath + '.bl-processing.json', function(data){
if(!data || data['processing']){
//recheck in another second
setTimeout(checkProcessing, 1000);
}else{
......
......@@ -56,6 +56,29 @@ module.exports=function($, window, options){
dblclick: function(event, data){
window.alert(data.node.key);
},
renderTitle: function(event, data){
if(data.node.data.queryProcessing){
var checkProcessing = function(){
var blQPath = window.BL.config.slingProxyPrefix + data.node.key + '.bl-processing.json?pageOnly=true';
$.get(blQPath + '.json', function(blProcessingData){
if(!blProcessingData || blProcessingData.processing){
//recheck in another second
setTimeout(checkProcessing, 1000);
}else{
//update UI
data.node.data.queryProcessing = false;
data.node.icon = 'fa fa-file';
data.node.lazy = true;
data.node.tooltip = data.node.title + " (query complete)";
data.node.renderTitle();
//todo: instead of just setting lazy true, could check for children now?
}
});
};
//found a page node that is processing. kick off the monitoring
setTimeout(checkProcessing, 1000);
}
}
};
......@@ -240,8 +263,8 @@ module.exports=function($, window, options){
}else{
title=title? (title + " <span class='lang-label'>(" + name + ")</span>") : name;
}
var hasChildren=val.hasChildren;
results.push({title:title, key:val.path, lazy:hasChildren, icon:options.treeIcon}); //, icon:"fa fa-file-o"});
var hasChildren= !val.queryProcessing && val.hasChildren;
results.push({title:title, key:val.path, lazy:hasChildren, icon: val.queryProcessing ? 'fa fa-refresh fa-spin' : options.treeIcon, queryProcessing: val.queryProcessing, tooltip: val.queryProcessing ? 'A query is modifying the children of this page.' : title}); //, icon:"fa fa-file-o"});
});
def.resolve(results);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment