From 503c05805d124b49d6153e8f630dd40c9b97a925 Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Sat, 25 Jan 2020 09:43:05 +0100 Subject: [PATCH] Move editable? method from helper to model --- app/helpers/repository_datatable_helper.rb | 6 +----- app/models/repository_row.rb | 4 ++++ app/services/repository_datatable_service.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/helpers/repository_datatable_helper.rb b/app/helpers/repository_datatable_helper.rb index c925784cb..95f2006ee 100644 --- a/app/helpers/repository_datatable_helper.rb +++ b/app/helpers/repository_datatable_helper.rb @@ -29,7 +29,7 @@ module RepositoryDatatableHelper ), 'recordInfoUrl': Rails.application.routes.url_helpers .repository_row_path(record.id), - 'recordEditable': record_editable + 'recordEditable': record.editable? } # Add custom columns @@ -75,10 +75,6 @@ module RepositoryDatatableHelper Constants::REPOSITORY_TABLE_DEFAULT_STATE['columns'].to_json end - def record_editable - true - end - def display_cell_value(cell, team) value_name = cell.repository_column.data_type.underscore serializer_class = "RepositoryDatatable::#{cell.repository_column.data_type}Serializer".constantize diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index 6fb472b51..eb87cbf7b 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -37,4 +37,8 @@ class RepositoryRow < ApplicationRecord .where('repositories.team_id = ? and repository_rows.created_by_id = ?', team, user) .update_all(created_by_id: new_owner.id) end + + def editable? + true + end end diff --git a/app/services/repository_datatable_service.rb b/app/services/repository_datatable_service.rb index b6ee3c154..415f6ecf6 100644 --- a/app/services/repository_datatable_service.rb +++ b/app/services/repository_datatable_service.rb @@ -52,7 +52,7 @@ class RepositoryDatatableService .select('COUNT(DISTINCT my_modules.experiment_id) AS "assigned_experiments_count"') .select('COUNT(DISTINCT experiments.project_id) AS "assigned_projects_count"') end - repository_rows.preload(Extends::REPOSITORY_ROWS_PRELOAD_RELATIONS) + repository_rows = repository_rows.preload(Extends::REPOSITORY_ROWS_PRELOAD_RELATIONS) @repository_rows = sort_rows(order_obj, repository_rows) end