Skip to content

Run action menu items in index views throught the menuAction element … #7

Merged
merged 2 commits into from
Jan 22, 2022
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
2 changes: 1 addition & 1 deletion app/resources/locales/en_US/menu.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ msgid "co.people"
msgstr "People"

msgid "co.switch"
msgstr "Switch Collaboration"
msgstr "Switch CO"
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ msgstr "Make Primary"
msgid "Types.restore"
msgstr "Add/Restore Default Types"

msgid "remove"
msgstr "Remove"

msgid "save"
msgstr "Save"

Expand Down
127 changes: 127 additions & 0 deletions app/src/View/Helper/BadgeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* COmanage Registry 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 registry
* @since COmanage Registry v5.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
*
* @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 bg-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
* @param boolean $dis_text_dark Disable dark-text fonts for light|info color mode.
* @return mixed
* @since COmanage Registry v5.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,
bool $dis_text_dark = false
) {

$badge_classes = [];

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

if(in_array($type, ['light', 'info'])
&& !$dis_text_dark) {
$badge_classes[] = "text-dark";
}

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 Registry v5.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',
];

if(!isset($color_map[$color])) {
return null;
}

return $color_map[$color];
}

}
84 changes: 84 additions & 0 deletions app/src/View/Helper/MenuHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* COmanage Registry Menu 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 registry
* @since COmanage Registry v5.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 MenuHelper extends Helper {

public $helpers = ['Html'];

/**
* Get the Menu Order per action
*
* @param string $action
* @return int|null
*
* @since COmanage Registry v5.0.0
*/
public function getMenuOrder($action) {
if(empty($action)) {
return null;
}

$order = array(
'View' => 5, // visibility
'Edit' => 10, // edit
'Default' => 20, // link - default starting order for arbitrary action menu items
'Delete' => 100 // delete
);

return $order[$action];
}

/**
* Get the Menu Icon per action
*
* @param string $action
* @return string|null
*
* @since COmanage Registry v5.0.0
*/
public function getMenuIcon($action) {
if(empty($action)) {
return null;
}

$icon = array(
'View' => 'visibility',
'Edit' => 'edit',
'Default' => 'link', // default icon for arbitrary menu items
'Delete' => 'delete'
);

return $icon[$action];
}

}
4 changes: 2 additions & 2 deletions app/templates/Cos/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ $indexColumns = [
];

$indexActions = [
// XXX Should these buttons move to or also be present in object view?
[
'action' => 'duplicate',
'class' => 'copybutton'
'class' => 'duplicate',
'icon' => 'content_copy'
]
];
Loading