2019-10-11 01:03:41 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryColumns
|
2020-05-28 18:18:46 +08:00
|
|
|
class StatusColumnsController < RepositoryColumnsController
|
2019-10-11 01:03:41 +08:00
|
|
|
include InputSanitizeHelper
|
|
|
|
|
|
|
|
def create
|
2019-10-16 21:07:46 +08:00
|
|
|
service = RepositoryColumns::CreateColumnService
|
|
|
|
.call(user: current_user, repository: @repository, team: current_team,
|
2019-10-17 22:43:44 +08:00
|
|
|
column_type: Extends::REPOSITORY_DATA_TYPES[:RepositoryStatusValue],
|
|
|
|
params: repository_column_params)
|
2019-10-11 01:03:41 +08:00
|
|
|
|
|
|
|
if service.succeed?
|
2019-11-11 16:04:36 +08:00
|
|
|
render json: service.column, status: :created, creating: true
|
2019-10-11 01:03:41 +08:00
|
|
|
else
|
|
|
|
render json: service.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2019-10-16 21:07:46 +08:00
|
|
|
service = RepositoryColumns::UpdateColumnService
|
2019-10-11 01:03:41 +08:00
|
|
|
.call(user: current_user,
|
|
|
|
team: current_team,
|
|
|
|
column: @repository_column,
|
2019-10-11 15:41:22 +08:00
|
|
|
params: update_repository_column_params)
|
2019-10-11 01:03:41 +08:00
|
|
|
|
|
|
|
if service.succeed?
|
2019-11-11 16:04:36 +08:00
|
|
|
render json: service.column, status: :ok, editing: true
|
2019-10-11 01:03:41 +08:00
|
|
|
else
|
|
|
|
render json: service.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-23 21:34:11 +08:00
|
|
|
def items
|
|
|
|
column_status_items = @repository_column.repository_status_items
|
|
|
|
.where('status ILIKE ?',
|
|
|
|
"%#{search_params[:query]}%")
|
|
|
|
.select(:id, :icon, :status)
|
|
|
|
|
|
|
|
render json: column_status_items
|
|
|
|
.map { |i| { value: i.id, label: "#{i.icon} #{escape_input(i.status)}" } }, status: :ok
|
|
|
|
end
|
|
|
|
|
2019-10-11 01:03:41 +08:00
|
|
|
private
|
|
|
|
|
2019-12-23 21:34:11 +08:00
|
|
|
def search_params
|
2020-06-30 19:44:49 +08:00
|
|
|
params.permit(:query, :repository_id, :id)
|
2019-12-23 21:34:11 +08:00
|
|
|
end
|
|
|
|
|
2019-10-11 15:41:22 +08:00
|
|
|
def repository_column_params
|
|
|
|
params.require(:repository_column).permit(:name, repository_status_items_attributes: %i(status icon))
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_repository_column_params
|
2019-10-17 22:43:44 +08:00
|
|
|
params.require(:repository_column).permit(:name, repository_status_items_attributes: %i(id status icon _destroy))
|
2019-10-11 15:41:22 +08:00
|
|
|
end
|
2019-10-11 01:03:41 +08:00
|
|
|
end
|
|
|
|
end
|