Allow palette categories to be predefined

This commit is contained in:
Nick O'Leary 2015-02-06 13:16:19 +00:00
parent 010abbd3d5
commit 86c8a5de81
3 changed files with 26 additions and 6 deletions

View File

@ -21,8 +21,8 @@ RED.palette = (function() {
function createCategoryContainer(category){
var escapedCategory = category.replace(" ","_");
$("#palette-container").append('<div class="palette-category">'+
'<div id="header-'+category+'" class="palette-header"><i class="expanded fa fa-caret-down"></i><span>'+category.replace("_"," ")+'</span></div>'+
var catDiv = $("#palette-container").append('<div id="palette-container-'+category+'" class="palette-category hide">'+
'<div id="palette-header-'+category+'" class="palette-header"><i class="expanded fa fa-caret-down"></i><span>'+category.replace("_"," ")+'</span></div>'+
'<div class="palette-content" id="palette-base-category-'+category+'">'+
'<div id="palette-'+category+'-input"></div>'+
'<div id="palette-'+category+'-output"></div>'+
@ -30,7 +30,7 @@ RED.palette = (function() {
'</div>'+
'</div>');
$("#header-"+category).on('click', function(e) {
$("#palette-header-"+category).on('click', function(e) {
$(this).next().slideToggle();
$(this).children("i").toggleClass("expanded");
});
@ -151,6 +151,7 @@ RED.palette = (function() {
if ($("#palette-base-category-"+rootCategory).length === 0) {
createCategoryContainer(rootCategory);
}
$("#palette-container-"+rootCategory).show();
if ($("#palette-"+category).length === 0) {
$("#palette-base-category-"+rootCategory).append('<div id="palette-'+category+'"></div>');
@ -241,7 +242,12 @@ RED.palette = (function() {
function init() {
$(".palette-spinner").show();
core.forEach(createCategoryContainer);
if (RED.settings.paletteCategories) {
RED.settings.paletteCategories.forEach(createCategoryContainer);
} else {
core.forEach(createCategoryContainer);
}
$("#palette-search-input").focus(function(e) {
RED.keyboard.disable();
});

View File

@ -1,5 +1,5 @@
/**
* Copyright 2014 IBM Corp.
* Copyright 2014, 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,6 +15,8 @@
**/
var settings = require('../settings');
var util = require('util');
module.exports = {
settings: function(req,res) {
var safeSettings = {
@ -22,6 +24,11 @@ module.exports = {
version: settings.version,
user: req.user
};
if (util.isArray(settings.paletteCategories)) {
safeSettings.paletteCategories = settings.paletteCategories;
}
res.json(safeSettings);
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013 IBM Corp.
* Copyright 2013, 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -133,6 +133,13 @@ module.exports = {
// bonescript:require('bonescript'),
// arduino:require('duino')
},
// The following property can be used to order the categories in the editor
// palette. If a node's category is not in the list, the category will get
// added to the end of the palette.
// If not set, the following default order is used:
//paletteCategories: ['input', 'output', 'function', 'subflows', 'social', 'storage', 'analysis', 'advanced'],
// Configure the logging output
logging: {