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 26, 2017
1 parent 441f98f commit 23d188b
Show file tree
Hide file tree
Showing 3 changed files with 66 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
34 changes: 32 additions & 2 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10140,7 +10140,34 @@ r.destroy();
});
}
};
}).directive("shortId", function() {
}).directive("copyLoginToClipboard", [ "NotificationsService", function(e) {
return {
restrict: "E",
replace: !0,
scope: {
clipboardText: "="
},
template: '<a href="" data-clipboard-text="">Copy Login Command</a>',
link: function(t, n) {
var a = new Clipboard(n.get(0));
a.on("success", function() {
e.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."
});
}), a.on("error", function() {
e.addNotification({
id: "copied_to_clipboard_toast_error",
type: "error",
message: "Unable to copy."
});
}), n.on("$destroy", function() {
a.destroy();
});
}
};
} ]).directive("shortId", function() {
return {
restrict: "E",
scope: {
Expand Down Expand Up @@ -14812,11 +14839,14 @@ type: "dom",
node: '<li><a href="about">About</a></li>'
}), e;
});
} ]), angular.module("openshiftConsole").run([ "extensionRegistry", "$rootScope", function(e, t) {
} ]), angular.module("openshiftConsole").run([ "extensionRegistry", "$rootScope", "DataService", "AuthService", function(e, t, n, a) {
e.add("nav-user-dropdown", function() {
var e = "Log out";
return t.user.fullName && t.user.fullName !== t.user.metadata.name && (e += " (" + t.user.metadata.name + ")"), [ {
type: "dom",
node: "<li><copy-login-to-clipboard clipboard-text=\"'oc login " + n.openshiftAPIBaseUrl() + " --token=" + a.UserStore().getToken() + "'\"></copy-login-to-clipboard></li>"
}, {
type: "dom",
node: '<li><a href="logout">' + _.escape(e) + "</a></li>"
} ];
});
Expand Down

0 comments on commit 23d188b

Please sign in to comment.