MOBILE-4081 database: Fix wrong entry displayed after sort
parent
6b0fbbeaa5
commit
413b69832b
|
@ -46,6 +46,8 @@ export class AddonModDataActionComponent implements OnInit {
|
||||||
@Input() title = ''; // Name of the module.
|
@Input() title = ''; // Name of the module.
|
||||||
@Input() group = 0; // Module group.
|
@Input() group = 0; // Module group.
|
||||||
@Input() offset?: number; // Offset of the entry.
|
@Input() offset?: number; // Offset of the entry.
|
||||||
|
@Input() sortBy?: string | number; // Sort by used to calculate the offset.
|
||||||
|
@Input() sortDirection?: string; // Sort direction used to calculate the offset.
|
||||||
|
|
||||||
siteId: string;
|
siteId: string;
|
||||||
userPicture?: string;
|
userPicture?: string;
|
||||||
|
@ -110,6 +112,8 @@ export class AddonModDataActionComponent implements OnInit {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
group: this.group,
|
group: this.group,
|
||||||
offset: this.offset,
|
offset: this.offset,
|
||||||
|
sortBy: this.sortBy,
|
||||||
|
sortDirection: this.sortDirection,
|
||||||
};
|
};
|
||||||
|
|
||||||
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
|
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
|
||||||
|
|
|
@ -39,7 +39,7 @@ import {
|
||||||
AddonModDataData,
|
AddonModDataData,
|
||||||
AddonModDataSearchEntriesAdvancedField,
|
AddonModDataSearchEntriesAdvancedField,
|
||||||
} from '../../services/data';
|
} from '../../services/data';
|
||||||
import { AddonModDataHelper } from '../../services/data-helper';
|
import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../services/data-helper';
|
||||||
import { AddonModDataAutoSyncData, AddonModDataSyncProvider, AddonModDataSyncResult } from '../../services/data-sync';
|
import { AddonModDataAutoSyncData, AddonModDataSyncProvider, AddonModDataSyncResult } from '../../services/data-sync';
|
||||||
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
|
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
|
||||||
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
|
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
|
||||||
|
@ -349,17 +349,20 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
entriesById[entry.id] = entry;
|
entriesById[entry.id] = entry;
|
||||||
|
|
||||||
const actions = AddonModDataHelper.getActions(this.database!, this.access!, entry);
|
const actions = AddonModDataHelper.getActions(this.database!, this.access!, entry);
|
||||||
const offset = this.search.searching
|
const options: AddonModDatDisplayFieldsOptions = {};
|
||||||
? 0
|
if (!this.search.searching) {
|
||||||
: this.search.page * AddonModDataProvider.PER_PAGE + index - numOfflineEntries;
|
options.offset = this.search.page * AddonModDataProvider.PER_PAGE + index - numOfflineEntries;
|
||||||
|
options.sortBy = this.search.sortBy;
|
||||||
|
options.sortDirection = this.search.sortDirection;
|
||||||
|
}
|
||||||
|
|
||||||
entriesHTML += AddonModDataHelper.displayShowFields(
|
entriesHTML += AddonModDataHelper.displayShowFields(
|
||||||
template,
|
template,
|
||||||
this.fieldsArray,
|
this.fieldsArray,
|
||||||
entry,
|
entry,
|
||||||
offset,
|
|
||||||
AddonModDataTemplateMode.LIST,
|
AddonModDataTemplateMode.LIST,
|
||||||
actions,
|
actions,
|
||||||
|
options,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -504,6 +507,8 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
const pageXOffset = this.entries.findIndex((entry) => entry.id == entryId);
|
const pageXOffset = this.entries.findIndex((entry) => entry.id == entryId);
|
||||||
if (pageXOffset >= 0) {
|
if (pageXOffset >= 0) {
|
||||||
params.offset = this.search.page * AddonModDataProvider.PER_PAGE + pageXOffset;
|
params.offset = this.search.page * AddonModDataProvider.PER_PAGE + pageXOffset;
|
||||||
|
params.sortBy = this.search.sortBy;
|
||||||
|
params.sortDirection = this.search.sortDirection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +561,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddonModDataSearchDataParams = {
|
export type AddonModDataSearchDataParams = {
|
||||||
sortBy: string;
|
sortBy: string | number;
|
||||||
sortDirection: string;
|
sortDirection: string;
|
||||||
page: number;
|
page: number;
|
||||||
text: string;
|
text: string;
|
||||||
|
|
|
@ -56,6 +56,8 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
protected fields: Record<number, AddonModDataField> = {};
|
protected fields: Record<number, AddonModDataField> = {};
|
||||||
protected fieldsArray: AddonModDataField[] = [];
|
protected fieldsArray: AddonModDataField[] = [];
|
||||||
protected logAfterFetch = true;
|
protected logAfterFetch = true;
|
||||||
|
protected sortBy = 0;
|
||||||
|
protected sortDirection = 'DESC';
|
||||||
|
|
||||||
moduleId = 0;
|
moduleId = 0;
|
||||||
courseId!: number;
|
courseId!: number;
|
||||||
|
@ -139,6 +141,9 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
this.title = CoreNavigator.getRouteParam<string>('title') || '';
|
this.title = CoreNavigator.getRouteParam<string>('title') || '';
|
||||||
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0;
|
this.selectedGroup = CoreNavigator.getRouteNumberParam('group') || 0;
|
||||||
this.offset = CoreNavigator.getRouteNumberParam('offset');
|
this.offset = CoreNavigator.getRouteNumberParam('offset');
|
||||||
|
this.sortDirection = CoreNavigator.getRouteParam('sortDirection') ?? this.sortDirection;
|
||||||
|
const sortBy = Number(CoreNavigator.getRouteParam('sortBy'));
|
||||||
|
this.sortBy = isNaN(sortBy) ? this.sortBy : sortBy;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CoreDomUtils.showErrorModal(error);
|
CoreDomUtils.showErrorModal(error);
|
||||||
|
|
||||||
|
@ -189,9 +194,13 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
template,
|
template,
|
||||||
this.fieldsArray,
|
this.fieldsArray,
|
||||||
this.entry!,
|
this.entry!,
|
||||||
this.offset,
|
|
||||||
AddonModDataTemplateMode.SHOW,
|
AddonModDataTemplateMode.SHOW,
|
||||||
actions,
|
actions,
|
||||||
|
{
|
||||||
|
offset: this.offset,
|
||||||
|
sortBy: this.sortBy,
|
||||||
|
sortDirection: this.sortDirection,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
this.showComments = actions.comments;
|
this.showComments = actions.comments;
|
||||||
|
@ -330,8 +339,8 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
|
|
||||||
const entries = await AddonModDataHelper.fetchEntries(this.database!, this.fieldsArray, {
|
const entries = await AddonModDataHelper.fetchEntries(this.database!, this.fieldsArray, {
|
||||||
groupId: this.selectedGroup,
|
groupId: this.selectedGroup,
|
||||||
sort: 0,
|
sort: this.sortBy,
|
||||||
order: 'DESC',
|
order: this.sortDirection,
|
||||||
page,
|
page,
|
||||||
perPage,
|
perPage,
|
||||||
});
|
});
|
||||||
|
|
|
@ -200,9 +200,9 @@ export class AddonModDataHelperProvider {
|
||||||
template: string,
|
template: string,
|
||||||
fields: AddonModDataField[],
|
fields: AddonModDataField[],
|
||||||
entry: AddonModDataEntry,
|
entry: AddonModDataEntry,
|
||||||
offset = 0,
|
|
||||||
mode: AddonModDataTemplateMode,
|
mode: AddonModDataTemplateMode,
|
||||||
actions: Record<AddonModDataAction, boolean>,
|
actions: Record<AddonModDataAction, boolean>,
|
||||||
|
options: AddonModDatDisplayFieldsOptions = {},
|
||||||
): string {
|
): string {
|
||||||
|
|
||||||
if (!template) {
|
if (!template) {
|
||||||
|
@ -233,8 +233,12 @@ export class AddonModDataHelperProvider {
|
||||||
} else if (action == 'approvalstatus') {
|
} else if (action == 'approvalstatus') {
|
||||||
render = Translate.instant('addon.mod_data.' + (entry.approved ? 'approved' : 'notapproved'));
|
render = Translate.instant('addon.mod_data.' + (entry.approved ? 'approved' : 'notapproved'));
|
||||||
} else {
|
} else {
|
||||||
render = '<addon-mod-data-action action="' + action + '" [entry]="entries[' + entry.id + ']" mode="' + mode +
|
render = `<addon-mod-data-action action="${action}" [entry]="entries[${entry.id}]" mode="${mode}" ` +
|
||||||
'" [database]="database" [title]="title" [offset]="' + offset + '" [group]="group" ></addon-mod-data-action>';
|
'[database]="database" [title]="title" ' +
|
||||||
|
(options.offset !== undefined ? `[offset]="${options.offset}" ` : '') +
|
||||||
|
(options.sortBy !== undefined ? `[sortBy]="${options.sortBy}" ` : '') +
|
||||||
|
(options.sortDirection !== undefined ? `sortDirection="${options.sortDirection}" ` : '') +
|
||||||
|
'[group]="group"></addon-mod-data-action>';
|
||||||
}
|
}
|
||||||
template = template.replace(replaceRegex, render);
|
template = template.replace(replaceRegex, render);
|
||||||
} else {
|
} else {
|
||||||
|
@ -822,3 +826,9 @@ export class AddonModDataHelperProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
export const AddonModDataHelper = makeSingleton(AddonModDataHelperProvider);
|
export const AddonModDataHelper = makeSingleton(AddonModDataHelperProvider);
|
||||||
|
|
||||||
|
export type AddonModDatDisplayFieldsOptions = {
|
||||||
|
sortBy?: string | number;
|
||||||
|
sortDirection?: string;
|
||||||
|
offset?: number;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue