2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {attributeBindings, classNames, tagName} from '@ember-decorators/component';
|
2019-02-26 06:29:57 +03:00
|
|
|
import {computed, defineProperty} from '@ember/object';
|
|
|
|
import {readOnly} from '@ember/object/computed';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
@tagName('label')
|
|
|
|
@classNames('switch')
|
|
|
|
@attributeBindings('for', 'disabled')
|
|
|
|
class FeatureFlagComponent extends Component {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service feature;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('_disabled')
|
|
|
|
get disabled() {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this._disabled) {
|
2019-02-26 06:29:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('_flagValue')
|
|
|
|
get value() {
|
|
|
|
return this._flagValue;
|
|
|
|
}
|
2016-01-19 17:25:36 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
set value(value) {
|
|
|
|
this.set(`feature.${this.flag}`, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('flag')
|
|
|
|
get for() {
|
2019-03-06 16:53:54 +03:00
|
|
|
return `labs-${this.flag}`;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-05-05 17:03:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('flag')
|
|
|
|
get name() {
|
2019-03-06 16:53:54 +03:00
|
|
|
return `labs[${this.flag}]`;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
|
|
|
|
init() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.init(...arguments);
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
defineProperty(this, '_flagValue', readOnly(`feature.${this.flag}`), function () {
|
|
|
|
return this.get(`feature.${this.flag}`);
|
2019-02-26 06:29:57 +03:00
|
|
|
});
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2016-01-19 17:25:36 +03:00
|
|
|
|
|
|
|
export default FeatureFlagComponent;
|