NASA-AMMOS / NASA-AMMOS/plandev

Allow user-defined helpers for templating in sequencing-server

Open
#1,646 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Java
Stars
128
Forks
33
Avg merge
1d 17h
Merged PRs (30d)
12

Description

Checked for duplicates

No - I haven't checked

Alternatives considered

No - I haven't considered

Related problems

This request is not related to a specific problem but IS based on a new feature that presently is on its way into develop: Sequence Templates.

Describe the feature request

Presently, sequence templating introduces the notion of 'helpers', which are methods in a sequence template acting on some input (currently limited to simulated activity properties). These can be used to manipulate time strings and print arrays.

It is very possible that more helpers may be desired by missions than just the 4 generic, provided in-AERIE helpers. The purpose of this ticket is to request that it be possible for users to upload their own helpers.

The infrastructure to do so has been figured out (but has been removed from the codebase) - if a user includes a custom helper function (any export function with any name that takes in and returns strings suffice) in a file in ./sequencing-server/src/lib/mustache/user-defined, it will automatically be included in the templating server. However, this would only work if the file is created and included in that folder prior to deploying AERIE locally; there is no easy and straightforward way to upload one of these helper function files and have it be included for future templating, like what is possible with mission model uploads. The agenda this issue seeks to push is that this becomes possible! The implementation that used to exist in sequencing-server/src/lib/mustache/util/index.ts follows:

import * as fs from 'fs';

//... code up until and including in-built AERIE helper registration

// TODO: FIGURE OUT A GOOD WAY TO ALLOW USER UPLOADS/DEFINITION IN AERIE MAIN? Ask about this.
/////////////// USER HELPERS ///////////////
//  Allow the user to provide their own helpers. WORK IN PROGRESS.

// relative to index.ts
const testFolder = './user-defined/';

fs.readdir(testFolder, (err, files) => {
    if (!err) {
        files.forEach(file => {
            if (file.includes(".js")) {
                // relative to mustache.ts
                import("../" + testFolder + file).then((module) => {
                    let moduleName = file.replace(".js", "")
                    let castedFunctions: { [key: string]: any } = module

                    Object.keys(castedFunctions).forEach(funcName => {
                        Handlebars.registerHelper(moduleName + "." + funcName, castedFunctions[funcName])
                    })
                })
            }
        });
    }
});

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with sequencing-server/src/lib/mustache/util/index.ts and the Sequence Templates pull request discussion linked in the issue. Trace how built-in helpers are registered and how mission model uploads are handled. Done means users can upload custom helper files and have their exported string helpers available to future templating without pre-deploying them.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, typescript
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.