chg: [object:edit] Started integration to allow updating object

templates - WiP
pull/4530/head
mokaddem 2019-04-19 11:43:28 +02:00
parent f44efc9299
commit e2c865e07c
6 changed files with 100 additions and 18 deletions

View File

@ -349,7 +349,7 @@ class ObjectsController extends AppController
$this->set('element', $element);
}
public function edit($id)
public function edit($id, $update_template=false)
{
if (Validation::uuid($id)) {
$conditions = array('Object.uuid' => $id);
@ -402,6 +402,23 @@ class ObjectsController extends AppController
$this->redirect(array('controller' => 'events', 'action' => 'view', $object['Object']['event_id']));
}
$newer_template = $this->MispObject->ObjectTemplate->find('first', array(
'conditions' => array(
'ObjectTemplate.uuid' => $object['Object']['template_uuid'],
'ObjectTemplate.version >' => $object['Object']['template_version'],
),
'recursive' => -1,
'contain' => array(
'ObjectTemplateElement'
),
'order' => array('ObjectTemplate.version DESC')
));
if (!empty($newer_template)) {
$newer_template_version = $newer_template['ObjectTemplate']['version'];
} else {
$newer_template_version = false;
}
if (isset($this->params['named']['attributeToInject'])) {
$attributes_to_inject = json_decode(base64_decode($this->params['named']['attributeToInject']), true);
foreach ($attributes_to_inject['Attribute'] as $attribute_to_inject) {
@ -481,6 +498,8 @@ class ObjectsController extends AppController
$this->set('template', $template);
$this->set('action', 'edit');
$this->set('object', $object);
$this->set('updateTemplate', $update_template);
$this->set('newer_template_version', $newer_template_version);
$this->render('add');
}

View File

@ -1,6 +1,6 @@
<div class="<?php if (!isset($ajax) || !$ajax) echo 'form';?>">
<?php
$url = ($action == 'add') ? '/objects/revise_object/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'] : '/objects/revise_object/edit/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'] . '/' . $object['Object']['id'];
$url = ($action == 'add') ? '/objects/revise_object/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'] : '/objects/revise_object/edit/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'] . '/' . h($object['Object']['id']);
echo $this->Form->create('Object', array('id', 'url' => $url, 'enctype' => 'multipart/form-data'));
?>
<h3><?php echo ucfirst($action) . ' ' . Inflector::humanize(h($template['ObjectTemplate']['name'])) . __(' Object'); ?></h3>
@ -10,7 +10,12 @@
<dd>
<?php
echo Inflector::humanize(h($template['ObjectTemplate']['name'])) . ' v' . h($template['ObjectTemplate']['version']);
?>
if ($action == 'edit' && !$updateTemplate && $newer_template_version !== false): ?>
<a class="btn btn-mini btn-primary useCursorPointer" title="<?php echo __('Update the template of this object to the newer version: ') . h($newer_template_version) ?>" href="<?php echo $baseurl . '/objects/edit/' . h($object['Object']['id']) . '/1'; ?>">
<span class="fa fa-arrow-circle-up"></span>
<?php echo __('Update template') ?>
</a>
<?php endif; ?>
&nbsp;
</dd>
<dt><?php echo __('Description');?></dt>
@ -165,6 +170,64 @@
echo $this->Form->end();
?>
</div>
<?php if ($updateTemplate): //add control panel (same as distribution network) and fill with data ?>
<div class="fixedRightPanel" style="width: unset; height:unset;">
<div style="box-shadow: 0px 0px 6px #B2B2B2;margin-bottom: 2px;width: 100%;height: 40px;overflow: hidden;"><h5 style="margin-left: 5px;"><?php echo __('Pre-update object'); ?></h5></div>
<div class="row" style="max-height: 800px; overflow-y: auto;">
<div style="border: 1px solid #3465a4 ; border-radius: 5px;" class="span5">
<div class="blueElement" style="padding: 4px 5px;">
<div>
<span class="bold"><?php echo __('ID') . ':'; ?></span>
<a href="<?php echo $baseurl . '/objects/edit/' . h($object['Object']['id']); ?>" style="color: white;"><?php echo h($object['Object']['id']); ?></a>
</div>
<div>
<span class="bold"><?php echo __('Name') . ':'; ?></span>
<span><?php echo h($object['Object']['name']); ?></span>
</div>
<div>
<span class="bold"><?php echo __('Description') . ':'; ?></span>
<span><?php echo h($object['Object']['description']); ?></span><br>
</div>
<div>
<span class="bold"><?php echo __('Distribution') . ':'; ?></span>
<span><?php echo h($object['Object']['distribution']); ?></span>
</div>
<div style="border-radius: 3px;">
<span class="bold"><?php echo __('Template version') . ':'; ?></span>
<span><?php echo h($object['Object']['template_version']); ?></span>
</div>
</div>
<table class="table table-striped table-condensed" style="margin-bottom: 0px;">
<tbody>
<?php foreach ($object['Attribute'] as $attribute): ?>
<tr class="error" title="<?php echo __('Can not be merged automatically'); ?>">
<td><?php echo h($attribute['object_relation']); ?></td>
<td><?php echo h($attribute['category']); ?></td>
<td><?php echo h($attribute['type']); ?></td>
<td><?php echo h($attribute['value']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<table class="table table-striped table-condensed" style="margin-bottom: 0px;">
<tbody>
<?php foreach ($object['Attribute'] as $attribute): ?>
<tr class="success" title="<?php echo __('Can be merged automatically. Injection done.'); ; ?>">
<td><?php echo h($attribute['object_relation']); ?></td>
<td><?php echo h($attribute['category']); ?></td>
<td><?php echo h($attribute['type']); ?></td>
<td><?php echo h($attribute['value']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php endif; ?>
<?php
if (!$ajax) {
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'event', 'menuItem' => 'addObject', 'event' => $event));

View File

@ -126,7 +126,7 @@
$temp_text = __('Update template and merge');
} else if ($temp_comparison == 'above') {
$btn_style = 'btn-danger';
$temp_text = __('Can\'t merge do to template version');
$temp_text = __('Can\'t merge due to template version');
} else {
$temp_text = __('Merge');
$btn_style = 'btn-success';

View File

@ -144,19 +144,6 @@ label.center-in-network-header {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#fff9f9f9', GradientType=0);
}
.advancedSharingNetwork {
position: fixed;
top: 45px;
right: 0px;
height: 800px;
width: 800px;
background: #ffffffcc;;
z-index: 1;
border: 1px solid #0088cc;
border-radius: 6px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.sharingNetworkOrgFinder {
position: absolute !important;
right: 30px !important;

View File

@ -2270,3 +2270,16 @@ table tr:hover .down-expand-button {
margin-left:2px;
color: black;
}
.fixedRightPanel {
position: fixed;
top: 45px;
right: 0px;
height: 800px;
width: 800px;
background: #ffffffcc;;
z-index: 1;
border: 1px solid #0088cc;
border-radius: 6px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

View File

@ -255,7 +255,7 @@
var allow_interactive_picking = $('#attributes_div table tr').length > 0;
var $div = '<div id="sharingNetworkWrapper" class="advancedSharingNetwork hidden">'
var $div = '<div id="sharingNetworkWrapper" class="fixedRightPanel hidden">'
+ '<div class="eventgraph_header" style="border-radius: 5px; display: flex;">'
+ '<it class="fa fa-circle-o" style="margin: auto 10px; font-size: x-large"></it>'
+ '<input type="text" id="sharingNetworkTargetId" class="center-in-network-header network-typeahead" style="width: 200px;" disabled></input>';