SciNote Electronic Lab Notebook (ELN)

repository·develop·Indexed 43 days ago

https://github.com/scinote-eln/scinote-web

An open source electronic lab notebook designed for life science researchers to manage laboratory work and experimental data. The web application is built with Ruby on Rails and includes a plugin system for addons, a Docker-based development environment, and specialized tools for report template population and frontend asset management using Webpack and Tailwind CSS.

Tokens
3.5K
Snippets
13
Records
15
Agent score
55%

What's inside SciNote

  1. Handle and render server-side errors

    develop

    When the server returns an error (distinct from standard input validation errors, such as unexpected system failures), follow these UI patterns:

    1. Within a Form: Display the error as general form error feedback within the form's UI.
    2. Outside a Form: Display the error using a flash message.
      • Important: If the error occurs inside a modal window, you MUST close the modal before showing the flash message to ensure the user actually sees it.
  2. Implement form validation using validation components

    develop

    For generic forms, use the built-in validation components to handle input validation on both the front-end and back-end.

    To link validation logic to a specific data field, provide the same tag property to all related elements (e.g., inputs and error displays). Attach the relevant validators to the <InputFormControl> component.

    Key features:

    • <ValidatedSubmitButton>: Automatically disables itself as soon as any error is detected in the form.
    • Custom Validators: You can define additional validators as JavaScript functions that receive target (the input element reference) and messageIds. These functions must return an array of error objects (JSON objects that support localization).

    To interact with the form instance from a parent/hosting component, use the ref mechanism to capture the form instance.

    // Accessing the form instance from a hosting component
    <ValidatedForm ref={(f) => { this.myForm = f; }}>
  3. Include a SciNote addon in the main application

    develop

    To integrate a SciNote addon into the main application, you must register the gem, mount the engine in the routes, and include the addon's assets.

    1. Register the Gem

    Add the addon to your Gemfile using a path reference:

    gem '${FULL_UNDERSCORE_NAME}',
        path: 'addons/${ADDON_NAME}'

    2. Mount the Engine

    In config/routes.rb, mount the addon's engine at the root path:

    mount ${NAME}::Engine => '/'

    3. Include Assets

    If the addon contains specific JavaScript or CSS, include them in the main application asset files:

    • JavaScript: Add to app/assets/javascripts/application.js.erb:

      //= require ${FOLDERS_PATH}
    • CSS: Add to the starting comment of app/assets/stylesheets/application.scss:

      *= require ${FOLDERS_PATH}/application

    4. Finalize Setup

    After updating the configuration, run the following commands to apply changes:

    1. make docker
    2. make cli -> rake db:migrate
    3. (Optional) Configure any addon-specific initializers or settings.
    4. Start the application using make run.
  4. Configure the gemspec for a SciNote addon

    develop

    When building a SciNote addon or plugin, use this .gemspec template to define the gem's identity and dependencies. The template uses placeholders that must be replaced during the generation process.

    Required Placeholders

    • ${FULL_UNDERSCORE_NAME}: The full name of the gem using underscores.
    • ${FOLDERS_PATH}: The path to the directory containing the version file.
    • ${NAME}: The module name used to access the version constant.

    Standard Dependencies

    Addons typically depend on:

    • rails (~> 4.2.5)
    • deface (~> 1.0)

    File Structure

    The gemspec expects the following files to be included in the gem:

    • Directories: app/, config/, db/, lib/
    • Files: LICENSE.txt, Rakefile, README.rdoc
    • Test files: All files within the test/ directory.
    Gem::Specification.new do |s|
      s.name        = '${FULL_UNDERSCORE_NAME}'
      s.version     = ${NAME}::VERSION
      s.authors     = ['']
      s.email       = ['']
      s.homepage    = ''
      s.summary     = ''
      s.description = ''
      s.license     = ''
    
      s.files = Dir['{app,config,db,lib}/**/*', 'LICENSE.txt', 'Rakefile', 'README.rdoc']
      s.test_files = Dir['test/**/*']
    
      s.add_dependency 'rails', '~> 4.2.5'
      s.add_dependency 'deface', '~> 1.0'
    end
  5. Run SciNote development environment with Docker Compose

    develop
    The docker-compose.yml file defines a multi-service development environment for SciNote. To run the full stack, you can use docker-compose up. The environment consists of a PostgreSQL database, a Rails web server, a Webpack watcher for assets, a CSS bundler, and a Tailwind CSS watcher.
    docker-compose up
  6. Set up the development environment with bin/setup

    develop

    The bin/setup script automates the installation of dependencies and the preparation of the development environment. It is designed to be idempotent, meaning it can be run multiple times to ensure the environment is in the expected state without causing errors.

    ./bin/setup
  7. Automated setup steps performed by bin/setup

    develop

    When executed, bin/setup performs the following sequence of operations:

    1. Dependency Installation: Installs bundler (using --conservative) and runs bundle install if dependencies are not already satisfied.
    2. Database Preparation: Runs bin/rails db:prepare to set up the database schema.
    3. Cleanup: Clears old logs and temporary files using bin/rails log:clear tmp:clear.
    4. Server Restart: Restarts the application server using bin/rails restart.
  8. Configure ESLint for SciNote Web

    develop

    The project uses the ESLint Flat Config format (eslint.config.mjs). The configuration includes support for Vue files, Airbnb style guidelines, and specific global variables.

    Key configuration details:

    • Global Ignores: node_modules, ./app/assets/builds/**, and ./public/ are excluded from linting.
    • Supported Environments: Browser, Node.js, and ES6 globals are enabled.
    • Custom Globals: jquery and _ (underscore) are explicitly defined as global variables.
    • Vue Support: Uses vue-eslint-parser for .vue files.
    • Style Guidelines: Extends airbnb and plugin:vue/base via FlatCompat.
    import { defineConfig, globalIgnores } from 'eslint/config';
    
    export default defineConfig([
      globalIgnores(['node_modules', './app/assets/builds/**', './public/']),
      // ... other configurations
    ]);
  9. Configure the SciNote PostgreSQL database service

    develop

    The db service uses the postgres:18 image. You can configure the database credentials using the following environment variables:

    • POSTGRES_USER: The username for the database (defaults to postgres).
    • POSTGRES_PASSWORD: The password for the database (defaults to mysecretpassword).

    Data is persisted in the scinote_development_postgres volume at /var/lib/postgresql/18/docker inside the container.

    services:
      db:
        image: postgres:18
        environment:
          - "POSTGRES_USER=postgres"
          - "POSTGRES_PASSWORD=mysecretpassword"
        volumes:
          - scinote_development_postgres:/var/lib/postgresql/18/docker
  10. Configure the SciNote web service

    develop

    The web service runs the Rails application. It is configured with the following settings:

    • Port Mapping: Maps host port 3000 to container port 3000.
    • Environment: Sets RAILS_ENV=development.
    • Startup Command: Automatically removes existing server PIDs, checks/installs Ruby gems via bundle, and starts the Rails server on 0.0.0.0.
    • Volumes:
      • Mounts the current directory to /usr/src/app for live code reloading.
      • Uses scinote_development_bundler for Ruby gems.
      • Uses scinote_development_storage for application storage.
    services:
      web:
        ports:
          - "3000:3000"
        environment:
          - RAILS_ENV=development
        command: >
          bash -c "rm -f /usr/src/app/tmp/pids/server.pid &&
                   (bundle check || bundle install) &&
                   bundle exec rails s -b 0.0.0.0"
  11. Manage frontend assets with Webpack, CSS, and Tailwind services

    develop

    SciNote uses several specialized services to handle frontend asset compilation in development mode:

    Webpack

    Runs yarn install and yarn build --watch to compile JavaScript assets. Sets NODE_ENV=development.

    CSS Bundling

    Runs yarn build:css --watch to compile CSS assets. Sets NODE_ENV=development.

    Tailwind

    Runs rails tailwindcss:watch to monitor and compile Tailwind CSS classes. Sets both RAILS_ENV=development and NODE_ENV=development.

    services:
      webpack:
        command: >
          bash -c "yarn install && yarn build --watch"
        environment:
          - NODE_ENV=development
    
      css_bundling:
        command: >
          bash -c "yarn build:css --watch"
        environment:
          - NODE_ENV=development
    
      tailwind:
        command: >
          bash -c "rails tailwindcss:watch"
        environment:
          - RAILS_ENV=development
          - NODE_ENV=development
  12. Reference: ESLint Rules and Settings

    develop

    The following custom rules and settings are applied in the SciNote Web ESLint configuration:

    rules: {
      'import/extensions': 'off',
      'import/no-unresolved': 'off',
      'spaced-comment': [
        'error',
        'always',
        {
          markers: ['=']
        }
      ],
      'lines-around-comment': [
        'warn',
        {
          beforeLineComment: false
        }
      ],
      'max-len': [
        'error',
        {
          code: 180
        }
      ],
      'vue/max-len': [
        'error',
        {
          code: 180,
          template: 240,
          tabWidth: 2
        }
      ],
      'comma-dangle': ['error', 'never'],
      'vue/no-v-html': 'warn'
    }