chg: [generic_picker] all view using the generic_picker now use the

generic_picker view elements - WIP
pull/4041/head
mokaddem 2019-01-22 16:02:01 +01:00
parent 7cfe1d87a9
commit 1a2edf05b1
7 changed files with 97 additions and 136 deletions

View File

@ -1580,26 +1580,22 @@ class AttributesController extends AppController
$selectedAttributeIds = array(); $selectedAttributeIds = array();
} }
App::uses('TextColourHelper', 'View/Helper');
$textColourHelper = new TextColourHelper(new View());
$tagTemplate = '<span href="#" class="tagComplete" style="background-color:{{=it.background}}; color:{{=it.color}}">{{=it.name}}</span>';
$galaxyTemplate = '<span href="#" class="tagComplete" style="background-color:{{=it.background}}; color:{{=it.color}}">{{=it.name}}</span>';
// tags to remove // tags to remove
$tags = $this->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $id, $selectedAttributeIds); $tags = $this->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $id, $selectedAttributeIds);
$tagItemsRemove = array(); $tagItemsRemove = array();
foreach ($tags as $k => $tag) { foreach ($tags as $k => $tag) {
$tagName = $tag['name']; $tagName = $tag['name'];
$tagItemsRemove[] = array( $tagItemsRemove[] = array(
'name' => h($tagName), 'name' => $tagName,
'value' => h($tag['id']), 'value' => $tag['id'],
'template' => $tagTemplate, 'template' => array(
'templateData' => array( 'name' => array(
'name' => h($tagName), 'name' => $tagName,
'background' => h(isset($tag['colour']) ? $tag['colour'] : '#ffffff'), 'label' => array(
'color' => h(isset($tag['colour']) ? $textColourHelper->getTextColour($tag['colour']) : '#0088cc') 'background' => isset($tag['colour']) ? $tag['colour'] : '#ffffff'
)
), ),
)
); );
} }
unset($tags); unset($tags);
@ -1608,32 +1604,21 @@ class AttributesController extends AppController
$clusters = $this->Attribute->AttributeTag->getAttributesClusters($this->Auth->user(), $id, $selectedAttributeIds); $clusters = $this->Attribute->AttributeTag->getAttributesClusters($this->Auth->user(), $id, $selectedAttributeIds);
$clusterItemsRemove = array(); $clusterItemsRemove = array();
foreach ($clusters as $k => $cluster) { foreach ($clusters as $k => $cluster) {
$clusterTemplate = '{{=it.name}}'; $title = __('Synonyms: ') . $cluster['synonyms_string'];
if (strlen($cluster['description']) < 50) { $name = $cluster['value'];
$clusterTemplate .= '<i style="float:right; font-size: smaller;">{{=it.description}}</i>'; $optionName = $cluster['value'];
} else { $optionName .= $cluster['synonyms_string'] !== '' ? ' (' . $cluster['synonyms_string'] . ')' : '';
$clusterTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>';
}
if ($cluster['synonyms_string'] !== "") {
$clusterTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; font-size: smaller;"><i>{{=it.synonyms_string}}</i></div>';
}
$title = __('Synonyms: ') . h($cluster['synonyms_string']);
$name = h($cluster['value']);
$optionName = h($cluster['value']);
$optionName .= $cluster['synonyms_string'] !== '' ? ' (' . h($cluster['synonyms_string']) . ')' : '';
$clusterItemsRemove[] = array( $clusterItemsRemove[] = array(
'name' => $optionName, 'name' => $optionName,
'value' => h($cluster['id']), 'value' => $cluster['id'],
'additionalData' => array( 'additionalData' => array(
'event_id' => h($id), 'event_id' => $id,
), ),
'template' => $clusterTemplate, 'template' => array(
'templateData' => array(
'name' => $name, 'name' => $name,
'description' => h($cluster['description']), 'infoExtra' => $cluster['description'],
'synonyms_string' => $title 'infoContextual' => $title
) )
); );
} }
@ -1654,14 +1639,16 @@ class AttributesController extends AppController
foreach ($tags as $k => $tag) { foreach ($tags as $k => $tag) {
$tagName = $tag['name']; $tagName = $tag['name'];
$tagItemsAdd[] = array( $tagItemsAdd[] = array(
'name' => h($tagName), 'name' => $tagName,
'value' => h($tag['id']), 'value' => $tag['id'],
'template' => $tagTemplate, 'template' => array(
'templateData' => array( 'name' => array(
'name' => h($tagName), 'name' => $tagName,
'background' => h(isset($tag['colour']) ? $tag['colour'] : '#ffffff'), 'label' => array(
'color' => h(isset($tag['colour']) ? $textColourHelper->getTextColour($tag['colour']) : '#0088cc') 'background' => isset($tag['colour']) ? $tag['colour'] : '#ffffff'
)
), ),
)
); );
} }

View File

@ -114,29 +114,19 @@ class GalaxiesController extends AppController
); );
foreach ($galaxies as $galaxy) { foreach ($galaxies as $galaxy) {
if ($galaxy['Galaxy']['id'] != -1) { if ($galaxy['Galaxy']['id'] != -1) {
// construct option template
$galaxyTemplate = '<it class="fa fa-{{=it.icon}}" style="width: 22px;"></it>';
$galaxyTemplate .= '{{=it.name}}';
if (strlen($galaxy['Galaxy']['description']) < 50) {
$galaxyTemplate .= '<i style="float:right; font-size: smaller;">{{=it.description}}</i>';
} else {
$galaxyTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>';
}
$items[] = array( $items[] = array(
'name' => h($galaxy['Galaxy']['name']), 'name' => h($galaxy['Galaxy']['name']),
'value' => "/galaxies/selectCluster/" . h($target_id) . '/' . h($target_type) . '/' . h($galaxy['Galaxy']['id']), 'value' => "/galaxies/selectCluster/" . $target_id . '/' . $target_type . '/' . $galaxy['Galaxy']['id'],
'template' => $galaxyTemplate, 'template' => array(
'templateData' => array( 'preIcon' => 'fa-' . $galaxy['Galaxy']['icon'],
'icon' => h($galaxy['Galaxy']['icon']), 'name' => $galaxy['Galaxy']['name'],
'name' => h($galaxy['Galaxy']['name']), 'infoExtra' => $galaxy['Galaxy']['description'],
'description' => h($galaxy['Galaxy']['description'])
) )
); );
} else { // attackMatrix } else { // attackMatrix
$items[] = array( $items[] = array(
'name' => $galaxy['Galaxy']['name'], 'name' => $galaxy['Galaxy']['name'],
'functionName' => "getMitreMatrixPopup('" . h($target_type) . "', '" . h($target_id) . "')", 'functionName' => "getMitreMatrixPopup('" . $target_type . "', '" . $target_id . "')",
'isPill' => true, 'isPill' => true,
'img' => "/img/mitre-attack-icon.ico", 'img' => "/img/mitre-attack-icon.ico",
); );
@ -159,12 +149,12 @@ class GalaxiesController extends AppController
$items = array(); $items = array();
$items[] = array( $items[] = array(
'name' => __('All namespaces'), 'name' => __('All namespaces'),
'value' => "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/0' 'value' => "/galaxies/selectGalaxy/" . $target_id . '/' . $target_type . '/0'
); );
foreach ($namespaces as $namespace) { foreach ($namespaces as $namespace) {
$items[] = array( $items[] = array(
'name' => h($namespace), 'name' => $namespace,
'value' => "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/' . h($namespace) 'value' => "/galaxies/selectGalaxy/" . $target_id . '/' . $target_type . '/' . $namespace
); );
} }
@ -209,38 +199,30 @@ class GalaxiesController extends AppController
$items = array(); $items = array();
foreach ($clusters as $namespace => $cluster_data) { foreach ($clusters as $namespace => $cluster_data) {
foreach ($cluster_data as $k => $cluster) { foreach ($cluster_data as $k => $cluster) {
$clusterTemplate = '{{=it.name}}'; $name = $cluster['value'];
if (strlen($cluster['description']) < 50) { $optionName = $cluster['value'];
$clusterTemplate .= '<i style="float:right; font-size: smaller;">{{=it.description}}</i>'; if ($cluster['synonyms_string'] !== '') {
$synom = __('Synonyms: ') . $cluster['synonyms_string'];
$optionName .= $cluster['synonyms_string'] !== '' ? ' (' . $cluster['synonyms_string'] . ')' : '';
} else { } else {
$clusterTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>'; $synom = '';
} }
if ($cluster['synonyms_string'] !== "") { $itemParam = array(
$clusterTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; font-size: smaller;"><i>{{=it.synonyms_string}}</i></div>';
}
$target_type = h($target_type);
$target_id = h($target_id);
$cluster_id = h($cluster['id']);
$title = __('Synonyms: ') . h($cluster['synonyms_string']);
$name = h($cluster['value']);
$optionName = h($cluster['value']);
$optionName .= $cluster['synonyms_string'] !== '' ? ' (' . h($cluster['synonyms_string']) . ')' : '';
$items[] = array(
'name' => $optionName, 'name' => $optionName,
'value' => h($cluster_id), 'value' => $cluster['id'],
'title' => $title,
'additionalData' => array( 'additionalData' => array(
'target_id' => $target_id, 'target_id' => $target_id,
'target_type' => $target_type, 'target_type' => $target_type,
), ),
'template' => $clusterTemplate, 'template' => array(
'templateData' => array(
'name' => $name, 'name' => $name,
'description' => h($cluster['description']), 'infoExtra' => $cluster['description'],
'synonyms_string' => $title
) )
); );
if ($cluster['synonyms_string'] !== '') {
$itemParam['template']['infoContextual'] = $synom;
}
$items[] = $itemParam;
} }
} }
$onClickForm = 'quickSubmitGalaxyForm'; $onClickForm = 'quickSubmitGalaxyForm';

View File

@ -62,24 +62,14 @@ class ObjectTemplatesController extends AppController
$items = array(); $items = array();
foreach($templates_raw as $template) { foreach($templates_raw as $template) {
$template = $template['ObjectTemplate'];
$chosenTemplate = '<span href="#">{{=it.name}}</span>';
if (strlen($template['description']) < 80) {
$chosenTemplate .= '<i style="float:right; font-size: smaller;">{{=it.description}}</i>';
} else {
$chosenTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>';
}
$chosenTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; margin-top: 5px; font-size: smaller;"><i>{{=it.metacateg}}</i></div>';
$items[] = array( $items[] = array(
'name' => $template['name'], 'name' => $template['name'],
'value' => $template['id'], 'value' => $template['id'],
'additionalData' => array('event_id' => h($event_id)), 'additionalData' => array('event_id' => $event_id),
'template' => $chosenTemplate, 'template' => array(
'templateData' => array( 'name' => $template['name'],
'name' => h($template['name']), 'infoExtra' => $template['description'],
'description' => h($template['description']), 'infoContextual' => $template['meta-category']
'metacateg' => __('Category') . ': ' . h($template['meta-category'])
) )
); );
} }

View File

@ -722,55 +722,41 @@ class TagsController extends AppController
$this->set('scope', $scope); $this->set('scope', $scope);
$this->set('object_id', $id); $this->set('object_id', $id);
App::uses('TextColourHelper', 'View/Helper');
$textColourHelper = new TextColourHelper(new View()); if ($scope === 'attribute') {
$onClickForm = 'quickSubmitAttributeTagForm';
} elseif ($scope === 'tag_collection') {
$onClickForm = 'quickSubmitTagCollectionTagForm';
} else {
$onClickForm = 'quickSubmitTagForm';
}
$items = array(); $items = array();
foreach ($tags as $k => $tag) { foreach ($tags as $k => $tag) {
$tagTemplate = '<span href="#" class="tagComplete" style="background-color:{{=it.background}}; color:{{=it.color}}">{{=it.name}}</span>';
$tagName = $tag['name']; $tagName = $tag['name'];
$choice_id = $k; $choice_id = $k;
if ($taxonomy_id === 'collections') { if ($taxonomy_id === 'collections') {
$choice_id = 'collection_' . $choice_id; $choice_id = 'collection_' . $choice_id;
} }
$onClickForm = 'quickSubmitTagForm';
if ($scope === 'attribute') {
$onClickForm = 'quickSubmitAttributeTagForm';
}
if ($scope === 'tag_collection') {
$onClickForm = 'quickSubmitTagCollectionTagForm';
}
if (is_numeric($taxonomy_id) && $taxonomy_id > 0 && isset($expanded[$tag['id']])) {
if (strlen($expanded[$tag['id']]) < 50) {
$tagTemplate .= '<i style="float:right; font-size: smaller;">{{=it.expanded}}</i>';
} else {
$tagTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.expanded}}"></it>';
}
}
if ($taxonomy_id === 'collections') {
$tagTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; margin-top: 5px; font-size: smaller;"><i>{{=it.includes}}</i></div>';
}
$itemParam = array( $itemParam = array(
'name' => h($tagName), 'name' => $tagName,
'value' => h($choice_id), 'value' => $choice_id,
'additionalData' => array( 'additionalData' => array(
'id' => h($id) 'id' => $id
), ),
'template' => $tagTemplate, 'template' => array(
'templateData' => array( 'name' => array(
'name' => h($tagName), 'name' => $tagName,
'background' => h(isset($tag['colour']) ? $tag['colour'] : '#ffffff'), 'label' => array(
'color' => h(isset($tag['colour']) ? $textColourHelper->getTextColour($tag['colour']) : '#0088cc'), 'background' => isset($tag['colour']) ? $tag['colour'] : '#ffffff'
'expanded' => h($expanded[$tag['id']]) )
),
'infoExtra' => $expanded[$tag['id']]
) )
); );
if ($taxonomy_id === 'collections') { if ($taxonomy_id === 'collections') {
$TagCollectionTag = __('Includes: ') . h($inludedTagListString[$tag['id']]); $itemParam['template']['infoContextual'] = __('Includes: ') . $inludedTagListString[$tag['id']];
$itemParam['templateData']['includes'] = $TagCollectionTag;
} }
$items[] = $itemParam; $items[] = $itemParam;
} }

View File

@ -0,0 +1,19 @@
<?php
if (is_array($name)) {
if (isset($name['label'])) {
$label = $name['label'];
$name = $name['name'];
$background_color = isset($label['background']) ? h($label['background']) : '#ffffff';
$color = isset($label['background']) ? $this->TextColour->getTextColour($label['background']) : '#0088cc';
?>
<span href="#" class="tagComplete" style="background-color:<?php echo $background_color; ?>; color:<?php echo $color; ?>">
<?php echo $name ?>
</span>
<?php
} else {
echo h($name);
}
} else {
echo h($name);
}

View File

@ -117,9 +117,6 @@ function redrawChosenWithTemplate($select, $chosenContainer) {
var res = ""; var res = "";
if (template !== undefined && template !== '') { if (template !== undefined && template !== '') {
var template = atob(template); var template = atob(template);
// var temp = doT.template(template);
// var templateData = JSON.parse(atob($option.data('templatedata')));
// res = temp(templateData);
$item.html(template); $item.html(template);
} }
}) })

View File

@ -105,7 +105,7 @@ class GenericPickerHelper extends AppHelper {
if (isset($templateParam['preIcon'])) { if (isset($templateParam['preIcon'])) {
$template .= $this->_View->element('genericPickerElements/pre_icon', array('preIcon' => $templateParam['preIcon'])); $template .= $this->_View->element('genericPickerElements/pre_icon', array('preIcon' => $templateParam['preIcon']));
} }
$template .= h($templateParam['name']); $template .= $this->_View->element('genericPickerElements/name', array('name' => $templateParam['name']));
if (isset($templateParam['infoExtra'])) { if (isset($templateParam['infoExtra'])) {
$template .= $this->_View->element('genericPickerElements/info_extra', array('infoExtra' => $templateParam['infoExtra'])); $template .= $this->_View->element('genericPickerElements/info_extra', array('infoExtra' => $templateParam['infoExtra']));
} }