Skip to content
Snippets Groups Projects
Commit 7d5240c2 authored by Andreas Schindlbeck's avatar Andreas Schindlbeck
Browse files

#1071409 Favorites: Refactor

parent cb0e43d2
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@ import("system.favorite");
import("system.tools");
import("system.entities");
/*
* loading favorites by id
*/
if(vars.get("$local.idvalues") && vars.get("$local.idvalues").length != 0)
{
var seekedByCore = vars.get("$local.idvalues");
......@@ -18,21 +21,35 @@ if(vars.get("$local.idvalues") && vars.get("$local.idvalues").length != 0)
result.object(seekedByCoreFavos);
}
/*
* loading and filtering by UI
*/
else
{
//save active filters and their logical operator
var filters = vars.get("$local.filter");
var activeFilters = [];
var logicalConnectionOperator;
if(filters["filter"] != null)
{
logicalConnectionOperator = filters["filter"]["operator"];
for(g = 0; g < filters["filter"]["childs"].length; g++)
activeFilters.push(filters["filter"]["childs"][g])
}
var finishedFavoritesForDisplay = [];
/*
* load all contexts and all favorites
*/
var allContexts = getAllFavoriteEnabledContexts();
var allFavorites = favorite.getFavorites(favorite.createGetFavoritesConfig()
.setUserId(tools.getCurrentUser()[tools.NAME]));
var allFavorites = favorite.getFavorites(favorite.createGetFavoritesConfig().setUserId(tools.getCurrentUser()[tools.NAME]));
/*
* complete-load (in buildFavorites) favorites by one context at a time
*/
for(i = 0; i < allContexts.length; i++)
{
var contextFavorites = [];
......@@ -45,7 +62,7 @@ else
for(let x = 0; x < builtFavos.length; x++)
{
var favo = builtFavos[x];
if(isFiltered(activeFilters, favo))
if(isFiltered(activeFilters, logicalConnectionOperator, favo))
finishedFavoritesForDisplay.push(favo);
}
}
......@@ -53,44 +70,46 @@ else
result.object(finishedFavoritesForDisplay);
}
function isFiltered(filters, fav)
function isFiltered(filters, logicalConnectionOperator, fav)
{
if(filters == null || filters.length == 0)
return true;
var favoObjectType = fav[3];
var favoGroupName = fav[1];
var favoRowId = fav[5];
var favoTitle = fav[6];
var isFiltered = true;
var allFilterFulfilled = true;
var oneFilterFulfilled = false;
for(let i = 0; i < filters.length; i++)
{
var attributeValue = "";
if(filters[i]["name"].includes("groupTypeExtension"))
{
if(!isValid(favoObjectType, filters[i]))
{
isFiltered = false;
break;
}
}
if(filters[i]["name"].includes("groupTitleExtension"))
{
if(!isValid(favoTitle, filters[i]))
{
isFiltered = false;
break;
}
}
if(filters[i]["name"].includes("groupGroupNameExtension"))
{
if(!isValid(favoGroupName, filters[i]))
{
isFiltered = false;
break;
}
}
attributeValue = favoObjectType;
else if(filters[i]["name"].includes("groupTitleExtension"))
attributeValue = favoTitle;
else if(filters[i]["name"].includes("groupGroupNameExtension"))
attributeValue = favoGroupName;
if(!isValid(attributeValue, filters[i]))
allFilterFulfilled = false;
else
oneFilterFulfilled = true;
}
return isFiltered;
if(logicalConnectionOperator == "AND")
if(allFilterFulfilled)
return true;
else
return false;
if(logicalConnectionOperator == "OR")
if(oneFilterFulfilled)
return true;
else
return false;
}
function isValid(value, filter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment