Inspector Form Configuration
Directory Structure
The appropriate site dependent settings are loaded in lib/couchdb.rb with the following lines:
module Couchdb require 'couchrest' require "forms/#{Settings.SXS.Couchdb.SiteName}/config.rb" ...I.e. the config.rb file under lib/foms#{Settings.SXS.Couchdb.SiteName} loads all of the necessary files used in the configuration. As a convention, the following files are stored in the directory:
config.rb - the main loader fields-tag.rb - field definitions for Item records fields-scan.rb - field definitions for History records form-tag-#{form_name}.rb - 1 or more files for Item forms form-scan-#{form_name}.rb - 1 or more files for History forms report-#{form_name}.rb - 1 or more files for reports
The Main Loader
The main loader, config.rb has to have the following structure (shown with a typical example):
module Couchdb::CouchdbMeta require "forms/generic.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-tag-inspection.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-tag-surveillance.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-tag-firerateddoor.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-scan-destructive.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-scan-surveillance.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/form-scan-firerateddoor.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/fields-tag.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/fields-scan.rb" require "forms/#{Settings.SXS.Couchdb.SiteName}/report-inspection.rb" @@forms = { tag: { inspection: TagInspection.getForm, surveillance: TagSurveillance.getForm, fireratteddoor: TagFireRatedDoor.getForm, }, scan: { "urt-destructive": ScanDestructive.getForm, "urt-surveillance": ScanSurveillance.getForm, "urt-firerateddoor": ScanFireRatedDoor.getForm, sort_: { # scan.sort_ "updated_at": "Update time", "_id": "Create time", "form_": "Inspection type", "reference_number": "Reference number", "risk_level": "Risk level", "status": "Status" } } }.with_indifferent_access @@fields = { tag: FieldsTag.getFields, scan: FieldsScan.getFields, }.with_indifferent_access @@reports = { inspection: ReportInspection.getReport }.with_indifferent_access def self.getForms return @@forms end def self.getFields return @@fields end def self.getReports return @@reports end endReplace, remove only appropriate parts to create a new configuration. The module globals and the module functions are called from outside to get the configuration elements. Using the hash modifier with_indifferent_access is very important.
NOTE: Generally symbols or strings can be used as keys in all hashes in the definition files, but only strings as values.
Field Definitions
The files fields-tag.rb and fields-scan.rb contain definitions of the fields commonly used in all type of forms. Note that both type of records have the following fields regardless of they are defined here or not:
_id - unique database id _rev - database revision form_ - name of the form referring this specification created_at - creation time of the record in ISO format updated_at - last update time of the record in ISO format created_by - creator of the record (email address) updated_by - updater of the record (email address)
Field Definition File Format
- The files have to have the following format:
module Couchdb::CouchdbMeta::FieldsTag @@fields = Hash def self.getFields return @@fields end endTheHash keys are the fields of CouchDB/PouchDB (hereinafter database) records, while the Hash values contain the definitions of the fields.
Field Definition Elements
- The following elements can be used in the field definition:
Definition Key
Description
Notes
label
Human name of the field
It is required if no custom template is used
type
Field type, one of form_, select, checkbox, textarea, text
Default is text
