assertPermission('businessprocess/create'); $this->setTitle($this->translate('Create a new business process')); $this->tabsForCreate()->activate('create'); $this->view->form = $this->loadForm('bpConfig') ->setStorage($this->storage()) ->setSuccessUrl('businessprocess/process/show') ->handleRequest(); } /** * Upload an existing business process configuration */ public function uploadAction() { $this->setTitle($this->translate('Upload a business process config file')); $this->tabsForCreate()->activate('upload'); $this->view->form = $this->loadForm('BpUpload') ->setStorage($this->storage()) ->setSuccessUrl('businessprocess/process/show') ->handleRequest(); } /** * Show a business process */ public function showAction() { $mode = $this->params->get('mode'); $unlocked = (bool) $this->params->get('unlocked'); $this->prepareProcessActions(); $this->prepareProcess(); $this->redirectOnConfigSwitch(); if ($unlocked) { $bp = $this->loadModifiedBpConfig(); $bp->unlock(); } else { $bp = $this->loadBpConfig(); } // Do not lock empty configs if ($bp->isEmpty() && ! $this->view->compact && $bp->isLocked()) { $this->redirectNow($this->url()->with('unlocked', true)); } if ($node = $this->params->get('node')) { // Render a specific node $this->view->nodeName = $node; $bpNode = $this->view->bp = $bp->getNode($node); } else { // Render a single process $this->view->bp = $bp; if ($bp->hasWarnings()) { $this->view->warnings = $bp->getWarnings(); } $bpNode = null; } $bp->retrieveStatesFromBackend(); if ($this->params->get('addSimulation')) { $this->simulationForm(); } $title = sprintf('Business Process "%s"', $bp->getTitle()); $this->setTitle($title); $this->tabsForShow()->activate('show'); if ($bp->isLocked()) { $this->tabs()->extend(new DashboardAction()); } else { $simulation = new Simulation($bp, $this->session()); if ($this->params->get('dismissSimulations')) { Notification::success( sprintf( $this->translate('%d applied simulation(s) have been dropped'), $simulation->count() ) ); $simulation->clear(); $this->redirectNow($this->url()->without('dismissSimulations')->without('unlocked')); } $bp->applySimulation($simulation); } if ($mode === 'tile') { $renderer = new TileRenderer($bp, $bpNode); } else { $renderer = new TreeRenderer($bp, $bpNode); } $renderer->setBaseUrl($this->url()) ->setPath($this->params->getValues('path')); $this->content()->add($renderer); $controls = $this->controls(); if ($this->showFullscreen) { $controls->attributes()->add('class', 'want-fullscreen'); $controls->add( Link::create( Icon::create('resize-small'), $this->url()->without('showFullscreen')->without('view'), null, array('style' => 'float: right') ) ); } elseif (! $this->view->compact) { $controls->add(HtmlString::create($this->getTabs())); } if (! $this->view->compact) { $controls->add(Element::create('h1')->setContent($title)); } $controls->add(Breadcrumb::create($renderer)); if (! $this->showFullscreen && ! $this->view->compact) { $controls->add($this->actions()); } if (! $bp->isLocked()) { $renderer->unlock(); } if ($this->isXhr()) { if ($this->params->get('addSimulation')) { $this->setAutorefreshInterval(30); } else { $this->setAutorefreshInterval(10); } } else { // This will trigger the very first XHR refresh immediately on page // load. Please not that this may hammer the server in case we would // decide to use autorefreshInterval for HTML meta-refreshes also. $this->setAutorefreshInterval(1); } } protected function prepareProcess() { if ($this->params->get('unlocked')) { $bp = $this->loadModifiedBpConfig(); $bp->unlock(); } else { $bp = $this->loadBpConfig(); } if ($node = $this->params->get('node')) { // Render a specific node $this->view->nodeName = $node; $this->view->bp = $bp->getNode($node); } } protected function prepareProcessActions() { $mode = $this->params->get('mode'); $unlocked = (bool) $this->params->get('unlocked'); if ($mode === 'tile') { $this->actions()->add( Link::create( $this->translate('Tree'), 'businessprocess/process/show', $this->currentProcessParams(), array('class' => 'icon-sitemap') ) ); } else { $this->actions()->add( Link::create( $this->translate('Tiles'), $this->url()->with('mode', 'tile'), null, array('class' => 'icon-dashboard') ) ); } if ($unlocked) { $this->actions()->add( Link::create( $this->translate('Lock'), $this->url()->without('unlocked'), null, array( 'class' => 'icon-lock', 'title' => $this->translate('Lock this process'), ) ) ); } else { $this->actions()->add( Link::create( $this->translate('Unlock'), $this->url()->with('unlocked', true), null, array( 'class' => 'icon-lock-open', 'title' => $this->translate('Unlock this process'), ) ) ); } $this->actions()->add( Link::create( $this->translate('Store'), 'businessprocess/process/config', $this->currentProcessParams(), array( 'class' => 'icon-wrench', 'title' => $this->translate('Modify this process'), 'data-base-target' => '_next', ) ) ); $this->actions()->add( Link::create( $this->translate('Fullscreen'), $this->url()->with('showFullscreen', true), null, array( 'class' => 'icon-resize-full-alt', 'title' => $this->translate('Switch to fullscreen mode'), 'data-base-target' => '_main', ) ) ); } protected function simulationForm() { $this->prepareProcess(); $bp = $this->loadBpConfig(); $nodename = $this->getParam('simulationNode'); $node = $bp->getNode($nodename); $url = $this->getRequest()->getUrl()->without('addSimulation')->without('simulationNode'); $this->view->form = $this->loadForm('simulation') ->setSimulation(new Simulation($bp, $this->session())) ->setNode($node) ->setSuccessUrl($url) ->handleRequest(); $this->view->node = $node; } /** * Show the source code for a process */ public function sourceAction() { $this->prepareProcess(); $this->tabsForConfig()->activate('source'); $bp = $this->loadModifiedBpConfig(); $this->view->source = $bp->toLegacyConfigString(); $this->view->showDiff = (bool) $this->params->get('showDiff', false); if ($this->view->showDiff) { $this->view->diff = ConfigDiff::create( $this->storage()->getSource($this->view->configName), $this->view->source ); $this->view->title = sprintf( $this->translate('%s: Source Code Differences'), $bp->getTitle() ); } else { $this->view->title = sprintf( $this->translate('%s: Source Code'), $bp->getTitle() ); } } /** * Download a process configuration file */ public function downloadAction() { $this->prepareProcess(); $bp = $this->loadModifiedBpConfig(); header( sprintf( 'Content-Disposition: attachment; filename="%s.conf";', $bp->getName() ) ); header('Content-Type: text/plain'); echo $bp->toLegacyConfigString(); // Didn't have time to lookup how to correctly disable our renderers // TODO: no exit :) $this->doNotRender(); } /** * Modify a business process configuration */ public function configAction() { $this->prepareProcess(); $this->tabsForConfig()->activate('config'); $bp = $this->loadModifiedBpConfig(); $this->setTitle( $this->translate('%s: Configuration'), $bp->getTitle() ); $url = Url::fromPath( 'businessprocess/process/show?unlocked', array('config' => $bp->getName()) ); $this->view->form = $this->loadForm('bpConfig') ->setProcessConfig($bp) ->setStorage($this->storage()) ->setSuccessUrl($url) ->handleRequest(); } /** * Redirect to our URL plus the chosen config if someone switched the * config in the appropriate dropdown list */ protected function redirectOnConfigSwitch() { $request = $this->getRequest(); if ($request->isPost() && $request->getPost('action') === 'switchConfig') { // We switched the process in the config dropdown list $params = array( 'config' => $request->getPost('config') ); $this->redirectNow($this->url()->with($params)); } } protected function tabsForShow() { return $this->tabs()->add('show', array( 'label' => $this->translate('Business Process'), 'url' => $this->url() )); } protected function tabsForCreate() { return $this->tabs()->add('create', array( 'label' => $this->translate('Create'), 'url' => 'businessprocess/process/create' ))->add('upload', array( 'label' => $this->translate('Upload'), 'url' => 'businessprocess/process/upload' )); } protected function tabsForConfig() { return $this->tabs()->add('config', array( 'label' => $this->translate('Process Configuration'), 'url' => $this->getRequest()->getUrl()->without('nix')->setPath('businessprocess/process/config') ))->add('source', array( 'label' => $this->translate('Source'), 'url' => $this->getRequest()->getUrl()->without('nix')->setPath('businessprocess/process/source') )); } }