Custom note type for stream does not have access to data field in note table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onepoint0
    Member
    • Jul 2023
    • 41

    Custom note type for stream does not have access to data field in note table

    Hi Devs!

    I'm building my own stream note type so that I can have custom notes on the Stream of my entities. I've created a note record of type mmxRelated and added some data into the note.data field that I want to parse and display on the front end. I've adapted it from the code in the CreateRelated note type.

    It basically works except that I don't have access to the contents of the note.data field in my view file so I can't do the parsing. I'm trying to get this data in my second code block below - in the init function (almost verbatim from the CreateRelated view).

    The Update and Create note types get the data in the same way and it is available to them (eg in the setup function of view file at client\src\views\stream\notes\update.js), but it is not available in either CreateRelated or my custom view. I think it must be to do with how the PHP is fetching the record from the DB but I can't find where it's happening.

    Can anyone please help with how can I give my view access to this data field?

    Here is my code:

    In \custom\Espo\Custom\Resources\metadata\clientDefs\ Note.json I've created an entry to tell espo where to find the view file:

    Code:
    {
        "itemViews": {
            "MmxRelated": "custom:views/stream/notes/mmx-related"
        }
    }
    I have created that view file at client\custom\src\views\stream\notes\mmx-related.js

    Code:
    define('custom:views/stream/notes/mmx-related', ['views/stream/note'], function (Dep) {
    
        return Dep.extend({
            template: 'custom:stream/notes/mmx-related',
            messageName: 'mmxRelated', 
    //        messageName: 'createRelated',
            data: function () {
                return _.extend({
                    relatedTypeString: this.translateEntityType(this.entityType),
                    iconHtml: this.getIconHtml(this.entityType, this.entityId),
                }, Dep.prototype.data.call(this));
            },
    
            init: function () {
    console.log('in my mmmx one');
                if (this.getUser().isAdmin()) {
                    this.isRemovable = true;
                }
                Dep.prototype.init.call(this);
            },
    
            setup: function () {
                let data = this.model.get('data');
    console.log('my mmx one setup function - data = ',data); // this is null - how do it get it??
                // do stuff here to construct the message for the note
    
            },
    
        });
    });
    ​

    and the custom template at client\custom\res\templates\stream\notes\mmx-related.tpl:

    Code:
    {{#unless noEdit}}
    <div class="pull-right right-container cell-buttons">
    {{{right}}}
    </div>
    {{/unless}}
    
    <div class="stream-head-container">
        <div class="pull-left">
            {{{avatar}}}
        </div>
        <div class="stream-head-text-container">
            {{#if iconHtml}}{{{iconHtml}}}{{/if}}
            <span class="text-muted message">{{{message}}} this is my mmx one</span>
        </div>
    </div>
    
    <div class="stream-date-container">
        <a class="text-muted small" href="#Note/view/{{model.id}}">{{{createdAt}}}</a>
    </div>
    I have extended the Global.json file to create the text template for the content at custom\Espo\Custom\Resources\i18n\en_US\Global.jso n:

    Code:
    {
        "streamMessages": {
            "mmxRelated": "{user} my mmx related {entityType} {entity}",
            "mmxRelatedThis": "{user} my mmx related {entityType} {entity} this"
        }
    }​
    Cheers,
    Clare
    Last edited by onepoint0; 11-08-2023, 06:21 AM.
  • onepoint0
    Member
    • Jul 2023
    • 41

    #2
    Ha, OK, I figured that out almost as soon as I posted it - the data in my note.data field is in the wrong format - if you use this format, it will be accessible to your view file:

    Code:
    {"fields":["dateEnd"],"attributes":{"was":{"dateEnd":"2023-10-28 13:00:00","dateEndDate":"2023-10-28"},"became":{"dateEnd":"2023-11-05 13:00:00","dateEndDate":"2023-11-05"}}}
    The code is looking for the fields and attributes fields in the data. It is then accessible in js using this.model.get('data')

    Comment

    Working...