mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-16 21:59:00 +08:00
Add dimension saving to label templates [SCI-7268] (#4489)
This commit is contained in:
parent
ae8f5526be
commit
bd535dc9ad
5 changed files with 47 additions and 15 deletions
|
|
@ -172,7 +172,7 @@ class LabelTemplatesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_template_params
|
def label_template_params
|
||||||
params.require(:label_template).permit(:name, :description, :content)
|
params.require(:label_template).permit(:name, :description, :content, :width_mm, :height_mm)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_activity(type_of, label_template = @label_template, message_items: {})
|
def log_activity(type_of, label_template = @label_template, message_items: {})
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,13 @@
|
||||||
<div class="label-preview__controls__size">
|
<div class="label-preview__controls__size">
|
||||||
<div class="sci-input-container">
|
<div class="sci-input-container">
|
||||||
<label>{{ i18n.t('label_templates.label_preview.height') }}</label>
|
<label>{{ i18n.t('label_templates.label_preview.height') }}</label>
|
||||||
<input v-model="height" type="number" class="sci-input-field" />
|
<input v-model="height" type="number" class="sci-input-field"
|
||||||
|
@change="$emit('height:update', (unit === 'in' ? height * 25.4 : height))" />
|
||||||
</div>
|
</div>
|
||||||
<div class="sci-input-container">
|
<div class="sci-input-container">
|
||||||
<label>{{ i18n.t('label_templates.label_preview.width') }}</label>
|
<label>{{ i18n.t('label_templates.label_preview.width') }}</label>
|
||||||
<input v-model="width" type="number" class="sci-input-field" />
|
<input v-model="width" type="number" class="sci-input-field"
|
||||||
|
@change="$emit('width:update', (unit === 'in' ? width * 25.4 : width))" />
|
||||||
</div>
|
</div>
|
||||||
<div class="sci-input-container">
|
<div class="sci-input-container">
|
||||||
<label>{{ i18n.t('label_templates.label_preview.density') }}</label>
|
<label>{{ i18n.t('label_templates.label_preview.density') }}</label>
|
||||||
|
|
@ -79,6 +81,7 @@
|
||||||
name: 'LabelPreview',
|
name: 'LabelPreview',
|
||||||
components: { DropdownSelector },
|
components: { DropdownSelector },
|
||||||
props: {
|
props: {
|
||||||
|
template: { type: Object, required: true},
|
||||||
zpl: { type: String, required: true },
|
zpl: { type: String, required: true },
|
||||||
previewUrl: { type: String, required: true },
|
previewUrl: { type: String, required: true },
|
||||||
viewOnly: {
|
viewOnly: {
|
||||||
|
|
@ -101,6 +104,9 @@
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.refreshPreview();
|
this.refreshPreview();
|
||||||
|
this.width = this.template.attributes.width_mm
|
||||||
|
this.height = this.template.attributes.height_mm
|
||||||
|
if (this.width && this.height) this.recalculateUnits();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
widthMm() {
|
widthMm() {
|
||||||
|
|
@ -112,14 +118,7 @@
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
unit() {
|
unit() {
|
||||||
if (this.unit === 'in') {
|
this.recalculateUnits();
|
||||||
this.width /= 25.4;
|
|
||||||
this.height /= 25.4;
|
|
||||||
} else {
|
|
||||||
this.width *= 25.4;
|
|
||||||
this.height *= 25.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setDefaults();
|
this.setDefaults();
|
||||||
},
|
},
|
||||||
zpl() {
|
zpl() {
|
||||||
|
|
@ -133,6 +132,15 @@
|
||||||
!this.width && (this.width = this.unit === 'in' ? 2 : 50.8);
|
!this.width && (this.width = this.unit === 'in' ? 2 : 50.8);
|
||||||
!this.height && (this.height = this.unit === 'in' ? 1 : 25.4);
|
!this.height && (this.height = this.unit === 'in' ? 1 : 25.4);
|
||||||
},
|
},
|
||||||
|
recalculateUnits() {
|
||||||
|
if (this.unit === 'in') {
|
||||||
|
this.width /= 25.4;
|
||||||
|
this.height /= 25.4;
|
||||||
|
} else {
|
||||||
|
this.width *= 25.4;
|
||||||
|
this.height *= 25.4;
|
||||||
|
}
|
||||||
|
},
|
||||||
refreshPreview() {
|
refreshPreview() {
|
||||||
if (this.zpl.length === 0) return;
|
if (this.zpl.length === 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,15 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="label-preview-container">
|
<div class="label-preview-container">
|
||||||
<LabelPreview :zpl='previewContent' :previewUrl="previewUrl" @preview:valid="updateContent" @preview:invalid="invalidPreview" />
|
<LabelPreview
|
||||||
|
:zpl='previewContent'
|
||||||
|
:template="labelTemplate"
|
||||||
|
:previewUrl="previewUrl"
|
||||||
|
@preview:valid="updateContent"
|
||||||
|
@preview:invalid="invalidPreview"
|
||||||
|
@height:update="setNewHeight"
|
||||||
|
@width:update="setNewWidth"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -126,6 +134,8 @@
|
||||||
editingDescription: false,
|
editingDescription: false,
|
||||||
editingContent: false,
|
editingContent: false,
|
||||||
newContent: '',
|
newContent: '',
|
||||||
|
newLabelWidth: null,
|
||||||
|
newLabelHeight: null,
|
||||||
previewContent: '',
|
previewContent: '',
|
||||||
previewValid: false,
|
previewValid: false,
|
||||||
skipSave: false,
|
skipSave: false,
|
||||||
|
|
@ -158,9 +168,17 @@
|
||||||
this.labelTemplate = result.data
|
this.labelTemplate = result.data
|
||||||
this.newContent = this.labelTemplate.attributes.content
|
this.newContent = this.labelTemplate.attributes.content
|
||||||
this.previewContent = this.labelTemplate.attributes.content
|
this.previewContent = this.labelTemplate.attributes.content
|
||||||
|
this.newLabelWidth = this.labelTemplate.attributes.width_mm
|
||||||
|
this.newLabelHeight = this.labelTemplate.attributes.height_mm
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
setNewHeight(val) {
|
||||||
|
this.newLabelHeight = val;
|
||||||
|
},
|
||||||
|
setNewWidth(val) {
|
||||||
|
this.newLabelWidth = val;
|
||||||
|
},
|
||||||
enableContentEdit() {
|
enableContentEdit() {
|
||||||
this.editingContent = true;
|
this.editingContent = true;
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
|
@ -210,9 +228,15 @@
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.labelTemplate.attributes.urls.update,
|
url: this.labelTemplate.attributes.urls.update,
|
||||||
type: 'PATCH',
|
type: 'PATCH',
|
||||||
data: {label_template: {content: this.newContent}},
|
data: {label_template: {
|
||||||
|
content: this.newContent,
|
||||||
|
width_mm: this.newLabelHeight,
|
||||||
|
height_mm: this.newLabelWidth
|
||||||
|
}},
|
||||||
success: (result) => {
|
success: (result) => {
|
||||||
this.labelTemplate.attributes.content = result.data.attributes.content;
|
this.labelTemplate.attributes.content = result.data.attributes.content;
|
||||||
|
this.labelTemplate.attributes.width_mm = result.data.attributes.width_mm;
|
||||||
|
this.labelTemplate.attributes.height_mm = result.data.attributes.height_mm;
|
||||||
this.editingContent = false;
|
this.editingContent = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
{{ i18n.t('repository_row.modal_print_label.label_preview') }}
|
{{ i18n.t('repository_row.modal_print_label.label_preview') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="label-preview-container">
|
<div class="label-preview-container">
|
||||||
<LabelPreview v-if="labelTemplateCode" :zpl='labelTemplateCode' :previewUrl="urls.labelPreview" :viewOnly="true"/>
|
<LabelPreview v-if="labelTemplateCode" :zpl='labelTemplateCode' :template="selectedTemplate" :previewUrl="urls.labelPreview" :viewOnly="true"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ class LabelTemplateSerializer < ActiveModel::Serializer
|
||||||
include Canaid::Helpers::PermissionsHelper
|
include Canaid::Helpers::PermissionsHelper
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type, :default
|
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type, :default, :width_mm, :height_mm
|
||||||
|
|
||||||
def icon_url
|
def icon_url
|
||||||
ActionController::Base.helpers.image_path("label_template_icons/#{object.icon}.svg")
|
ActionController::Base.helpers.image_path("label_template_icons/#{object.icon}.svg")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue