@@ -2,71 +2,83 @@ var View = require('ampersand-view');
2
2
var pluralize = require ( 'pluralize' ) ;
3
3
var format = require ( 'util' ) . format ;
4
4
var app = require ( 'ampersand-app' ) ;
5
+ var numeral = require ( 'numeral' ) ;
5
6
var debug = require ( 'debug' ) ( 'scout:sampling-message:index' ) ;
6
7
7
8
var SamplingMessageView = View . extend ( {
9
+ template : require ( './index.jade' ) ,
8
10
session : {
9
11
parent : 'state'
10
12
} ,
11
- bindings : {
12
- visible : {
13
- type : 'booleanClass' ,
14
- no : 'hidden'
15
- } ,
16
- sample_size_message : {
17
- hook : 'sample_size_message'
18
- } ,
19
- is_sample : [
20
- {
21
- hook : 'is_sample' ,
22
- type : 'booleanClass' ,
23
- no : 'hidden'
24
- } ,
25
- {
26
- hook : 'is_query' ,
27
- type : 'booleanClass' ,
28
- yes : 'hidden'
29
- }
30
- ]
31
- } ,
32
13
props : {
33
- schema_sample_size : {
14
+ sample_size : {
15
+ type : 'number' ,
16
+ default : 0
17
+ } ,
18
+ total_count : {
34
19
type : 'number' ,
35
20
default : 0
36
21
}
37
22
} ,
38
23
derived : {
39
24
visible : {
40
- deps : [ 'schema_sample_size ' ] ,
25
+ deps : [ 'sample_size ' ] ,
41
26
fn : function ( ) {
42
- return this . schema_sample_size > 0 ;
27
+ return this . sample_size > 0 ;
43
28
}
44
29
} ,
45
30
is_sample : {
46
- deps : [ 'schema_sample_size' ] ,
31
+ deps : [ 'sample_size' ] ,
32
+ fn : function ( ) {
33
+ return this . sample_size === app . queryOptions . size ;
34
+ }
35
+ } ,
36
+ formatted_total_count : {
37
+ deps : [ 'total_count' ] ,
47
38
fn : function ( ) {
48
- return this . schema_sample_size === app . queryOptions . size ;
39
+ return numeral ( this . total_count ) . format ( '0,0' ) ;
49
40
}
50
41
} ,
51
- sample_size_message : {
52
- deps : [ 'schema_sample_size ' ] ,
42
+ formatted_sample_size : {
43
+ deps : [ 'sample_size ' ] ,
53
44
fn : function ( ) {
54
- return format ( '%d %s' , this . parent . parent . schema . sample_size ,
55
- pluralize ( 'document' , this . parent . parent . schema . sample_size ) ) ;
45
+ return numeral ( this . sample_size ) . format ( '0,0' ) ;
46
+ }
47
+ } ,
48
+ total_count_document : {
49
+ deps : [ 'total_count' ] ,
50
+ fn : function ( ) {
51
+ return pluralize ( 'document' , this . total_count ) ;
52
+ }
53
+ } ,
54
+ sample_size_document : {
55
+ deps : [ 'sample_size' ] ,
56
+ fn : function ( ) {
57
+ return pluralize ( 'document' , this . sample_size ) ;
56
58
}
57
59
}
58
60
} ,
59
- template : require ( './index.jade' ) ,
61
+ bindings : {
62
+ visible : {
63
+ type : 'booleanClass' ,
64
+ no : 'hidden'
65
+ }
66
+ } ,
60
67
initialize : function ( ) {
61
68
this . listenTo ( this . parent . parent . schema , 'request' , this . hide . bind ( this ) ) ;
62
69
this . listenTo ( this . parent . parent . schema , 'sync' , this . show . bind ( this ) ) ;
63
70
} ,
64
71
hide : function ( ) {
65
- this . schema_sample_size = 0 ;
72
+ this . sample_size = 0 ;
73
+ this . total_count = 0 ;
66
74
} ,
67
75
show : function ( ) {
68
- debug ( 'actual count' , this . parent . parent . schema . total ) ;
69
- this . schema_sample_size = this . parent . parent . schema . sample_size ;
76
+ this . sample_size = this . parent . parent . schema . sample_size ;
77
+ this . total_count = this . parent . parent . schema . total ;
78
+ this . render ( ) ;
79
+ } ,
80
+ render : function ( ) {
81
+ this . renderWithTemplate ( this ) ;
70
82
}
71
83
} ) ;
72
84
module . exports = SamplingMessageView ;
0 commit comments