Files
threshold-ui/ui/admin/app/services/feature-edition.js
T

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-04-03 20:28:31 -07:00
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2023-03-17 14:34:37 -07:00
import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import config from 'admin/config/environment';
export default class FeatureEditionService extends Service {
// =services
@service features;
// =attributes
2023-04-03 20:28:31 -07:00
licensedFeatures = Object.keys(config.features.licensedFeatures);
2023-03-17 14:34:37 -07:00
@tracked edition;
// array of edition strings
get editions() {
2023-04-03 20:28:31 -07:00
return Object.keys(config.features.featureEditions);
2023-03-17 14:34:37 -07:00
}
// =methods
/**
* Initializes the selected edition from the config.
2023-04-03 20:28:31 -07:00
* @param {string} edition
* @param {?string[]} enabledFeatures - list of extra features to enable
2023-03-17 14:34:37 -07:00
*/
2023-04-03 20:28:31 -07:00
initialize(edition, enabledFeatures) {
this.setEdition(edition || config.features.defaultEdition, enabledFeatures);
2023-03-17 14:34:37 -07:00
}
2023-04-03 20:28:31 -07:00
/**
* Enables the specified edition.
* @param {string} edition
* @param {?string[]} enabledFeatures - list of extra features to enable
*/
setEdition(edition, enabledFeatures) {
this.edition = edition;
const editionFlags = config.features.featureEditions[edition];
2023-03-17 14:34:37 -07:00
Object.keys(editionFlags).forEach((flag) => {
if (editionFlags[flag]) {
this.features.enable(flag);
} else {
this.features.disable(flag);
}
});
2023-04-03 20:28:31 -07:00
if (enabledFeatures) {
enabledFeatures.forEach((flag) => this.features.enable(flag));
}
2023-03-17 14:34:37 -07:00
}
}