<commit_before>/*
 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

var deviceId = $(".device-id");
var deviceIdentifier = deviceId.data("deviceid");
var deviceType = deviceId.data("type");
var deviceOwner = deviceId.data("owner");

$(document).ready(function() {
    $(".panel-body").removeClass("hidden");
    $("#loading-content").remove();

    if ($('#event_log').length) {
        loadOperationsLog();
    }

    if ($('#policy_compliance').length) {
        loadPolicyCompliance();
    }

    $("#refresh-policy").click(function() {
        $('#policy-spinner').removeClass('hidden');
        loadPolicyCompliance();
    });

    $("#refresh-operations").click(function() {
        $('#operations-spinner').removeClass('hidden');
        loadOperationsLog(true);
    });

    $("#refresh-apps").click(function() {
        $('#apps-spinner').removeClass('hidden');
        loadApplicationsList();
    });

});

function getLogStatusIcon(entry) {
    switch (entry) {
        case 'COMPLETED':
            return 'fw-success';
        case 'PENDING':
            return 'fw-pending';
        case 'ERROR':
            return 'fw-error';
        default:
            return 'fw-info'
    }
}

function loadOperationsLog(update) {
    var operationsLogTable = "#operation-log";
    if (update) {
        operationTable = $(operationsLogTable).DataTable();
        $("#operations-spinner").removeClass("hidden");
        operationTable.ajax.reload(function(json) {
            $("#operations-spinner").addClass("hidden");
        }, false);
        return;
    }
    var table = $('#operation-log').DataTable({
        serverSide: true,
        processing: false,
        searching: false,
        ordering: false,
        pageLength: 10,
        order: [],
        autoWidth: false,
        ajax: {
            url: "/devicemgt/api/operation/paginate",
            data: {
                deviceId: deviceIdentifier,
                deviceType: deviceType,
                owner: deviceOwner
            },
            dataSrc: function(json) {
                $("#operations-spinner").addClass("hidden");
                return json.data;
            }
        },
        columnDefs: [{
                targets: 0,
                data: "code",
                class: "icon-only content-fill"
            },
            {
                targets: 1,
                data: "createdTimeStamp",
                class: "text-right",
                render: function(date) {
                    var value = String(date);
                    return value.slice(0, 16);
                }
            },
            {
                targets: 2,
                data: "status",
                class: "text-right extended-log-data log-record-status",
                render: function(data, type, full, meta) {
                    return '<i class="icon fw ' + getLogStatusIcon(data) +  '"> </i><span> ' + data + ' </span><i class="icon fw fw-down"></i>';
                },
                width: "100%"
            }
        ],
        fnCreatedRow: function(nRow, aData, iDataIndex) {
            $('td:eq(0)', nRow)
                .attr('data-search', aData.Device_Type)
                .attr('data-display', aData.Device_Type)
                .addClass(' icon-only content-fill');

            $('td:eq(1), td:eq(2)', nRow).addClass('text-right');
            $('td:eq(2)', nRow).addClass('log-record-status')

        }
    });

    $('#operation-log tbody').on('click', 'td.extended-log-data', function() {
        var tr = $(this).closest('tr');
        var row = table.row(tr);
        var rowData = row.data()
        var deviceid = $('.device-id').data('deviceid');
        var deviceType = $('.device-id').data('type');
        var uri = "/api/device-mgt/v1.0/activities/" + rowData.activityId + "/" + deviceType + "/" + deviceid;
        var contentType = "application/json";

        if (row.child.isShown()) {
            row.child.hide();
            tr.find('i.fw-up').removeClass('fw-up').addClass('fw-down');
            $(row.child()).removeClass('log-data-row');
            tr.removeClass('shown');
        } else {
            invokerUtil.get(uri,(payload) => {
                row.child(renderLogDetails(row.data(),payload)).show();
                tr.find('i.fw-down').removeClass('fw-down').addClass('fw-up');
                $(row.child()).addClass('log-data-row');
                tr.addClass('shown');
            },(error) => {

            },contentType);<commit_msg>Update operation status header on click<commit_after>/*
 * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

var deviceId = $(".device-id");
var deviceIdentifier = deviceId.data("deviceid");
var deviceType = deviceId.data("type");
var deviceOwner = deviceId.data("owner");

$(document).ready(function() {
    $(".panel-body").removeClass("hidden");
    $("#loading-content").remove();

    if ($('#event_log').length) {
        loadOperationsLog();
    }

    if ($('#policy_compliance').length) {
        loadPolicyCompliance();
    }

    $("#refresh-policy").click(function() {
        $('#policy-spinner').removeClass('hidden');
        loadPolicyCompliance();
    });

    $("#refresh-operations").click(function() {
        $('#operations-spinner').removeClass('hidden');
        loadOperationsLog(true);
    });

    $("#refresh-apps").click(function() {
        $('#apps-spinner').removeClass('hidden');
        loadApplicationsList();
    });

});

function getLogStatusIcon(entry) {
    switch (entry) {
        case 'COMPLETED':
            return 'fw-success';
        case 'PENDING':
            return 'fw-pending';
        case 'ERROR':
            return 'fw-error';
        default:
            return 'fw-info'
    }
}

function loadOperationsLog(update) {
    var operationsLogTable = "#operation-log";
    if (update) {
        operationTable = $(operationsLogTable).DataTable();
        $("#operations-spinner").removeClass("hidden");
        operationTable.ajax.reload(function(json) {
            $("#operations-spinner").addClass("hidden");
        }, false);
        return;
    }
    var table = $('#operation-log').DataTable({
        serverSide: true,
        processing: false,
        searching: false,
        ordering: false,
        pageLength: 10,
        order: [],
        autoWidth: false,
        ajax: {
            url: "/devicemgt/api/operation/paginate",
            data: {
                deviceId: deviceIdentifier,
                deviceType: deviceType,
                owner: deviceOwner
            },
            dataSrc: function(json) {
                $("#operations-spinner").addClass("hidden");
                return json.data;
            }
        },
        columnDefs: [{
                targets: 0,
                data: "code",
                class: "icon-only content-fill"
            },
            {
                targets: 1,
                data: "createdTimeStamp",
                class: "text-right",
                render: function(date) {
                    var value = String(date);
                    return value.slice(0, 16);
                }
            },
            {
                targets: 2,
                data: "status",
                class: "text-right extended-log-data log-record-status",
                render: function(data, type, full, meta) {
                    return '<i class="icon fw ' + getLogStatusIcon(data) +  '"> </i><span> ' + data + ' </span><i class="icon fw fw-down"></i>';
                },
                width: "100%"
            }
        ],
        fnCreatedRow: function(nRow, aData, iDataIndex) {
            $('td:eq(0)', nRow)
                .attr('data-search', aData.Device_Type)
                .attr('data-display', aData.Device_Type)
                .addClass(' icon-only content-fill');

            $('td:eq(1), td:eq(2)', nRow).addClass('text-right');
            $('td:eq(2)', nRow).addClass('log-record-status')

        }
    });

    $('#operation-log tbody').on('click', 'td.extended-log-data', function() {
        var tr = $(this).closest('tr');
        var row = table.row(tr);
        var rowData = row.data()
        var deviceid = $('.device-id').data('deviceid');
        var deviceType = $('.device-id').data('type');
        var uri = "/api/device-mgt/v1.0/activities/" + rowData.activityId + "/" + deviceType + "/" + deviceid;
        var contentType = "application/json";
        var index = row[0][0];

        if (row.child.isShown()) {
            row.child.hide();
            tr.find('i.fw-up').removeClass('fw-up').addClass('fw-down');
            $(row.child()).removeClass('log-data-row');
            tr.removeClass('shown');
        } else {
            invokerUtil.get(uri,(payload) => {
                //update the parent status
                var payloadObject = JSON.parse(payload);
                if ( payloadObject["activityStatus"][0]["status"] != rowData["status"] ) {
                    rowData["status"] = payloadObject["activityStatus"][0]["status"];
                    $('#operation-log').dataTable().fnUpdate(rowData,index,undefined,false);
                }

                row.child(renderLogDetails(row.data(),payload)).show();
                tr.find('i.fw-down').removeClass('fw-down').addClass('fw-up');
                $(row.child()).addClass('log-data-row');
                tr.addClass('shown');
            },(error) => {

            },contentType);
{'fraction_non_alphanumeric': 0.1591377694470478, 'fraction_numerical': 0.005623242736644799, 'mean_word_length': 1.9372419488026424, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5534173', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2903, 'n_words': 612}