Skip to content
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

Let users paste certificate values #1068

Merged
merged 2 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions app/scripts/directives/oscFileInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ angular.module('openshiftConsole')
model: "=",
required: "=",
disabled: "=ngDisabled",
// Show the file contents below the file input.
showValues: "=",
showTextArea: '=',
helpText: "@?",
dropZoneId: "@?"
},
Expand All @@ -24,7 +23,7 @@ angular.module('openshiftConsole')
var dropMessageSelector = "#" + scope.dropMessageID,
highlightDropZone = false,
showDropZone = false,
inputFileField = element.find('input[type=file]')[0];
inputFileField = element.find('input[type=file]');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we could do inputFileField = element.find('input[type=file]')[0]; or inputFileField = _.first(element.find()) here & not have to repeat the [0] a few places below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately I can't because I need the jQuery object in one place :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, true, because of the .change on 73, no worries!


setTimeout(addDropZoneListeners);

Expand Down Expand Up @@ -68,11 +67,11 @@ angular.module('openshiftConsole')
scope.cleanInputValues = function() {
scope.model = '';
scope.fileName = '';
inputFileField.value = "";
inputFileField[0].value = "";
};

element.change(function() {
addFile(inputFileField.files[0]);
inputFileField.change(function() {
addFile(inputFileField[0].files[0]);
});

// Add listeners for the dropZone element
Expand Down
6 changes: 6 additions & 0 deletions app/styles/_forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@
}
}
}

.osc-file-input textarea {
font-family: @font-family-monospace;
// Use the same spacing as `help-block` so the textarea is evenly spaced under the help text.
margin: 5px 0;
}
6 changes: 1 addition & 5 deletions app/views/directives/create-secret.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
model="newSecret.data.cacert"
drop-zone-id="cacert"
help-text="Upload your ca.crt file."
show-values="false"
required="true"></osc-file-input>
<div ui-ace="{
mode: 'txt',
Expand All @@ -134,8 +133,7 @@
id="private-key-file-input"
model="newSecret.data.privateKey"
drop-zone-id="private-key"
help-text="Upload your private SSH key file."
show-values="false"></osc-file-input>
help-text="Upload your private SSH key file."></osc-file-input>
<div ui-ace="{
theme: 'eclipse',
rendererOptions: {
Expand Down Expand Up @@ -166,7 +164,6 @@
model="newSecret.data.gitconfig"
drop-zone-id="gitconfig"
help-text="Upload your .gitconfig or file."
show-values="false"
required="true"></osc-file-input>
<div ui-ace="{
mode: 'ini',
Expand Down Expand Up @@ -271,7 +268,6 @@
model="newSecret.data.dockerConfig"
drop-zone-id="docker-config"
help-text="Upload a .dockercfg or .docker/config.json file"
show-values="false"
required="true"></osc-file-input>
<div ui-ace="{
mode: 'json',
Expand Down
3 changes: 1 addition & 2 deletions app/views/directives/edit-config-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
<osc-file-input
model="item.value"
drop-zone-id="drop-zone-{{$id}}"
help-text="Enter a value for the config map entry or use the contents of a file."
show-values="false"></osc-file-input>
help-text="Enter a value for the config map entry or use the contents of a file."></osc-file-input>
<div ui-ace="{
theme: 'eclipse',
rendererOptions: {
Expand Down
3 changes: 1 addition & 2 deletions app/views/directives/from-file.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
model="editorContent"
drop-zone-id="from-file"
help-text="Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="false"
show-values="false"></osc-file-input>
ng-disabled="false"></osc-file-input>
<div ui-ace="{
mode: 'yaml',
theme: 'eclipse',
Expand Down
70 changes: 36 additions & 34 deletions app/views/directives/osc-file-input.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
<div ng-attr-id="{{dropMessageID}}" class="drag-and-drop-zone">
<p>Drop file here</p>
</div>
<div class="input-group">
<input
type="text"
class="form-control"
ng-model="fileName"
readonly
ng-show="supportsFileUpload"
<div class="osc-file-input">
<div ng-attr-id="{{dropMessageID}}" class="drag-and-drop-zone">
<p>Drop file here</p>
</div>
<div class="input-group">
<input
type="text"
class="form-control"
ng-model="fileName"
readonly
ng-show="supportsFileUpload"
ng-disabled="disabled"
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
<span class="input-group-btn">
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ disabled || undefined }}">
Browse&hellip;
<input type="file" ng-disabled="disabled" class="form-control">
</span>
</span>
</div>
<div ng-if="helpText">
<span ng-attr-id="{{helpID}}" class="help-block">{{::helpText}}</span>
</div>
<div class="has-error" ng-show="uploadError">
<span class="help-block">There was an error reading the file. Please copy the file content into the text area.</span>
</div>
<textarea class="form-control"
rows="5"
ng-show="showTextArea || !supportsFileUpload"
ng-model="model"
ng-required="required"
ng-disabled="disabled"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
<span class="input-group-btn">
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ disabled || undefined }}">
Browse&hellip;
<input type="file" ng-disabled="disabled" class="form-control">
</span>
</span>
</div>
<textarea class="form-control"
rows="8"
ng-hide="supportsFileUpload"
ng-model="model"
ng-required="required"
ng-disabled="disabled"
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
</textarea>
<div ng-if="helpText">
<span ng-attr-id="{{helpID}}" class="help-block">{{::helpText}}</span>
</div>
<div class="has-error" ng-show="uploadError">
<span class="help-block">There was an error reading the file. Please copy the file content into the text area.</span>
</div>
</textarea>

<div ng-if="model && showValues && supportsFileUpload">
<pre ng-if="model && showValues && supportsFileUpload" class="clipped scroll">{{model}}</pre>
<a href="" ng-show="(model || fileName) && !disabled" ng-click="cleanInputValues()">Clear Value</a>
</div>
<a href="" ng-show="model || fileName" class="clear-btn" ng-click="cleanInputValues()">Clear Value</a>
16 changes: 8 additions & 8 deletions app/views/directives/osc-routing.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ <h3>Certificates</h3>
<osc-file-input
model="route.tls.certificate"
drop-zone-id="certificate-file"
show-values="true"
help-text="The PEM format certificate. Upload file by dragging & dropping, or selecting it."
show-text-area="true"
help-text="The PEM format certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipbard."
ng-disabled="disableCertificateInputs()">
</osc-file-input>
</div>
Expand All @@ -272,8 +272,8 @@ <h3>Certificates</h3>
<osc-file-input
model="route.tls.key"
drop-zone-id="private-key-file"
show-values="true"
help-text="The PEM format key. Upload file by dragging & dropping, or selecting it."
show-text-area="true"
help-text="The PEM format key. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="disableCertificateInputs()">
</osc-file-input>
</div>
Expand All @@ -282,18 +282,18 @@ <h3>Certificates</h3>
<osc-file-input
model="route.tls.caCertificate"
drop-zone-id="ca-certificate-file"
show-values="true"
help-text="The PEM format CA certificate. Upload file by dragging & dropping, or selecting it."
show-text-area="true"
help-text="The PEM format CA certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="disableCertificateInputs()">
</osc-file-input>
</div>
<div class="form-group" id="dest-ca-certificate-file">
<label>Destination CA Certificate</label>
<osc-file-input
model="route.tls.destinationCACertificate"
show-values="true"
show-text-area="true"
drop-zone-id="dest-ca-certificate-file"
help-text="The PEM format CA certificate to validate the endpoint certificate for re-encrypt termination. Upload file by dragging & dropping, or selecting it."
help-text="The PEM format CA certificate to validate the endpoint certificate for re-encrypt termination. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="route.tls.termination !== 'reencrypt'">
</osc-file-input>
<!-- Show a warning if the value won't be used, but only if we're
Expand Down
10 changes: 5 additions & 5 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9658,7 +9658,7 @@ scope:{
model:"=",
required:"=",
disabled:"=ngDisabled",
showValues:"=",
showTextArea:"=",
helpText:"@?",
dropZoneId:"@?"
},
Expand Down Expand Up @@ -9715,7 +9715,7 @@ c.find(".drag-and-drop-zone").removeClass("show-drag-and-drop-zone highlight-dra
}
var g = _.uniqueId("osc-file-input-");
b.dropMessageID = g + "-drop-message", b.helpID = g + "-help", b.supportsFileUpload = window.File && window.FileReader && window.FileList && window.Blob, b.uploadError = !1;
var h = "#" + b.dropMessageID, i = !1, j = !1, k = c.find("input[type=file]")[0];
var h = "#" + b.dropMessageID, i = !1, j = !1, k = c.find("input[type=file]");
setTimeout(d), $(document).on("drop." + g, function() {
return f(), c.find(".drag-and-drop-zone").trigger("putDropZoneFront", !1), !1;
}), $(document).on("dragenter." + g, function() {
Expand All @@ -9727,9 +9727,9 @@ return j = !1, _.delay(function() {
j || c.find(".drag-and-drop-zone").removeClass("show-drag-and-drop-zone");
}, 200), !1;
}), b.cleanInputValues = function() {
b.model = "", b.fileName = "", k.value = "";
}, c.change(function() {
e(k.files[0]);
b.model = "", b.fileName = "", k[0].value = "";
}, k.change(function() {
e(k[0].files[0]);
}), b.$on("$destroy", function() {
$(h).off(), $(document).off("drop." + g).off("dragenter." + g).off("dragover." + g).off("dragleave." + g);
});
Expand Down
31 changes: 15 additions & 16 deletions dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5905,7 +5905,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</div>\n" +
"<div class=\"form-group\" ng-if=\"add.cacert\" id=\"cacert\">\n" +
"<label class=\"required\" for=\"cacert\">CA Certificate File</label>\n" +
"<osc-file-input id=\"cacert-file-input\" model=\"newSecret.data.cacert\" drop-zone-id=\"cacert\" help-text=\"Upload your ca.crt file.\" show-values=\"false\" required=\"true\"></osc-file-input>\n" +
"<osc-file-input id=\"cacert-file-input\" model=\"newSecret.data.cacert\" drop-zone-id=\"cacert\" help-text=\"Upload your ca.crt file.\" required=\"true\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" mode: 'txt',\n" +
" theme: 'eclipse',\n" +
Expand All @@ -5919,7 +5919,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div ng-if=\"newSecret.authType === 'kubernetes.io/ssh-auth'\">\n" +
"<div class=\"form-group\" id=\"private-key\">\n" +
"<label for=\"privateKey\" class=\"required\">SSH Private Key</label>\n" +
"<osc-file-input id=\"private-key-file-input\" model=\"newSecret.data.privateKey\" drop-zone-id=\"private-key\" help-text=\"Upload your private SSH key file.\" show-values=\"false\"></osc-file-input>\n" +
"<osc-file-input id=\"private-key-file-input\" model=\"newSecret.data.privateKey\" drop-zone-id=\"private-key\" help-text=\"Upload your private SSH key file.\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" theme: 'eclipse',\n" +
" rendererOptions: {\n" +
Expand All @@ -5943,7 +5943,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</div>\n" +
"<div class=\"form-group\" ng-if=\"add.gitconfig\" id=\"gitconfig\">\n" +
"<label class=\"required\" for=\"gitconfig\">Git Configuration File</label>\n" +
"<osc-file-input id=\"gitconfig-file-input\" model=\"newSecret.data.gitconfig\" drop-zone-id=\"gitconfig\" help-text=\"Upload your .gitconfig or file.\" show-values=\"false\" required=\"true\"></osc-file-input>\n" +
"<osc-file-input id=\"gitconfig-file-input\" model=\"newSecret.data.gitconfig\" drop-zone-id=\"gitconfig\" help-text=\"Upload your .gitconfig or file.\" required=\"true\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" mode: 'ini',\n" +
" theme: 'eclipse',\n" +
Expand Down Expand Up @@ -6006,7 +6006,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div ng-if=\"newSecret.authType === 'kubernetes.io/dockerconfigjson'\">\n" +
"<div class=\"form-group\" id=\"docker-config\">\n" +
"<label for=\"dockerConfig\" class=\"required\">Configuration File</label>\n" +
"<osc-file-input id=\"dockercfg-file-input\" model=\"newSecret.data.dockerConfig\" drop-zone-id=\"docker-config\" help-text=\"Upload a .dockercfg or .docker/config.json file\" show-values=\"false\" required=\"true\"></osc-file-input>\n" +
"<osc-file-input id=\"dockercfg-file-input\" model=\"newSecret.data.dockerConfig\" drop-zone-id=\"docker-config\" help-text=\"Upload a .dockercfg or .docker/config.json file\" required=\"true\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" mode: 'json',\n" +
" theme: 'eclipse',\n" +
Expand Down Expand Up @@ -6398,7 +6398,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</div>\n" +
"<div class=\"form-group\" ng-attr-id=\"drop-zone-{{$id}}\">\n" +
"<label ng-attr-for=\"name-{{$id}}\">Value</label>\n" +
"<osc-file-input model=\"item.value\" drop-zone-id=\"drop-zone-{{$id}}\" help-text=\"Enter a value for the config map entry or use the contents of a file.\" show-values=\"false\"></osc-file-input>\n" +
"<osc-file-input model=\"item.value\" drop-zone-id=\"drop-zone-{{$id}}\" help-text=\"Enter a value for the config map entry or use the contents of a file.\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" theme: 'eclipse',\n" +
" rendererOptions: {\n" +
Expand Down Expand Up @@ -6790,7 +6790,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div class=\"col-sm-12 pod-bottom-xl\">\n" +
"<form name=\"form\">\n" +
"<div class=\"form-group\" id=\"from-file\">\n" +
"<osc-file-input model=\"editorContent\" drop-zone-id=\"from-file\" help-text=\"Upload file by dragging & dropping, selecting it, or pasting from the clipboard.\" ng-disabled=\"false\" show-values=\"false\"></osc-file-input>\n" +
"<osc-file-input model=\"editorContent\" drop-zone-id=\"from-file\" help-text=\"Upload file by dragging & dropping, selecting it, or pasting from the clipboard.\" ng-disabled=\"false\"></osc-file-input>\n" +
"<div ui-ace=\"{\n" +
" mode: 'yaml',\n" +
" theme: 'eclipse',\n" +
Expand Down Expand Up @@ -7308,6 +7308,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(


$templateCache.put('views/directives/osc-file-input.html',
"<div class=\"osc-file-input\">\n" +
"<div ng-attr-id=\"{{dropMessageID}}\" class=\"drag-and-drop-zone\">\n" +
"<p>Drop file here</p>\n" +
"</div>\n" +
Expand All @@ -7320,18 +7321,16 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"</span>\n" +
"</span>\n" +
"</div>\n" +
"<textarea class=\"form-control\" rows=\"8\" ng-hide=\"supportsFileUpload\" ng-model=\"model\" ng-required=\"required\" ng-disabled=\"disabled\" ng-attr-aria-describedby=\"{{helpText ? helpID : undefined}}\">\n" +
"</textarea>\n" +
"<div ng-if=\"helpText\">\n" +
"<span ng-attr-id=\"{{helpID}}\" class=\"help-block\">{{::helpText}}</span>\n" +
"</div>\n" +
"<div class=\"has-error\" ng-show=\"uploadError\">\n" +
"<span class=\"help-block\">There was an error reading the file. Please copy the file content into the text area.</span>\n" +
"</div>\n" +
"<div ng-if=\"model && showValues && supportsFileUpload\">\n" +
"<pre ng-if=\"model && showValues && supportsFileUpload\" class=\"clipped scroll\">{{model}}</pre>\n" +
"</div>\n" +
"<a href=\"\" ng-show=\"model || fileName\" class=\"clear-btn\" ng-click=\"cleanInputValues()\">Clear Value</a>"
"<textarea class=\"form-control\" rows=\"5\" ng-show=\"showTextArea || !supportsFileUpload\" ng-model=\"model\" ng-required=\"required\" ng-disabled=\"disabled\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" ng-attr-aria-describedby=\"{{helpText ? helpID : undefined}}\">\n" +
" </textarea>\n" +
"<a href=\"\" ng-show=\"(model || fileName) && !disabled\" ng-click=\"cleanInputValues()\">Clear Value</a>\n" +
"</div>"
);


Expand Down Expand Up @@ -7855,22 +7854,22 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
"<div>\n" +
"<div class=\"form-group\" id=\"certificate-file\">\n" +
"<label>Certificate</label>\n" +
"<osc-file-input model=\"route.tls.certificate\" drop-zone-id=\"certificate-file\" show-values=\"true\" help-text=\"The PEM format certificate. Upload file by dragging & dropping, or selecting it.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"<osc-file-input model=\"route.tls.certificate\" drop-zone-id=\"certificate-file\" show-text-area=\"true\" help-text=\"The PEM format certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipbard.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"</osc-file-input>\n" +
"</div>\n" +
"<div class=\"form-group\" id=\"private-key-file\">\n" +
"<label>Private Key</label>\n" +
"<osc-file-input model=\"route.tls.key\" drop-zone-id=\"private-key-file\" show-values=\"true\" help-text=\"The PEM format key. Upload file by dragging & dropping, or selecting it.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"<osc-file-input model=\"route.tls.key\" drop-zone-id=\"private-key-file\" show-text-area=\"true\" help-text=\"The PEM format key. Upload file by dragging & dropping, selecting it, or pasting from the clipboard.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"</osc-file-input>\n" +
"</div>\n" +
"<div class=\"form-group\" id=\"ca-certificate-file\">\n" +
"<label>CA Certificate</label>\n" +
"<osc-file-input model=\"route.tls.caCertificate\" drop-zone-id=\"ca-certificate-file\" show-values=\"true\" help-text=\"The PEM format CA certificate. Upload file by dragging & dropping, or selecting it.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"<osc-file-input model=\"route.tls.caCertificate\" drop-zone-id=\"ca-certificate-file\" show-text-area=\"true\" help-text=\"The PEM format CA certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipboard.\" ng-disabled=\"disableCertificateInputs()\">\n" +
"</osc-file-input>\n" +
"</div>\n" +
"<div class=\"form-group\" id=\"dest-ca-certificate-file\">\n" +
"<label>Destination CA Certificate</label>\n" +
"<osc-file-input model=\"route.tls.destinationCACertificate\" show-values=\"true\" drop-zone-id=\"dest-ca-certificate-file\" help-text=\"The PEM format CA certificate to validate the endpoint certificate for re-encrypt termination. Upload file by dragging & dropping, or selecting it.\" ng-disabled=\"route.tls.termination !== 'reencrypt'\">\n" +
"<osc-file-input model=\"route.tls.destinationCACertificate\" show-text-area=\"true\" drop-zone-id=\"dest-ca-certificate-file\" help-text=\"The PEM format CA certificate to validate the endpoint certificate for re-encrypt termination. Upload file by dragging & dropping, selecting it, or pasting from the clipboard.\" ng-disabled=\"route.tls.termination !== 'reencrypt'\">\n" +
"</osc-file-input>\n" +
"\n" +
"<div ng-if=\"route.tls.destinationCACertificate && route.tls.termination !== 'reencrypt' && !showCertificatesNotUsedWarning\" class=\"has-warning\">\n" +
Expand Down
Loading