Skip to content

Commit 0b99a35

Browse files
committed
Add ability to copy commands in cli tools page
1 parent 3d8c136 commit 0b99a35

File tree

7 files changed

+45
-31
lines changed

7 files changed

+45
-31
lines changed

app/scripts/directives/util.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ angular.module('openshiftConsole')
7676
restrict: 'E',
7777
scope: {
7878
clipboardText: "=",
79-
isDisabled: "=?"
79+
isDisabled: "=?",
80+
displayWide: "=?",
81+
inputText: "=?"
8082
},
8183
templateUrl: 'views/directives/_copy-to-clipboard.html',
8284
controller: function($scope) {
@@ -88,8 +90,13 @@ angular.module('openshiftConsole')
8890
return;
8991
}
9092

91-
var node = $('a', element);
92-
var clipboard = new Clipboard( node.get(0) );
93+
var nodeElem = $('a', element);
94+
var node = nodeElem.get(0);
95+
if ($scope.inputText) {
96+
node = nodeElem.get(1);
97+
}
98+
99+
var clipboard = new Clipboard( node );
93100
clipboard.on('success', function (e) {
94101
$(e.trigger)
95102
.attr('title', 'Copied!')

app/styles/_core.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ h1 small.meta, .build-config-summary .meta {
12051205
}
12061206

12071207
// don't allow copy-to-clipboard .input-groups get bigger than 600px so Github webhook secrets aren't revealed within the input-group
1208-
copy-to-clipboard .input-group {
1208+
copy-to-clipboard .input-group.limit-width {
12091209
max-width: 300px;
12101210
}
12111211

app/views/command-line.html

+5-7
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,28 @@ <h1 id="cli">Command Line Tools</h1>
3737
</p>
3838
<p>
3939
After downloading and installing it, you can start by logging in using<span ng-if="sessionToken"> this current session token</span>:
40-
<div class="code prettyprint ng-binding" ng-if="sessionToken">
41-
oc login {{loginBaseURL}} --token=<span ng-show="showSessionToken">{{sessionToken}}</span><a href="#" ng-click="toggleShowSessionToken()" ng-show="!showSessionToken">...click to show token...</a>
42-
</div>
40+
<copy-to-clipboard display-wide="true" clipboard-text="'oc login ' + loginBaseURL + ' --token=' + sessionToken" input-text="'oc login ' + loginBaseURL + ' --token=<hidden>'"></copy-to-clipboard>
4341
<pre class="code prettyprint ng-binding" ng-if="!sessionToken">
4442
oc login {{loginBaseURL}}
4543
</pre>
4644
</p>
4745

48-
<div ng-show="showSessionToken" class="alert alert-warning">
46+
<div class="alert alert-warning">
4947
<span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span>
5048
<strong>A token is a form of a password.</strong>
5149
Do not share your API token.
5250
</div>
5351

5452
<p>After you login to your account you will get a list of projects that you can switch between:
55-
<pre class="code prettyprint">oc project <i>project-name</i></pre>
53+
<copy-to-clipboard display-wide="true" clipboard-text="'oc project <project-name>'"></copy-to-clipboard>
5654
</p>
5755

5856
<p>If you do not have any existing projects, you can create one:
59-
<pre class="code prettyprint">oc new-project <i>project-name</i></pre>
57+
<copy-to-clipboard display-wide="true" clipboard-text="'oc new-project <project-name>'"></copy-to-clipboard>
6058
</p>
6159

6260
<p>To show a high level overview of the current project:
63-
<pre class="code prettyprint">oc status</pre>
61+
<copy-to-clipboard display-wide="true" clipboard-text="'oc status'"></copy-to-clipboard>
6462
</p>
6563

6664
<p>For other information about the command line tools, check the <a target="_blank" href="{{'cli' | helpLink}}">CLI Reference</a> and <a target="_blank" href="{{'basic_cli_operations' | helpLink}}">Basic CLI Operations</a>.</p>
+10-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
<div class="input-group copy-to-clipboard">
2-
<input id="{{id}}" type="text" class="form-control" value="{{clipboardText}}" ng-disabled="isDisabled" ng-readonly="!isDisabled" select-on-focus>
1+
<div class="input-group copy-to-clipboard" ng-class="{'limit-width': !displayWide}">
2+
<input id="{{id}}" type="text" class="form-control" value="{{inputText ? inputText : clipboardText}}" ng-disabled="isDisabled" ng-readonly="!isDisabled" select-on-focus>
33
<span class="input-group-btn" ng-hide="hidden">
4-
<a data-clipboard-target="#{{id}}"
4+
<a ng-show="!inputText" data-clipboard-target="#{{id}}"
5+
ng-disabled="isDisabled"
6+
data-toggle="tooltip"
7+
title="Copy to clipboard"
8+
role="button"
9+
class="btn btn-default"><i class="fa fa-clipboard"/></a>
10+
<a ng-show="inputText" data-clipboard-text="{{clipboardText}}"
511
ng-disabled="isDisabled"
612
data-toggle="tooltip"
713
title="Copy to clipboard"
814
role="button"
915
class="btn btn-default"><i class="fa fa-clipboard"/></a>
1016
</span>
11-
</div><!-- /input-group -->
17+
</div><!-- /input-group -->

dist/scripts/scripts.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -9756,22 +9756,26 @@ return {
97569756
restrict:"E",
97579757
scope:{
97589758
clipboardText:"=",
9759-
isDisabled:"=?"
9759+
isDisabled:"=?",
9760+
displayWide:"=?",
9761+
inputText:"=?"
97609762
},
97619763
templateUrl:"views/directives/_copy-to-clipboard.html",
97629764
controller:[ "$scope", function(a) {
97639765
a.id = _.uniqueId("clipboardJs");
97649766
} ],
97659767
link:function(b, c) {
97669768
if (a) return void (b.hidden = !0);
9767-
var d = $("a", c), e = new Clipboard(d.get(0));
9768-
e.on("success", function(a) {
9769+
var d = $("a", c), e = d.get(0);
9770+
b.inputText && (e = d.get(1));
9771+
var f = new Clipboard(e);
9772+
f.on("success", function(a) {
97699773
$(a.trigger).attr("title", "Copied!").tooltip("fixTitle").tooltip("show").attr("title", "Copy to clipboard").tooltip("fixTitle"), a.clearSelection();
9770-
}), e.on("error", function(a) {
9774+
}), f.on("error", function(a) {
97719775
var b = /Mac/i.test(navigator.userAgent) ? "Press ⌘C to copy" :"Press Ctrl-C to copy";
97729776
$(a.trigger).attr("title", b).tooltip("fixTitle").tooltip("show").attr("title", "Copy to clipboard").tooltip("fixTitle");
97739777
}), c.on("$destroy", function() {
9774-
e.destroy();
9778+
f.destroy();
97759779
});
97769780
}
97779781
};

dist/scripts/templates.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -3871,26 +3871,24 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
38713871
"</p>\n" +
38723872
"<p>\n" +
38733873
"After downloading and installing it, you can start by logging in using<span ng-if=\"sessionToken\"> this current session token</span>:\n" +
3874-
"<div class=\"code prettyprint ng-binding\" ng-if=\"sessionToken\">\n" +
3875-
"oc login {{loginBaseURL}} --token=<span ng-show=\"showSessionToken\">{{sessionToken}}</span><a href=\"#\" ng-click=\"toggleShowSessionToken()\" ng-show=\"!showSessionToken\">...click to show token...</a>\n" +
3876-
"</div>\n" +
3874+
"<copy-to-clipboard display-wide=\"true\" clipboard-text=\"'oc login ' + loginBaseURL + ' --token=' + sessionToken\" input-text=\"'oc login ' + loginBaseURL + ' --token=<hidden>'\"></copy-to-clipboard>\n" +
38773875
"<pre class=\"code prettyprint ng-binding\" ng-if=\"!sessionToken\">\n" +
38783876
" oc login {{loginBaseURL}}\n" +
38793877
" </pre>\n" +
38803878
"</p>\n" +
3881-
"<div ng-show=\"showSessionToken\" class=\"alert alert-warning\">\n" +
3879+
"<div class=\"alert alert-warning\">\n" +
38823880
"<span class=\"pficon pficon-warning-triangle-o\" aria-hidden=\"true\"></span>\n" +
38833881
"<strong>A token is a form of a password.</strong>\n" +
38843882
"Do not share your API token.\n" +
38853883
"</div>\n" +
38863884
"<p>After you login to your account you will get a list of projects that you can switch between:\n" +
3887-
"<pre class=\"code prettyprint\">oc project <i>project-name</i></pre>\n" +
3885+
"<copy-to-clipboard display-wide=\"true\" clipboard-text=\"'oc project <project-name>'\"></copy-to-clipboard>\n" +
38883886
"</p>\n" +
38893887
"<p>If you do not have any existing projects, you can create one:\n" +
3890-
"<pre class=\"code prettyprint\">oc new-project <i>project-name</i></pre>\n" +
3888+
"<copy-to-clipboard display-wide=\"true\" clipboard-text=\"'oc new-project <project-name>'\"></copy-to-clipboard>\n" +
38913889
"</p>\n" +
38923890
"<p>To show a high level overview of the current project:\n" +
3893-
"<pre class=\"code prettyprint\">oc status</pre>\n" +
3891+
"<copy-to-clipboard display-wide=\"true\" clipboard-text=\"'oc status'\"></copy-to-clipboard>\n" +
38943892
"</p>\n" +
38953893
"<p>For other information about the command line tools, check the <a target=\"_blank\" href=\"{{'cli' | helpLink}}\">CLI Reference</a> and <a target=\"_blank\" href=\"{{'basic_cli_operations' | helpLink}}\">Basic CLI Operations</a>.</p>\n" +
38963894
"</div>\n" +
@@ -4839,10 +4837,11 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
48394837

48404838

48414839
$templateCache.put('views/directives/_copy-to-clipboard.html',
4842-
"<div class=\"input-group copy-to-clipboard\">\n" +
4843-
"<input id=\"{{id}}\" type=\"text\" class=\"form-control\" value=\"{{clipboardText}}\" ng-disabled=\"isDisabled\" ng-readonly=\"!isDisabled\" select-on-focus>\n" +
4840+
"<div class=\"input-group copy-to-clipboard\" ng-class=\"{'limit-width': !displayWide}\">\n" +
4841+
"<input id=\"{{id}}\" type=\"text\" class=\"form-control\" value=\"{{inputText ? inputText : clipboardText}}\" ng-disabled=\"isDisabled\" ng-readonly=\"!isDisabled\" select-on-focus>\n" +
48444842
"<span class=\"input-group-btn\" ng-hide=\"hidden\">\n" +
4845-
"<a data-clipboard-target=\"#{{id}}\" ng-disabled=\"isDisabled\" data-toggle=\"tooltip\" title=\"Copy to clipboard\" role=\"button\" class=\"btn btn-default\"><i class=\"fa fa-clipboard\"/></a>\n" +
4843+
"<a ng-show=\"!inputText\" data-clipboard-target=\"#{{id}}\" ng-disabled=\"isDisabled\" data-toggle=\"tooltip\" title=\"Copy to clipboard\" role=\"button\" class=\"btn btn-default\"><i class=\"fa fa-clipboard\"/></a>\n" +
4844+
"<a ng-show=\"inputText\" data-clipboard-text=\"{{clipboardText}}\" ng-disabled=\"isDisabled\" data-toggle=\"tooltip\" title=\"Copy to clipboard\" role=\"button\" class=\"btn btn-default\"><i class=\"fa fa-clipboard\"/></a>\n" +
48464845
"</span>\n" +
48474846
"</div>"
48484847
);

dist/styles/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -3995,7 +3995,7 @@ labels+.resource-details{margin-top:10px}
39953995
.environment-variables.table.table-bordered>tbody>tr>td:last-child .env-var-value a{font-family:"Open Sans",Helvetica,Arial,sans-serif}
39963996
.pretty-json{font-family:Menlo,Monaco,Consolas,monospace;white-space:pre-wrap}
39973997
.info-popover,.warnings-popover{cursor:help;vertical-align:middle;margin-left:2px}
3998-
copy-to-clipboard .input-group{max-width:300px}
3998+
copy-to-clipboard .input-group.limit-width{max-width:300px}
39993999
.strong{font-weight:700}
40004000
.tech-preview-header{justify-content:space-between}
40014001
@media (max-width:479px){.col-xxs-12{width:100%}

0 commit comments

Comments
 (0)