Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // View
- [CustomAuthorize(Roles = "admin")]
- public ActionResult Log()
- {
- Log model = new Log();
- return View(model);
- }
- // List
- [System.Web.Mvc.HttpGet]
- [System.Web.Mvc.Authorize(Roles = "admin")]
- public JsonResult GetLog(DataTablesParam param)
- {
- return Json(
- new
- {
- aaData = new PagedList<Log>(appContext.Logs.OrderByDescending(m => m.Id), (param.iDisplayStart / param.iDisplayLength) + 1, param.iDisplayLength)
- }
- , JsonRequestBehavior.AllowGet);
- }
- // View
- <script type="text/javascript">
- var table;
- $(document).ready(function () {
- $("#signalrbutton").click(function () {
- $("#signalrModal").modal({ show: true });
- $("#signalrrefresh").click();
- });
- $("#signalrrefresh").click(function () {
- $.ajax({
- method: "GET",
- contenttype: "application/x-www-form-urlencoded",
- url: "@Url.Action("SignalRClients", "Administrace")"
- })
- .success(function (html) {
- $("#signalrclients-holder").html(html);
- });
- });
- table = $('#logs').dataTable({
- "bDestroy": true,
- "bProcessing": true,
- "bServerSide": true,
- "sAjaxSource": '@Url.Action("GetLog", "Administrace")',
- "sScrollX": "100%",
- "sScrollXInner": "100%",
- "bScrollCollapse": true,
- "iDisplayLength": 25,
- "order": [[0, "desc"]],
- "aoColumns":
- [
- {
- "mData": "ActionDate",
- "mRender": function (data, type, full) {
- if (type === 'set') {
- var dtStart = new Date(parseInt(data.substr(6)));
- var dtStartWrapper = moment(dtStart);
- return dtStartWrapper.format('D.M.YYY H:mm:ss');
- }
- else if (type === 'display' || type === 'filter') {
- var dtStart = new Date(parseInt(data.substr(6)));
- var dtStartWrapper = moment(dtStart);
- return dtStartWrapper.format('D.M.YYYY H:mm:ss');
- }
- else {
- return data;
- }
- },
- "bSearchable": true,
- "bSortable": true
- },
- {
- "mData": "ActionName",
- "bSearchable": true,
- "bSortable": true
- },
- {
- "mData": "ActionMessage",
- "bSearchable": true,
- "bSortable": true
- },
- {
- "mData": "User",
- "bSearchable": true,
- "bSortable": true
- },
- {
- "mData": "RemoteIP",
- "bSearchable": true,
- "bSortable": true,
- },
- {
- "mData": "Browser",
- "bSearchable": true,
- "bSortable": true,
- }
- @if (Context.User.IsInRole("superadmin"))
- {
- <text>
- , {
- "mData": "Id",
- "mRender": function (data, type, full) {
- var button = '<button onclick="DeleteLog(' + data + ')" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-remove"></span> Smazat</button>';
- return button;
- },
- "bSearchable": false,
- "bSortable": false,
- }
- </text>
- }
- ],
- "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
- if (aData.ActionName == "Chyba") {
- $('td', nRow).addClass("danger");
- } else if (aData.ActionName == "SignalR") {
- $('td', nRow).addClass("warning");
- }
- },
- language: {
- processing: '',
- search: "Hledat:",
- lengthMenu: "Počet výsledků na stránku: _MENU_",
- info: "Zobrazuji _START_ z _END_ z _TOTAL_ výsledků",
- infoEmpty: "Nenalezena žádná data",
- infoFiltered: "(filtrováno z celkového počtu _MAX_ výsledků)",
- infoPostFix: "",
- loadingRecords: '<img src="/Images/loading.gif" height=32/> ',
- zeroRecords: "Nenalezena žádná data",
- emptyTable: "Nenalezena žádná data",
- paginate: {
- first: "První",
- previous: "Předchozí",
- next: "Další",
- last: "Poslední"
- },
- },
- "sPaginationType": "full_numbers"
- });
- });
- <table id="logs" class="table table-hover">
- <thead>
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.ActionDate)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.ActionName)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.ActionMessage)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.User)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.RemoteIP)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Browser)
- </th>
- @if (Context.User.IsInRole("superadmin"))
- {
- <th>
- Smazat
- </th>
- }
- </tr>
- </thead>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement