Skip to content

Commit 97b5bd0

Browse files
committed
list websites: choose to show number of records
1 parent 01b588f commit 97b5bd0

File tree

5 files changed

+127
-46
lines changed

5 files changed

+127
-46
lines changed

websiteFunctions/static/websiteFunctions/websiteFunctions.js

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -231,57 +231,34 @@ $("#listFail").hide();
231231
app.controller('listWebsites', function ($scope, $http) {
232232

233233

234-
url = "/websites/submitWebsiteListing";
234+
$scope.currentPage = 1;
235+
$scope.recordsToShow = 10;
235236

236-
var data = {page: 1};
237-
238-
var config = {
239-
headers: {
240-
'X-CSRFToken': getCookie('csrftoken')
241-
}
242-
};
243-
244-
$http.post(url, data, config).then(ListInitialData, cantLoadInitialData);
245-
246-
247-
function ListInitialData(response) {
248-
249-
if (response.data.listWebSiteStatus === 1) {
250-
var finalData = JSON.parse(response.data.data);
251-
$scope.WebSitesList = finalData;
252-
$scope.pagination = response.data.pagination;
253-
$("#listFail").hide();
254-
} else {
255-
$("#listFail").fadeIn();
256-
$scope.errorMessage = response.data.error_message;
257-
258-
}
259-
}
260-
261-
function cantLoadInitialData(response) {
262-
}
263-
264-
$scope.getFurtherWebsitesFromDB = function (pageNumber) {
237+
$scope.getFurtherWebsitesFromDB = function () {
265238

266239
var config = {
267240
headers: {
268241
'X-CSRFToken': getCookie('csrftoken')
269242
}
270243
};
271244

272-
var data = {page: pageNumber};
245+
var data = {
246+
page: $scope.currentPage,
247+
recordsToShow: $scope.recordsToShow
248+
};
273249

274250

275-
dataurl = "/websites/submitWebsiteListing";
251+
dataurl = "/websites/fetchWebsitesList";
276252

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

279255

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

283-
var finalData = JSON.parse(response.data.data);
284-
$scope.WebSitesList = finalData;
259+
$scope.WebSitesList = JSON.parse(response.data.data);
260+
$scope.pagination = response.data.pagination;
261+
$scope.clients = JSON.parse(response.data.data);
285262
$("#listFail").hide();
286263
} else {
287264
$("#listFail").fadeIn();
@@ -291,11 +268,11 @@ app.controller('listWebsites', function ($scope, $http) {
291268
}
292269

293270
function cantLoadInitialData(response) {
294-
console.log("not good");
295271
}
296272

297273

298274
};
275+
$scope.getFurtherWebsitesFromDB();
299276

300277
$scope.cyberPanelLoading = true;
301278

websiteFunctions/templates/websiteFunctions/listWebsites.html

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ <h2 id="domainNamePage">{% trans "List Websites" %}</h2> <img ng-hide="cyberPane
2121
<p>{% trans "On this page you can launch, list, modify and delete websites from your server." %}</p>
2222
</div>
2323

24-
<div class="col-sm-12" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
24+
<div class="col-sm-10" style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
2525
<input ng-change="searchWebsites()" placeholder="Search..." ng-model="patternAdded" name="dom" type="text"
2626
class="form-control" required>
2727
</div>
2828

29+
<div class="col-sm-2">
30+
<div class="form-group">
31+
<select ng-model="recordsToShow" ng-change="getFurtherWebsitesFromDB()"
32+
class="form-control" id="example-select">
33+
<option>10</option>
34+
<option>50</option>
35+
<option>100</option>
36+
</select>
37+
</div>
38+
</div>
39+
2940
<div ng-repeat="web in WebSitesList track by $index" class="panel col-md-12"
3041
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888;">
3142
<div class="">
@@ -124,16 +135,20 @@ <h2 style="display: inline; color: #414C59;" ng-bind="web.domain"></h2>
124135
</div>
125136
</div>
126137
</div>
127-
<div class="row text-center">
128-
<div class="col-sm-11">
129-
<nav aria-label="Page navigation">
130-
<ul class="pagination">
131-
{% for items in pagination %}
132-
<li ng-click="getFurtherWebsitesFromDB({{ forloop.counter }})" id="webPages"><a
133-
href="">{{ forloop.counter }}</a></li>
134-
{% endfor %}
135-
</ul>
136-
</nav>
138+
<div style="margin-top: 2%" class="row">
139+
<div class="col-md-12">
140+
<div class="row">
141+
<div class="col-md-9">
142+
</div>
143+
<div class="col-md-3">
144+
<div class="form-group">
145+
<select ng-model="currentPage" class="form-control"
146+
ng-change="getFurtherWebsitesFromDB()">
147+
<option ng-repeat="page in pagination">{$ $index + 1 $}</option>
148+
</select>
149+
</div>
150+
</div>
151+
</div> <!-- end row -->
137152
</div>
138153
</div>
139154

websiteFunctions/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
url(r'^submitWebsiteCreation$', views.submitWebsiteCreation, name='submitWebsiteCreation'),
1818
url(r'^submitWebsiteDeletion$', views.submitWebsiteDeletion, name='submitWebsiteDeletion'),
1919
url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
20+
url(r'^fetchWebsitesList$', views.fetchWebsitesList, name='fetchWebsitesList'),
2021
url(r'^searchWebsites$', views.searchWebsites, name='searchWebsites'),
2122
url(r'^submitWebsiteModification$', views.deleteWebsite, name='submitWebsiteModification'),
2223
url(r'^submitWebsiteStatus$', views.submitWebsiteStatus, name='submitWebsiteStatus'),

websiteFunctions/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def getFurtherAccounts(request):
125125
except KeyError:
126126
return redirect(loadLoginPage)
127127

128+
def fetchWebsitesList(request):
129+
try:
130+
userID = request.session['userID']
131+
wm = WebsiteManager()
132+
return wm.fetchWebsitesList(userID, json.loads(request.body))
133+
except KeyError:
134+
return redirect(loadLoginPage)
135+
128136
def submitWebsiteDeletion(request):
129137
try:
130138
userID = request.session['userID']

websiteFunctions/website.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,86 @@ def getFurtherAccounts(self, userID=None, data=None):
334334
json_data = json.dumps(dic)
335335
return HttpResponse(json_data)
336336

337+
338+
def fetchWebsitesList(self, userID=None, data=None):
339+
try:
340+
currentACL = ACLManager.loadedACL(userID)
341+
pageNumber = int(data['page'])
342+
recordsToShow = int(data['recordsToShow'])
343+
344+
endPageNumber, finalPageNumber = self.recordsPointer(pageNumber, recordsToShow)
345+
websites = ACLManager.findWebsiteObjects(currentACL, userID)
346+
pagination = self.getPagination(len(websites), recordsToShow)
347+
json_data = self.findWebsitesListJson(websites[finalPageNumber:endPageNumber])
348+
349+
final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data,
350+
'pagination': pagination}
351+
final_json = json.dumps(final_dic)
352+
return HttpResponse(final_json)
353+
except BaseException, msg:
354+
dic = {'status': 1, 'listWebSiteStatus': 0, 'error_message': str(msg)}
355+
json_data = json.dumps(dic)
356+
return HttpResponse(json_data)
357+
358+
def findWebsitesListJson(self, websites):
359+
360+
json_data = "["
361+
checker = 0
362+
363+
try:
364+
ipFile = "/etc/cyberpanel/machineIP"
365+
f = open(ipFile)
366+
ipData = f.read()
367+
ipAddress = ipData.split('\n', 1)[0]
368+
except BaseException, msg:
369+
logging.CyberCPLogFileWriter.writeToFile("Failed to read machine IP, error:" + str(msg))
370+
ipAddress = "192.168.100.1"
371+
372+
for items in websites:
373+
if items.state == 0:
374+
state = "Suspended"
375+
else:
376+
state = "Active"
377+
378+
diskUsed = "%sMB" % str(virtualHostUtilities.getDiskUsage("/home/" + items.domain, items.package.diskSpace)[0])
379+
380+
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
381+
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, 'diskUsed': diskUsed}
382+
383+
if checker == 0:
384+
json_data = json_data + json.dumps(dic)
385+
checker = 1
386+
else:
387+
json_data = json_data + ',' + json.dumps(dic)
388+
389+
json_data = json_data + ']'
390+
391+
return json_data
392+
393+
def recordsPointer(self, page, toShow):
394+
finalPageNumber = ((page * toShow)) - toShow
395+
endPageNumber = finalPageNumber + toShow
396+
return endPageNumber, finalPageNumber
397+
398+
def getPagination(self, records, toShow):
399+
pages = float(records) / float(toShow)
400+
401+
pagination = []
402+
counter = 1
403+
404+
if pages <= 1.0:
405+
pages = 1
406+
pagination.append(counter)
407+
else:
408+
pages = ceil(pages)
409+
finalPages = int(pages) + 1
410+
411+
for i in range(1, finalPages):
412+
pagination.append(counter)
413+
counter = counter + 1
414+
415+
return pagination
416+
337417
def submitWebsiteDeletion(self, userID=None, data=None):
338418
try:
339419

0 commit comments

Comments
 (0)