scinote-web/app/controllers/user_repositories_controller.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2017-06-06 23:35:29 +08:00
class UserRepositoriesController < ApplicationController
before_action :load_vars
def save_table_state
2017-06-07 19:36:39 +08:00
table_state = RepositoryTableState.where(user: current_user,
2017-06-06 23:35:29 +08:00
repository: @repository).first
2017-06-07 19:36:39 +08:00
if table_state
table_state.update(state: params[:state])
2017-06-06 23:35:29 +08:00
else
2017-06-07 19:36:39 +08:00
RepositoryTableState.create(user: current_user,
repository: @repository,
state: params[:state])
2017-06-06 23:35:29 +08:00
end
respond_to do |format|
format.json do
render json: {
status: :ok
}
end
end
end
def load_table_state
2017-06-07 19:36:39 +08:00
table_state = RepositoryTableState.load_state(current_user,
@repository).first
2017-06-06 23:35:29 +08:00
respond_to do |format|
if table_state
format.json do
render json: {
state: table_state
}
end
end
end
end
private
def load_vars
@repository = Repository.find_by_id(params[:repository_id])
2017-12-12 21:56:07 +08:00
render_403 if @repository.nil? || !can_read_team?(@repository.team)
2017-06-06 23:35:29 +08:00
end
end