Skip to content

Module YAML Conversion

Jon Crain edited this page May 12, 2020 · 4 revisions

Converting modules to a YAML format will make things more portable and hopefully more secure. It will also lower the barrier for the creation of simple modules without the need for a deep understanding of php/javascript.

Currently the following files can be transitioned to YAML:

  • provides.php
  • report.php
  • listing.php
  • widget.php
  • detail_widget.php

provides.php to provides.yml

Original php file:

<?php

return [
    'client_tabs' => [
        'MODULE-tab' => ['view' => 'MODULE_tab', 'i18n' => 'MODULE.title'],
    ],
    'listings' => [
        'MODULE' => ['view' => 'MODULE_listing', 'i18n' => 'MODULE.listing.title'],
    ],
    'widgets' => [
        'MODULE' => ['view' => 'MODULE_widget'],
    ],
    'reports' => [
        'MODULE' => ['view' => 'MODULE_report', 'i18n' => 'MODULE.report.title'],
    ],
];

New YAML style:

client_tabs:
    MODULE-tab:
        view: MODULE_tab
        i18n: MODULE.title
listings:
    MODULE:
        view: MODULE_listing
        i18n: MODULE.listing.title
widgets:
    MODULE:
        view: MODULE_widget
reports:
    MODULE:
        view: MODULE_report
        i18n: MODULE.report.title

report.php to report.yml

Original php file:

<?php $this->view('partials/head', array(
    "scripts" => array(
        "clients/client_list.js"
    )
)); ?>

<div class="container">

    <div class="row">

        <?php $widget->view($this, 'MODULE'); ?>

    </div> <!-- /row -->

</div>  <!-- /container -->

<script src="<?php echo conf('subdirectory'); ?>assets/js/munkireport.autoupdate.js"></script>

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

New YAML style:

row1:
    MODULE:

listing.php to listing.yml

Original php file:

The original listing.php had a couple of variations:

JSON Style

PHP Style

New YAML style:

i18n_title: MODULE.listing.title
table:
    -
        column: machine.computer_name
        i18n_header: listing.computername
        formatter: clientDetail
        tab_link: MODULE-tab
    -
        column: reportdata.serial_number
        i18n_header: serial
    -
        column: MODULE.item1
        i18n_header: MODULE.listing.item1
    -
        column: MODULE.item2
        i18n_header: MODULE.listing.item2

Formatter options

  • clientDetail
  • binaryEnabledDisabled
  • binaryYesNo

widget.php to widget.yml

Original php file:

Widget PHP

New YAML style:

type: scrollbox
widget_id: MODULE-widget
api_url: /module/MODULE/get_list
i18n_title: MODULE.widget.title
icon: fa-laptop
listing_link: /show/listing/MODULE/MODULE
search_key: item1

Widget Options

  • type:
    • valid options:
      • scrollbox
      • button
      • table
  • url_type:
  • i18nEmptyResult:
  • badge:

detail_widget.php to detail_widget.yml

Original php file:

<div class="col-lg-4">
    <h4 data-i18n="disk_report.storage"></h4>
    <table id="disk_report_detail" class="table"></table>
</div>

<!-- Detail widget data comes from the storage_tab -->

or

<div class="col-lg-4">
     <h4><i class="fa fa-clock-o"></i> <span data-i18n="timemachine.timemachine"></span></h4>
     <table class="mr-timemachine-table">
     </table>
 </div>

  <script>

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

 });

 </script> 

New YAML style:

type: table
i18n_title: disk_report.storage
table_id: disk_report_detail
table:
# Detail widget data comes from the storage_tab

or

type: table
i18n_title: timemachine.timemachine
table_id: timemachine_detail
icon: fa-clock-o
table:
    - i18n_header: backup.last_success
      class: timemachine-last_success
    - i18n_header: backup.duration
      class: timemachine-duration
    - i18n_header: backup.last_failure_msg
      class: timemachine-last_failure_msg
    - i18n_header: backup.last_failure
      class: timemachine-last_failure
    - i18n_header: backup.location_name
      class: timemachine-location_name
    - i18n_header: backup.destinations
      class: timemachine-destinations
    - i18n_header: timemachine.result
      class: timemachine-result
Clone this wiki locally