MOBILE-3200 database: Fix update access data on group change
parent
8d95636690
commit
1652e4d8f2
|
@ -180,29 +180,34 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @param showErrors If show errors to the user of hide them.
|
* @param showErrors If show errors to the user of hide them.
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<any> {
|
protected async fetchContent(refresh: boolean = false, sync: boolean = false, showErrors: boolean = false): Promise<any> {
|
||||||
let canAdd = false,
|
let canAdd = false,
|
||||||
canSearch = false;
|
canSearch = false;
|
||||||
|
|
||||||
return this.dataProvider.getDatabase(this.courseId, this.module.id).then((data) => {
|
this.data = await this.dataProvider.getDatabase(this.courseId, this.module.id);
|
||||||
this.data = data;
|
this.hasComments = this.data.comments;
|
||||||
this.hasComments = data.comments;
|
|
||||||
|
|
||||||
this.description = data.intro || data.description;
|
this.description = this.data.intro || this.data.description;
|
||||||
this.dataRetrieved.emit(data);
|
this.dataRetrieved.emit(this.data);
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
|
try {
|
||||||
// Try to synchronize the data.
|
// Try to synchronize the data.
|
||||||
return this.syncActivity(showErrors).catch(() => {
|
await this.syncActivity(showErrors);
|
||||||
|
} catch (error) {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}
|
||||||
return this.dataProvider.getDatabaseAccessInformation(this.data.id, {cmId: this.module.id});
|
|
||||||
}).then((accessData) => {
|
|
||||||
this.access = accessData;
|
|
||||||
|
|
||||||
if (!accessData.timeavailable) {
|
this.groupInfo = await this.groupsProvider.getActivityGroupInfo(this.data.coursemodule);
|
||||||
|
this.selectedGroup = this.groupsProvider.validateGroupId(this.selectedGroup, this.groupInfo);
|
||||||
|
|
||||||
|
this.access = await this.dataProvider.getDatabaseAccessInformation(this.data.id, {
|
||||||
|
cmId: this.module.id,
|
||||||
|
groupId: this.selectedGroup || undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.access.timeavailable) {
|
||||||
const time = this.timeUtils.timestamp();
|
const time = this.timeUtils.timestamp();
|
||||||
|
|
||||||
this.timeAvailableFrom = this.data.timeavailablefrom && time < this.data.timeavailablefrom ?
|
this.timeAvailableFrom = this.data.timeavailablefrom && time < this.data.timeavailablefrom ?
|
||||||
|
@ -214,35 +219,28 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
|
|
||||||
this.isEmpty = true;
|
this.isEmpty = true;
|
||||||
this.groupInfo = null;
|
this.groupInfo = null;
|
||||||
|
} else {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
canSearch = true;
|
canSearch = true;
|
||||||
canAdd = accessData.canaddentry;
|
canAdd = this.access.canaddentry;
|
||||||
|
|
||||||
return this.groupsProvider.getActivityGroupInfo(this.data.coursemodule).then((groupInfo) => {
|
|
||||||
this.groupInfo = groupInfo;
|
|
||||||
this.selectedGroup = this.groupsProvider.validateGroupId(this.selectedGroup, groupInfo);
|
|
||||||
});
|
|
||||||
}).then(() => {
|
|
||||||
return this.dataProvider.getFields(this.data.id, {cmId: this.module.id}).then((fields) => {
|
|
||||||
if (fields.length == 0) {
|
|
||||||
canSearch = false;
|
|
||||||
canAdd = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fields = await this.dataProvider.getFields(this.data.id, {cmId: this.module.id});
|
||||||
this.search.advanced = [];
|
this.search.advanced = [];
|
||||||
|
|
||||||
this.fields = this.utils.arrayToObject(fields, 'id');
|
this.fields = this.utils.arrayToObject(fields, 'id');
|
||||||
this.fieldsArray = this.utils.objectToArray(this.fields);
|
this.fieldsArray = this.utils.objectToArray(this.fields);
|
||||||
|
if (this.fieldsArray.length == 0) {
|
||||||
|
canSearch = false;
|
||||||
|
canAdd = false;
|
||||||
|
}
|
||||||
|
|
||||||
return this.fetchEntriesData();
|
try {
|
||||||
});
|
await this.fetchEntriesData();
|
||||||
}).finally(() => {
|
} finally {
|
||||||
this.canAdd = canAdd;
|
this.canAdd = canAdd;
|
||||||
this.canSearch = canSearch;
|
this.canSearch = canSearch;
|
||||||
this.fillContextMenu(refresh);
|
this.fillContextMenu(refresh);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,13 +250,6 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
*/
|
*/
|
||||||
protected fetchEntriesData(): Promise<any> {
|
protected fetchEntriesData(): Promise<any> {
|
||||||
|
|
||||||
return this.dataProvider.getDatabaseAccessInformation(this.data.id, {
|
|
||||||
groupId: this.selectedGroup,
|
|
||||||
cmId: this.module.id,
|
|
||||||
}).then((accessData) => {
|
|
||||||
// Update values for current group.
|
|
||||||
this.access.canaddentry = accessData.canaddentry;
|
|
||||||
|
|
||||||
const search = this.search.searching && !this.search.searchingAdvanced ? this.search.text : undefined;
|
const search = this.search.searching && !this.search.searchingAdvanced ? this.search.text : undefined;
|
||||||
const advSearch = this.search.searching && this.search.searchingAdvanced ? this.search.advanced : undefined;
|
const advSearch = this.search.searching && this.search.searchingAdvanced ? this.search.advanced : undefined;
|
||||||
|
|
||||||
|
@ -269,7 +260,6 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
sort: Number(this.search.sortBy),
|
sort: Number(this.search.sortBy),
|
||||||
order: this.search.sortDirection,
|
order: this.search.sortDirection,
|
||||||
page: this.search.page,
|
page: this.search.page,
|
||||||
});
|
|
||||||
}).then((entries) => {
|
}).then((entries) => {
|
||||||
const numEntries = entries.entries.length;
|
const numEntries = entries.entries.length;
|
||||||
const numOfflineEntries = entries.offlineEntries.length;
|
const numOfflineEntries = entries.offlineEntries.length;
|
||||||
|
@ -390,18 +380,29 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
* @param groupId Group ID.
|
* @param groupId Group ID.
|
||||||
* @return Resolved when new group is selected or rejected if not.
|
* @return Resolved when new group is selected or rejected if not.
|
||||||
*/
|
*/
|
||||||
setGroup(groupId: number): Promise<any> {
|
async setGroup(groupId: number): Promise<void> {
|
||||||
this.selectedGroup = groupId;
|
this.selectedGroup = groupId;
|
||||||
this.search.page = 0;
|
this.search.page = 0;
|
||||||
|
|
||||||
return this.fetchEntriesData().then(() => {
|
// Only update canAdd if there's any field, otheerwise, canAdd will remain false.
|
||||||
|
if (this.fieldsArray.length > 0) {
|
||||||
|
// Update values for current group.
|
||||||
|
this.access = await this.dataProvider.getDatabaseAccessInformation(this.data.id, {
|
||||||
|
groupId: this.selectedGroup,
|
||||||
|
cmId: this.module.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.canAdd = this.access.canaddentry;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.fetchEntriesData();
|
||||||
|
|
||||||
// Log activity view for coherence with Moodle web.
|
// Log activity view for coherence with Moodle web.
|
||||||
return this.logView();
|
return this.logView();
|
||||||
}).catch((message) => {
|
} catch (error) {
|
||||||
this.domUtils.showErrorModalDefault(message, 'core.course.errorgetmodule', true);
|
this.domUtils.showErrorModalDefault(error, 'core.course.errorgetmodule', true);
|
||||||
|
}
|
||||||
return Promise.reject(null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue