Skip to content

Commit

Permalink
Migrate roads to new course numbers (#476)
Browse files Browse the repository at this point in the history
* Migrate roads to new course numbers

* Put course numbers in class infor card + subject scrollers

* Search by old id

* Migrate in vuex friendly way

* Make sure to clear migration queue
  • Loading branch information
georgiashay authored May 2, 2022
1 parent 2a49d35 commit a7822a5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/components/Auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import axios from 'axios';
import moment from 'moment';
import UAParser from 'ua-parser-js';
import simpleSSMixin from './../mixins/simpleSelectedSubjects.js';
import simpleSSMixin from './../mixins/sanitizeSubjects.js';
var DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSS000Z';
Expand Down Expand Up @@ -284,6 +284,8 @@ export default {
_this.$store.commit('setRetrieved', roadID);
_this.$store.dispatch('waitAndMigrateOldSubjects', roadID);
_this.gettingUserData = false;
return roadData;
});
Expand Down
13 changes: 12 additions & 1 deletion src/components/Class.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
cancel
</v-icon>
<v-card-text class="card-text">
<span style="font-weight: bold; font-size: 1.1em;">{{ classInfo.subject_id }}</span> {{ classInfo.title }}
<span style="font-weight: bold; font-size: 1.1em;">{{ classInfo.subject_id }}<sub v-if="oldID != undefined">[{{ oldID }}]</sub></span> {{ classInfo.title }}
</v-card-text>
</div>
</v-card>
Expand Down Expand Up @@ -123,6 +123,17 @@ export default {
cardClass: function (classInfo) {
return `classbox ${this.courseColor(classInfo)}`;
}
},
computed: {
oldID: function() {
const subjectIndex = this.$store.state.subjectsIndex[this.classInfo.subject_id];
if (subjectIndex !== undefined) {
const subject = this.$store.state.subjectsInfo[subjectIndex];
return subject.old_id;
} else {
return undefined;
}
}
}
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClassInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</v-btn>
</div>
<div style="padding: 0 0.5em 0 0;">
<h3>{{ currentSubject.subject_id }}</h3>
<h3>{{ currentSubject.subject_id }}<sub v-if="currentSubject.old_id !== undefined">[{{currentSubject.old_id}}]</sub></h3>
</div>
<div style="margin-left:auto">
<v-btn icon style="margin: 0;" data-cy="closeClassInfoButton" @click="$store.commit('clearClassInfoStack')">
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClassSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var unitsGte15 = new MathFilter('>15', '>15', [15, undefined], false, ['total_un
var termFall = new BooleanFilter('Fall', 'FA', false, ['offered_fall']);
var termIAP = new BooleanFilter('IAP', 'IAP', false, ['offered_IAP']);
var termSpring = new BooleanFilter('Spring', 'SP', false, ['offered_spring']);
var textFilter = new RegexFilter('Subject ID', 'ID', '', 'nameInput', ['subject_id', 'title'], 'OR');
var textFilter = new RegexFilter('Subject ID', 'ID', '', 'nameInput', ['subject_id', 'title', 'old_id'], 'OR');
var instructorFilter = new ArrayFilter('Instructor', 'Prof', RegexFilter, ['', 'nameInput'], ['instructors'], 'OR');
export default {
Expand Down
17 changes: 14 additions & 3 deletions src/components/ImportExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</template>

<script>
import simpleSSMixin from './../mixins/simpleSelectedSubjects.js';
import simpleSSMixin from './../mixins/sanitizeSubjects.js';
export default {
name: 'ImportExport',
Expand Down Expand Up @@ -156,7 +156,7 @@ export default {
document.body.removeChild(element);
},
importRoad: function (event) {
importRoad: async function (event) {
let fail = false;
// check for legal input
if (this.inputtext === '' ||
Expand Down Expand Up @@ -196,6 +196,17 @@ export default {
subject = this.$store.state.genericCourses[this.$store.state.genericIndex[s.subject_id]];
}
if (subject == undefined) {
const oldSubjects = this.$store.state.subjectsInfo.filter((subj) => {
return subj.old_id == s.subject_id;
});
if (oldSubjects.length > 0) {
subject = oldSubjects[0];
s.subject_id = subject.subject_id;
}
}
if (subject !== undefined) {
expectedFields.forEach((f) => {
if (s[f] === undefined) {
Expand All @@ -216,7 +227,7 @@ export default {
});
// convert selected subjects to more convenient format
const simpless = this.getSimpleSelectedSubjects(ss);
const simpless = await this.getSimpleSelectedSubjects(ss);
this.$emit('add-road', this.roadtitle, obj.coursesOfStudy, simpless, obj.progressOverrides);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SubjectScroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<v-card class="subject" :data-cy="'subjectInScroller'+index" @click="$emit('click-subject', {subject_id:subject.subject_id,index:index})">
<div :class="[courseColor(subject), shouldLighten(subject)]" style="height:100%;">
<v-card-text class="cardtext pa-1">
<div><b>{{ subject.subject_id }}</b></div>
<div><b>{{ subject.subject_id }}<sub v-if="subject.old_id !== undefined">[{{subject.old_id}}]</sub></b></div>
<p class="subject-title">
{{ subject.title }}
</p>
Expand Down
File renamed without changes.
74 changes: 71 additions & 3 deletions src/stores/courseData.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const getDefaultState = () => {
// none: no update to audit is needed (for changes like road name)
fulfillmentNeeded: 'all',
// list of road IDs that have not been retrieved from the server yet
unretrieved: []
unretrieved: [],
loadSubjectsPromise: undefined,
loadedSubjects: false,
roadsToMigrate: []
};
};

Expand Down Expand Up @@ -76,6 +79,33 @@ const store = new Vuex.Store({
state.roads[state.activeRoad].changed = moment().format(DATE_FORMAT);
state.fulfillmentNeeded = event;
},
migrateOldSubjects(state, roadID) {
for (var i = 0; i < 16; i++) {
for (var j = 0; j < state.roads[roadID].contents.selectedSubjects[i].length; j++) {
const subject = state.roads[roadID].contents.selectedSubjects[i][j];

const subjectIndex = state.subjectsIndex[subject.subject_id];
const genericIndex = state.genericIndex[subject.subject_id];

const notInCatalog = subjectIndex == undefined && genericIndex == undefined;
const isHistorical = subjectIndex != undefined && state.subjectsInfo[subjectIndex].is_historical;

if (notInCatalog || isHistorical) {
// Look for subject with old ID
const oldSubjects = state.subjectsInfo.filter((subj) => {
return subj.old_id == subject.subject_id;
});

if (oldSubjects.length > 0) {
const oldSubject = oldSubjects[0];
subject.subject_id = oldSubject.subject_id;
subject.title = oldSubject.title;
subject.units = oldSubject.total_units;
}
}
}
}
},
allowCookies (state) {
state.cookiesAllowed = true;
},
Expand Down Expand Up @@ -262,6 +292,10 @@ const store = new Vuex.Store({
Vue.delete(state.roads, oldid);
state.ignoreRoadChanges = true;
state.fulfillmentNeeded = 'none';
const migrationIndex = state.roadsToMigrate.indexOf(oldid);
if (migrationIndex >= 0) {
state.roadsToMigrate.splice(migrationIndex, 1, newid);
}
},
setActiveRoad (state, activeRoad) {
state.activeRoad = activeRoad;
Expand Down Expand Up @@ -323,16 +357,35 @@ const store = new Vuex.Store({
// Reset fulfillment needed to default of all
resetFulfillmentNeeded (state) {
state.fulfillmentNeeded = 'all';
},
setLoadSubjectsPromise (state, promise) {
state.loadSubjectsPromise = promise;
},
setSubjectsLoaded (state) {
state.subjectsLoaded = true;
},
queueRoadMigration (state, roadID) {
state.roadsToMigrate.push(roadID);
},
clearMigrationQueue (state) {
state.roadsToMigrate = [];
}
},
actions: {
async loadAllSubjects ({ commit }) {
const response = await axios.get(process.env.VUE_APP_FIREROAD_URL + '/courses/all?full=true');
async loadAllSubjects ({ commit, state }) {
const promise = axios.get(process.env.VUE_APP_FIREROAD_URL + '/courses/all?full=true');
commit('setLoadSubjectsPromise', promise);
const response = await promise;
commit('setSubjectsLoaded');
commit('setSubjectsInfo', response.data);
commit('setFullSubjectsInfoLoaded', true);
commit('parseGenericCourses');
commit('parseGenericIndex');
commit('parseSubjectsIndex');
for (let roadID of state.roadsToMigrate) {
commit('migrateOldSubjects', roadID);
}
commit('clearMigrationQueue');
},
addAtPlaceholder ({ commit, state }, index) {
const newClass = {
Expand All @@ -344,6 +397,21 @@ const store = new Vuex.Store({
};
commit('addClass', newClass);
commit('cancelAddFromCard');
},
async waitLoadSubjects ({ dispatch, state }) {
if (state.loadSubjectsPromise != undefined) {
return state.loadSubjectsPromise;
} else {
return dispatch("loadAllSubjects");
}
},
waitAndMigrateOldSubjects({ dispatch, commit, state }, roadID) {
if (state.subjectsLoaded) {
commit("migrateOldSubjects", roadID);
} else {
commit("queueRoadMigration", roadID);
dispatch("waitLoadSubjects");
}
}
}
});
Expand Down

0 comments on commit a7822a5

Please sign in to comment.