Help for Custom view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zkuun8
    Junior Member
    • Dec 2024
    • 6

    Help for Custom view

    Hello,
    I try to build my first Custom View, and I meet some issues.
    I use the extension Project Management and would like to add a custom view to entity Project.

    I made 4 files :
    - custom/Espo/Custom/Resources/metadata/clientDefs/Project.json
    - client/custom/src/views/project/list-with-hello.js
    - custom/Espo/Custom/Resources/metadata/app/routes.json
    - client/custom/src/controllers/project/list-with-hello.js

    The method I try to use is:
    - define a view in clientDefs
    - make a route for this view
    - make a button to access to this view

    At the moment, the button give me link that return 404.
    I'm not sure to understand exactly is the issue, but I think the view is not reconized as it should.
    Any advice would be much appreciated !



    custom/Espo/Custom/Resources/metadata/clientDefs/Project.json :
    Code:
    {
       "kanbanViewMode": true,
       "color": null,
       "iconClass": "fas fa-list-alt",
       "relationshipPanels": {
          "typeProjets": {
             "layout": null,
             "selectPrimaryFilterName": null
          }
       },
       "views": {
          "listWithHello": "custom:views/project/list-with-hello"
       },
       "menu": {
          "list": {
             "buttons": [
                {
                   "label": "Vue ListWithHello",
                   "link": "#Project/list-with-hello",
                   "acl": "read"
                }
              ]
          }
      }
    
    }
    client/custom/src/views/project/list-with-hello.js:
    Code:
    define('custom:views/project/list-with-hello', ['view'], (View) => {
       return class extends View {
          template() {
             return `
                <div>
                   <div style="width: 50%; float: left; border-right: 1px solid #ccc;">
                      <h3>Liste des projets</h3>
                    </div>
                   <div style="width: 50%; float: left;">
                      <h1>Hello</h1>
                   </div>
               </div>
              `;
             }
          };
       });



    custom/Espo/Custom/Resources/metadata/app/routes.json:
    Code:
    {
       "listWithHello": {
          "path": "#Project/list-with-hello",
          "controller": "controllers/project/list-with-hello"
          }
    }


    client/custom/src/controllers/project/list-with-hello.js​​
    Code:
    define('custom:controllers/project/list-with-hello', ['controller'], (Controller) => {
       return class extends Controller {
          run() {
             this.main('custom:views/project/list-with-hello');
          }
       };
    });
    ​
    Attached Files
    Last edited by zkuun8; 01-01-2025, 08:36 PM.
  • rabii
    Active Community Member
    • Jun 2016
    • 1254

    #2
    This is not correct

    PHP Code:
    "views": {
    "listWithHello": "custom:views/project/list-with-hello"
    } 
    
    It should be

    PHP Code:
    "views": {
    "list": "custom:views/project/list-with-hello"
    }


    see documentation here https://docs.espocrm.com/development/custom-views/
    Rabii
    Web Dev

    Comment

    • yuri
      Member
      • Mar 2014
      • 8492

      #3
      Hi,

      I noticed a mistake. Should be clientRoutes.json rather than routes.json.



      Another issue. In the view, instead of the method template(), you need to use templateContent property. https://docs.espocrm.com/development/view/#render

      Note that the metadata reference can be helpful https://docs.espocrm.com/development/metadata/. As well as very helpful metadata schema in IDE.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8492

        #4
        I also recommend to develop an extension rather than using the custom directory. It will allow to use ES6 javascript modules which are much more convenient and have IDE support (autocompletion in PHPStorm works well). https://github.com/espocrm/ext-template

        It may be bit harder to get started, but is much better in the long run.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • yuri
          Member
          • Mar 2014
          • 8492

          #5
          Code:
          {
             "Project/list-with-hello": {
                 "params": {
                     "controller": "custom:controllers/project/list-with-hello",
                     "action": "run"
                 }
             }
          }
          Then, the controller method should be named "actionRun".
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • zkuun8
            Junior Member
            • Dec 2024
            • 6

            #6
            Thanks guys, it helps a lot !

            Comment

            Working...