Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Conversation

@simo9000
Copy link
Contributor

I resisted the urge to do this but I didn't see a way around it. #2284 provided a clear means of decided when level of options was in control of the editable behavior of items. However it fell short in that when individual items are determined to be editable (and overrideItems is false), it enabled all three edit behaviors. This enables further control over individual item behavior but allowing updateTime, updateGroup, and remove to be toggled at the item level. I am glad I chose to pursue this as I found a bug which was introduced in #2284 where timeline.editable == true would also set overrideItems to true.

Copy link
Member

@yotamberk yotamberk left a comment

Choose a reason for hiding this comment

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

The idea of this PR is good, but there are some logic problems... This will cause some breaking changes.
Please review the different scenarios to make sure the behavior is as expected

// override options.editable
if ((item.editable === false || !item.editable)
&& !this.options.editable.overrideItems) {
if (!item.editable.updateTime && !item.editable.updateGroup
Copy link
Member

Choose a reason for hiding this comment

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

What about remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This predicate is in the ItemSet._onDragStart, my understanding is that remove is only concerned with Item._repaintDeleteButton. Shouldn't this predicate not be affected by the value of remove?

Copy link
Member

Choose a reason for hiding this comment

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

oops you're right. I didn't notice the function it was in. Ignore this comment


var updateTimeAllowed = me.options.editable.updateTime || (
props.item.editable === true && !me.options.editable.overrideItems);
var updateTimeAllowed = (me.options.editable.overrideItems && me.options.editable.updateTime) || (
Copy link
Member

Choose a reason for hiding this comment

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

This overrides the previous default... what happens when:
me.options.editable.overrideItems==false and me.options.editable.updateTime==true?
updating time in this case should be allowed even if props.item.editable.updateTime is not defined (or false, as set in default)

var updateGroupAllowed = me.options.editable.updateGroup ||
props.item.editable === true;
var updateGroupAllowed = (me.options.editable.overrideItems && me.options.editable.updateGroup) ||
props.item.editable.updateGroup;
Copy link
Member

Choose a reason for hiding this comment

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

What about: !me.options.editable.overrideItems && me.options.editable.updateGroup? You should be able to update groups but in this logic, you can't...

this.options.editable.overrideItems)
|| (this.data.editable === true &&
|| (this.editable.remove &&
!this.options.editable.overrideItems);
Copy link
Member

Choose a reason for hiding this comment

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

What about: this.data.editable.remove && !this.options.editable.overrideItems?

@simo9000 simo9000 force-pushed the itemEditableOptions branch from 7f0b987 to 13a8695 Compare November 13, 2016 23:34
@simo9000
Copy link
Contributor Author

@yotamberk Prior to this PR, there was no default for item.editable, the behavior was actually to enable editing if item.editable is not set as configured by the timeline. To keep this behavior, i have removed the defaults for item.editable to allow it to be null and updated the predicates. This oversight was actually made when i set up the test matrix for #2284. I have changed the anticipated behavior of default for this commit. Please reconsider for approval.

Thanks for catching the logic flaws.

@mojoaxel mojoaxel added this to the Minor Release v4.18 milestone Nov 15, 2016
var updateGroupAllowed = me.options.editable.updateGroup ||
(!this.options.editable.overrideItems && selectedItem.editable === true);
var updateGroupAllowed = (me.options.editable.overrideItems && this.options.editable.updateGroup) ||
(!this.options.editable.overrideItems && (!selectedItem.editable || selectedItem.editable.updateGroup));
Copy link
Member

Choose a reason for hiding this comment

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

Still something weird with the logic. Shouldn't it should be:
(me.options.editable.overrideItems && this.options.editable.updateGroup) || (!this.options.editable.overrideItems && (selectedItem.editable == true || selectedItem.editable.updateGroup))?

var updateTimeAllowed = me.options.editable.updateTime || (
props.item.editable === true && !me.options.editable.overrideItems);
var updateTimeAllowed = ((me.options.editable.overrideItems || !props.item.editable ) && me.options.editable.updateTime) || (
(props.item.editable && props.item.editable.updateTime) && !me.options.editable.overrideItems);
Copy link
Member

Choose a reason for hiding this comment

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

Sorry but here too.
(me.options.editable.overrideItems && me.options.editable.updateTime) || ( (!me.options.editable.overrideItems && (props.item.editable==true || props.item.editable.updateTime));

|| (this.data.editable === true &&
(this.options.editable.overrideItems || !this.editable))
|| (this.editable && this.editable.remove &&
!this.options.editable.overrideItems);
Copy link
Member

Choose a reason for hiding this comment

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

Here too:
(this.options.editable.overrideItems && this.options.editable.remove) || (!this.options.editable.overrideItems && (this.editable==true || this.editable.remove)


var updateGroupAllowed = me.options.editable.updateGroup ||
props.item.editable === true;
var updateGroupAllowed = ((me.options.editable.overrideItems || !props.item.editable ) && me.options.editable.updateGroup) || (
Copy link
Member

Choose a reason for hiding this comment

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

Here too:
(me.options.editable.overrideItems && me.options.editable.updateGroup) || (!me.options.editable.overrideItems && (me.options.editable==true || me.options.editable.updateGroup)

@yotamberk
Copy link
Member

I hope I'm not discouraging you. The logic is kind of messy and I think it needs to be cleaned up a bit before being approved

* Fixed bug introduced in visjs#2284 where overrideItems is set to true when boolean is provided
* Added the option of supplying object to item.editable with updateTime, updateGroup, and remove functioning similarly to timeline.editable but only on a single item
* Updated Documentation to reflect the new feature
* Updated the individualEditableItems example page to show feature usage.
@simo9000 simo9000 force-pushed the itemEditableOptions branch from 13a8695 to f2e9a4b Compare November 17, 2016 05:10
@simo9000
Copy link
Contributor Author

@yotamberk It's not discouraging at all. You are right that it was still messy. While it was "working" to pass all the tests I could come up with, the predicates were not standardized even though they were doing the same basic tests. I decided to formalize this logic:

Ov = options.editable.overrideItems
<property> => updateGroup || updateTime || remove
Tp = options.editable.<property>
I = item.editable
Ip = item.editable.<property>

The abstract predicate that applies in all cases is

((Ov || I == null) && Tp) || (!Ov && I != null && Ip)

I have changed all three predicates you suggested changes on to use this form. The predicate at line 1460 of itemset.js is actually redundant as updateGroupAllowed is still in scope from the predicate at line 1364 so i have removed it.

Your code suggestions included item.editable == true, this will not work with the edits that i have made to Item.js. Item.editable is only assigned values of null or of object. As the abstract predicate indicates, i have removed the reliance on truthiness.

@yotamberk
Copy link
Member

yotamberk commented Nov 17, 2016

MUCH BETTER! Did you check the logic matrix?

Item.editable is only assigned values of null or of object.

I'm still wondering about that. seems a little weird that it's different than options.editable. But I'll approve this. Again, very nice work! Looking forward to more PRs =)

@mojoaxel
Copy link
Member

@simo9000 Thanks! Thats a nice improvement!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants