Forums

Lars Kniep
Lars Kniep
Offline
Resolved
0 votes
Hello,

How can i make my own widget for the dashboard (webconfig)? (I am using ClearOS 7 latest version)
I can't find any documentation or something about it.

I want to create a widget like this:
https://monosnap.com/file/LsNIZRgBZXwvxBAiSTm7YewGtPJ7WY.png

Any help is appreciated!
Sunday, April 10 2016, 09:44 AM
Share this post:
Responses (6)
  • Accepted Answer

    Monday, April 11 2016, 01:33 PM - #Permalink
    Resolved
    0 votes
    You'll likely need lm_sensors:

    yum -y --enablerepo=centos-unverified install lm_sensors


    Then run:

    sensors


    To see what was detected/supported by that library for your particular hardware.

    You can use the -u flag with sensors script and ClearOS's Shell API (/usr/clearos/apps/base/library/Shell.php to call the script from PHP and parse the output for inclusion into your widget.

    B.
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, April 10 2016, 05:46 PM - #Permalink
    Resolved
    0 votes
    Fixed image link first post.
    The reply is currently minimized Show
  • Accepted Answer

    Lars Kniep
    Lars Kniep
    Offline
    Sunday, April 10 2016, 01:26 PM - #Permalink
    Resolved
    0 votes
    Ben Chambers wrote:

    Oh...I see. I wasn't really expecting you to do your own standalone widget, but instead, extend an existing app or build a full app. However, I suppose your hack could / should work..you just need to add some stuff to your info.php file:


    $app['basename'] = 'cputemp';


    And create one additional folder:


    mkdir /usr/clearos/apps/cputemp/htdocs


    I think that should do it.

    Keep in mind, dashboard widget metadata is cached for 2 minutes, so you might not see it immediately. To change this behaviour during development to avoid frustration, edit:

    /usr/clearos/apps/dashboard/libraries/Dashboard.php


    and set the cache time in seconds to 0:

    const CACHE_S = 120;


    B.


    Thanks!, this worked like a champ.

    What i wanna do is read out "sensors" and take some information from that (cpu temps) and display it in that widget in a fancy way.

    Is it even possible to get that information from the shell ?
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, April 10 2016, 01:13 PM - #Permalink
    Resolved
    1 votes
    Oh...I see. I wasn't really expecting you to do your own standalone widget, but instead, extend an existing app or build a full app. However, I suppose your hack could / should work..you just need to add some stuff to your info.php file:


    $app['basename'] = 'cputemp';


    And create one additional folder:


    mkdir /usr/clearos/apps/cputemp/htdocs


    I think that should do it.

    Keep in mind, dashboard widget metadata is cached for 2 minutes, so you might not see it immediately. To change this behaviour during development to avoid frustration, edit:

    /usr/clearos/apps/dashboard/libraries/Dashboard.php


    and set the cache time in seconds to 0:

    const CACHE_S = 120;


    B.
    The reply is currently minimized Show
  • Accepted Answer

    Lars Kniep
    Lars Kniep
    Offline
    Sunday, April 10 2016, 12:56 PM - #Permalink
    Resolved
    0 votes
    Hi, thanks for the reply.

    I think i missed something, or doing something wrong.

    I have created a folder in /usr/clearos/apps/ called cputemp.

    In that folder i have the following:

    Folder: controllers --> cputemp_dashboard.php

    Folder: deploy --> info.php

    Folder: views --> Folder: dashboard --> index.php



    cputemp_dashboard.php


    <?php

    /**
    * Events Dashboard controller.
    *
    * @category apps
    * @package cputemp
    * @subpackage controllers
    * @author LarsCom
    */

    class Cputemp_Dashboard extends ClearOS_Controller
    {
    /**
    * Dashboard default controller.
    *
    * @return view
    */

    function index()
    {
    $this->page->view_form('cputemp/dashboard/index');
    }

    }




    info.php


    <?php

    /////////////////////////////////////////////////////////////////////////////
    // Dashboard Widgets
    /////////////////////////////////////////////////////////////////////////////

    $app['dashboard_widgets'] = array(
    $app['category'] => array(
    'cputemp/cputemp_dashboard/index' => array(
    'title' => 'CPU TEMP',
    'restricted' => FALSE,
    )
    )
    );




    index.php


    <?php

    /**
    *
    *
    * @category apps
    * @package cputemp
    * @subpackage controllers
    * @author LarsCom
    */


    echo "INDEX.PHP";





    I think i am missing more required information.
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, April 10 2016, 11:54 AM - #Permalink
    Resolved
    0 votes
    Hi,

    Best thing to do is look at an example. The dashboard widgets in the 'Events' app is a good one.

    Dashboard widgets are provided by the app when you install them (and removed if you un-install the app).

    Each app has a basename with the root of the listing here:

    /usr/clearos/apps/


    In order for a dashboard widget to get picked up, you need to create a controller with the format basename_dashboard.php.

    So, for the events app example, look to:

    /usr/clearos/apps/events/controller/events_dashboard.php

    Create as many controller calls (functions) as you wish in that file. It's basically just displaying a view of your choosing (or create a new view).

    The only thing you need to do when you're done is 'register' the dashboard widget in the packages's info.php file found here:

    /usr/clearos/apps/<basename>/deploy/info.php


    Here's a sample for the events app:


    /////////////////////////////////////////////////////////////////////////////
    // Dashboard Widgets
    /////////////////////////////////////////////////////////////////////////////

    $app['dashboard_widgets'] = array(
    $app['category'] => array(
    'events/events_dashboard/last_24' => array(
    'title' => lang('events_last_24_hours'),
    'restricted' => FALSE,
    )
    )
    );


    It's just a nested associative array....The '$app['dashboard_widgets']' element never changes...the next key is the category you want the widget to show up under. Finally, the last key is based on the controller URL, and provides the title and whether non-root users can select/view the widget or not.

    Hope that helps get you started.

    B.
    The reply is currently minimized Show
Your Reply