MOBILE-4616 data: Move data constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:40:39 +02:00
parent 4934dcec99
commit 09791c8d20
19 changed files with 107 additions and 88 deletions

View File

@ -24,14 +24,13 @@ import {
AddonModDataData,
AddonModDataEntry,
AddonModDataGetDataAccessInformationWSResponse,
AddonModDataProvider,
AddonModDataTemplateMode,
} from '../../services/data';
import { AddonModDataHelper } from '../../services/data-helper';
import { AddonModDataOffline } from '../../services/data-offline';
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
import { CoreDomUtils } from '@services/utils/dom';
import { AddonModDataActionsMenuComponent, AddonModDataActionsMenuItem } from '../actionsmenu/actionsmenu';
import { ADDON_MOD_DATA_ENTRY_CHANGED, ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
/**
* Component that displays a database action.
@ -101,7 +100,7 @@ export class AddonModDataActionComponent implements OnInit {
title: this.title,
};
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
const basePath = ADDON_MOD_DATA_PAGE_NAME;
CoreNavigator.navigateToSitePath(
`${basePath}/${this.database.course}/${this.database.coursemodule}/edit/${this.entry.id}`,
{ params },
@ -120,7 +119,7 @@ export class AddonModDataActionComponent implements OnInit {
sortDirection: this.sortDirection,
};
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
const basePath = ADDON_MOD_DATA_PAGE_NAME;
CoreNavigator.navigateToSitePath(
`${basePath}/${this.database.course}/${this.database.coursemodule}/${this.entry.id}`,
{ params },
@ -140,7 +139,7 @@ export class AddonModDataActionComponent implements OnInit {
// Found. Just delete the action.
await AddonModDataOffline.deleteEntry(dataId, entryId, AddonModDataAction.DELETE, this.siteId);
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, this.siteId);
CoreEvents.trigger(ADDON_MOD_DATA_ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, this.siteId);
}
/**

View File

@ -29,7 +29,6 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import {
AddonModDataProvider,
AddonModData,
AddonModDataEntry,
AddonModDataTemplateType,
@ -40,13 +39,19 @@ import {
AddonModDataSearchEntriesAdvancedField,
} from '../../services/data';
import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../services/data-helper';
import { AddonModDataAutoSyncData, AddonModDataSyncProvider, AddonModDataSyncResult } from '../../services/data-sync';
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
import { AddonModDataAutoSyncData, AddonModDataSyncResult } from '../../services/data-sync';
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
import { AddonModDataComponentsCompileModule } from '../components-compile.module';
import { AddonModDataSearchComponent } from '../search/search';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreTime } from '@singletons/time';
import {
ADDON_MOD_DATA_AUTO_SYNCED,
ADDON_MOD_DATA_COMPONENT,
ADDON_MOD_DATA_ENTRIES_PER_PAGE,
ADDON_MOD_DATA_ENTRY_CHANGED,
ADDON_MOD_DATA_PAGE_NAME,
} from '../../constants';
const contentToken = '<!-- CORE-DATABASE-CONTENT-GOES-HERE -->';
@ -60,7 +65,7 @@ const contentToken = '<!-- CORE-DATABASE-CONTENT-GOES-HERE -->';
})
export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit, OnDestroy {
component = AddonModDataProvider.COMPONENT;
component = ADDON_MOD_DATA_COMPONENT;
pluginName = 'data';
access?: AddonModDataGetDataAccessInformationWSResponse;
@ -110,7 +115,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
hasOfflineRatings = false;
protected syncEventName = AddonModDataSyncProvider.AUTO_SYNCED;
protected syncEventName = ADDON_MOD_DATA_AUTO_SYNCED;
protected hasComments = false;
protected fieldsArray: AddonModDataField[] = [];
protected entryChangedObserver?: CoreEventObserver;
@ -134,7 +139,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
this.selectedGroup = this.group || 0;
// Refresh entries on change.
this.entryChangedObserver = CoreEvents.on(AddonModDataProvider.ENTRY_CHANGED, (eventData) => {
this.entryChangedObserver = CoreEvents.on(ADDON_MOD_DATA_ENTRY_CHANGED, (eventData) => {
if (this.database?.id == eventData.dataId) {
this.showLoading = true;
@ -303,8 +308,8 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
this.isEmpty = !numEntries && !numOfflineEntries;
this.hasNextPage = numEntries >= AddonModDataProvider.PER_PAGE && ((this.search.page + 1) *
AddonModDataProvider.PER_PAGE) < entries.totalcount;
this.hasNextPage = numEntries >= ADDON_MOD_DATA_ENTRIES_PER_PAGE && ((this.search.page + 1) *
ADDON_MOD_DATA_ENTRIES_PER_PAGE) < entries.totalcount;
this.hasOffline = !!entries.hasOfflineActions;
@ -355,7 +360,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
const actions = AddonModDataHelper.getActions(this.database!, this.access!, entry, AddonModDataTemplateMode.LIST);
const options: AddonModDatDisplayFieldsOptions = {};
if (!this.search.searching) {
options.offset = this.search.page * AddonModDataProvider.PER_PAGE + index - numOfflineEntries;
options.offset = this.search.page * ADDON_MOD_DATA_ENTRIES_PER_PAGE + index - numOfflineEntries;
options.sortBy = this.search.sortBy;
options.sortDirection = this.search.sortDirection;
}
@ -489,7 +494,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
};
CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/edit`,
`${ADDON_MOD_DATA_PAGE_NAME}/${this.courseId}/${this.module.id}/edit`,
{ params },
);
}
@ -509,14 +514,14 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
if (!this.search.searching) {
const pageXOffset = this.entries.findIndex((entry) => entry.id == entryId);
if (pageXOffset >= 0) {
params.offset = this.search.page * AddonModDataProvider.PER_PAGE + pageXOffset;
params.offset = this.search.page * ADDON_MOD_DATA_ENTRIES_PER_PAGE + pageXOffset;
params.sortBy = this.search.sortBy;
params.sortDirection = this.search.sortDirection;
}
}
CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/${entryId}`,
`${ADDON_MOD_DATA_PAGE_NAME}/${this.courseId}/${this.module.id}/${entryId}`,
{ params },
);
}
@ -550,7 +555,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
}
const params: Record<string, unknown> = {
perpage: AddonModDataProvider.PER_PAGE,
perpage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
search: !this.search.searchingAdvanced ? this.search.text : '',
sort: this.search.sortBy,
order: this.search.sortDirection,

View File

@ -13,3 +13,11 @@
// limitations under the License.
export const ADDON_MOD_DATA_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModData';
export const ADDON_MOD_DATA_COMPONENT = 'mmaModData';
export const ADDON_MOD_DATA_PAGE_NAME = 'mod_data';
export const ADDON_MOD_DATA_ENTRIES_PER_PAGE = 25;
export const ADDON_MOD_DATA_ENTRY_CHANGED = 'addon_mod_data_entry_changed';
export const ADDON_MOD_DATA_AUTO_SYNCED = 'addon_mod_data_autom_synced';

View File

@ -62,4 +62,4 @@ const routes: Routes = [
AddonModDataEditPage,
],
})
export class AddonModDataLazyModule {}
export default class AddonModDataLazyModule {}

View File

@ -21,25 +21,25 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
import { CoreCronDelegate } from '@services/cron';
import { CORE_SITE_SCHEMAS } from '@services/sites';
import { AddonModDataProvider } from './services/data';
import { ADDON_MOD_DATA_OFFLINE_SITE_SCHEMA } from './services/database/data';
import { AddonModDataApproveLinkHandler } from './services/handlers/approve-link';
import { AddonModDataDeleteLinkHandler } from './services/handlers/delete-link';
import { AddonModDataEditLinkHandler } from './services/handlers/edit-link';
import { AddonModDataIndexLinkHandler } from './services/handlers/index-link';
import { AddonModDataListLinkHandler } from './services/handlers/list-link';
import { AddonModDataModuleHandler, AddonModDataModuleHandlerService } from './services/handlers/module';
import { AddonModDataModuleHandler } from './services/handlers/module';
import { AddonModDataPrefetchHandler } from './services/handlers/prefetch';
import { AddonModDataShowLinkHandler } from './services/handlers/show-link';
import { AddonModDataSyncCronHandler } from './services/handlers/sync-cron';
import { AddonModDataTagAreaHandler } from './services/handlers/tag-area';
import { AddonModDataFieldModule } from './fields/field.module';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { ADDON_MOD_DATA_COMPONENT, ADDON_MOD_DATA_PAGE_NAME } from './constants';
const routes: Routes = [
{
path: AddonModDataModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./data-lazy.module').then(m => m.AddonModDataLazyModule),
path: ADDON_MOD_DATA_PAGE_NAME,
loadChildren: () => import('./data-lazy.module'),
},
];
@ -69,7 +69,7 @@ const routes: Routes = [
CoreContentLinksDelegate.registerHandler(AddonModDataEditLinkHandler.instance);
CoreTagAreaDelegate.registerHandler(AddonModDataTagAreaHandler.instance);
CoreCourseHelper.registerModuleReminderClick(AddonModDataProvider.COMPONENT);
CoreCourseHelper.registerModuleReminderClick(ADDON_MOD_DATA_COMPONENT);
},
},
],

View File

@ -13,10 +13,11 @@
// limitations under the License.
import { Component } from '@angular/core';
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { AddonModDataEntryField } from '@addons/mod/data/services/data';
import { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
import { CoreFileSession } from '@services/file-session';
import { CoreFileEntry } from '@services/file-helper';
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
/**
* Component to render data file field.
@ -59,7 +60,7 @@ export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginBaseC
return;
}
this.component = AddonModDataProvider.COMPONENT;
this.component = ADDON_MOD_DATA_COMPONENT;
this.componentId = this.database!.coursemodule;
this.updateValue(this.value);

View File

@ -15,7 +15,6 @@
import {
AddonModDataEntryField,
AddonModDataField,
AddonModDataProvider,
AddonModDataSearchEntriesAdvancedFieldFormatted,
AddonModDataSubfieldData,
} from '@addons/mod/data/services/data';
@ -29,6 +28,7 @@ import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldFileComponent } from '../component/file';
import { CoreFileEntry } from '@services/file-helper';
import type { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
/**
* Handler for file data field plugin.
@ -79,14 +79,14 @@ export class AddonModDataFieldFileHandlerService implements AddonModDataFieldHan
* @inheritdoc
*/
getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id);
return CoreFileSession.getFiles(ADDON_MOD_DATA_COMPONENT, field.dataid + '_' + field.id);
}
/**
* @inheritdoc
*/
hasFieldDataChanged(field: AddonModDataField, inputData: CoreFormFields, originalFieldData: AddonModDataEntryField): boolean {
const files = CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id) || [];
const files = CoreFileSession.getFiles(ADDON_MOD_DATA_COMPONENT, field.dataid + '_' + field.id) || [];
let originalFiles = (originalFieldData && originalFieldData.files) || [];
if (originalFiles.length) {

View File

@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { AddonModDataEntryField } from '@addons/mod/data/services/data';
import { Component } from '@angular/core';
import { CoreFileEntry, CoreFileHelper } from '@services/file-helper';
import { CoreFileSession } from '@services/file-session';
import { CoreDomUtils } from '@services/utils/dom';
import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-field-plugin-component';
import { CoreFile } from '@services/file';
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
/**
* Component to render data picture field.
@ -82,7 +83,7 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginBa
return;
}
this.component = AddonModDataProvider.COMPONENT;
this.component = ADDON_MOD_DATA_COMPONENT;
this.componentId = this.database!.coursemodule;
this.updateValue(this.value);

View File

@ -15,7 +15,6 @@
import {
AddonModDataEntryField,
AddonModDataField,
AddonModDataProvider,
AddonModDataSearchEntriesAdvancedFieldFormatted,
AddonModDataSubfieldData,
} from '@addons/mod/data/services/data';
@ -29,6 +28,7 @@ import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldPictureComponent } from '../component/picture';
import { CoreFileEntry } from '@services/file-helper';
import type { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
/**
* Handler for picture data field plugin.
@ -90,7 +90,7 @@ export class AddonModDataFieldPictureHandlerService implements AddonModDataField
* @inheritdoc
*/
getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id);
return CoreFileSession.getFiles(ADDON_MOD_DATA_COMPONENT, field.dataid + '_' + field.id);
}
/**

View File

@ -14,9 +14,10 @@
import { Component } from '@angular/core';
import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-field-plugin-component';
import { AddonModDataEntryField, AddonModDataProvider } from '@addons/mod/data/services/data';
import { AddonModDataEntryField } from '@addons/mod/data/services/data';
import { CoreTextUtils } from '@services/utils/text';
import { CoreWSFile } from '@services/ws';
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
/**
* Component to render data number field.
@ -46,7 +47,7 @@ export class AddonModDataFieldTextareaComponent extends AddonModDataFieldPluginB
* Initialize field.
*/
protected init(): void {
this.component = AddonModDataProvider.COMPONENT;
this.component = ADDON_MOD_DATA_COMPONENT;
this.componentId = this.database?.coursemodule;
if (this.displayMode) {

View File

@ -30,7 +30,6 @@ import { AddonModDataComponentsCompileModule } from '../../components/components
import {
AddonModDataData,
AddonModDataField,
AddonModDataProvider,
AddonModData,
AddonModDataTemplateType,
AddonModDataEntry,
@ -45,6 +44,7 @@ import { AddonModDataEntryFieldInitialized } from '../../classes/base-field-plug
import { CoreTextUtils } from '@services/utils/text';
import { CoreTime } from '@singletons/time';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { ADDON_MOD_DATA_COMPONENT, ADDON_MOD_DATA_ENTRY_CHANGED } from '../../constants';
/**
* Page that displays the view edit page.
@ -75,7 +75,7 @@ export class AddonModDataEditPage implements OnInit {
moduleId = 0;
database?: AddonModDataData;
title = '';
component = AddonModDataProvider.COMPONENT;
component = ADDON_MOD_DATA_COMPONENT;
loaded = false;
selectedGroup = 0;
cssClass = '';
@ -369,7 +369,7 @@ export class AddonModDataEditPage implements OnInit {
try {
await Promise.all(promises);
CoreEvents.trigger(
AddonModDataProvider.ENTRY_CHANGED,
ADDON_MOD_DATA_ENTRY_CHANGED,
{ dataId: this.database!.id, entryId: this.entryId },
this.siteId,

View File

@ -25,7 +25,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { AddonModDataComponentsCompileModule } from '../../components/components-compile.module';
import { AddonModDataProvider,
import {
AddonModData,
AddonModDataData,
AddonModDataGetDataAccessInformationWSResponse,
@ -35,9 +35,14 @@ import { AddonModDataProvider,
AddonModDataEntry,
} from '../../services/data';
import { AddonModDataHelper } from '../../services/data-helper';
import { AddonModDataSyncProvider } from '../../services/data-sync';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreTime } from '@singletons/time';
import {
ADDON_MOD_DATA_AUTO_SYNCED,
ADDON_MOD_DATA_COMPONENT,
ADDON_MOD_DATA_ENTRIES_PER_PAGE,
ADDON_MOD_DATA_ENTRY_CHANGED,
} from '../../constants';
/**
* Page that displays the view entry page.
@ -66,7 +71,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
offset?: number;
title = '';
moduleName = 'data';
component = AddonModDataProvider.COMPONENT;
component = ADDON_MOD_DATA_COMPONENT;
entryLoaded = false;
renderingEntry = false;
loadingComments = false;
@ -102,7 +107,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
this.siteId = CoreSites.getCurrentSiteId();
// Refresh data if this discussion is synchronized automatically.
this.syncObserver = CoreEvents.on(AddonModDataSyncProvider.AUTO_SYNCED, (data) => {
this.syncObserver = CoreEvents.on(ADDON_MOD_DATA_AUTO_SYNCED, (data) => {
if (data.entryId === undefined) {
return;
}
@ -120,7 +125,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
}, this.siteId);
// Refresh entry on change.
this.entryChangedObserver = CoreEvents.on(AddonModDataProvider.ENTRY_CHANGED, (data) => {
this.entryChangedObserver = CoreEvents.on(ADDON_MOD_DATA_ENTRY_CHANGED, (data) => {
if (data.entryId == this.entryId && this.database?.id == data.dataId) {
if (data.deleted) {
// If deleted, go back.
@ -331,7 +336,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
return;
}
const perPage = AddonModDataProvider.PER_PAGE;
const perPage = ADDON_MOD_DATA_ENTRIES_PER_PAGE;
const page = this.offset !== undefined && this.offset >= 0
? Math.floor(this.offset / perPage)
: 0;

View File

@ -28,7 +28,6 @@ import { CoreEvents } from '@singletons/events';
import {
AddonModDataEntry,
AddonModData,
AddonModDataProvider,
AddonModDataSearchEntriesOptions,
AddonModDataEntries,
AddonModDataEntryFields,
@ -44,6 +43,7 @@ import {
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
import { CoreFileEntry } from '@services/file-helper';
import { ADDON_MOD_DATA_COMPONENT, ADDON_MOD_DATA_ENTRY_CHANGED } from '../constants';
/**
* Service that provides helper functions for datas.
@ -171,7 +171,7 @@ export class AddonModDataHelperProvider {
await CoreUtils.ignoreErrors(Promise.all(promises));
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, siteId);
CoreEvents.trigger(ADDON_MOD_DATA_ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, siteId);
CoreDomUtils.showToast(
approve ? 'addon.mod_data.recordapproved' : 'addon.mod_data.recorddisapproved',
@ -878,7 +878,7 @@ export class AddonModDataHelperProvider {
// Ignore errors.
}
CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId, entryId, deleted: true }, siteId);
CoreEvents.trigger(ADDON_MOD_DATA_ENTRY_CHANGED, { dataId, entryId, deleted: true }, siteId);
CoreDomUtils.showToast('addon.mod_data.recorddeleted', true, ToastDuration.LONG);
@ -969,7 +969,7 @@ export class AddonModDataHelperProvider {
return 0;
}
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModDataProvider.COMPONENT, itemId, siteId);
return CoreFileUploader.uploadOrReuploadFiles(files, ADDON_MOD_DATA_COMPONENT, itemId, siteId);
}
}

View File

@ -29,9 +29,10 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { Translate, makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { AddonModDataProvider, AddonModData, AddonModDataData, AddonModDataAction } from './data';
import { AddonModData, AddonModDataData, AddonModDataAction } from './data';
import { AddonModDataHelper } from './data-helper';
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
import { ADDON_MOD_DATA_AUTO_SYNCED, ADDON_MOD_DATA_COMPONENT } from '../constants';
/**
* Service to sync databases.
@ -39,8 +40,6 @@ import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
@Injectable({ providedIn: 'root' })
export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModDataSyncResult> {
static readonly AUTO_SYNCED = 'addon_mod_data_autom_synced';
protected componentTranslatableString = 'data';
constructor() {
@ -93,7 +92,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
if (result && result.updated) {
// Sync done. Send event.
CoreEvents.trigger(AddonModDataSyncProvider.AUTO_SYNCED, {
CoreEvents.trigger(ADDON_MOD_DATA_AUTO_SYNCED, {
dataId: dataId,
warnings: result.warnings,
}, siteId);
@ -142,7 +141,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
}
// Verify that database isn't blocked.
if (CoreSync.isBlocked(AddonModDataProvider.COMPONENT, dataId, siteId)) {
if (CoreSync.isBlocked(ADDON_MOD_DATA_COMPONENT, dataId, siteId)) {
this.logger.debug(`Cannot sync database '${dataId}' because it is blocked.`);
throw new CoreSyncBlockedError(Translate.instant('core.errorsyncblocked', { $a: this.componentTranslate }));
@ -165,7 +164,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
protected async performSyncDatabase(dataId: number, siteId: string): Promise<AddonModDataSyncResult> {
// Sync offline logs.
await CoreUtils.ignoreErrors(
CoreCourseLogHelper.syncActivity(AddonModDataProvider.COMPONENT, dataId, siteId),
CoreCourseLogHelper.syncActivity(ADDON_MOD_DATA_COMPONENT, dataId, siteId),
);
const result: AddonModDataSyncResult = {
@ -243,7 +242,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
}
// Sync done. Send event.
CoreEvents.trigger(AddonModDataSyncProvider.AUTO_SYNCED, {
CoreEvents.trigger(ADDON_MOD_DATA_AUTO_SYNCED, {
dataId: database.id,
entryId: syncEntryResult.entryId,
offlineEntryId: syncEntryResult.offlineId,

View File

@ -28,10 +28,14 @@ import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
import { makeSingleton, Translate } from '@singletons';
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
import { AddonModDataOffline } from './data-offline';
import { AddonModDataAutoSyncData, AddonModDataSyncProvider } from './data-sync';
import { AddonModDataAutoSyncData } from './data-sync';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
const ROOT_CACHE_KEY = 'mmaModData:';
import {
ADDON_MOD_DATA_AUTO_SYNCED,
ADDON_MOD_DATA_COMPONENT,
ADDON_MOD_DATA_ENTRIES_PER_PAGE,
ADDON_MOD_DATA_ENTRY_CHANGED,
} from '../constants';
declare module '@singletons/events' {
@ -41,8 +45,8 @@ declare module '@singletons/events' {
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
*/
export interface CoreEventsData {
[AddonModDataSyncProvider.AUTO_SYNCED]: AddonModDataAutoSyncData;
[AddonModDataProvider.ENTRY_CHANGED]: AddonModDataEntryChangedEventData;
[ADDON_MOD_DATA_AUTO_SYNCED]: AddonModDataAutoSyncData;
[ADDON_MOD_DATA_ENTRY_CHANGED]: AddonModDataEntryChangedEventData;
}
}
@ -90,9 +94,7 @@ export enum AddonModDataTemplateMode {
@Injectable({ providedIn: 'root' })
export class AddonModDataProvider {
static readonly COMPONENT = 'mmaModData';
static readonly PER_PAGE = 25;
static readonly ENTRY_CHANGED = 'addon_mod_data_entry_changed';
protected static readonly ROOT_CACHE_KEY = 'mmaModData:';
/**
* Adds a new entry to a database.
@ -504,7 +506,7 @@ export class AddonModDataProvider {
options.siteId = options.siteId || CoreSites.getCurrentSiteId();
options = Object.assign({
page: 0,
perPage: AddonModDataProvider.PER_PAGE,
perPage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
}, options);
return this.fetchEntriesRecursive(dataId, [], options);
@ -543,7 +545,7 @@ export class AddonModDataProvider {
* @returns Cache key.
*/
protected getDatabaseDataCacheKey(courseId: number): string {
return ROOT_CACHE_KEY + 'data:' + courseId;
return AddonModDataProvider.ROOT_CACHE_KEY + 'data:' + courseId;
}
/**
@ -553,7 +555,7 @@ export class AddonModDataProvider {
* @returns Cache key.
*/
protected getDatabaseDataPrefixCacheKey(dataId: number): string {
return ROOT_CACHE_KEY + dataId;
return AddonModDataProvider.ROOT_CACHE_KEY + dataId;
}
/**
@ -579,7 +581,7 @@ export class AddonModDataProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getDatabaseDataCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
const response =
@ -660,7 +662,7 @@ export class AddonModDataProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getDatabaseAccessInformationDataCacheKey(dataId, options.groupId),
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
@ -681,7 +683,7 @@ export class AddonModDataProvider {
sort: 0,
order: 'DESC',
page: 0,
perPage: AddonModDataProvider.PER_PAGE,
perPage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
}, options);
const site = await CoreSites.getSite(options.siteId);
@ -699,7 +701,7 @@ export class AddonModDataProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesCacheKey(dataId, options.groupId),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
@ -757,7 +759,7 @@ export class AddonModDataProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntryCacheKey(dataId, entryId),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
@ -809,7 +811,7 @@ export class AddonModDataProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getFieldsCacheKey(dataId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
@ -911,7 +913,7 @@ export class AddonModDataProvider {
* @returns Promise resolved when the files are invalidated.
*/
async invalidateFiles(moduleId: number, siteId?: string): Promise<void> {
await CoreFilepool.invalidateFilesByComponent(siteId, AddonModDataProvider.COMPONENT, moduleId);
await CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_DATA_COMPONENT, moduleId);
}
/**
@ -969,7 +971,7 @@ export class AddonModDataProvider {
await CoreCourseLogHelper.log(
'mod_data_view_database',
params,
AddonModDataProvider.COMPONENT,
ADDON_MOD_DATA_COMPONENT,
id,
siteId,
);
@ -989,7 +991,7 @@ export class AddonModDataProvider {
options.sort = options.sort || 0;
options.order = options.order || 'DESC';
options.page = options.page || 0;
options.perPage = options.perPage || AddonModDataProvider.PER_PAGE;
options.perPage = options.perPage || ADDON_MOD_DATA_ENTRIES_PER_PAGE;
options.readingStrategy = options.readingStrategy || CoreSitesReadingStrategy.PREFER_NETWORK;
const params: AddonModDataSearchEntriesWSParams = {
@ -1000,7 +1002,7 @@ export class AddonModDataProvider {
perpage: options.perPage,
};
const preSets: CoreSiteWSPreSets = {
component: AddonModDataProvider.COMPONENT,
component: ADDON_MOD_DATA_COMPONENT,
componentId: options.cmId,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
};
@ -1087,7 +1089,7 @@ export type AddonModDataGetEntriesOptions = CoreCourseCommonModWSOptions & {
// -4: timemodified
order?: string; // The direction of the sorting: 'ASC' or 'DESC'. Defaults to 'DESC'.
page?: number; // Page of records to return. Defaults to 0.
perPage?: number; // Records per page to return. Defaults to AddonModDataProvider.PER_PAGE.
perPage?: number; // Records per page to return. Defaults to ADDON_MOD_DATA_ENTRIES_PER_PAGE.
};
/**

View File

@ -21,8 +21,7 @@ import { CoreNavigator } from '@services/navigator';
import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { AddonModDataModuleHandlerService } from './module';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
import { ADDON_MOD_DATA_FEATURE_NAME, ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
/**
* Content links handler for database add or edit entry.
@ -56,7 +55,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
};
await CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/edit/${rId}`,
`${ADDON_MOD_DATA_PAGE_NAME}/${module.course}/${module.id}/edit/${rId}`,
{ siteId, params: pageParams },
);
} finally {

View File

@ -17,6 +17,7 @@ import { Injectable, Type } from '@angular/core';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
import { makeSingleton } from '@singletons';
import { ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
/**
* Handler to support data modules.
@ -24,11 +25,9 @@ import { makeSingleton } from '@singletons';
@Injectable({ providedIn: 'root' })
export class AddonModDataModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
static readonly PAGE_NAME = 'mod_data';
name = 'AddonModData';
modName = 'data';
protected pageName = AddonModDataModuleHandlerService.PAGE_NAME;
protected pageName = ADDON_MOD_DATA_PAGE_NAME;
supportedFeatures = {
[CoreConstants.FEATURE_GROUPS]: true,

View File

@ -24,9 +24,10 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
import { AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync';
import { ContextLevel } from '@/core/constants';
import { ADDON_MOD_DATA_COMPONENT } from '../../constants';
/**
* Handler to prefetch databases.
@ -36,7 +37,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
name = 'AddonModData';
modName = 'data';
component = AddonModDataProvider.COMPONENT;
component = ADDON_MOD_DATA_COMPONENT;
updatesNames = /^configuration$|^.*files$|^entries$|^gradeitems$|^outcomes$|^comments$|^ratings/;
/**

View File

@ -21,8 +21,7 @@ import { CoreNavigator } from '@services/navigator';
import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { AddonModDataModuleHandlerService } from './module';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
import { ADDON_MOD_DATA_FEATURE_NAME, ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
/**
* Content links handler for database show entry.
@ -67,7 +66,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
}
await CoreNavigator.navigateToSitePath(
`${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/${rId}`,
`${ADDON_MOD_DATA_PAGE_NAME}/${module.course}/${module.id}/${rId}`,
{ siteId, params: pageParams },
);
} finally {