Add published view for protocol [SCI-7617]

This commit is contained in:
Anton 2023-01-17 15:44:16 +01:00
parent 3902310463
commit 743d901310
6 changed files with 14 additions and 6 deletions
app
config/locales

View file

@ -78,7 +78,6 @@ class ProtocolsController < ApplicationController
only: %i(protocolsio_import_create protocolsio_import_save)
before_action :set_importer, only: %i(load_from_file import)
before_action :set_inline_name_editing, only: :show
layout 'fluid'

View file

@ -226,7 +226,7 @@
this.protocol.attributes.name = newName;
this.refreshProtocolStatus();
$.ajax({
type: 'PUT',
type: 'PATCH',
url: this.urls.update_protocol_name_url,
data: { protocol: { name: newName } }
});

View file

@ -17,7 +17,8 @@
<span class="fas fa-print" aria-hidden="true"></span>
</a>
<button class="btn btn-light">{{ i18n.t("protocols.header.versions") }}</button>
<button class="btn btn-primary">{{ i18n.t("protocols.header.publish") }}</button>
<button v-if="!protocol.attributes.published" class="btn btn-primary">{{ i18n.t("protocols.header.publish") }}</button>
<button v-else class="btn btn-secondary">{{ i18n.t("protocols.header.save_as_draft") }}</button>
</div>
</div>
<div id="details-container" class="protocol-details collapse in">

View file

@ -86,7 +86,8 @@ Canaid::Permissions.register_for(Protocol) do
# protocol in repository: update, create/update/delete/reorder step,
# toggle private/public visibility, archive
can :manage_protocol_in_repository do |user, protocol|
protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
protocol.protocol_type.in_repository_draft? &&
protocol.permission_granted?(user, ProtocolPermissions::MANAGE)
end
can :manage_protocol_draft_in_repository do |user, protocol|

View file

@ -7,14 +7,19 @@ class ProtocolSerializer < ActiveModel::Serializer
include ActionView::Helpers::TextHelper
attributes :name, :id, :urls, :description, :description_view, :updated_at, :in_repository,
:created_at_formatted, :updated_at_formatted, :added_by, :authors, :keywords, :version, :code
:created_at_formatted, :updated_at_formatted, :added_by, :authors, :keywords, :version, :code,
:published
def updated_at
object.updated_at.to_i
end
def version
object.protocol_type == 'in_repository_draft' ? I18n.t('protocols.header.draft') : object.version_number
object.in_repository_draft? ? I18n.t('protocols.draft') : object.version_number
end
def published
object.in_repository_published?
end
def added_by

View file

@ -2427,6 +2427,7 @@ en:
unchangable_error_message: "Predefined roles can not be changed!"
protocols:
draft: "Draft"
no_text_placeholder: 'No protocol description'
reorder_steps:
button: "Rearrange steps"
@ -2535,6 +2536,7 @@ en:
protocol_description: 'Protocol description'
protocol_steps: 'Protocol steps'
publish: 'Publish'
save_as_draft: 'Save as draft'
version: "Version:"
draft: 'Draft'
created_at: "Created at:"