# frozen_string_literal: true

Redmine::Plugin.register :redmine_ux_toolkit do
  name 'Redmine UX Toolkit'
  author 'www.SaaS-Secure.com, S. Ruttloff'
  author_url 'https://www.saas-secure.com'
  description 'UX and productivity toolkit for Redmine.'
  version '4.4.9'
  requires_redmine :version_or_higher => '6.0.0'

  settings(
    default: {
      'global_landing_page_type' => '',
      'global_landing_page_value' => '',
      'allow_user_landing_page_override' => '1',
      'login_notice_text' => '',
      'global_new_issue_notice_text' => '',
      'recent_issues_limit' => '10',
      'recent_projects_limit' => '10',
      'show_recent_issues_in_sidebar' => '1',
      'show_recent_projects_in_sidebar' => '1',
      'enable_assign_to_me_button' => '1',
      'enable_assign_to_me_and_start_button' => '0',
      'assign_to_me_and_start_status_id' => '',
      'enable_quick_status_actions' => '0',
      'quick_status_action_status_ids' => [],
      'enable_checklists' => '1',
      'prevent_closing_with_open_checklist_items' => '0',
      'prevent_closing_with_open_subtasks' => '0',
      'auto_watch_issue_author' => '0',
      'auto_watch_issue_commenters' => '0',
      'enable_issue_quality_check' => '0',
      'issue_quality_check_subject_short' => '1',
      'issue_quality_check_description_empty' => '1',
      'issue_quality_check_description_short' => '1',
      'issue_quality_check_assignee_missing' => '1',
      'issue_quality_check_priority_missing' => '1',
      'issue_quality_min_subject_length' => '8',
      'issue_quality_min_description_length' => '30',
      'enable_sla_light' => '0',
      'sla_light_first_response_hours' => '8',
      'sla_light_resolution_hours' => '72',
      'sla_light_pause_status_ids' => [],
      'enable_repository_refresh_scheduler' => '1',
      'repository_refresh_default_interval_minutes' => '1440',
      'repository_refresh_max_per_run' => '1',
      'repository_refresh_max_runtime_seconds' => '300',
      'repository_refresh_failure_backoff' => '1',
      'enable_attachment_trash' => '0',
      'attachment_trash_retention_days' => '30',
      'attachment_trash_cleanup_limit' => '50',
      'attachment_preview_enabled' => '1',
      'attachment_preview_images' => '1',
      'attachment_preview_pdfs' => '1',
      'attachment_preview_gallery' => '1',
      'attachment_preview_download' => '1',
      'modern_ui_enabled' => '0',
      'modern_ui_base' => '1',
      'modern_ui_header' => '1',
      'modern_ui_navigation' => '1',
      'modern_ui_issue_list' => '1',
      'modern_ui_issue_detail' => '1',
      'modern_ui_forms' => '1',
      'modern_ui_filters' => '1',
      'modern_ui_project_overview' => '0',
      'modern_ui_roadmap' => '0',
      'modern_ui_activity' => '0',
      'modern_ui_wiki' => '0',
      'modern_ui_repository' => '0',
      'modern_ui_login' => '1',
      'modern_ui_admin' => '0',
      'modern_ui_density' => 'comfortable',
      'modern_ui_color_preset' => 'redmine_modern',
      'enable_issue_reminder_emails' => '0',
      'issue_reminder_send_time' => '07:30',
      'issue_reminder_time_zone' => '',
      'issue_reminder_weekdays' => ['1', '2', '3', '4', '5'],
      'issue_reminder_days_before_due' => '7',
      'helpdesk_mail_fetch_interval_minutes' => '60',
      'cron_monitoring_interval' => '4_hours',
      'cron_monitoring_email' => '',
      'show_my_work_top_menu' => '0',
      'secure_external_links' => '1',
      'stale_issue_days' => '14',
      'visible_navigation_links' => [
        'home',
        'my_page',
        'projects',
        'help',
        'administration',
        'my_account',
        'my_work'
      ],
      'default_my_work_dashboard_blocks' => [
        'assigned_to_me',
        'due_today',
        'overdue',
        'due_soon',
        'favorite_projects',
        'favorite_queries',
        'recent_issues',
        'recent_projects'
      ]
    },
    partial: 'settings/redmine_ux_toolkit'
  )

  menu :top_menu,
       :ux_toolkit_my_work,
       {controller: 'ux_toolkit_my_work', action: 'index'},
       caption: :label_ux_toolkit_my_work,
       icon: 'user',
       html: {class: 'ux-toolkit-my-work-top-menu'},
       if: proc {
         settings = Setting.plugin_redmine_ux_toolkit || {}

         User.current.logged? &&
           settings.fetch('show_my_work_top_menu', '0').to_s == '1' &&
           RedmineUxToolkit::Services::NavigationLinks.visible?(:ux_toolkit_my_work, settings)
       }

  menu :admin_menu,
       :redmine_ux_toolkit,
       {controller: 'settings', action: 'plugin', id: 'redmine_ux_toolkit'},
       caption: :label_redmine_ux_toolkit,
       icon: 'settings'

  project_module :redmine_ux_toolkit do
    permission :view_ux_toolkit_checklists, {}
    permission :edit_ux_toolkit_checklists, {}
    permission :manage_ux_toolkit_checklist_templates, {}
    permission :view_ux_toolkit_team_workload, {
      ux_toolkit_team_workload: [:index]
    }, read: true
    permission :view_ux_toolkit_project_health, {
      ux_toolkit_project_health: [:index]
    }, read: true
    permission :manage_ux_toolkit_recurring_issues, {
      ux_toolkit_recurring_issue_rules: [:index, :new, :create, :edit, :update, :destroy]
    }
  end

  menu :project_menu,
       :ux_toolkit_team_workload,
       {controller: 'ux_toolkit_team_workload', action: 'index'},
       caption: :label_ux_toolkit_team_workload,
       after: :issues,
       param: :project_id,
       if: proc {|project| User.current.allowed_to?(:view_ux_toolkit_team_workload, project)}

  menu :project_menu,
       :ux_toolkit_project_health,
       {controller: 'ux_toolkit_project_health', action: 'index'},
       caption: :label_ux_toolkit_project_health,
       after: :ux_toolkit_team_workload,
       if: proc {|project| User.current.allowed_to?(:view_ux_toolkit_project_health, project)}
end

require_relative 'lib/redmine_ux_toolkit'
