Skip to content

Commit

Permalink
Add support for badges.Use badges in match/matchgrids view
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Nov 5, 2021
1 parent 3f629d1 commit 744ba80
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 5 deletions.
57 changes: 57 additions & 0 deletions app/resources/locales/en_US/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -146,60 +146,117 @@ msgstr "{0,plural,=1{Pending Request} other{Pending Requests}}"
msgid "match.en.ConfidenceModeEnum.C"
msgstr "Canonical"

msgid "match.en.ConfidenceModeEnum.C.warn.level"
msgstr "Light"

msgid "match.en.ConfidenceModeEnum.P"
msgstr "Potential"

msgid "match.en.ConfidenceModeEnum.P.warn.level"
msgstr "Light"

msgid "match.en.ConfidenceModeEnum.S"
msgstr "Suspended"

msgid "match.en.ConfidenceModeEnum.S.warn.level"
msgstr "Danger"

msgid "match.en.PermissionEnum.A"
msgstr "Platform Administrator"

msgid "match.en.PermissionEnum.A.warn.level"
msgstr "Secondary"

msgid "match.en.PermissionEnum.MA"
msgstr "Matchgrid Administrator"

msgid "match.en.PermissionEnum.MA.warn.level"
msgstr "Light"

msgid "match.en.PermissionEnum.RM"
msgstr "Reconciliation Manager"

msgid "match.en.PermissionEnum.RM.warn.level"
msgstr "Light"

msgid "match.en.PermissionEnum.RS"
msgstr "Reconciliation Support"

msgid "match.en.PermissionEnum.RS.warn.level"
msgstr "Light"

msgid "match.en.PermissionEnum.X"
msgstr "None"

msgid "match.en.PermissionEnum.X.warn.level"
msgstr "Warning"

msgid "match.en.ReferenceIdEnum.S"
msgstr "Sequence"

msgid "match.en.ReferenceIdEnum.S.warn.level"
msgstr "Light"

msgid "match.en.ReferenceIdEnum.U"
msgstr "UUID (Type 4)"

msgid "match.en.ReferenceIdEnum.U.warn.level"
msgstr "Light"

msgid "match.en.ResolutionModeEnum.E"
msgstr "External"

msgid "match.en.ResolutionModeEnum.E.warn.level"
msgstr "Light"

msgid "match.en.ResolutionModeEnum.I"
msgstr "Interactive"

msgid "match.en.ResolutionModeEnum.I.warn.level"
msgstr "Light"

msgid "match.en.SearchTypeEnum.D"
msgstr "Distance"

msgid "match.en.SearchTypeEnum.D.warn.level"
msgstr "Light"

msgid "match.en.SearchTypeEnum.E"
msgstr "Exact"

msgid "match.en.SearchTypeEnum.E.warn.level"
msgstr "Light"

msgid "match.en.SearchTypeEnum.M"
msgstr "Mapping"

msgid "match.en.SearchTypeEnum.M.warn.level"
msgstr "Light"

msgid "match.en.SearchTypeEnum.X"
msgstr "Skip"

msgid "match.en.SearchTypeEnum.X.warn.level"
msgstr "Light"

msgid "match.en.SearchTypeEnum.S"
msgstr "Substring"

msgid "match.en.SearchTypeEnum.S.warn.level"
msgstr "Light"

msgid "match.en.StatusEnum.A"
msgstr "Active"

msgid "match.en.StatusEnum.A.warn.level"
msgstr "Light"

msgid "match.en.StatusEnum.S"
msgstr "Suspended"

msgid "match.en.StatusEnum.S.warn.level"
msgstr "Danger"

### Error Messages
msgid "match.er.args"
msgstr "Incorrect arguments provided to {0}"
Expand Down
4 changes: 2 additions & 2 deletions app/src/Lib/Enum/StandardEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static function getLocalizedConsts() {

$consts = $reflect->getConstants();

$className = substr(strrchr(get_called_class(), '\\'), 1);
$className = $reflect->getShortName();

foreach(array_values($consts) as $key) {
$ret[$key] = __('match.en.'.$className.'.'.$key);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/View/AppView.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ class AppView extends View {
public function initialize(): void {
parent::initialize();
$this->loadHelper('Field');
$this->loadHelper('Menu');
$this->loadHelper('Badge');
}
}
118 changes: 118 additions & 0 deletions app/src/View/Helper/BadgeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* COmanage Match Badge Helper
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

declare(strict_types = 1);

namespace App\View\Helper;
use \Cake\View\Helper;

class BadgeHelper extends Helper {

public $helpers = ['Html'];

/**
* Helper which will produce Bootstrap based Badge
* Bootstrap v5 uses different notation, e.g. bg-success instead of badge success. So, keep everything in one place
* to facilitate an upgrade process
*
* @param string $title The title of the badge
* @param string $type Define the type of Badge. The value should be one of
* [primary,secondary,success,danger,warning,info,light,dark]
* Defaults to light
* @param boolean $badge_pill Is this a badge-pill. Defaults to false
* @param boolean $badge_outline Is this an outlined badge. Defaults to false
* @param array $class_list List of extra classes
* @param string|null $fa_class Fonts Awesome Icon we will prepend to the badge text
* @return mixed
* @since COmanage Match v1.0.0
*/
public function badgeIt(
string $title,
string $type = 'secondary',
bool $badge_pill = false,
bool $badge_outline = false,
array $class_list = [],
string $fa_class = null
) {

$badge_classes = [];

if($badge_pill) {
$badge_classes[] = "badge-pill";
}
if($badge_outline) {
$badge_classes[] = "badge-outline-" . $type;
} else {
$badge_classes[] = "badge-" . $type;
}

if(!empty($class_list)) {
$badge_classes[] = implode(' ', $class_list);
}

if(!empty($fa_class)) {
$fa_element = '<i class="mr-1 fa ' . $fa_class .'"></i>';
}

return $this->Html->tag(
'span',
$fa_element . $title,
[
'class' => 'mr-1 badge ' . implode(' ', $badge_classes),
'escape' => false,
]
);
}

/**
* Get the Badge Color
*
* @param string $color
* @return string|null
*
* @since COmanage Match v1.0.0
*/
public function getBadgeColor(string $color): ?string {
if(empty($color)) {
return null;
}

$color_map = [
'Success' => 'success',
'Danger' => 'danger',
'Warning' => 'warning',
'Primary' => 'primary',
'Secondary' => 'secondary',
'Light' => 'light',
'Info' => 'info',
'Dark' => 'dark',
];

return $color_map[$color];
}

}
5 changes: 4 additions & 1 deletion app/templates/Standard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ function _column_key($modelsName, $c, $tz=null) {
break;
case 'enum':
if($entity->$col) {
print __('match.en.'.$cfg['class'].'.'.$entity->$col);
$warning_level = __('match.en.'.$cfg['class'].'.'.$entity->$col . '.warn.level');
$title = __('match.en.'.$cfg['class'].'.'.$entity->$col);

print $this->Badge->badgeIt($title, $this->Badge->getBadgeColor($warning_level));
}
break;
case 'fk':
Expand Down
74 changes: 74 additions & 0 deletions app/templates/element/badgeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
* COmanage Match Badge List
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* List of Badge configuration
* $vv_badge_list = array(
* array(
* 'order' => BadgeOrderEnum::Status,
* 'text' => "mytext",
* 'color' => BadgeColorModeEnum::Blue,
* 'outline' => false,
* 'pill' => true,
* 'fa_class' => 'fa-key',
* ),
* );
*
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
?>

<?php
// Sort the Badges
usort($vv_badge_list, function ($item1, $item2) {
if ($item1['order'] == $item2['order']) return 0;
return $item1['order'] < $item2['order'] ? -1 : 1;
});

foreach($vv_badge_list as $badge) {
$badge_classes = [];
$fa_element = "";

if(isset($badge['pill']) && $badge['pill']) {
$badge_classes[] = "badge-pill";
}
if(!empty($badge['fa_class'])) {
$fa_element = '<i class="mr-1 fa ' . $badge["fa_class"] .'"></i>';
}
if(isset($badge['outline']) && $badge['outline']) {
$badge_classes[] = "badge-outline-" . $badge['color'];
} else {
$badge_classes[] = "badge-" . $badge['color'];
}

// Print the Badge
print $this->Html->tag(
'span',
$fa_element . $badge['text'],
[
'class' => 'mr-1 badge ' . implode(' ', $badge_classes),
'escape' => false,
]
);
}
Loading

0 comments on commit 744ba80

Please sign in to comment.