1 | var APIClient = require( '@bipsync/apiclient' );
|
2 |
|
3 |
|
4 | APIClient.generateReportTool( {
|
5 |
|
6 | formats : [ 'html' ],
|
7 |
|
8 | schema : {
|
9 | "type" : "object",
|
10 | "properties" : {
|
11 | "reportPeriod" : {
|
12 | "title" : "WAU/MAU Report Period",
|
13 | "type" : "string",
|
14 | "enum": [ "wau", "mau" ],
|
15 | "enumNames": [ "Weekly Active Users", "Monthly Active Users" ]
|
16 | }
|
17 | },
|
18 | "required" : [ "reportPeriod" ]
|
19 | },
|
20 |
|
21 | fetch : function() {
|
22 |
|
23 | APIClient( 'https://devenvone-api.bipsync.dev' )
|
24 | .then( function( client ) {
|
25 |
|
26 | client.request( 'v1/analytics/' + client.options.reportPeriod, { body : {
|
27 | select : 'name,singular,initialStage,created,updated',
|
28 | dateFormat : 'm/j/Y'
|
29 | } } )
|
30 | .then( function( report ) {
|
31 |
|
32 | var reportPeriod = client.options.reportPeriod === 'wau' ? 'week' : 'month',
|
33 | period = Object.keys( report[ 'calendar' + reportPeriod ] )[ 0 ],
|
34 | users = report[ 'calendar' + reportPeriod ][ period ].users;
|
35 |
|
36 | var output = {
|
37 | period : period,
|
38 | users : []
|
39 | };
|
40 |
|
41 | var chain = new Promise( function( resolve ) {
|
42 |
|
43 | users.forEach( function( id ) {
|
44 |
|
45 | client.request( 'v1/user/' + id )
|
46 | .then( function( document ) {
|
47 | output.users.push( document );
|
48 |
|
49 | if ( output.users.length === users.length ) {
|
50 | resolve();
|
51 | }
|
52 | } );
|
53 |
|
54 | } );
|
55 |
|
56 | });
|
57 |
|
58 |
|
59 | chain.then( function() {
|
60 | client.output( output );
|
61 | } );
|
62 |
|
63 | } );
|
64 |
|
65 | } );
|
66 |
|
67 | },
|
68 |
|
69 | template : `
|
70 | <div class="hide-with-empty-cells">
|
71 | <h1>{{month}}</h1>
|
72 | <!--<h2>Total Users: {{total}}</h2>-->
|
73 |
|
74 | <table class="hide-with-empty-cells">
|
75 | <tr>
|
76 | <th>User ID</th>
|
77 | <th>Name</th>
|
78 | <th>Email</th>
|
79 | </tr>
|
80 | {{#users}}<tr>
|
81 | <td>{{id}}</td>
|
82 | <td>{{name}}</td>
|
83 | <td>{{email}}</td>
|
84 | </tr>{{/users}}
|
85 | </table>
|
86 | </div>`
|
87 |
|
88 | } );
|