File: RenderedProcessActionBar.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 (161 lines) | stat: -rw-r--r-- 5,556 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php

namespace Icinga\Module\Businessprocess\Web\Component;

use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Renderer\Renderer;
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
use Icinga\Web\Url;
use ipl\Html\Html;
use ipl\Web\Widget\Icon;

class RenderedProcessActionBar extends ActionBar
{
    public function __construct(BpConfig $config, Renderer $renderer, Url $url)
    {
        $meta = $config->getMetadata();

        if ($renderer instanceof TreeRenderer) {
            $link = Html::tag(
                'a',
                [
                    'href'  => $url->with('mode', 'tile'),
                    'title' => mt('businessprocess', 'Switch to Tile view')
                ]
            );
        } else {
            $link = Html::tag(
                'a',
                [
                    'href'  => $url->with('mode', 'tree'),
                    'title' => mt('businessprocess', 'Switch to Tree view')
                ]
            );
        }

        $link->add([
            new Icon('grip', ['class' => $renderer instanceof TreeRenderer ? null : 'active']),
            new Icon('sitemap', ['class' => $renderer instanceof TreeRenderer ? 'active' : null])
        ]);

        $this->add(
            Html::tag('div', ['class' => 'view-toggle'])
                ->add(Html::tag('span', null, mt('businessprocess', 'View')))
                ->add($link)
        );

        $this->add(Html::tag(
            'a',
            [
                'data-base-target' => '_main',
                'href'  => $url->with('showFullscreen', true),
                'title' => mt('businessprocess', 'Switch to fullscreen mode'),
            ],
            [
                new Icon('maximize'),
                mt('businessprocess', 'Fullscreen')
            ]
        ));

        $hasChanges = $config->hasSimulations() || $config->hasBeenChanged();

        if ($renderer->isLocked()) {
            if (! $renderer->wantsRootNodes() && $renderer->rendersImportedNode()) {
                $span = Html::tag('span', [
                    'class' => 'disabled',
                    'title' => mt(
                        'businessprocess',
                        'Imported processes can only be changed in their original configuration'
                    )
                ]);
                $span->add([new Icon('lock'), mt('businessprocess', 'Editing Locked')]);
                $this->add($span);
            } else {
                $this->add(Html::tag(
                    'a',
                    [
                        'href'  => $url->with('unlocked', true),
                        'title' => mt('businessprocess', 'Click to unlock editing for this process'),
                    ],
                    [
                        new Icon('lock'),
                        mt('businessprocess', 'Unlock Editing')
                    ]
                ));
            }
        } elseif (! $hasChanges) {
            $this->add(Html::tag(
                'a',
                [
                    'href'  => $url->without('unlocked')->without('action'),
                    'title' => mt('businessprocess', 'Click to lock editing for this process'),
                ],
                [
                    new Icon('lock-open'),
                    mt('businessprocess', 'Lock Editing')
                ]
            ));
        }

        if (($hasChanges || ! $renderer->isLocked()) && $meta->canModify()) {
            if ($renderer->wantsRootNodes()) {
                $this->add(Html::tag(
                    'a',
                    [
                        'data-base-target' => '_next',
                        'href'  => Url::fromPath('businessprocess/process/config', $this->currentProcessParams($url)),
                        'title' => mt('businessprocess', 'Modify this process'),
                    ],
                    [
                        new Icon('wrench'),
                        mt('businessprocess', 'Config')
                    ]
                ));
            } else {
                $this->add(Html::tag(
                    'a',
                    [
                        'href'  => $url->with([
                            'action'    => 'edit',
                            'editnode'  => $url->getParam('node')
                        ])->getAbsoluteUrl(),
                        'title' => mt('businessprocess', 'Modify this process'),
                    ],
                    [
                        new Icon('wrench'),
                        mt('businessprocess', 'Config')
                    ]
                ));
            }
        }

        if (($hasChanges || (! $renderer->isLocked())) && $meta->canModify()) {
            $this->add(Html::tag(
                'a',
                [
                    'href'  => $url->with('action', 'add'),
                    'title' => mt('businessprocess', 'Add a new business process node'),
                    'class' => 'button-link'
                ],
                [
                    new Icon('plus'),
                    mt('businessprocess', 'Add Node')
                ]
            ));
        }
    }

    protected function currentProcessParams(Url $url)
    {
        $urlParams = $url->getParams();
        $params = array();
        foreach (array('config', 'node') as $name) {
            if ($value = $urlParams->get($name)) {
                $params[$name] = $value;
            }
        }

        return $params;
    }
}