all files / src/ config.ts

70% Statements 14/20
37.5% Branches 3/8
50% Functions 1/2
68.42% Lines 13/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                                            43× 43×                   43×          
"use strict";
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var _ = require('lodash');
var Action = require('./actionNames');
var buildInfo = require('./buildInfo.json');
/**
 * Override config values at runtime in dashboard.json, see: https://gitlab.com/lobaro/iot-dashboard/wikis/home#configuration
 */
var defaultConfig = {
    version: "",
    revision: "",
    revisionShort: "",
    branch: "",
    persistenceTarget: "local-storage",
    devMode: true,
    auth: {
        username: null,
        logoutUrl: null
    },
    title: {
        text: "IoT-Dashboard",
        url: "http://iot-dashboard.org"
    },
    pluginRegistryApiKey: "",
    pluginRegistryUrl: "https://dashboard.lobaro.com"
};
function setConfigValue(key, value) {
    return {
        type: Action.SET_CONFIG_VALUE,
        key: key,
        value: value
    };
}
exports.setConfigValue = setConfigValue;
function config(state, action) {
    if (state === void 0) { state = buildInfo; }
    switch (action.type) {
        case Action.SET_CONFIG_VALUE: {
            var value = action.value;
            if (action.key === 'pluginRegistryUrl' && _.endsWith(value, '/')) {
                value = value.replace(/\/+$/, "");
            }
            return _.assign({}, defaultConfig, state, (_a = {}, _a[action.key] = value, _a), buildInfo);
        }
        default:
            // Content of configJson overrides everything else!
            return _.assign({}, defaultConfig, state, buildInfo);
    }
    var _a;
}
exports.config = config;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = config;