Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit 124e443

Browse files
authored
Merge pull request #86 from jjasonclark/single_config
Move customization to layout generation
2 parents 02ec9b4 + c2a9fee commit 124e443

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/dashboard.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var THROTTLE_TIMEOUT = 150;
1515
var Dashboard = function Dashboard(options) {
1616
this.options = options || {};
1717
this.views = {};
18-
this.settings = options.settings;
1918

2019
this.screen = blessed.screen({
2120
smartCSR: true,
@@ -31,7 +30,7 @@ var Dashboard = function Dashboard(options) {
3130
};
3231

3332
Dashboard.prototype._createViews = function () {
34-
this.layouts = generateLayouts(this.options.layoutsFile);
33+
this.layouts = generateLayouts(this.options.layoutsFile, this.options.settings);
3534
this.views = [];
3635

3736
// container prevents stream view scrolling from interfering with side views
@@ -136,11 +135,6 @@ Dashboard.prototype._showLayout = function (id) {
136135
var View = views.getConstructor(layoutConfig.view);
137136

138137
if (View) {
139-
if (this.settings[layoutConfig.view.type]) {
140-
layoutConfig = _.merge(layoutConfig, {
141-
view: this.settings[layoutConfig.view.type]
142-
});
143-
}
144138
var view = new View({
145139
parent: this.container,
146140
logProvider: this.logProvider,

lib/generate-layouts.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
2+
23
var _ = require("lodash");
34
var assert = require("assert");
45
var path = require("path");
56
var defaultLayoutConfig = require("./default-layout-config");
67
var validate = require("jsonschema").validate;
78
var layoutConfigSchema = require("./layout-config-schema.json");
8-
/* eslint-disable no-magic-numbers */
99

1010
// Each layout consists of vertical panels, that contains its position and horizontal views.
1111
// Flex-like positions of panels and views defined by 'grow' and 'size' parameters.
@@ -108,7 +108,7 @@ var createLayout = function (panelsConfig) {
108108
}, []);
109109
};
110110

111-
module.exports = function generateLayouts(layoutsFile) {
111+
var loadConfigs = function (layoutsFile) {
112112
var layoutConfig = defaultLayoutConfig;
113113
if (layoutsFile) {
114114
/* eslint-disable global-require */
@@ -124,6 +124,23 @@ module.exports = function generateLayouts(layoutsFile) {
124124
"Layout config is invalid:\n\n * " + validationResult.errors.join("\n * ") + "\n"
125125
);
126126
}
127+
return layoutConfig;
128+
};
129+
130+
var applyCustomizations = function (customizations) {
131+
return function (panelsConfig) {
132+
return panelsConfig.map(function (view) {
133+
var customization = customizations[view.type];
134+
if (!customization) {
135+
return view;
136+
}
137+
return _.merge(view, { view: customization });
138+
});
139+
};
140+
};
127141

128-
return layoutConfig.map(createLayout);
142+
module.exports = function generateLayouts(layoutsFile, customizations) {
143+
return loadConfigs(layoutsFile)
144+
.map(applyCustomizations(customizations || {}))
145+
.map(createLayout);
129146
};

0 commit comments

Comments
 (0)