Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-7475: Added template for calculator paragraph #475

Merged
merged 57 commits into from
Mar 3, 2023

Conversation

lonkaanna
Copy link
Contributor

@lonkaanna lonkaanna commented Nov 3, 2022

UHF-7475

We need a way to create calculators easily with these things in mind:

  • Should be easy to update values like trigger points or prices of meals and such on a yearly base by instance admin
  • Should be easy to create and validate algorithm of the calculator by a non-drupal javascript coder
    • Should be easy to run the calculator even without drupal on local machine
  • Calculators should be language supported, but translation should stay near the code as they both change likely at the same time
  • Should follow hds.hel.fi styles
  • Should be lightweight
  • Easy to add to pages as a paragraph in Drupal

What was done

  • We created a setup page for updating settings of calculators by instance admin
    • The setup page contains 7 initial calculators, option to enable each (disabled by default) and settings textarea for each
  • We added a paragraph type that updates its contents based on the enabled calculators
    • It contains normal component title and description and a dropdown with enabled calculators
    • If a calculator is disabled by admin after it's being used on a page, it will return to special "disabled" state and whole paragraph will not render, but its contents will stay for the editor to see
  • We created a base js library for handling most of the repeating form building and validating tasks helfi_calculator.js.
  • We created 3 javascript files for 3 calculators as a proof of concept with the current "old" calculator design
    • One of them contains the actual algorithm in use today
    • Two others contain basic form inputs, and basic validation for those, but no algorithm to calculate anything as the old algorithms were horrible and due for update.

How to install

  • Make sure your instance is up and running on latest dev branch.
    • git pull origin dev
    • make fresh
  • Update the HDBT theme
    • composer require drupal/hdbt:dev-UHF-7029-helfi-calculator
  • Enable calculator module: drush en helfi_calculator
  • Add calculator paragraph to upper and lower content area in /admin/structure/types/manage/page/fields
  • Enable daycare calculator from /admin/tools/calculator-settings
  • run in hdbt: nvm use; npm i; npm run build
  • Run make drush-cr

How to test

  • Open the calculator settings page for example: https://helfi-etusivu.docker.so/fi/admin/tools/calculator-settings
  • Enable these calculators (or all of them, the others will not render as of now)
    • House cleaning service voucher
    • Home care service voucher
    • Home care client payment
  • Add this JSON to House cleaning service voucher textarea:
    {
      "household_size_1": {
        "first_level": {
          "value": 24,
          "max_allowed_income": 1138
        },
        "second_level": {
          "value": 21,
          "max_allowed_income": 1422
        }
      },
      "household_size_2": {
        "first_level": {
          "value": 24,
          "max_allowed_income": 1575
        },
        "second_level": {
          "value": 21,
          "max_allowed_income": 2107
        }
      }
    }
  • Create a new page, add the three calculators in separate paragraphs on it
  • Check that calculators work, the cleaning service voucher calculates and concept is solid
  • Check that code follows our standards

Designers review

  • This PR does not need designers review as it's a poc of feasibility, not style (it has been shown to designers tho)

Other PRs

@lonkaanna lonkaanna marked this pull request as draft November 3, 2022 12:11
@Arkkimaagi Arkkimaagi changed the title UHF-7029: Added template for calculator paragraph UHF-7475: Added template for calculator paragraph Nov 11, 2022
Anna Lonka and others added 25 commits February 17, 2023 15:27
…lt + added children, add common way to show errors
@Arkkimaagi Arkkimaagi marked this pull request as ready for review March 3, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants