update payment plan settings
This commit is contained in:
@@ -1118,7 +1118,7 @@ def save_instance():
|
||||
rooms_count=0,
|
||||
conversations_count=0,
|
||||
data_size=0.0,
|
||||
payment_plan='Basic',
|
||||
payment_plan=data.get('payment_plan', 'Basic'),
|
||||
main_url=f"https://{data['domains'][0]}" if data['domains'] else f"http://localhost:{data['port']}",
|
||||
status=data['status'],
|
||||
portainer_stack_id=data['stack_id'],
|
||||
|
||||
@@ -593,6 +593,9 @@ async function startLaunch(data) {
|
||||
// Save instance data
|
||||
await updateStep(10, 'Saving Instance Data', 'Storing instance information...');
|
||||
try {
|
||||
// Get the launch data from sessionStorage to access pricing tier info
|
||||
const launchData = JSON.parse(sessionStorage.getItem('instanceLaunchData') || '{}');
|
||||
|
||||
const instanceData = {
|
||||
name: data.instanceName,
|
||||
port: data.port,
|
||||
@@ -603,7 +606,8 @@ async function startLaunch(data) {
|
||||
repository: data.repository,
|
||||
branch: data.branch,
|
||||
deployed_version: dockerComposeResult.latest_tag || dockerComposeResult.commit_hash || 'unknown',
|
||||
deployed_branch: data.branch
|
||||
deployed_branch: data.branch,
|
||||
payment_plan: launchData.pricingTier?.name || 'Basic' // Use the selected pricing tier name
|
||||
};
|
||||
console.log('Saving instance data:', instanceData);
|
||||
const saveResult = await saveInstanceData(instanceData);
|
||||
@@ -2046,28 +2050,45 @@ async function saveInstanceData(instanceData) {
|
||||
|
||||
if (existingInstance) {
|
||||
console.log('Instance already exists:', instanceData.port);
|
||||
// Update existing instance with new data
|
||||
const updateResponse = await fetch('/api/admin/save-instance', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: instanceData.port,
|
||||
port: instanceData.port,
|
||||
domains: instanceData.domains,
|
||||
stack_id: instanceData.stack_id || '',
|
||||
stack_name: instanceData.stack_name,
|
||||
status: instanceData.status,
|
||||
repository: instanceData.repository,
|
||||
branch: instanceData.branch,
|
||||
deployed_version: instanceData.deployed_version,
|
||||
deployed_branch: instanceData.deployed_branch,
|
||||
payment_plan: instanceData.payment_plan || 'Basic'
|
||||
})
|
||||
});
|
||||
|
||||
if (!updateResponse.ok) {
|
||||
const errorText = await updateResponse.text();
|
||||
console.error('Error updating instance:', errorText);
|
||||
throw new Error(`Failed to update instance data: ${updateResponse.status} ${updateResponse.statusText}`);
|
||||
}
|
||||
|
||||
const updateResult = await updateResponse.json();
|
||||
console.log('Instance updated:', updateResult);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
name: instanceData.port,
|
||||
company: 'loading...',
|
||||
rooms_count: 0,
|
||||
conversations_count: 0,
|
||||
data_size: 0.0,
|
||||
payment_plan: 'Basic',
|
||||
main_url: `https://${instanceData.domains[0]}`,
|
||||
status: 'inactive',
|
||||
port: instanceData.port,
|
||||
stack_id: instanceData.stack_id || '', // Use empty string if null
|
||||
stack_name: instanceData.stack_name,
|
||||
repository: instanceData.repository,
|
||||
branch: instanceData.branch
|
||||
}
|
||||
data: updateResult.data
|
||||
};
|
||||
}
|
||||
|
||||
// If instance doesn't exist, create it
|
||||
const response = await fetch('/instances/add', {
|
||||
const response = await fetch('/api/admin/save-instance', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -2075,18 +2096,16 @@ async function saveInstanceData(instanceData) {
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: instanceData.port,
|
||||
company: 'loading...',
|
||||
rooms_count: 0,
|
||||
conversations_count: 0,
|
||||
data_size: 0.0,
|
||||
payment_plan: 'Basic',
|
||||
main_url: `https://${instanceData.domains[0]}`,
|
||||
status: 'inactive',
|
||||
port: instanceData.port,
|
||||
stack_id: instanceData.stack_id || '', // Use empty string if null
|
||||
domains: instanceData.domains,
|
||||
stack_id: instanceData.stack_id || '',
|
||||
stack_name: instanceData.stack_name,
|
||||
status: instanceData.status,
|
||||
repository: instanceData.repository,
|
||||
branch: instanceData.branch
|
||||
branch: instanceData.branch,
|
||||
deployed_version: instanceData.deployed_version,
|
||||
deployed_branch: instanceData.deployed_branch,
|
||||
payment_plan: instanceData.payment_plan || 'Basic'
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
<td>{{ instance.rooms_count }}</td>
|
||||
<td>{{ instance.conversations_count }}</td>
|
||||
<td>{{ "%.1f"|format(instance.data_size) }} GB</td>
|
||||
<td>{{ instance.payment_plan }}</td>
|
||||
<td id="payment-plan-{{ instance.id }}">{{ instance.payment_plan }}</td>
|
||||
<td>
|
||||
<a href="{{ instance.main_url }}"
|
||||
target="_blank"
|
||||
@@ -2490,5 +2490,50 @@ function validateStep6() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// For each instance row, fetch the payment plan from the instance API
|
||||
document.querySelectorAll('[data-instance-id]').forEach(function(badge) {
|
||||
const instanceId = badge.getAttribute('data-instance-id');
|
||||
const token = badge.getAttribute('data-token');
|
||||
const row = badge.closest('tr');
|
||||
const urlCell = row.querySelector('td:nth-child(7) a');
|
||||
const paymentPlanCell = document.getElementById('payment-plan-' + instanceId);
|
||||
|
||||
if (!urlCell || !token || !paymentPlanCell) return;
|
||||
const instanceUrl = urlCell.getAttribute('href');
|
||||
|
||||
// Get management token
|
||||
fetch(instanceUrl.replace(/\/$/, '') + '/api/admin/management-token', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-API-Key': token,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (!data.token) throw new Error('No management token');
|
||||
// Fetch version info (which includes pricing_tier_name)
|
||||
return fetch(instanceUrl.replace(/\/$/, '') + '/api/admin/version-info', {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + data.token,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.pricing_tier_name) {
|
||||
paymentPlanCell.textContent = data.pricing_tier_name;
|
||||
} else {
|
||||
paymentPlanCell.textContent = 'Unknown';
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
paymentPlanCell.textContent = 'Unknown';
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user