From 86c8a5de817631a4d0a9f313c056a31351d515be Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 6 Feb 2015 13:16:19 +0000 Subject: [PATCH] Allow palette categories to be predefined --- public/red/ui/palette.js | 14 ++++++++++---- red/api/info.js | 9 ++++++++- settings.js | 9 ++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/public/red/ui/palette.js b/public/red/ui/palette.js index 42e096ba2..c8255b517 100644 --- a/public/red/ui/palette.js +++ b/public/red/ui/palette.js @@ -21,8 +21,8 @@ RED.palette = (function() { function createCategoryContainer(category){ var escapedCategory = category.replace(" ","_"); - $("#palette-container").append('
'+ - '
'+category.replace("_"," ")+'
'+ + var catDiv = $("#palette-container").append('
'+ + '
'+category.replace("_"," ")+'
'+ '
'+ '
'+ '
'+ @@ -30,7 +30,7 @@ RED.palette = (function() { '
'+ '
'); - $("#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('
'); @@ -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(); }); diff --git a/red/api/info.js b/red/api/info.js index 7a63f6a3a..a0b78cbb0 100644 --- a/red/api/info.js +++ b/red/api/info.js @@ -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); } } diff --git a/settings.js b/settings.js index 1bfacbe53..3db5fca2d 100644 --- a/settings.js +++ b/settings.js @@ -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: {