Improved categories sorting and center content.

This commit is contained in:
Christian P. MOMON 2020-09-25 06:01:22 +02:00
parent 53732f23af
commit 01df6b63c0
5 changed files with 194 additions and 28 deletions

View file

@ -19,6 +19,7 @@
package fr.devinsy.statoolinfos.core; package fr.devinsy.statoolinfos.core;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -72,4 +73,55 @@ public class Categories extends ArrayList<Category>
// //
return result; return result;
} }
/**
* Reverse.
*
* @return the categories
*/
public Categories reverse()
{
Categories result;
Collections.reverse(this);
result = this;
//
return result;
}
/**
* Sort.
*
* @param sorting
* the sorting
* @return the issues
*/
public Categories sort(final CategoryComparator.Sorting sorting)
{
Categories result;
sort(new CategoryComparator(sorting));
result = this;
//
return result;
}
/**
* Sort by name.
*
* @return the services
*/
public Categories sortByName()
{
Categories result;
result = sort(CategoryComparator.Sorting.NAME);
//
return result;
}
} }

View file

@ -0,0 +1,110 @@
/*
*
*/
package fr.devinsy.statoolinfos.core;
import java.util.Comparator;
import fr.devinsy.statoolinfos.util.CompareUtils;
/**
* The Class OrganizationComparator.
*/
public class CategoryComparator implements Comparator<Category>
{
public enum Sorting
{
NAME
}
private Sorting sorting;
/**
* Instantiates a new organization comparator.
*
* @param sorting
* the sorting
*/
public CategoryComparator(final Sorting sorting)
{
this.sorting = sorting;
}
/**
* Compare.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the int
*/
@Override
public int compare(final Category alpha, final Category bravo)
{
int result;
result = compare(alpha, bravo, this.sorting);
//
return result;
}
/**
* Compare.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @param sorting
* the sorting
* @return the int
*/
public static int compare(final Category alpha, final Category bravo, final Sorting sorting)
{
int result;
if (sorting == null)
{
result = 0;
}
else
{
switch (sorting)
{
default:
case NAME:
result = CompareUtils.compare(getName(alpha), getName(bravo));
break;
}
}
//
return result;
}
/**
* Gets the name.
*
* @param source
* the source
* @return the name
*/
public static String getName(final Category source)
{
String result;
if (source == null)
{
result = null;
}
else
{
result = source.getName();
}
//
return result;
}
}

View file

@ -84,6 +84,8 @@ public class Factory
result.add(category); result.add(category);
} }
result.sortByName();
// //
return result; return result;
} }
@ -105,7 +107,7 @@ public class Factory
result = loadCategories(source); result = loadCategories(source);
Category other = new Category("{Autres}", "Qui ne rentre pas dans une catégorie existante."); Category other = new Category("Autres", "Qui ne rentre pas dans une catégorie existante.");
result.add(other); result.add(other);
for (Service service : federation.getAllServices()) for (Service service : federation.getAllServices())

View file

@ -57,7 +57,7 @@ public class CategoriesPage
data.setContent("categoryCount", stats.size()); data.setContent("categoryCount", stats.size());
int index = 0; int index = 0;
for (CategoryStat stat : stats.sortByName()) for (CategoryStat stat : stats)
{ {
data.setEscapedContent("categoryListLine", index, "categoryListLineNameLink", stat.getCategory().getName()); data.setEscapedContent("categoryListLine", index, "categoryListLineNameLink", stat.getCategory().getName());
data.setAttribute("categoryListLine", index, "categoryListLineNameLink", "href", "category-" + stat.getCategory().getTechnicalName() + ".xhtml"); data.setAttribute("categoryListLine", index, "categoryListLineNameLink", "href", "category-" + stat.getCategory().getTechnicalName() + ".xhtml");

View file

@ -11,11 +11,12 @@
<script src="Chart.bundle.min.js"></script> <script src="Chart.bundle.min.js"></script>
</head> </head>
<body> <body>
<div class="center">
<h2>Catégories</h2> <h2>Catégories</h2>
<div>Nombre de catégories : <span id="categoryCount">n/a</span></div> <div>Nombre de catégories : <span id="categoryCount">n/a</span></div>
<div> <div class="left">
<table class="table_classic sortable"> <table class="table_classic center_table sortable" style="width: 900px; margin-left: auto; margin-right: auto;">
<thead> <thead>
<tr> <tr>
<th class="">Nom de la catégorie</th> <th class="">Nom de la catégorie</th>
@ -38,5 +39,6 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
</body> </body>
</html> </html>