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