Autosave: 20260302-080601
This commit is contained in:
parent
b1016e2a54
commit
f2aacc643f
@ -62,47 +62,10 @@ $instance = $engine->getInstanceByDefId($person_id, $process_definition_id);
|
|||||||
<strong><?= t('modal.process_completed', 'Proces zakończony.') ?></strong>
|
<strong><?= t('modal.process_completed', 'Proces zakończony.') ?></strong>
|
||||||
Obecny status: <?= htmlspecialchars($instance['current_status']) ?>.
|
Obecny status: <?= htmlspecialchars($instance['current_status']) ?>.
|
||||||
</div>
|
</div>
|
||||||
<button id="startNewProcessBtn" class="btn btn-sm btn-primary" data-person-id="<?= $person_id ?>" data-process-id="<?= $process_definition_id ?>">
|
<button id="restartProcessBtn" class="btn btn-sm btn-primary" data-person-id="<?= $person_id ?>" data-process-code="<?= htmlspecialchars($process['code']) ?>" data-mode="create_new_run">
|
||||||
<?= t('modal.start_new_instance', 'Rozpocznij od nowa') ?>
|
<?= t('modal.start_new_instance', 'Rozpocznij od nowa') ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
document.getElementById('startNewProcessBtn')?.addEventListener('click', function() {
|
|
||||||
const personId = this.getAttribute('data-person-id');
|
|
||||||
const processId = this.getAttribute('data-process-id');
|
|
||||||
if (confirm('Czy na pewno chcesz rozpocząć nową instancję tego procesu? Dotychczasowa historia pozostanie, ale proces rozpocznie się od nowa.')) {
|
|
||||||
fetch('_init_single_instance.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: 'person_id=' + personId + '&process_id=' + processId + '&force=1'
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
// Reload the modal content
|
|
||||||
fetch('_get_instance_details.php?person_id=' + personId + '&process_id=' + processId)
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(html => {
|
|
||||||
document.querySelector('#instanceModal .modal-body').innerHTML = html;
|
|
||||||
// Trigger custom event to re-attach handlers and update title
|
|
||||||
const event = new Event('instanceModalLoaded');
|
|
||||||
document.querySelector('#instanceModal .modal-body').dispatchEvent(event);
|
|
||||||
// Set a flag to refresh the matrix when the modal closes
|
|
||||||
window.matrixNeedsRefresh = true;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
alert('Błąd: ' + (data.error || 'Nieznany błąd'));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
alert('Wystąpił błąd podczas uruchamiania nowej instancji.');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php
|
<?php
|
||||||
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;
|
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;
|
||||||
|
|||||||
@ -1,21 +1,22 @@
|
|||||||
import re
|
with open('index.php', 'r', encoding='utf-8') as f:
|
||||||
|
|
||||||
with open('index.php', 'r') as f:
|
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
patch_code = """
|
start_str = " const instanceModalElement = document.getElementById('instanceModal');\n if (instanceModalElement) {\n instanceModalElement.addEventListener('click', function(event) {\n const btn = event.target.closest('#startProcessBtn');\n if (!btn) return;"
|
||||||
instanceModalElement.addEventListener('hidden.bs.modal', function () {
|
end_str = " });\n }"
|
||||||
if (window.matrixNeedsRefresh) {
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
"""
|
|
||||||
|
|
||||||
content = content.replace("});\n</script>", patch_code)
|
start_idx = content.find(start_str)
|
||||||
|
if start_idx != -1:
|
||||||
with open('index.php', 'w') as f:
|
end_idx = content.find(end_str, start_idx)
|
||||||
f.write(content)
|
if end_idx != -1:
|
||||||
|
end_idx += len(end_str)
|
||||||
print("Patched index.php")
|
|
||||||
|
replacement = " const instanceModalElement = document.getElementById('instanceModal');\n if (instanceModalElement) {\n instanceModalElement.addEventListener('click', function(event) {\n const startBtn = event.target.closest('#startProcessBtn');\n const restartBtn = event.target.closest('#restartProcessBtn');\n const btn = startBtn || restartBtn;\n if (!btn) return;\n \n event.preventDefault();\n event.stopPropagation();\n \n const isRestart = !!restartBtn;\n \n const personId = btn.dataset.personId;\n const processId = btn.dataset.processId;\n const processCode = btn.dataset.processCode;\n \n if (!personId) {\n alert('Brak ID osoby');\n return;\n }\n if (isRestart && !processCode) {\n alert('Brak kodu procesu');\n return;\n }\n if (!isRestart && !processId) {\n alert('Brak ID procesu');\n return;\n }\n \n const originalText = btn.innerHTML;\n btn.disabled = true;\n btn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>...';\n \n const formData = new FormData();\n formData.append('person_id', personId);\n \n if (isRestart) {\n formData.append('process_code', processCode);\n formData.append('mode', 'create_new_run');\n } else {\n formData.append('process_id', processId);\n }\n \n if (instanceModalElement && processId) {\n instanceModalElement.dataset.lastPersonId = personId;\n instanceModalElement.dataset.lastProcessId = processId;\n }\n \n fetch('_init_single_instance.php', {\n method: 'POST',\n body: formData\n })\n .then(async response => {\n let data;\n try {\n data = await response.json();\n } catch (e) {\n throw new Error(`Błąd serwera (HTTP ${response.status}): Nieoczekiwany błąd (invalid JSON)`);\n }\n \n if (!response.ok || !data.success) {\n let errMsg = data?.error?.message || data?.error || 'Nieznany błąd';\n if (data?.correlation_id) {\n errMsg += ` (ID błędu: ${data.correlation_id})`;\n }\n throw new Error(errMsg);\n }\n return data;\n })\n .then(data => {\n const modalBody = instanceModalElement.querySelector('.modal-body');\n modalBody.innerHTML = '<div class="text-center mt-4"><div class="spinner-border text-primary" role="status"></div><p class="mt-2">Ładowanie...</p></div>';\n \n const refreshProcessId = data.process_definition_id || processId || instanceModalElement.dataset.lastProcessId;\n if (refreshProcessId) {\n instanceModalElement.dataset.lastProcessId = refreshProcessId;\n }\n \n fetch(`_get_instance_details.php?person_id=${personId}&process_id=${refreshProcessId}`)\n .then(r => r.text())\n .then(html => {\n modalBody.innerHTML = html;\n window.matrixNeedsRefresh = true;\n });\n })\n .catch(err => {\n console.error(err);\n alert(err.message || 'Błąd sieci');\n btn.disabled = false;\n btn.innerHTML = originalText;\n });\n });\n }"
|
||||||
|
|
||||||
|
new_content = content[:start_idx] + replacement + content[end_idx:]
|
||||||
|
with open('index.php', 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
print("Replaced index.php block successfully.")
|
||||||
|
else:
|
||||||
|
print("End string not found.")
|
||||||
|
else:
|
||||||
|
print("Start string not found.")
|
||||||
|
|||||||
@ -1,73 +1,17 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
with open('_get_instance_details.php', 'r') as f:
|
with open('_get_instance_details.php', 'r', encoding='utf-8') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
patch_code = """<?php if ($instance): // INSTANCE EXISTS ?>
|
pattern = r'<button id="startNewProcessBtn"([^>]+)>.*?</button>\s*</div>\s*<script>.*?</script>'
|
||||||
<?php
|
replacement = r'''<button id="restartProcessBtn" class="btn btn-sm btn-primary" data-person-id="<?= $person_id ?>" data-process-code="<?= htmlspecialchars($process['code']) ?>" data-mode="create_new_run">
|
||||||
$instanceId = $instance['id'];
|
|
||||||
$isCompleted = in_array($instance['current_status'], ['completed', 'positive', 'negative', 'error']);
|
|
||||||
?>
|
|
||||||
<?php if ($isCompleted): ?>
|
|
||||||
<div class="alert alert-info d-flex justify-content-between align-items-center">
|
|
||||||
<div>
|
|
||||||
<strong><?= t('modal.process_completed', 'Proces zakończony.') ?></strong>
|
|
||||||
Obecny status: <?= htmlspecialchars($instance['current_status']) ?>.
|
|
||||||
</div>
|
|
||||||
<button id="startNewProcessBtn" class="btn btn-sm btn-primary" data-person-id="<?= $person_id ?>" data-process-id="<?= $process_definition_id ?>">
|
|
||||||
<?= t('modal.start_new_instance', 'Rozpocznij od nowa') ?>
|
<?= t('modal.start_new_instance', 'Rozpocznij od nowa') ?>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>'''
|
||||||
<script>
|
|
||||||
document.getElementById('startNewProcessBtn')?.addEventListener('click', function() {
|
|
||||||
const personId = this.getAttribute('data-person-id');
|
|
||||||
const processId = this.getAttribute('data-process-id');
|
|
||||||
if (confirm('Czy na pewno chcesz rozpocząć nową instancję tego procesu? Dotychczasowa historia pozostanie, ale proces rozpocznie się od nowa.')) {
|
|
||||||
fetch('_init_single_instance.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
|
||||||
body: 'person_id=' + personId + '&process_id=' + processId + '&force=1'
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
// Reload the modal content
|
|
||||||
fetch('_get_instance_details.php?person_id=' + personId + '&process_id=' + processId)
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(html => {
|
|
||||||
document.getElementById('instanceModalBody').innerHTML = html;
|
|
||||||
// Trigger custom event to re-attach handlers and update title
|
|
||||||
const event = new Event('instanceModalLoaded');
|
|
||||||
document.getElementById('instanceModalBody').dispatchEvent(event);
|
|
||||||
// Set a flag to refresh the matrix when the modal closes
|
|
||||||
window.matrixNeedsRefresh = true;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
alert('Błąd: ' + (data.error || 'Nieznany błąd'));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
alert('Wystąpił błąd podczas uruchamiania nowej instancji.');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<?php endif; ?>
|
|
||||||
<?php
|
|
||||||
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;"""
|
|
||||||
|
|
||||||
content = content.replace(
|
new_content, count = re.subn(pattern, replacement, content, flags=re.DOTALL)
|
||||||
"""<?php if ($instance): // INSTANCE EXISTS ?>
|
|
||||||
<?php
|
|
||||||
$instanceId = $instance['id'];
|
|
||||||
$definition = $process['definition_json'] ? json_decode($process['definition_json'], true) : null;""",
|
|
||||||
patch_code
|
|
||||||
)
|
|
||||||
|
|
||||||
with open('_get_instance_details.php', 'w') as f:
|
with open('_get_instance_details.php', 'w', encoding='utf-8') as f:
|
||||||
f.write(content)
|
f.write(new_content)
|
||||||
|
|
||||||
print("Patched.")
|
print(f"Replaced {count} instances.")
|
||||||
Loading…
x
Reference in New Issue
Block a user