Skip to content

Commit

Permalink
List duplicates as sets and update display in import
Browse files Browse the repository at this point in the history
  • Loading branch information
gloverkari committed Sep 27, 2023
1 parent cb6c921 commit f061979
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 69 deletions.
162 changes: 95 additions & 67 deletions src/components/import/ImportFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,6 @@
class="is-size-6">
{{ importStatus }}
</p>
<div v-if="importDuplicates.length > 0">
<p
class="is-size-6 has-text-danger">
<br>
Found {{ importDuplicates.length }} instance{{ importDuplicates.length > 1 ? 's' : '' }} of duplicate competencies with different CTIDs.
<br>
For each instance, choose whether to upload all or select a single CTID.
</p>
<br>
<div v-for="(set) in importDuplicates">
{{ '(' + set.lines + ') ' + set.competencyText }}{{ set.codedNotation ? '(' + set.codedNotation + ')' : '' }}
<div>
<label for="select-ctid">select CTID </label>
<select
id="select-ctid"
name="CTIDs">
<option
v-for="duplicate in set.duplicates"
:value="duplicate.line">
{{ duplicate.ctid }}
</option>
</select>
</div>
<br>
</div>
<br>
<br>
<br>
</div>
</div>
</div>
<!-- import errors -->
Expand Down Expand Up @@ -208,6 +179,43 @@
</div>
</div>
</div>
<!-- handle duplicates -->
<div v-if="duplicateSets.length > 0">
<div
class="has-text-danger">
<br>
Found {{ duplicateSets.length }} instance{{ duplicateSets.length > 1 ? 's' : '' }} of duplicate competencies with different CTIDs.
<br>
For each instance, choose whether to upload all or select a single CTID.
</div>
<br>
<div v-for="(set, i) in duplicateSets">
<div class="has-text-weight-bold">
{{ set.competencyText }}
</div>
<div v-if="set.codedNotation">
{{ "ceasn:codedNotation: " + set.codedNotation }}
</div>
<div>
{{ set.lines }}
</div>
<br />
<div class="control">
<label for="select-ctid">select CTID </label>
<select
id="select-ctid"
name="CTIDs"
v-model="selectedDuplicateOption[i]">
<option
v-for="duplicate in set.duplicates"
:value="duplicate.ctid">
{{ duplicate.ctid }}
</option>
</select>
</div>
<br>
</div>
</div>
<!-- handle non pdf imports -->
<div
v-if="(importType === 'file' && importTransition === 'info') || importAllowCancel"
Expand Down Expand Up @@ -282,7 +290,9 @@ export default {
optionImportNameColumn: this.$store.getters['app/importNameColumn'],
optionImportDescriptionColumn: this.$store.getters['app/importDescriptionColumn'],
optionImportScopeColumn: this.$store.getters['app/importScopeColumn'],
optionImportIdColumn: this.$store.getters['app/importIdColumn']
optionImportIdColumn: this.$store.getters['app/importIdColumn'],
selectedDuplicateOption: [],
duplicateSets: []
};
},
computed: {
Expand Down Expand Up @@ -381,39 +391,6 @@ export default {
importStatus: function() {
return this.$store.getters['app/importStatus'];
},
importDuplicates: function() {
// Separate duplicates by competencyText and codedNotation
let setsOfDuplicates = [];
const duplicates = this.$store.getters['app/importDuplicates'];
duplicates.forEach((duplicate) => {
const foundIndex = setsOfDuplicates.findIndex((set) => (set.competencyText === duplicate.competencyText) && (set.codedNotation === duplicate.codedNotation));
console.log(duplicate);
console.log(foundIndex);
if (foundIndex >= 0) {
setsOfDuplicates[foundIndex].lines += ', ' + duplicate.line;
setsOfDuplicates[foundIndex].duplicates.push({
ctid: duplicate.ctid,
id: duplicate.id
});
} else {
setsOfDuplicates.push({
competencyText: duplicate.competencyText,
codedNotation: duplicate.codedNotation,
lines: 'Line ' + duplicate.line,
duplicates: [
{
ctid: 'upload all'
},
{
ctid: duplicate.ctid
}
]
});
}
});
console.log(setsOfDuplicates);
return setsOfDuplicates;
},
importFileType: function() {
return this.$store.getters['app/importFileType'];
},
Expand All @@ -438,6 +415,9 @@ export default {
importIdColumn: function() {
return this.$store.getters['app/importIdColumn'];
},
importDuplicates: function() {
return this.$store.getters['app/importDuplicates'];
},
importSourceColumn: {
get() {
return this.$store.getters['app/importSourceColumn'];
Expand Down Expand Up @@ -492,7 +472,7 @@ export default {
x: false,
y: true
};
this.updateDuplicateSkips();
if (this.importFileType === 'csv') {
// prepare csv
this.$store.commit('app/importFrameworkName', this.optionImportFrameworkName);
Expand Down Expand Up @@ -533,10 +513,55 @@ export default {
}
}
},
removeDuplicate: function(index) {
findDuplicateSets: function() {
// Separate duplicates by competencyText and codedNotation
this.duplicateSets = [];
const duplicates = this.$store.getters['app/importDuplicates'];
duplicates.splice(index, 1);
this.$store.commit('app/importDuplicates', duplicates);
duplicates.forEach((duplicate) => {
const foundIndex = this.duplicateSets.findIndex((set) => (set.competencyText === duplicate.competencyText) && (set.codedNotation === duplicate.codedNotation));
if (foundIndex >= 0) {
this.duplicateSets[foundIndex].lines += ', ' + duplicate.line;
this.duplicateSets[foundIndex].duplicates.push({
ctid: duplicate.ctid,
id: duplicate.id
});
} else {
this.duplicateSets.push({
competencyText: duplicate.competencyText,
codedNotation: duplicate.codedNotation,
lines: 'Lines ' + duplicate.line,
duplicates: [
{
ctid: 'upload all'
},
{
ctid: duplicate.ctid
}
]
});
}
});
this.selectedDuplicateOption = [];
this.duplicateSets.forEach(() => {
this.selectedDuplicateOption.push('upload all');
});
},
updateDuplicateSkips: function() {
let skip = [];
this.selectedDuplicateOption.forEach((set, i) => {
if (set !== 'upload all') {
this.duplicateSets[i].duplicates.forEach((duplicate) => {
if (duplicate.ctid !== set && !duplicate.ctid.includes('upload all')) {
skip.push(duplicate.ctid);
if (duplicate.replaceWith) {
// Replace all instances of duplicate.ctid with duplicate.replaceWith in import file
}
}
});
}
});
this.duplicateSets = [];
this.$store.commit('app/importSkip', skip);
}
},
watch: {
Expand Down Expand Up @@ -566,6 +591,9 @@ export default {
},
importTargetColumn: function() {
this.csvRelationDetails.targetColumn.value = this.importTargetColumn;
},
importDuplicates: function() {
this.findDuplicateSets();
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/mixins/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ export default {
this.$store.commit('app/importStatus', '');
this.$store.commit('app/importFeedback', '');
this.$store.commit('app/importFileType', '');
this.$store.commit('app/importDuplicates', []);
this.$store.commit('app/importSkip', []);
if (this.caseDocs) {
this.caseDocs = [];
}
Expand Down Expand Up @@ -589,8 +591,7 @@ export default {
if (EcIdentityManager.default.ids.length > 0) { ceo = EcIdentityManager.default.ids[0]; }
let me = this;
me.$store.commit('app/importAllowCancel', true);
let duplicates = this.$store.getters['app/importDuplicates'];
let skip = duplicates.map((element) => { return element.ctid; });
let skip = this.$store.getters['app/importSkip'];
CTDLASNCSVImport.importFrameworksAndCompetencies(me.repo, me.importFile[0], function(frameworks, competencies, relations) {
me.$store.commit('app/importAllowCancel', false);
for (var i = 0; i < frameworks.length; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/store/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const state = {
errors: [], // erorrs from the code or from the api
feedback: '', // additional information
duplicates: [],
skip: [],
framework: null,
serverUrl: '',
url: '',
Expand Down Expand Up @@ -171,6 +172,7 @@ const mutations = {
errors: [], // erorrs from the code or from the api
feedback: '', // additional information
duplicates: [],
skip: [],
framework: null,
serverUrl: '',
url: '',
Expand Down Expand Up @@ -222,6 +224,9 @@ const mutations = {
importDuplicates: function(state, val) {
state.import.duplicates = val;
},
importSkip: function(state, val) {
state.import.skip = val;
},
importFramework: function(state, val) {
state.import.framework = val;
},
Expand Down Expand Up @@ -371,6 +376,8 @@ const actions = {
commit('importAllowCancel', false);
commit('importFeedback', '');
commit('importFileType', '');
commit('importDuplicates', []);
commit('importSkip', []);
},
refreshDirectories: function({commit}) {
let directories = [];
Expand Down Expand Up @@ -460,6 +467,9 @@ const getters = {
importDuplicates: state => {
return state.import.duplicates;
},
importSkip: state => {
return state.import.skip;
},
importFramework: state => {
return state.import.framework;
},
Expand Down

0 comments on commit f061979

Please sign in to comment.