This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit ea0d991f0d903fd0f6ad0a02b29c95e6ed33e400
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Nov 2 21:06:43 2022 +0000

    show workflow for ui-based scripts, to be able to re-run it
---
 .../workflow/workflow-steps.directive.js           |  2 +-
 ui-modules/app-inspector/app/index.js              |  3 ++-
 .../inspect/activities/activities.controller.js    |  2 +-
 .../inspect/activities/detail/detail.controller.js | 26 ++++++++++++++++++----
 .../inspect/activities/detail/detail.template.html |  4 ++++
 .../app/views/main/inspect/inspect.controller.js   | 21 ++++++++++++++---
 .../main/inspect/run-workflow-modal.template.html  |  2 +-
 .../utils/user-management/user-management.js       |  1 -
 ui-modules/utils/yaml-editor/yaml-editor.js        |  6 ++++-
 9 files changed, 54 insertions(+), 13 deletions(-)

diff --git 
a/ui-modules/app-inspector/app/components/workflow/workflow-steps.directive.js 
b/ui-modules/app-inspector/app/components/workflow/workflow-steps.directive.js
index ab49d345..35021841 100644
--- 
a/ui-modules/app-inspector/app/components/workflow/workflow-steps.directive.js
+++ 
b/ui-modules/app-inspector/app/components/workflow/workflow-steps.directive.js
@@ -163,7 +163,7 @@ function makeArrows(workflow, steps) {
 
         function stepY(n) {
             if (n==-1) return 'start/end';
-            if (!steps || n<0 || n>=steps.length) {
+            if (!steps || n<0 || n>=steps.length || _.isNil(n)) {
                 console.log("workflow arrow bounds error", steps, n);
                 return null;
             }
diff --git a/ui-modules/app-inspector/app/index.js 
b/ui-modules/app-inspector/app/index.js
index d8c00ebf..9dbfd95f 100755
--- a/ui-modules/app-inspector/app/index.js
+++ b/ui-modules/app-inspector/app/index.js
@@ -36,6 +36,7 @@ import brYamlEditor from 
"brooklyn-ui-utils/yaml-editor/yaml-editor";
 import brWebNotifications from 
'brooklyn-ui-utils/web-notifications/web-notifications';
 import brExpandablePanel from 
'brooklyn-ui-utils/expandable-panel/expandable-panel';
 import brLogbook from 'brooklyn-ui-utils/logbook/logbook';
+import serverApi from 'brooklyn-ui-utils/api/brooklyn/server';
 
 import "angular-xeditable";
 import apiProvider from "components/providers/api.provider";
@@ -71,7 +72,7 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production' 
|| false;
 angular.module('brooklynAppInspector', [ngResource, ngCookies, ngSanitize, 
uiRouter, brCore, brUtilsGeneral,
     dropdownNested,
     brServerStatus, brIconGenerator, brInterstitialSpinner, 
brooklynModuleLinks, brSensitiveField, brooklynUserManagement,
-    brYamlEditor, brWebNotifications, brExpandablePanel, 'xeditable', 
brLogbook, apiProvider, entityTree, loadingState,
+    brYamlEditor, brWebNotifications, brExpandablePanel, 'xeditable', 
brLogbook, apiProvider, entityTree, loadingState, serverApi,
     configSensorTable, entityEffector, entityPolicy, breadcrumbNavigation, 
taskList, taskSunburst, stream, adjunctsList,
     workflowSteps, workflowStep,
     managementDetail, brandAngularJs])
diff --git 
a/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
 
b/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
index 449504e6..eb00c68b 100644
--- 
a/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
+++ 
b/ui-modules/app-inspector/app/views/main/inspect/activities/activities.controller.js
@@ -195,7 +195,7 @@ function ActivitiesController($scope, $state, $stateParams, 
$log, $timeout, enti
 export function makeTaskStubFromWorkflowRecord(wf, wft) {
     const result = {
         id: wft.taskId,
-        displayName: wf.name + (wft.reasonForReplay && 
wft.reasonForReplay!="initial run" ? " ("+wft.reasonForReplay+")" : ""),
+        displayName: wf.name + (wft.reasonForReplay && 
wft.reasonForReplay!="Initial run" ? " ("+wft.reasonForReplay+")" : ""),
         entityId: (wf.entity || {}).id,
         isError: wft.isError===false ? false : true,
         currentStatus: _.isNil(wft.isError) ? "Unavailable" : wft.status,
diff --git 
a/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.controller.js
 
b/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.controller.js
index 6589760f..86fa0e6f 100644
--- 
a/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.controller.js
+++ 
b/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.controller.js
@@ -142,7 +142,10 @@ function DetailController($scope, $state, $stateParams, 
$location, $log, $uibMod
                         });
                     }
 
-                    $scope.actions.workflowReplays = [];
+                    let osi = vm.model.workflow.data.oldStepInfo;
+                    vm.model.workflow.finishedWithNoSteps = ((osi["-2"] || 
{}).previous || [])[0] == -1;
+
+                        $scope.actions.workflowReplays = [];
                     if (vm.model.workflow.data.status !== 'RUNNING') {
 
                         $scope.actions.workflowReplays = [];
@@ -170,8 +173,8 @@ function DetailController($scope, $state, $stateParams, 
$location, $log, $uibMod
                         if (replayableFromStart) {
                             let w1 = 'Restart', w2 = '(not resumable)';
                             if (stepIndex<0 || (_.isNil(stepIndex) && 
vm.model.workflow.data.replayableLastStep==-2)) { w1 = 'Run'; w2 = 'again'; }
-                            else if (_.isNil(stepIndex)) { w2 = '(did not 
start)'; }
                             else if (replayableContinuing) w2 = '';
+                            else if (_.isNil(stepIndex)) { w2 = '(did not 
start)'; }
 
                             $scope.actions.workflowReplays.push({targetId: 
'start', reason: 'Restart workflow from UI',
                                 label: w1+' '+(stepIndex>=0 ? 'workflow ' : 
'')+w2});
@@ -212,6 +215,21 @@ function DetailController($scope, $state, $stateParams, 
$location, $log, $uibMod
                 if (vm.model.workflow.data.status === 'RUNNING') 
wResponse.interval(1000);
                 observers.push(wResponse.subscribe(processWorkflowData));
 
+                function initFromWorkflowFirstReplayTask(task) {
+                    if (task) {
+                        const workflowYaml = (task.tags || []).find(t => 
t.workflow_yaml);
+                        if (workflowYaml) {
+                            $scope.workflow_yaml = workflowYaml.workflow_yaml;
+                        }
+                    }
+                }
+
+                if ($scope.workflowId === activityId) 
initFromWorkflowFirstReplayTask(vm.model.activity);
+                else activityApi.activity($scope.workflowId).then((response)=> 
{
+                    initFromWorkflowFirstReplayTask(response.data);
+                });
+
+
             }).catch(error => {
                 if (optimistic) {
                     vm.model.workflow.loading = null;
@@ -318,13 +336,13 @@ function DetailController($scope, $state, $stateParams, 
$location, $log, $uibMod
     }
 
     vm.isNonEmpty = Utils.isNonEmpty;
-    vm.yaml = jsyaml.dump;
+    vm.yaml = (o) => typeof o === 'string' ? o : jsyaml.dump(o);
 
     vm.openInRunModel = function (workflowYaml) {
         $uibModal.open({
             animation: true,
             template: runWorkflowModalTemplate,
-            controller: ['$scope', '$http', '$uibModalInstance', 
'applicationId', 'entityId', 'workflowYaml', runWorkflowController],
+            controller: ['$scope', '$http', '$uibModalInstance', 'serverApi', 
'applicationId', 'entityId', 'workflowYaml', runWorkflowController],
             size: 'lg',
             resolve: {
                 applicationId: ()=>(applicationId),
diff --git 
a/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.template.html
 
b/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.template.html
index 04a68636..1fe8b110 100644
--- 
a/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.template.html
+++ 
b/ui-modules/app-inspector/app/views/main/inspect/activities/detail/detail.template.html
@@ -255,6 +255,10 @@
                                     ></a></b>.
                                 </div>
 
+                                <div 
ng-if="vm.model.workflow.finishedWithNoSteps" class="workflow-preface-para">
+                                    The workflow did not run any steps; if 
this is unexpected, check the conditions on the steps.
+                                </div>
+
                                 <div 
ng-if="vm.model.workflow.data.errorHandlerTaskId" class="workflow-preface-para">
                                     <span 
ng-if="vm.model.activityId==vm.model.workflow.data.errorHandlerTaskId">
                                         This is the page for the error handler 
for this workflow.
diff --git 
a/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js 
b/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
index 61dd014f..896374e3 100644
--- a/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
+++ b/ui-modules/app-inspector/app/views/main/inspect/inspect.controller.js
@@ -80,7 +80,7 @@ export function inspectController($scope, $state, 
$stateParams, $uibModal, brSna
         $uibModal.open({
             animation: true,
             template: runWorkflowModalTemplate,
-            controller: ['$scope', '$http', '$uibModalInstance', 
'applicationId', 'entityId', runWorkflowController],
+            controller: ['$scope', '$http', '$uibModalInstance', 'serverApi', 
'applicationId', 'entityId', runWorkflowController],
             size: 'lg',
             resolve: {
                 applicationId: ()=>(applicationId),
@@ -144,12 +144,27 @@ export function addChildController($scope, $http, 
$uibModalInstance, application
     }
 }
 
-export function runWorkflowController($scope, $http, $uibModalInstance, 
applicationId, entityId, workflowYaml) {
-    $scope.workflowYaml = workflowYaml || 'steps:\n  - ';
+export function runWorkflowController($scope, $http, $uibModalInstance, 
serverApi, applicationId, entityId, workflowYaml) {
+    $scope.workflowYaml = workflowYaml;
     $scope.errorMessage = null;
     $scope.running = false;
     $scope.runWorkflow = runWorkflow;
 
+    if (!$scope.workflowYaml) {
+        function initWorkflowYaml() {
+            if (!$scope.workflowYaml) {
+                $scope.workflowYaml = 'name: Workflow via UI' + ($scope.user ? 
' ' + $scope.user : '') + '\n' + 'steps:\n  - ';
+            }
+        }
+        serverApi.getUser().then((response) => {
+            $scope.user = response.data;
+            initWorkflowYaml();
+        }).catch((response) => {
+            $scope.user = null;
+            initWorkflowYaml();
+        });
+    }
+
     function runWorkflow() {
         $scope.running = true;
         $scope.errorMessage = null;
diff --git 
a/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
 
b/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
index 9bb3e654..83860e0a 100644
--- 
a/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
+++ 
b/ui-modules/app-inspector/app/views/main/inspect/run-workflow-modal.template.html
@@ -25,7 +25,7 @@
     <div ng-if="errorMessage" class="alert alert-danger" role="alert">
         <strong>Error</strong> {{errorMessage}}
     </div>
-    <br-yaml-editor value="workflowYaml" enable-auto-complete></br-yaml-editor>
+    <br-yaml-editor value="workflowYaml" enable-auto-complete 
reset-to-end-on-external-value-set="true"></br-yaml-editor>
 </div>
 
 <div class="modal-footer">
diff --git a/ui-modules/utils/user-management/user-management.js 
b/ui-modules/utils/user-management/user-management.js
index 5383461b..54fd2bd6 100644
--- a/ui-modules/utils/user-management/user-management.js
+++ b/ui-modules/utils/user-management/user-management.js
@@ -42,7 +42,6 @@ export function userMenuDirective($compile, serverApi) {
             .addClass('dropdown')
             .removeAttr('br-user-menu') //remove the attribute to avoid 
indefinite loop
             .removeAttr('data-br-user-menu'); //also remove the same attribute 
with data- prefix in case users specify data-common-things in the html
-
         serverApi.getUser().then((response) => {
             scope.user = response.data;
         }).catch((response) => {
diff --git a/ui-modules/utils/yaml-editor/yaml-editor.js 
b/ui-modules/utils/yaml-editor/yaml-editor.js
index 4cfa160b..38952be2 100644
--- a/ui-modules/utils/yaml-editor/yaml-editor.js
+++ b/ui-modules/utils/yaml-editor/yaml-editor.js
@@ -45,7 +45,8 @@ export function yamlEditorDirective($rootScope, brSnackbar) {
         scope: {
             type: '@',
             value: '=',
-            onChange: '&'
+            onChange: '&',
+            resetToEndOnExternalValueSet: '=?',
         },
         link: link
     };
@@ -180,6 +181,9 @@ export function yamlEditorDirective($rootScope, brSnackbar) 
{
             $scope.cm.focus();
             if ($scope.cm.getValue() !== newVal && angular.isDefined(newVal)) {
                 $scope.cm.setValue(newVal);
+                if ($scope.resetToEndOnExternalValueSet) {
+                    $scope.cm.setCursor($scope.cm.lineCount(), 0);
+                }
             }
             setTimeout(()=> {
                 $scope.cm.focus();

Reply via email to