From 4a0a53cf84213094c6f90881935cf64e19b6e9dd Mon Sep 17 00:00:00 2001 From: Victoria Date: Sat, 23 Mar 2019 02:31:38 -0400 Subject: [PATCH 1/7] Modify listings in place to stop redraw --- .../sidebar/interested-courses/component.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index eeba75e6..7dec3cf8 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -51,7 +51,34 @@ export class InterestedCoursesComponent implements OnInit { .includes('course') .includes('course.subject') .all().then((listings) => { - this.listings = listings.data; + //this.listings = listings.data; + for (let i = 0; i < listings.data.length; ++i) { + let inCurList: boolean = false; + console.log(listings.data[i]); + for (let j = 0; j < this.listings.length; ++j) { + if (listings.data[i].id == this.listings[j].id) { + inCurList = true; + console.log("inCurList is True"); + } + } + + if (!inCurList) { + this.listings.push(listings.data[i]); + } + } + + for (let i = 0; i < this.listings.length; ++i) { + let removeCurList: boolean = true; + for (let j = 0; j < listings.data.length; ++j) { + if (this.listings[j].id == listings.data[i].id) { + removeCurList = false; + } + } + + if (removeCurList) { + this.listings.splice(i, 1); + } + } this.conflictsService.populateConflictsCache(this.listings); this.isLoaded = true; }); From 11e17546e66d218beb9d0a841db73e0317e8c65b Mon Sep 17 00:00:00 2001 From: Victoria Date: Mon, 25 Mar 2019 00:05:07 -0400 Subject: [PATCH 2/7] Rename listings array --- .../sidebar/interested-courses/component.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index 97f00e2d..520cbfbc 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -55,33 +55,40 @@ export class InterestedCoursesComponent implements OnInit { .includes('sections.listing') .includes('course') .includes('course.subject') - .all().then((listings) => { + .all().then((newListings) => { //this.listings = listings.data; - for (let i = 0; i < listings.data.length; ++i) { + + /* + oldListingsSet = new Set(this.listings.map((listing) => listing.id)); + for (let new_listing of listings) + */ + for (let i = 0; i < newListings.data.length; ++i) { let inCurList: boolean = false; - console.log(listings.data[i]); + console.log(newListings.data[i]); for (let j = 0; j < this.listings.length; ++j) { - if (listings.data[i].id == this.listings[j].id) { + if (newListings.data[i].id == this.listings[j].id) { inCurList = true; console.log("inCurList is True"); } } if (!inCurList) { - this.listings.push(listings.data[i]); + this.listings.push(newListings.data[i]); } } for (let i = 0; i < this.listings.length; ++i) { let removeCurList: boolean = true; - for (let j = 0; j < listings.data.length; ++j) { - if (this.listings[j].id == listings.data[i].id) { + for (let j = 0; j < newListings.data.length; ++j) { + if (this.listings[i].id == newListings.data[j].id) { removeCurList = false; + console.log("removeCurList is False"); } } if (removeCurList) { this.listings.splice(i, 1); + console.log("Removed"); } } this.conflictsService.populateConflictsCache(this.listings); From 21d048818df29ee51b786f6c3ac3152fa1003fe7 Mon Sep 17 00:00:00 2001 From: Victoria Date: Tue, 26 Mar 2019 02:48:03 -0400 Subject: [PATCH 3/7] Refactor to decrease run time --- .../sidebar/interested-courses/component.ts | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index 520cbfbc..8e355e94 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -8,6 +8,8 @@ import 'rxjs/Rx'; import {Subject, Subscription} from 'rxjs/Rx'; import * as domtoimage from 'dom-to-image'; + + @Component({ selector: 'interested-courses', templateUrl: './component.html', @@ -18,9 +20,12 @@ export class InterestedCoursesComponent implements OnInit { listings: Listing[] = []; isLoaded: boolean = false; + oldListingsSet: Set; + newListingsSet: Set; private listingIds: Set; private subscription; + @Input() showStatusText: boolean = false; constructor ( @@ -56,41 +61,24 @@ export class InterestedCoursesComponent implements OnInit { .includes('course') .includes('course.subject') .all().then((newListings) => { - //this.listings = listings.data; - - /* - oldListingsSet = new Set(this.listings.map((listing) => listing.id)); - for (let new_listing of listings) - */ - for (let i = 0; i < newListings.data.length; ++i) { - let inCurList: boolean = false; - console.log(newListings.data[i]); - for (let j = 0; j < this.listings.length; ++j) { - if (newListings.data[i].id == this.listings[j].id) { - inCurList = true; - console.log("inCurList is True"); - } - } - + this.oldListingsSet = new Set(this.listings.map((listing) => listing.id)); + this.newListingsSet = new Set(newListings.data.map((benis) => benis.id)); + for (let i in newListings.data) { + let inCurList: boolean = this.oldListingsSet.has(newListings.data[i].id); if (!inCurList) { this.listings.push(newListings.data[i]); - } - } - for (let i = 0; i < this.listings.length; ++i) { - let removeCurList: boolean = true; - for (let j = 0; j < newListings.data.length; ++j) { - if (this.listings[i].id == newListings.data[j].id) { - removeCurList = false; - console.log("removeCurList is False"); - } } + } + for( let j = 0; j < this.listings.length; ++j) { + let removeCurList: boolean = !this.newListingsSet.has(this.listings[j].id); if (removeCurList) { - this.listings.splice(i, 1); - console.log("Removed"); + this.listings.splice(j, 1); + } } + this.conflictsService.populateConflictsCache(this.listings); this.isLoaded = true; }); From 4a35d36fd92b52dec6f56bcc7c19f2f46e802f3d Mon Sep 17 00:00:00 2001 From: Victoria Date: Tue, 26 Mar 2019 03:08:03 -0400 Subject: [PATCH 4/7] Rename variables --- web/src/app/sidebar/interested-courses/component.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index 8e355e94..db281860 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -20,8 +20,6 @@ export class InterestedCoursesComponent implements OnInit { listings: Listing[] = []; isLoaded: boolean = false; - oldListingsSet: Set; - newListingsSet: Set; private listingIds: Set; private subscription; @@ -61,10 +59,10 @@ export class InterestedCoursesComponent implements OnInit { .includes('course') .includes('course.subject') .all().then((newListings) => { - this.oldListingsSet = new Set(this.listings.map((listing) => listing.id)); - this.newListingsSet = new Set(newListings.data.map((benis) => benis.id)); + let oldListingsSet = new Set(this.listings.map((listing) => listing.id)); + let newListingsSet = new Set(newListings.data.map((newListing) => newListing.id)); for (let i in newListings.data) { - let inCurList: boolean = this.oldListingsSet.has(newListings.data[i].id); + let inCurList: boolean = oldListingsSet.has(newListings.data[i].id); if (!inCurList) { this.listings.push(newListings.data[i]); @@ -72,7 +70,7 @@ export class InterestedCoursesComponent implements OnInit { } for( let j = 0; j < this.listings.length; ++j) { - let removeCurList: boolean = !this.newListingsSet.has(this.listings[j].id); + let removeCurList: boolean = !newListingsSet.has(this.listings[j].id); if (removeCurList) { this.listings.splice(j, 1); From fc7802a90728cad373f57b5560562519cf22668a Mon Sep 17 00:00:00 2001 From: Victoria Date: Tue, 2 Apr 2019 19:43:49 -0400 Subject: [PATCH 5/7] Remove extra newlines --- web/src/app/sidebar/interested-courses/component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index db281860..7f648993 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -65,7 +65,6 @@ export class InterestedCoursesComponent implements OnInit { let inCurList: boolean = oldListingsSet.has(newListings.data[i].id); if (!inCurList) { this.listings.push(newListings.data[i]); - } } @@ -73,7 +72,6 @@ export class InterestedCoursesComponent implements OnInit { let removeCurList: boolean = !newListingsSet.has(this.listings[j].id); if (removeCurList) { this.listings.splice(j, 1); - } } From 3b27dac007ac25ceac2946d3f042f62e38ef377b Mon Sep 17 00:00:00 2001 From: Victoria Date: Mon, 8 Apr 2019 01:58:38 -0400 Subject: [PATCH 6/7] Use forEach for iteration --- .../sidebar/interested-courses/component.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index 7f648993..1a75be34 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -59,21 +59,29 @@ export class InterestedCoursesComponent implements OnInit { .includes('course') .includes('course.subject') .all().then((newListings) => { + // Create sets from the ids of the two arrays to check for memebership + // This allows the runtime to be linear let oldListingsSet = new Set(this.listings.map((listing) => listing.id)); let newListingsSet = new Set(newListings.data.map((newListing) => newListing.id)); - for (let i in newListings.data) { - let inCurList: boolean = oldListingsSet.has(newListings.data[i].id); + + // Iterate over new listings, and add each new listing if it is not already + // present in the current listings + newListings.data.forEach((newListing) => { + let inCurList: boolean = oldListingsSet.has(newListing.id); + if (!inCurList) { - this.listings.push(newListings.data[i]); + this.listings.push(newListing); } - } + }); + + // Remove listings that are not in the array of new listings + this.listings.forEach((listing, index) => { + let removeCurList: boolean = !newListingsSet.has(listing.id); - for( let j = 0; j < this.listings.length; ++j) { - let removeCurList: boolean = !newListingsSet.has(this.listings[j].id); if (removeCurList) { - this.listings.splice(j, 1); + this.listings.splice(index, 1); } - } + }); this.conflictsService.populateConflictsCache(this.listings); this.isLoaded = true; From ddebf8ad6ab05dcd8a2c76fc2498ca5c8c8119d9 Mon Sep 17 00:00:00 2001 From: Victoria Date: Mon, 8 Apr 2019 02:05:29 -0400 Subject: [PATCH 7/7] Remove excess newlines --- web/src/app/sidebar/interested-courses/component.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/web/src/app/sidebar/interested-courses/component.ts b/web/src/app/sidebar/interested-courses/component.ts index 1a75be34..6474ae95 100644 --- a/web/src/app/sidebar/interested-courses/component.ts +++ b/web/src/app/sidebar/interested-courses/component.ts @@ -8,8 +8,6 @@ import 'rxjs/Rx'; import {Subject, Subscription} from 'rxjs/Rx'; import * as domtoimage from 'dom-to-image'; - - @Component({ selector: 'interested-courses', templateUrl: './component.html', @@ -23,7 +21,6 @@ export class InterestedCoursesComponent implements OnInit { private listingIds: Set; private subscription; - @Input() showStatusText: boolean = false; constructor (