Skip to content

Update overview to use toast notifications #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions app/scripts/controllers/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
'Logger',
'MetricsService',
'Navigate',
'NotificationsService',
'OwnerReferencesService',
'PodsService',
'ProjectsService',
Expand All @@ -45,6 +46,7 @@ function OverviewController($scope,
Logger,
MetricsService,
Navigate,
NotificationsService,
OwnerReferencesService,
PodsService,
ProjectsService,
Expand Down Expand Up @@ -1087,16 +1089,36 @@ function OverviewController($scope,
$scope.$evalAsync(updateFilter);
});

overview.startBuild = function(buildConfig) {
// This is used by the overview empty state message and also the list row,
// which is why it's assigned to the `state` object.
overview.startBuild = state.startBuild = function(buildConfig) {
var buildType = isJenkinsPipelineStrategy(buildConfig) ? 'pipeline' : 'build';
BuildsService
.startBuild(buildConfig.metadata.name, { namespace: buildConfig.metadata.namespace })
.then(_.noop, function(result) {
var buildType = isJenkinsPipelineStrategy(buildConfig) ? 'pipeline' : 'build';
state.alerts["start-build"] = {
.then(function(build) {
var buildName;
var buildNumber = annotation(build, 'buildNumber');
var buildURL = Navigate.resourceURL(build);
if (buildNumber) {
buildName = buildConfig.metadata.name + " #" + buildNumber;
} else {
buildName = build.metadata.name;
}

NotificationsService.addNotification({
type: "success",
message: _.capitalize(buildType) + " " + buildName + " successfully created.",
links: [{
href: buildURL,
label: 'View ' + _.capitalize(buildType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not have the View Log link here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I linked to the build instead of the log is because the build might not start immediately. But I'm not against changing it.

}]
});
}, function(result) {
NotificationsService.addNotification({
type: "error",
message: "An error occurred while starting the " + buildType + ".",
details: getErrorDetails(result)
};
});
});
};

Expand Down
34 changes: 12 additions & 22 deletions app/scripts/directives/overview/listRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
'APIService',
'BuildsService',
'DeploymentsService',
'Navigate',
'ListRowUtils',
'Navigate',
'NotificationsService',
OverviewListRow
],
controllerAs: 'row',
Expand All @@ -29,17 +30,16 @@
APIService,
BuildsService,
DeploymentsService,
ListRowUtils,
Navigate,
rowMethods) {
NotificationsService) {
var row = this;

_.extend(row, rowMethods.ui);
_.extend(row, ListRowUtils.ui);

var canI = $filter('canI');
var deploymentIsInProgress = $filter('deploymentIsInProgress');
var getErrorDetails = $filter('getErrorDetails');
var isBinaryBuild = $filter('isBinaryBuild');
var isJenkinsPipelineStrategy = $filter('isJenkinsPipelineStrategy');

var updateTriggers = function(apiObject) {
var triggers = _.get(apiObject, 'spec.triggers');
Expand Down Expand Up @@ -95,7 +95,7 @@

row.$doCheck = function() {
// Update notifications.
row.notifications = rowMethods.getNotifications(row.apiObject, row.state);
row.notifications = ListRowUtils.getNotifications(row.apiObject, row.state);

// Update HPA.
row.hpa = getHPA(row.apiObject);
Expand Down Expand Up @@ -213,18 +213,8 @@
return canI('buildconfigs/instantiate', 'create') && _.size(row.pipelines) === 1;
};

row.startBuild = function(buildConfig) {
BuildsService
.startBuild(buildConfig.metadata.name, { namespace: buildConfig.metadata.namespace })
.then(_.noop, function(result) {
var buildType = isJenkinsPipelineStrategy(buildConfig) ? 'pipeline' : 'build';
row.state.alerts["start-build"] = {
type: "error",
message: "An error occurred while starting the " + buildType + ".",
details: getErrorDetails(result)
};
});
};
// Resuse the function from the overview controller.
row.startBuild = row.state.startBuild;

row.canDeploy = function() {
if (!row.apiObject) {
Expand Down Expand Up @@ -291,10 +281,10 @@

modalInstance.result.then(function() {
if (replicationController.metadata.uid !== row.current.metadata.uid) {
row.state.alerts["cancel-deployment"] = {
NotificationsService.addNotification({
type: "error",
message: "Deployment #" + latestVersion + " is no longer the latest."
};
});
return;
}

Expand All @@ -303,10 +293,10 @@

// Make sure it's still running.
if (!deploymentIsInProgress(replicationController)) {
row.state.alerts["cancel-deployment"] = {
NotificationsService.addNotification({
type: "error",
message: "Deployment " + rcName + " is no longer in progress."
};
});
return;
}

Expand Down
29 changes: 18 additions & 11 deletions app/scripts/directives/overview/serviceInstanceRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
angular.module('openshiftConsole').component('serviceInstanceRow', {
controller: [
'$filter',
'$uibModal',
'DataService',
'ListRowUtils',
'$uibModal',
'NotificationsService',
ServiceInstanceRow
],
controllerAs: 'row',
Expand All @@ -18,9 +19,13 @@
templateUrl: 'views/overview/_service-instance-row.html'
});

function ServiceInstanceRow($filter, DataService, rowMethods, $uibModal) {
function ServiceInstanceRow($filter,
$uibModal,
DataService,
ListRowUtils,
NotificationsService) {
var row = this;
_.extend(row, rowMethods.ui);
_.extend(row, ListRowUtils.ui);

var getErrorDetails = $filter('getErrorDetails');

Expand All @@ -37,7 +42,7 @@
};

row.$doCheck = function() {
row.notifications = rowMethods.getNotifications(row.apiObject, row.state);
row.notifications = ListRowUtils.getNotifications(row.apiObject, row.state);
row.displayName = getDisplayName();
row.description = getDescription();
};
Expand Down Expand Up @@ -83,23 +88,25 @@
}
})
.result.then(function() {
NotificationsService.hideNotification("deprovision-service-error");
DataService.delete({
group: 'servicecatalog.k8s.io',
resource: 'instances'
},
row.apiObject.metadata.name,
{ namespace: row.apiObject.metadata.namespace })
.then(function() {
row.state.alerts["start-build"] = {
NotificationsService.addNotification({
type: "success",
message: "Successfully deprovisioned " + row.apiObject.metadata.name
};
message: "Successfully deprovisioned " + row.apiObject.metadata.name + "."
});
}, function(err) {
row.state.alerts["start-build"] = {
NotificationsService.addNotification({
id: "deprovision-service-error",
type: "error",
message: "An error occurred while deprovisioning " + row.apiObject.metadata.name,
details: "Reason: " + getErrorDetails(err)
};
message: "An error occurred while deprovisioning " + row.apiObject.metadata.name + ".",
details: getErrorDetails(err)
});
});
});
};
Expand Down
Loading