Skip to content

Commit

Permalink
Convert listing to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
bochoven committed Jul 3, 2019
1 parent 9e6a184 commit 82d81aa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 114 deletions.
14 changes: 14 additions & 0 deletions js/format_appusage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var appNameToLink = function(colNumber, row){
var col = $('td:eq('+colNumber+')', row),
appName = col.text();
col.html($('<a>').attr('href', appUrl+'/module/inventory/items/'+appName).text(appName))
}

var localizeEvent = function(colNumber, row){
var col = $('td:eq('+colNumber+')', row),
event = col.text();
event = event == 'launch' ? i18n.t('appusage.launch') :
event = event == 'activate' ? i18n.t('appusage.activation') :
(event === 'quit' ? i18n.t('appusage.quit') : '')
col.text(event)
}
164 changes: 50 additions & 114 deletions views/appusage_listing.php
Original file line number Diff line number Diff line change
@@ -1,114 +1,50 @@
<?php $this->view('partials/head'); ?>

<?php
//Initialize models needed for the table
new Machine_model;
new Reportdata_model;
new Appusage_model;
?>

<div class="container">
<div class="row">
<div class="col-lg-12">
<h3><span data-i18n="appusage.appusagereport"></span> <span id="total-count" class='label label-primary'>…</span></h3>

<table class="table table-striped table-condensed table-bordered">
<thead>
<tr>
<th data-i18n="listing.computername" data-colname='machine.computer_name'></th>
<th data-i18n="serial" data-colname='reportdata.serial_number'></th>
<th data-i18n="appusage.event" data-colname='appusage.event'></th>
<th data-i18n="appusage.appname" data-colname='appusage.app_name'></th>
<th data-i18n="appusage.lastevent" data-colname='appusage.last_time_epoch'></th>
<th data-i18n="appusage.count" data-colname='appusage.number_times'></th>
<th data-i18n="version" data-colname='appusage.app_version'></th>
<th data-i18n="path" data-colname='appusage.app_path'></th>
<th data-i18n="bundle_id" data-colname='appusage.bundle_id'></th>
</tr>
</thead>
<tbody>
<tr>
<td data-i18n="listing.loading" colspan="9" class="dataTables_empty"></td>
</tr>
</tbody>
</table>
</div> <!-- /span 12 -->
</div> <!-- /row -->
</div> <!-- /container -->

<script type="text/javascript">

$(document).on('appUpdate', function(e){

var oTable = $('.table').DataTable();
oTable.ajax.reload();
return;

});

$(document).on('appReady', function(e, lang) {

// Get modifiers from data attribute
var mySort = [], // Initial sort
hideThese = [], // Hidden columns
col = 0, // Column counter
runtypes = [], // Array for runtype column
columnDefs = [{ visible: false, targets: hideThese }]; //Column Definitions

$('.table th').map(function(){

columnDefs.push({name: $(this).data('colname'), targets: col});

if($(this).data('sort')){
mySort.push([col, $(this).data('sort')])
}

if($(this).data('hide')){
hideThese.push(col);
}

col++
});

oTable = $('.table').dataTable( {
ajax: {
url: appUrl + '/datatables/data',
type: "POST",
data: function(d){
d.mrColNotEmpty = "app_name";
}
},
dom: mr.dt.buttonDom,
buttons: mr.dt.buttons,
order: mySort,
columnDefs: columnDefs,
createdRow: function( nRow, aData, iDataIndex ) {
// Update name in first column to link
var name=$('td:eq(0)', nRow).html();
if(name == ''){name = "No Name"};
var sn=$('td:eq(1)', nRow).html();
var link = mr.getClientDetailLink(name, sn, '#tab_appusage-tab');
$('td:eq(0)', nRow).html(link);

// Format date
var event = parseInt($('td:eq(4)', nRow).html());
var date = new Date(event * 1000);
$('td:eq(4)', nRow).html('<span title="' + moment(date).format('llll') + '">'+moment(date).fromNow()+'</span>');

// Get name link
var appname=$('td:eq(3)', nRow).html();
$('td:eq(3)', nRow).html($('<a>').attr('href', appUrl+'/module/inventory/items/'+appname).text(appname))

// Event type
var autoreset=$('td:eq(2)', nRow).html();
autoreset = autoreset == 'launch' ? i18n.t('appusage.launch') :
autoreset = autoreset == 'activate' ? i18n.t('appusage.activation') :
(autoreset === 'quit' ? i18n.t('appusage.quit') : '')
$('td:eq(2)', nRow).html(autoreset)

}
} );
} );
</script>

<?php $this->view('partials/foot'); ?>
<?php

$this->view('listings/default',
[
"i18n_title" => 'appusage.appusagereport',
"not_null_column" => "app_name",
"js_link" => "module/appusage/js/format_appusage",
"table" => [
[
"column" => "machine.computer_name",
"i18n_header" => "listing.computername",
"formatter" => "clientDetail",
],
[
"column" => "reportdata.serial_number",
"i18n_header" => "serial",
],
[
"column" => "appusage.event",
"i18n_header" => "appusage.event",
"formatter" => "appNlocalizeEventameToLink",
],
[
"column" => "appusage.app_name",
"i18n_header" => "appusage.appname",
"formatter" => "appNameToLink",
],
[
"column" => "appusage.last_time_epoch",
"i18n_header" => "appusage.lastevent",
"formatter" => "timestampToMoment",
],
[
"column" => "appusage.number_times",
"i18n_header" => "appusage.count",
],
[
"column" => "appusage.app_version",
"i18n_header" => "version",
],
[
"column" => "appusage.app_path",
"i18n_header" => "path",
],
[
"column" => "appusage.bundle_id",
"i18n_header" => "bundle_id",
],
]
]);

0 comments on commit 82d81aa

Please sign in to comment.