activities: fix updateExistingElements, rename
forgot to wipe this._ordering, so search was attempting to run on non-existent items. Also renamed the two functions to appendNewItems and replaceWithNewItems, this makes more sense to me.
This commit is contained in:
@@ -925,7 +925,7 @@ export class accountsList extends PaginatedList {
|
|||||||
getPageEndpoint: "/users",
|
getPageEndpoint: "/users",
|
||||||
itemsPerPage: 40,
|
itemsPerPage: 40,
|
||||||
maxItemsLoadedForSearch: 200,
|
maxItemsLoadedForSearch: 200,
|
||||||
newElementsFromPage: (resp: paginatedDTO) => {
|
appendNewItems: (resp: paginatedDTO) => {
|
||||||
for (let u of ((resp as UsersDTO).users || [])) {
|
for (let u of ((resp as UsersDTO).users || [])) {
|
||||||
if (u.id in this.users) {
|
if (u.id in this.users) {
|
||||||
this.users[u.id].update(u);
|
this.users[u.id].update(u);
|
||||||
@@ -940,7 +940,7 @@ export class accountsList extends PaginatedList {
|
|||||||
this._search.ascending
|
this._search.ascending
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
updateExistingElementsFromPage: (resp: paginatedDTO) => {
|
replaceWithNewItems: (resp: paginatedDTO) => {
|
||||||
let accountsOnDOM: { [id: string]: boolean } = {};
|
let accountsOnDOM: { [id: string]: boolean } = {};
|
||||||
|
|
||||||
for (let id of Object.keys(this.users)) { accountsOnDOM[id] = true; }
|
for (let id of Object.keys(this.users)) { accountsOnDOM[id] = true; }
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ export class activityList extends PaginatedList {
|
|||||||
getPageEndpoint: "/activity",
|
getPageEndpoint: "/activity",
|
||||||
itemsPerPage: 20,
|
itemsPerPage: 20,
|
||||||
maxItemsLoadedForSearch: 200,
|
maxItemsLoadedForSearch: 200,
|
||||||
newElementsFromPage: (resp: paginatedDTO) => {
|
appendNewItems: (resp: paginatedDTO) => {
|
||||||
let ordering: string[] = this._search.ordering;
|
let ordering: string[] = this._search.ordering;
|
||||||
for (let act of ((resp as ActivitiesDTO).activities || [])) {
|
for (let act of ((resp as ActivitiesDTO).activities || [])) {
|
||||||
this.activities[act.id] = new Activity(act);
|
this.activities[act.id] = new Activity(act);
|
||||||
@@ -511,12 +511,16 @@ export class activityList extends PaginatedList {
|
|||||||
}
|
}
|
||||||
this._search.setOrdering(ordering, this._c.defaultSortField, this.ascending);
|
this._search.setOrdering(ordering, this._c.defaultSortField, this.ascending);
|
||||||
},
|
},
|
||||||
updateExistingElementsFromPage: (resp: paginatedDTO) => {
|
replaceWithNewItems: (resp: paginatedDTO) => {
|
||||||
// FIXME: Implement updates to existing elements, rather than just wiping each time.
|
// FIXME: Implement updates to existing elements, rather than just wiping each time.
|
||||||
|
|
||||||
|
// Remove existing items
|
||||||
for (let id of Object.keys(this.activities)) {
|
for (let id of Object.keys(this.activities)) {
|
||||||
delete this.activities[id];
|
delete this.activities[id];
|
||||||
}
|
}
|
||||||
this._c.newElementsFromPage(resp);
|
// And wipe their ordering
|
||||||
|
this._search.setOrdering([], this._c.defaultSortField, this.ascending);
|
||||||
|
this._c.appendNewItems(resp);
|
||||||
},
|
},
|
||||||
defaultSortField: ACTIVITY_DEFAULT_SORT_FIELD,
|
defaultSortField: ACTIVITY_DEFAULT_SORT_FIELD,
|
||||||
defaultSortAscending: ACTIVITY_DEFAULT_SORT_ASCENDING,
|
defaultSortAscending: ACTIVITY_DEFAULT_SORT_ASCENDING,
|
||||||
|
|||||||
+5
-5
@@ -85,8 +85,8 @@ export interface PaginatedListConfig {
|
|||||||
getPageEndpoint: string;
|
getPageEndpoint: string;
|
||||||
itemsPerPage: number;
|
itemsPerPage: number;
|
||||||
maxItemsLoadedForSearch: number;
|
maxItemsLoadedForSearch: number;
|
||||||
newElementsFromPage: (resp: paginatedDTO) => void;
|
appendNewItems: (resp: paginatedDTO) => void;
|
||||||
updateExistingElementsFromPage: (resp: paginatedDTO) => void;
|
replaceWithNewItems: (resp: paginatedDTO) => void;
|
||||||
defaultSortField: string;
|
defaultSortField: string;
|
||||||
defaultSortAscending: boolean;
|
defaultSortAscending: boolean;
|
||||||
pageLoadCallback?: (req: XMLHttpRequest) => void;
|
pageLoadCallback?: (req: XMLHttpRequest) => void;
|
||||||
@@ -238,7 +238,7 @@ export abstract class PaginatedList {
|
|||||||
let timer = this._search.timeSearches ? performance.now() : null;
|
let timer = this._search.timeSearches ? performance.now() : null;
|
||||||
if (visible) this._visible = elements;
|
if (visible) this._visible = elements;
|
||||||
else this._visible = this._search.ordering.filter(v => !elements.includes(v));
|
else this._visible = this._search.ordering.filter(v => !elements.includes(v));
|
||||||
console.log(elements.length, visible, this._visible.length);
|
// console.log(elements.length, visible, this._visible.length);
|
||||||
this._counter.shown = this._visible.length;
|
this._counter.shown = this._visible.length;
|
||||||
if (this._visible.length == 0) {
|
if (this._visible.length == 0) {
|
||||||
this._container.textContent = ``;
|
this._container.textContent = ``;
|
||||||
@@ -341,7 +341,7 @@ export abstract class PaginatedList {
|
|||||||
|
|
||||||
this.lastPage = resp.last_page;
|
this.lastPage = resp.last_page;
|
||||||
|
|
||||||
this._c.updateExistingElementsFromPage(resp);
|
this._c.replaceWithNewItems(resp);
|
||||||
|
|
||||||
this._counter.loaded = this._search.ordering.length;
|
this._counter.loaded = this._search.ordering.length;
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ export abstract class PaginatedList {
|
|||||||
|
|
||||||
this.lastPage = resp.last_page;
|
this.lastPage = resp.last_page;
|
||||||
|
|
||||||
this._c.newElementsFromPage(resp);
|
this._c.appendNewItems(resp);
|
||||||
|
|
||||||
this._counter.loaded = this._search.ordering.length;
|
this._counter.loaded = this._search.ordering.length;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user