Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_base.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. var path= require('path');
  4. var gsp = require.resolve('gridstack');
  5. var node;
  6. var uiset = RED.settings.ui || "{}";
  7. function BaseNode(config) {
  8. RED.nodes.createNode(this, config);
  9. node = this;
  10. var baseFontName = "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif";
  11. var defaultLightTheme = {
  12. baseColor: '#0094CE',
  13. baseFont: baseFontName
  14. }
  15. var defaultDarkTheme = {
  16. baseColor: '#097479',
  17. baseFont: baseFontName
  18. }
  19. var defaultCustomTheme = {
  20. name: 'Untitled Theme 1',
  21. baseColor: defaultLightTheme.baseColor,
  22. baseFont: baseFontName
  23. }
  24. var defaultAngularTheme = {
  25. primary:'indigo',
  26. accents:'teal',
  27. warn: "red",
  28. background:'grey',
  29. palette:'light'
  30. };
  31. // Setup theme name
  32. // First try old format (for upgrading with old flow file)
  33. // Then try new format
  34. // Else fallback to theme-light
  35. var themeName;
  36. if (typeof(config.theme) === 'string') { themeName = config.theme; }
  37. else { themeName = config.theme.name || "theme-light"; }
  38. // Setup other styles
  39. var defaultThemeState = {}
  40. if (themeName === 'theme-light') {
  41. defaultThemeState["base-font"] = {value: baseFontName};
  42. defaultThemeState["base-color"] = {value: "#0094CE"};
  43. defaultThemeState["page-backgroundColor"] = {value: "#fafafa"};
  44. defaultThemeState["page-titlebar-backgroundColor"] = {value: "#0094CE"};
  45. defaultThemeState["page-sidebar-backgroundColor"] = {value: "#ffffff"};
  46. defaultThemeState["group-backgroundColor"] = {value: "#ffffff"};
  47. defaultThemeState["group-textColor"] = {value: "#000000"};
  48. defaultThemeState["group-borderColor"] = {value: "#ffffff"};
  49. defaultThemeState["widget-textColor"] = {value: "#111111"};
  50. defaultThemeState["widget-backgroundColor"] = {value: "#0094CE"};
  51. }
  52. else {
  53. defaultThemeState["base-font"] = {value: baseFontName};
  54. defaultThemeState["base-color"] = {value: "#097479"};
  55. defaultThemeState["page-backgroundColor"] = {value: "#111111"};
  56. defaultThemeState["page-titlebar-backgroundColor"] = {value: "#097479"};
  57. defaultThemeState["page-sidebar-backgroundColor"] = {value: "#333333"};
  58. defaultThemeState["group-backgroundColor"] = {value: "#333333"};
  59. defaultThemeState["group-textColor"] = {value: "#10cfd8"};
  60. defaultThemeState["group-borderColor"] = {value: "#555555"};
  61. defaultThemeState["widget-textColor"] = {value: "#eeeeee"};
  62. defaultThemeState["widget-backgroundColor"] = {value: "#097479"};
  63. }
  64. var defaultThemeObject = {
  65. name: themeName,
  66. lightTheme: config.theme.lightTheme || defaultLightTheme,
  67. darkTheme: config.theme.darkTheme || defaultDarkTheme,
  68. customTheme: config.theme.customTheme || defaultCustomTheme,
  69. angularTheme: config.theme.angularTheme || defaultAngularTheme,
  70. themeState: config.theme.themeState || defaultThemeState
  71. }
  72. this.config = {
  73. theme: defaultThemeObject,
  74. site: config.site
  75. }
  76. ui.addBaseConfig(this.config);
  77. }
  78. RED.nodes.registerType("ui_base", BaseNode);
  79. RED.library.register("themes");
  80. RED.httpAdmin.get('/uisettings', function(req, res) {
  81. res.json(uiset);
  82. });
  83. const optsjs = { root: path.join(__dirname , '../dist/js'), dotfiles: 'deny' };
  84. const optscss = { root: path.join(__dirname , '../dist/css'), dotfiles: 'deny' };
  85. const optsgs = { root: path.dirname(gsp), dotfiles: 'deny' };
  86. RED.httpAdmin.get('/ui_base/js/*', function(req, res) {
  87. res.sendFile(req.params[0], optsjs, function (err) {
  88. if (err) {
  89. res.sendStatus(404);
  90. if (node) { node.warn("JS File not found."); }
  91. else { console.log("ui_base - error:",err); }
  92. }
  93. });
  94. });
  95. RED.httpAdmin.get('/ui_base/css/*', function(req, res) {
  96. res.sendFile(req.params[0], optscss, function (err) {
  97. if (err) {
  98. res.sendStatus(404);
  99. if (node) { node.warn("CSS File not found."); }
  100. else { console.log("ui_base - error:",err); }
  101. }
  102. });
  103. });
  104. RED.httpAdmin.get('/ui_base/gs/*', function(req, res) {
  105. res.sendFile(req.params[0], optsgs, function (err) {
  106. if (err) {
  107. res.sendStatus(404);
  108. if (node) { node.warn("Gridstack file not found."); }
  109. else { console.log("ui_base - error:",err); }
  110. }
  111. });
  112. });
  113. };