Having a separate route to display all the hardcoded project’s configuration makes it very easy to compare web apps with each other. A similar architecture has been followed in loklak to create a ‘/settings’ route to display configs used inside it. Respective implementation would be discussed in this blog.
Creating Settings Component
First step would be to create a Settings component to render under /settings route.
This command will create new settings component. We have to create settings-routing and settings module inside settings component separately. This route module will be called inside the root app module. The settings-routing module would import Router module as follows:
The settings module would follow the basic module configuration of Angular, and import the settings-routing module as follows:
At this point of time, we are having a basic settings component to render under /settings route.
Loading /settings as child route under root app module
Now, we need to add path of ‘/settings’ route inside root app module as follows:
Which means when user is on path /settings, load settings component.
Fetching project configs inside settings component
At this point, we have successfully established /settings route and settings component. Now we need to fetch the project configs inside the settings component to display. We would actually import the config and store it in an array to loop through it in template file using *ngFor to display the items under config array.
Note: We would import newsOrgs containing twitter username of news organizations, and the defaultUrlConfig containing the list of all hardcoded URLs used inside the project. It can be taken as an example to add and display more configurations.
urlObject is an array used to store the list of hardcoded URLs, and newsConfigOrgs is an array containing all the list of news organizations.
Displaying array items in template file
Up to this point, we have successfully stored the data inside the component file of settings component and now we need to display this data in template file. For a sake of an example, we would display news orgs as follows:
|<!– News Config –>
<div class=“url-container” *ngFor=“let key of newsConfigOrgs”>
The above code could be used as an example to display more config stored inside component file. Only the basic implementation has been followed and mentioned inside this blog, complete code can be found here: code.
Creating settings tab in Advanced-Feed
Now we need to provide a link to user to check /settings route. We would actually add another tab as settings inside Advanced-Feed as follows:
Testing /settings route
Search a query on loklak.org, and then click on settings tab which would be similar to:
On clicking settings tab, user should be directed to the /settings route containing non-editable (read-only) configuration.