This project is a Google Apps Script-based management system for the Caving Crew. It provides various functionalities to manage events, participants, and generate reports.
The project consists of several JavaScript files, each responsible for different aspects of the system:
Admin.js
: Handles administrative data retrieval and display.Buddy.js
: Manages buddy system information.CommonFunctions.js
: Contains shared utility functions and configurations.Diet.js
: Handles dietary information for participants.Event List.js
: Manages the list of events.EveryoneFunctions.js
: Contains functions that apply to all participants.Gear.js
: Manages gear-related information.MarkAttendance.js
: Handles attendance marking functionality.Menu.js
: Creates the custom menu in the Google Sheets UI.pokeToWordPress.js
: Manages communication with WordPress.Transport.js
: Handles transportation-related information.Volunteering.js
: Manages volunteering-related data.Weekends.js
: Contains functions for weekend events.
The eventListing()
function in Event List.js
retrieves a list of all 'Pending' trips from the Caving Crew website server and populates it into the Event Listing spreadsheet. It includes columns for Trip Name, ID, and Date.
The MarkAttendance.js
file contains functions to mark different attendance statuses:
markAttended()
: Marks a participant as attended.markCancelled()
: Marks a participant as cancelled.markNoShow()
: Marks a participant as a no-show.markDuplicate()
: Marks a participant's entry as a duplicate.markLateBail()
: Marks a participant as a late bail.
These functions update both the Google Sheet and the WordPress database via API calls.
Various reports are generated using SQL queries to retrieve specific information:
-
Admin Report (
Admin.js
):- Columns: First Name, Last Name, Facebook Name, Phone Number, Participation Statements, Car Registration, Emergency Contact Details, Order ID
-
Buddy Report (
Buddy.js
):- Columns: First Name, Facebook Name, First Timer status, Order Count, Order ID
-
Diet Report (
Diet.js
):- Columns: First Name, Facebook Name, Dietary Requirements, Diet and Health Details, Order ID
-
Gear Report (
Gear.js
):- Columns: First Name, Facebook Name, various skill levels and preferences, kit information
-
Transport Report (
Transport.js
):- Columns: First Name, Facebook Name, Lift Needs/Offers, Departure Location and Time, Order ID
-
Volunteering Report (
Volunteering.js
):- Columns: First Name, Facebook Name, Selected Roles, various volunteering positions, experience metrics
The CommonFunctions.js
file contains shared utility functions, database connection details, and color definitions used throughout the project. It includes functions for setting up sheets, formatting cells, and handling conditional formatting.
This project uses clasp
(Command Line Apps Script Projects) for deployment and management. The package.json
file includes several scripts for common operations:
npm run push
: Deploys the local files to Google Apps Script. This is how you update the live script.npm run pull
: Fetches the latest version from Google Apps Script to your local environment.npm run watch
: Watches for local changes and automatically pushes them to Google Apps Script.npm run version
: Creates a new version of the Google Apps Script project.npm run logs
: Shows the most recent logs from the Google Apps Script project.
To use these commands, make sure you have Node.js and npm installed, then run npm install
in the project directory to install the necessary dependencies.
The system integrates with WordPress using the WooCommerce REST API. The pokeToWordPress.js
file contains functions to communicate with the WordPress site, updating order statuses and user metadata. This integration allows for seamless data flow between the Google Sheet interface and the WordPress-based website.
The Menu.js
file creates a custom menu in the Google Sheets UI, providing easy access to various functions like marking attendance and refreshing data. This enhances the user experience by making key functions readily available within the spreadsheet interface.
When contributing to or maintaining this project, please ensure to update the relevant JavaScript files and test thoroughly before deploying. The clasp
commands make it easy to manage versions and deployments, but care should be taken to avoid disrupting the live system.
The CredentialStoreManager.js
file is responsible for securely managing and refreshing credentials used throughout the application. Here's a detailed explanation of its functionality:
This function fetches credentials from a specific Google Sheets document and stores them in the script's properties. Here's how it works:
- It opens a specific Google Sheet (ID: '1MVTO45ZusIw2BRgtRh4BffPRbbuIZHViZKPZE3OntEc') and accesses the 'Credentials' sheet.
- It reads all the data from this sheet, expecting two columns: 'label' and 'value'.
- For each row in the sheet, it stores the 'value' in the script's properties, using 'cred_[label]' as the key.
This approach allows for centralized credential management, making it easy to update credentials without changing the code.
This function sets up an automatic nightly refresh of the credentials:
- It first removes any existing triggers for the
refreshCredentials
function. - It then creates a new trigger that runs
refreshCredentials
every day at 1:00 AM.
This ensures that the credentials are always up-to-date, even if they're changed in the source spreadsheet.
This function is meant to be run once to initialize the credential management system:
- It calls
refreshCredentials()
to immediately fetch and store the credentials. - It then calls
createNightlyTrigger()
to set up the automatic nightly refresh.
To use this system, a developer would run setupCredentialRefresh()
once, and then the credentials will be automatically managed from that point forward.
The eventSpaceManager.js
file handles the opening and closing of event spaces (i.e., available slots for an event). It's designed to work with both simple and variable products in WooCommerce. Here's a breakdown of its main functions:
This is the main function for opening event spaces:
- It fetches the product ID from a specific cell in the 'Dashboard' sheet.
- It then retrieves the product details from WooCommerce.
- Depending on whether the product is simple or variable, it calls either
openSimpleProductSpaces()
oropenVariableProductSpaces()
.
This function handles opening spaces for variable products (e.g., events with different ticket types):
- It fetches all variations of the product from WooCommerce.
- It creates an HTML form with input fields for each variation, allowing the user to set the number of spaces for each.
- When the form is submitted, it calls
updateProductVariations()
to update the stock quantity for each variation in WooCommerce.
This function handles opening spaces for simple products:
- It prompts the user to enter the number of spaces to open.
- If a valid number is entered, it calls
updateProductStock()
to update the stock quantity in WooCommerce.
This function closes the signup for an event:
- It fetches the product ID from the 'Dashboard' sheet.
- Depending on whether the product is simple or variable, it calls either
closeSimpleProductSpaces()
orcloseVariableProductSpaces()
. - Both of these functions set the stock quantity to 0 for all variations or for the simple product.
These functions make API calls to WooCommerce to update the stock quantities for variable and simple products respectively.
To use this system, a user would typically:
- Select the event in the 'Dashboard' sheet.
- Use the custom menu to run either 'Open Signup' (which calls
openEventSpaces()
) or 'Close Signup' (which callscloseSignup()
).
This system provides a user-friendly interface for managing event capacities directly from Google Sheets, with the changes being reflected immediately in the WooCommerce store.