WIP: adds datatable to index datatype. #370

Draft
laurensmartina wants to merge 3 commits from hypha-117 into master
laurensmartina commented 2021-01-06 09:17:48 +00:00 (Migrated from github.com)

Still not ready to merge, but reviews are highly appreciated.

Still not ready to merge, but reviews are highly appreciated.
RoukePouw (Migrated from github.com) reviewed 2021-01-06 09:57:32 +00:00
RoukePouw (Migrated from github.com) commented 2021-01-06 09:57:31 +00:00

Would it make sense to add a prefix to these translation identifiers to indicate that they will be used as column headers?

Would it make sense to add a prefix to these translation identifiers to indicate that they will be used as column headers?
laurensmartina (Migrated from github.com) reviewed 2021-01-06 10:18:26 +00:00
laurensmartina (Migrated from github.com) commented 2021-01-06 10:18:25 +00:00

Good point! Will do that!

Good point! Will do that!
matthijskooijman (Migrated from github.com) reviewed 2021-01-06 11:24:51 +00:00
matthijskooijman (Migrated from github.com) left a comment

Overall, looks like this is heading in the right direction. I added a bunch of inline comments.

I think that it would be good to split off the getAuthor() changes into their own commit before finalizing this.

Overall, looks like this is heading in the right direction. I added a bunch of inline comments. I think that it would be good to split off the `getAuthor()` changes into their own commit before finalizing this.
matthijskooijman (Migrated from github.com) commented 2021-01-06 11:20:12 +00:00

What is the point of this array_intersect? This seems to drop any keys from $dataMtx that do not appear in getIndexTableColumns(), but in the code I can see that this does not happen? Or is the point that subclasses can delete columns from their superclasses by removing them from getIndexTableColumns (by overriding it)? If so, I'd suggest that those superclasses can also just delete the columns from getIndexData (by overriding that as well), or maybe index page should globally just do this intersect (rather than each datatype having to do it individually)?

What is the point of this array_intersect? This seems to drop any keys from `$dataMtx` that do not appear in `getIndexTableColumns()`, but in the code I can see that this does not happen? Or is the point that subclasses can *delete* columns from their superclasses by removing them from `getIndexTableColumns (by overriding it)`? If so, I'd suggest that those superclasses can also just delete the columns from `getIndexData` (by overriding that as well), or maybe index page should globally just do this intersect (rather than each datatype having to do it individually)?
matthijskooijman (Migrated from github.com) commented 2021-01-06 11:23:48 +00:00

Also, I think this is the first time we're using constants as translation string ids (instead of passing them to __() literally). If we ever want to add some automatic translation checking, which I can imagine works by scanning the code for calls to __() and picking out the argument, this might make that more complicated.

Also, I think this is the first time we're using constants as translation string ids (instead of passing them to `__()` literally). If we ever want to add some automatic translation checking, which I can imagine works by scanning the code for calls to `__()` and picking out the argument, this might make that more complicated.
@ -61,0 +84,4 @@
$id = $this->pageListNode->getAttribute('id');
$date = $this->getSortDateTime();
$data = [
__(self::INDEX_TABLE_COLUMNS_TITLE) => [
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:10:33 +00:00

I wonder if using the translated titles as array indices here is the best approach? I would tend to use some kind of (untranslated) name as the index, and then put the translated title in a field next to class/sort/value?

I wonder if using the translated titles as array indices here is the best approach? I would tend to use some kind of (untranslated) name as the index, and then put the translated title in a field next to class/sort/value?
@ -61,0 +85,4 @@
$date = $this->getSortDateTime();
$data = [
__(self::INDEX_TABLE_COLUMNS_TITLE) => [
'class' => 'type_'.get_class($this).' '.($this->privateFlag ? 'is-private' : 'is-public'),
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:15:43 +00:00

These things (datatype and private flag) seem to be unrelated to the title, so I wonder if these are appropriate here? Conceptually, they would be a column of their own, but you probably do not want to display them as such.

Maybe these would be more appropriate as classes on the <tr> instead of an individual column? Maybe returned as a special column in this array?

These things (datatype and private flag) seem to be unrelated to the title, so I wonder if these are appropriate here? Conceptually, they would be a column of their own, but you probably do not want to display them as such. Maybe these would be more appropriate as classes on the `<tr>` instead of an individual column? Maybe returned as a special column in this array?
@ -61,0 +87,4 @@
__(self::INDEX_TABLE_COLUMNS_TITLE) => [
'class' => 'type_'.get_class($this).' '.($this->privateFlag ? 'is-private' : 'is-public'),
'sort' => preg_replace("/[^A-Za-z0-9]/", '', $this->getTitle()).'_'.$id,
'value' => '<a href="'.$this->language.'/'.$this->pagename.'">'.$this->getTitle().'</a>',
matthijskooijman (Migrated from github.com) commented 2021-01-06 11:22:07 +00:00

Should this be html_value to distinguish between html and text value? Alternatively, the non-HTML values should be htmlspecialchars'd? Alternatively, this could maybe build a DomNode to indicate that it is already HTML (combined with my other suggestion to build a DOM tree instead of an HTML string), and then any strings can be treated as text (and thus encoded).

Should this be `html_value` to distinguish between html and text value? Alternatively, the non-HTML values should be `htmlspecialchars`'d? Alternatively, this could maybe build a `DomNode` to indicate that it is already HTML (combined with my other suggestion to build a DOM tree instead of an HTML string), and then any strings can be treated as text (and thus encoded).
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:25:58 +00:00

If you just want the latest version, no need to keep a full array and sort that, just keep a latest version variable and whenever you find a later version, update that variable?

If you just want the latest version, no need to keep a full array and sort that, just keep a latest version variable and whenever you find a later version, update that variable?
@ -41,1 +41,4 @@
$this->html->linkScript('//cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js');
$this->html->linkStyle('//cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css');
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:26:55 +00:00

Don't forget to add these locally later.

Don't forget to add these locally later.
@ -42,0 +62,4 @@
ROW;
$tRowItemTpl = <<<ROWITEM
<td class="index-item [[name]] [[class]]" data-sort="[[sort]]">[[value]]</td>
ROWITEM;
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:46:03 +00:00

I'm not sure if I like using these HTML templates like this. They are easy to read, but building HTML from text also seems prone to typos, encoding errors, etc. For forms, we're using this approach because those are complex and very diverse, but here the structure is very repetitive and simple, which means it could be feasible to just build up the DOM in memory like we do elsewhere. This has the advantage that all encoding is done automatically, you can't break the DOM with a typo, you can easily make changes to earlier sections of the DOM, etc.

I'm not sure if I like using these HTML templates like this. They are easy to read, but building HTML from text also seems prone to typos, encoding errors, etc. For forms, we're using this approach because those are complex and very diverse, but here the structure is very repetitive and simple, which means it could be feasible to just build up the DOM in memory like we do elsewhere. This has the advantage that all encoding is done automatically, you can't break the DOM with a typo, you can easily make changes to earlier sections of the DOM, etc.
@ -49,0 +74,4 @@
$isInDataType = array_key_exists($page->getAttribute('type'), $dataTypes);
if ($lang && $isPrivateOrUser && $isInDataType) {
/** @var HyphaDatatypePage $hyphaPage */
$hyphaPage = createPageInstance($this->O_O, $page);
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:31:11 +00:00

This should be $isPublicOrUser (or $isNotPrivateOrIsUser).

This should be `$isPublicOrUser` (or `$isNotPrivateOrIsUser`).
@ -49,0 +75,4 @@
if ($lang && $isPrivateOrUser && $isInDataType) {
/** @var HyphaDatatypePage $hyphaPage */
$hyphaPage = createPageInstance($this->O_O, $page);
$titleSort = preg_replace("/[^A-Za-z0-9]/", '', $hyphaPage->getTitle());
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:31:21 +00:00

Can this ever be false?

Can this ever be false?
@ -49,2 +79,4 @@
$titleSort .= '_'.$index;
$pageList[$titleSort] = $hyphaPage;
}
}
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:35:07 +00:00

This duplicates the sort return in the column data, could the default sorting maybe reuse that (i.e. by using a user-defined sorting function after collecting all index data that looks at title->sort?

This duplicates the sort return in the column data, could the default sorting maybe reuse that (i.e. by using a user-defined sorting function after collecting all index data that looks at `title->sort`?
@ -65,2 +102,2 @@
$capital++;
$first = false;
if (!is_array($item)) {
$item = ['value' => $item];
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:42:07 +00:00

Should this list of columns be based on the datatypes available? That would mean you always get a "status" field, even for sites that do not have any articles at all (then the status column will be present but always empty). How about filling $columns based on the result from all getIndexData calls instead?

Should this list of columns be based on the datatypes available? That would mean you always get a "status" field, even for sites that do not have any articles at all (then the status column will be present but always empty). How about filling `$columns` based on the result from all `getIndexData` calls instead?
@ -76,0 +143,4 @@
$dateIndex = array_search(__(HyphaDatatypePage::INDEX_TABLE_COLUMNS_DATE), array_values($columns));
$vars = [
'sortIndex' => $dateIndex,
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:37:17 +00:00

Why build the header after the body? $columns is already know before right?

Why build the header after the body? `$columns` is already know before right?
matthijskooijman (Migrated from github.com) commented 2021-01-06 10:39:38 +00:00

What does this sortIndex mean exactly? Is this the default sorting (if so, then why sort the HTML at all)? Or the only option for interactive sorting? This could probably use a comment.

What does this sortIndex mean exactly? Is this the default sorting (if so, then why sort the HTML at all)? Or the only option for interactive sorting? This could probably use a comment.
laurensmartina (Migrated from github.com) reviewed 2021-01-06 12:26:49 +00:00
@ -49,0 +74,4 @@
$isInDataType = array_key_exists($page->getAttribute('type'), $dataTypes);
if ($lang && $isPrivateOrUser && $isInDataType) {
/** @var HyphaDatatypePage $hyphaPage */
$hyphaPage = createPageInstance($this->O_O, $page);
laurensmartina (Migrated from github.com) commented 2021-01-06 12:26:49 +00:00

Probably is isPublicOrUser

Probably is `isPublicOrUser`
laurensmartina (Migrated from github.com) reviewed 2021-01-13 09:59:06 +00:00
laurensmartina (Migrated from github.com) commented 2021-01-13 09:59:06 +00:00

true

true
laurensmartina (Migrated from github.com) reviewed 2021-01-13 10:15:35 +00:00
@ -49,0 +75,4 @@
if ($lang && $isPrivateOrUser && $isInDataType) {
/** @var HyphaDatatypePage $hyphaPage */
$hyphaPage = createPageInstance($this->O_O, $page);
$titleSort = preg_replace("/[^A-Za-z0-9]/", '', $hyphaPage->getTitle());
laurensmartina (Migrated from github.com) commented 2021-01-13 10:15:34 +00:00

I can think of ways it could be false. But I guess we can cover that case when it actually happens.

I can think of ways it could be false. But I guess we can cover that case when it actually happens.
laurensmartina (Migrated from github.com) reviewed 2021-01-13 10:49:43 +00:00
@ -41,1 +41,4 @@
$this->html->linkScript('//cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js');
$this->html->linkStyle('//cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css');
laurensmartina (Migrated from github.com) commented 2021-01-13 10:49:43 +00:00

done

done
laurensmartina (Migrated from github.com) reviewed 2021-01-13 10:52:08 +00:00
@ -49,0 +75,4 @@
if ($lang && $isPrivateOrUser && $isInDataType) {
/** @var HyphaDatatypePage $hyphaPage */
$hyphaPage = createPageInstance($this->O_O, $page);
$titleSort = preg_replace("/[^A-Za-z0-9]/", '', $hyphaPage->getTitle());
laurensmartina (Migrated from github.com) commented 2021-01-13 10:52:08 +00:00

There is a page on De Stadsbron that has an incorrect type definition. So yes, it can be false.

There is a page on De Stadsbron that has an incorrect type definition. So yes, it can be false.
laurensmartina (Migrated from github.com) reviewed 2021-01-13 11:17:13 +00:00
@ -65,2 +102,2 @@
$capital++;
$first = false;
if (!is_array($item)) {
$item = ['value' => $item];
laurensmartina (Migrated from github.com) commented 2021-01-13 11:17:13 +00:00

I've fixed this by fetching the used datatypes when iterating over the pages.

I've fixed this by fetching the used datatypes when iterating over the pages.
laurensmartina (Migrated from github.com) reviewed 2021-01-13 11:19:04 +00:00
@ -76,0 +143,4 @@
$dateIndex = array_search(__(HyphaDatatypePage::INDEX_TABLE_COLUMNS_DATE), array_values($columns));
$vars = [
'sortIndex' => $dateIndex,
laurensmartina (Migrated from github.com) commented 2021-01-13 11:19:03 +00:00

No reason, I've moved this piece of code above the body.

No reason, I've moved this piece of code above the body.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin hypha-117:hypha-117
git switch hypha-117

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff hypha-117
git switch hypha-117
git rebase master
git switch master
git merge --ff-only hypha-117
git switch hypha-117
git rebase master
git switch master
git merge --no-ff hypha-117
git switch master
git merge --squash hypha-117
git switch master
git merge --ff-only hypha-117
git switch master
git merge hypha-117
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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
harmen/hypha!370
No description provided.