chg: [cluster:view_relations] Decoupled relation_tree from the form

pull/6120/head
mokaddem 2020-05-13 09:43:12 +02:00
parent 6de4117696
commit 52a89a2507
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 111 additions and 112 deletions

View File

@ -4,48 +4,6 @@ echo $this->element('genericElements/assetLoader', array(
));
?>
<div>
<div style="padding: 5px; background-color: #f6f6f6; border-bottom: 1px solid #ccc; ">
<form id="relationsQuickAddForm">
<div class="input">
<label for="RelationshipSource"><?= __('Source UUID') ?></label>
<input id="RelationshipSource" name="source_id" type="text" value="<?= h($cluster['GalaxyCluster']['uuid']) ?>" disabled></input>
</div>
<div class="input">
<label for="RelationshipType"><?= __('Relationship type') ?></label>
<select id="RelationshipType" name="referenced_galaxy_cluster_type">
<?php foreach ($existingRelations as $relation): ?>
<option value="<?= h($relation) ?>"><?= h($relation) ?></option>
<?php endforeach; ?>
<option value="<?= __('custom') ?>"><?= __('Custom relationship') ?></option>
<input id="RelationshipTypeFreetext" type="text"></input>
</select>
</div>
<div class="input">
<label for="RelationshipTarget"><?= __('Target UUID') ?></label>
<input id="RelationshipTarget" name="target_id" type="text"></input>
</div>
<div class="input">
<label for="RelationshipDistribution"><?= __('Distribution') ?></label>
<select id="RelationshipDistribution" name="distribution">
<?php foreach ($distributionLevels as $k => $distribution): ?>
<option value="<?= h($k) ?>"><?= h($distribution) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="input">
<label for="RelationshipTags"><?= __('Tags') ?></label>
<input id="RelationshipTags" name="tags" type="text"></input>
</div>
<div class="clear"></div>
<button id="buttonAddRelationship" type="button" class="btn btn-primary" style="">
<i class="fas fa-plus"></i>
Add relationship
</button>
</form>
</div>
</div>
<div style="padding: 5px; min-height: 600px;">
<svg id="treeSVG" style="width: 100%; height: 100%; min-height: 500px;"></svg>
</div>
@ -58,75 +16,6 @@ echo $this->element('genericElements/assetLoader', array(
var treeWidth, treeHeight;
var colors = d3.scale.category10();
var hasBeenBuilt = false;
$(document).ready(function() {
// $('#relationsQuickAddForm select').chosen();
$('#relationsQuickAddForm #RelationshipType').change(function() {
if (this.value === 'custom') {
$('#relationsQuickAddForm #RelationshipTypeFreetext').show();
} else {
$('#relationsQuickAddForm #RelationshipTypeFreetext').hide();
}
});
$('#relationsQuickAddForm #RelationshipTypeFreetext').hide();
})
$('#buttonAddRelationship').click(function() {
submitRelationshipForm();
})
function submitRelationshipForm() {
var url = "<?= $baseurl ?>/galaxy_cluster_relations/add/";
var data = {
source_id: $('#RelationshipSource').val(),
target_id: $('#RelationshipTarget').val(),
type: $('#RelationshipType').val(),
tags: $('#RelationshipTags').val(),
distribution: $('#RelationshipDistribution').val(),
tags: $('#RelationshipTags').val(),
freetext_relation: $('#RelationshipTypeFreetext').val(),
};
if (data.type === 'custom') {
data.type = data.freetext_relation;
}
toggleLoadingButton(true);
fetchFormDataAjax(url,
function(formData) {
$('body').append($('<div id="temp"/>').html(formData));
$('#temp #GalaxyClusterRelationSourceId').val(data.source_id);
$('#temp #GalaxyClusterRelationTargetId').val(data.target_id);
$('#temp #GalaxyClusterRelationReferencedGalaxyClusterType').val(data.type);
$('#temp #GalaxyClusterRelationDistribution').val(data.distribution);
$('#temp #GalaxyClusterRelationTags').val(data.tags);
$.ajax({
data: $('#GalaxyClusterRelationAddForm').serialize(),
success:function (data) {
$.get("/galaxy_clusters/viewRelations/<?php echo $cluster['GalaxyCluster']['id']; ?>", function(data) {
$("#relations_container").html(data);
});
},
error:function(jqXHR, textStatus, errorThrown) {
showMessage('fail', textStatus + ": " + errorThrown);
},
complete:function() {
toggleLoadingButton(false);
$('#temp').remove();
},
type:"post",
url: $('#GalaxyClusterRelationAddForm').attr('action')
});
},
function() {
toggleLoadingButton(false);
}
)
}
function toggleLoadingButton(loading) {
if (loading) {
$('#buttonAddRelationship > i').removeClass('fa-plus').addClass('fa-spinner fa-spin');
} else {
$('#buttonAddRelationship > i').removeClass('fa-spinner fa-spin').addClass('fa-plus');
}
}
function buildTree() {
if (hasBeenBuilt) {

View File

@ -110,7 +110,48 @@
</div>
<div id="references_div" style="position: relative; border: solid 1px;" class="statistics_attack_matrix hidden">
<?php echo $this->element('GalaxyClusters/view_relations'); ?>
<div>
<div style="padding: 5px; background-color: #f6f6f6; border-bottom: 1px solid #ccc; ">
<form id="relationsQuickAddForm">
<div class="input">
<label for="RelationshipSource"><?= __('Source UUID') ?></label>
<input id="RelationshipSource" name="source_id" type="text" value="<?= h($cluster['GalaxyCluster']['uuid']) ?>" disabled></input>
</div>
<div class="input">
<label for="RelationshipType"><?= __('Relationship type') ?></label>
<select id="RelationshipType" name="referenced_galaxy_cluster_type">
<?php foreach ($existingRelations as $relation): ?>
<option value="<?= h($relation) ?>"><?= h($relation) ?></option>
<?php endforeach; ?>
<option value="<?= __('custom') ?>"><?= __('Custom relationship') ?></option>
<input id="RelationshipTypeFreetext" type="text"></input>
</select>
</div>
<div class="input">
<label for="RelationshipTarget"><?= __('Target UUID') ?></label>
<input id="RelationshipTarget" name="target_id" type="text"></input>
</div>
<div class="input">
<label for="RelationshipDistribution"><?= __('Distribution') ?></label>
<select id="RelationshipDistribution" name="distribution">
<?php foreach ($distributionLevels as $k => $distribution): ?>
<option value="<?= h($k) ?>"><?= h($distribution) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="input">
<label for="RelationshipTags"><?= __('Tags') ?></label>
<input id="RelationshipTags" name="tags" type="text"></input>
</div>
<div class="clear"></div>
<button id="buttonAddRelationship" type="button" class="btn btn-primary" style="">
<i class="fas fa-plus"></i>
Add relationship
</button>
</form>
</div>
</div>
<?php echo $this->element('GalaxyClusters/view_relation_tree'); ?>
</div>
<div id="referencesTable_div" style="position: relative;" class="statistics_attack_matrix hidden">
<?= $relationTable ?>
@ -134,4 +175,73 @@ function toggleRelationTable() {
duration: 300,
});
}
$(document).ready(function() {
$('#relationsQuickAddForm #RelationshipType').change(function() {
if (this.value === 'custom') {
$('#relationsQuickAddForm #RelationshipTypeFreetext').show();
} else {
$('#relationsQuickAddForm #RelationshipTypeFreetext').hide();
}
});
$('#relationsQuickAddForm #RelationshipTypeFreetext').hide();
})
$('#buttonAddRelationship').click(function() {
submitRelationshipForm();
})
function submitRelationshipForm() {
var url = "<?= $baseurl ?>/galaxy_cluster_relations/add/";
var data = {
source_id: $('#RelationshipSource').val(),
target_id: $('#RelationshipTarget').val(),
type: $('#RelationshipType').val(),
tags: $('#RelationshipTags').val(),
distribution: $('#RelationshipDistribution').val(),
tags: $('#RelationshipTags').val(),
freetext_relation: $('#RelationshipTypeFreetext').val(),
};
if (data.type === 'custom') {
data.type = data.freetext_relation;
}
toggleLoadingButton(true);
fetchFormDataAjax(url,
function(formData) {
$('body').append($('<div id="temp"/>').html(formData));
$('#temp #GalaxyClusterRelationSourceId').val(data.source_id);
$('#temp #GalaxyClusterRelationTargetId').val(data.target_id);
$('#temp #GalaxyClusterRelationReferencedGalaxyClusterType').val(data.type);
$('#temp #GalaxyClusterRelationDistribution').val(data.distribution);
$('#temp #GalaxyClusterRelationTags').val(data.tags);
$.ajax({
data: $('#GalaxyClusterRelationAddForm').serialize(),
success:function (data) {
$.get("/galaxy_clusters/viewRelations/<?php echo $cluster['GalaxyCluster']['id']; ?>", function(data) {
$("#relations_container").html(data);
});
},
error:function(jqXHR, textStatus, errorThrown) {
showMessage('fail', textStatus + ": " + errorThrown);
},
complete:function() {
toggleLoadingButton(false);
$('#temp').remove();
},
type:"post",
url: $('#GalaxyClusterRelationAddForm').attr('action')
});
},
function() {
toggleLoadingButton(false);
}
)
}
function toggleLoadingButton(loading) {
if (loading) {
$('#buttonAddRelationship > i').removeClass('fa-plus').addClass('fa-spinner fa-spin');
} else {
$('#buttonAddRelationship > i').removeClass('fa-spinner fa-spin').addClass('fa-plus');
}
}
</script>