Skip to content
Permalink
Browse files

list websites: choose to show number of records

  • Loading branch information...
usmannasir committed Aug 18, 2019
1 parent 01b588f commit 97b5bd0e702e5fe02138bb33f47fc4ebd93f7795
@@ -231,57 +231,34 @@ $("#listFail").hide();
app.controller('listWebsites', function ($scope, $http) {


url = "/websites/submitWebsiteListing";
$scope.currentPage = 1;
$scope.recordsToShow = 10;

var data = {page: 1};

var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);


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) {
$scope.getFurtherWebsitesFromDB = function () {

var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};

var data = {page: pageNumber};
var data = {
page: $scope.currentPage,
recordsToShow: $scope.recordsToShow
};


dataurl = "/websites/submitWebsiteListing";
dataurl = "/websites/fetchWebsitesList";

$http.post(dataurl, data, config).then(ListInitialData, cantLoadInitialData);


function ListInitialData(response) {
if (response.data.listWebSiteStatus === 1) {

var finalData = JSON.parse(response.data.data);
$scope.WebSitesList = finalData;
$scope.WebSitesList = JSON.parse(response.data.data);
$scope.pagination = response.data.pagination;
$scope.clients = JSON.parse(response.data.data);
$("#listFail").hide();
} else {
$("#listFail").fadeIn();
@@ -291,11 +268,11 @@ app.controller('listWebsites', function ($scope, $http) {
}

function cantLoadInitialData(response) {
console.log("not good");
}


};
$scope.getFurtherWebsitesFromDB();

$scope.cyberPanelLoading = true;

@@ -21,11 +21,22 @@ <h2 id="domainNamePage">{% trans "List Websites" %}</h2> <img ng-hide="cyberPane
<p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p>
</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"
class="form-control" required>
</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"
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;">
<div class="">
@@ -124,16 +135,20 @@ <h2 style="display: inline; color: #414C59;" ng-bind="web.domain"></h2>
</div>
</div>
</div>
<div class="row text-center">
<div class="col-sm-11">
<nav aria-label="Page navigation">
<ul class="pagination">
{% for items in pagination %}
<li ng-click="getFurtherWebsitesFromDB({{ forloop.counter }})" id="webPages"><a
href="">{{ forloop.counter }}</a></li>
{% endfor %}
</ul>
</nav>
<div style="margin-top: 2%" class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-9">
</div>
<div class="col-md-3">
<div class="form-group">
<select ng-model="currentPage" class="form-control"
ng-change="getFurtherWebsitesFromDB()">
<option ng-repeat="page in pagination">{$ $index + 1 $}</option>
</select>
</div>
</div>
</div> <!-- end row -->
</div>
</div>

@@ -17,6 +17,7 @@
url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'),
url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'),
url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
url(r'^fetchWebsitesList$', views.fetchWebsitesList, name='fetchWebsitesList'),
url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'),
url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'),
url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'),
@@ -125,6 +125,14 @@ def getFurtherAccounts(request):
except KeyError:
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):
try:
userID = request.session['userID']
@@ -334,6 +334,86 @@ def getFurtherAccounts(self, userID=None, data=None):
json_data = json.dumps(dic)
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):
try:

0 comments on commit 97b5bd0

Please sign in to comment.
You can’t perform that action at this time.