Merge "Update gr-rule-editor"
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
editing: {
|
editing: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
|
observer: '_handleEditingChanged',
|
||||||
},
|
},
|
||||||
groupId: String,
|
groupId: String,
|
||||||
groupName: String,
|
groupName: String,
|
||||||
@@ -87,6 +88,10 @@
|
|||||||
'_handleValueChange(rule.value.*)',
|
'_handleValueChange(rule.value.*)',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
listeners: {
|
||||||
|
'access-saved': '_handleAccessSaved',
|
||||||
|
},
|
||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
// Called on ready rather than the observer because when new rules are
|
// Called on ready rather than the observer because when new rules are
|
||||||
// added, the observer is triggered prior to being ready.
|
// added, the observer is triggered prior to being ready.
|
||||||
@@ -114,6 +119,21 @@
|
|||||||
return `${this.getBaseUrl()}/admin/groups/${this.encodeURL(group, true)}`;
|
return `${this.getBaseUrl()}/admin/groups/${this.encodeURL(group, true)}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_handleAccessSaved() {
|
||||||
|
// Set a new 'original' value to keep track of after the value has been
|
||||||
|
// saved.
|
||||||
|
this._setOriginalRuleValues(this.rule.value);
|
||||||
|
},
|
||||||
|
|
||||||
|
_handleEditingChanged(editing, editingOld) {
|
||||||
|
// Ignore when editing gets set initially.
|
||||||
|
if (!editingOld) { return; }
|
||||||
|
// Restore original values if no longer editing.
|
||||||
|
if (!editing) {
|
||||||
|
this._handleUndoChange();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_computeSectionClass(editing, deleted) {
|
_computeSectionClass(editing, deleted) {
|
||||||
const classList = [];
|
const classList = [];
|
||||||
if (editing) {
|
if (editing) {
|
||||||
@@ -179,6 +199,8 @@
|
|||||||
_handleValueChange() {
|
_handleValueChange() {
|
||||||
if (!this._originalRuleValues) { return; }
|
if (!this._originalRuleValues) { return; }
|
||||||
this._modified = true;
|
this._modified = true;
|
||||||
|
// Allows overall access page to know a change has been made.
|
||||||
|
this.dispatchEvent(new CustomEvent('access-modified', {bubbles: true}));
|
||||||
},
|
},
|
||||||
|
|
||||||
_setOriginalRuleValues(value) {
|
_setOriginalRuleValues(value) {
|
||||||
|
@@ -152,11 +152,23 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('_handleValueChange', () => {
|
test('_handleValueChange', () => {
|
||||||
|
const modifiedHandler = sandbox.stub();
|
||||||
|
element.addEventListener('access-modified', modifiedHandler);
|
||||||
element._handleValueChange();
|
element._handleValueChange();
|
||||||
assert.isFalse(element._modified);
|
assert.isFalse(element._modified);
|
||||||
element._originalRuleValues = {};
|
element._originalRuleValues = {};
|
||||||
element._handleValueChange();
|
element._handleValueChange();
|
||||||
assert.isTrue(element._modified);
|
assert.isTrue(element._modified);
|
||||||
|
assert.isTrue(modifiedHandler.called);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('_handleAccessSaved', () => {
|
||||||
|
const originalValue = {action: 'DENY'};
|
||||||
|
const newValue = {action: 'ALLOW'};
|
||||||
|
element._originalRuleValues = originalValue;
|
||||||
|
element.rule = {value: newValue};
|
||||||
|
element._handleAccessSaved();
|
||||||
|
assert.deepEqual(element._originalRuleValues, newValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_setOriginalRuleValues', () => {
|
test('_setOriginalRuleValues', () => {
|
||||||
@@ -199,6 +211,17 @@ limitations under the License.
|
|||||||
assert.isFalse(element.$.force.classList.contains('force'));
|
assert.isFalse(element.$.force.classList.contains('force'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('modify and cancel restores original values', () => {
|
||||||
|
element.editing = true;
|
||||||
|
assert.isFalse(element._modified);
|
||||||
|
element.$.action.bindValue = 'DENY';
|
||||||
|
assert.isTrue(element._modified);
|
||||||
|
element.editing = false;
|
||||||
|
assert.deepEqual(element._originalRuleValues, element.rule.value);
|
||||||
|
assert.equal(element.$.action.bindValue, 'ALLOW');
|
||||||
|
assert.isFalse(element._modified);
|
||||||
|
});
|
||||||
|
|
||||||
test('modify and undo value', () => {
|
test('modify and undo value', () => {
|
||||||
assert.isFalse(element._modified);
|
assert.isFalse(element._modified);
|
||||||
assert.isFalse(element.$.undoBtn.classList.contains('modified'));
|
assert.isFalse(element.$.undoBtn.classList.contains('modified'));
|
||||||
|
Reference in New Issue
Block a user