File: Dashboard.php

package info (click to toggle)
icingaweb2-module-businessprocess 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,720 kB
  • sloc: php: 10,971; javascript: 2,019; sh: 115; xml: 49; makefile: 18
file content (140 lines) | stat: -rw-r--r-- 4,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php

namespace Icinga\Module\Businessprocess\Web\Component;

use Exception;
use Icinga\Application\Modules\Module;
use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Businessprocess\State\IcingaDbState;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\Storage;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;

class Dashboard extends BaseHtmlElement
{
    /** @var string */
    protected $contentSeparator = "\n";

    /** @var string */
    protected $tag = 'div';

    protected $defaultAttributes = array(
        'class' => 'overview-dashboard',
        'data-base-target' => '_next'
    );

    /** @var Auth */
    protected $auth;

    /** @var Storage */
    protected $storage;

    /**
     * Dashboard constructor.
     * @param Auth $auth
     * @param Storage $storage
     */
    protected function __construct(Auth $auth, Storage $storage)
    {
        $this->auth = $auth;
        $this->storage = $storage;
        // TODO: Auth?
        $processes = $storage->listProcessNames();
        $this->add(
            Html::tag('h1', null, mt('businessprocess', 'Welcome to your Business Process Overview'))
        );
        $this->add(Html::tag(
            'p',
            null,
            mt(
                'businessprocess',
                'From here you can reach all your defined Business Process'
                . ' configurations, create new or modify existing ones'
            )
        ));
        if ($auth->hasPermission('businessprocess/create')) {
            $this->add(
                new DashboardAction(
                    mt('businessprocess', 'Create'),
                    mt('businessprocess', 'Create a new Business Process configuration'),
                    'plus',
                    'businessprocess/process/create',
                    null,
                    array('class' => 'addnew')
                )
            )->add(
                new DashboardAction(
                    mt('businessprocess', 'Upload'),
                    mt('businessprocess', 'Upload an existing Business Process configuration'),
                    'upload',
                    'businessprocess/process/upload',
                    null,
                    array('class' => 'addnew')
                )
            );
        } elseif (empty($processes)) {
            $this->add(
                Html::tag('div')
                    ->add(Html::tag('h1', null, mt('businessprocess', 'Not available')))
                    ->add(Html::tag('p', null, mt(
                        'businessprocess',
                        'No Business Process has been defined for you'
                    )))
            );
        }

        foreach ($processes as $name) {
            $meta = $storage->loadMetadata($name);
            $title = $meta->get('Title');

            if ($title === null) {
                $title = $name;
            }

            try {
                $bp = $storage->loadProcess($name);
            } catch (Exception $e) {
                $this->add(new BpDashboardTile(
                    new BpConfig(),
                    $title,
                    sprintf(t('File %s has faulty config'), $name . '.conf'),
                    'file-circle-xmark',
                    'businessprocess/process/show',
                    ['config' => $name]
                ));

                continue;
            }

            if (Module::exists('icingadb') &&
                (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
            ) {
                IcingaDbState::apply($bp);
            } else {
                MonitoringState::apply($bp);
            }

            $this->add(new BpDashboardTile(
                $bp,
                $title,
                $meta->get('Description'),
                'sitemap',
                'businessprocess/process/show',
                array('config' => $name)
            ));
        }
    }

    /**
     * @param Auth $auth
     * @param Storage $storage
     * @return static
     */
    public static function create(Auth $auth, Storage $storage)
    {
        return new static($auth, $storage);
    }
}