Table of Contents
New Developers Working Group
Adding and Retrieving Library and Workstation Settings
Adding a Library Setting
These instructions cover how to add a library setting to the database. The example is for adding a library setting that can be referenced by the Hemlock app. Setting types are in config.org_unit_setting_type.
To-dos:
- Add instructions about how to reference the setting in other places in the code.
- Add instructions on writing seed data for contributing back to the community.
1. Determine the setting group and add one if necessary
Setting groups are listed in the table config.settings_group. If none of the listed groups are appropriate, you can add one to the table like so:
INSERT INTO config.settings_group
(name, label)
VALUES
('hemlock', 'Hemlock App');
2. Determine if you need to add an fm_class
If you are referencing something that exists in another table, you may need this. Most library settings don't have one. This is not necessary for our example.
Run the following for a list of settings where fm_class is used:
SELECT * FROM config.org_unit_setting_type WHERE fm_class IS NOT NULL;
3. Determine the datatype for the value
Currently used datatypes are:
- array
- bool
- currency
- integer
- interval
- link
- string
You can look at examples similar to the setting you want to add to determine the datatype. For our example, the most other settings pointing to external URLs use the string datatype, so this is what we will use.
4. Add a reference to VIEW or UPDATE permissions if necessary
If there are permissions related to your setting, you can point to them in the view_perm and update_perm columns. There are no related permissions for our example.
5. Add the setting type to the table
Once you determine what fields need to be referenced, you can add your new setting type to the table.
INSERT INTO config.org_unit_setting_type
(name, label, grp, description, datatype)
VALUES
('hemlock.events_calendar_url', 'Events calendar URL to display in the Hemlock app', 'hemlock', 'Direct link to library's events calendar for display in the Hemlock app.', 'string');
You should now be able to add a new library setting via the GUI or via the actor.org_unit_setting table.
Adding and Retrieving Library Settings for the OPAC
This example adds two library settings to the database and references them in the OPAC:
This example creates a new library setting and references it in Perl:
Retrieving Settings in Angular
getItemBatch
This example retrieves two workstation settings at the same time:
First, setup:
- Import the ServerStoreService:
import {ServerStoreService} from '@eg/core/server-store.service'; - Set it up in the component class:
private serverStore = inject(ServerStoreService);
- Create your variables in the component class:
showDobDefault = false; showDob = false; showFullName = false;
Second, retrieve the workstation settings and put them into a format we can use:
ngOnInit() {
this.serverStore.getItemBatch([
'circ.obscure_dob',
'eg.orgselect.show_combined_names'
]).then(settings => {
const hide = settings['circ.obscure_dob'];
const showFullName = settings['eg.orgselect.show_combined_names'];
this.showDobDefault = this.showDob = !hide;
this.showFullName = showFullName;
})
}
Do whatever you need to do with the code. This example determines whether to show the library's full name or short name on the screen:
orgSn(orgId: number): string {
const org = this.org.get(orgId);
if (this.showFullName) {
return org ? org.name() : '';
} else {
return org ? org.shortname() : '';
}
}
And then this code in the HTML file displays that code:
<div>
<dt i18n>Home Library</dt>
<dd>{{orgSn(p().home_ou())}}</dd>
</div>
getItem
This example is similar to getItemBatch, but it retrieves a single workstation setting:
<code> this.serverStore.getItem('eg.staff.catalog.results.show_sidebar').then(
show_sidebar => {
this.facetsCollapsed = show_sidebar === false;
// Set how many columns the results may take.
this.setResultsWidth();
}
);