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

Better handling of RemarksField and friendly display #1495

Merged
merged 46 commits into from
Jan 15, 2020
Merged

Conversation

xispa
Copy link
Member

@xispa xispa commented Dec 22, 2019

Description of the issue/feature this PR addresses

Remarks field is a bit wonky, especially because of how handles and displays the text. This Pull Request improves the RemarksField as well as it's look&feel (see screenshot below).

Remarks are now stored in a list (a RemarksHistory object) made of dicts (RemarksHistoryRecord objects), that allows easy access to remark entries and metadata as well (user id, user name, etc). It opens the possibility to add more keys in the RemarksHistoryRecord dict to handle future behaviors (e.g. pin remarks, choose those to be printed in results report, etc.)

Captura de 2019-12-23 00-26-37

Current behavior before PR

The way RemarksField works is wonky

Desired behavior after PR is merged

RemarksField becomes more flexible

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

xispa added 10 commits December 20, 2019 23:04
When include_methods param is used in a read call with a single
parameter (instead of a list of more than one), the jsonapi does
not handle the value parameter properly and transforms it to
a list of characters instead.

A call like follows:

```
this.ajax_submit({
  url: this.get_portal_url() + "/@@API/read",
  data: {
          catalog_name: "uid_catalog",
          UID: widget.attr('data-uid'),
          include_methods: ["getSomething"],
        }
}).done(function(data) {
  return deferred.resolveWith(this, [data.objects[0]["getSomething"]]);
});
```

fails. The function `get_include_methods` returns `getSomething`
instead of a list `[getSomething]`. Therefore, the function
`load_method_values` tries the following calls to the instance:
`g`, `e`, `t`, `S`, `o`, ...

If the call is like follows:
```
this.ajax_submit({
  url: this.get_portal_url() + "/@@API/read",
  data: {
          catalog_name: "uid_catalog",
          UID: widget.attr('data-uid'),
          include_methods: ["getSomething", "getId"],
        }
}).done(function(data) {
  return deferred.resolveWith(this, [data.objects[0]["getSomething"]]);
});
```
the list is resolved properly.
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

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

Fails for Unicode Remarks with the following Traceback:

  [...]
  Module bika.lims.browser.fields.remarksfield, line 102, in markdown_content
  Module markdown, line 411, in markdown
  Module markdown, line 279, in convert
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 91: ordinal not in range(128). -- Note: Markdown only accepts unicode input!

@ramonski
Copy link
Contributor

It also seems that the timestamp for new remarks is missing:

Remarks Test

Is there any chance to migrate existing remarks to the new format?

Also just an idea: How about storing that whole thing in JSON format?

@ramonski
Copy link
Contributor

ramonski commented Dec 23, 2019

Sorry, the timestamp is now displayed after a full reload, but old comments get the same timestamp as the new ones:

Also I would rather display the full date instead of the friendly date and do the conversion in JavaScript with momentjs

@xispa
Copy link
Member Author

xispa commented Dec 23, 2019

Also I would rather display the full date instead of the friendly date

Done

Is there any chance to migrate existing remarks to the new format?

Can be done, but since the remarks is already handling legacy values without having to walk-through all objects in an endless upgrade step, I thought that was not worth.

Also just an idea: How about storing that whole thing in JSON format?

I did store the value jsonified at the beginning:

0718a9b#diff-ff77314d577c3d0d3aca8ee30f1ff8a9L107

but I thought it was making the thing more complex without providing any benefits.

Fails for Unicode Remarks with the following Traceback:

Umm, this comes from the markdown library. I tested the RemarksField using html_content instead of markdown_content and was warking properly. This was my last commit and I did not test it thoroughly. Going to take a look Fixed

@xispa
Copy link
Member Author

xispa commented Jan 11, 2020

I think is working fine now, except that the styling of remarks fields in places where the form is automatically rendered by AT (e.g. for setup content types such as Analysis Profile) is missing because of this change: cd5b734#diff-08f153d902254658e1293551c2475c89

Without the previous commit and adding the following property in remarkswidget.py:

        'helper_css': (
            "bika_widgets/remarkswidget.css",),

the remarks styling in e.g. Analysis Profile (both in view and edit), would look like this:

Captura de 2020-01-11 23-48-14

Now it looks like follows:

Captura de 2020-01-11 23-52-52

@xispa
Copy link
Member Author

xispa commented Jan 11, 2020

Also, I feel the sort order from newest to oldest is quite confusing. I know it was like this before, but still...

@ramonski
Copy link
Contributor

ramonski commented Jan 12, 2020

Hmm, I've seen that in view-mode the class ArchetypesRemarksWidget was absent, that's why I did the change. Shall we remove these Remarks fields in the Setup Items? I think they are misplaced there anyway...

Or maybe we can use a simple text widget for the remarks in setup items? I've seen that this is the case for Analysis Services.

@xispa
Copy link
Member Author

xispa commented Jan 12, 2020

Or maybe we can use a simple text widget for the remarks in setup items? I've seen that this is the case for Analysis Services.

Agree, I don't think such remarks widget makes sense in setup items. A simple text widget would work, indeed.

@ramonski ramonski self-requested a review January 15, 2020 07:53
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

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

Finally merging....

@ramonski ramonski merged commit b9e5144 into master Jan 15, 2020
@ramonski ramonski deleted the better-remarks branch January 15, 2020 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants