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

Commit eeb88c9

Browse files
committed
Move customization to layout generation
1 parent 90355b3 commit eeb88c9

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

lib/dashboard.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var THROTTLE_TIMEOUT = 150;
2020
var Dashboard = function Dashboard(options) {
2121
this.options = options || {};
2222
this.views = {};
23-
this.settings = options.settings;
2423

2524
this.screen = blessed.screen({
2625
smartCSR: true,
@@ -36,7 +35,7 @@ var Dashboard = function Dashboard(options) {
3635
};
3736

3837
Dashboard.prototype._createViews = function () {
39-
this.layouts = generateLayouts(this.options.layoutsFile);
38+
this.layouts = generateLayouts(this.options.layoutsFile, this.options.settings);
4039
this.views = [];
4140

4241
// container prevents stream view scrolling from interfering with side views
@@ -156,11 +155,6 @@ Dashboard.prototype._showLayout = function (id) {
156155
}
157156

158157
if (View) {
159-
if (this.settings[layoutConfig.view.type]) {
160-
layoutConfig = _.merge(layoutConfig, {
161-
view: this.settings[layoutConfig.view.type]
162-
});
163-
}
164158
var view = new View({
165159
parent: this.container,
166160
logProvider: this.logProvider,

lib/generate-layouts.js

Lines changed: 21 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,24 @@ 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+
var customized = 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+
return customized;
140+
};
141+
};
127142

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

0 commit comments

Comments
 (0)