<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: After converting an XML dashboard to HTML, where do I add CSS and javascript files on the filesystem and reference the items in the HTML? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127346#M7538</link>
    <description>&lt;P&gt;omg i've been searching for the syntax of the script src="file location" for ages thank you greatly sir &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 27 May 2017 00:11:16 GMT</pubDate>
    <dc:creator>ewmin3m</dc:creator>
    <dc:date>2017-05-27T00:11:16Z</dc:date>
    <item>
      <title>After converting an XML dashboard to HTML, where do I add CSS and javascript files on the filesystem and reference the items in the HTML?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127344#M7536</link>
      <description>&lt;P&gt;I have created a XML dashboard and that works fine. I had splunk generate an HTML view of that dashboard so that I can add my own Javascript and CSS for a tree viewer. Now I'm working on the HTML that Splunk generated.&lt;/P&gt;

&lt;P&gt;My question is  &lt;STRONG&gt;"Where do i put the CSS and .js files on the filesystem and how do I reference the items in the HTML.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I have been using the path:            &lt;/P&gt;

&lt;PRE&gt;
 $SPLUNK_HOME/etc/apps/-appname-/appserver/static.
&lt;/PRE&gt;

&lt;OL&gt;
&lt;LI&gt;What path do I add to the in the HTML to get the CSS? I have been trying:
&lt;PRE&gt;&lt;/PRE&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;BR /&gt;
 2. To get the javascript I tried adding entries to the "LIBRARY REQUIREMENTS" section in the HTML but I did not know what to use for the path in the require([]) arrays.&lt;/P&gt;

&lt;P&gt;Same example HTML snippets would be great.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2015 03:25:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127344#M7536</guid>
      <dc:creator>paulgreenspan</dc:creator>
      <dc:date>2015-04-04T03:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: After converting an XML dashboard to HTML, where do I add CSS and javascript files on the filesystem and reference the items in the HTML?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127345#M7537</link>
      <description>&lt;P&gt;Hello! your &lt;STRONG&gt;js&lt;/STRONG&gt; and &lt;STRONG&gt;css&lt;/STRONG&gt; files remain where they were befor you generated the Html view: &lt;STRONG&gt;$SPLUNK_HOME/etc/apps/-appname-/appserver/static&lt;/STRONG&gt;. Except the html file which is automatically created into: &lt;STRONG&gt;$SPLUNK_HOME/etc/apps/-appname-/local/data/ui/html/&lt;/STRONG&gt; folder.&lt;/P&gt;

&lt;P&gt;Take a look at the example bellow and notice how my &lt;STRONG&gt;table_cell_highlighting.css&lt;/STRONG&gt; and &lt;STRONG&gt;table_cell_highlighting.js&lt;/STRONG&gt;   are called (at the top , and at the end of the html file respectively) in my  &lt;STRONG&gt;table_cell_highlithtn_html.html&lt;/STRONG&gt;. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;title&amp;gt;Table Cell Highlighting HTML | Splunk&amp;lt;/title&amp;gt;
    &amp;lt;link rel="shortcut icon" href="{{SPLUNKWEB_URL_PREFIX}}/static/img/favicon.ico" /&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="{{SPLUNKWEB_URL_PREFIX}}/static/css/build/bootstrap.min.css" /&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" media="all" href="{{SPLUNKWEB_URL_PREFIX}}/static/css/build/pages/dashboard-simple-bootstrap.min.css" /&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" media="all" href="{{SPLUNKWEB_URL_PREFIX}}/static/app/stephane_app/table_cell_highlighting.css" /&amp;gt;
    &amp;lt;!--[if IE 7]&amp;gt;&amp;lt;link rel="stylesheet" href="{{SPLUNKWEB_URL_PREFIX}}/static/css/sprites-ie7.css" /&amp;gt;&amp;lt;![endif]--&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body class="simplexml preload locale-en"&amp;gt;

&amp;lt;!-- 
BEGIN LAYOUT
This section contains the layout for the dashboard. Splunk uses proprietary
styles in &amp;lt;div&amp;gt; tags, similar to Bootstrap's grid system. 
--&amp;gt;
&amp;lt;a class="navSkip" href="#navSkip" tabindex="1"&amp;gt;Screen reader users, click here to skip the navigation bar&amp;lt;/a&amp;gt;
&amp;lt;div class="header"&amp;gt;
    &amp;lt;div id="placeholder-splunk-bar"&amp;gt;
        &amp;lt;a href="{{SPLUNKWEB_URL_PREFIX}}/app/launcher/home" class="brand" title="splunk &amp;amp;gt; listen to your data"&amp;gt;splunk&amp;lt;strong&amp;gt;&amp;amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div id="placeholder-app-bar"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;a id="navSkip"&amp;gt;&amp;lt;/a&amp;gt;
&amp;lt;div class="dashboard-body container-fluid main-section-body" data-role="main"&amp;gt;
    &amp;lt;div class="dashboard-header clearfix"&amp;gt;
        &amp;lt;h2&amp;gt;Table Cell Highlighting HTML&amp;lt;/h2&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="fieldset"&amp;gt;
        &amp;lt;div class="input input-timerangepicker" id="field1"&amp;gt;
            &amp;lt;label&amp;gt;Select a time:&amp;lt;/label&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="input input-dropdown" id="field2"&amp;gt;
            &amp;lt;label&amp;gt;index&amp;lt;/label&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="dashboard-row dashboard-row1"&amp;gt;
        &amp;lt;div class="dashboard-cell" style="width: 100%;"&amp;gt;
            &amp;lt;div class="dashboard-panel clearfix"&amp;gt;                
                &amp;lt;div class="panel-element-row"&amp;gt;
                    &amp;lt;div class="dashboard-element table" id="highlight" style="width: 100%"&amp;gt;
                        &amp;lt;div class="panel-head"&amp;gt;
                            &amp;lt;h3&amp;gt;Table of Count Sourcetypes Between $time_range.earliest$ and $time_range.latest$ for index= $index$&amp;lt;/h3&amp;gt;
                        &amp;lt;/div&amp;gt;
                        &amp;lt;div class="panel-body"&amp;gt;&amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div class="footer"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;!-- 
END LAYOUT
--&amp;gt;

&amp;lt;script src="{{SPLUNKWEB_URL_PREFIX}}/config?autoload=1"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="{{SPLUNKWEB_URL_PREFIX}}/static/js/i18n.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="{{SPLUNKWEB_URL_PREFIX}}/i18ncatalog?autoload=1"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="{{SPLUNKWEB_URL_PREFIX}}/static/js/build/simplexml.min/config.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;
require.config({
    baseUrl: "{{SPLUNKWEB_URL_PREFIX}}/static/js",
    waitSeconds: 0 // Disable require.js load timeout
});

//
// LIBRARY REQUIREMENTS
//
// In the require function, we include the necessary libraries and modules for
// the HTML dashboard. Then, we pass variable names for these libraries and
// modules as function parameters, in order.
// 
// When you add libraries or modules, remember to retain this mapping order
// between the library or module and its function parameter. You can do this by
// adding to the end of these lists, as shown in the commented examples below.

require([
    "splunkjs/mvc",
    "splunkjs/mvc/utils",
    "splunkjs/mvc/tokenutils",
    "underscore",
    "jquery",
    "splunkjs/mvc/simplexml",
    "splunkjs/mvc/headerview",
    "splunkjs/mvc/footerview",
    "splunkjs/mvc/simplexml/dashboardview",
    "splunkjs/mvc/simplexml/element/chart",
    "splunkjs/mvc/simplexml/element/event",
    "splunkjs/mvc/simplexml/element/html",
    "splunkjs/mvc/simplexml/element/list",
    "splunkjs/mvc/simplexml/element/map",
    "splunkjs/mvc/simplexml/element/single",
    "splunkjs/mvc/simplexml/element/table",
    "splunkjs/mvc/simpleform/formutils",
    "splunkjs/mvc/simpleform/input/dropdown",
    "splunkjs/mvc/simpleform/input/radiogroup",
    "splunkjs/mvc/simpleform/input/multiselect",
    "splunkjs/mvc/simpleform/input/checkboxgroup",
    "splunkjs/mvc/simpleform/input/text",
    "splunkjs/mvc/simpleform/input/timerange",
    "splunkjs/mvc/simpleform/input/submit",
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/savedsearchmanager",
    "splunkjs/mvc/postprocessmanager",
    "splunkjs/mvc/simplexml/urltokenmodel"
    // Add comma-separated libraries and modules manually here, for example:
    // ..."splunkjs/mvc/simplexml/urltokenmodel",
    // "splunkjs/mvc/checkboxview"
    ],
    function(
        mvc,
        utils,
        TokenUtils,
        _,
        $,
        DashboardController,
        HeaderView,
        FooterView,
        Dashboard,
        ChartElement,
        EventElement,
        HtmlElement,
        ListElement,
        MapElement,
        SingleElement,
        TableElement,
        FormUtils,
        DropdownInput,
        RadioGroupInput,
        MultiSelectInput,
        CheckboxGroupInput,
        TextInput,
        TimeRangeInput,
        SubmitButton,
        SearchManager,
        SavedSearchManager,
        PostProcessManager,
        UrlTokenModel

        // Add comma-separated parameter names here, for example: 
        // ...UrlTokenModel, 
        // CheckboxView
        ) {



        var pageLoading = true;


        // 
        // TOKENS
        //

        // Create token namespaces
        var urlTokenModel = new UrlTokenModel();
        mvc.Components.registerInstance('url', urlTokenModel);
        var defaultTokenModel = mvc.Components.getInstance('default', {create: true});
        var submittedTokenModel = mvc.Components.getInstance('submitted', {create: true});

        urlTokenModel.on('url:navigate', function() {
            defaultTokenModel.set(urlTokenModel.toJSON());
            if (!_.isEmpty(urlTokenModel.toJSON()) &amp;amp;&amp;amp; !_.all(urlTokenModel.toJSON(), _.isUndefined)) {
                submitTokens();
            } else {
                submittedTokenModel.clear();
            }
        });

        // Initialize tokens
        defaultTokenModel.set(urlTokenModel.toJSON());

        function submitTokens() {
            // Copy the contents of the defaultTokenModel to the submittedTokenModel and urlTokenModel
            FormUtils.submitForm({ replaceState: pageLoading });
        }

        function setToken(name, value) {
            defaultTokenModel.set(name, value);
            submittedTokenModel.set(name, value);
        }

        function unsetToken(name) {
            defaultTokenModel.unset(name);
            submittedTokenModel.unset(name);
        }

        //
        // SEARCH MANAGERS
        //

        var search1 = new SearchManager({
            "id": "search1",
            "latest_time": "$time_range.latest$",
            "earliest_time": "$time_range.earliest$",
            "status_buckets": 0,
            "cancelOnUnload": true,
            "search": "index=$index$  OR index=_$index$  | stats count as total_count  by sourcetype",
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "runWhenTimeIsUndefined": false
        }, {tokens: true, tokenNamespace: "submitted"});



        //
        // SPLUNK HEADER AND FOOTER
        //

        new HeaderView({
            id: 'header',
            section: 'dashboards',
            el: $('.header'),
            acceleratedAppNav: true,
            useSessionStorageCache: true
        }, {tokens: true}).render();

        new FooterView({
            id: 'footer',
            el: $('.footer')
        }, {tokens: true}).render();


        //
        // DASHBOARD EDITOR
        //

        new Dashboard({
            id: 'dashboard',
            el: $('.dashboard-body')
        }, {tokens: true}).render();


        //
        // VIEWS: VISUALIZATION ELEMENTS
        //

        var highlight = new TableElement({
            "id": "highlight",
            "drilldown": "none",
            "managerid": "search1",
            "el": $('#highlight')
        }, {tokens: true}).render();



        //
        // VIEWS: FORM INPUTS
        //
        var field1 = new TimeRangeInput({
            "id": "field1",
            "searchWhenChanged": true,
            "default": {"latest_time": "now", "earliest_time": "0"},
            "earliest_time": "$form.time_range.earliest$",
            "latest_time": "$form.time_range.latest$",
            "el": $('#field1')
        }, {tokens: true}).render();

        field1.on("change", function(newValue) {
            FormUtils.handleValueChange(field1);
        });

        var field2 = new DropdownInput({
            "id": "field2",
            "choices": [
                {"value": "*", "label": "All"}
            ],
            "searchWhenChanged": true,
            "labelField": "index",
            "default": "*",
            "selectFirstChoice": false,
            "valueField": "index",
            "value": "$form.index$",
            "managerid": "search2",
            "showClearButton": true,
            "el": $('#field2')
        }, {tokens: true}).render();

        field2.on("change", function(newValue) {
            FormUtils.handleValueChange(field2);
        });

        // Populating search for field 'field2'
        var search2 = new SearchManager({
            "id": "search2",
            "earliest_time": "$earliest$",
            "latest_time": "$latest$",
            "status_buckets": 0,
            "cancelOnUnload": true,
            "search": "| eventcount summarize=false index=* OR index=_*",
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "runWhenTimeIsUndefined": false
        }, {tokens: true});



        // Initialize time tokens to default
        if (!defaultTokenModel.has('earliest') &amp;amp;&amp;amp; !defaultTokenModel.has('latest')) {
            defaultTokenModel.set({ earliest: '0', latest: '' });
        }

        submitTokens();


        //
        // DASHBOARD READY
        //

        DashboardController.ready();
        pageLoading = false;

    }
);
&amp;lt;/script&amp;gt;
&amp;lt;script src="{{SPLUNKWEB_URL_PREFIX}}/static/app/stephane_app/table_cell_highlighting.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;table_cell_highlighting.js&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

     // Row Coloring Example with custom, client-side range interpretation

    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            // Enable this custom cell renderer for both the active_hist_searches and the active_realtime_searches field
            return _(['total_count', 'active_realtime_searches']).contains(cell.field);
        },
        render: function($td, cell) {
            // Add a class to the cell based on the returned value
            var value = parseFloat(cell.value);

            // Apply interpretation for number of historical searches
            if (cell.field === 'total_count') {
                if (value &amp;gt; 400.00) {
                    $td.addClass('range-cell').addClass('range-severe');
                }
                else if (value &amp;gt; 100.00) {
                    $td.addClass('range-cell').addClass('range-elevated');
                }
                else if (value &amp;lt; 100.00) {
                    $td.addClass('range-cell').addClass('range-low');
                }
            }

            // Apply interpretation for number of realtime searches
            if (cell.field === 'active_realtime_searches') {
                if (value &amp;gt; 1) {
                    $td.addClass('range-cell').addClass('range-severe');
                }
            }

            // Update the cell content
            $td.text(value.toFixed(2)).addClass('numeric');
        }
    });

    mvc.Components.get('highlight').getVisualization(function(tableView) {
        // Add custom cell renderer
        tableView.table.addCellRenderer(new CustomRangeRenderer());
        // tableView.on('rendered', function() {
            // Apply class of the cells to the parent row in order to color the whole row
           // tableView.$el.find('td.range-cell').each(function() {
           //     $(this).addClass(this.className);
           // });
        //});
        // Force the table to re-render
        tableView.table.render();
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;table_cell_highlighting.css&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/* Cell Highlighting */

/* 
#highlight td {
    background-color: #c1ffc3 !important;
}
*/

#highlight td.range-low {
    color: #C0D9D9;


}

#highlight td.range-elevated {
    background-color: #ffc57a !important;
    font-weight: bold;
    color: blue;
}

#highlight td.range-severe {
    background-color: #d59392 !important;
    font-weight: bold;
    color: yellow;
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127345#M7537</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2020-09-28T19:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: After converting an XML dashboard to HTML, where do I add CSS and javascript files on the filesystem and reference the items in the HTML?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127346#M7538</link>
      <description>&lt;P&gt;omg i've been searching for the syntax of the script src="file location" for ages thank you greatly sir &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2017 00:11:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/After-converting-an-XML-dashboard-to-HTML-where-do-I-add-CSS-and/m-p/127346#M7538</guid>
      <dc:creator>ewmin3m</dc:creator>
      <dc:date>2017-05-27T00:11:16Z</dc:date>
    </item>
  </channel>
</rss>

