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

Fixed bugs in displaying secrets #36

Merged
merged 1 commit into from
Dec 21, 2018
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
11 changes: 10 additions & 1 deletion app/elements/secret-display.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<div class="horizontal pad justified" style="padding-top:25px">
<iron-pages selected="{{selected}}">
<section>
<secret-structure data="{{data}}" indent="0" hide-values="{{hideValues}}"></secret-structure>
<secret-structure data="{{data}}" force-update="[[forceUpdate]]" indent="0" hide-values="{{hideValues}}"></secret-structure>
</section>
<section>
<div class="vertical">
Expand Down Expand Up @@ -142,8 +142,13 @@
data: {
type: Object,
value: {},
observer: '_forceUpdate',
notify: true
},
forceUpdate: {
type: Boolean,
value: false
},
selected: {
type: Number,
value: 0,
Expand All @@ -164,6 +169,10 @@
value: function() { return this.$.jsonEditorContainer; }
}
},
_forceUpdate: function() {
// Touch forceUpdate to trigger cascading update. This overrides Polymer's dirty checking
this.forceUpdate = !this.forceUpdate;
},
_convertFile: function(e, file){
this.data = {data: file.data, filename: file.name, lastModified: file.lastModified, type: 'file'};
}
Expand Down
70 changes: 60 additions & 10 deletions app/elements/secret-structure.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,38 @@
<paper-input value="{{item.value}}" on-blur="_newValues" label="Value" no-label-float style="width: 200px" type="{{valueType}}"></paper-input>
</paper-item>
<paper-item>
<paper-icon-button style="color: #999; font-size: small;" on-tap="_copy" icon="content-copy"></paper-button>
<paper-icon-button style="color: #999; font-size: small;" on-tap="_copy" icon="content-copy"></paper-icon-button>
</paper-item>
</div>
</template>
<template is="dom-repeat" items="{{nonKeyValues}}">
<div class="horizontal highlight">
<paper-item>
<paper-input value="{{item}}" on-blur="_newValues" label="Value" type="{{valueType}}" no-label-float style="width: 200px;"></paper-input>
</paper-item>
<paper-item>
<paper-icon-button style="color: #999; font-size: small;" on-tap="_copy" icon="content-copy"></paper-icon-button>
</paper-item>
</div>
</template>
<template is="dom-repeat" items="{{objects}}">
<div class="horizontal highlight" style="height: 40px;">
<paper-item>
<paper-input value="{{item.key}}" on-blur="_newValues" label="Name" no-label-float style="width: auto;" disabled={{item.disabled}}></paper-input>
<paper-input value="{{item.key}}" on-blur="_newValues" label="Name" no-label-float style="width: auto;"></paper-input>
</paper-item>
</div>
<div class="horizontal">
<secret-structure data="{{item.value}}" updated="{{childUpdated}}" hide-values="{{hideValues}}"></secret-structure>
<secret-structure data="{{item.value}}" force-update="[[forceUpdate]]" updated="{{childUpdated}}" hide-values="{{hideValues}}"></secret-structure>
</div>
</template>
<template is="dom-repeat" items="{{arrays}}">
<div class="horizontal highlight" style="height: 40px;">
<paper-item>
<paper-input value="{{item.key}}" on-blur="_newValues" label="Number" no-label-float disabled="{{item.disabled}}" style="width: auto;"></paper-input>
</paper-item>
</div>
<div class="horizontal">
<secret-structure data="{{item.value}}" force-update="[[forceUpdate]]" updated="{{childUpdated}}" hide-values="{{hideValues}}"></secret-structure>
</div>
</template>
</div>
Expand All @@ -90,18 +110,30 @@
type: Array,
value: []
},
arrays: {
type: Array,
value: []
},
nonKeyValues: {
type: Array,
value: []
},
hideValues: {
type: Boolean,
observer: '_watchHideValues'
},
childUpdated: {
type: Boolean,
type: Boolean,
observer: '_watchChildUpdated'
},
updated: {
type: Boolean,
notify: true,
value: false
},
forceUpdate: {
type: Boolean,
observer: '_reloadData'
}
},
_watchHideValues: function(){
Expand All @@ -118,24 +150,42 @@
this.$.copied.show();
},
_newValues: function() {
var temp = {};
var temp = (Array.isArray(this.data)) ? [] : {};

for (var i = 0; i < this.nonKeyValues.length; i++) {
if (this.data[i] && typeof(this.data[i]) == "number") {
temp.push(Number(this.nonKeyValues[i]));
} else temp.push(this.nonKeyValues[i]);
}
for (var i = 0; i < this.strings.length; i++) {
temp[this.strings[i].key] = this.strings[i].value;
if (typeof(this.data[this.strings[i].key]) == "number") {
temp[this.strings[i].key] = Number(this.strings[i].value);
} else temp[this.strings[i].key] = this.strings[i].value;
}
for (var j = 0; j < this.objects.length; j++) {
temp[this.objects[j].key] = this.objects[j].value;
}
for (var j = 0; j < this.arrays.length; j++) {
if (Array.isArray(temp)) temp.push(this.arrays[j].value);
else temp[this.arrays[j].key] = this.arrays[j].value;
}
if (JSON.stringify(this.data) != JSON.stringify(temp)) this.data = temp;
this.updated = true;
},
_reloadData: function() {
this.strings = [];
this.objects = [];
this.arrays = [];
this.nonKeyValues = [];
for (var key in this.data) {
if (typeof(this.data[key]) == 'object') {
if (!isNaN(key)) this.push('objects', {key: '#' + (parseInt(key) + 1), disabled: true, value: this.data[key]});
else this.push('objects', {key: key, disabled: false, value: this.data[key]});
} else this.push('strings', {key: key, value: this.data[key]});
if (Array.isArray(this.data)) {
if (typeof(this.data[key]) == 'object') this.push('arrays', {key: key, disabled: true, value: this.data[key]});
else this.push('nonKeyValues', this.data[key]);
}
else if (Array.isArray(this.data[key])) this.push('arrays', {key: key, disabled: false, value: this.data[key]});
else if (typeof(this.data[key]) == 'object') this.push('objects', {key: key, value: this.data[key]});
else if (typeof(this.data[key]) == 'string') this.push('strings', {key: key, value: this.data[key]});
else if (typeof(this.data[key]) == 'number') this.push('strings', {key: key, value: this.data[key]});
}
}
});
Expand Down