mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-28 23:18:10 +08:00
Create new column on inventory import [SCI-10595]
This commit is contained in:
parent
b756a87123
commit
59e767bcde
6 changed files with 59 additions and 14 deletions
|
|
@ -75,7 +75,7 @@
|
|||
<div id="table-rows" ref="tableRowsRef" class="w-full h-[28rem] flex flex-col py-4 overflow-auto gap-1">
|
||||
<!-- rows -->
|
||||
<div v-for="(item, index) in stepProps.columnNames" :key="item"
|
||||
class="flex flex-col gap-4 min-h-[56px] justify-center px-4 rounded"
|
||||
class="flex flex-col gap-4 min-h-[56px] justify-center px-4 rounded shrink-0"
|
||||
:class="{'bg-sn-super-light-blue': this.selectedItemsIndexes.includes(index)}"
|
||||
>
|
||||
<SecondStepTableRow
|
||||
|
|
@ -121,7 +121,7 @@
|
|||
{{ i18n.t('repositories.import_records.steps.step2.cancelBtnText') }}
|
||||
</button>
|
||||
|
||||
<button class="btn btn-primary" @click="importRecords">
|
||||
<button class="btn btn-primary" :disabled="!rowsIsValid" @click="importRecords">
|
||||
{{ i18n.t('repositories.import_records.steps.step2.confirmBtnText') }}
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -233,7 +233,7 @@ export default {
|
|||
for (let i = 0; i < this.stepProps.columnNames.length; i++) {
|
||||
const foundItem = this.selectedItems.find((item) => item.index === i);
|
||||
if (foundItem) {
|
||||
mapping[foundItem.index] = foundItem.key;
|
||||
mapping[foundItem.index] = (foundItem.key === 'new' ? foundItem.value : foundItem.key);
|
||||
} else {
|
||||
mapping[i] = '';
|
||||
}
|
||||
|
|
@ -293,7 +293,8 @@ export default {
|
|||
}
|
||||
|
||||
if (this.availableFields) {
|
||||
const options = this.availableFields.map((el) => [String(el.key), `${String(el.value)} (${columnKeyToLabelMapping[el.key]})`]);
|
||||
let options = this.availableFields.map((el) => [String(el.key), `${String(el.value)} (${columnKeyToLabelMapping[el.key]})`]);
|
||||
options = [['new', this.i18n.t('repositories.import_records.steps.step2.table.tableRow.importAsNewColumn')]].concat(options);
|
||||
return options;
|
||||
}
|
||||
return [];
|
||||
|
|
@ -302,6 +303,15 @@ export default {
|
|||
const importedSum = this.selectedItems.length;
|
||||
const ignoredSum = this.stepProps.columnNames.length - importedSum;
|
||||
return { importedSum, ignoredSum };
|
||||
},
|
||||
rowsIsValid() {
|
||||
let valid = true;
|
||||
this.selectedItems.forEach((v) => {
|
||||
if (v.key === 'new' && (!v.value.type || v.value.name.length < 2)) {
|
||||
valid = false;
|
||||
}
|
||||
});
|
||||
return valid;
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
<!-- columns -->
|
||||
<div class="flex flex-row justify-between gap-6">
|
||||
<!-- number col -->
|
||||
<div class="w-6 my-auto">{{ index + 1 }}</div>
|
||||
<div class="w-6 h-10 flex items-center">{{ index + 1 }}</div>
|
||||
|
||||
<div class="w-40 my-auto truncate" :title="item">{{ item }}</div>
|
||||
<div class="w-40 h-10 flex items-center truncate" :title="item">{{ item }}</div>
|
||||
|
||||
<i class="sn-icon sn-icon-arrow-right w-6 my-auto relative left-5"></i>
|
||||
<i class="sn-icon sn-icon-arrow-right w-6 h-10 flex items-center relative left-5"></i>
|
||||
|
||||
<div class="w-60 my-auto">
|
||||
<div class="w-60 min-h-10 flex items-center flex-col gap-2">
|
||||
|
||||
<!-- system generated data -->
|
||||
<SelectDropdown v-if="systemGeneratedData.includes(item)"
|
||||
|
|
@ -26,9 +26,21 @@
|
|||
placeholder="Do not import"
|
||||
:title="this.selectedColumnType?.value"
|
||||
></SelectDropdown>
|
||||
<template v-if="selectedColumnType?.key == 'new'">
|
||||
<SelectDropdown
|
||||
:options="newColumnTypes"
|
||||
@change="(v) => { newColumn.type = v }"
|
||||
:value="newColumn.type"
|
||||
size="sm"
|
||||
placeholder="Select column type"
|
||||
></SelectDropdown>
|
||||
<div class="sci-input-container-v2 w-full">
|
||||
<input type="text" v-model="newColumn.name" class="sci-input" placeholder="Name">
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="w-14 my-auto flex justify-center">
|
||||
<div class="w-14 h-10 flex items-center flex justify-center">
|
||||
<!-- import -->
|
||||
<i v-if="this.selectedColumnType?.key && this.selectedColumnType?.value === item && !systemGeneratedData.includes(item)"
|
||||
class="sn-icon sn-icon-check" :title="i18n.t('repositories.import_records.steps.step2.table.tableRow.importedColumnTitle')">
|
||||
|
|
@ -54,7 +66,7 @@
|
|||
<i v-else class="sn-icon sn-icon-close text-sn-sleepy-grey" :title="i18n.t('repositories.import_records.steps.step2.table.tableRow.doNotImportColumnTitle')"></i>
|
||||
</div>
|
||||
|
||||
<div class="w-56 truncate my-auto" :title="stepProps.exampleData[index]">{{ stepProps.exampleData[index] }}</div>
|
||||
<div class="w-56 truncate h-10 flex items-center" :title="stepProps.exampleData[index]">{{ stepProps.exampleData[index] }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -85,9 +97,23 @@ export default {
|
|||
required: true
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
newColumn() {
|
||||
this.selectedColumnType.value = this.newColumn;
|
||||
this.$emit('selection:changed', this.selectedColumnType);
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selectedColumnType: null,
|
||||
newColumn: {
|
||||
type: 'Text',
|
||||
name: ''
|
||||
},
|
||||
newColumnTypes: [
|
||||
['Text', this.i18n.t('repositories.import_records.steps.step2.table.tableRow.newColumnType.text')],
|
||||
['List', this.i18n.t('repositories.import_records.steps.step2.table.tableRow.newColumnType.list')]
|
||||
],
|
||||
systemGeneratedData: [
|
||||
this.i18n.t('repositories.import_records.steps.step2.table.tableRow.systemGeneratedData.itemId'),
|
||||
this.i18n.t('repositories.import_records.steps.step2.table.tableRow.systemGeneratedData.createdOn'),
|
||||
|
|
@ -101,7 +127,12 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
changeSelected(e) {
|
||||
const value = this.stepProps.availableFields[e];
|
||||
let value;
|
||||
if (e === 'new') {
|
||||
value = this.newColumn;
|
||||
} else {
|
||||
value = this.stepProps.availableFields[e];
|
||||
}
|
||||
const selectedColumnType = { index: this.index, key: e, value };
|
||||
this.selectedColumnType = selectedColumnType;
|
||||
this.$emit('selection:changed', selectedColumnType);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class SpreadsheetParser
|
|||
header = row
|
||||
else
|
||||
escaped_row = row.map do |cell|
|
||||
cell.gsub("\\n", "\n")
|
||||
cell.to_s.gsub("\\n", "\n")
|
||||
end
|
||||
columns = escaped_row
|
||||
end
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ module RepositoryImportParser
|
|||
if index == @name_index
|
||||
|
||||
# check if row (inventory) already exists
|
||||
existing_row = RepositoryRow.includes(repository_cells: :value).find_by(id: incoming_row[0].gsub(RepositoryRow::ID_PREFIX, ''))
|
||||
existing_row = RepositoryRow.includes(repository_cells: :value).find_by(id: incoming_row[0].to_s.gsub(RepositoryRow::ID_PREFIX, ''))
|
||||
|
||||
# if it doesn't exist create it
|
||||
unless existing_row
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
<div class="toolbar-middle-block">
|
||||
<div id='repositoryStateMenu' data-behaviour="vue">
|
||||
<repository-state-menu
|
||||
view-mode="<%= params[:archived] %>"
|
||||
view-mode="<%= params[:archived] ? 'archived' : 'active' %>"
|
||||
disabled="<%= @repository.archived? %>"
|
||||
active-url="<%= repository_url(@repository) %>"
|
||||
archived-url="<%= repository_url(@repository, params: { archived: true }) %>">
|
||||
|
|
|
|||
|
|
@ -2244,6 +2244,10 @@ en:
|
|||
userDefinedColumnTitle: 'Column name does not match. Column will be imported as '
|
||||
importedColumnTitle: 'Column will be imported.'
|
||||
doNotImportColumnTitle: 'Column will not import.'
|
||||
importAsNewColumn: 'Import as new column'
|
||||
newColumnType:
|
||||
text: 'Text'
|
||||
list: 'Dropdown'
|
||||
systemGeneratedData:
|
||||
itemId: 'Item ID'
|
||||
createdOn: 'Created on'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue