Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 7870d02

Browse files
committed
Merge pull request #33 from appirio-tech/vikas-sup-20-mergedesigndashboard
SUP-20,Merge My Dashboard UI Design with Functional Pages
2 parents 7bdb183 + a7cda39 commit 7870d02

File tree

11 files changed

+151
-72
lines changed

11 files changed

+151
-72
lines changed

src/js/app/my-dashboard/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
.module('myDashboard', [
1212
'ngRoute',
1313
'restangular',
14+
'angular-storage',
1415
'ngCookies',
1516
'myDashboard.services'
1617
])
@@ -35,7 +36,6 @@
3536
if (AuthService.validate()) {
3637
// nothing to do, valid user
3738
} else {
38-
console.log(event);
3939
$returnUrl = $location.absUrl();
4040
event.preventDefault();
4141
$window.location.href = tcconfig.mainURL + "/login?next=" + $returnUrl;

src/js/app/my-dashboard/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@@header
22

3-
<div ng-show="vm.loggedIn">
3+
<div ng-show="vm.loggedIn && vm.user">
44
<style>
55
/* CSS to override bootstrap and existing css conflicts*/
66
.btn, a.btn{

src/js/app/my-dashboard/js/controllers/my-dashboard-controller.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,44 @@
1818
* Inject dependencies
1919
* @type {string[]}
2020
*/
21-
MyDashboardCtrl.$inject = ['$scope', '$location', 'AuthService'];
21+
MyDashboardCtrl.$inject = ['$scope', '$location', 'store', 'AuthService', 'ProfileService'];
2222

2323
/**
2424
* Controller implementation
2525
*
2626
* @param $scope
2727
* @constructor
2828
*/
29-
function MyDashboardCtrl($scope, $location, AuthService) {
29+
function MyDashboardCtrl($scope, $location, store, AuthService, ProfileService) {
3030
var vm = this;
3131
vm.title = "My Dashboard";
32+
vm.user = null;
3233
vm.loggedIn = AuthService.validate();
3334
vm.getTemplateURL = getTemplateURL;
35+
vm.addIdentityChangeListener = addIdentityChangeListener;
36+
vm.removeIdentityChangeListener = removeIdentityChangeListener;
3437

3538
// activate controller
3639
activate();
3740

3841
function activate() {
39-
// nothing to do yet
42+
// try to get user's identity from browser (local storage or cookie)
43+
vm.user = ProfileService.getLocalIdentity();
44+
if (!vm.user) { // if identity not found in browser, fetch it from api
45+
if (AuthService.isLoggedIn) {
46+
ProfileService.getIdentity().then(function(data) {
47+
vm.user = data;
48+
vm.loading = false;
49+
// call all identity change listeners
50+
for (var name in idenityListeners) {
51+
var listener = idenityListeners[name];
52+
if (typeof listener == 'function') {
53+
listener.call(data);
54+
}
55+
};
56+
});
57+
}
58+
}
4059
}
4160

4261
/**
@@ -49,6 +68,33 @@
4968
return base_url + '/js/app/my-dashboard/partials/' + template;
5069
}
5170

71+
// stores all listeners for identity change
72+
var idenityListeners = {};
73+
74+
/**
75+
* Adds the provided listener for identity change event. If listener already exists, it does not update it.
76+
* Caller has to remove it first and then add new one in such cases.
77+
*
78+
* @param name String name of the listener, it is used to uniquely identify a listener
79+
* @param listener function callback to be called when identity change happens
80+
*/
81+
function addIdentityChangeListener(name, listener) {
82+
if (!idenityListeners[name]) {
83+
idenityListeners[name] = listener;
84+
}
85+
}
86+
87+
/**
88+
* Removes the listener, identified by given name, for identity change event.
89+
*
90+
* @param name String name of the listener, it is used to uniquely identify a listener
91+
*/
92+
function removeIdentityChangeListener(name) {
93+
if (idenityListeners[name]) {
94+
delete idenityListeners[name];
95+
}
96+
}
97+
5298
}
5399

54100

src/js/app/my-dashboard/js/controllers/subscribe-updates-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
3-
* @author vikas
3+
* @author vikas.agarwal@appirio.com
44
* @version 1.0
55
*
66
* Controller for subscribe for updates widget

src/js/app/my-dashboard/js/controllers/welcome-back-controller.js

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
* @author mdesiderio
4+
* @author vikas.agarwal@appirio.com
45
* @version 1.0
56
*
67
* Controller for the welcome back widget
@@ -43,78 +44,84 @@
4344
// count of member stats/metrices to be shown in profile header
4445
vm.statsToShow = 2;
4546

47+
// parent dashboard controller
48+
var db = $scope.$parent.vm;
49+
4650
// activate controller
4751
if (AuthService.isLoggedIn === true) {
48-
activate();
52+
db.addIdentityChangeListener("welcomeback", function(identity) {
53+
activate();
54+
});
55+
if (db.user) {
56+
activate();
57+
}
4958
} else { // if user is not logged in, return (to avoid extra ajax calls)
5059
return false;
5160
}
5261

5362
function activate() {
54-
// fetch user info to get handle
55-
app.getHandle(function() {
56-
ProfileService.getUserProfile(app.handle)
57-
.then(function(profile) {
58-
vm.profile = profile;
59-
60-
var highestRating = 0;
61-
62-
// Find user's highest rating to set color to the handle
63-
angular.forEach(vm.profile.ratingSummary, function(value, key) {
64-
if (highestRating < value.rating) {
65-
highestRating = value.rating;
66-
vm.ratingColor = value.colorStyle;
67-
}
68-
});
69-
70-
vm.showUploadPhotoLink = false;
71-
// Parse user picture link to build photo url
72-
if (profile && profile.photoLink) {
73-
if (profile.photoLink.indexOf('//') != -1){
74-
vm.photoLink = profile.photoLink;
75-
} else {
76-
vm.photoLink = PHOTO_LINK_LOCATION + profile.photoLink;
77-
}
78-
} else {
79-
vm.photoLink = PHOTO_LINK_LOCATION + '/i/m/nophoto_login.gif';
80-
vm.uploadPhotoLink = $location.protocol + ":" + communityBaseUrl + '/tc?module=MyHome';
81-
vm.showUploadPhotoLink = true;
63+
// fetch user info
64+
ProfileService.getUserProfile(db.user.handle)
65+
.then(function(profile) {
66+
vm.profile = profile;
67+
68+
var highestRating = 0;
69+
70+
// Find user's highest rating to set color to the handle
71+
angular.forEach(vm.profile.ratingSummary, function(value, key) {
72+
if (highestRating < value.rating) {
73+
highestRating = value.rating;
74+
vm.ratingColor = value.colorStyle;
8275
}
76+
});
8377

84-
// calculates the count of metrices to be shown in profile header
85-
if (vm.profile.overallEarning > 0) { // earnings should be shown
86-
vm.statsToShow = 3;
87-
} else { // earnings should not be shown
88-
vm.statsToShow = 2;
78+
vm.showUploadPhotoLink = false;
79+
// Parse user picture link to build photo url
80+
if (profile && profile.photoLink) {
81+
if (profile.photoLink.indexOf('//') != -1){
82+
vm.photoLink = profile.photoLink;
83+
} else {
84+
vm.photoLink = PHOTO_LINK_LOCATION + profile.photoLink;
8985
}
86+
} else {
87+
vm.photoLink = PHOTO_LINK_LOCATION + '/i/m/nophoto_login.gif';
88+
vm.uploadPhotoLink = $location.protocol + ":" + communityBaseUrl + '/tc?module=MyHome';
89+
vm.showUploadPhotoLink = true;
90+
}
91+
92+
// calculates the count of metrices to be shown in profile header
93+
if (vm.profile.overallEarning > 0) { // earnings should be shown
94+
vm.statsToShow = 3;
95+
} else { // earnings should not be shown
96+
vm.statsToShow = 2;
97+
}
98+
99+
});
100+
101+
// Get active challenges in ordor to populate user's active challenges and review opportunities
102+
ChallengeService.getMyActiveChallenges()
103+
.then(function(data) {
104+
console.log(data);
105+
106+
vm.myActiveChallenges = data;
107+
108+
var ctOpenChallenges = 0;
109+
var ctReviewChallenges = 0;
110+
111+
angular.forEach(vm.myActiveChallenges, function(challenge) {
112+
if(challenge.roles && challenge.roles.indexOf("Submitter") != -1) {
113+
ctOpenChallenges++
114+
}
115+
116+
if(challenge.roles && challenge.roles.indexOf("Reviewer") != -1) {
117+
ctReviewChallenges++
118+
}
119+
});
90120

121+
vm.myOpenChallengesCount = ctOpenChallenges;
122+
vm.reviewOpportunities = ctReviewChallenges;
123+
console.log(vm);
91124
});
92-
93-
// Get active challenges in ordor to populate user's active challenges and review opportunities
94-
ChallengeService.getMyActiveChallenges()
95-
.then(function(data) {
96-
console.log(data);
97-
98-
vm.myActiveChallenges = data;
99-
100-
var ctOpenChallenges = 0;
101-
var ctReviewChallenges = 0;
102-
103-
angular.forEach(vm.myActiveChallenges, function(challenge) {
104-
if(challenge.roles && challenge.roles.indexOf("Submitter") != -1) {
105-
ctOpenChallenges++
106-
}
107-
108-
if(challenge.roles && challenge.roles.indexOf("Reviewer") != -1) {
109-
ctReviewChallenges++
110-
}
111-
});
112-
113-
vm.myOpenChallengesCount = ctOpenChallenges;
114-
vm.reviewOpportunities = ctReviewChallenges;
115-
console.log(vm);
116-
});
117-
});
118125
}
119126

120127
}

src/js/app/my-dashboard/js/lib/angular-storage.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/app/my-dashboard/js/services/profile-services.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
.module('myDashboard.services')
1212
.factory('ProfileService', ProfileService);
1313

14-
ProfileService.$inject = ['Restangular'];
14+
ProfileService.$inject = ['Restangular', 'store'];
1515

1616
/**
1717
* SRMService
1818
* @param Restangular to access the REST api
1919
* @constructor
2020
*/
21-
function ProfileService(Restangular) {
21+
function ProfileService(Restangular, store) {
2222
var service = Restangular.withConfig(function(RestangularConfigurer) {
2323
});
2424

@@ -39,6 +39,18 @@
3939
return service.one("user").one("identity").get();
4040
}
4141

42+
service.getLocalIdentity = function() {
43+
var identity = store.get("userIdentity");
44+
if (!identity) {
45+
var $cookies;
46+
angular.injector(['ngCookies']).invoke(function(_$cookies_) {
47+
$cookies = _$cookies_;
48+
});
49+
identity = $cookies["userIdentity"];
50+
}
51+
return identity;
52+
}
53+
4254
return service;
4355
}
4456
})();

src/js/app/my-dashboard/partials/welcome-back.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
<div class="profile-image"><img width="130px" src="{{vm.photoLink}}"></div>
44
<div rel="upload-photo" ng-show="vm.showUploadPhotoLink"><a href="{{vm.uploadPhotoLink}}">Upload Photo</a></div>
55
<div class="handle" style="{{vm.ratingColor}}">[{{vm.profile.handle}}]</div>
6-
<div class="doj">Joined: {{vm.profile.memberSince | date}}</div>
6+
<div class="doj">Joined: <span ng-bind="vm.profile.memberSince | date"></span></div>
77
</div>
88
<div class="profile-right col-xs-12 col-sm-10">
99
<div class="col-xs-{{12/vm.statsToShow}}" ng-show="vm.profile && vm.profile.overallEarning > 0">
1010
<div class="money-in-bank">
11-
<div rel="value">{{vm.profile.overallEarning || 0 | currency}}</div>
11+
<div rel="value" ng-bind="vm.profile.overallEarning || 0 | currency"></div>
1212
<div rel="label">Money in Bank</div>
1313
</div>
1414
</div>
1515
<div class="col-xs-{{12/vm.statsToShow}}">
1616
<div class="open-challenges">
17-
<div rel="value">{{vm.myOpenChallengesCount || 0}}</div>
17+
<div rel="value" ng-bind="vm.myOpenChallengesCount || 0"></div>
1818
<div rel="label">Open Challenges</div>
1919
</div>
2020
</div>
2121
<div class="col-xs-{{12/vm.statsToShow}}">
2222
<div class="review-opportunities">
23-
<div rel="value">{{vm.reviewOpportunities || 0}}</div>
23+
<div rel="value" ng-bind="vm.reviewOpportunities || 0"></div>
2424
<div rel="label">Review Opportunities</div>
2525
</div>
2626
</div>

src/js/init-header.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,12 @@ function initMemberDetails(pagePersisted){
12621262
$('.logoutLink, .actionLogout').click(function() {
12631263
document.cookie = 'tcsso=; path=/; domain=.' + tcconfig.domain + '; expires=' + new Date(0).toUTCString();
12641264
document.cookie = 'tcjwt=; path=/; domain=.' + tcconfig.domain + '; expires=' + new Date(0).toUTCString();
1265+
// SUP-20 // removes identity stored in local storage or cookie
1266+
if (window.localStorage) {
1267+
window.localStorage.removeItem("userIdentity");
1268+
} else {
1269+
$.removeCookie("userIdentity");
1270+
}
12651271
// check if we have the weird facebook hash
12661272
// if so, redirect to root
12671273
if (window.location.hash == '#_=_') {

src/js/scripts.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,12 @@ var app = {
17341734
'Authorization': 'Bearer ' + tcjwt
17351735
},
17361736
success: function(data) {
1737+
// SUP-20 // stores user identity in local storage or cookie
1738+
if (window.localStorage) {
1739+
window.localStorage.setItem("userIdentity", JSON.stringify(data));
1740+
} else {
1741+
$.cookie("userIdentity", JSON.stringify(data));
1742+
}
17371743
if (_kmq) _kmq.push(['identify', data.email]);
17381744
self.handle = data.handle;
17391745
callback(self.handle);

0 commit comments

Comments
 (0)