Merge pull request #4148 from aignatov-bio/ai-sci-6870-finalize-protocol-repository

Finalize protocol repository [SCI-6870]
This commit is contained in:
aignatov-bio 2022-06-07 15:11:40 +02:00 committed by GitHub
commit 2cb5d44109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 51 additions and 21 deletions

View file

@ -16,7 +16,6 @@ function init() {
initKeywordFiltering(); initKeywordFiltering();
initProtocolPreviewModal(); initProtocolPreviewModal();
initLinkedChildrenModal(); initLinkedChildrenModal();
initCreateNewModal();
initModals(); initModals();
initImport(); initImport();
} }

View file

@ -7,6 +7,7 @@
.content-pane.protocols-show { .content-pane.protocols-show {
background-color: $color-alto; background-color: $color-alto;
margin: 0 -16px; margin: 0 -16px;
min-height: calc(100vh - var(--navbar-height));
overflow: hidden; overflow: hidden;
padding: 36px 10px 10px; padding: 36px 10px 10px;
width: calc(100% + 31px); width: calc(100% + 31px);

View file

@ -35,8 +35,10 @@ module StepElements
end end
def log_step_activity(element_type_of, message_items) def log_step_activity(element_type_of, message_items)
message_items[:my_module] = @protocol.my_module.id if @protocol.in_module?
Activities::CreateActivityService.call( Activities::CreateActivityService.call(
activity_type: "#{@step.protocol.in_module? ? 'protocol_step_' : 'task_step_'}#{element_type_of}", activity_type: "#{!@step.protocol.in_module? ? 'protocol_step_' : 'task_step_'}#{element_type_of}",
owner: current_user, owner: current_user,
team: @protocol.in_module? ? @protocol.my_module.experiment.project.team : @protocol.team, team: @protocol.in_module? ? @protocol.my_module.experiment.project.team : @protocol.team,
project: @protocol.in_module? ? @protocol.my_module.experiment.project : nil, project: @protocol.in_module? ? @protocol.my_module.experiment.project : nil,
@ -47,7 +49,6 @@ module StepElements
id: @step.id, id: @step.id,
value_for: 'position_plus_one' value_for: 'position_plus_one'
}, },
my_module: @protocol.my_module.id
}.merge(message_items) }.merge(message_items)
) )
end end

View file

@ -124,7 +124,7 @@ module StepElements
owner: current_user, owner: current_user,
subject: @step.protocol, subject: @step.protocol,
team: @step.protocol.team, team: @step.protocol.team,
project: @step.protocol.my_module.experiment.project, project: @step.protocol.in_module? ? @step.protocol.my_module.experiment.project : nil,
message_items: message_items message_items: message_items
) )
end end

View file

@ -23,7 +23,7 @@ module StepElements
log_step_activity(:checklist_edited, { checklist_name: @checklist.name }) log_step_activity(:checklist_edited, { checklist_name: @checklist.name })
end end
render json: @checklist, serializer: ChecklistSerializer render json: @checklist, serializer: ChecklistSerializer, user: current_user
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
head :unprocessable_entity head :unprocessable_entity
end end

View file

@ -28,7 +28,7 @@ module StepElements
log_step_activity(:table_edited, { table_name: @table.name }) log_step_activity(:table_edited, { table_name: @table.name })
end end
render json: @table, serializer: TableSerializer render json: @table, serializer: TableSerializer, user: current_user
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
head :unprocessable_entity head :unprocessable_entity
end end

View file

@ -24,7 +24,7 @@ module StepElements
log_step_activity(:text_edited, { text_name: @step_text.name }) log_step_activity(:text_edited, { text_name: @step_text.name })
end end
render json: @step_text, serializer: StepTextSerializer render json: @step_text, serializer: StepTextSerializer, user: current_user
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
head :unprocessable_entity head :unprocessable_entity
end end

View file

@ -38,7 +38,7 @@
{{ protocol.attributes.name }} {{ protocol.attributes.name }}
</span> </span>
</div> </div>
<ProtocolMetadata v-if="protocol.attributes" :protocol="protocol" @update="updateProtocol"/> <ProtocolMetadata v-if="protocol.attributes && protocol.attributes.in_repository" :protocol="protocol" @update="updateProtocol"/>
<Tinymce <Tinymce
v-if="urls.update_protocol_description_url" v-if="urls.update_protocol_description_url"
:value="protocol.attributes.description" :value="protocol.attributes.description"

View file

@ -1,4 +1,4 @@
/* global ActiveStorage GLOBAL_CONSTANTS Promise i18n */ /* global ActiveStorage GLOBAL_CONSTANTS Promise I18n */
export default { export default {
data() { data() {
@ -40,7 +40,7 @@ export default {
} }
}; };
if (file.size > GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB * 1024 * 1024) { if (file.size > GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB * 1024 * 1024) {
fileObject.error = i18n.t('protocols.steps.attachments.new.file_too_big'); fileObject.error = I18n.t('protocols.steps.attachments.new.file_too_big');
this.attachments.push(fileObject); this.attachments.push(fileObject);
return; return;
} }
@ -51,7 +51,7 @@ export default {
upload.create((error, blob) => { upload.create((error, blob) => {
if (error) { if (error) {
fileObject.error = i18n.t('protocols.steps.attachments.new.general_error'); fileObject.error = I18n.t('protocols.steps.attachments.new.general_error');
reject(error); reject(error);
} else { } else {
const signedId = blob.signed_id; const signedId = blob.signed_id;

View file

@ -69,6 +69,7 @@
</ul> </ul>
</div> </div>
<a href="#" <a href="#"
v-if="!inRepository"
ref="comments" ref="comments"
class="open-comments-sidebar btn icon-btn btn-light" class="open-comments-sidebar btn icon-btn btn-light"
data-turbolinks="false" data-turbolinks="false"
@ -111,6 +112,7 @@
:is="elements[index].attributes.orderable_type" :is="elements[index].attributes.orderable_type"
:key="index" :key="index"
:element.sync="elements[index]" :element.sync="elements[index]"
:inRepository="inRepository"
:reorderElementUrl="urls.reorder_elements_url" :reorderElementUrl="urls.reorder_elements_url"
@component:delete="deleteElement" @component:delete="deleteElement"
@update="updateElement" @update="updateElement"

View file

@ -47,6 +47,7 @@
:checklistItem="checklistItem" :checklistItem="checklistItem"
:locked="locked" :locked="locked"
:reorderChecklistItemUrl="element.attributes.orderable.urls.reorder_url" :reorderChecklistItemUrl="element.attributes.orderable.urls.reorder_url"
:inRepository="inRepository"
@editStart="editingItem = true" @editStart="editingItem = true"
@editEnd="editingItem = false" @editEnd="editingItem = false"
@update="saveItem" @update="saveItem"
@ -80,6 +81,10 @@
type: Object, type: Object,
required: true required: true
}, },
inRepository: {
type: Boolean,
required: true
},
reorderElementUrl: { reorderElementUrl: {
type: String type: String
} }

View file

@ -5,7 +5,7 @@
<i class="fas fa-grip-vertical"></i> <i class="fas fa-grip-vertical"></i>
</div> </div>
<div class="step-element-name" :class="{ 'done': checklistItem.attributes.checked }"> <div class="step-element-name" :class="{ 'done': checklistItem.attributes.checked }">
<div class="sci-checkbox-container" :class="{ 'disabled': !checklistItem.attributes.urls.update_url}"> <div class="sci-checkbox-container" :class="{ 'disabled': !updateUrl || inRepository}">
<input ref="checkbox" <input ref="checkbox"
type="checkbox" type="checkbox"
class="sci-checkbox" class="sci-checkbox"
@ -15,7 +15,7 @@
</div> </div>
<div class="step-checklist-text"> <div class="step-checklist-text">
<InlineEdit <InlineEdit
v-if="checklistItem.attributes.urls.update_url" v-if="!checklistItem.attributes.urls || updateUrl"
:value="checklistItem.attributes.text" :value="checklistItem.attributes.text"
:characterLimit="10000" :characterLimit="10000"
:placeholder="''" :placeholder="''"
@ -35,10 +35,10 @@
</div> </div>
</div> </div>
<div class="step-element-controls"> <div class="step-element-controls">
<button v-if="checklistItem.attributes.urls.update_url" class="btn icon-btn btn-light" @click="enableTextEdit"> <button v-if="!checklistItem.attributes.urls || updateUrl" class="btn icon-btn btn-light" @click="enableTextEdit">
<i class="fas fa-pen"></i> <i class="fas fa-pen"></i>
</button> </button>
<button v-if="checklistItem.attributes.urls.delete_url" class="btn icon-btn btn-light" @click="showDeleteModal"> <button v-if="!checklistItem.attributes.urls || deleteUrl" class="btn icon-btn btn-light" @click="showDeleteModal">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
</div> </div>
@ -65,6 +65,10 @@
type: Boolean, type: Boolean,
default: false default: false
}, },
inRepository: {
type: Boolean,
required: true
},
reorderChecklistItemUrl: { reorderChecklistItemUrl: {
type: String type: String
} }
@ -82,6 +86,16 @@
position: this.checklistItem.attributes.position position: this.checklistItem.attributes.position
} }
}); });
},
updateUrl() {
if (!this.checklistItem.attributes.urls) return
return this.checklistItem.attributes.urls.update_url;
},
deleteUrl() {
if (!this.checklistItem.attributes.urls) return
return this.checklistItem.attributes.urls.delete_url;
} }
}, },
methods: { methods: {
@ -94,7 +108,7 @@
this.$emit('editEnd'); this.$emit('editEnd');
}, },
toggleChecked(e) { toggleChecked(e) {
if (!this.checklistItem.attributes.urls.update_url) return if (!this.updateUrl) return
this.checklistItem.attributes.checked = this.$refs.checkbox.checked; this.checklistItem.attributes.checked = this.$refs.checkbox.checked;
this.update(); this.update();
}, },

View file

@ -66,6 +66,10 @@
type: Object, type: Object,
required: true required: true
}, },
inRepository: {
type: Boolean,
required: true
},
reorderElementUrl: { reorderElementUrl: {
type: String type: String
} }

View file

@ -46,6 +46,10 @@
type: Object, type: Object,
required: true required: true
}, },
inRepository: {
type: Boolean,
required: true
},
reorderElementUrl: { reorderElementUrl: {
type: String type: String
} }

View file

@ -12,7 +12,7 @@ class ChecklistSerializer < ActiveModel::Serializer
end end
def urls def urls
return {} if object.destroyed? || !can_manage_step?(scope[:user], object.step) return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
{ {
delete_url: step_checklist_path(object.step, object), delete_url: step_checklist_path(object.step, object),

View file

@ -15,8 +15,8 @@ class ProtocolSerializer < ActiveModel::Serializer
def added_by def added_by
{ {
avatar: object.added_by.avatar_url(:icon_small), avatar: object.added_by&.avatar_url(:icon_small),
name: object.added_by.full_name name: object.added_by&.full_name
} }
end end

View file

@ -29,7 +29,7 @@ class StepTextSerializer < ActiveModel::Serializer
end end
def urls def urls
return {} if object.destroyed? || !can_manage_step?(scope[:user], object.step) return {} if object.destroyed? || !can_manage_step?(scope[:user] || @instance_options[:user], object.step)
{ {
delete_url: step_text_path(object.step, object), delete_url: step_text_path(object.step, object),

View file

@ -19,7 +19,7 @@ class TableSerializer < ActiveModel::Serializer
object.reload unless object.step object.reload unless object.step
return {} unless can_manage_step?(scope[:user], object.step) return {} unless can_manage_step?(scope[:user] || @instance_options[:user], object.step)
{ {
delete_url: step_table_path(object.step, object), delete_url: step_table_path(object.step, object),