Skip to content

Commit

Permalink
Merge pull request #4663 from njkim/4658_node_label
Browse files Browse the repository at this point in the history
add the choice to only show selected node in dropdown #4658
  • Loading branch information
chiatt authored Mar 7, 2019
2 parents 2e68066 + 74c5310 commit 1f8171b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
40 changes: 22 additions & 18 deletions arches/app/media/js/viewmodels/node-value-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ define([
'viewmodels/widget',
'arches',
], function(_, ko, $, WidgetViewModel, arches) {
var nameLookup = {};

var NodeValueSelectViewModel = function(params) {
var self = this;
params.configKeys = ['placeholder'];
params.configKeys = ['placeholder','displayOnlySelectedNode'];
this.multiple = params.multiple || false;

WidgetViewModel.apply(this, [params]);
Expand All @@ -20,8 +20,8 @@ define([
var resourceId = ko.unwrap(self.resourceinstanceid);
if (resourceId === '') {
resourceId = window.location.pathname.split('/');
resourceId = resourceId[resourceId.length-1]
};
resourceId = resourceId[resourceId.length-1];
}
var url = arches.urls.resource_tiles.replace('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', resourceId);
if (nodeid && resourceId) {
$.ajax({
Expand All @@ -46,10 +46,14 @@ define([
this.form.on('after-update', updateTiles);
}

this.toggleDisplayOnlySelected = function(){
this.displayOnlySelectedNode(!this.displayOnlySelectedNode());
};

this.getSelectedDisplayValue = function() {
var value = self.value();
var nodeid = params.node.config.nodeid();
var tile = _.find(self.tiles(), function (tile) {
var tile = _.find(self.tiles(), function(tile) {
return tile.tileid === value;
});

Expand All @@ -58,7 +62,7 @@ define([
return nodeid === dv.nodeid;
});
}
}
};
this.displayValue = ko.computed(function() {
var displayValue = this.getSelectedDisplayValue();
return displayValue ? displayValue.value : '';
Expand All @@ -77,9 +81,9 @@ define([
multiple: this.multiple,
placeholder: this.placeholder,
allowClear: true,
query: function (query) {
query: function(query) {
var tiles = self.tiles();
var data = {results: []}
var data = {results: []};
tiles.forEach(function(tile) {
data.results.push(tile);
});
Expand All @@ -89,16 +93,16 @@ define([
var id = $(element).val();
var tiles = self.tiles();
if (id !== "") {
var setSelection = function (tiles, callback) {
var selection = _.find(tiles, function (tile) {
var setSelection = function(tiles, callback) {
var selection = _.find(tiles, function(tile) {
return tile.tileid === id;
});
if (selection) {
callback(selection);
}
};
if (tiles.length === 0) {
var subscription = self.tiles.subscribe(function (tiles) {
var subscription = self.tiles.subscribe(function(tiles) {
setSelection(tiles, callback);
subscription.dispose();
});
Expand All @@ -107,7 +111,7 @@ define([
}
}
},
escapeMarkup: function (m) { return m; },
escapeMarkup: function(m) { return m; },
id: function(tile) {
return tile.tileid;
},
Expand All @@ -120,12 +124,12 @@ define([
'<div class="selected-node-value">' +
getDisplayValueMarkup(nodeDisplayValue) +
'</div>';

tile.display_values.forEach(function(displayValue) {
if (nodeid !== displayValue.nodeid) {
markup += getDisplayValueMarkup(displayValue);
}
});
if (!params.config().displayOnlySelectedNode) {
tile.display_values.forEach(function(displayValue) {
if (nodeid !== displayValue.nodeid) {
markup += getDisplayValueMarkup(displayValue);
}
});}
markup += '</div>';
return markup;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2019-023-05 14:40
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
('models', '4352_format_config_number_widget'),
]

operations = [
migrations.RunSQL(
"""
update widgets as w
set defaultconfig = jsonb_set(defaultconfig, '{displayOnlySelectedNode}', to_jsonb(false), true)
where w.name = 'node-value-select';
update cards_x_nodes_x_widgets as c
set config = jsonb_set(config, '{displayOnlySelectedNode}', to_jsonb(false), true)
where c.widgetid = 'f5d6b190-bbf0-4dc9-b991-1debab8cb4a9';
""",
"""
update widgets as w
set defaultconfig = defaultconfig - 'displayOnlySelectedNode'
where w.name = 'node-value-select';
update cards_x_nodes_x_widgets as c
set config = config - 'displayOnlySelectedNode'
where c.widgetid = 'f5d6b190-bbf0-4dc9-b991-1debab8cb4a9';
""")
]
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,22 @@
{% trans "Placeholder" %}
</div>
<div class="col-xs-12 pad-no crud-widget-container">
<div class='node-config-item'>
<input placeholder="{% trans "Placeholder" %}"
class="form-control input-md widget-input"
data-bind="value: placeholder, valueUpdate: 'keyup'">
</div>
<div class='node-config-item'>
<div class='control-label'>{% trans "Dropdown Format" %}
</div>
<div class="toggle-container">
<span class="switch switch-small" data-bind="css: {'on': displayOnlySelectedNode()}, click: toggleDisplayOnlySelected"><small></small></span>
<div style="display:flex; flex-direction:row;">
<div class="arches-toggle-sm" data-bind="text:'Show only the value of the selected node in the dropdown options'"></div>
</div>
<span class="arches-toggle-subtitle" data-bind="text: 'Check to limit the dropdown to only this widgets node rather than all nodes in the tile.'"></span>
</div>
</div>
</div>
</div>
{% endblock config_form %}
Expand Down

0 comments on commit 1f8171b

Please sign in to comment.