Skip to content

Commit

Permalink
Add quick command to help dropdown
Browse files Browse the repository at this point in the history
Signed-off-by: Will Gordon <wgordon@redhat.com>
  • Loading branch information
wgordon17 committed Jul 18, 2017
1 parent adf6034 commit 6f60a06
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
30 changes: 30 additions & 0 deletions app/scripts/directives/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ angular.module('openshiftConsole')
}
};
})
.directive('copyLoginToClipboard', function(NotificationsService) {
return {
restrict: 'E',
replace: true,
scope: {
clipboardText: "="
},
template: '<a href="" data-clipboard-text="">Copy Login Command</a>',
link: function($scope, element) {
var clipboard = new Clipboard( element.get(0) );
clipboard.on('success', function () {
NotificationsService.addNotification({
id: 'copied_to_clipboard_toast_success',
type: 'warning',
message: 'Do not share the API token in your clipboard. A token is a form of a password.'
});
});
clipboard.on('error', function () {
NotificationsService.addNotification({
id: 'copied_to_clipboard_toast_error',
type: 'error',
message: 'Unable to copy.'
});
});
element.on('$destroy', function() {
clipboard.destroy();
});
}
};
})
.directive('shortId', function() {
return {
restrict:'E',
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/extensions/nav/userDropdown.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict';

angular.module('openshiftConsole')
.run(function(extensionRegistry, $rootScope) {
.run(function(extensionRegistry, $rootScope, DataService, AuthService) {
extensionRegistry
.add('nav-user-dropdown', function() {
var msg = 'Log out';
if ($rootScope.user.fullName && $rootScope.user.fullName !== $rootScope.user.metadata.name) {
msg += ' (' + $rootScope.user.metadata.name + ')';
}
return [{
type: 'dom',
node: '<li><copy-login-to-clipboard clipboard-text="\'oc login ' + DataService.openshiftAPIBaseUrl() + ' --token=' + AuthService.UserStore().getToken() + '\'"></copy-login-to-clipboard></li>'
},{
type: 'dom',
node: '<li><a href="logout">' + _.escape(msg) + '</a></li>'
}];
Expand Down
3 changes: 3 additions & 0 deletions app/styles/_navbar-alt.less
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
margin-top: -10px;
right: 0;
}
.copy-to-clipboard {
padding: 1px 8px;
}
&:after {
border: 6px solid transparent;
border-bottom-color: #fff;
Expand Down
34 changes: 32 additions & 2 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10370,7 +10370,34 @@ e.destroy();
});
}
};
}).directive("shortId", function() {
}).directive("copyLoginToClipboard", [ "NotificationsService", function(a) {
return {
restrict:"E",
replace:!0,
scope:{
clipboardText:"="
},
template:'<a href="" data-clipboard-text="">Copy Login Command</a>',
link:function(b, c) {
var d = new Clipboard(c.get(0));
d.on("success", function() {
a.addNotification({
id:"copied_to_clipboard_toast_success",
type:"warning",
message:"Do not share the API token in your clipboard. A token is a form of a password."
});
}), d.on("error", function() {
a.addNotification({
id:"copied_to_clipboard_toast_error",
type:"error",
message:"Unable to copy."
});
}), c.on("$destroy", function() {
d.destroy();
});
}
};
} ]).directive("shortId", function() {
return {
restrict:"E",
scope:{
Expand Down Expand Up @@ -14999,11 +15026,14 @@ type:"dom",
node:'<li><a href="about">About</a></li>'
}), a;
});
} ]), angular.module("openshiftConsole").run([ "extensionRegistry", "$rootScope", function(a, b) {
} ]), angular.module("openshiftConsole").run([ "extensionRegistry", "$rootScope", "DataService", "AuthService", function(a, b, c, d) {
a.add("nav-user-dropdown", function() {
var a = "Log out";
return b.user.fullName && b.user.fullName !== b.user.metadata.name && (a += " (" + b.user.metadata.name + ")"), [ {
type:"dom",
node:"<li><copy-login-to-clipboard clipboard-text=\"'oc login " + c.openshiftAPIBaseUrl() + " --token=" + d.UserStore().getToken() + "'\"></copy-login-to-clipboard></li>"
}, {
type:"dom",
node:'<li><a href="logout">' + _.escape(a) + "</a></li>"
} ];
});
Expand Down
1 change: 1 addition & 0 deletions dist/styles/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f60a06

Please sign in to comment.