diff --git a/src/components/CreateMappingModal.vue b/src/components/CreateMappingModal.vue index 68b8a42d..48e34f0c 100644 --- a/src/components/CreateMappingModal.vue +++ b/src/components/CreateMappingModal.vue @@ -14,10 +14,21 @@ - +
- + + {{ translate("Required") }} + + + + {{ prop }} + + + + {{ translate("Optional") }} + + {{ prop }} @@ -42,13 +53,14 @@ import { IonHeader, IonIcon, IonInput, + IonItem, + IonItemDivider, + IonLabel, IonSelect, IonSelectOption, IonTitle, IonToolbar, - IonItem, IonList, - onIonViewDidEnter, modalController } from '@ionic/vue'; @@ -67,34 +79,43 @@ let mappingName = ref(null) let fieldMapping = ref ({}) let fileColumns = ref([]) let identificationTypeId = ref('SKU') +const fields = process.env["VUE_APP_MAPPING_INVCOUNT"] ? JSON.parse(process.env["VUE_APP_MAPPING_INVCOUNT"]) : {} onMounted(() => { fieldMapping.value = { ...props.seletedFieldMapping } fileColumns.value = Object.keys(props.content[0]); }) -function getFields() { - const fields = process.env["VUE_APP_MAPPING_" + props.mappingType]; - return fields ? JSON.parse(fields) : {}; +function getFields(fields, required = true) { + return Object.keys(fields).reduce((result, key) => { + if (fields[key].required === required) { + result[key] = fields[key]; + } + return result; + }, {}); } function closeModal() { modalController.dismiss({ dismissed: true }); } async function saveMapping() { - if(!mappingName.value) { + if(!mappingName.value || !mappingName.value.trim()) { showToast(translate("Enter mapping name")); return } if (!areAllFieldsSelected()) { - showToast(translate("Map all fields")); + showToast(translate("Map all required fields")); return } const id = generateUniqueMappingPrefId(); await store.dispatch("user/createFieldMapping", { id, name: mappingName.value, value: fieldMapping.value, mappingType: props.mappingType }) closeModal(); } + function areAllFieldsSelected() { - return Object.values(fieldMapping.value).every(field => field !== ""); + const requiredFields = Object.keys(getFields(fields, true)); + const selectedFields = Object.keys(fieldMapping.value).filter(key => fieldMapping.value[key] !== '') + + return requiredFields.every(field => selectedFields.includes(field)); } //Todo: Generating unique identifiers as we are currently storing in local storage. Need to remove it as we will be storing data on server. @@ -103,4 +124,9 @@ function generateUniqueMappingPrefId() { return !fieldMappings.value[id] ? id : this.generateUniqueMappingPrefId(); } - \ No newline at end of file + + \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json index 0054c287..0fdcaec1 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -145,6 +145,7 @@ "Line status": "Line status", "Make sure all the columns are mapped correctly.": "Make sure all the columns are mapped correctly.", "Make sure you've reviewed the products and their counts before uploading them for review": "Make sure you've reviewed the products and their counts before uploading them for review", + "Map all required fields": "Map all required fields", "Mapping name": "Mapping name", "New mapping": "New mapping", "No cycle counts found": "No cycle counts found", diff --git a/src/store/modules/count/actions.ts b/src/store/modules/count/actions.ts index 1bfa4daa..018c4983 100644 --- a/src/store/modules/count/actions.ts +++ b/src/store/modules/count/actions.ts @@ -186,7 +186,7 @@ const actions: ActionTree = { const resp = await CountService.fetchCycleCountImportSystemMessages({ systemMessageTypeId: "ImportInventoryCounts", initDate_from: fifteenMinutesEarlier.toMillis(), - orderByField: 'processedDate desc,initDate desc', + orderByField: 'initDate desc, processedDate desc', pageSize: 10 }) if (!hasError(resp)) { diff --git a/src/views/BulkUpload.vue b/src/views/BulkUpload.vue index 8f35aef9..2f8b2b8f 100644 --- a/src/views/BulkUpload.vue +++ b/src/views/BulkUpload.vue @@ -23,7 +23,7 @@ {{ translate("New mapping") }} - + {{ mapping.name }}
@@ -129,6 +129,7 @@ let fileName = ref(null) let content = ref([]) let fieldMapping = ref({}) let fileColumns = ref([]) +let selectedMappingId = ref(null) const fileUploaded = ref(false); const fields = process.env["VUE_APP_MAPPING_INVCOUNT"] ? JSON.parse(process.env["VUE_APP_MAPPING_INVCOUNT"]) : {} @@ -154,6 +155,8 @@ function resetDefaults() { uploadedFile.value = {} content.value = [] fileName.value = null + file.value.value = '' + selectedMappingId.value = null } function extractFilename(filePath) { if (!filePath) { @@ -265,7 +268,6 @@ async function save(){ throw resp.data } resetDefaults() - file.value.value = '' await store.dispatch('count/fetchCycleCountImportSystemMessages') showToast(translate("The cycle counts file uploaded successfully.")) }).catch(() => { @@ -277,7 +279,7 @@ async function save(){ }); return alert.present(); } -function mapFields(mapping) { +function mapFields(mapping, mappingId) { const fieldMappingData = JSON.parse(JSON.stringify(mapping)); // TODO: Store an object in this.content variable, so everytime when accessing it, we don't need to use 0th index @@ -295,6 +297,7 @@ function mapFields(mapping) { } }) fieldMapping.value = fieldMappingData.value; + selectedMappingId.value = mappingId } function areAllFieldsSelected() { const requiredFields = Object.keys(getFilteredFields(fields, true));