mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 17:51:13 +08:00
Merge pull request #7761 from rekonder/aj_SCI_10794
Add state saving for result [SCI-10794]
This commit is contained in:
commit
51717c343e
7 changed files with 48 additions and 12 deletions
|
@ -17,8 +17,8 @@ module Users
|
|||
next unless Extends::WHITELISTED_USER_SETTINGS.include?(key.to_s)
|
||||
|
||||
case key.to_s
|
||||
when 'task_step_states'
|
||||
update_task_step_states(data)
|
||||
when 'task_step_states', 'result_states'
|
||||
update_object_states(data, key.to_s)
|
||||
else
|
||||
current_user.settings[key] = data
|
||||
end
|
||||
|
@ -34,18 +34,18 @@ module Users
|
|||
|
||||
private
|
||||
|
||||
def update_task_step_states(task_step_states_data)
|
||||
current_states = current_user.settings.fetch('task_step_states', {})
|
||||
def update_object_states(object_states_data, object_state_key)
|
||||
current_states = current_user.settings.fetch(object_state_key, {})
|
||||
|
||||
task_step_states_data.each do |step_id, collapsed|
|
||||
object_states_data.each do |object_id, collapsed|
|
||||
if collapsed
|
||||
current_states[step_id] = true
|
||||
current_states[object_id] = true
|
||||
else
|
||||
current_states.delete(step_id)
|
||||
current_states.delete(object_id)
|
||||
end
|
||||
end
|
||||
|
||||
current_user.settings['task_step_states'] = current_states
|
||||
current_user.settings[object_state_key] = current_states
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -158,6 +158,9 @@ export default {
|
|||
resultToReload: { type: Number, required: false },
|
||||
activeDragResult: {
|
||||
required: false
|
||||
},
|
||||
userSettingsUrl: {
|
||||
required: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
@ -215,6 +218,17 @@ export default {
|
|||
deep: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
const resultId = `#resultBody${this.result.id}`;
|
||||
this.isCollapsed = this.result.attributes.collapsed;
|
||||
if (this.isCollapsed) {
|
||||
$(resultId).collapse('hide');
|
||||
} else {
|
||||
$(resultId).collapse('show');
|
||||
}
|
||||
});
|
||||
},
|
||||
computed: {
|
||||
reorderableElements() {
|
||||
return this.orderedElements.map((e) => ({ id: e.id, attributes: e.attributes.orderable }));
|
||||
|
@ -321,6 +335,13 @@ export default {
|
|||
toggleCollapsed() {
|
||||
this.isCollapsed = !this.isCollapsed;
|
||||
this.result.attributes.collapsed = this.isCollapsed;
|
||||
|
||||
const settings = {
|
||||
key: 'result_states',
|
||||
data: { [this.result.id]: this.isCollapsed }
|
||||
};
|
||||
|
||||
axios.put(this.userSettingsUrl, { settings: [settings] });
|
||||
},
|
||||
dragEnter(e) {
|
||||
if (!this.urls.upload_attachment_url) return;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
:result="result"
|
||||
:resultToReload="resultToReload"
|
||||
:activeDragResult="activeDragResult"
|
||||
:userSettingsUrl="userSettingsUrl"
|
||||
@result:elements:loaded="resultToReload = null"
|
||||
@result:move_element="reloadResult"
|
||||
@result:attachments:loaded="resultToReload = null"
|
||||
|
@ -64,7 +65,8 @@ export default {
|
|||
canCreate: { type: String, required: true },
|
||||
archived: { type: String, required: true },
|
||||
active_url: { type: String, required: true },
|
||||
archived_url: { type: String, required: true }
|
||||
archived_url: { type: String, required: true },
|
||||
userSettingsUrl: { type: String, required: false }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -74,10 +76,12 @@ export default {
|
|||
resultToReload: null,
|
||||
nextPageUrl: null,
|
||||
loadingPage: false,
|
||||
activeDragResult: null
|
||||
activeDragResult: null,
|
||||
userSettingsUrl: null
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.userSettingsUrl = document.querySelector('meta[name="user-settings-url"]').getAttribute('content');
|
||||
window.addEventListener('scroll', this.loadResults, false);
|
||||
window.addEventListener('scroll', this.initStackableHeaders, false);
|
||||
this.nextPageUrl = this.url;
|
||||
|
|
|
@ -4,7 +4,9 @@ class CleanupUserSettingsJob < ApplicationJob
|
|||
queue_as :default
|
||||
|
||||
def perform(record_type, record_id)
|
||||
raise ArgumentError, 'Invalid record_type' unless %w(task_step_states results_order).include?(record_type)
|
||||
unless %w(task_step_states results_order result_states).include?(record_type)
|
||||
raise ArgumentError, 'Invalid record_type'
|
||||
end
|
||||
|
||||
sanitized_record_id = record_id.to_i.to_s
|
||||
raise ArgumentError, 'Invalid record_id' unless sanitized_record_id == record_id.to_s
|
||||
|
|
|
@ -37,6 +37,9 @@ class Result < ApplicationRecord
|
|||
accepts_nested_attributes_for :tables
|
||||
|
||||
before_save :ensure_default_name
|
||||
after_discard do
|
||||
CleanupUserSettingsJob.perform_later('result_states', id)
|
||||
end
|
||||
|
||||
def self.search(user,
|
||||
include_archived,
|
||||
|
|
|
@ -10,7 +10,12 @@ class ResultSerializer < ActiveModel::Serializer
|
|||
attributes :name, :id, :urls, :updated_at, :created_at_formatted, :updated_at_formatted, :user,
|
||||
:my_module_id, :attachments_manageble, :marvinjs_enabled, :marvinjs_context, :type,
|
||||
:wopi_enabled, :wopi_context, :created_at, :created_by, :archived, :assets_order,
|
||||
:open_vector_editor_context, :comments_count, :assets_view_mode, :storage_limit
|
||||
:open_vector_editor_context, :comments_count, :assets_view_mode, :storage_limit, :collapsed
|
||||
|
||||
def collapsed
|
||||
result_states = current_user.settings.fetch('result_states', {})
|
||||
result_states[object.id.to_s] == true
|
||||
end
|
||||
|
||||
def marvinjs_enabled
|
||||
MarvinJsService.enabled?
|
||||
|
|
|
@ -675,6 +675,7 @@ class Extends
|
|||
repository_export_file_type
|
||||
navigator_collapsed
|
||||
navigator_width
|
||||
result_states
|
||||
).freeze
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue