src/app/plugins/profile/components/profile-badge/profile-badge.component.ts
selector | app-profile-badge |
styleUrls | profile-badge.component.scss |
templateUrl | profile-badge.component.html |
constructor(resourceService: ResourceService, userService: UserService, badgeService: BadgesService, configService: ConfigService)
|
getBadgeData |
getBadgeData()
|
This method is used to fetch detailed badge data
Returns:
void
|
toggle |
toggle(viewMore: any)
|
This method is used to show/hide ViewMore based on the limit
Returns:
void
|
badgeArray |
badgeArray: |
Contains array of badges |
badgeService |
badgeService: |
configService |
configService: |
defaultLimit |
defaultLimit: |
Contains default limit to show awards |
limit |
limit: |
Used to store limit to show/hide awards |
resourceService |
resourceService: |
userProfile |
userProfile: |
Reference of User Profile interface |
userService |
userService: |
viewMore |
viewMore: |
Default value: true
|
Booloean value to hide/show awards |
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Component, OnInit } from '@angular/core';
import { ResourceService, ConfigService, ServerResponse, IUserProfile, IUserData } from '../../../../modules/shared';
import { UserService, BadgesService } from '../../../../modules/core/services';
import * as _ from 'lodash-es';
@Component({
selector: 'app-profile-badge',
templateUrl: './profile-badge.component.html',
styleUrls: ['./profile-badge.component.scss']
})
export class ProfileBadgeComponent implements OnInit {
/**
* Reference of User Profile interface
*/
userProfile: IUserProfile;
/**
* Booloean value to hide/show awards
*/
viewMore = true;
/**
* Contains default limit to show awards
*/
defaultLimit = this.configService.appConfig.PROFILE.defaultShowMoreLimit;
/**
* Used to store limit to show/hide awards
*/
limit = this.defaultLimit;
/**
* Contains array of badges
*/
badgeArray: any = [];
constructor(public resourceService: ResourceService, public userService: UserService,
public badgeService: BadgesService, public configService: ConfigService) { }
/**
* This method is used to call getBadgeData method
*/
ngOnInit() {
this.getBadgeData();
}
/**
* This method is used to fetch detailed badge data
*/
getBadgeData() {
this.userService.userData$.subscribe(
(user: IUserData) => {
if (user && !user.err && user.userProfile.badgeAssertions) {
this.userProfile = user.userProfile;
const badgeList = [];
_.each(this.userProfile.badgeAssertions, (badge) => {
badgeList.push(badge['badgeId']);
});
const req = {
request: {
filters: {
'badgeList': badgeList,
'type': 'user',
'rootOrgId': this.userProfile.rootOrgId
}
}
};
this.badgeArray = [];
this.badgeService.getDetailedBadgeAssertions(req, this.userProfile.badgeAssertions).subscribe((detailedAssertion) => {
if (detailedAssertion) {
this.badgeArray.push(detailedAssertion);
}
});
}
});
}
/**
* This method is used to show/hide ViewMore based on the limit
*/
toggle(viewMore) {
if (viewMore === true) {
this.limit = this.badgeArray.length;
this.viewMore = false;
} else {
this.viewMore = true;
this.limit = this.defaultLimit;
}
}
}