Skip to content

Commit 3bbf623

Browse files
rueckstiesskangas
authored andcommitted
added type distribution bars for array sub-types
to avoid recursive imports, TypeListItem is now implemented in type-list.js
1 parent 6e7cd59 commit 3bbf623

File tree

4 files changed

+125
-74
lines changed

4 files changed

+125
-74
lines changed

src/field-list/index.less

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
}
8383
.schema-field-type-list {
8484
border-radius: 1px;
85-
// background: @gray6;
85+
padding-top: 4px;
8686

8787
.schema-field-wrapper {
8888
float: left;
@@ -92,6 +92,11 @@
9292
&.schema-field-type-undefined {
9393
cursor: default;
9494
}
95+
96+
.schema-field-type-list .schema-field-type {
97+
// nested array subtypes
98+
background: @gray4;
99+
}
95100
}
96101

97102
.schema-field-type {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.schema-field-wrapper(data-hook='bar')
2-
.schema-field-type(data-toggle='tooltip')
2+
if hasSubtype
3+
.schema-field-type(data-toggle='tooltip')
34
span.schema-field-type-label
45
= model.getId()
6+
if !hasSubtype
7+
.schema-field-type(data-toggle='tooltip')
8+
div(data-hook='array-subtype-subview')

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

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/field-list/type-list.js

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,120 @@
11
var View = require('ampersand-view');
2-
var TypeListItem = require('./type-list-item');
2+
var format = require('util').format;
3+
var numeral = require('numeral');
4+
var tooltipMixin = require('../tooltip-mixin');
5+
var _ = require('lodash');
6+
// var debug = require('debug')('scout:field-list:type-list');
37

4-
module.exports = View.extend({
8+
var TypeListView;
9+
10+
var TypeListItem = View.extend(tooltipMixin, {
11+
template: require('./type-list-item.jade'),
12+
namespace: 'TypeListItem',
13+
bindings: {
14+
'model.name': [
15+
{
16+
hook: 'name'
17+
},
18+
{
19+
hook: 'bar',
20+
type: function(el) {
21+
el.classList.add('schema-field-type-' + this.model.getId().toLowerCase());
22+
}
23+
}
24+
],
25+
probability_percentage: {
26+
hook: 'bar',
27+
type: function(el) {
28+
el.style.width = this.probability_percentage;
29+
}
30+
},
31+
tooltip_message: {
32+
type: function() {
33+
// need to set `title` and `data-original-title` due to bug in bootstrap's tooltip
34+
// @see https://github.com/twbs/bootstrap/issues/14769
35+
this.tooltip({
36+
title: this.tooltip_message,
37+
placement: this.hasSubtype ? 'bottom' : 'top'
38+
}).attr('data-original-title', this.tooltip_message);
39+
}
40+
}
41+
},
42+
props: {
43+
parent: 'state'
44+
},
45+
derived: {
46+
probability_percentage: {
47+
deps: ['model.probability'],
48+
fn: function() {
49+
return numeral(this.model.probability).format('0.00%');
50+
}
51+
},
52+
tooltip_message: {
53+
deps: ['model.probability'],
54+
fn: function() {
55+
return format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%'));
56+
}
57+
},
58+
hasSubtype: {
59+
deps: ['parent'],
60+
fn: function() {
61+
return this.parent.hasSubtype;
62+
}
63+
}
64+
},
65+
events: {
66+
'click .schema-field-wrapper': 'typeClicked'
67+
},
68+
subviews: {
69+
subtypes: {
70+
hook: 'array-subtype-subview',
71+
waitFor: 'model.types',
72+
prepareView: function(el) {
73+
return new TypeListView({
74+
el: el,
75+
parent: this,
76+
hasSubtype: true,
77+
collection: this.model.types
78+
});
79+
}
80+
}
81+
},
82+
typeClicked: function(evt) {
83+
evt.stopPropagation();
84+
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+
}
93+
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();
98+
}
99+
},
100+
render: function() {
101+
this.renderWithTemplate(this);
102+
}
103+
});
104+
105+
106+
TypeListView = module.exports = View.extend({
107+
props: {
108+
hasSubtype: {
109+
type: 'boolean',
110+
default: false
111+
}
112+
},
5113
template: require('./type-list.jade'),
6114
render: function() {
7-
this.renderWithTemplate();
8-
this.renderCollection(this.collection, TypeListItem, this.queryByHook('types'));
115+
if (!_.get(this, 'parent.hasSubtype')) {
116+
this.renderWithTemplate(this);
117+
this.renderCollection(this.collection, TypeListItem, this.queryByHook('types'));
118+
}
9119
}
10120
});

0 commit comments

Comments
 (0)