Improvement: Sort order if fields in Editing the Admin View #147

Closed
opened 2017-10-25 12:49:17 +00:00 by kevincam3 · 13 comments
kevincam3 commented 2017-10-25 12:49:17 +00:00 (Migrated from github.com)

It would be nice to sort the fields in the order I set them to display in the admin view in the attached view:

image

It would be nice to sort the fields in the order I set them to display in the admin view in the attached view: ![image](https://user-images.githubusercontent.com/870934/31999475-1eb3cf94-b972-11e7-9baf-d2e876cd001d.png)

The automated sort of the fields has been removed since you can with the subform drag and drop the fields in the correct order very easy.

To avoid us change you own selected order, we removed the feature.

The automated sort of the fields has been removed since you can with the subform drag and drop the fields in the correct order very easy. To avoid us change you own selected order, we removed the feature.
kevincam3 commented 2017-10-25 14:00:07 +00:00 (Migrated from github.com)

So do we need the "Order in Edit" if Drag and Drop works?

So do we need the "Order in Edit" if Drag and Drop works?

yes the drag and drop does work 👍

You still need to set the order for edit and order for list, as those orders are for the compiler. The drag and drop is just for you... :)

yes the drag and drop does work :+1: You still need to set the order for edit and order for list, as those orders are for the compiler. The drag and drop is just for you... :)
kevincam3 commented 2017-10-25 14:02:25 +00:00 (Migrated from github.com)

Ok, so what I was thinking is we just have one and not both sorts. Unless there's a reason that someone would want them to be different.

Ok, so what I was thinking is we just have one and not both sorts. Unless there's a reason that someone would want them to be different.
kevincam3 commented 2017-10-25 14:05:40 +00:00 (Migrated from github.com)

It's not a big deal it was just something that was counter intuitive to me that after I changed the sort order in "Order edit" I was expecting to see them listed in that order after I saved it.

It's not a big deal it was just something that was counter intuitive to me that after I changed the sort order in "Order edit" I was expecting to see them listed in that order after I saved it.

I do not have one view where those are the same. So of course we want them both, they target two different concepts. The one for the list layout and the other for the edit layout in a tab and position.

I do not have one view where those are the same. So of course we want them both, they target two different concepts. The one for the list layout and the other for the edit layout in a tab and position.

Hey we can always add the sort feature back.. if you are up to the task.

Look here is the old code that sorted the fields on save.

Convert it to now work on the new admin_fields. This is the issue that we last addressed this.

This is the area (from line 815 in the admin_fields model) the code must go.

So adapt the code, test it, and once you think it works as you expected, share it in this issue. Then I will test it and add it to the core once we are sure it works.

Hey we can always add the sort feature back.. if you are up to the task. [Look here is the old code](https://github.com/vdm-io/Joomla-Component-Builder/blob/v2.5.5/admin/models/admin_view.php#L2822) that sorted the fields on save. Convert it to now work on the new admin_fields. This is [the issue that we last addressed this](https://github.com/vdm-io/Joomla-Component-Builder/issues/43). [This is the area (from line 815 in the admin_fields model) the code must go](https://github.com/vdm-io/Joomla-Component-Builder/blob/master/admin/models/admin_fields.php#L815). So adapt the code, test it, and once you think it works as you expected, share it in this issue. Then I will test it and add it to the core once we are sure it works.
kevincam3 commented 2017-10-25 14:18:14 +00:00 (Migrated from github.com)

I thought it was just a simple matter of a query that was returning the results in this image and we would just sort by "Order edit" column. But if it's more complicated than that we can leave it as is.

image

I thought it was just a simple matter of a query that was returning the results in this image and we would just sort by "Order edit" column. But if it's more complicated than that we can leave it as is. ![image](https://user-images.githubusercontent.com/870934/31999475-1eb3cf94-b972-11e7-9baf-d2e876cd001d.png)

Doing it in the returned results could cause confusion. Since we will display the data in away that is not true to how it is stored. Then once the user opens the fields it will look strange and not in the same order. SO the way is to do it in the model on save, to insure that we have consistency.

Doing it in the returned results could cause confusion. Since we will display the data in away that is not true to how it is stored. Then once the user opens the fields it will look strange and not in the same order. SO the way is to do it in the model on save, to insure that we have consistency.

This is not complex... I just don't have time now. Your help with this will be wonderful.

This is not complex... I just don't have time now. Your help with this will be wonderful.
kevincam3 commented 2017-10-25 14:23:12 +00:00 (Migrated from github.com)

Ok, got it. I didn't realize that the two sorts served different purposes.

Ok, got it. I didn't realize that the two sorts served different purposes.
ro-ot commented 2017-10-25 15:24:17 +00:00 (Migrated from github.com)

Hi guys, I have not tested this.

if (isset($data['addfields']) && ComponentbuilderHelper::checkJson($data['addfields']))
{
	// Sort fields by 'Tab' ASC, 'Order in Edit' ASC
	$addfields = json_decode($data['addfields'], true);
	if (ComponentbuilderHelper::checkArray($addfields))
	{
		// do the actual sort by tab and order_edit
		usort($addfields, function ($a, $b) {
			$val_a = sprintf('%02u', $a['tab']) . sprintf('%02u', $a['alignment']) . sprintf('%03u', $a['order_edit']);
			$val_b = sprintf('%02u', $b['tab']) . sprintf('%02u', $b['alignment']) . sprintf('%03u', $b['order_edit']);
			return strcmp($val_a, $val_b);
		});
		$data['addfields'] = json_encode($addfields, true);
	}
}

But this should work.

Hi guys, I have not tested this. ``` if (isset($data['addfields']) && ComponentbuilderHelper::checkJson($data['addfields'])) { // Sort fields by 'Tab' ASC, 'Order in Edit' ASC $addfields = json_decode($data['addfields'], true); if (ComponentbuilderHelper::checkArray($addfields)) { // do the actual sort by tab and order_edit usort($addfields, function ($a, $b) { $val_a = sprintf('%02u', $a['tab']) . sprintf('%02u', $a['alignment']) . sprintf('%03u', $a['order_edit']); $val_b = sprintf('%02u', $b['tab']) . sprintf('%02u', $b['alignment']) . sprintf('%03u', $b['order_edit']); return strcmp($val_a, $val_b); }); $data['addfields'] = json_encode($addfields, true); } } ``` But this should work.

Thanks, I will add that 👍

Thanks, I will add that :+1:
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#147
No description provided.