Files
codeocean/app/models/event/synchronized_editor.rb
Sebastian Serth 735a74901f Update ACE Editor to version 1.2.0
Previously, we were at an ACE editor published between 1.1.8 and 1.1.9. This caused multiple issues and was especially a problem for the upcoming pair programming feature. Further, updating ace is a long-time priority, see https://github.com/openHPI/codeocean/issues/250.

Now, we are not yet updating to the latest version, but rather to the next minor version. This already contains breaking changes, and we are currently interested to keep the number of changes as low as possible. Further updating ACE might be still a future task.

The new ACE version 1.2.0 is taken from this tag: https://github.com/ajaxorg/ace-builds/releases/tag/v1.2.0.
We are using the src build (not minified, not in the noconflict version), since the same was used before as well.

Further, we need to change our migration for storing editor events. Since the table is not yet used (in production), we also update the enum.
2023-09-12 16:41:33 +02:00

78 lines
2.7 KiB
Ruby

# frozen_string_literal: true
class Event::SynchronizedEditor < ApplicationRecord
self.table_name = 'events_synchronized_editor'
include Creation
belongs_to :programming_group
belongs_to :study_group
belongs_to :file, class_name: 'CodeOcean::File', optional: true
enum action: {
editor_change: 0,
connection_change: 1,
connection_status: 2,
}, _prefix: true
enum status: {
connected: 0,
disconnected: 1,
}, _prefix: true
enum editor_action: {
insert: 0,
remove: 1,
}, _prefix: true
validates :status, presence: true, if: -> { action_connection_change? }
validates :file_id, presence: true, if: -> { action_editor_change? }
validates :session_id, presence: true, if: -> { action_editor_change? }
validates :editor_action, presence: true, if: -> { action_editor_change? }
validates :range_start_row, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? }
validates :range_start_column, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? }
validates :range_end_row, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? }
validates :range_end_column, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: -> { action_editor_change? }
validates :lines, presence: true, if: -> { action_editor_change? }
def self.create_for_editor_change(event, user, programming_group)
event_copy = event.deep_dup
file = event_copy.delete(:active_file)
delta = event_copy.delete(:delta)
start_range = delta.delete(:start)
end_range = delta.delete(:end)
create!(
user:,
programming_group:,
study_group_id: user.current_study_group_id,
action: event_copy.delete(:action),
editor_action: delta.delete(:action),
file_id: file[:id],
session_id: event_copy.delete(:session_id),
range_start_row: start_range[:row],
range_start_column: start_range[:column],
range_end_row: end_range[:row],
range_end_column: end_range[:column],
lines: delta.delete(:lines),
data: data_attribute(event_copy, delta)
)
end
def self.create_for_connection_change(message, user, programming_group)
create!(
user:,
programming_group:,
study_group_id: user.current_study_group_id,
action: message[:action],
status: message[:status]
)
end
def self.data_attribute(event, delta)
event[:delta] = {data: delta} if delta.present?
event.presence if event.present? # TODO: As of now, we are storing the `session_id` most of the times. Intended?
end
private_class_method :data_attribute
end