chg: [refacto] removed useless code and views

pull/4024/head
mokaddem 2019-01-17 14:46:43 +01:00
parent e5ce38a1b4
commit 38718e7932
8 changed files with 1 additions and 311 deletions

View File

@ -179,25 +179,14 @@ class GalaxiesController extends AppController
'recursive' => -1
));
$clusters = array();
$lookup_table = array();
foreach ($data as $k => $cluster) {
$cluster['GalaxyCluster']['synonyms_string'] = array();
foreach ($cluster['GalaxyElement'] as $element) {
$cluster['GalaxyCluster']['synonyms_string'][] = $element['value'];
if (isset($lookup_table[$cluster['GalaxyCluster']['type']][$element['value']])) {
$lookup_table[$cluster['GalaxyCluster']['type']][$element['value']][] = $cluster['GalaxyCluster']['id'];
} else {
$lookup_table[$cluster['GalaxyCluster']['type']][$element['value']] = array($cluster['GalaxyCluster']['id']);
}
}
$cluster['GalaxyCluster']['synonyms_string'] = implode(', ', $cluster['GalaxyCluster']['synonyms_string']);
unset($cluster['GalaxyElement']);
$clusters[$cluster['GalaxyCluster']['type']][$cluster['GalaxyCluster']['value']] = $cluster['GalaxyCluster'];
if (isset($lookup_table[$cluster['GalaxyCluster']['type']][$cluster['GalaxyCluster']['value']])) {
$lookup_table[$cluster['GalaxyCluster']['type']][$cluster['GalaxyCluster']['value']][] = $cluster['GalaxyCluster']['id'];
} else {
$lookup_table[$cluster['GalaxyCluster']['type']][$cluster['GalaxyCluster']['value']] = array($cluster['GalaxyCluster']['id']);
}
}
ksort($clusters);
$this->set('target_id', $target_id);

View File

@ -3,14 +3,13 @@
* Generic select picker
*/
/** Config **/
$select_threshold = 6; // threshold on which pills will be replace by a select (unused if multiple is > 1)
$select_threshold = 6; // threshold above which pills will be replace by a select (unused if multiple is > 1)
$defaults_options = array(
'select_options' => array(
// 'multiple' => '', // set to add possibility to pick multiple options in the select
//'placeholder' => '' // set to replace the default placeholder text
),
'chosen_options' => array(
// 'width' => '500px',
'width' => '85%',
'search_contains' => true, // matches starting from anywhere within a word
//'no_results_text' => '', // set to replace the default no result text after filtering

View File

@ -1,86 +0,0 @@
<?php
/**
* Generic pre select picker from JSON
* Required: $choices
*/
?>
<script>
function addOptionsToSelect(clicked) {
var $clicked = $(clicked);
var $wrapper = $clicked.closest('div').find('div.generic-picker-wrapper');
$.ajax({
dataType:"html",
async: true,
cache: false,
beforeSend: function() {
var loadingHtml = '<div style="height: 40px; width: 40px; left: 50%; position: relative;"><div class="spinner" style="height: 30px; width: 30px;"></div></div>';
var $arrow = $clicked.closest('div.popover').find('div.arrow');
syncPopoverArrow($arrow, $wrapper, loadingHtml)
},
success:function (data, textStatus) {
var $arrow = $clicked.closest('div.popover').find('div.arrow');
syncPopoverArrow($arrow, $wrapper, data)
},
error:function() {
$wrapper.html('<div class="alert alert-error" style="margin-bottom: 0px;">Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).</div>');
},
url: $clicked.data('endpoint')
});
}
// Used to keep the popover arrow at the correct place regardless of the popover content
function syncPopoverArrow($arrow, $wrapper, content) {
var ar_pos = $arrow.position();
$wrapper.html(content);
// redraw popover
$arrow.css('top', ar_pos.top + 'px');
$arrow.css('left', ar_pos.left + 'px');
}
<?php if ($use_select): ?>
function setupChosen(id) {
var $elem = $('#'+id);
$elem.chosen({disable_search_threshold: 10});
$elem.change(function(event, selected) {
select = this;
$select = $(select);
$select.data('endpoint', selected.selected);
addOptionsToSelect($select)
});
}
<?php endif; ?>
</script>
<?php if ($use_select): ?>
<?php $select_id = h(uniqid()); // used to only register the listener on this select (allowing nesting) ?>
<select id="<?php echo $select_id; ?>" style="height: 20px; margin-bottom: 0px;">
<option></option>
<?php foreach ($choices as $name => $endpoint): ?>
<option value="<?php echo h($endpoint); ?>"><?php echo h($name); ?></option>
<?php endforeach; ?>
</select>
<script>
$(document).ready(function() {
setTimeout(function() { // let time for the popup to show
setupChosen("<?php echo $select_id; ?>");
}, 10);
});
</script>
<?php else: ?>
<ul class="nav nav-pills">
<?php foreach($choices as $name => $endpoint): ?>
<li>
<a href="#" data-toggle="pill" class="pill-pre-picker"
data-endpoint="<?php echo h($endpoint); ?>"
onclick="addOptionsToSelect(this)"
>
<?php echo h($name); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<div class='generic-picker-wrapper'></div>

View File

@ -124,7 +124,6 @@ foreach($attackTactic as $tactic):
?>
</select>
</div>
<!-- <div role="button" tabindex="0" aria-label="<?php echo __('Submit');?>" title="<?php echo __('Submit');?>" class="templateChoiceButton btn-matrix-submit" onClick="cancelPopoverForm('#popover_form_large');"><?php echo __('Submit'); ?></div> -->
<div role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm('#popover_form_large');"><?php echo __('Cancel'); ?></div>
<?php endif; ?>

View File

@ -1,32 +0,0 @@
<div class="popover_choice select_galaxy_source">
<legend><?php echo __('Select Cluster Source');?></legend>
<div class="popover_choice_main" id ="popover_choice_main">
<table style="width:100%;">
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
<td role="button" tabindex="0" aria-label="<?php echo __('All clusters');?>" title="<?php echo __('All clusters');?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id) . '/' . h($target_type); ?>/0', 'galaxies', 'selectCluster');"><?php echo __('All Galaxies');?></td>
</tr>
<?php foreach ($galaxies as $galaxy): ?>
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
<?php if ($galaxy['Galaxy']['id'] != -1): ?>
<td role="button" tabindex="0" aria-label="<?php echo h($galaxy['Galaxy']['name']); ?>" title="<?php echo h($galaxy['Galaxy']['name']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id) . "/" . h($target_type); ?>/<?php echo h($galaxy['Galaxy']['id']);?>', 'galaxies', 'selectCluster');">Galaxy: <?php echo h($galaxy['Galaxy']['name']); ?></td>
<?php else: ?>
<td role="button" tabindex="0" aria-label="<?php echo h($galaxy['Galaxy']['name']); ?>" title="<?php echo h($galaxy['Galaxy']['name']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getMitreMatrixPopup('<?php echo h($target_id) . "/" . h($target_type); ?>');">
<img src="<?php echo h($galaxy['Galaxy']['icon']); ?>" style="margin-right: 8px; height: 25px;"/>
<?php echo h($galaxy['Galaxy']['name']); ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</table>
</div>
<div role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();"><?php echo __('Cancel');?></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
resizePopoverBody();
});
$(window).resize(function() {
resizePopoverBody();
});
</script>

View File

@ -1,25 +0,0 @@
<div class="popover_choice select_galaxy_namespace_source">
<legend><?php echo __('Select Galaxy Namespace Source');?></legend>
<div class="popover_choice_main" id ="popover_choice_main">
<table style="width:100%;">
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
<td role="button" tabindex="0" aria-label="<?php echo __('All namespaces');?>" title="<?php echo __('All namespaces');?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id) . '/' . h($target_type); ?>/0', 'galaxies', 'selectGalaxy');"><?php echo __('All Namespaces');?></td>
</tr>
<?php foreach ($namespaces as $namespace): ?>
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
<td role="button" tabindex="0" aria-label="<?php echo h($namespace); ?>" title="<?php echo h($namespace); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id) . "/" . h($target_type); ?>/<?php echo h($namespace)?>', 'galaxies', 'selectGalaxy');"><?php echo h($namespace); ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();"><?php echo __('Cancel');?></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
resizePopoverBody();
});
$(window).resize(function() {
resizePopoverBody();
});
</script>

View File

@ -1,57 +0,0 @@
<div class="popover_choice">
<legend><?php echo __('Select Object Category');?></legend>
<div class="popover_choice_main" id ="popover_choice_main">
<table style="width:100%;" id="MainTable">
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
<td role="button" tabindex="0" aria-label="<?php echo __('All meta-categories');?>" title="<?php echo __('All Objects');?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="objectChoiceSelect('all');"><?php echo __('All Objects');?></td>
</tr>
</table>
</div>
<div role="button" tabindex="0" aria-label="<?php echo __('Cancel');?>" title="<?php echo __('Cancel');?>" class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();"><?php echo __('Cancel');?></div>
</div>
<script type="text/javascript">
var choice = "categories";
var eventId = "<?php echo h($eventId);?>";
var templates = <?php echo json_encode($templates); ?>;
var template_categories = <?php echo json_encode($template_categories); ?>;
$(document).ready(function() {
resizePopoverBody();
populateObjectChoiceList(choice);
});
$(window).resize(function() {
resizePopoverBody();
});
function populateObjectChoiceList(choice) {
$("#MainTable").empty();
if (choice == "categories") {
template_categories.forEach(function(category) {
$("#MainTable").append(createObjectChoiceRowCategories(category));
});
} else {
templates[choice].forEach(function(element) {
$("#MainTable").append(createObjectChoiceRow(eventId, element));
});
$("#MainTable").append(createObjectChoiceRowCategories('categories'));
}
}
function createObjectChoiceRow(eventId, data) {
var html = '<tr style="border-bottom:1px solid black;" class="templateChoiceButton">';
var html = html + '<td role="button" tabindex="0" aria-label="' + data["description"] + '" title="' + data["description"] + '" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="window.location=\'/objects/add/' + eventId + '/' + data["id"] + '\';">' + data["name"].charAt(0).toUpperCase() + data["name"].slice(1) + '</td>';
var html = html + '</tr>';
return html;
}
function createObjectChoiceRowCategories(data) {
var text = data;
if (text == 'categories') {
text = '<?php echo __('Back to categories');?>';
}
var html = '<tr style="border-bottom:1px solid black;" class="templateChoiceButton">';
var html = html + '<td role="button" tabindex="0" aria-label="' + (text[0].toUpperCase() + text.slice(1)) + '" title="' + (text[0].toUpperCase() + text.slice(1)) + '" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="populateObjectChoiceList(\'' + data + '\');">' + (text[0].toUpperCase() + text.slice(1)) + '</td>';
var html = html + '</tr>';
return html;
}
</script>

View File

@ -1,97 +0,0 @@
<!-- to delete if unused -->
<div class="popover_choice select_tag_source">
<legend><?php echo __('Select Tag Source');?></legend>
<div style="text-align:right;width:100%;" class="select_tag_search">
<input id="filterField" style="width:100%;border:0px;padding:0px;" placeholder="<?php echo __('search tags…');?>"/>
</div>
<div class="popover_choice_main" id ="popover_choice_main">
<table style="width:100%;">
<?php
if ($favourites) {
echo sprintf(
'<tr style="border-bottom:1px solid black;" class="templateChoiceButton">%s</tr>',
sprintf(
'<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%%;" onClick="getPopup(\'%s/favourites/%s\', \'tags\', \'selectTag\');">%s</td>',
h($object_id),
h($scope),
__('Favourite Tags')
)
);
}
if ($scope !== 'tag_collection') {
echo sprintf(
'<tr style="border-bottom:1px solid black;" class="templateChoiceButton">%s</tr>',
sprintf(
'<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%%;" onClick="getPopup(\'%s/collections/%s\', \'tags\', \'selectTag\');">%s</td>',
h($object_id),
h($scope),
__('Tag Collections')
)
);
}
echo sprintf(
'<tr style="border-bottom:1px solid black;" class="templateChoiceButton">%s</tr>',
sprintf(
'<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%%;" onClick="getPopup(\'%s/0/%s\', \'tags\', \'selectTag\');">%s</td>',
h($object_id),
h($scope),
__('Custom Tags')
)
);
echo sprintf(
'<tr style="border-bottom:1px solid black;" class="templateChoiceButton">%s</tr>',
sprintf(
'<td id="allTags" style="padding-left:10px;padding-right:10px; text-align:center;width:100%%;" data-url="%s/all/%s" onClick="getPopup(this.getAttribute(\'data-url\') + $(\'#filterField\').val(), \'tags\', \'selectTag\');">%s</td>',
h($object_id),
h($scope),
__('All Tags')
)
);
foreach ($options as $k => &$option) {
echo sprintf(
'<tr style="border-bottom:1px solid black;" class="templateChoiceButton">%s</tr>',
sprintf(
'<td style="padding-left:10px;padding-right:10px; text-align:center;width:100%%;" onClick="getPopup(\'%s/%s/%s\', \'tags\', \'selectTag\');">%s: %s</td>',
h($object_id),
h($k),
h($scope),
__('Taxonomy Library'),
h($option)
)
);
}
?>
</table>
</div>
<div class="templateChoiceButton templateChoiceButtonLast" onClick="cancelPopoverForm();"><?php echo __('Cancel');?></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
resizePopoverBody();
try {
new Promise(function(resolve) { setTimeout(function() {$("#filterField").focus()}, 100)});
} catch(error) {
setTimeout(function() {$("#filterField").focus()}, 100);
}
});
$(window).resize(function() {
resizePopoverBody();
});
var lastKeyPressTimestamp = null;
function onKeyUp() {
lastKeyPressTimestamp = (new Date()).getTime();
setTimeout(function() {
if(lastKeyPressTimestamp + 400 < (new Date()).getTime()) {
var filterString = $("#filterField").val().toLowerCase();
if(filterString.length > 0) {
$('#allTags').click();
}
}
}, 500);
}
$('#filterField').keyup(onKeyUp);
</script>