Skip to content

Commit beafc42

Browse files
rueckstiesskangas
authored andcommitted
copied changes from branch INT-271 in here.
1 parent 3bbf623 commit beafc42

File tree

3 files changed

+79
-34
lines changed

3 files changed

+79
-34
lines changed

src/field-list/index.less

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,24 @@
9393
cursor: default;
9494
}
9595

96-
.schema-field-type-list .schema-field-type {
96+
&.active > .schema-field-type {
97+
background: @gray1;
98+
}
99+
100+
&.active.selected > .schema-field-type {
101+
background: @chart0;
102+
}
103+
104+
.schema-field-type-list > .schema-field-wrapper:not(.active) > .schema-field-type {
97105
// nested array subtypes
98-
background: @gray4;
106+
background: @gray5;
99107
}
100108
}
101109

102110
.schema-field-type {
103111
height: 5px;
104112
margin-right: 2px;
105-
background: @gray1;
113+
background: @gray5;
106114
}
107115

108116
.schema-field-type-label {

src/field-list/type-list-item.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.schema-field-wrapper(data-hook='bar')
2-
if hasSubtype
2+
if isSubtype
33
.schema-field-type(data-toggle='tooltip')
44
span.schema-field-type-label
55
= model.getId()
6-
if !hasSubtype
6+
if !isSubtype
77
.schema-field-type(data-toggle='tooltip')
88
div(data-hook='array-subtype-subview')

src/field-list/type-list.js

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ var format = require('util').format;
33
var numeral = require('numeral');
44
var tooltipMixin = require('../tooltip-mixin');
55
var _ = require('lodash');
6-
// var debug = require('debug')('scout:field-list:type-list');
6+
var debug = require('debug')('scout:field-list:type-list');
77

88
var TypeListView;
99

1010
var TypeListItem = View.extend(tooltipMixin, {
1111
template: require('./type-list-item.jade'),
12-
namespace: 'TypeListItem',
12+
modelType: 'TypeListItem',
1313
bindings: {
14+
active: {
15+
type: 'booleanClass',
16+
name: 'active'
17+
},
18+
selected: {
19+
type: 'booleanClass',
20+
name: 'selected'
21+
},
1422
'model.name': [
1523
{
1624
hook: 'name'
@@ -34,13 +42,22 @@ var TypeListItem = View.extend(tooltipMixin, {
3442
// @see https://github.com/twbs/bootstrap/issues/14769
3543
this.tooltip({
3644
title: this.tooltip_message,
37-
placement: this.hasSubtype ? 'bottom' : 'top'
45+
placement: this.hasSubtype ? 'bottom' : 'top',
46+
container: 'body'
3847
}).attr('data-original-title', this.tooltip_message);
3948
}
4049
}
4150
},
42-
props: {
43-
parent: 'state'
51+
session: {
52+
parent: 'state',
53+
active: {
54+
type: 'boolean',
55+
default: false
56+
},
57+
selected: {
58+
type: 'boolean',
59+
default: false
60+
}
4461
},
4562
derived: {
4663
probability_percentage: {
@@ -55,10 +72,10 @@ var TypeListItem = View.extend(tooltipMixin, {
5572
return format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%'));
5673
}
5774
},
58-
hasSubtype: {
75+
isSubtype: {
5976
deps: ['parent'],
6077
fn: function() {
61-
return this.parent.hasSubtype;
78+
return this.parent.hasSubtypes;
6279
}
6380
}
6481
},
@@ -73,48 +90,68 @@ var TypeListItem = View.extend(tooltipMixin, {
7390
return new TypeListView({
7491
el: el,
7592
parent: this,
76-
hasSubtype: true,
93+
hasSubtypes: true,
7794
collection: this.model.types
7895
});
7996
}
8097
}
8198
},
99+
initialize: function() {
100+
this.on('change:active', this.activeChanged);
101+
},
82102
typeClicked: function(evt) {
83103
evt.stopPropagation();
84104

85-
// no clicks on Undefined allowed
86-
if (this.model.getId() === 'Undefined') return;
87-
88-
// find the field view, at most 2 levels up
89-
var fieldView = this.parent.parent;
90-
if (fieldView.getType() !== 'FieldView') {
91-
fieldView = fieldView.parent.parent;
92-
}
105+
if (this.active) {
106+
// already active, query building mode
107+
this.toggle('selected');
108+
} else {
109+
// no clicks on Undefined allowed
110+
if (this.model.getId() === 'Undefined') return;
93111

94-
// if type model has changed, render its minichart
95-
if (fieldView.type_model !== this.model) {
96-
fieldView.type_model = this.model;
97-
fieldView.renderMinicharts();
112+
// find the field view, at most 2 levels up
113+
var fieldView = this.parent.parent;
114+
if (fieldView.getType() !== 'FieldView') {
115+
fieldView = fieldView.parent.parent;
116+
}
117+
// if type model has changed, render its minichart
118+
if (fieldView.type_model !== this.model) {
119+
this.active = true;
120+
fieldView.type_model = this.model;
121+
fieldView.renderMinicharts();
122+
}
98123
}
99124
},
100-
render: function() {
101-
this.renderWithTemplate(this);
125+
activeChanged: function(view, value) {
126+
debug('active changed to %s for %s -> %s', value, view.model.parent.name, view.model.name);
102127
}
103128
});
104129

105130

106131
TypeListView = module.exports = View.extend({
107-
props: {
108-
hasSubtype: {
132+
modelType: 'TypeListView',
133+
session: {
134+
collectionView: 'object',
135+
hasSubtypes: {
109136
type: 'boolean',
110137
default: false
111-
}
138+
},
139+
parent: 'state'
112140
},
113141
template: require('./type-list.jade'),
142+
deactivateOthers: function(view) {
143+
if (!this.collectionView) return;
144+
_.each(this.collectionView.views, function(typeView) {
145+
if (view !== typeView) {
146+
typeView.active = false;
147+
typeView.selected = false;
148+
}
149+
});
150+
},
114151
render: function() {
115-
if (!_.get(this, 'parent.hasSubtype')) {
116-
this.renderWithTemplate(this);
117-
this.renderCollection(this.collection, TypeListItem, this.queryByHook('types'));
118-
}
152+
this.renderWithTemplate(this);
153+
this.collectionView = this.renderCollection(this.collection, TypeListItem,
154+
this.queryByHook('types'));
155+
this.collectionView.views[0].active = true;
119156
}
120157
});

0 commit comments

Comments
 (0)