MOBILE-3200 database: Do not need courseId to delete an offline entry

main
Pau Ferrer Ocaña 2020-09-29 14:40:51 +02:00
parent 1652e4d8f2
commit 6d7a96d8df
1 changed files with 44 additions and 29 deletions

View File

@ -18,7 +18,6 @@ import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreFileUploaderProvider } from '@core/fileuploader/providers/fileuploader';
import { AddonModDataFieldsDelegate } from './fields-delegate';
@ -35,12 +34,19 @@ import { CoreRatingOfflineProvider } from '@core/rating/providers/offline';
@Injectable()
export class AddonModDataHelperProvider {
constructor(private sitesProvider: CoreSitesProvider, protected dataProvider: AddonModDataProvider,
private translate: TranslateService, private fieldsDelegate: AddonModDataFieldsDelegate,
private dataOffline: AddonModDataOfflineProvider, private fileUploaderProvider: CoreFileUploaderProvider,
private textUtils: CoreTextUtilsProvider, private eventsProvider: CoreEventsProvider, private utils: CoreUtilsProvider,
private domUtils: CoreDomUtilsProvider, private courseProvider: CoreCourseProvider,
private ratingOffline: CoreRatingOfflineProvider) {}
constructor(
protected sitesProvider: CoreSitesProvider,
protected dataProvider: AddonModDataProvider,
protected translate: TranslateService,
protected fieldsDelegate: AddonModDataFieldsDelegate,
protected dataOffline: AddonModDataOfflineProvider,
protected fileUploaderProvider: CoreFileUploaderProvider,
protected textUtils: CoreTextUtilsProvider,
protected eventsProvider: CoreEventsProvider,
protected domUtils: CoreDomUtilsProvider,
protected courseProvider: CoreCourseProvider,
protected ratingOffline: CoreRatingOfflineProvider
) {}
/**
* Returns the record with the offline actions applied.
@ -632,35 +638,44 @@ export class AddonModDataHelperProvider {
* @param courseId Course ID. It not defined, it will be fetched.
* @param siteId Site ID. If not defined, current site.
*/
showDeleteEntryModal(dataId: number, entryId: number, courseId?: number, siteId?: string): void {
async showDeleteEntryModal(dataId: number, entryId: number, courseId?: number, siteId?: string): Promise<void> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
this.domUtils.showDeleteConfirm('addon.mod_data.confirmdeleterecord').then(() => {
const modal = this.domUtils.showModalLoading();
let modal;
try {
await this.domUtils.showDeleteConfirm('addon.mod_data.confirmdeleterecord');
return this.getActivityCourseIdIfNotSet(dataId, courseId, siteId).then((courseId) => {
return this.dataProvider.deleteEntry(dataId, entryId, courseId, siteId);
}).catch((message) => {
modal = this.domUtils.showModalLoading();
try {
if (entryId > 0) {
courseId = await this.getActivityCourseIdIfNotSet(dataId, courseId, siteId);
}
this.dataProvider.deleteEntry(dataId, entryId, courseId, siteId);
} catch (message) {
this.domUtils.showErrorModalDefault(message, 'addon.mod_data.errordeleting', true);
return Promise.reject(null);
}).then(() => {
return this.utils.allPromises([
this.dataProvider.invalidateEntryData(dataId, entryId, siteId),
this.dataProvider.invalidateEntriesData(dataId, siteId)
]).catch(() => {
modal && modal.dismiss();
return;
}
try {
await this.dataProvider.invalidateEntryData(dataId, entryId, siteId);
await this.dataProvider.invalidateEntriesData(dataId, siteId);
} catch (error) {
// Ignore errors.
});
}).then(() => {
}
this.eventsProvider.trigger(AddonModDataProvider.ENTRY_CHANGED, {dataId, entryId, deleted: true}, siteId);
this.domUtils.showToast('addon.mod_data.recorddeleted', true, 3000);
}).finally(() => {
modal.dismiss();
});
}).catch(() => {
} catch (error) {
// Ignore error, it was already displayed.
});
}
modal && modal.dismiss();
}
/**