The objective is to create a new entity called "notes" in the codebase. We would do the following:
- Creation of model(schema) for notes, giving it attributes like title, description and status.
- Providing appropriate "Seeds"(dummy data) for the "notes" model.
- Creation of appropriate "Routes" for the "notes" in order to provide appropriate paths for carrying out operations.
- Creation of "Services".
- Creation of "Controllers"
- Creating appropriate "View"
- Performing CRUD operations for "notes".
Models act as schema for representing the information for a particular table to be inserted into the document. We are using the model structure defined by Sequelize(https://sequelize.org/) here. Create a model called "notes.js" under the “models” folder in your smarthub project folder.
Seeding is basically providing dummy data that can be stored in the "notes" table in the database if before any information can be inserted by the user. Navigate to the "seed" folder in your smarthub project. create a new seed file called "notes.json" and enter some dummy data in JSON format.
Routes provide the pathway for various operations to be performed within the project. Create a file called notes.routes.js under the "routes" folder in smarthub project. Also provide application router by the name of "noteRouter" in the app.js file of the smarthub project.
We need to create services that facilitate the operations we are going to perform. Create a service called noteService.js under the "services" folder in your smarthub_ch project.
Controllers are used for rendering the data onto the client. Create a file called "notesControllers.js" under the "controllers" folder in the smarthub_ch project.
View Layer will render all our back-end logic to the client-side. In the smarthub project, for view layer, we will have to make certain changes for the "notes". Following is the list of files we need to make changes to:
We need to add our notes menu to the navigation dashboard of smarthub project. Add the following piece of code in the navigationConfig.json file.
"notesMenu": {
"display": "none",
"subMenuState": {
"Notes": ""
}
}
acl.json file facilitates that there is notes menu present in the navigation dashboard. add "notesMenu" key under the "navigation" object in acl.json file.
"navigation": {
"dashboardsMenu": true,
"partnerCharitiesMenu": true,
"vendingMachinesMenu": true,
"clientsMenu": true,
"employeesMenu": true,
"jobsMenu": true,
"donationsMenu": true,
"superAdminMenu": true,
"cmssMenu": true,
"pimMenu": true,
"notesMenu": true // newly added notesMenu
}
default.hbs is the main rendering page of the smarthub. Here it will render the views of all layers. We need to add notesMenu here as well.
<!--Dashboards-->
{{#if loggedInUser.navigationRules.notesMenu}}
{{> navigation/notesMenu this}}
{{/if}}
the above layers facilitate the rendering of your particular table data(in this case, notes) on the client-side.
under the "views" section, we need to have self-defined view layers for various operations, that is creating a new note, reading the notes, and deleting the notes.
- create "notes" folder under the "views" folder in smarthub.
- create "getNotes.hbs" file for reading all notes in the dashboard.
- create "createNotes.hbs" file for creating a new note.