mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 13:25:51 +01:00
list websites: choose to show number of records
This commit is contained in:
@@ -231,9 +231,10 @@ $("#listFail").hide();
|
|||||||
app.controller('listWebsites', function ($scope, $http) {
|
app.controller('listWebsites', function ($scope, $http) {
|
||||||
|
|
||||||
|
|
||||||
url = "/websites/submitWebsiteListing";
|
$scope.currentPage = 1;
|
||||||
|
$scope.recordsToShow = 10;
|
||||||
|
|
||||||
var data = {page: 1};
|
$scope.getFurtherWebsitesFromDB = function () {
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -241,38 +242,13 @@ app.controller('listWebsites', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
|
var data = {
|
||||||
|
page: $scope.currentPage,
|
||||||
|
recordsToShow: $scope.recordsToShow
|
||||||
function ListInitialData(response) {
|
|
||||||
|
|
||||||
if (response.data.listWebSiteStatus === 1) {
|
|
||||||
var finalData = JSON.parse(response.data.data);
|
|
||||||
$scope.WebSitesList = finalData;
|
|
||||||
$scope.pagination = response.data.pagination;
|
|
||||||
$("#listFail").hide();
|
|
||||||
} else {
|
|
||||||
$("#listFail").fadeIn();
|
|
||||||
$scope.errorMessage = response.data.error_message;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function cantLoadInitialData(response) {
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.getFurtherWebsitesFromDB = function (pageNumber) {
|
|
||||||
|
|
||||||
var config = {
|
|
||||||
headers: {
|
|
||||||
'X-CSRFToken': getCookie('csrftoken')
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var data = {page: pageNumber};
|
|
||||||
|
|
||||||
|
dataurl = "/websites/fetchWebsitesList";
|
||||||
dataurl = "/websites/submitWebsiteListing";
|
|
||||||
|
|
||||||
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);
|
||||||
|
|
||||||
@@ -280,8 +256,9 @@ app.controller('listWebsites', function ($scope, $http) {
|
|||||||
function ListInitialData(response) {
|
function ListInitialData(response) {
|
||||||
if (response.data.listWebSiteStatus === 1) {
|
if (response.data.listWebSiteStatus === 1) {
|
||||||
|
|
||||||
var finalData = JSON.parse(response.data.data);
|
$scope.WebSitesList = JSON.parse(response.data.data);
|
||||||
$scope.WebSitesList = finalData;
|
$scope.pagination = response.data.pagination;
|
||||||
|
$scope.clients = JSON.parse(response.data.data);
|
||||||
$("#listFail").hide();
|
$("#listFail").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#listFail").fadeIn();
|
$("#listFail").fadeIn();
|
||||||
@@ -291,11 +268,11 @@ app.controller('listWebsites', function ($scope, $http) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cantLoadInitialData(response) {
|
function cantLoadInitialData(response) {
|
||||||
console.log("not good");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
$scope.getFurtherWebsitesFromDB();
|
||||||
|
|
||||||
$scope.cyberPanelLoading = true;
|
$scope.cyberPanelLoading = true;
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,22 @@
|
|||||||
<p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p>
|
<p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-12" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
|
<div class="col-sm-10" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
|
||||||
<input ng-change="searchWebsites()" placeholder="Search..." ng-model="patternAdded" name="dom" type="text"
|
<input ng-change="searchWebsites()" placeholder="Search..." ng-model="patternAdded" name="dom" type="text"
|
||||||
class="form-control" required>
|
class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<div class="form-group">
|
||||||
|
<select ng-model="recordsToShow" ng-change="getFurtherWebsitesFromDB()"
|
||||||
|
class="form-control" id="example-select">
|
||||||
|
<option>10</option>
|
||||||
|
<option>50</option>
|
||||||
|
<option>100</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div ng-repeat="web in WebSitesList track by $index" class="panel col-md-12"
|
<div ng-repeat="web in WebSitesList track by $index" class="panel col-md-12"
|
||||||
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;">
|
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;">
|
||||||
<div class="">
|
<div class="">
|
||||||
@@ -124,16 +135,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row text-center">
|
<div style="margin-top: 2%" class="row">
|
||||||
<div class="col-sm-11">
|
<div class="col-md-12">
|
||||||
<nav aria-label="Page navigation">
|
<div class="row">
|
||||||
<ul class="pagination">
|
<div class="col-md-9">
|
||||||
{% for items in pagination %}
|
</div>
|
||||||
<li ng-click="getFurtherWebsitesFromDB({{ forloop.counter }})" id="webPages"><a
|
<div class="col-md-3">
|
||||||
href="">{{ forloop.counter }}</a></li>
|
<div class="form-group">
|
||||||
{% endfor %}
|
<select ng-model="currentPage" class="form-control"
|
||||||
</ul>
|
ng-change="getFurtherWebsitesFromDB()">
|
||||||
</nav>
|
<option ng-repeat="page in pagination">{$ $index + 1 $}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div> <!-- end row -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ urlpatterns = [
|
|||||||
url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'),
|
url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'),
|
||||||
url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'),
|
url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'),
|
||||||
url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
|
url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
|
||||||
|
url(r'^fetchWebsitesList$', views.fetchWebsitesList, name='fetchWebsitesList'),
|
||||||
url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'),
|
url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'),
|
||||||
url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'),
|
url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'),
|
||||||
url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'),
|
url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'),
|
||||||
|
|||||||
@@ -125,6 +125,14 @@ def getFurtherAccounts(request):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
|
def fetchWebsitesList(request):
|
||||||
|
try:
|
||||||
|
userID = request.session['userID']
|
||||||
|
wm = WebsiteManager()
|
||||||
|
return wm.fetchWebsitesList(userID, json.loads(request.body))
|
||||||
|
except KeyError:
|
||||||
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
def submitWebsiteDeletion(request):
|
def submitWebsiteDeletion(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
|
|||||||
@@ -334,6 +334,86 @@ class WebsiteManager:
|
|||||||
json_data = json.dumps(dic)
|
json_data = json.dumps(dic)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
|
||||||
|
def fetchWebsitesList(self, userID=None, data=None):
|
||||||
|
try:
|
||||||
|
currentACL = ACLManager.loadedACL(userID)
|
||||||
|
pageNumber = int(data['page'])
|
||||||
|
recordsToShow = int(data['recordsToShow'])
|
||||||
|
|
||||||
|
endPageNumber, finalPageNumber = self.recordsPointer(pageNumber, recordsToShow)
|
||||||
|
websites = ACLManager.findWebsiteObjects(currentACL, userID)
|
||||||
|
pagination = self.getPagination(len(websites), recordsToShow)
|
||||||
|
json_data = self.findWebsitesListJson(websites[finalPageNumber:endPageNumber])
|
||||||
|
|
||||||
|
final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data,
|
||||||
|
'pagination': pagination}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
except BaseException, msg:
|
||||||
|
dic = {'status': 1, 'listWebSiteStatus': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(dic)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def findWebsitesListJson(self, websites):
|
||||||
|
|
||||||
|
json_data = "["
|
||||||
|
checker = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
ipFile = "/etc/cyberpanel/machineIP"
|
||||||
|
f = open(ipFile)
|
||||||
|
ipData = f.read()
|
||||||
|
ipAddress = ipData.split('\n', 1)[0]
|
||||||
|
except BaseException, msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" + str(msg))
|
||||||
|
ipAddress = "192.168.100.1"
|
||||||
|
|
||||||
|
for items in websites:
|
||||||
|
if items.state == 0:
|
||||||
|
state = "Suspended"
|
||||||
|
else:
|
||||||
|
state = "Active"
|
||||||
|
|
||||||
|
diskUsed = "%sMB" % str(virtualHostUtilities.getDiskUsage("/home/" + items.domain, items.package.diskSpace)[0])
|
||||||
|
|
||||||
|
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
|
||||||
|
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, 'diskUsed': diskUsed}
|
||||||
|
|
||||||
|
if checker == 0:
|
||||||
|
json_data = json_data + json.dumps(dic)
|
||||||
|
checker = 1
|
||||||
|
else:
|
||||||
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
|
json_data = json_data + ']'
|
||||||
|
|
||||||
|
return json_data
|
||||||
|
|
||||||
|
def recordsPointer(self, page, toShow):
|
||||||
|
finalPageNumber = ((page * toShow)) - toShow
|
||||||
|
endPageNumber = finalPageNumber + toShow
|
||||||
|
return endPageNumber, finalPageNumber
|
||||||
|
|
||||||
|
def getPagination(self, records, toShow):
|
||||||
|
pages = float(records) / float(toShow)
|
||||||
|
|
||||||
|
pagination = []
|
||||||
|
counter = 1
|
||||||
|
|
||||||
|
if pages <= 1.0:
|
||||||
|
pages = 1
|
||||||
|
pagination.append(counter)
|
||||||
|
else:
|
||||||
|
pages = ceil(pages)
|
||||||
|
finalPages = int(pages) + 1
|
||||||
|
|
||||||
|
for i in range(1, finalPages):
|
||||||
|
pagination.append(counter)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
return pagination
|
||||||
|
|
||||||
def submitWebsiteDeletion(self, userID=None, data=None):
|
def submitWebsiteDeletion(self, userID=None, data=None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user