@@ -13,13 +13,13 @@ function getUser(callback) {
1313 callback ( _currentUser ) ;
1414 return ;
1515 }
16- buildfire . auth . getCurrentUser ( function ( err , user ) {
16+ buildfire . auth . getCurrentUser ( function ( err , user ) {
1717 if ( err ) {
1818 callback ( null ) ;
1919 return console . error ( err ) ;
2020 }
2121 if ( ! user ) {
22- return buildfire . auth . login ( { } , function ( err , user ) {
22+ return buildfire . auth . login ( { } , function ( err , user ) {
2323 if ( err ) {
2424 callback ( ) ;
2525 return console . error ( err ) ;
@@ -35,7 +35,7 @@ function getUser(callback) {
3535 buildfire . notifications . pushNotification . subscribe ( { groupName : 'suggestions' } ) ;
3636 } ) ;
3737}
38- getUser ( function ( ) { } ) ;
38+ getUser ( function ( ) { } ) ;
3939
4040var config = { } ;
4141
@@ -44,15 +44,15 @@ function listCtrl($scope) {
4444 $scope . suggestions = [ ] ;
4545 $scope . isInitalized = false ;
4646
47- $scope . $on ( 'suggestionAdded' , function ( e , obj ) {
47+ $scope . $on ( 'suggestionAdded' , function ( e , obj ) {
4848 obj . disableUpvote = true ;
4949 $scope . suggestions . unshift ( obj ) ;
5050 if ( ! $scope . $$phase ) $scope . $apply ( ) ;
5151 } ) ;
5252
5353 // added pluginInstance search to find out if social wall is available
54- var social = function ( ) {
55- buildfire . pluginInstance . search ( { } , function ( err , instances ) {
54+ var social = function ( ) {
55+ buildfire . pluginInstance . search ( { } , function ( err , instances ) {
5656 if ( err ) return console . error ( err ) ;
5757 if ( typeof instances !== 'object' ) return ;
5858
@@ -71,11 +71,12 @@ function listCtrl($scope) {
7171 } ;
7272
7373 function init ( ) {
74+
7475 buildfire . spinner . show ( ) ;
7576 $scope . suggestions = [ ] ;
7677 $scope . isInitalized = false ;
7778
78- buildfire . publicData . search ( { sort : { upVoteCount : - 1 } } , 'suggestion' , function ( err , results ) {
79+ buildfire . publicData . search ( { sort : { upVoteCount : - 1 } } , 'suggestion' , function ( err , results ) {
7980 social ( ) ;
8081
8182 if ( err ) return console . error ( err ) ;
@@ -147,26 +148,26 @@ function listCtrl($scope) {
147148 $scope . goSocial = ( s = { } ) => {
148149 if ( ! s . data ) return ;
149150 const { title, createdOn, createdBy } = s . data ;
150- const navigateToCwByDefault = (
151- config && ! Object . keys ( config ) . length
152- ?
153- true
154- :
155- config && config . navigateToCwByDefault
156- ?
157- config . navigateToCwByDefault
158- :
159- false
160- ) ;
151+ const navigateToCwByDefault = (
152+ config && ! Object . keys ( config ) . length
153+ ?
154+ true
155+ :
156+ config && config . navigateToCwByDefault
157+ ?
158+ config . navigateToCwByDefault
159+ :
160+ false
161+ ) ;
161162 const queryString = `wid=${ createdBy . displayName } -${ createdOn } &wTitle=${ title } ` ;
162- buildfire . navigation . navigateToSocialWall ( {
163- title,
164- queryString,
165- pluginTypeOrder : navigateToCwByDefault ? [ 'community' , 'premium_social' , 'social' ] : [ 'premium_social' , 'social' , 'community' ]
166- } , ( ) => { } ) ;
163+ buildfire . navigation . navigateToSocialWall ( {
164+ title,
165+ queryString,
166+ pluginTypeOrder : navigateToCwByDefault ? [ 'community' , 'premium_social' , 'social' ] : [ 'premium_social' , 'social' , 'community' ]
167+ } , ( ) => { } ) ;
167168 } ;
168169
169- $scope . showVoterModal = function ( s ) {
170+ $scope . showVoterModal = function ( s ) {
170171 var voterIds = Object . keys ( s . data . upVotedBy ) ;
171172 if ( ! voterIds . length ) {
172173 var richContent = '<p style="padding-top: 10px; text-align: center">No votes yet!<p>' ;
@@ -189,15 +190,15 @@ function listCtrl($scope) {
189190 var richContent = `
190191 <div class="user-container">
191192 ${ users
192- . map ( user => {
193- return `
193+ . map ( user => {
194+ return `
194195 <div class="user-item">
195- <img src=${ buildfire . auth . getUserPictureUrl ( { userId : user . _id } ) } class="avatar" onerror="this.src=window._appRoot+'media/avatar.png'"/>
196+ <img alt=" ${ user . displayName } " src=${ buildfire . auth . getUserPictureUrl ( { userId : user . _id } ) } class="avatar" onerror="this.src=window._appRoot+'media/avatar.png'"/>
196197 <p class="ellipsis margin-bottom-zero">${ user . displayName } </p>
197198 </div>
198199 ` ;
199- } )
200- . join ( '' ) }
200+ } )
201+ . join ( '' ) }
201202 </div>
202203 <style>
203204 .user-container{
@@ -230,12 +231,15 @@ function listCtrl($scope) {
230231 } ) ;
231232 } ;
232233
233- $scope . upVote = function ( suggestionObj ) {
234- getUser ( function ( user ) {
234+ $scope . upVote = function ( suggestionObj ) {
235+ getUser ( function ( user ) {
235236 if ( ! suggestionObj . data . upVotedBy ) suggestionObj . data . upVotedBy = { } ;
236237 if ( ! suggestionObj . data . upVoteCount ) suggestionObj . data . upVoteCount = 1 ;
237238
238239 if ( ! suggestionObj . data . upVotedBy [ user . _id ] ) {
240+ // vote
241+ Analytics . trackAction ( analyticKeys . VOTE_NUMBER . key , { votes : 1 , _buildfire : { aggregationValue : 1 } } ) ;
242+
239243 suggestionObj . data . upVoteCount ++ ;
240244 suggestionObj . disableUpvote = true ;
241245 suggestionObj . data . upVotedBy [ user . _id ] = {
@@ -250,13 +254,15 @@ function listCtrl($scope) {
250254 text : user . displayName + ' upvoted your suggestion ' + suggestionObj . data . title ,
251255 users : [ suggestionObj . data . createdBy . _id ]
252256 } ,
253- function ( err ) {
257+ function ( err ) {
254258 if ( err ) console . error ( err ) ;
255259 }
256260 ) ;
257261 }
258262 } else {
259263 // unvote
264+ Analytics . trackAction ( analyticKeys . VOTE_NUMBER . key , { votes : - 1 , _buildfire : { aggregationValue : - 1 } } ) ;
265+
260266 suggestionObj . data . upVoteCount -- ;
261267 suggestionObj . disableUpvote = false ;
262268 delete suggestionObj . data . upVotedBy [ user . _id ] ;
@@ -267,14 +273,14 @@ function listCtrl($scope) {
267273 suggestionObj . data . upVoteCount = Object . keys ( suggestionObj . data . upVotedBy ) . length ;
268274 }
269275
270- buildfire . publicData . update ( suggestionObj . id , suggestionObj . data , 'suggestion' , function ( err ) {
276+ buildfire . publicData . update ( suggestionObj . id , suggestionObj . data , 'suggestion' , function ( err ) {
271277 if ( err ) console . error ( err ) ;
272278 } ) ;
273279 } ) ;
274280 } ;
275281}
276- upvoteApp . filter ( 'getUserImage' , function ( ) {
277- return function ( user ) {
282+ upvoteApp . filter ( 'getUserImage' , function ( ) {
283+ return function ( user ) {
278284 var url = './avatar.png' ;
279285 if ( user ) {
280286 url = buildfire . auth . getUserPictureUrl ( { userId : user . _id } ) ;
@@ -289,52 +295,54 @@ function suggestionBoxCtrl($scope, $sce, $rootScope) {
289295 $scope . popupOn = false ;
290296 $scope . text = $sce . trustAsHtml ( config . text ) ;
291297
292- window . openPopup = function ( ) {
298+ window . openPopup = function ( ) {
293299 $scope . popupOn = true ;
294300 if ( ! $scope . $$phase ) $scope . $apply ( ) ;
295301 } ;
296302
297- buildfire . datastore . get ( function ( err , obj ) {
303+ buildfire . datastore . get ( function ( err , obj ) {
298304 if ( obj ) config = obj . data ;
299305 $scope . text = $sce . trustAsHtml ( config . text ) ;
300306 } ) ;
301307
302- buildfire . datastore . onUpdate ( function ( obj ) {
308+ buildfire . datastore . onUpdate ( function ( obj ) {
303309 if ( obj ) config = obj . data ;
304310 $scope . text = $sce . trustAsHtml ( config . text ) ;
305311 if ( ! $scope . $$phase ) $scope . $apply ( ) ;
306312 } ) ;
307313
308- $scope . clearForm = function ( ) {
314+ $scope . clearForm = function ( ) {
309315 $scope . suggestionTitle = '' ;
310316 $scope . suggestionText = '' ;
311317 $scope . suggestionForm . $setUntouched ( ) ;
312318 $scope . popupOn = false ;
313319 } ;
314320
315- $scope . closeForm = function ( ) {
321+ $scope . closeForm = function ( ) {
316322 $scope . popupOn = false ;
317323 } ;
318324
319- $scope . addSuggestion = function ( ) {
325+ $scope . addSuggestion = function ( ) {
326+
320327 if ( $scope . suggestionForm . $invalid ) {
321328 $scope . suggestionForm . suggestionTitle . $setTouched ( ) ;
322329 $scope . suggestionForm . suggestionText . $setTouched ( ) ;
323330 return ;
324331 }
325332
326- getUser ( function ( user ) {
333+ getUser ( function ( user ) {
327334 _addSuggestion ( user , $scope . suggestionTitle , $scope . suggestionText ) ;
328335 $scope . popupOn = false ;
329336
337+ Analytics . trackAction ( analyticKeys . SUGGESTIONS_NUMBER . key , { _buildfire : { aggregationValue : 1 } } ) ;
330338 buildfire . notifications . pushNotification . schedule (
331339 {
332340 title : 'New suggestion by ' + user . displayName ,
333341 text : $scope . suggestionTitle ,
334342 //,at: new Date()
335343 groupName : 'suggestions'
336344 } ,
337- function ( err ) {
345+ function ( err ) {
338346 if ( err ) console . error ( err ) ;
339347 }
340348 ) ;
@@ -360,7 +368,7 @@ function suggestionBoxCtrl($scope, $sce, $rootScope) {
360368 user : user
361369 } ;
362370
363- buildfire . publicData . insert ( obj , 'suggestion' , function ( err , obj ) {
371+ buildfire . publicData . insert ( obj , 'suggestion' , function ( err , obj ) {
364372 $rootScope . $broadcast ( 'suggestionAdded' , obj ) ;
365373 } ) ;
366374 }
0 commit comments