Update fluics and permissions for label templates [SCI-7222]

This commit is contained in:
Anton 2022-09-20 12:59:58 +02:00
parent e524355207
commit fed1228adc
3 changed files with 28 additions and 7 deletions

View file

@ -4,9 +4,11 @@
display: flex;
flex-direction: column;
height: calc(100vh - var(--navbar-height));
padding-left: 1.5em;
.title-row {
align-items: center;
@include font-h1;
align-items: end;
background: $color-white;
border-bottom: $border-tertiary;
display: flex;
@ -23,7 +25,6 @@
}
.sci-inline-edit {
@include font-h1;
flex-grow: 1;
max-width: calc(100% - 50px);
}
@ -47,6 +48,7 @@
.label-template-container {
display: flex;
flex-grow: 1;
margin-top: 1em;
.title {
font-weight: bold;
@ -124,7 +126,7 @@
top: 0;
}
&:hover {
&:hover:not(.read-only) {
background-color: $color-concrete;
.fa-pen {

View file

@ -12,6 +12,7 @@
<div v-if="labelTemplate.id" class="title-row">
<img :src="labelTemplate.attributes.icon_url" class="label-template-icon"/>
<InlineEdit
v-if="canManage"
:value="labelTemplate.attributes.name"
:characterLimit="255"
:allowBlank="false"
@ -22,14 +23,18 @@
@editingDisabled="editingName = false"
@update="updateName"
/>
<template v-else>
{{ labelTemplate.attributes.name }}
</template>
</div>
</div>
<div v-if="labelTemplate.id" class="template-descripiton">
<div v-if="labelTemplate.id && notFluics" class="template-descripiton">
<div class="title">
{{ i18n.t('label_templates.show.description_title') }}
</div>
<div class="description">
<InlineEdit
v-if="canManage"
:value="labelTemplate.attributes.description"
:characterLimit="255"
:allowBlank="true"
@ -40,10 +45,13 @@
@editingDisabled="editingDescription = false"
@update="updateDescription"
/>
<template v-else>
{{ labelTemplate.attributes.description }}
</template>
</div>
</div>
<div v-if="labelTemplate.id" class="label-template-container">
<div class="label-edit-container">
<div class="label-edit-container" v-if="notFluics">
<div class="label-edit-header">
<div class="title">
{{ i18n.t('label_templates.show.content_title', { format: labelTemplate.attributes.language_type.toUpperCase() }) }}
@ -80,10 +88,13 @@
</div>
</div>
</template>
<div v-else class="label-view-container" :title="i18n.t('label_templates.show.view_content_tooltip')" @click="enableContentEdit">
<div v-else-if="canManage" class="label-view-container" :title="i18n.t('label_templates.show.view_content_tooltip')" @click="enableContentEdit">
{{ labelTemplate.attributes.content}}
<i class="fas fa-pen"></i>
</div>
<div v-else class="label-view-container read-only" :title="i18n.t('label_templates.show.view_content_tooltip')">
{{ labelTemplate.attributes.content}}
</div>
</div>
<div class="label-preview-container">
<LabelPreview :zpl='previewContent' :previewUrl="previewUrl" @preview:valid="updateContent" @preview:invalid="invalidPreview" />
@ -133,6 +144,12 @@
computed: {
hasError() {
return this.codeErrorMessage.length > 0
},
canManage() {
return this.labelTemplate.attributes.urls.update && this.notFluics
},
notFluics() {
return this.labelTemplate.attributes.type !== "FluicsLabelTemplate"
}
},
components: {InlineEdit, InsertFieldDropdown, LabelPreview},

View file

@ -1,15 +1,17 @@
# frozen_string_literal: true
class LabelTemplateSerializer < ActiveModel::Serializer
include Canaid::Helpers::PermissionsHelper
include Rails.application.routes.url_helpers
attributes :name, :description, :language_type, :icon_url, :urls, :content
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type
def icon_url
ActionController::Base.helpers.image_path("label_template_icons/#{object.icon}.svg")
end
def urls
return {} unless can_manage_label_templates?(object.team)
{
update: label_template_path(object),
fields: template_tags_label_templates_path