mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Updating repository table state of every user belonging to the team of the repository, when custom column is removed or added. [SCI-1384]
This commit is contained in:
parent
14429a270c
commit
6c7987681c
1 changed files with 29 additions and 27 deletions
|
@ -14,12 +14,12 @@ class RepositoryTableState < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_state(custom_column, column_index, user)
|
def self.update_state(custom_column, column_index, user)
|
||||||
table_state = RepositoryTableState.where(
|
# table state of every user having access to this repository needs udpating
|
||||||
user: user,
|
table_states = RepositoryTableState.where(
|
||||||
repository: custom_column.repository
|
repository: custom_column.repository
|
||||||
)
|
)
|
||||||
return if table_state.empty?
|
table_states.each do |table_state|
|
||||||
repository_state = table_state.first['state']
|
repository_state = table_state['state']
|
||||||
if column_index
|
if column_index
|
||||||
# delete column
|
# delete column
|
||||||
repository_state['columns'].delete(column_index)
|
repository_state['columns'].delete(column_index)
|
||||||
|
@ -31,6 +31,7 @@ class RepositoryTableState < ActiveRecord::Base
|
||||||
index
|
index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
repository_state['ColReorder'].delete(column_index)
|
repository_state['ColReorder'].delete(column_index)
|
||||||
repository_state['ColReorder'].map! do |index|
|
repository_state['ColReorder'].map! do |index|
|
||||||
if index.to_i > column_index.to_i
|
if index.to_i > column_index.to_i
|
||||||
|
@ -46,7 +47,8 @@ class RepositoryTableState < ActiveRecord::Base
|
||||||
REPOSITORY_TABLE_DEFAULT_STATE['columns'].first
|
REPOSITORY_TABLE_DEFAULT_STATE['columns'].first
|
||||||
repository_state['ColReorder'].insert(2, index)
|
repository_state['ColReorder'].insert(2, index)
|
||||||
end
|
end
|
||||||
table_state.first.update(state: repository_state)
|
table_state.update(state: repository_state)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_state(user, repository)
|
def self.create_state(user, repository)
|
||||||
|
|
Loading…
Add table
Reference in a new issue