---
include:
  - nav.yml
---
modules:
  - .aldashboard  
---
metadata:
  title: Bulk Package Update
  sessions are unique: True
  required privileges:
    - admin
    - developer
  temporary session: True
---
objects:
  - packages: DAList.using(object_type=DAObject, there_are_any=True, complete_attribute="package_name")
---
code: |
  installed_packages = get_package_info()
---
mandatory: True
id: interview order
code: |
  packages.gather()
  if install_packages_task.ready():
    ending_screen
  else:
    waiting_screen
---
question: |
  What packages do you want to update?
fields:
  - no label: packages
    required: False
    datatype: checkboxes
    code: |
      [
        package.package.name
        for package in installed_packages[0]
        if (
          package.package.name.startswith("docassemble")
          and package.can_update
          and package.package.name not in ["docassemble", "docassemble-backports", "docassemble.webapp", "docassemble-textstat", "docassemblekvsession"]
        )
      ]
---
code: |
  install_packages_task = background_action('install_packages_event')
---
event: install_packages_event
code: |
  background_error_action("bg_failure")
  for package in installed_packages[0]:
    if package.package.name in packages.true_values():
      if package.package.type and package.package.type == "git":
        pkgname = install_from_github_url(package.package.giturl)
        reset(pkgname)
      elif package.package.type and package.package.type == "pip":
        install_from_pypi(package.package.name)
  background_response_action("bg_success")
---
event: bg_success
code: |
  it_worked = True
  background_response()
---  
event: waiting_screen
question: |
  Wait here while we start the installation process
reload: True
---
event: bg_failure
code: |
  it_worked = False
  background_response()
---
event: ending_screen
question: |
  Your packages are installing
subquestion: |
  % if it_worked:
  Check the log file to monitor progress. It may still take a few more minutes
  for the installation process to complete.
  % else:
  Something went wrong. Check the [worker.log](/logs?file=worker.log) to learn what.
  % endif
buttons:
  - Restart: restart