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',
|
|
|
|
classNames: 'checkbox',
|
2019-02-26 06:29:57 +03:00
|
|
|
attributeBindings: ['for', 'disabled'],
|
|
|
|
disabled: computed('_disabled', function () {
|
|
|
|
if (this.get('_disabled')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
2016-01-19 17:25:36 +03:00
|
|
|
value: computed('_flagValue', {
|
|
|
|
get() {
|
|
|
|
return this.get('_flagValue');
|
|
|
|
},
|
|
|
|
set(key, value) {
|
2019-02-26 06:29:57 +03:00
|
|
|
if (this.get('flag') === 'members' && value === true) {
|
|
|
|
this.set(`feature.subscribers`, false);
|
|
|
|
}
|
2016-01-19 17:25:36 +03:00
|
|
|
return this.set(`feature.${this.get('flag')}`, value);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
for: computed('flag', function () {
|
|
|
|
return `labs-${this.get('flag')}`;
|
|
|
|
}),
|
2016-05-05 17:03:09 +03:00
|
|
|
|
2016-01-19 17:25:36 +03:00
|
|
|
name: computed('flag', function () {
|
|
|
|
return `labs[${this.get('flag')}]`;
|
2018-01-11 20:43:23 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
2019-02-26 06:29:57 +03:00
|
|
|
defineProperty(this, '_flagValue', readOnly(`feature.${this.get('flag')}`), function () {
|
|
|
|
return this.get(`feature.${this.get('flag')}`);
|
|
|
|
});
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
FeatureFlagComponent.reopenClass({
|
2019-02-26 06:29:57 +03:00
|
|
|
positionalParams: ['flag', '_disabled']
|
2016-01-19 17:25:36 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
export default FeatureFlagComponent;
|