2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/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
|
|
|
|
|
|
|
const FeatureFlagComponent = Component.extend({
|
2018-01-11 20:43:23 +03:00
|
|
|
feature: service(),
|
|
|
|
|
2016-01-19 17:25:36 +03:00
|
|
|
tagName: 'label',
|
2021-06-07 22:07:45 +03:00
|
|
|
classNames: 'switch',
|
2019-02-26 06:29:57 +03:00
|
|
|
attributeBindings: ['for', 'disabled'],
|
|
|
|
disabled: computed('_disabled', function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this._disabled) {
|
2019-02-26 06:29:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
2016-01-19 17:25:36 +03:00
|
|
|
value: computed('_flagValue', {
|
|
|
|
get() {
|
2019-03-06 16:53:54 +03:00
|
|
|
return this._flagValue;
|
2016-01-19 17:25:36 +03:00
|
|
|
},
|
|
|
|
set(key, value) {
|
2019-03-06 16:53:54 +03:00
|
|
|
return this.set(`feature.${this.flag}`, value);
|
2016-01-19 17:25:36 +03:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
for: computed('flag', function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
return `labs-${this.flag}`;
|
2016-01-19 17:25:36 +03:00
|
|
|
}),
|
2016-05-05 17:03:09 +03:00
|
|
|
|
2016-01-19 17:25:36 +03:00
|
|
|
name: computed('flag', function () {
|
2019-03-06 16:53:54 +03:00
|
|
|
return `labs[${this.flag}]`;
|
2018-01-11 20:43:23 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
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
|
|
|
}
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
export default FeatureFlagComponent;
|