1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
define.class("$ui/view", function ($ui$, view, label) {

        this.attributes = {
                config:Config({type:Object})
        }

        this.render = function() {
                var name = this.config.name;
                var states = [];
                // get the last, most meaningful facet
                var type = this.config.facets[this.config.facets.length - 1];
                states.push(label({text: 'type: ' + type}))
                for (var key in this.config.state) {
                        var state = this.config.state[key];
                        // format type
                        var val = JSON.stringify(state.value);
                        if (state.units) {
                                // append units after formatting, e.g. temperature.imperial.fahrenheit -> fahrenheit
                                var units = state.units.split('.');
                                val += ' ' + units[units.length - 1];
                        }
                        states.push(label({text: key + ': ' + val}))
                }

                return [
                        view({
                                        name:"things",
                                        flexdirection: "column",
                                        justifycontent:"space-around"
                                },
                                label({text:name}),
                                states
                        )
                ]
        }

});