Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
[#00] fix (user.search) -> show correct match factor for interested u…
Browse files Browse the repository at this point in the history
…ser and prevent duplication of users
  • Loading branch information
Duc Anh Phi committed Feb 3, 2017
1 parent e9c4ab5 commit fe6e0ac
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions assets/app/authenticated/userSearch/user.search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { UserSearchService } from '../../_services/user.search.service';

export class UserSearchComponent implements OnInit {
@Input() requiredSkills;
@Input() interestedUsers;
users: User[];
@Input() interestedUsers: any[];
users: any[];
visibleUsers: any[] = [];
hiddenUsers: any[] = [];
searchText;
Expand All @@ -27,8 +27,16 @@ export class UserSearchComponent implements OnInit {
this.userService.getUsers()
.subscribe(
users => {
this.users = users as User[];
this.visibleUsers = users as any[];
this.users = users as any[];
this.visibleUsers = [];
outer: for(let user of this.users) {
for(let interested of this.interestedUsers) {
if(interested._id.localeCompare(user._id)===0) {
continue outer;
}
}
this.visibleUsers.push(user);
}
this.sortUsers();
this.retrieveImgURLs();
},
Expand Down Expand Up @@ -75,7 +83,7 @@ export class UserSearchComponent implements OnInit {
}

reset() {
this.visibleUsers = new Array<User>();
this.visibleUsers = new Array<any>();
this.visibleUsers.push(...this.users);
this.sortUsers();
}
Expand All @@ -93,13 +101,19 @@ export class UserSearchComponent implements OnInit {
}

calculateMatch(requiredSkills: Skill[]){
function doCalculation(users) {
function doCalculation(users, interested) {
for(let user of users) {
user.match = 0;
if(requiredSkills.length > 0) {
for(let userSkill of user.userSkills) {
for(let reqSkill of requiredSkills) {
if(userSkill.skill._id === reqSkill._id) {
var expression;
if(interested) {
expression = userSkill.skill === reqSkill._id;
} else {
expression = userSkill.skill._id === reqSkill._id
}
if(expression) {
switch(userSkill.rating){
case 0: user.match += 0.25;
break;
Expand All @@ -116,10 +130,10 @@ export class UserSearchComponent implements OnInit {
}
}
}
doCalculation(this.visibleUsers);
doCalculation(this.visibleUsers, false);

if(this.interestedUsers) {
doCalculation(this.interestedUsers);
doCalculation(this.interestedUsers, true);
}
this.sortUsers();
}
Expand Down

0 comments on commit fe6e0ac

Please sign in to comment.