You are here

class MaestroProcessStatusController in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/MaestroProcessStatusController.php \Drupal\maestro\Controller\MaestroProcessStatusController

Maestro Process Status Controller class.

Hierarchy

Expanded class hierarchy of MaestroProcessStatusController

File

src/Controller/MaestroProcessStatusController.php, line 17

Namespace

Drupal\maestro\Controller
View source
class MaestroProcessStatusController extends ControllerBase {

  /**
   * Returns response for the process status queries.
   *
   * @param int $processID
   *   The processID we wish to get details for.
   *
   * @return \Drupal\Core\Ajax\AjaxResponse
   *   The ajax response
   */
  public function getDetails($processID) {
    $build = [];
    $taskDetails = '';

    // first, we determine if the template even wants process shown.
    $template = MaestroEngine::getTemplate(MaestroEngine::getTemplateIdFromProcessId($processID));
    if (isset($template->show_details) && $template->show_details) {
      $templateName = MaestroEngine::getTemplateIdFromProcessId($processID);

      // Skip the can execute check as this is not against a queue entry.
      $status_bar = MaestroStatus::getMaestroStatusBar($processID, 0, TRUE);
      $build['status'] = [
        '#prefix' => '<div id="processid-' . $processID . '" class="maestro-block-process ' . $templateName . '">',
        '#suffix' => '</div>',
        '#markup' => $status_bar['status_bar']['#children'],
      ];

      // Lets see if there's any views attached that we should be showing.
      if (isset($template->views_attached)) {
        foreach ($template->views_attached as $machine_name => $arr) {
          $view = Views::getView($machine_name);
          if ($view) {
            $display = explode(';', $arr['view_display']);
            $display_to_use = isset($display[0]) ? $display[0] : 'default';
            $render_build = $view
              ->buildRenderable($display_to_use, [
              $processID,
              0,
            ], FALSE);
            if ($render_build) {
              $thisViewOutput = \Drupal::service('renderer')
                ->renderPlain($render_build);
              if ($thisViewOutput) {
                $task_information_render_array = [
                  '#theme' => 'taskconsole_views',
                  '#task_information' => $thisViewOutput,
                  '#title' => $view->storage
                    ->label(),
                ];
                $taskDetails .= \Drupal::service('renderer')
                  ->renderPlain($task_information_render_array);
              }
            }
          }
        }
      }

      // Anyone want to override the task details display or add to it?
      \Drupal::moduleHandler()
        ->invokeAll('maestro_process_status_alter', [
        &$taskDetails,
        $processID,
        $template,
      ]);
      $build['views_bar'] = [
        '#children' => '<div class="maestro-process-details">' . $taskDetails . '</div>',
      ];
    }

    // $build = MaestroStatus::getMaestroStatusBar($processID, 0, TRUE);  //skip the can execute check as this is not against a queue entry
    // we replace the down arrow with the toggle up arrow
    $replace['expand'] = [
      '#attributes' => [
        'class' => [
          'maestro-timeline-status',
          'maestro-status-toggle-up',
        ],
        'title' => $this
          ->t('Close Details'),
      ],
      '#type' => 'link',
      '#id' => 'maestro-id-ajax-' . $processID,
      '#url' => Url::fromRoute('maestro.process_details_ajax_close', [
        'processID' => $processID,
      ]),
      '#title' => $this
        ->t('Close Details'),
      '#ajax' => [
        'progress' => [
          'type' => 'throbber',
          'message' => NULL,
        ],
      ],
    ];

    // Empty array.
    if (count($build) == 0) {
      $build['status'] = [
        '#plain_text' => $this
          ->t('No details to show'),
      ];
    }
    $response = new AjaxResponse();

    // Row.
    $response
      ->addCommand(new HtmlCommand('#details_replace_column_' . $processID, $build));

    // Wrapper attribute TD tag. Toggle up arrow.
    $response
      ->addCommand(new HtmlCommand('.maestro-status-toggle-' . $processID . '', $replace['expand']));
    $response
      ->addCommand(new CssCommand('#details_replace_row_' . $processID, [
      'display' => 'table-row',
    ]));
    return $response;
  }

  /**
   * Close Details method.
   */
  public function closeDetails($processID) {
    $build = [];

    // We replace the up arrow with the down arrow.
    $build['expand'] = [
      '#attributes' => [
        'class' => [
          'maestro-timeline-status',
          'maestro-status-toggle',
        ],
        'title' => $this
          ->t('Open Details'),
      ],
      '#type' => 'link',
      '#id' => 'maestro-id-ajax-' . $processID,
      '#url' => Url::fromRoute('maestro.process_details_ajax_open', [
        'processID' => $processID,
      ]),
      '#title' => $this
        ->t('Open Details'),
      '#ajax' => [
        'progress' => [
          'type' => 'throbber',
          'message' => NULL,
        ],
      ],
    ];
    $response = new AjaxResponse();
    $response
      ->addCommand(new HtmlCommand('#maestro-ajax-' . $processID, ''));
    $response
      ->addCommand(new HtmlCommand('.maestro-status-toggle-' . $processID, $build['expand']));
    $response
      ->addCommand(new CssCommand('#details_replace_row_' . $processID, [
      'display' => 'none',
    ]));
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ControllerBase::$configFactory protected property The configuration factory.
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$formBuilder protected property The form builder. 2
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 46
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route.
ControllerBase::state protected function Returns the state storage service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MaestroProcessStatusController::closeDetails public function Close Details method.
MaestroProcessStatusController::getDetails public function Returns response for the process status queries.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.