Deep custom AngularJS Filter
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I need to filter projects using a searchbar, it should filter all properties of the projects with a few exceptions. It's working, but it's extremely slow, where can I make optimizations?
The "_" is from the library underscore.js
<div class="fixed-header">
<form>
<div class="form-group">
<input type="text" ng-model="searchText" class="form-control" placeholder="Suche..."/>
</div>
</form>
</div>
<ul>
<li class="initial"
ng-repeat-start="(customer, projectGroup) in projects | searchProjects:searchText">
customer
</li>
</ul>
Here's the filter:
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
var passFilter = projects.filter(p =>
let backUpContacts = false;
if (p)
//If project has customer and customer has references, don't search in all of them
if (p.kunde && p.kunde.contacts)
backUpContacts = p.kunde.contacts.concat();
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//Search also for project leaders that have to be found first
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
if (role.project === p.id)
let projectRole = role.masterData['Projektrolle'];
if (projectRole && ~projectRole.indexOf(864))
projectLeaders.push(profile.firstName + " " + profile.lastName);
);
);
p["projectLeaders"] = projectLeaders;
let pContain = _.contains($filter('filter')(projects, query), p);
delete p["projectLeaders"];
if (backUpContacts)
p.kunde.contacts = backUpContacts;
return pContain;
);
return passFilter;
;
)
javascript angular.js underscore.js
add a comment |Â
up vote
0
down vote
favorite
I need to filter projects using a searchbar, it should filter all properties of the projects with a few exceptions. It's working, but it's extremely slow, where can I make optimizations?
The "_" is from the library underscore.js
<div class="fixed-header">
<form>
<div class="form-group">
<input type="text" ng-model="searchText" class="form-control" placeholder="Suche..."/>
</div>
</form>
</div>
<ul>
<li class="initial"
ng-repeat-start="(customer, projectGroup) in projects | searchProjects:searchText">
customer
</li>
</ul>
Here's the filter:
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
var passFilter = projects.filter(p =>
let backUpContacts = false;
if (p)
//If project has customer and customer has references, don't search in all of them
if (p.kunde && p.kunde.contacts)
backUpContacts = p.kunde.contacts.concat();
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//Search also for project leaders that have to be found first
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
if (role.project === p.id)
let projectRole = role.masterData['Projektrolle'];
if (projectRole && ~projectRole.indexOf(864))
projectLeaders.push(profile.firstName + " " + profile.lastName);
);
);
p["projectLeaders"] = projectLeaders;
let pContain = _.contains($filter('filter')(projects, query), p);
delete p["projectLeaders"];
if (backUpContacts)
p.kunde.contacts = backUpContacts;
return pContain;
);
return passFilter;
;
)
javascript angular.js underscore.js
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to filter projects using a searchbar, it should filter all properties of the projects with a few exceptions. It's working, but it's extremely slow, where can I make optimizations?
The "_" is from the library underscore.js
<div class="fixed-header">
<form>
<div class="form-group">
<input type="text" ng-model="searchText" class="form-control" placeholder="Suche..."/>
</div>
</form>
</div>
<ul>
<li class="initial"
ng-repeat-start="(customer, projectGroup) in projects | searchProjects:searchText">
customer
</li>
</ul>
Here's the filter:
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
var passFilter = projects.filter(p =>
let backUpContacts = false;
if (p)
//If project has customer and customer has references, don't search in all of them
if (p.kunde && p.kunde.contacts)
backUpContacts = p.kunde.contacts.concat();
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//Search also for project leaders that have to be found first
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
if (role.project === p.id)
let projectRole = role.masterData['Projektrolle'];
if (projectRole && ~projectRole.indexOf(864))
projectLeaders.push(profile.firstName + " " + profile.lastName);
);
);
p["projectLeaders"] = projectLeaders;
let pContain = _.contains($filter('filter')(projects, query), p);
delete p["projectLeaders"];
if (backUpContacts)
p.kunde.contacts = backUpContacts;
return pContain;
);
return passFilter;
;
)
javascript angular.js underscore.js
I need to filter projects using a searchbar, it should filter all properties of the projects with a few exceptions. It's working, but it's extremely slow, where can I make optimizations?
The "_" is from the library underscore.js
<div class="fixed-header">
<form>
<div class="form-group">
<input type="text" ng-model="searchText" class="form-control" placeholder="Suche..."/>
</div>
</form>
</div>
<ul>
<li class="initial"
ng-repeat-start="(customer, projectGroup) in projects | searchProjects:searchText">
customer
</li>
</ul>
Here's the filter:
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
var passFilter = projects.filter(p =>
let backUpContacts = false;
if (p)
//If project has customer and customer has references, don't search in all of them
if (p.kunde && p.kunde.contacts)
backUpContacts = p.kunde.contacts.concat();
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//Search also for project leaders that have to be found first
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
if (role.project === p.id)
let projectRole = role.masterData['Projektrolle'];
if (projectRole && ~projectRole.indexOf(864))
projectLeaders.push(profile.firstName + " " + profile.lastName);
);
);
p["projectLeaders"] = projectLeaders;
let pContain = _.contains($filter('filter')(projects, query), p);
delete p["projectLeaders"];
if (backUpContacts)
p.kunde.contacts = backUpContacts;
return pContain;
);
return passFilter;
;
)
javascript angular.js underscore.js
edited Mar 2 at 17:47
200_success
123k14142399
123k14142399
asked Mar 2 at 17:26
Cold_Class
1033
1033
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I tried to improve it myself and it is much faster than before!
Here's my new code, feel free to comment on what can be further done to improve it.
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
//Create project leader search object
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
let projectRole = role.masterData['Projektrolle'];
//864 = Projectleader Tag ID
if (projectRole && ~projectRole.indexOf(864))
let projectLeader = profile.firstName + " " + profile.lastName;
if (projectLeaders.hasOwnProperty(role.project))
projectLeaders[role.project].push(projectLeader);
else
projectLeaders[role.project] = [projectLeader];
);
);
return projects.filter(p =>
//delete customers' contacts to exclude from search
if (p.kunde && p.kunde.contacts)
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//if project has leaders, add them to it for searching
if (projectLeaders.hasOwnProperty(p.id))
p["projectLeaders"] = projectLeaders[p.id];
return Boolean($filter('filter')([p], query).length);
);
;
)
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I tried to improve it myself and it is much faster than before!
Here's my new code, feel free to comment on what can be further done to improve it.
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
//Create project leader search object
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
let projectRole = role.masterData['Projektrolle'];
//864 = Projectleader Tag ID
if (projectRole && ~projectRole.indexOf(864))
let projectLeader = profile.firstName + " " + profile.lastName;
if (projectLeaders.hasOwnProperty(role.project))
projectLeaders[role.project].push(projectLeader);
else
projectLeaders[role.project] = [projectLeader];
);
);
return projects.filter(p =>
//delete customers' contacts to exclude from search
if (p.kunde && p.kunde.contacts)
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//if project has leaders, add them to it for searching
if (projectLeaders.hasOwnProperty(p.id))
p["projectLeaders"] = projectLeaders[p.id];
return Boolean($filter('filter')([p], query).length);
);
;
)
add a comment |Â
up vote
0
down vote
accepted
I tried to improve it myself and it is much faster than before!
Here's my new code, feel free to comment on what can be further done to improve it.
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
//Create project leader search object
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
let projectRole = role.masterData['Projektrolle'];
//864 = Projectleader Tag ID
if (projectRole && ~projectRole.indexOf(864))
let projectLeader = profile.firstName + " " + profile.lastName;
if (projectLeaders.hasOwnProperty(role.project))
projectLeaders[role.project].push(projectLeader);
else
projectLeaders[role.project] = [projectLeader];
);
);
return projects.filter(p =>
//delete customers' contacts to exclude from search
if (p.kunde && p.kunde.contacts)
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//if project has leaders, add them to it for searching
if (projectLeaders.hasOwnProperty(p.id))
p["projectLeaders"] = projectLeaders[p.id];
return Boolean($filter('filter')([p], query).length);
);
;
)
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I tried to improve it myself and it is much faster than before!
Here's my new code, feel free to comment on what can be further done to improve it.
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
//Create project leader search object
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
let projectRole = role.masterData['Projektrolle'];
//864 = Projectleader Tag ID
if (projectRole && ~projectRole.indexOf(864))
let projectLeader = profile.firstName + " " + profile.lastName;
if (projectLeaders.hasOwnProperty(role.project))
projectLeaders[role.project].push(projectLeader);
else
projectLeaders[role.project] = [projectLeader];
);
);
return projects.filter(p =>
//delete customers' contacts to exclude from search
if (p.kunde && p.kunde.contacts)
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//if project has leaders, add them to it for searching
if (projectLeaders.hasOwnProperty(p.id))
p["projectLeaders"] = projectLeaders[p.id];
return Boolean($filter('filter')([p], query).length);
);
;
)
I tried to improve it myself and it is much faster than before!
Here's my new code, feel free to comment on what can be further done to improve it.
.filter('searchProjects', ($rootScope, $filter) =>
return (projects, query) =>
if (projects)
//Create project leader search object
let projectLeaders = ;
$rootScope.profiles.forEach(profile =>
profile.projects.forEach(role =>
let projectRole = role.masterData['Projektrolle'];
//864 = Projectleader Tag ID
if (projectRole && ~projectRole.indexOf(864))
let projectLeader = profile.firstName + " " + profile.lastName;
if (projectLeaders.hasOwnProperty(role.project))
projectLeaders[role.project].push(projectLeader);
else
projectLeaders[role.project] = [projectLeader];
);
);
return projects.filter(p =>
//delete customers' contacts to exclude from search
if (p.kunde && p.kunde.contacts)
//Only leave the selected Reference Contact in Customer's Contacts for Search
p.kunde.contacts = p.kunde.contacts.filter(contact => p.reference === contact.id);
//if project has leaders, add them to it for searching
if (projectLeaders.hasOwnProperty(p.id))
p["projectLeaders"] = projectLeaders[p.id];
return Boolean($filter('filter')([p], query).length);
);
;
)
answered Mar 7 at 11:20
Cold_Class
1033
1033
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188689%2fdeep-custom-angularjs-filter%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password