From d5eb868186fd6f672aaf23a2bcd6fe8b36266986 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 4 Apr 2025 21:44:18 +0500 Subject: [PATCH] fix showwpsites --- .../websiteFunctions/websiteFunctions.js | 116 +++++++++++++----- .../websiteFunctions/listWebsites.html | 12 +- 2 files changed, 92 insertions(+), 36 deletions(-) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index a12105241..5b042f691 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -2675,11 +2675,21 @@ app.controller('listWebsites', function ($scope, $http, $window) { $scope.getFurtherWebsitesFromDB(); $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + var url = '/websites/fetchWPDetails'; var data = { domain: domain }; + console.log('Making request to:', url, 'with data:', data); + $http({ method: 'POST', url: url, @@ -2689,17 +2699,26 @@ app.controller('listWebsites', function ($scope, $http, $window) { 'X-CSRFToken': getCookie('csrftoken') } }).then(function(response) { + console.log('Response received:', response); if (response.data.status === 1 && response.data.fetchStatus === 1) { - $scope.web.wp_sites = response.data.sites; - $scope.web.showWPSites = true; + // Find the website in the list and update its properties + $scope.WebSitesList.forEach(function(website) { + if (website.domain === domain) { + website.wp_sites = response.data.sites; + website.showWPSites = true; + console.log('Updated website:', website); + } + }); $("#listFail").hide(); } else { $("#listFail").fadeIn(); $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); } }).catch(function(error) { $("#listFail").fadeIn(); $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + console.error('Request failed:', error); }); }; @@ -6048,31 +6067,51 @@ app.controller('listWebsites', function ($scope, $http, $window) { // Call it immediately $scope.getFurtherWebsitesFromDB(); - $scope.Sites = function(domain) { + $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + var url = '/websites/fetchWPDetails'; var data = { - domain: domain + domain: domain }; + + console.log('Making request to:', url, 'with data:', data); + $http({ - method: 'POST', - url: url, - data: $.param(data), - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'X-CSRFToken': getCookie('csrftoken') - } + method: 'POST', + url: url, + data: $.param(data), + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'X-CSRFToken': getCookie('csrftoken') + } }).then(function(response) { - if (response.data.status === 1 && response.data.fetchStatus === 1) { - $scope.web.wp_sites = response.data.sites; - $scope.web.showWPSites = true; - $("#listFail").hide(); - } else { - $("#listFail").fadeIn(); - $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; - } + console.log('Response received:', response); + if (response.data.status === 1 && response.data.fetchStatus === 1) { + // Find the website in the list and update its properties + $scope.WebSitesList.forEach(function(website) { + if (website.domain === domain) { + website.wp_sites = response.data.sites; + website.showWPSites = true; + console.log('Updated website:', website); + } + }); + $("#listFail").hide(); + } else { + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); + } }).catch(function(error) { - $("#listFail").fadeIn(); - $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + console.error('Request failed:', error); }); }; @@ -9944,11 +9983,21 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind } $scope.showWPSites = function(domain) { + console.log('showWPSites called for domain:', domain); + + // Make sure domain is defined + if (!domain) { + console.error('Domain is undefined'); + return; + } + var url = '/websites/fetchWPDetails'; var data = { domain: domain }; + console.log('Making request to:', url, 'with data:', data); + $http({ method: 'POST', url: url, @@ -9958,21 +10007,26 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind 'X-CSRFToken': getCookie('csrftoken') } }).then(function(response) { + console.log('Response received:', response); if (response.data.status === 1 && response.data.fetchStatus === 1) { - var sites = response.data.sites; - var message = 'WordPress Sites for ' + domain + ':\n\n'; - sites.forEach(function(site) { - message += 'Title: ' + site.title + '\n'; - message += 'URL: ' + site.url + '\n'; - message += 'Version: ' + site.version + '\n'; - message += 'Status: ' + site.status + '\n\n'; + // Find the website in the list and update its properties + $scope.WebSitesList.forEach(function(website) { + if (website.domain === domain) { + website.wp_sites = response.data.sites; + website.showWPSites = true; + console.log('Updated website:', website); + } }); - alert(message); + $("#listFail").hide(); } else { - alert('Error: ' + response.data.error_message); + $("#listFail").fadeIn(); + $scope.errorMessage = response.data.error_message || 'Failed to fetch WordPress sites'; + console.error('Error in response:', response.data.error_message); } }).catch(function(error) { - alert('Error fetching WordPress sites: ' + JSON.stringify(error)); + $("#listFail").fadeIn(); + $scope.errorMessage = error.message || 'An error occurred while fetching WordPress sites'; + console.error('Request failed:', error); }); }; diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index 370e2a94a..b9e58588f 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -101,11 +101,13 @@
- - - {$ web.wp_sites.length $} WordPress Sites - + + + + {$ web.wp_sites.length $} WordPress Sites + +