Skip to content

Commit

Permalink
Merge pull request #1915 from CodeNow/SAN-5460-add-hang-tight
Browse files Browse the repository at this point in the history
Add new watcher for hang-tight message
  • Loading branch information
thejsj authored Nov 28, 2016
2 parents 7007387 + 3d6a6e1 commit edd5546
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
32 changes: 29 additions & 3 deletions client/controllers/controllerInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function ControllerInstance(
pageName,
setLastInstance
) {

var CIS = this;
CIS.isInGuide = ahaGuide.isInGuide;
var dataInstance = $scope.dataInstance = {
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -78,6 +79,8 @@ function ControllerInstance(
var instance = results.instance;
data.instance = instance;

checkForEnablingHangTightMessage(instance);

// Check that current commit is not already building
var currentCommit = keypather.get(instance, 'attrs.contextVersion.appCodeVersions[0].commit');
getCommitForCurrentlyBuildingBuild(instance)
Expand Down Expand Up @@ -201,11 +204,26 @@ function ControllerInstance(
data.openItems.removeAllButBuildLogs();
break;
}
if (!isBuildingOrStarting(status) && data.showHangTightMessage) {
data.showHangTightMessage = false;
}
$timeout(function () {
favico.setInstanceState(keypather.get($scope, 'dataInstance.data.instance'));
});
});

function checkForEnablingHangTightMessage (instance) {
// Only show message if user hasn't:
// 1. Seen message before
if ($scope.$storage.hasSeenHangTightMessage) { return; }
// 2. Is looking at a repo instance
if (!keypather.get(instance, 'contextVersion.getMainAppCodeVersion()')) { return; }
// 3. Container is currently building or starting
if (!isBuildingOrStarting(instance.status())) { return; }
$scope.$storage.hasSeenHangTightMessage = true;
data.showHangTightMessage = true;
}

if (ahaGuide.isInGuide()) {
if (keypather.get(instancesByPod, 'models.length')) {
if (instancesByPod.models.some(function (instance) {
Expand All @@ -218,4 +236,12 @@ function ControllerInstance(
}
}
}

function fetchCurrentInstance () {
return fetchInstances({ name: $stateParams.instanceName }, true);
}

function isBuildingOrStarting (status) {
return ['building', 'starting'].indexOf(status) !== -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
)

.grid-block(
ng-if = "$root.featureFlags.demoMultiTierBuilding"
ng-if = "dataInstance.data.showHangTightMessage && $root.featureFlags.demoMultiTierBuilding"
ng-include = "'firstBuildNotificationView'"
)
3 changes: 3 additions & 0 deletions client/services/ahaGuideService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var STEPS = {
};

function ahaGuide(
$localStorage,
$rootScope,
currentOrg,
eventTracking,
Expand All @@ -25,6 +26,7 @@ function ahaGuide(
var instances = [];
var hasRunnabot = false;
var ahaModalController;
var $storage = $localStorage.$default({});
function refreshInstances() {
return fetchInstancesByPod()
.then(function (fetchedInstances) {
Expand Down Expand Up @@ -341,6 +343,7 @@ function ahaGuide(
}
})
.then(function (updatedOrg) {
delete $storage.hasSeenHangTightMessage;
updateCurrentOrg(updatedOrg);
});
}
Expand Down
2 changes: 1 addition & 1 deletion client/templates/viewInstance.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
4 changes: 3 additions & 1 deletion test/unit/controllers/controllerInstance.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit edd5546

Please sign in to comment.