Skip to content

Commit

Permalink
Add unique switches to ui re #4375
Browse files Browse the repository at this point in the history
  • Loading branch information
chiatt committed Mar 22, 2019
1 parent ad9856b commit dbcefd1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
32 changes: 32 additions & 0 deletions arches/app/media/js/models/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ define([
this.set('component_id', this.component_id);
this.set('config', {});

this.uniqueNodes = ko.observableArray([]);
this.uniqueToAllInstances = ko.observable(false);

this.toggleUniqueConstraint = function(node){
_.contains(this.uniqueNodes(), node) === false ? this.uniqueNodes.push(node) : this.uniqueNodes.remove(node);
};

this.uniqueToAllInstances.subscribe(function(val){
console.log(val);
});

this.cardComponentLookup = cardComponentLookup;
this.configKeys = ko.observableArray();
this.disposables = [];
Expand Down Expand Up @@ -141,6 +152,27 @@ define([
this.parseNodes(attributes);
}, this);

this.widgets().forEach(function(widget){
widget.node.isUnique = ko.observable(false);
});

this.uniqueNodes = ko.pureComputed(function(){
var res = [];
self.widgets().forEach(function(widget) {
if (widget.node.isUnique()) {
res.push(widget.node.nodeid);
}
});
return res;
});

var updateConfigsWithUniqueNodes = function(val) {
self.configJSON({uniqueNodes: val});
console.log(self.configJSON);
}

this.uniqueNodes.subscribe(updateConfigsWithUniqueNodes);

this.disposables.push(componentIdSubscription);
this.disposables.push(cardSubscription);
this.disposables.push(widgetSubscription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</div>

<!-- Enable help -->
<div data-bind="component: { name: 'views/components/simple-switch', params: {value: model.helpenabled, config:{label: '{% trans "Enable Card-level help" %}', subtitle: '{% trans "Provide specific user guidance for this card" %}'}}}"></div>
<div data-bind="component: { name: 'views/components/simple-switch', params: {value: model.helpenabled, config:{label: '{% trans "Enable Card-level help!" %}', subtitle: '{% trans "Provide specific user guidance for this card" %}'}}}"></div>

<!-- Tertiary Panel For Card Help Text-->
<div class="" style="display: none;" data-bind="visible: model.helpenabled">
Expand Down Expand Up @@ -109,6 +109,17 @@
</div>
</div>
</div>
<div class="panel-section-title dark-colored-text pad-top">
{% trans "Unique Values" %}
</div>
<div class="form-divider">
<div data-bind="component: { name: 'views/components/simple-switch', params: {value: model.uniqueToAllInstances, config:{label: 'Unique to all resource instances?'}}}"></div>
<!-- ko if: widgets().length > 0 -->
<div data-bind="foreach: {data: widgets(), as: 'widget'}">
<div data-bind="component: { name: 'views/components/simple-switch', params: {value: widget.node.isUnique, config:{label: widget.label()}}}"></div>
</div>
<!--/ko-->
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit dbcefd1

Please sign in to comment.