OPEN QUESTIONS
Select existing data
should we use a library like choices.jsfor supporting filling in and validation? (currently, I'm using a datalist)
Documentation
App Architecture
Frontend: vanilla html and js.
Backend: google spreadsheet and Google Script deployed as web app.
The app is a simple CRUD interface for a google spreadsheet (well, not really "Deleting").
The frontend is a simple html page with a form to add/edit data (here);
an embedded spreadsheet (here); and this documentation.
The backend is a Google Script that handles the requests from the frontend and updates the spreadsheet accordingly.
The add/edit data function is the one documented in details here.
The page "Add/Edit data" is organised in three steps:
- Select the type of data to add/edit (people, activities, works, places).
- Search if the record already exist.
If the data already exist, the current record will be shown in a table on the left, with the form prefilled with existing data on the right, which the user can edit.
If the data do not exist, only the form will appear. - Fill the form with the data to add/edit and submit (there will be conditional messages, depending on whether the user is editing or adding data).
Note that there are a lot of console logs, to check every step of the process. Additional logs are also in the GAS.
The "search" function is a GET request to the Google Script, sending the type of data and the name of the person to search and eventually fetch. It is case insensitive and trims white spaces, but further spellings/* are not yet implemented.
"Add data": it's a POST request to the Google Script sending the data from the form.
"Edit data": it's first a GET request to the Google Script, sending the name of the person to fetch,
followed by a POST request to the Google Script, sending the updated data from the form.
Javascript
tableform.js contains JavaScript code that dynamically handles fetching, displaying, and submitting data for different entities (`person`, `activity`, `work`, `place`). It includes functionality for rendering tables, forms, and dynamically configuring a button for adding or editing records.
Entity Configuration
entityFields
Defines the fields for each entity type. These fields are used to dynamically render forms and tables. These correspond to the variables in GAS for each entity type.
fieldLabels
Maps field names to user-friendly labels for display in forms and tables. These are dynamically added in the html.
pluralEntities
Maps entity types to their plural forms for configuring fetch calls and calling the right GAS functions (e.g. getDataPeople).
entityButtons
Maps entity types to their respective button labels for the dynamic button. These are dynamically added in the html. It basically helps with the configuration of the "search" (=fetch) fields (suggestions, instructions, labels) and the "add/edit" (=submit) button.
Event Listeners
Fetch Data Button
Adds an event listener to the "Fetch Data" button to fetch data for the selected entity.
Functions
Object.keys(entityButtons)
Sets up the entity Buttons in the fetch form, depending on the entity selected.
loadSuggestionsForEntity
Fetches data for creating the datalist, used in the suggestions during the fetch phase (e.g. checks if a name already exists; users can choose existing names or creating new ones).
This could be used as validation for names (mainly for avoiding duplicates/spellings); validation for dates is still open.
loadSuggestionsForPlaceField
Fetches the list of existing place names (from place_name in table "places") and create a datalist, for suggesting those names in place-related fields (birth place, death place, activity place, work place).
Used in render form fields function.
fetchEntityData
Fetches data for the selected entity and name. If data is found, it renders the table and form. If no data is found, it prepares the form for adding a new record.
renderDataTable
Renders a table displaying the existing data for the selected entity.
renderFormFields
Renders a form with input fields for the selected entity.
fillFormFields
Fills the form fields with data.
clearFormFields
Clears all form fields for the selected entity.
isValidDate
Validation for dates, used in the forms. It accepts formats: DD-MM-YYYY, MM-YYYY, and YYYY. Otherwise, there is an error message via alert and the user cannot submit the record.
setupDynamicButton
Configures the dynamic button for adding or editing records.
Google Apps Script (GAS)
...COMING SOON...
Variables in GAS People
Sheet name
sheetPeople
Functions and corresponding actions
Note: in the Javascript, you need to mention the action, so that the respective Google Script function is called.- Action: [not needed, it's the get call with parameter.name in automatic used in the fetch call in javascript]
- Function: getDataPeople
- Action: addPeople
- Function: addDataPeople
- Action: editPeople
- Function: editDataPeople
Fields (corresponding to name of columns in G-Sheet)
- timestamp
- person_name
- person_alternative_name
- person_birth_date
- person_birth_place
- person_death_date
- person_death_place
- person_ids
- person_sources
Variables in GAS Activities
Sheet name
sheetActivities
Functions and corresponding actions
Note: in the Javascript, you need to mention the action, so that the respective Google Script function is called.- Action: [not needed, it's the get call with parameter.name in automatic used in the fetch call in javascript]
- Function: getDataActivities
- Action: addActivities
- Function: addDataActivities
- Action: editActivities
- Function: editDataActivities
Fields (corresponding to name of columns in G-Sheet)
- timestamp
- activity_title
- activity_type
- activity_start_date
- activity_end_date
- activity_place
- activity_institution
- activity_instrument_played
- activity_testimonies
- activity_sources
- activity_people_involved
- activity_works_references
Variables in GAS Works
Sheet name
sheetWorks
Functions and corresponding actions
Note: in the Javascript, you need to mention the action, so that the respective Google Script function is called.- Action: [not needed, it's the get call with parameter.name in automatic used in the fetch call in javascript]
- Function: getDataWorks
- Action: addWorks
- Function: addDataWorks
- Action: editWorks
- Function: editDataWorks
Fields (corresponding to name of columns in G-Sheet)
- timestamp
- work_title
- work_type
- work_subtype
- work_people_involved
- work_performance
- work_place
- work_sources
- work_date
Variables in GAS Places
Sheet name
sheetPlaces
Functions and corresponding actions
Note: in the Javascript, you need to mention the action, so that the respective Google Script function is called.- Action: [not needed, it's the get call with parameter.name in automatic used in the fetch call in javascript]
- Function: getDataPlaces
- Action: addPlaces
- Function: addDataPlaces
- Action: editPlaces
- Function: editDataPlaces
Fields (corresponding to name of columns in G-Sheet)
- timestamp
- place_name
- place_country
- place_lat
- place_long
- place_geonames