Implemented enabling/disabling of features
This commit is contained in:
@@ -7,6 +7,7 @@ Schemas.Feature = new SimpleSchema({
|
|||||||
uses: {type: String, optional: true, trim: false},
|
uses: {type: String, optional: true, trim: false},
|
||||||
used: {type: Number, defaultValue: 0},
|
used: {type: Number, defaultValue: 0},
|
||||||
reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
|
reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"},
|
||||||
|
enabled: {type: String, allowedValues: ["enabled", "disabled", "alwaysEnabled"], defaultValue: "alwaysEnabled"},
|
||||||
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -21,8 +22,17 @@ Features.helpers({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Delete effects where this the removed feature is source
|
||||||
Features.before.remove(function (userId, feature) {
|
Features.before.remove(function (userId, feature) {
|
||||||
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
||||||
Effects.remove(effect._id);
|
Effects.remove(effect._id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//keep the effects up to date with enabled state
|
||||||
|
Features.after.update(function (userId, feature, fieldNames, modifier, options) {
|
||||||
|
var enabled = feature.enabled !== "disabled";
|
||||||
|
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
||||||
|
Effects.update(effect._id, { $set: {charId: feature.charId, enabled: enabled, name: feature.name} });
|
||||||
|
});
|
||||||
|
}, {fetchPrevious: false});
|
||||||
|
|||||||
@@ -24,8 +24,17 @@
|
|||||||
{{#if usesSet}}
|
{{#if usesSet}}
|
||||||
<paper-input id="usesInput" label="Uses" floatinglabel value={{uses}}></paper-input>
|
<paper-input id="usesInput" label="Uses" floatinglabel value={{uses}}></paper-input>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
<paper-dropdown-menu id="enabledDropdown" label="Enable Feature">
|
||||||
|
<paper-dropdown layered class="dropdown">
|
||||||
|
<core-menu id="enabledMenu" class="menu" selected={{enabled}} on-tap="onStatMenuTap">
|
||||||
|
<paper-item name="alwaysEnabled"> Always Enabled </paper-item>
|
||||||
|
<paper-item name="enabled"> Enabled </paper-item>
|
||||||
|
<paper-item name="disabled"> Disabled </paper-item>
|
||||||
|
</core-menu>
|
||||||
|
</paper-dropdown>
|
||||||
|
</paper-dropdown-menu>
|
||||||
</div>
|
</div>
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="feature"}}
|
{{> effectsEditList sourceId=_id charId=charId type="feature" name=name enabled=isEnabled}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
</template>
|
</template>
|
||||||
@@ -27,7 +27,14 @@ Template.featureDialog.events({
|
|||||||
var value = event.target.value;
|
var value = event.target.value;
|
||||||
var featureId = this._id;
|
var featureId = this._id;
|
||||||
Features.update(featureId, {$set: {uses: value}});
|
Features.update(featureId, {$set: {uses: value}});
|
||||||
}
|
},
|
||||||
|
"core-select #enabledDropdown": function(event){
|
||||||
|
var detail = event.originalEvent.detail;
|
||||||
|
if(!detail.isSelected) return;
|
||||||
|
var value = detail.item.getAttribute("name");
|
||||||
|
if (value === this.enabled) return;
|
||||||
|
Features.update(this._id, {$set: {enabled: value}});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.featureDialog.helpers({
|
Template.featureDialog.helpers({
|
||||||
@@ -36,5 +43,8 @@ Template.featureDialog.helpers({
|
|||||||
},
|
},
|
||||||
usesSet: function(){
|
usesSet: function(){
|
||||||
return _.isString(this.uses);
|
return _.isString(this.uses);
|
||||||
|
},
|
||||||
|
isEnabled: function(){
|
||||||
|
return this.enabled !== "disabled";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -21,3 +21,37 @@
|
|||||||
.resourceCards paper-shadow.healthCard {
|
.resourceCards paper-shadow.healthCard {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*To change the ink color for checked state:*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #ink[checked] {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*To change the checkbox checked color:*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #checkbox.checked {
|
||||||
|
background-color: #ffffff;
|
||||||
|
background-color: rgba(255,255,255,0.27);
|
||||||
|
border-color: #ffffff;
|
||||||
|
border-color: rgba(255,255,255,0.27);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ensure the checkmark is shown when ticked*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #checkbox.checked #checkmark {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*To change the ink color for unchecked state:*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #ink {
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*To change the checkbox unchecked color:*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #checkbox {
|
||||||
|
border-color: #ffffff;
|
||||||
|
border-color: rgba(255,255,255,0.54);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*ensure checkmark isn't shown early*/
|
||||||
|
paper-checkbox.enabledCheckbox::shadow #checkbox #checkmark {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,9 +65,15 @@
|
|||||||
{{#each features}}
|
{{#each features}}
|
||||||
<paper-shadow class="card container featureCard" hero-id="main" {{detailHero}}>
|
<paper-shadow class="card container featureCard" hero-id="main" {{detailHero}}>
|
||||||
<div class="containerTop {{colorClass}}" hero-id="toolbar" layout horizontal center {{detailHero}}>
|
<div class="containerTop {{colorClass}}" hero-id="toolbar" layout horizontal center {{detailHero}}>
|
||||||
|
<paper-ripple fit></paper-ripple>
|
||||||
<div class="containerName subhead" hero-id="title" flex {{detailHero}}>{{name}}</div>
|
<div class="containerName subhead" hero-id="title" flex {{detailHero}}>{{name}}</div>
|
||||||
{{#if hasUses}}<div class="subhead" style="margin-right: 8px">{{usesLeft}}/{{usesValue}}</div>{{/if}}
|
{{#if hasUses}}<div class="subhead" style="margin-right: 8px">{{usesLeft}}/{{usesValue}}</div>{{/if}}
|
||||||
<paper-ripple fit></paper-ripple>
|
<paper-ripple fit></paper-ripple>
|
||||||
|
{{#if canEnable}}
|
||||||
|
<core-tooltip label="Feature enabled" position="left">
|
||||||
|
<paper-checkbox class="enabledCheckbox" checked={{isEnabled}}></paper-checkbox>
|
||||||
|
</core-tooltip>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{#if description}}<div flex class="containerMain body1 featureDescription">{{description}}</div>{{/if}}
|
{{#if description}}<div flex class="containerMain body1 featureDescription">{{description}}</div>{{/if}}
|
||||||
{{#if hasUses}}
|
{{#if hasUses}}
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ Template.features.helpers({
|
|||||||
characterProficiencies: function(){
|
characterProficiencies: function(){
|
||||||
var char = Characters.findOne(this._id);
|
var char = Characters.findOne(this._id);
|
||||||
return char && char.proficiencies;
|
return char && char.proficiencies;
|
||||||
|
},
|
||||||
|
canEnable: function(){
|
||||||
|
return this.enabled !== "alwaysEnabled";
|
||||||
|
},
|
||||||
|
isEnabled: function(){
|
||||||
|
return this.enabled !== "disabled";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,6 +89,15 @@ Template.features.events({
|
|||||||
data: {charId: charId, field: "proficiencies", title: "Proficiencies", color: "q"},
|
data: {charId: charId, field: "proficiencies", title: "Proficiencies", color: "q"},
|
||||||
heroId: this._id + "proficiencies"
|
heroId: this._id + "proficiencies"
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
"tap .enabledCheckbox": function(event){
|
||||||
|
event.stopPropagation();
|
||||||
|
},
|
||||||
|
"change .enabledCheckbox": function(event){
|
||||||
|
var enabled;
|
||||||
|
if(this.enabled === "enabled") enabled = "disabled";
|
||||||
|
else enabled = "enabled";
|
||||||
|
Features.update(this._id, {$set: {enabled: enabled}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,13 @@
|
|||||||
</div>
|
</div>
|
||||||
{{#if settings.showUnprepared}}
|
{{#if settings.showUnprepared}}
|
||||||
{{#if maxPrepared}}<div class="subhead">{{numPrepared}} / {{evaluate charId maxPrepared}}</div>{{/if}}
|
{{#if maxPrepared}}<div class="subhead">{{numPrepared}} / {{evaluate charId maxPrepared}}</div>{{/if}}
|
||||||
<paper-icon-button class="finishPrep" icon="done"></paper-icon-button>
|
<core-tooltip label="Done" position="left">
|
||||||
|
<paper-icon-button class="finishPrep" icon="done"></paper-icon-button>
|
||||||
|
</core-tooltip>
|
||||||
{{else}}
|
{{else}}
|
||||||
<paper-icon-button class="prepSpells" icon="book"></paper-icon-button>
|
<core-tooltip label="Change prepared spells" position="left">
|
||||||
|
<paper-icon-button class="prepSpells" icon="book"></paper-icon-button>
|
||||||
|
</core-tooltip>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div class="containerMain">
|
<div class="containerMain">
|
||||||
|
|||||||
Reference in New Issue
Block a user