Browse Source

Fin de la Filters Class

merge-requests/3/head
JamesRezo 4 years ago
parent
commit
2c23495d68
  1. 2
      css/supported-versions.css
  2. 12
      modeles/supportedversions_calendar.html
  3. 158
      supportedversions_fonctions.php
  4. 8
      supportedversions_options.php

2
css/supported-versions.css

@ -1,7 +1,7 @@
/* Branches page */
table.supportedversions tr.eol td:first-child {
background: #e29ea2;
background: #930000;
color: white;
}

12
modeles/supportedversions_calendar.html

@ -75,16 +75,16 @@
<!-- Branch blocks -->
<g class="supver_branches">
<BOUCLE_active_branches_2(DATA){source json, #CHEMIN{data/releases.json}}>[(#EOL|>={#DATE}|ou{#EOL|intval|non})
<rect class="supver_stable" x="[(#INITIAL_RELEASE|supver_horiz_coord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#ACTIVE_SUPPORT|supver_horiz_coord|strmoins{#INITIAL_RELEASE|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<rect class="supver_security" x="[(#ACTIVE_SUPPORT|supver_horiz_coord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#EOL|supver_horiz_coord|strmoins{#ACTIVE_SUPPORT|supver_horiz_coord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />]
<rect class="supver_stable" x="[(#INITIAL_RELEASE|SupportedVersions::horizCoord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#ACTIVE_SUPPORT|SupportedVersions::horizCoord|strmoins{#INITIAL_RELEASE|SupportedVersions::horizCoord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />
<rect class="supver_security" x="[(#ACTIVE_SUPPORT|SupportedVersions::horizCoord)]" y="[(#BRANCH|SupportedVersions::top)]" width="[(#EOL|SupportedVersions::horizCoord|strmoins{#ACTIVE_SUPPORT|SupportedVersions::horizCoord})]" height="#SUPPORTED_VERSIONS{svg/branch_height}" />]
</BOUCLE_active_branches_2>
</g>
<!-- Year lines -->
<g class="supver_years">
<BOUCLE_years(DATA){source table, #NULL|years}>
<line x1="[(#VALEUR|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header_height}" x2="[(#VALEUR|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#VALEUR|supver_horiz_coord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|mult{0.8})]">
<line x1="[(#VALEUR|SupportedVersions::horizCoord)]" y1="#SUPPORTED_VERSIONS{svg/header_height}" x2="[(#VALEUR|SupportedVersions::horizCoord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#VALEUR|SupportedVersions::horizCoord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|mult{0.8})]">
[(#VALEUR|affdate{M Y})]
</text>
</BOUCLE_years>
@ -92,8 +92,8 @@
<!-- Today -->
<g class="supver_today">
<line x1="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y1="#SUPPORTED_VERSIONS{svg/header}" x2="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#DATE|affdate{Y-m-d}|supver_horiz_coord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height|strplus{#SUPPORTED_VERSIONS{svg/footer_height}|mult{0.8}})]">
<line x1="[(#DATE|affdate{Y-m-d}|SupportedVersions::horizCoord)]" y1="#SUPPORTED_VERSIONS{svg/header}" x2="[(#DATE|affdate{Y-m-d}|SupportedVersions::horizCoord)]" y2="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]" />
<text x="[(#DATE|affdate{Y-m-d}|SupportedVersions::horizCoord)]" y="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height|strplus{#SUPPORTED_VERSIONS{svg/footer_height}|mult{0.8}})]">
[<:info_aujourdhui:> (#DATE|affdate)]
</text>
</g>

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

158
supportedversions_fonctions.php

@ -18,11 +18,72 @@ function balise_SUPPORTED_VERSIONS_dist($p) {
return balise_ENV_dist($p, '$GLOBALS["supportedversions"]');
}
// Supported Versions filters class
/**
* Supported Versions filters class.
*/
class SupportedVersions
{
private static $config = null;
private static $now;
private static $minDate;
private static $maxDate;
private static $years;
private static $branches;
protected static function init() {
self::$config = $GLOBALS['supportedversions'];
self::$now = new DateTime;
self::$minDate = (new DateTime('January 1'))->sub(new DateInterval(self::$config['calendar']['min_year']));
self::$maxDate = (new DateTime('January 1'))->add(new DateInterval(self::$config['calendar']['max_year']));
self::$years = array_map(
function ($year) {
return $year->format('Y-m-d');
},
iterator_to_array(new DatePeriod(self::$minDate, new DateInterval('P1Y'), self::$maxDate))
);
self::$branches = array_map(
function ($branch) {
return $branch['branch'];
},
json_decode(file_get_contents(find_in_path('data/releases.json')), true)
);
}
//Calendar Part
protected static function dateHorizCoord(DateTime $date) {
if (!self::$config) {
self::init();
}
$diff = $date->diff(self::$minDate);
if (!$diff->invert) {
return self::$config['svg']['margin_left'];
}
return self::$config['svg']['margin_left'] +
($diff->days / (365.24 / self::$config['svg']['year_width']));
}
public static function years() {
if (!self::$config) {
self::init();
}
return self::$years;
}
public static function horizCoord($date) {
if ($date) {
return self::dateHorizCoord(date_create_from_format('Y-m-d', $date));
}
return self::dateHorizCoord(self::$maxDate);
}
//SVG Part
public static function state(array $valeurs) {
$now = new DateTime;
$initial = new DateTime($valeurs['initial_release']);
@ -43,97 +104,46 @@ class SupportedVersions
}
public static function top($branch) {
global $supportedversions;
if (!self::$config) {
self::init();
}
$i = array_search($branch, branches(), true);
$i = array_search($branch, self::$branches, true);
return $supportedversions['svg']['header_height'] + ($supportedversions['svg']['branch_height'] * $i++);
return self::$config['svg']['header_height'] + (self::$config['svg']['branch_height'] * $i++);
}
public static function topForText($branch) {
global $supportedversions;
if (!self::$config) {
self::init();
}
$top = self::top($branch) + (0.5 * $supportedversions['svg']['branch_height']);
$top = self::top($branch) + (0.5 * self::$config['svg']['branch_height']);
return $top;
}
public static function width($margin_left) {
global $supportedversions;
if (!self::$config) {
self::init();
}
return $margin_left +
$supportedversions['svg']['margin_right'] +
((count(years()) - 1) * $supportedversions['svg']['year_width']);
self::$config['svg']['margin_right'] +
((count(years()) - 1) * self::$config['svg']['year_width']);
}
public static function height($header_height) {
global $supportedversions;
if (!self::$config) {
self::init();
}
return $header_height +
$supportedversions['svg']['footer_height'] +
(count(branches()) * $supportedversions['svg']['branch_height']);
self::$config['svg']['footer_height'] +
(count(self::$branches) * self::$config['svg']['branch_height']);
}
}
function supver_min_date() {
$now = new DateTime('January 1');
return $now->sub(new DateInterval('P3Y'));
}
function supver_max_date() {
$now = new DateTime('January 1');
return $now->add(new DateInterval('P5Y'));
}
function supver_date_horiz_coord(DateTime $date) {
global $supportedversions;
$diff = $date->diff(supver_min_date());
if (!$diff->invert) {
return $supportedversions['svg']['margin_left'];
}
return $supportedversions['svg']['margin_left'] +
($diff->days / (365.24 / $supportedversions['svg']['year_width']));
}
function supver_horiz_coord($date) {
if ($date) {
return supver_date_horiz_coord(date_create_from_format('Y-m-d', $date));
}
//return '';
return supver_date_horiz_coord(supver_max_date());
}
function years() {
static $years = [];
if (empty($years)) {
$years = array_map(
function ($year) {
return $year->format('Y-m-d');
},
iterator_to_array(new DatePeriod(supver_min_date(), new DateInterval('P1Y'), supver_max_date()))
);
}
return $years;
}
function branches() {
static $branches = [];
if (empty($branches)) {
$branches = array_map(
function ($branch) {
return $branch['branch'];
},
json_decode(file_get_contents(find_in_path('data/releases.json')), true)
);
}
return $branches;
return SupportedVersions::years();
}

8
supportedversions_options.php

@ -21,8 +21,12 @@ $GLOBALS['supportedversions'] = [
'background' => '#fceaae',
],
'eol' => [
'background' => '#e29ea2',
'background' => '#930000',
'color' => 'white',
],
]
],
'calendar' => [
'min_year' => 'P3Y',
'max_year' => 'P5Y',
],
];

Loading…
Cancel
Save