<commit_before># frozen_string_literal: true

module Dashboard
  class CurrentTasksController < ApplicationController
    include InputSanitizeHelper

    before_action :load_project, only: %i(show experiment_filter)
    before_action :load_experiment, only: :show
    before_action :check_task_view_permissions, only: :show

    def show
      tasks = if @experiment
                @experiment.my_modules.active
              elsif @project
                MyModule.active.where(projects: { id: @project.id })
              else
                MyModule.active.viewable_by_user(current_user, current_team)
              end

      tasks = tasks.joins(experiment: :project)
                   .where(experiments: { archived: false })
                   .where(projects: { archived: false })

      if task_filters[:mode] == 'assigned'
        tasks = tasks.left_outer_joins(:user_my_modules).where(user_my_modules: { user_id: current_user.id })
      end
      tasks = tasks.where(my_modules: { state: task_filters[:view] })
                   .search_by_name(current_user, current_team, task_filters[:query])

      case task_filters[:sort]
      when 'date_desc'
        tasks = tasks.order('my_modules.due_date': :desc)
      when 'date_asc'
        tasks = tasks.order('my_modules.due_date': :asc)
      when 'atoz'
        tasks = tasks.order('my_modules.name': :asc)
      when 'ztoa'
        tasks = tasks.order('my_modules.name': :desc)
      else
        tasks
      end

      page = (params[:page] || 1).to_i
      tasks = tasks.with_step_statistics.preload(experiment: :project).page(page).per(Constants::INFINITE_SCROLL_LIMIT)

      tasks_list = tasks.map do |task|
        { id: task.id,
          link: protocols_my_module_path(task.id),
          experiment: escape_input(task.experiment.name),
          project: escape_input(task.experiment.project.name),
          name: escape_input(task.name),
          due_date: task.due_date.present? ? I18n.l(task.due_date, format: :full_date) : nil,
          overdue: task.is_overdue?,
          state: task.state,
          steps_state: { completed_steps: task.steps_completed,
                         all_steps: task.steps_total,
                         percentage: task.steps_completed_percentage } }<commit_msg>Add alphabetical order for tasks without due date<commit_after># frozen_string_literal: true

module Dashboard
  class CurrentTasksController < ApplicationController
    include InputSanitizeHelper

    before_action :load_project, only: %i(show experiment_filter)
    before_action :load_experiment, only: :show
    before_action :check_task_view_permissions, only: :show

    def show
      tasks = if @experiment
                @experiment.my_modules.active
              elsif @project
                MyModule.active.where(projects: { id: @project.id })
              else
                MyModule.active.viewable_by_user(current_user, current_team)
              end

      tasks = tasks.joins(experiment: :project)
                   .where(experiments: { archived: false })
                   .where(projects: { archived: false })

      if task_filters[:mode] == 'assigned'
        tasks = tasks.left_outer_joins(:user_my_modules).where(user_my_modules: { user_id: current_user.id })
      end
      tasks = tasks.where(my_modules: { state: task_filters[:view] })
                   .search_by_name(current_user, current_team, task_filters[:query])

      case task_filters[:sort]
      when 'date_desc'
        tasks = tasks.order('my_modules.due_date': :desc).order('my_modules.name': :asc)
      when 'date_asc'
        tasks = tasks.order('my_modules.due_date': :asc).order('my_modules.name': :asc)
      when 'atoz'
        tasks = tasks.order('my_modules.name': :asc)
      when 'ztoa'
        tasks = tasks.order('my_modules.name': :desc)
      else
        tasks
      end

      page = (params[:page] || 1).to_i
      tasks = tasks.with_step_statistics.preload(experiment: :project).page(page).per(Constants::INFINITE_SCROLL_LIMIT)

      tasks_list = tasks.map do |task|
        { id: task.id,
          link: protocols_my_module_path(task.id),
          experiment: escape_input(task.experiment.name),
          project: escape_input(task.experiment.project.name),
          name: escape_input(task.name),
          due_date: task.due_date.present? ? I18n.l(task.due_date, format: :full_date) : nil,
          overdue: task.is_overdue?,
          state: task.state,
          steps_state: { completed_steps: task.steps_completed,
                         all_steps: task.steps_total,
                         percentage: task.steps_completed_percentage } }
{'fraction_non_alphanumeric': 0.10438144329896908, 'fraction_numerical': 0.001288659793814433, 'mean_word_length': 2.5333839150227617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6738732', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1370, 'n_words': 257}