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,32 +11,34 @@
<script src="Chart.bundle.min.js"></script> <script src="Chart.bundle.min.js"></script>
</head> </head>
<body> <body>
<h2>Catégories</h2> <div class="center">
<h2>Catégories</h2>
<div>Nombre de catégories : <span id="categoryCount">n/a</span></div>
<div> <div>Nombre de catégories : <span id="categoryCount">n/a</span></div>
<table class="table_classic sortable"> <div class="left">
<thead> <table class="table_classic center_table sortable" style="width: 900px; margin-left: auto; margin-right: auto;">
<tr> <thead>
<th class="">Nom de la catégorie</th> <tr>
<th class="">Logiciels</th> <th class="">Nom de la catégorie</th>
<th class="" style="width: 100px;">Services</th> <th class="">Logiciels</th>
<th class="" style="width: 100px;">Organizations</th> <th class="" style="width: 100px;">Services</th>
<th class="" style="width: 100px;">Utilisateurs mensuels</th> <th class="" style="width: 100px;">Organizations</th>
</tr> <th class="" style="width: 100px;">Utilisateurs mensuels</th>
</thead> </tr>
<tbody> </thead>
<tr id="categoryListLine"> <tbody>
<td id="categoryListLineName" style="padding-top: 0; padding-bottom: 0;"> <tr id="categoryListLine">
<a href="#" id="categoryListLineNameLink" title="categoryListLineNameDescription">n/a</a> <td id="categoryListLineName" style="padding-top: 0; padding-bottom: 0;">
</td> <a href="#" id="categoryListLineNameLink" title="categoryListLineNameDescription">n/a</a>
<td id="categoryListLineSoftwares">n/a</td> </td>
<td id="categoryListLineServiceCount" class="td_number">n/a</td> <td id="categoryListLineSoftwares">n/a</td>
<td id="categoryListLineOrganizationCount" class="td_number">n/a</td> <td id="categoryListLineServiceCount" class="td_number">n/a</td>
<td id="categoryListLineUserCount" class="td_number">n/a</td> <td id="categoryListLineOrganizationCount" class="td_number">n/a</td>
</tr> <td id="categoryListLineUserCount" class="td_number">n/a</td>
</tbody> </tr>
</table> </tbody>
</table>
</div>
</div> </div>
</body> </body>
</html> </html>