Newer
Older
function showAdminUserLogsWindow(id) {
// Calculate dates we going to need
var today = new Date();
var firstOfMonth = today.getFirstDateOfMonth();
var firstOfNext = today.getLastDateOfMonth().add(Date.DAY, 1);
var adminUserLogsWindow = new Ext.ux.GenericGridWindow(
Robert Anderson
committed
title: 'Logs',
layout:'border',
height: 480,
width: 700,
minHeight: 480,
minWidth: 700,
closable: true,
plain: true,
uxItems: [
{
xtype: 'form',
id: 'search-form',
title: 'Search',
region: 'west',
border: true,
frame: true,
defaultType: 'datefield',
height: 180,
labelWidth: 100,
items: [
{
id: 'after',
name: 'after',
width: 180,
fieldLabel: 'From',
format: 'Y-m-d',
value: firstOfMonth,
},
{
id: 'before',
name: 'before',
width: 180,
fieldLabel: 'To',
format: 'Y-m-d',
value: firstOfNext,
startDateField: 'after'
}
],
buttons: [
{
text: 'Search',
id: 'formbtn',
handler: function() {
// Pull in window, grid & form
var mainWindow = this.ownerCt.ownerCt;
var grid = mainWindow.getComponent('gridpanel');
var form = mainWindow.getComponent('search-form');
// Grab store
var store = grid.getStore();
// Grab timestamp filter
var gridFilters = grid.filters;
Robert Anderson
committed
var timestampFilter = gridFilters.getFilter('EventTimestamp');
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Grab form fields
var afterField = form.getForm().findField('after');
var beforeField = form.getForm().findField('before');
// Set filter values from form
timestampFilter.setValue({
after: afterField.getValue(),
before: beforeField.getValue()
});
// Trigger store reload
store.reload();
}
}
],
buttonAlign: 'center'
},
{
xtype: 'form',
id: 'summary-form',
region: 'center',
split: true,
border: true,
autoScroll: true,
defaultType: 'textarea',
height: 180,
width: 400,
labelWidth: 80,
items: [
{
id: 'summaryTotal',
name: 'summaryTotal',
readOnly: true,
height: 139,
width: 275,
fieldLabel: 'Summary',
fieldClass: 'font-family: monospace; font-size: 10px;',
value: ''
}
]
}
]
},
// Grid config
{
region: 'south',
width: 700,
border: true,
// Column model
colModel: new Ext.grid.ColumnModel([
Robert Anderson
committed
{
header: "ID",
hidden: true,
dataIndex: 'ID'
},
header: "Timestamp",
sortable: true,
dataIndex: 'EventTimestamp'
},
{
header: "Status",
sortable: true,
Robert Anderson
committed
hidden: true,
header: "Framed Protocol",
sortable: true,
dataIndex: 'FramedProtocol'
Robert Anderson
committed
hidden: true,
dataIndex: 'NASPortType'
},
{
header: "Calling Station",
sortable: true,
dataIndex: 'CallingStationID'
},
{
Robert Anderson
committed
hidden: true,
Robert Anderson
committed
hidden: true,
Robert Anderson
committed
header: "IP Address",
hidden: true,
Robert Anderson
committed
},
{
header: "Input Mbyte",
dataIndex: 'AcctInputMbyte'
},
{
header: "Output Mbyte",
dataIndex: 'AcctOutputMbyte'
},
{
header: "Session Uptime",
dataIndex: 'AcctSessionTime'
},
{
header: "Term. Reason",
dataIndex: 'ConnectTermReason'
Robert Anderson
committed
}
])
},
// Store config
{
baseParams: {
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUserLogs',
SOAPFunction: 'getAdminUserLogs',
SOAPParams: 'ID,__search'
}
},
// Filter config
{
filters: [
Robert Anderson
committed
{type: 'numeric', dataIndex: 'ID'},
value: {
after: firstOfMonth,
before: firstOfNext
}
{type: 'numeric', dataIndex: 'AcctStatusType'},
{type: 'numeric', dataIndex: 'ServiceType'},
{type: 'numeric', dataIndex: 'FramedProtocol'},
{type: 'numeric', dataIndex: 'NASPortType'},
{type: 'string', dataIndex: 'NASPortID'},
{type: 'string', dataIndex: 'CallingStationID'},
{type: 'string', dataIndex: 'CalledStationID'},
{type: 'string', dataIndex: 'AcctSessionID'},
Robert Anderson
committed
{type: 'string', dataIndex: 'FramedIPAddress'},
{type: 'numeric', dataIndex: 'AcctInputMbyte'},
{type: 'numeric', dataIndex: 'AcctOutputMbyte'},
{type: 'numeric', dataIndex: 'AcctSessionTime'},
Robert Anderson
committed
{type: 'string', dataIndex: 'ConnectTermReason'}
var store = adminUserLogsWindow.getComponent('gridpanel').getStore();
store.on('load',function() {
var inputTotal = store.sum('AcctInputMbyte');
var outputTotal = store.sum('AcctOutputMbyte');
var uptimeTotal = store.sum('AcctSessionTime');
var searchForm = adminUserLogsWindow.getComponent('search-form');
var afterField = (searchForm.getForm().findField('after')).getValue();
var beforeField = (searchForm.getForm().findField('before')).getValue();
// Mask parent window
adminUserLogsWindow.getEl().mask();
uxAjaxRequest(
adminUserLogsWindow,
{
params: {
From: afterField,
To: beforeField,
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUserLogs',
SOAPFunction: 'getAdminUserLogsSummary',
SOAPParams: '0:ID,0:From,0:To'
},
customSuccess: function (result) {
response = Ext.decode(result.responseText);
// Traffic variables
var trafficCap = response.data.trafficCap; // value of -1: prepaid
var trafficCurrentTopupUsed = response.data.trafficCurrentTopupUsed; // value of -1: no current topup
var trafficCurrentTopupCap = response.data.trafficCurrentTopupCap; // value of -1: no current topup
var trafficTopupRemaining = response.data.trafficTopupRemaining;
// Uptime variables
var uptimeCap = response.data.uptimeCap; // value of -1: prepaid
var uptimeCurrentTopupUsed = response.data.uptimeCurrentTopupUsed; // value of -1: no current topup
var uptimeCurrentTopupCap = response.data.uptimeCurrentTopupCap; // value of -1: no current topup
var uptimeTopupRemaining = response.data.uptimeTopupRemaining;
// Total up traffic
var trafficTotalAllowed;
var validTrafficTopups;
if (trafficCurrentTopupCap > 0) {
validTrafficTopups = trafficCurrentTopupCap;
validTrafficTopups += trafficTopupRemaining;
} else {
validTrafficTopups = trafficTopupRemaining;
}
if (trafficCap < 0) {
trafficTotalAllowed = validTrafficTopups;
} else {
trafficTotalAllowed = trafficCap + validTrafficTopups;
}
// Traffic usage
var trafficUsage = inputTotal + outputTotal;
// Total up uptime
var uptimeTotalAllowed;
var validUptimeTopups;
if (uptimeCurrentTopupCap > 0) {
validUptimeTopups = uptimeCurrentTopupCap;
validUptimeTopups += uptimeTopupRemaining;
} else {
validUptimeTopups = uptimeTopupRemaining;
}
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
if (uptimeCap < 0) {
uptimeTotalAllowed = validUptimeTopups;
} else {
uptimeTotalAllowed = uptimeCap + validUptimeTopups;
}
// Get summary field
var form = adminUserLogsWindow.getComponent('summary-form');
var summaryTotal = form.getForm().findField('summaryTotal');
// Format string before printing
var trafficString = '';
// Prepaid traffic
if (trafficCap == -1) {
trafficCap = 'Prepaid';
trafficString += sprintf(' Traffic\nCap: %s MB Topup: %d MB\n'+
'Usage: %d/%d MB\n=====================================\n',
trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed);
// Uncapped traffic
} else if (trafficCap == 0) {
trafficString += sprintf(' Traffic\nCap: Uncapped Used: %d\n=====================================n',
trafficUsage);
// Capped traffic
} else {
trafficString += sprintf(' Traffic\nCap: %d MB Topup: %d MB\n'+
'Usage: %d/%d MB\n=====================================\n',
trafficCap,validTrafficTopups,trafficUsage,trafficTotalAllowed);
}
// Format string before printing
var uptimeString = '';
// Prepaid uptime
if (uptimeCap == -1) {
uptimeCap = 'Prepaid';
uptimeString += sprintf(' Uptime\nCap: %s MB Topup: %d MB\n'+
'Usage: %d/%d MB',
uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed);
// Uncapped uptime
} else if (uptimeCap == 0) {
uptimeString += sprintf(' Uptime\nCap: Uncapped Used: %d',
uptimeTotal);
// Capped uptime
} else {
uptimeString += sprintf(' Uptime\nCap: %d MB Topup: %d MB\n'+
'Usage: %d/%d MB',
uptimeCap,validUptimeTopups,uptimeTotal,uptimeTotalAllowed);
}
summaryTotal.setValue(trafficString+uptimeString);
},
failure: function (result) {
Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date);
},
}
);