From c3eba581dc03e0b1420ee506bf7066dbf7c306e2 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Wed, 7 Dec 2016 12:01:17 -0800 Subject: [PATCH 01/13] Added polling for container url --- client/controllers/controllerInstance.js | 25 ++++++++++++++++-------- client/services/demoFlowService.js | 20 +++++++++++++++++-- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 0eef971f0..2859830cb 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -6,6 +6,7 @@ require('app') * @ngInject */ function ControllerInstance( + $interval, $localStorage, $q, $rootScope, @@ -223,19 +224,13 @@ function ControllerInstance( if (!demoFlowService.hasSeenHangTightMessage()) { data.demoFlowFlags.showHangTightMessage = true; } - } else { - if (data.demoFlowFlags.showHangTightMessage) { - data.demoFlowFlags.showHangTightMessage = false; - demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); - } } } function checkForEnablingUrlCallout (instance) { if (instance.status() === 'running' && keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && - !demoFlowService.hasSeenUrlCallout() && - !data.demoFlowFlags.showHangTightMessage) { - data.demoFlowFlags.showUrlCallout = true; + !demoFlowService.hasSeenUrlCallout()) { + pollContainerUrl(instance); } } @@ -259,6 +254,20 @@ function ControllerInstance( } } + function pollContainerUrl (instance) { + var stopPolling = $interval(function () { + return demoFlowService.checkStatusOnInstance(instance) + .then(function (statusOK) { + if (statusOK) { + $interval.cancel(stopPolling); + data.demoFlowFlags.showUrlCallout = true; + data.demoFlowFlags.showHangTightMessage = false; + demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); + } + }); + }, 2000); + } + function fetchCurrentInstance () { return fetchInstances({ name: $stateParams.instanceName }, true); } diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index 028bb644d..09cfa049b 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -4,8 +4,10 @@ require('app') .factory('demoFlowService', demoFlowService); function demoFlowService( + $http, $localStorage, currentOrg, + defaultContainerUrl, keypather, patchOrgMetadata ) { @@ -40,6 +42,20 @@ function demoFlowService( }); } + function checkStatusOnInstance (instance) { + var url = defaultContainerUrl(instance); + return $http({ + method: 'get', + url: url + }) + .then(function(res) { + if (res.status < 300) { + return true; + } + return false; + }) + } + function hasSeenHangTightMessage () { return $localStorage.hasSeenHangTightMessage; } @@ -57,6 +73,7 @@ function demoFlowService( } return { + checkStatusOnInstance: checkStatusOnInstance, endDemoFlow: endDemoFlow, getItem: getItem, hasSeenHangTightMessage: hasSeenHangTightMessage, @@ -67,5 +84,4 @@ function demoFlowService( setIsUsingDemoRepo: setIsUsingDemoRepo, setItem: setItem }; - -} \ No newline at end of file +} From 416a3236ebc3f710b5ce54cb0551920cc6e1b23b Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Wed, 7 Dec 2016 12:09:02 -0800 Subject: [PATCH 02/13] Fixed linting --- client/services/demoFlowService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index adf7feebc..0c552abc3 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -54,7 +54,7 @@ function demoFlowService( return true; } return false; - }) + }); } function hasSeenHangTightMessage () { From 3dd9e6cd2edeb5ebc30eeba868c4546c02dfb0d5 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Thu, 8 Dec 2016 11:06:49 -0800 Subject: [PATCH 03/13] Will continue flow if application does not communicate over http --- client/controllers/controllerInstance.js | 20 ++++++++++++++----- client/services/demoFlowService.js | 3 +++ .../controllers/controllerInstance.unit.js | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 2859830cb..436c41708 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -255,17 +255,27 @@ function ControllerInstance( } function pollContainerUrl (instance) { - var stopPolling = $interval(function () { + var timesToPoll = 15; + var stopPolling = $interval(function (timesToPoll) { + // zero indexed, once we've polled 15 times just go to add branch + if (timesToPoll === 14 && instance.status() === 'running') { + demoFlowService.setItem('hasSeenUrlCallout', data.instance.id()); + return cancelPolling(stopPolling, instance); + } return demoFlowService.checkStatusOnInstance(instance) .then(function (statusOK) { if (statusOK) { - $interval.cancel(stopPolling); data.demoFlowFlags.showUrlCallout = true; - data.demoFlowFlags.showHangTightMessage = false; - demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); + return cancelPolling(stopPolling, instance); } }); - }, 2000); + }, 1000, timesToPoll); + } + + function cancelPolling (stopPolling, instance) { + $interval.cancel(stopPolling); + data.demoFlowFlags.showHangTightMessage = false; + demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); } function fetchCurrentInstance () { diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index 0c552abc3..a59d66c5b 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -54,6 +54,9 @@ function demoFlowService( return true; } return false; + }) + .catch(function () { + return true; }); } diff --git a/test/unit/controllers/controllerInstance.unit.js b/test/unit/controllers/controllerInstance.unit.js index 0dc20cdb4..e1e2bf239 100644 --- a/test/unit/controllers/controllerInstance.unit.js +++ b/test/unit/controllers/controllerInstance.unit.js @@ -4,6 +4,7 @@ // injector-provided var $controller; var $httpBackend; +var $interval; var $rootScope; var $scope; var $state; @@ -114,6 +115,7 @@ describe('controllerInstance'.bold.underline.blue, function () { angular.mock.inject(function ( _$controller_, _$httpBackend_, + _$interval_, _$rootScope_, _$stateParams_, _$state_, @@ -126,6 +128,7 @@ describe('controllerInstance'.bold.underline.blue, function () { ) { $controller = _$controller_; $httpBackend = _$httpBackend_; + $interval = _$interval_; $rootScope = _$rootScope_; $state = _$state_; $stateParams = _$stateParams_; From bddc3a1400ae094f18f93a69cbef7cb31b006a81 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Thu, 8 Dec 2016 16:55:21 -0800 Subject: [PATCH 04/13] Moved logic for polling url into hang tight directive --- client/controllers/controllerInstance.js | 28 +-------- .../hangTightDirective.js | 58 +++++++++++++++++++ .../notifications/viewNotifications.jade | 4 +- test/unit/services/demoFlowService.unit.js | 0 4 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 client/directives/components/buildUpdateNotifications/hangTightDirective.js create mode 100644 test/unit/services/demoFlowService.unit.js diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 436c41708..9c0f2c9ba 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -216,6 +216,7 @@ function ControllerInstance( favico.setInstanceState(keypather.get($scope, 'dataInstance.data.instance')); }); }); + function checkForEnablingHangTightMessage (instance) { if (!keypather.get(instance, 'contextVersion.getMainAppCodeVersion()')) { return; @@ -229,8 +230,9 @@ function ControllerInstance( function checkForEnablingUrlCallout (instance) { if (instance.status() === 'running' && keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && + demoFlowService.hasSeenHangTightMessage() && !demoFlowService.hasSeenUrlCallout()) { - pollContainerUrl(instance); + data.demoFlowFlags.showUrlCallout = true; } } @@ -254,30 +256,6 @@ function ControllerInstance( } } - function pollContainerUrl (instance) { - var timesToPoll = 15; - var stopPolling = $interval(function (timesToPoll) { - // zero indexed, once we've polled 15 times just go to add branch - if (timesToPoll === 14 && instance.status() === 'running') { - demoFlowService.setItem('hasSeenUrlCallout', data.instance.id()); - return cancelPolling(stopPolling, instance); - } - return demoFlowService.checkStatusOnInstance(instance) - .then(function (statusOK) { - if (statusOK) { - data.demoFlowFlags.showUrlCallout = true; - return cancelPolling(stopPolling, instance); - } - }); - }, 1000, timesToPoll); - } - - function cancelPolling (stopPolling, instance) { - $interval.cancel(stopPolling); - data.demoFlowFlags.showHangTightMessage = false; - demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); - } - function fetchCurrentInstance () { return fetchInstances({ name: $stateParams.instanceName }, true); } diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js new file mode 100644 index 000000000..d112dd3af --- /dev/null +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -0,0 +1,58 @@ +'use strict'; + +require('app') + .directive('hangTight', hangTight); + +function hangTight( + $interval, + demoFlowService, + keypather +) { + return { + restrict: 'A', + templateUrl: 'firstBuildNotificationView', + scope: { + instance: '=', + demoFlowFlags: '=' + }, + link: function ($scope) { + var instance = $scope.instance; + var demoFlowFlags = $scope.demoFlowFlags; + + var stopWatchingForRunningInstance = $scope.$watch(function () { + return instance.status() === 'running'; + }, function () { + if (keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && + !demoFlowService.hasSeenUrlCallout()) { + stopWatchingForRunningInstance(); + pollContainerUrl(instance); + } + }) + + + function pollContainerUrl (instance) { + var timesToPoll = 15; + var stopPolling = $interval(function (timesToPoll) { + // zero indexed, once we've polled 15 times just go to add branch + if (timesToPoll === 14 && instance.status() === 'running') { + demoFlowService.setItem('hasSeenUrlCallout', instance.id()); + return cancelPolling(stopPolling, instance); + } + return demoFlowService.checkStatusOnInstance(instance) + .then(function (statusOK) { + if (statusOK) { + demoFlowFlags.showUrlCallout = true; + return cancelPolling(stopPolling, instance); + } + }); + }, 1000, timesToPoll); + } + + function cancelPolling (stopPolling, instance) { + $interval.cancel(stopPolling); + demoFlowFlags.showHangTightMessage = false; + demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); + } + } + }; +} diff --git a/client/directives/components/notifications/viewNotifications.jade b/client/directives/components/notifications/viewNotifications.jade index cf174a427..49a87718e 100644 --- a/client/directives/components/notifications/viewNotifications.jade +++ b/client/directives/components/notifications/viewNotifications.jade @@ -10,5 +10,7 @@ .grid-block( ng-if = "$root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage" - ng-include = "'firstBuildNotificationView'" + hang-tight + instance = "dataInstance.data.instance" + demo-flow-flags = "dataInstance.data.demoFlowFlags" ) diff --git a/test/unit/services/demoFlowService.unit.js b/test/unit/services/demoFlowService.unit.js new file mode 100644 index 000000000..e69de29bb From 7d8e35ea738e619e800353bb95ace9a06c97f9bf Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Thu, 8 Dec 2016 17:16:05 -0800 Subject: [PATCH 05/13] Fixed linting --- .../components/buildUpdateNotifications/hangTightDirective.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index d112dd3af..8caf3ec46 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -27,8 +27,7 @@ function hangTight( stopWatchingForRunningInstance(); pollContainerUrl(instance); } - }) - + }); function pollContainerUrl (instance) { var timesToPoll = 15; From 21d01b69531ba6aa3a460785e1abb15bb9aa8ba9 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Thu, 8 Dec 2016 18:18:40 -0800 Subject: [PATCH 06/13] PR comments --- client/controllers/controllerInstance.js | 1 + .../buildUpdateNotifications/hangTightDirective.js | 9 +++++---- .../components/notifications/viewNotifications.jade | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 9c0f2c9ba..4137eca28 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -33,6 +33,7 @@ function ControllerInstance( ) { var CIS = this; CIS.isInGuide = ahaGuide.isInGuide; + CIS.isInDemoFlow = demoFlowService.isInDemoFlow; var dataInstance = $scope.dataInstance = { data: { unsavedAcvs: [], diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index 8caf3ec46..0d5bc61e2 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -6,7 +6,8 @@ require('app') function hangTight( $interval, demoFlowService, - keypather + keypather, + watchOncePromise ) { return { restrict: 'A', @@ -19,12 +20,12 @@ function hangTight( var instance = $scope.instance; var demoFlowFlags = $scope.demoFlowFlags; - var stopWatchingForRunningInstance = $scope.$watch(function () { + watchOncePromise($scope, function () { return instance.status() === 'running'; - }, function () { + }, true) + .then(function () { if (keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && !demoFlowService.hasSeenUrlCallout()) { - stopWatchingForRunningInstance(); pollContainerUrl(instance); } }); diff --git a/client/directives/components/notifications/viewNotifications.jade b/client/directives/components/notifications/viewNotifications.jade index 49a87718e..7b51806f6 100644 --- a/client/directives/components/notifications/viewNotifications.jade +++ b/client/directives/components/notifications/viewNotifications.jade @@ -9,7 +9,7 @@ ) .grid-block( - ng-if = "$root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage" + ng-if = "CI.isInDemoFlow() && $root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage" hang-tight instance = "dataInstance.data.instance" demo-flow-flags = "dataInstance.data.demoFlowFlags" From e916fb2f1f32bb804f7eb7d52030df8a935275ab Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 8 Dec 2016 19:03:47 -0800 Subject: [PATCH 07/13] Move the getter for urlCallout popover into instanceHeaderView Move showHangTightMessage to getter in controllerInstance Cleaned up code that is no longer needed --- client/controllers/controllerInstance.js | 44 +++---------------- .../hangTightDirective.js | 22 +++------- .../containerUrl/containerUrlDirective.js | 4 -- .../containerUrl/containerUrlView.jade | 2 +- .../notifications/viewNotifications.jade | 5 +-- .../instance/instanceHeaderDirective.js | 9 ++++ .../instance/instanceHeaderView.jade | 2 +- client/services/demoFlowService.js | 6 +++ client/templates/viewInstance.jade | 4 +- 9 files changed, 34 insertions(+), 64 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 9c0f2c9ba..56fb6557d 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -31,8 +31,8 @@ function ControllerInstance( pageName, setLastInstance ) { - var CIS = this; - CIS.isInGuide = ahaGuide.isInGuide; + var CI = this; + CI.isInGuide = ahaGuide.isInGuide; var dataInstance = $scope.dataInstance = { data: { unsavedAcvs: [], @@ -207,41 +207,16 @@ function ControllerInstance( break; } - if (demoFlowService.isInDemoFlow()) { - checkForEnablingHangTightMessage(keypather.get($scope, 'dataInstance.data.instance')); - checkForEnablingUrlCallout(keypather.get($scope, 'dataInstance.data.instance')); - } - $timeout(function () { favico.setInstanceState(keypather.get($scope, 'dataInstance.data.instance')); }); }); - function checkForEnablingHangTightMessage (instance) { - if (!keypather.get(instance, 'contextVersion.getMainAppCodeVersion()')) { - return; - } - if (isBuildingOrStarting(instance.status())) { - if (!demoFlowService.hasSeenHangTightMessage()) { - data.demoFlowFlags.showHangTightMessage = true; - } - } - } - function checkForEnablingUrlCallout (instance) { - if (instance.status() === 'running' && - keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && - demoFlowService.hasSeenHangTightMessage() && - !demoFlowService.hasSeenUrlCallout()) { - data.demoFlowFlags.showUrlCallout = true; - } - } - - $scope.$on('dismissUrlCallout', function () { - if (data.demoFlowFlags.showUrlCallout) { - data.demoFlowFlags.showUrlCallout = false; - demoFlowService.setItem('hasSeenUrlCallout', data.instance.id()); - } - }); + CI.showHangTightMessage = function () { + return demoFlowService.isInDemoFlow() && + !demoFlowService.hasSeenHangTightMessage() && + !!keypather.get(dataInstance.data, 'instance.contextVersion.getMainAppCodeVersion()'); + }; if (ahaGuide.isInGuide()) { if (keypather.get(instancesByPod, 'models.length')) { @@ -259,9 +234,4 @@ function ControllerInstance( function fetchCurrentInstance () { return fetchInstances({ name: $stateParams.instanceName }, true); } - - function isBuildingOrStarting (status) { - return ['building', 'starting'].indexOf(status) !== -1; - } - } diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index d112dd3af..ef7ce4960 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -6,42 +6,33 @@ require('app') function hangTight( $interval, demoFlowService, - keypather + watchOncePromise ) { return { restrict: 'A', templateUrl: 'firstBuildNotificationView', scope: { instance: '=', - demoFlowFlags: '=' }, link: function ($scope) { var instance = $scope.instance; - var demoFlowFlags = $scope.demoFlowFlags; - var stopWatchingForRunningInstance = $scope.$watch(function () { + watchOncePromise($scope, function () { return instance.status() === 'running'; - }, function () { - if (keypather.get(instance, 'contextVersion.getMainAppCodeVersion()') && - !demoFlowService.hasSeenUrlCallout()) { - stopWatchingForRunningInstance(); - pollContainerUrl(instance); - } - }) + }, true) + .then(pollContainerUrl); - - function pollContainerUrl (instance) { + function pollContainerUrl () { var timesToPoll = 15; var stopPolling = $interval(function (timesToPoll) { // zero indexed, once we've polled 15 times just go to add branch if (timesToPoll === 14 && instance.status() === 'running') { - demoFlowService.setItem('hasSeenUrlCallout', instance.id()); + $scope.$emit('dismissUrlCallout', instance.id()); return cancelPolling(stopPolling, instance); } return demoFlowService.checkStatusOnInstance(instance) .then(function (statusOK) { if (statusOK) { - demoFlowFlags.showUrlCallout = true; return cancelPolling(stopPolling, instance); } }); @@ -50,7 +41,6 @@ function hangTight( function cancelPolling (stopPolling, instance) { $interval.cancel(stopPolling); - demoFlowFlags.showHangTightMessage = false; demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); } } diff --git a/client/directives/components/containerUrl/containerUrlDirective.js b/client/directives/components/containerUrl/containerUrlDirective.js index 442ff586b..93e2673d8 100644 --- a/client/directives/components/containerUrl/containerUrlDirective.js +++ b/client/directives/components/containerUrl/containerUrlDirective.js @@ -32,10 +32,6 @@ function containerUrl( $scope.openedContainerUrl = eventTracking.openedContainerUrl; $scope.shouldShowCopyButton = !UNAVAILABLE_OS_LIST.includes($window.navigator.platform); - $scope.dismissUrlCallout = function () { - $scope.$emit('dismissUrlCallout'); - }; - $scope.onClipboardEvent = function (err) { if (err) { var modifier = getModifierKey(); diff --git a/client/directives/components/containerUrl/containerUrlView.jade b/client/directives/components/containerUrl/containerUrlView.jade index 299ac07b0..ffb36d759 100644 --- a/client/directives/components/containerUrl/containerUrlView.jade +++ b/client/directives/components/containerUrl/containerUrlView.jade @@ -28,7 +28,7 @@ button.btn.btn-xs.white( a.btn.btn-xs.white( ng-click = "\ - dismissUrlCallout();\ + $emit('demo::dismissUrlCallout', instance);\ openedContainerUrl();\ " ng-href = "{{getContainerUrl(instance)}}" diff --git a/client/directives/components/notifications/viewNotifications.jade b/client/directives/components/notifications/viewNotifications.jade index 49a87718e..f6d7e85cf 100644 --- a/client/directives/components/notifications/viewNotifications.jade +++ b/client/directives/components/notifications/viewNotifications.jade @@ -4,13 +4,12 @@ ) .grid-block( - ng-if = "!dataInstance.data.instance.isMigrating() && (!$root.featureFlags.demoMultiTierBuilding || !dataInstance.data.demoFlowFlags.showHangTightMessage)" + ng-if = "!dataInstance.data.instance.isMigrating() && (!$root.featureFlags.demoMultiTierBuilding || !CI.showHangTightMessage())" ng-include = "'buildNotificationView'" ) .grid-block( - ng-if = "$root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage" + ng-if = "CI.showHangTightMessage()" hang-tight instance = "dataInstance.data.instance" - demo-flow-flags = "dataInstance.data.demoFlowFlags" ) diff --git a/client/directives/instances/instance/instanceHeaderDirective.js b/client/directives/instances/instance/instanceHeaderDirective.js index 567495b66..cfb9a40c1 100644 --- a/client/directives/instances/instance/instanceHeaderDirective.js +++ b/client/directives/instances/instance/instanceHeaderDirective.js @@ -10,6 +10,7 @@ function instanceHeader( $localStorage, $stateParams, ahaGuide, + demoFlowService, eventTracking, fetchPullRequest, keypather @@ -38,6 +39,14 @@ function instanceHeader( }); }); $scope.isInGuide = ahaGuide.isInGuide; + + $scope.showUrlCallout = function () { + return demoFlowService.isInDemoFlow() && + !!keypather.get($scope.instance, 'contextVersion.getMainAppCodeVersion()') && + !demoFlowService.hasSeenUrlCallout() && + demoFlowService.hasSeenHangTightMessage() && + keypather.get($scope.instance, 'status()') === 'running'; + }; } }; } diff --git a/client/directives/instances/instance/instanceHeaderView.jade b/client/directives/instances/instance/instanceHeaderView.jade index 48123f02d..e05437153 100644 --- a/client/directives/instances/instance/instanceHeaderView.jade +++ b/client/directives/instances/instance/instanceHeaderView.jade @@ -72,7 +72,7 @@ ) .popover.bottom.in.popover-url.below-modals( - ng-if = "$root.featureFlags.demoMultiTierUrl && demoFlowFlags.showUrlCallout" + ng-if = "$root.featureFlags.demoMultiTierUrl && showUrlCallout()" ng-include = "'containerUrlPopoverView'" ) diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index a59d66c5b..6d9a4ca99 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -6,6 +6,7 @@ require('app') function demoFlowService( $http, $localStorage, + $rootScope, currentOrg, defaultContainerUrl, keypather, @@ -75,6 +76,11 @@ function demoFlowService( function isUsingDemoRepo () { return $localStorage.isUsingDemoRepo; } + $rootScope.$on('demo::dismissUrlCallout', function ($event, instance) { + if (!hasSeenUrlCallout()) { + setItem('hasSeenUrlCallout', instance.id()); + } + }); return { checkStatusOnInstance: checkStatusOnInstance, diff --git a/client/templates/viewInstance.jade b/client/templates/viewInstance.jade index 75614ec0d..0b8df4973 100644 --- a/client/templates/viewInstance.jade +++ b/client/templates/viewInstance.jade @@ -26,12 +26,12 @@ ng-class = "{\ 'green': dataInstance.data.showUpdatedMessage,\ 'orange': dataInstance.data.showUpdatingMessage || dataInstance.data.instance.isMigrating(),\ - 'white below-modals': $root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage\ + 'white below-modals': $root.featureFlags.demoMultiTierBuilding && CI.showHangTightMessage()\ }" ng-if = "\ (dataInstance.data.showUpdatingMessage || dataInstance.data.showUpdatedMessage) ||\ dataInstance.data.instance.isMigrating() ||\ - ($root.featureFlags.demoMultiTierBuilding && dataInstance.data.demoFlowFlags.showHangTightMessage)\ + ($root.featureFlags.demoMultiTierBuilding && CI.showHangTightMessage())\ " ng-include = "'viewNotifications'" ) From 2618146dbcf64c3f58b130cebaa86fd163edab80 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 8 Dec 2016 19:09:06 -0800 Subject: [PATCH 08/13] remove unneeded changes --- client/controllers/controllerInstance.js | 1 - test/unit/controllers/controllerInstance.unit.js | 3 --- 2 files changed, 4 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 56fb6557d..9cfde9e28 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -6,7 +6,6 @@ require('app') * @ngInject */ function ControllerInstance( - $interval, $localStorage, $q, $rootScope, diff --git a/test/unit/controllers/controllerInstance.unit.js b/test/unit/controllers/controllerInstance.unit.js index e1e2bf239..0dc20cdb4 100644 --- a/test/unit/controllers/controllerInstance.unit.js +++ b/test/unit/controllers/controllerInstance.unit.js @@ -4,7 +4,6 @@ // injector-provided var $controller; var $httpBackend; -var $interval; var $rootScope; var $scope; var $state; @@ -115,7 +114,6 @@ describe('controllerInstance'.bold.underline.blue, function () { angular.mock.inject(function ( _$controller_, _$httpBackend_, - _$interval_, _$rootScope_, _$stateParams_, _$state_, @@ -128,7 +126,6 @@ describe('controllerInstance'.bold.underline.blue, function () { ) { $controller = _$controller_; $httpBackend = _$httpBackend_; - $interval = _$interval_; $rootScope = _$rootScope_; $state = _$state_; $stateParams = _$stateParams_; From d13ffc33303c79e385a18573affef29092dc7341 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 8 Dec 2016 19:47:16 -0800 Subject: [PATCH 09/13] make sure status 0 is false --- client/services/demoFlowService.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index 9ce3974c4..92dfeee97 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -52,15 +52,9 @@ function demoFlowService( function checkStatusOnInstance (instance) { var url = defaultContainerUrl(instance); - return $http({ - method: 'get', - url: url - }) - .then(function(res) { - if (res.status < 300) { - return true; - } - return false; + return $http.get(url) + .then(function (res) { + return res.status >= 200 && res.status < 300; }) .catch(function () { return true; From 161d689ebe183667ed34d463d67fe6d6dea63005 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Fri, 9 Dec 2016 14:59:41 -0800 Subject: [PATCH 10/13] Adding unit tests for hangTight directive --- .../hangTightDirective.js | 6 +- .../notifications/hangTightDirective.unit.js | 103 ++++++++++++++++++ 2 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 test/unit/directives/components/notifications/hangTightDirective.unit.js diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index ef7ce4960..861710ce7 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -12,7 +12,7 @@ function hangTight( restrict: 'A', templateUrl: 'firstBuildNotificationView', scope: { - instance: '=', + instance: '=' }, link: function ($scope) { var instance = $scope.instance; @@ -27,11 +27,13 @@ function hangTight( var stopPolling = $interval(function (timesToPoll) { // zero indexed, once we've polled 15 times just go to add branch if (timesToPoll === 14 && instance.status() === 'running') { - $scope.$emit('dismissUrlCallout', instance.id()); + $scope.$emit('demo::dismissUrlCallout', instance); return cancelPolling(stopPolling, instance); } + console.log('demoFlowService'); return demoFlowService.checkStatusOnInstance(instance) .then(function (statusOK) { + console.log('status', statusOK); if (statusOK) { return cancelPolling(stopPolling, instance); } diff --git a/test/unit/directives/components/notifications/hangTightDirective.unit.js b/test/unit/directives/components/notifications/hangTightDirective.unit.js new file mode 100644 index 000000000..f0ef6d076 --- /dev/null +++ b/test/unit/directives/components/notifications/hangTightDirective.unit.js @@ -0,0 +1,103 @@ +'use strict'; + +var $rootScope; +var $scope; +var element; +var $compile; +var $interval; +var $q; +var $elScope; + +describe('hangTight'.bold.underline.blue, function () { + + var mockInstance; + var demoFlowService; + var mockMainACV; + var mockOpenItems; + + beforeEach(function () { + angular.mock.module('app', function ($provide) { + $provide.factory('demoFlowService', function ($q) { + demoFlowService = { + checkStatusOnInstance: sinon.stub().returns($q.when(false)), + setItem: sinon.stub() + }; + return demoFlowService; + }); + }); + angular.mock.inject(function (_$compile_, _$interval_, _$rootScope_, _$q_) { + $rootScope = _$rootScope_; + $compile = _$compile_; + $interval = _$interval_; + $scope = $rootScope.$new(); + $q = _$q_; + sinon.stub($interval, 'cancel'); + + mockMainACV = { + attrs: { + mainACVAttrs: true + } + }; + mockInstance = { + attrs: { + name: 'foo' + }, + restart: sinon.spy(), + fetch: sinon.spy(), + status: sinon.stub().returns('running'), + stop: sinon.spy(), + start: sinon.spy(), + build: { + deepCopy: sinon.spy() + }, + contextVersion: { + getMainAppCodeVersion: sinon.stub().returns(mockMainACV) + }, + fetchDependencies: sinon.stub().returns({ + models: [] + }), + id: sinon.stub().returns(1), + on: sinon.spy() + }; + $scope.instance = mockInstance; + + mockOpenItems = {}; + + mockOpenItems.getAllFileModels = sinon.stub().returns(mockOpenItems.models); + + var template = directiveTemplate.attribute('hang-tight', { + instance: 'instance', + }); + + element = $compile(template)($scope); + $scope.$digest(); + $elScope = element.isolateScope(); + }); + }); + + describe('watching instance', function () { + it('should poll the status until it retuns true', function () { + $interval.flush(1000); + $scope.$digest(); + sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance); + demoFlowService.checkStatusOnInstance = sinon.stub().returns($q.when(true)); + $interval.flush(1000); + $scope.$digest(); + sinon.assert.calledOnce($interval.cancel); + sinon.assert.calledOnce(demoFlowService.setItem); + }); + it('should emit dismissUrlCallout when it tries 15 times', function () { + var dismissStub = sinon.stub(); + $rootScope.$on('demo::dismissUrlCallout', dismissStub); + $interval.flush(1000); + $scope.$digest(); + sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance); + $interval.flush(15000); + $scope.$digest(); + sinon.assert.calledOnce(dismissStub); + sinon.assert.calledWith(dismissStub, sinon.match.any, mockInstance); + sinon.assert.calledOnce($interval.cancel); + sinon.assert.calledOnce(demoFlowService.setItem); + }); + }); +}); From 197e2f08254a8e50c55bb7925a58e5649c5762da Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Fri, 9 Dec 2016 15:00:08 -0800 Subject: [PATCH 11/13] remove console logs --- .../components/buildUpdateNotifications/hangTightDirective.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index 861710ce7..2a06bd973 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -30,10 +30,8 @@ function hangTight( $scope.$emit('demo::dismissUrlCallout', instance); return cancelPolling(stopPolling, instance); } - console.log('demoFlowService'); return demoFlowService.checkStatusOnInstance(instance) .then(function (statusOK) { - console.log('status', statusOK); if (statusOK) { return cancelPolling(stopPolling, instance); } From cb44e4a8c577f28f4580ebb0d8cc7f55ec324eae Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Fri, 9 Dec 2016 15:07:24 -0800 Subject: [PATCH 12/13] switch the emit to take in the id, not the whole instance --- .../components/buildUpdateNotifications/hangTightDirective.js | 2 +- .../directives/components/containerUrl/containerUrlView.jade | 2 +- client/services/demoFlowService.js | 4 ++-- .../components/notifications/hangTightDirective.unit.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/directives/components/buildUpdateNotifications/hangTightDirective.js b/client/directives/components/buildUpdateNotifications/hangTightDirective.js index 2a06bd973..b548da916 100644 --- a/client/directives/components/buildUpdateNotifications/hangTightDirective.js +++ b/client/directives/components/buildUpdateNotifications/hangTightDirective.js @@ -27,7 +27,7 @@ function hangTight( var stopPolling = $interval(function (timesToPoll) { // zero indexed, once we've polled 15 times just go to add branch if (timesToPoll === 14 && instance.status() === 'running') { - $scope.$emit('demo::dismissUrlCallout', instance); + $scope.$emit('demo::dismissUrlCallout', instance.id()); return cancelPolling(stopPolling, instance); } return demoFlowService.checkStatusOnInstance(instance) diff --git a/client/directives/components/containerUrl/containerUrlView.jade b/client/directives/components/containerUrl/containerUrlView.jade index ffb36d759..2d2fa2ac5 100644 --- a/client/directives/components/containerUrl/containerUrlView.jade +++ b/client/directives/components/containerUrl/containerUrlView.jade @@ -28,7 +28,7 @@ button.btn.btn-xs.white( a.btn.btn-xs.white( ng-click = "\ - $emit('demo::dismissUrlCallout', instance);\ + $emit('demo::dismissUrlCallout', instance.id());\ openedContainerUrl();\ " ng-href = "{{getContainerUrl(instance)}}" diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index 92dfeee97..bc83d038b 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -82,9 +82,9 @@ function demoFlowService( function isUsingDemoRepo () { return $localStorage.isUsingDemoRepo; } - $rootScope.$on('demo::dismissUrlCallout', function ($event, instance) { + $rootScope.$on('demo::dismissUrlCallout', function ($event, instanceId) { if (!hasSeenUrlCallout()) { - setItem('hasSeenUrlCallout', instance.id()); + setItem('hasSeenUrlCallout', instanceId); } }); diff --git a/test/unit/directives/components/notifications/hangTightDirective.unit.js b/test/unit/directives/components/notifications/hangTightDirective.unit.js index f0ef6d076..a62bb1bb4 100644 --- a/test/unit/directives/components/notifications/hangTightDirective.unit.js +++ b/test/unit/directives/components/notifications/hangTightDirective.unit.js @@ -95,7 +95,7 @@ describe('hangTight'.bold.underline.blue, function () { $interval.flush(15000); $scope.$digest(); sinon.assert.calledOnce(dismissStub); - sinon.assert.calledWith(dismissStub, sinon.match.any, mockInstance); + sinon.assert.calledWith(dismissStub, sinon.match.any, mockInstance.id()); sinon.assert.calledOnce($interval.cancel); sinon.assert.calledOnce(demoFlowService.setItem); }); From c2158284b19d3a74de8a8cd102e4dc69080046ad Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Fri, 9 Dec 2016 18:26:06 -0800 Subject: [PATCH 13/13] stub --- .../notifications/hangTightDirective.unit.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/directives/components/notifications/hangTightDirective.unit.js b/test/unit/directives/components/notifications/hangTightDirective.unit.js index a62bb1bb4..c5ddbede9 100644 --- a/test/unit/directives/components/notifications/hangTightDirective.unit.js +++ b/test/unit/directives/components/notifications/hangTightDirective.unit.js @@ -42,13 +42,13 @@ describe('hangTight'.bold.underline.blue, function () { attrs: { name: 'foo' }, - restart: sinon.spy(), - fetch: sinon.spy(), + restart: sinon.stub(), + fetch: sinon.stub(), status: sinon.stub().returns('running'), - stop: sinon.spy(), - start: sinon.spy(), + stop: sinon.stub(), + start: sinon.stub(), build: { - deepCopy: sinon.spy() + deepCopy: sinon.stub() }, contextVersion: { getMainAppCodeVersion: sinon.stub().returns(mockMainACV) @@ -57,7 +57,7 @@ describe('hangTight'.bold.underline.blue, function () { models: [] }), id: sinon.stub().returns(1), - on: sinon.spy() + on: sinon.stub() }; $scope.instance = mockInstance;