605 lines
28 KiB
HTML
605 lines
28 KiB
HTML
{% extends 'base.html' %}
|
|
{% load static %}
|
|
|
|
{% block title %}Delete Data Source - Hospital Management{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="content">
|
|
<div class="container-fluid">
|
|
<!-- Page Header -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-header">
|
|
<div class="page-title">
|
|
<h4>Delete Data Source</h4>
|
|
<h6>Confirm data source deletion</h6>
|
|
</div>
|
|
<div class="page-btn">
|
|
<a href="{% url 'analytics:data_source_detail' data_source.pk %}" class="btn btn-secondary">
|
|
<i class="fas fa-arrow-left me-1"></i>Back to Source
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<!-- Warning Alert -->
|
|
<div class="alert alert-warning alert-dismissible fade show" role="alert">
|
|
<div class="d-flex align-items-center">
|
|
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
|
|
<div>
|
|
<h5 class="alert-heading mb-1">Confirm Data Source Deletion</h5>
|
|
<p class="mb-0">This action will permanently remove the data source and all associated data. This cannot be undone.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Data Source Information -->
|
|
<div class="card">
|
|
<div class="card-header bg-warning text-dark">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-database me-2"></i>Data Source to be Deleted
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<div class="source-info">
|
|
<h4 class="text-warning">{{ data_source.name }}</h4>
|
|
<p class="text-muted mb-3">{{ data_source.description|default:"No description provided" }}</p>
|
|
|
|
<div class="row">
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Source Type:</label>
|
|
<span class="badge bg-primary">{{ data_source.get_source_type_display }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Status:</label>
|
|
{% if data_source.status == 'active' %}
|
|
<span class="badge bg-success">Active</span>
|
|
{% elif data_source.status == 'error' %}
|
|
<span class="badge bg-danger">Error</span>
|
|
{% else %}
|
|
<span class="badge bg-secondary">Inactive</span>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Records:</label>
|
|
<span class="text-muted">{{ data_source.record_count|default:"0"|floatformat:0 }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Last Sync:</label>
|
|
<span class="text-muted">
|
|
{% if data_source.last_sync %}
|
|
{{ data_source.last_sync|timesince }} ago
|
|
{% else %}
|
|
Never
|
|
{% endif %}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Created By:</label>
|
|
<span class="text-muted">{{ data_source.created_by|default:"System" }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<div class="info-item">
|
|
<label class="form-label">Created Date:</label>
|
|
<span class="text-muted">{{ data_source.created_at|date:"M d, Y" }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="source-preview-card">
|
|
<div class="preview-header">
|
|
<div class="source-icon">
|
|
{% if data_source.source_type == 'database' %}
|
|
<i class="fas fa-database fa-2x text-primary"></i>
|
|
{% elif data_source.source_type == 'api' %}
|
|
<i class="fas fa-plug fa-2x text-info"></i>
|
|
{% elif data_source.source_type == 'file' %}
|
|
<i class="fas fa-file fa-2x text-warning"></i>
|
|
{% elif data_source.source_type == 'stream' %}
|
|
<i class="fas fa-stream fa-2x text-success"></i>
|
|
{% endif %}
|
|
</div>
|
|
<h6>{{ data_source.get_source_type_display }}</h6>
|
|
</div>
|
|
<div class="preview-stats">
|
|
<div class="stat-item">
|
|
<span class="stat-value">{{ data_source.total_syncs|default:"0" }}</span>
|
|
<span class="stat-label">Total Syncs</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-value">{{ data_source.widgets_count|default:"0" }}</span>
|
|
<span class="stat-label">Widgets</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Impact Analysis -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title">
|
|
<i class="fas fa-chart-line me-2"></i>Deletion Impact
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h6 class="text-warning">What will be deleted:</h6>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-database text-warning me-2"></i>
|
|
Data source configuration
|
|
</div>
|
|
<span class="badge bg-warning rounded-pill">1</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-table text-warning me-2"></i>
|
|
Cached data records
|
|
</div>
|
|
<span class="badge bg-warning rounded-pill">{{ data_source.record_count|default:"0"|floatformat:0 }}</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-history text-warning me-2"></i>
|
|
Sync history
|
|
</div>
|
|
<span class="badge bg-warning rounded-pill">{{ data_source.total_syncs|default:"0" }}</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-chart-bar text-warning me-2"></i>
|
|
Associated widgets
|
|
</div>
|
|
<span class="badge bg-warning rounded-pill">{{ data_source.widgets_count|default:"0" }}</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h6 class="text-info">What will remain:</h6>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-server text-success me-2"></i>
|
|
Original data source
|
|
</div>
|
|
<span class="badge bg-success rounded-pill">Safe</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-tachometer-alt text-success me-2"></i>
|
|
Other dashboards
|
|
</div>
|
|
<span class="badge bg-success rounded-pill">Safe</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-users text-success me-2"></i>
|
|
User accounts
|
|
</div>
|
|
<span class="badge bg-success rounded-pill">Safe</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<i class="fas fa-cog text-success me-2"></i>
|
|
System settings
|
|
</div>
|
|
<span class="badge bg-success rounded-pill">Safe</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
{% if data_source.widgets_count > 0 %}
|
|
<div class="alert alert-danger mt-3">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>
|
|
<strong>Warning:</strong> This data source is used by {{ data_source.widgets_count }} widget{{ data_source.widgets_count|pluralize }}.
|
|
Deleting it will break these widgets and they will need to be reconfigured.
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Alternative Actions -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title">
|
|
<i class="fas fa-lightbulb me-2"></i>Alternative Actions
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="text-muted mb-3">Consider these alternatives before deleting the data source:</p>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="alternative-action">
|
|
<div class="action-icon">
|
|
<i class="fas fa-pause text-warning"></i>
|
|
</div>
|
|
<div class="action-content">
|
|
<h6>Deactivate Source</h6>
|
|
<p class="text-muted">Temporarily disable without deleting data.</p>
|
|
<button type="button" class="btn btn-outline-warning btn-sm" onclick="deactivateSource()">
|
|
<i class="fas fa-pause me-1"></i>Deactivate Instead
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="alternative-action">
|
|
<div class="action-icon">
|
|
<i class="fas fa-download text-info"></i>
|
|
</div>
|
|
<div class="action-content">
|
|
<h6>Export Data</h6>
|
|
<p class="text-muted">Download data before deletion.</p>
|
|
<button type="button" class="btn btn-outline-info btn-sm" onclick="exportData()">
|
|
<i class="fas fa-download me-1"></i>Export First
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row mt-3">
|
|
<div class="col-md-6">
|
|
<div class="alternative-action">
|
|
<div class="action-icon">
|
|
<i class="fas fa-copy text-success"></i>
|
|
</div>
|
|
<div class="action-content">
|
|
<h6>Backup Configuration</h6>
|
|
<p class="text-muted">Save configuration for future use.</p>
|
|
<button type="button" class="btn btn-outline-success btn-sm" onclick="backupConfig()">
|
|
<i class="fas fa-copy me-1"></i>Backup Config
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="alternative-action">
|
|
<div class="action-icon">
|
|
<i class="fas fa-edit text-primary"></i>
|
|
</div>
|
|
<div class="action-content">
|
|
<h6>Edit Source</h6>
|
|
<p class="text-muted">Modify instead of deleting.</p>
|
|
<a href="{% url 'analytics:data_source_update' data_source.pk %}" class="btn btn-outline-primary btn-sm">
|
|
<i class="fas fa-edit me-1"></i>Edit Instead
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmation Form -->
|
|
<div class="card border-warning">
|
|
<div class="card-header bg-warning text-dark">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>Confirm Deletion
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="post" id="deleteForm">
|
|
{% csrf_token %}
|
|
|
|
<div class="form-group">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="confirmUnderstand" name="confirm_understand" required>
|
|
<label class="form-check-label" for="confirmUnderstand">
|
|
I understand that this data source and all associated data will be permanently deleted.
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
{% if data_source.widgets_count > 0 %}
|
|
<div class="form-group">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="confirmWidgets" name="confirm_widgets" required>
|
|
<label class="form-check-label" for="confirmWidgets">
|
|
I understand that {{ data_source.widgets_count }} widget{{ data_source.widgets_count|pluralize }} will be affected and may stop working.
|
|
</label>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="form-group">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="confirmBackup" name="confirm_backup">
|
|
<label class="form-check-label" for="confirmBackup">
|
|
I have considered backing up the data or configuration.
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="deletionReason" class="form-label">Reason for Deletion (Optional):</label>
|
|
<select class="form-select" id="deletionReason" name="deletion_reason">
|
|
<option value="">Select a reason</option>
|
|
<option value="outdated">Data source is outdated</option>
|
|
<option value="duplicate">Duplicate data source</option>
|
|
<option value="not_needed">No longer needed</option>
|
|
<option value="migration">Migrating to new source</option>
|
|
<option value="security">Security concerns</option>
|
|
<option value="other">Other reason</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group" id="otherReasonGroup" style="display: none;">
|
|
<label for="otherReason" class="form-label">Please specify:</label>
|
|
<textarea class="form-control" id="otherReason" name="other_reason" rows="2"
|
|
placeholder="Please provide more details..."></textarea>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mt-4">
|
|
<div class="deletion-actions">
|
|
<a href="{% url 'analytics:data_source_detail' data_source.pk %}" class="btn btn-secondary me-2">
|
|
<i class="fas fa-times me-1"></i>Cancel
|
|
</a>
|
|
<a href="{% url 'analytics:data_source_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-list me-1"></i>Back to Sources
|
|
</a>
|
|
</div>
|
|
<button type="submit" class="btn btn-warning" id="deleteButton" disabled>
|
|
<i class="fas fa-trash me-1"></i>Delete Data Source
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const confirmUnderstand = document.getElementById('confirmUnderstand');
|
|
const confirmWidgets = document.getElementById('confirmWidgets');
|
|
const deleteButton = document.getElementById('deleteButton');
|
|
const deleteForm = document.getElementById('deleteForm');
|
|
const deletionReason = document.getElementById('deletionReason');
|
|
const otherReasonGroup = document.getElementById('otherReasonGroup');
|
|
|
|
// Enable/disable delete button based on confirmations
|
|
function updateDeleteButton() {
|
|
const understandChecked = confirmUnderstand.checked;
|
|
const widgetsChecked = confirmWidgets ? confirmWidgets.checked : true;
|
|
|
|
deleteButton.disabled = !(understandChecked && widgetsChecked);
|
|
}
|
|
|
|
confirmUnderstand.addEventListener('change', updateDeleteButton);
|
|
if (confirmWidgets) {
|
|
confirmWidgets.addEventListener('change', updateDeleteButton);
|
|
}
|
|
|
|
// Show/hide other reason field
|
|
deletionReason.addEventListener('change', function() {
|
|
if (this.value === 'other') {
|
|
otherReasonGroup.style.display = 'block';
|
|
} else {
|
|
otherReasonGroup.style.display = 'none';
|
|
}
|
|
});
|
|
|
|
// Form submission with confirmation
|
|
deleteForm.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const finalConfirm = confirm(
|
|
'Are you absolutely sure you want to delete this data source?\n\n' +
|
|
'This action cannot be undone and will permanently remove:\n' +
|
|
'- Data source configuration\n' +
|
|
'- All cached data\n' +
|
|
'- Sync history\n' +
|
|
'- Associated widgets\n\n' +
|
|
'Click OK to proceed or Cancel to abort.'
|
|
);
|
|
|
|
if (finalConfirm) {
|
|
// Show loading state
|
|
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Deleting...';
|
|
deleteButton.disabled = true;
|
|
|
|
// Simulate deletion process
|
|
setTimeout(() => {
|
|
alert('Data source deleted successfully!');
|
|
window.location.href = "{% url 'analytics:data_source_list' %}";
|
|
}, 2000);
|
|
}
|
|
});
|
|
});
|
|
|
|
function deactivateSource() {
|
|
if (confirm('Deactivate this data source instead of deleting it?')) {
|
|
alert('Data source deactivated successfully! You can reactivate it later.');
|
|
window.location.href = "{% url 'analytics:data_source_list' %}";
|
|
}
|
|
}
|
|
|
|
function exportData() {
|
|
if (confirm('Export all data from this source before deletion?')) {
|
|
alert('Data export started! You will receive a download link when ready.');
|
|
}
|
|
}
|
|
|
|
function backupConfig() {
|
|
if (confirm('Create a backup of the data source configuration?')) {
|
|
alert('Configuration backup created successfully!');
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.info-item {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.info-item label {
|
|
font-weight: 600;
|
|
margin-bottom: 5px;
|
|
display: block;
|
|
color: #2c3e50;
|
|
}
|
|
|
|
.source-preview-card {
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 8px;
|
|
background: white;
|
|
overflow: hidden;
|
|
height: 100%;
|
|
}
|
|
|
|
.preview-header {
|
|
background: #f8f9fa;
|
|
padding: 20px;
|
|
text-align: center;
|
|
border-bottom: 1px solid #e9ecef;
|
|
}
|
|
|
|
.source-icon {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.preview-header h6 {
|
|
margin: 0;
|
|
font-weight: 600;
|
|
color: #2c3e50;
|
|
}
|
|
|
|
.preview-stats {
|
|
padding: 20px;
|
|
display: flex;
|
|
justify-content: space-around;
|
|
}
|
|
|
|
.stat-item {
|
|
text-align: center;
|
|
}
|
|
|
|
.stat-value {
|
|
display: block;
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
color: #2c3e50;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 0.875rem;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.alternative-action {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
padding: 20px;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 8px;
|
|
background: #f8f9fa;
|
|
margin-bottom: 15px;
|
|
height: 100%;
|
|
}
|
|
|
|
.action-icon {
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 50%;
|
|
background: white;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-right: 15px;
|
|
font-size: 1.5rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.action-content {
|
|
flex: 1;
|
|
}
|
|
|
|
.action-content h6 {
|
|
margin: 0 0 8px 0;
|
|
font-weight: 600;
|
|
color: #2c3e50;
|
|
}
|
|
|
|
.action-content p {
|
|
margin-bottom: 12px;
|
|
font-size: 0.875rem;
|
|
}
|
|
|
|
.deletion-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
#deleteButton:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.source-preview-card {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.alternative-action {
|
|
flex-direction: column;
|
|
text-align: center;
|
|
}
|
|
|
|
.action-icon {
|
|
margin-right: 0;
|
|
margin-bottom: 15px;
|
|
align-self: center;
|
|
}
|
|
|
|
.deletion-actions {
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
width: 100%;
|
|
}
|
|
|
|
.deletion-actions .btn {
|
|
width: 100%;
|
|
}
|
|
|
|
#deleteButton {
|
|
width: 100%;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.preview-stats {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|