Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUT-28884: Add a filter on the "Favorites Management" page #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ manage_favorites.activated=Favori enabled
manage_favorites.desactivated=Favori disabled
manage_favorites.default=Default favorite
manage_favorites.not_default=Non default favorite
manage_favorites.filter.label=Filter by category
manage_favorites.filter.btn=Filter
import_favorites.title=Import favorites
import_favorites.label=Favorite label
import_favorites.url=Favorite url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ manage_favorites.activated=Favori activ\u00e9
manage_favorites.default=Favori par d\u00e9faut
manage_favorites.not_default=Favori non cr\u00e9\u00e9 par d\u00e9faut
manage_favorites.desactivated=Favori d\u00e9sactiv\u00e9
manage_favorites.filter.label=Filtrer par rubrique sectorielle
manage_favorites.filter.btn=Filtrer
import_favorites.title=Importer des favoris
import_favorites.label=Label du favori
import_favorites.url=Url du favori
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

Expand All @@ -77,6 +78,7 @@ public class FavoriteJspBean extends ManageFavoritesJspBean
// Parameters
private static final String PARAMETER_ID_FAVORITE = "id";
private static final String PARAMETER_IMPORT_FAVORITES = "import_favorites";
private static final String PARAMETER_CATEGORY_FILTER = "categoryFilter";

// Properties for page titles
private static final String PROPERTY_PAGE_TITLE_MANAGE_FAVORITES = "module.mydashboard.favorites.manage_favorites.pageTitle";
Expand All @@ -89,6 +91,8 @@ public class FavoriteJspBean extends ManageFavoritesJspBean
private static final String MARK_IMPORT_FAVORITES = "import_favorites";
private static final String MARK_CATEGORY_LIST = "category_list";
private static final String MARK_PICTOGRAMME = "pictogramme";
private static final String MARK_CATEGORY_FILTER = "categoryFilter";


private static final String JSP_MANAGE_FAVORITES = "jsp/admin/plugins/mydashboard/modules/favorites/ManageFavorites.jsp";

Expand Down Expand Up @@ -124,6 +128,9 @@ public class FavoriteJspBean extends ManageFavoritesJspBean
//Separators
private static final String SEPARATOR_IDENTIFIER = "_";

//CONSTANTS
private static final String CONSTANT_EMPTY = "empty";

// Session variable to store working values
private Favorite _favorite;

Expand All @@ -137,8 +144,25 @@ public String getManageFavorites( HttpServletRequest request )
{
_favorite = null;
List<Favorite> listFavorites = FavoriteHome.getFavoritesList( );

String strCategoryFilter = request.getParameter( PARAMETER_CATEGORY_FILTER );

if( StringUtils.isNotEmpty( strCategoryFilter ) && !strCategoryFilter.equals( CONSTANT_EMPTY ) && !strCategoryFilter.equals( "-1" ) )
{
listFavorites = listFavorites.stream( )
.filter( f -> f.getCategoryCode( ) != null && f.getCategoryCode( ).equalsIgnoreCase( strCategoryFilter ) )
.collect( Collectors.toList( ) );
}
else if ( StringUtils.isNotEmpty( strCategoryFilter ) && strCategoryFilter.equals( CONSTANT_EMPTY ) )
{
listFavorites = listFavorites.stream( )
.filter( f -> StringUtils.isEmpty(f.getCategoryCode( )) ).collect( Collectors.toList( ) );
}

Map<String, Object> model = getPaginatedListModel( request, MARK_FAVORITE_LIST, listFavorites, JSP_MANAGE_FAVORITES );

model.put( MARK_CATEGORY_LIST, getCategoryList( false ) );
model.put( MARK_CATEGORY_FILTER, strCategoryFilter );

return getPage( PROPERTY_PAGE_TITLE_MANAGE_FAVORITES, TEMPLATE_MANAGE_FAVORITES, model );
}

Expand All @@ -155,7 +179,7 @@ public String getCreateFavorite( HttpServletRequest request )

Map<String, Object> model = getModel( );
model.put( MARK_FAVORITE, _favorite );
model.put( MARK_CATEGORY_LIST, getCategoryList( ) );
model.put( MARK_CATEGORY_LIST, getCategoryList( true ) );

return getPage( PROPERTY_PAGE_TITLE_CREATE_FAVORITE, TEMPLATE_CREATE_FAVORITE, model );
}
Expand Down Expand Up @@ -262,7 +286,7 @@ public String getModifyFavorite( HttpServletRequest request )

Map<String, Object> model = getModel( );
model.put( MARK_FAVORITE, _favorite );
model.put( MARK_CATEGORY_LIST, getCategoryList( ) );
model.put( MARK_CATEGORY_LIST, getCategoryList( true ) );
FileImagePublicService.init( );

return getPage( PROPERTY_PAGE_TITLE_MODIFY_FAVORITE, TEMPLATE_MODIFY_FAVORITE, model );
Expand Down Expand Up @@ -379,11 +403,14 @@ public String doImportFavorites( HttpServletRequest request )
return redirectView( request, VIEW_MANAGE_FAVORITES );
}

private ReferenceList getCategoryList( )
private ReferenceList getCategoryList( boolean bAddDashItem )
{
ReferenceList referenceList = new ReferenceList( );

referenceList.addItem( -1, "-" );
if( bAddDashItem )
{
referenceList.addItem( -1, "-" );
}

for ( Category category : CategoryHome.getCategoriesList( ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ <h3 class="card-title">#i18n{module.mydashboard.favorites.manage_favorites.title
</@tform>
</div>
</div>
<@boxBody>
<@boxBody>
<@div class="col-12 col-lg-4">
<@tform name='filterFavorites' action='jsp/admin/plugins/mydashboard/modules/favorites/ManageFavorites.jsp'>
<label>#i18n{module.mydashboard.favorites.manage_favorites.filter.label}</label>
<@div class="d-flex">
<select name="categoryFilter" class="form-select">
<option value="-1" <#if categoryFilter?? && categoryFilter == '-1'>selected="selected"</#if>>-</option>
<option value="empty" <#if categoryFilter?? && categoryFilter == 'empty'>selected="selected"</#if>>Rubrique sectorielle vide</option>
<#if category_list?? && category_list?has_content>
<#list category_list as category>
<option value="${category.code}" <#if categoryFilter?? && categoryFilter == category.code>selected="selected"</#if>>${category.name}</option>
</#list>
</#if>
</select>
<@button type='submit' name='view_manageFavorites' title='#i18n{module.mydashboard.favorites.manage_favorites.filter.btn}' size='md' />
</@div>
</@tform>
</@div>
<@messages infos=infos />
<@paginationAdmin paginator=paginator combo=1 />
<@table>
Expand Down