From fc719d10956c5b59b8e6700af7a9a8c9ceee8476 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 14:00:51 -0800 Subject: [PATCH 01/12] Add new watcher for hang-tight message --- client/controllers/controllerInstance.js | 47 +++++++++++++++++-- .../notifications/viewNotifications.jade | 2 +- client/services/ahaGuideService.js | 3 ++ client/templates/viewInstance.jade | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 6e4fee42f..da50afd54 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -29,7 +29,6 @@ function ControllerInstance( pageName, setLastInstance ) { - var CIS = this; CIS.isInGuide = ahaGuide.isInGuide; var dataInstance = $scope.dataInstance = { @@ -39,7 +38,9 @@ function ControllerInstance( actions: {} }; var data = dataInstance.data; - $scope.$storage = $localStorage; + $scope.$storage = $localStorage.$default({ + hasSeenHangTightMessage: false + }); loading('main', true); data.openItems = new OpenItems(); @@ -59,7 +60,7 @@ function ControllerInstance( // product team - track visits to instance page & referrer eventTracking.visitedState(); return $q.all({ - instance: fetchInstances({ name: $stateParams.instanceName }, true), + instance: fetchCurrentInstance(), settings: fetchSettings() }) .then(function (results) { @@ -201,11 +202,47 @@ function ControllerInstance( data.openItems.removeAllButBuildLogs(); break; } + if (['building', 'starting'].indexOf(status) === -1 && keypather.get($scope, 'dataInstance.data.instance.attrs.id') === data.showHangTightMessage) { + data.showHangTightMessage = false; + } $timeout(function () { favico.setInstanceState(keypather.get($scope, 'dataInstance.data.instance')); }); }); + // Only listen to hang tight message if we're going to show it + if (!$scope.$storage.hasSeenHangTightMessage) { + var stopWatcherFornewRepoInstanced = $scope.$watch(function () { + return instancesByPod.models.filter(function (instance) { + return keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0]'); + }).length; + }, numberOfInstancesUpdatedHandler); + } + + function numberOfInstancesUpdatedHandler (newVal, previousVal) { + $q.when() + .then(function () { + var instance = keypather.get(data, 'instance'); + if (instance) { return instance; } + return fetchCurrentInstance(); + }) + .then(function (instance) { + var currentInstanceIsRepoInstance = keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0]'); + // Only show message if user hasn't: + // 1. Seen message before + if ($scope.$storage.hasSeenHangTightMessage) { return; } + // 2. Is looking at a repo instance + if (!currentInstanceIsRepoInstance) { return; } + // 3. Container is currently building + if (['building', 'starting'].indexOf(instance.status()) === -1) { return; } + $scope.$storage.hasSeenHangTightMessage = true; + data.showHangTightMessage = instance.attrs.id; + if (stopWatcherFornewRepoInstanced) { + stopWatcherFornewRepoInstanced(); + } + }); + } + if (ahaGuide.isInGuide()) { if (keypather.get(instancesByPod, 'models.length')) { if (instancesByPod.models.some(function (instance) { @@ -218,4 +255,8 @@ function ControllerInstance( } } } + + function fetchCurrentInstance () { + return fetchInstances({ name: $stateParams.instanceName }, true); + } } diff --git a/client/directives/components/notifications/viewNotifications.jade b/client/directives/components/notifications/viewNotifications.jade index fa0fb8b81..5b5cac60d 100644 --- a/client/directives/components/notifications/viewNotifications.jade +++ b/client/directives/components/notifications/viewNotifications.jade @@ -9,6 +9,6 @@ ) .grid-block( - ng-if = "$root.featureFlags.demoMultiTierBuilding" + ng-if = "dataInstance.data.showHangTightMessage && $root.featureFlags.demoMultiTierBuilding" ng-include = "'firstBuildNotificationView'" ) diff --git a/client/services/ahaGuideService.js b/client/services/ahaGuideService.js index 00e13acd9..4459c703d 100644 --- a/client/services/ahaGuideService.js +++ b/client/services/ahaGuideService.js @@ -12,6 +12,7 @@ var STEPS = { }; function ahaGuide( + $localStorage, $rootScope, currentOrg, eventTracking, @@ -25,6 +26,7 @@ function ahaGuide( var instances = []; var hasRunnabot = false; var ahaModalController; + var $storage = $localStorage.$default({}); function refreshInstances() { return fetchInstancesByPod() .then(function (fetchedInstances) { @@ -343,6 +345,7 @@ function ahaGuide( } }) .then(function (updatedOrg) { + delete $storage.hasSeenHangTightMessage; updateCurrentOrg(updatedOrg); }); } diff --git a/client/templates/viewInstance.jade b/client/templates/viewInstance.jade index 94f3a463b..3bb18975b 100644 --- a/client/templates/viewInstance.jade +++ b/client/templates/viewInstance.jade @@ -26,7 +26,7 @@ ng-class = "{\ 'green': dataInstance.data.showUpdatedMessage,\ 'orange': dataInstance.data.showUpdatingMessage || dataInstance.data.instance.isMigrating(),\ - 'white': $root.featureFlags.demoMultiTierBuilding\ + 'white': $root.featureFlags.demoMultiTierBuilding && dataInstance.data.showHangTightMessage\ }" ng-if = "(dataInstance.data.showUpdatingMessage || dataInstance.data.showUpdatedMessage) || dataInstance.data.instance.isMigrating() || $root.featureFlags.demoMultiTierBuilding" ng-include = "'viewNotifications'" From 8168a8a3ea9cb4e0b037015ce5e0d87097a201e8 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 14:05:20 -0800 Subject: [PATCH 02/12] Add isBuildingOrStarting function --- client/controllers/controllerInstance.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index da50afd54..c2a25b386 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -202,7 +202,7 @@ function ControllerInstance( data.openItems.removeAllButBuildLogs(); break; } - if (['building', 'starting'].indexOf(status) === -1 && keypather.get($scope, 'dataInstance.data.instance.attrs.id') === data.showHangTightMessage) { + if (!isBuildingOrStarting(status) && keypather.get($scope, 'dataInstance.data.instance.attrs.id') === data.showHangTightMessage) { data.showHangTightMessage = false; } $timeout(function () { @@ -233,8 +233,8 @@ function ControllerInstance( if ($scope.$storage.hasSeenHangTightMessage) { return; } // 2. Is looking at a repo instance if (!currentInstanceIsRepoInstance) { return; } - // 3. Container is currently building - if (['building', 'starting'].indexOf(instance.status()) === -1) { return; } + // 3. Container is currently building or starting + if (!isBuildingOrStarting(instance.status())) { return; } $scope.$storage.hasSeenHangTightMessage = true; data.showHangTightMessage = instance.attrs.id; if (stopWatcherFornewRepoInstanced) { @@ -259,4 +259,8 @@ function ControllerInstance( function fetchCurrentInstance () { return fetchInstances({ name: $stateParams.instanceName }, true); } + + function isBuildingOrStarting () { + return ['building', 'starting'].indexOf(status) !== -1; + } } From ab38c78a7bbe2c45c778feeb6fc0d08641bb7d69 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 14:08:10 -0800 Subject: [PATCH 03/12] Fix typo --- client/controllers/controllerInstance.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index c2a25b386..cc17f5857 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -212,7 +212,7 @@ function ControllerInstance( // Only listen to hang tight message if we're going to show it if (!$scope.$storage.hasSeenHangTightMessage) { - var stopWatcherFornewRepoInstanced = $scope.$watch(function () { + var stopWatcherForNewRepoInstances = $scope.$watch(function () { return instancesByPod.models.filter(function (instance) { return keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0]'); }).length; @@ -237,8 +237,8 @@ function ControllerInstance( if (!isBuildingOrStarting(instance.status())) { return; } $scope.$storage.hasSeenHangTightMessage = true; data.showHangTightMessage = instance.attrs.id; - if (stopWatcherFornewRepoInstanced) { - stopWatcherFornewRepoInstanced(); + if (stopWatcherForNewRepoInstances) { + stopWatcherForNewRepoInstances(); } }); } From e87728a82d446b1b606cef0a099b8dd3846a5dcb Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 14:26:37 -0800 Subject: [PATCH 04/12] Fix tests --- test/unit/controllers/controllerInstance.unit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/controllers/controllerInstance.unit.js b/test/unit/controllers/controllerInstance.unit.js index 1086b0f8a..0dc20cdb4 100644 --- a/test/unit/controllers/controllerInstance.unit.js +++ b/test/unit/controllers/controllerInstance.unit.js @@ -69,7 +69,9 @@ describe('controllerInstance'.bold.underline.blue, function () { ADD_FIRST_BRANCH: 123 } }); - $provide.value('instancesByPod', {}); + $provide.value('instancesByPod', { + models: [] + }); $provide.value('favico', mockFavico); $provide.factory('fetchUser', function ($q) { return function () { From be4fd7742dfd1a323e2793c91b96a2f42b31ac32 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 14:37:32 -0800 Subject: [PATCH 05/12] Fix status --- client/controllers/controllerInstance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index cc17f5857..3359b5ce3 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -260,7 +260,7 @@ function ControllerInstance( return fetchInstances({ name: $stateParams.instanceName }, true); } - function isBuildingOrStarting () { + function isBuildingOrStarting (status) { return ['building', 'starting'].indexOf(status) !== -1; } } From e520f80961b508995a2a6e13006610189c6b0add Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:19:31 -0800 Subject: [PATCH 06/12] Remove unnecessary watcher --- client/controllers/controllerInstance.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 3359b5ce3..3e6613ec8 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -212,11 +212,7 @@ function ControllerInstance( // Only listen to hang tight message if we're going to show it if (!$scope.$storage.hasSeenHangTightMessage) { - var stopWatcherForNewRepoInstances = $scope.$watch(function () { - return instancesByPod.models.filter(function (instance) { - return keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0]'); - }).length; - }, numberOfInstancesUpdatedHandler); + numberOfInstancesUpdatedHandler(); } function numberOfInstancesUpdatedHandler (newVal, previousVal) { @@ -227,7 +223,7 @@ function ControllerInstance( return fetchCurrentInstance(); }) .then(function (instance) { - var currentInstanceIsRepoInstance = keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0]'); + var currentInstanceIsRepoInstance = keypather.get(instance, 'contextVersion.getMainAppCodeVersion()'); // Only show message if user hasn't: // 1. Seen message before if ($scope.$storage.hasSeenHangTightMessage) { return; } @@ -237,9 +233,6 @@ function ControllerInstance( if (!isBuildingOrStarting(instance.status())) { return; } $scope.$storage.hasSeenHangTightMessage = true; data.showHangTightMessage = instance.attrs.id; - if (stopWatcherForNewRepoInstances) { - stopWatcherForNewRepoInstances(); - } }); } From 39eb297180db6055c86a3c52f3b2223827c315a5 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:35:02 -0800 Subject: [PATCH 07/12] Remove unused function params --- client/controllers/controllerInstance.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 3e6613ec8..8575524bb 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -215,7 +215,7 @@ function ControllerInstance( numberOfInstancesUpdatedHandler(); } - function numberOfInstancesUpdatedHandler (newVal, previousVal) { + function numberOfInstancesUpdatedHandler () { $q.when() .then(function () { var instance = keypather.get(data, 'instance'); From 02f8e5839e8efec9e144c88c4c5d064ca4d350da Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:38:29 -0800 Subject: [PATCH 08/12] Remove even more code --- client/controllers/controllerInstance.js | 40 ++++++++++-------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 8575524bb..d3cdf87ae 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -79,6 +79,11 @@ function ControllerInstance( var instance = results.instance; data.instance = instance; + // Only listen to hang tight message if we're going to show it + if (!$scope.$storage.hasSeenHangTightMessage) { + numberOfInstancesUpdatedHandler(instance); + } + // Check that current commit is not already building var currentCommit = keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0].commit'); getCommitForCurrentlyBuildingBuild(instance) @@ -210,30 +215,17 @@ function ControllerInstance( }); }); - // Only listen to hang tight message if we're going to show it - if (!$scope.$storage.hasSeenHangTightMessage) { - numberOfInstancesUpdatedHandler(); - } - - function numberOfInstancesUpdatedHandler () { - $q.when() - .then(function () { - var instance = keypather.get(data, 'instance'); - if (instance) { return instance; } - return fetchCurrentInstance(); - }) - .then(function (instance) { - var currentInstanceIsRepoInstance = keypather.get(instance, 'contextVersion.getMainAppCodeVersion()'); - // Only show message if user hasn't: - // 1. Seen message before - if ($scope.$storage.hasSeenHangTightMessage) { return; } - // 2. Is looking at a repo instance - if (!currentInstanceIsRepoInstance) { return; } - // 3. Container is currently building or starting - if (!isBuildingOrStarting(instance.status())) { return; } - $scope.$storage.hasSeenHangTightMessage = true; - data.showHangTightMessage = instance.attrs.id; - }); + function numberOfInstancesUpdatedHandler (instance) { + var currentInstanceIsRepoInstance = keypather.get(instance, 'contextVersion.getMainAppCodeVersion()'); + // Only show message if user hasn't: + // 1. Seen message before + if ($scope.$storage.hasSeenHangTightMessage) { return; } + // 2. Is looking at a repo instance + if (!currentInstanceIsRepoInstance) { return; } + // 3. Container is currently building or starting + if (!isBuildingOrStarting(instance.status())) { return; } + $scope.$storage.hasSeenHangTightMessage = true; + data.showHangTightMessage = instance.attrs.id; } if (ahaGuide.isInGuide()) { From 3481c91596fc9ae5ac0931b1df3f2fb6ce81c6c5 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:39:50 -0800 Subject: [PATCH 09/12] Rename function --- client/controllers/controllerInstance.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index d3cdf87ae..d73839f01 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -81,7 +81,7 @@ function ControllerInstance( // Only listen to hang tight message if we're going to show it if (!$scope.$storage.hasSeenHangTightMessage) { - numberOfInstancesUpdatedHandler(instance); + checkForEnablingHangTightMessage(instance); } // Check that current commit is not already building @@ -215,7 +215,7 @@ function ControllerInstance( }); }); - function numberOfInstancesUpdatedHandler (instance) { + function checkForEnablingHangTightMessage (instance) { var currentInstanceIsRepoInstance = keypather.get(instance, 'contextVersion.getMainAppCodeVersion()'); // Only show message if user hasn't: // 1. Seen message before From 8e669afeb0fbd71f8e1bcf69c2e185155c3c3dff Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:45:13 -0800 Subject: [PATCH 10/12] Move code --- client/controllers/controllerInstance.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index d73839f01..516ab69c1 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -216,12 +216,11 @@ function ControllerInstance( }); function checkForEnablingHangTightMessage (instance) { - var currentInstanceIsRepoInstance = keypather.get(instance, 'contextVersion.getMainAppCodeVersion()'); // Only show message if user hasn't: // 1. Seen message before if ($scope.$storage.hasSeenHangTightMessage) { return; } // 2. Is looking at a repo instance - if (!currentInstanceIsRepoInstance) { return; } + if (!keypather.get(instance, 'contextVersion.getMainAppCodeVersion()')) { return; } // 3. Container is currently building or starting if (!isBuildingOrStarting(instance.status())) { return; } $scope.$storage.hasSeenHangTightMessage = true; From 1e51ae4fd0120d34238c2ae8247bdf49d15866f3 Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:48:46 -0800 Subject: [PATCH 11/12] Remove double check --- client/controllers/controllerInstance.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 516ab69c1..5f5a8e4a5 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -79,10 +79,7 @@ function ControllerInstance( var instance = results.instance; data.instance = instance; - // Only listen to hang tight message if we're going to show it - if (!$scope.$storage.hasSeenHangTightMessage) { - checkForEnablingHangTightMessage(instance); - } + checkForEnablingHangTightMessage(instance); // Check that current commit is not already building var currentCommit = keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0].commit'); From 3d6a6e1f3114881820a6751d4409cf767027b97c Mon Sep 17 00:00:00 2001 From: thejsj Date: Mon, 28 Nov 2016 15:51:41 -0800 Subject: [PATCH 12/12] Remove unnecessary id --- client/controllers/controllerInstance.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/controllers/controllerInstance.js b/client/controllers/controllerInstance.js index 5f5a8e4a5..199f7890c 100644 --- a/client/controllers/controllerInstance.js +++ b/client/controllers/controllerInstance.js @@ -204,7 +204,7 @@ function ControllerInstance( data.openItems.removeAllButBuildLogs(); break; } - if (!isBuildingOrStarting(status) && keypather.get($scope, 'dataInstance.data.instance.attrs.id') === data.showHangTightMessage) { + if (!isBuildingOrStarting(status) && data.showHangTightMessage) { data.showHangTightMessage = false; } $timeout(function () { @@ -221,7 +221,7 @@ function ControllerInstance( // 3. Container is currently building or starting if (!isBuildingOrStarting(instance.status())) { return; } $scope.$storage.hasSeenHangTightMessage = true; - data.showHangTightMessage = instance.attrs.id; + data.showHangTightMessage = true; } if (ahaGuide.isInGuide()) {