front end for n8n version

This commit is contained in:
usmannasir
2025-04-12 20:04:16 +05:00
parent c1e3947769
commit 5dcf9d734b
5 changed files with 161 additions and 176 deletions

View File

@@ -347,4 +347,99 @@ app.controller('ListDockersitecontainer', function ($scope, $http) {
// Add location service to the controller for the n8n URL
$scope.location = window.location;
// Initialize n8n version info for containers
$scope.initializeN8nVersion = function(container) {
if (!container || !container.id) return;
$http({
method: 'POST',
url: '/docker/fetchN8nVersions',
data: {
container_id: container.id
}
}).then(function(response) {
if (response.data.status === 1) {
container.n8nVersion = {
current: response.data.current_version,
latest: response.data.latest_version,
updateAvailable: response.data.update_available
};
} else {
console.error('Error fetching n8n versions:', response.data.error_message);
}
}, function(error) {
console.error('Error fetching n8n versions:', error);
});
};
// Update n8n function
$scope.updateN8n = function(container) {
if (!container || container.updatingN8n) return;
container.updatingN8n = true;
// First stop the container
$http({
method: 'POST',
url: '/docker/stopContainer',
data: {
container_id: container.id,
name: container.name
}
}).then(function(response) {
if (response.data.status === 1) {
// Execute update command
return $http({
method: 'POST',
url: '/docker/executeCommand',
data: {
container_id: container.id,
command: 'npm install -g n8n@latest'
}
});
} else {
throw new Error('Failed to stop container');
}
}).then(function(response) {
if (response.data.status === 1) {
// Start the container back
return $http({
method: 'POST',
url: '/docker/startContainer',
data: {
container_id: container.id,
name: container.name
}
});
} else {
throw new Error('Failed to update n8n');
}
}).then(function(response) {
if (response.data.status === 1) {
// Refresh version info
$scope.initializeN8nVersion(container);
} else {
throw new Error('Failed to start container');
}
}).catch(function(error) {
console.error('Error updating n8n:', error);
}).finally(function() {
container.updatingN8n = false;
});
};
// Hook into existing container loading
var originalLunchcontainer = $scope.Lunchcontainer;
if (originalLunchcontainer) {
$scope.Lunchcontainer = function(containerId) {
var result = originalLunchcontainer(containerId);
// Initialize version info after container is loaded
if ($scope.web && $scope.web.environment &&
$scope.web.environment.some(function(env) { return env.includes('n8n'); })) {
$scope.initializeN8nVersion($scope.web);
}
return result;
};
}
});