MOBILE-4616 data: Move data constants to a file
parent
4934dcec99
commit
09791c8d20
|
@ -24,14 +24,13 @@ import {
|
||||||
AddonModDataData,
|
AddonModDataData,
|
||||||
AddonModDataEntry,
|
AddonModDataEntry,
|
||||||
AddonModDataGetDataAccessInformationWSResponse,
|
AddonModDataGetDataAccessInformationWSResponse,
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModDataTemplateMode,
|
AddonModDataTemplateMode,
|
||||||
} from '../../services/data';
|
} from '../../services/data';
|
||||||
import { AddonModDataHelper } from '../../services/data-helper';
|
import { AddonModDataHelper } from '../../services/data-helper';
|
||||||
import { AddonModDataOffline } from '../../services/data-offline';
|
import { AddonModDataOffline } from '../../services/data-offline';
|
||||||
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
|
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { AddonModDataActionsMenuComponent, AddonModDataActionsMenuItem } from '../actionsmenu/actionsmenu';
|
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.
|
* Component that displays a database action.
|
||||||
|
@ -101,7 +100,7 @@ export class AddonModDataActionComponent implements OnInit {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
|
const basePath = ADDON_MOD_DATA_PAGE_NAME;
|
||||||
CoreNavigator.navigateToSitePath(
|
CoreNavigator.navigateToSitePath(
|
||||||
`${basePath}/${this.database.course}/${this.database.coursemodule}/edit/${this.entry.id}`,
|
`${basePath}/${this.database.course}/${this.database.coursemodule}/edit/${this.entry.id}`,
|
||||||
{ params },
|
{ params },
|
||||||
|
@ -120,7 +119,7 @@ export class AddonModDataActionComponent implements OnInit {
|
||||||
sortDirection: this.sortDirection,
|
sortDirection: this.sortDirection,
|
||||||
};
|
};
|
||||||
|
|
||||||
const basePath = AddonModDataModuleHandlerService.PAGE_NAME;
|
const basePath = ADDON_MOD_DATA_PAGE_NAME;
|
||||||
CoreNavigator.navigateToSitePath(
|
CoreNavigator.navigateToSitePath(
|
||||||
`${basePath}/${this.database.course}/${this.database.coursemodule}/${this.entry.id}`,
|
`${basePath}/${this.database.course}/${this.database.coursemodule}/${this.entry.id}`,
|
||||||
{ params },
|
{ params },
|
||||||
|
@ -140,7 +139,7 @@ export class AddonModDataActionComponent implements OnInit {
|
||||||
|
|
||||||
// Found. Just delete the action.
|
// Found. Just delete the action.
|
||||||
await AddonModDataOffline.deleteEntry(dataId, entryId, AddonModDataAction.DELETE, this.siteId);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,7 +29,6 @@ import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import {
|
import {
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModData,
|
AddonModData,
|
||||||
AddonModDataEntry,
|
AddonModDataEntry,
|
||||||
AddonModDataTemplateType,
|
AddonModDataTemplateType,
|
||||||
|
@ -40,13 +39,19 @@ import {
|
||||||
AddonModDataSearchEntriesAdvancedField,
|
AddonModDataSearchEntriesAdvancedField,
|
||||||
} from '../../services/data';
|
} from '../../services/data';
|
||||||
import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../services/data-helper';
|
import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../services/data-helper';
|
||||||
import { AddonModDataAutoSyncData, AddonModDataSyncProvider, AddonModDataSyncResult } from '../../services/data-sync';
|
import { AddonModDataAutoSyncData, AddonModDataSyncResult } from '../../services/data-sync';
|
||||||
import { AddonModDataModuleHandlerService } from '../../services/handlers/module';
|
|
||||||
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
|
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch';
|
||||||
import { AddonModDataComponentsCompileModule } from '../components-compile.module';
|
import { AddonModDataComponentsCompileModule } from '../components-compile.module';
|
||||||
import { AddonModDataSearchComponent } from '../search/search';
|
import { AddonModDataSearchComponent } from '../search/search';
|
||||||
import { CoreUrlUtils } from '@services/utils/url';
|
import { CoreUrlUtils } from '@services/utils/url';
|
||||||
import { CoreTime } from '@singletons/time';
|
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 -->';
|
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 {
|
export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
component = AddonModDataProvider.COMPONENT;
|
component = ADDON_MOD_DATA_COMPONENT;
|
||||||
pluginName = 'data';
|
pluginName = 'data';
|
||||||
|
|
||||||
access?: AddonModDataGetDataAccessInformationWSResponse;
|
access?: AddonModDataGetDataAccessInformationWSResponse;
|
||||||
|
@ -110,7 +115,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
|
|
||||||
hasOfflineRatings = false;
|
hasOfflineRatings = false;
|
||||||
|
|
||||||
protected syncEventName = AddonModDataSyncProvider.AUTO_SYNCED;
|
protected syncEventName = ADDON_MOD_DATA_AUTO_SYNCED;
|
||||||
protected hasComments = false;
|
protected hasComments = false;
|
||||||
protected fieldsArray: AddonModDataField[] = [];
|
protected fieldsArray: AddonModDataField[] = [];
|
||||||
protected entryChangedObserver?: CoreEventObserver;
|
protected entryChangedObserver?: CoreEventObserver;
|
||||||
|
@ -134,7 +139,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
this.selectedGroup = this.group || 0;
|
this.selectedGroup = this.group || 0;
|
||||||
|
|
||||||
// Refresh entries on change.
|
// 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) {
|
if (this.database?.id == eventData.dataId) {
|
||||||
this.showLoading = true;
|
this.showLoading = true;
|
||||||
|
|
||||||
|
@ -303,8 +308,8 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
|
|
||||||
this.isEmpty = !numEntries && !numOfflineEntries;
|
this.isEmpty = !numEntries && !numOfflineEntries;
|
||||||
|
|
||||||
this.hasNextPage = numEntries >= AddonModDataProvider.PER_PAGE && ((this.search.page + 1) *
|
this.hasNextPage = numEntries >= ADDON_MOD_DATA_ENTRIES_PER_PAGE && ((this.search.page + 1) *
|
||||||
AddonModDataProvider.PER_PAGE) < entries.totalcount;
|
ADDON_MOD_DATA_ENTRIES_PER_PAGE) < entries.totalcount;
|
||||||
|
|
||||||
this.hasOffline = !!entries.hasOfflineActions;
|
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 actions = AddonModDataHelper.getActions(this.database!, this.access!, entry, AddonModDataTemplateMode.LIST);
|
||||||
const options: AddonModDatDisplayFieldsOptions = {};
|
const options: AddonModDatDisplayFieldsOptions = {};
|
||||||
if (!this.search.searching) {
|
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.sortBy = this.search.sortBy;
|
||||||
options.sortDirection = this.search.sortDirection;
|
options.sortDirection = this.search.sortDirection;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +494,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
};
|
};
|
||||||
|
|
||||||
CoreNavigator.navigateToSitePath(
|
CoreNavigator.navigateToSitePath(
|
||||||
`${AddonModDataModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/edit`,
|
`${ADDON_MOD_DATA_PAGE_NAME}/${this.courseId}/${this.module.id}/edit`,
|
||||||
{ params },
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -509,14 +514,14 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
if (!this.search.searching) {
|
if (!this.search.searching) {
|
||||||
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 * ADDON_MOD_DATA_ENTRIES_PER_PAGE + pageXOffset;
|
||||||
params.sortBy = this.search.sortBy;
|
params.sortBy = this.search.sortBy;
|
||||||
params.sortDirection = this.search.sortDirection;
|
params.sortDirection = this.search.sortDirection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreNavigator.navigateToSitePath(
|
CoreNavigator.navigateToSitePath(
|
||||||
`${AddonModDataModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/${entryId}`,
|
`${ADDON_MOD_DATA_PAGE_NAME}/${this.courseId}/${this.module.id}/${entryId}`,
|
||||||
{ params },
|
{ params },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -550,7 +555,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
|
||||||
}
|
}
|
||||||
|
|
||||||
const params: Record<string, unknown> = {
|
const params: Record<string, unknown> = {
|
||||||
perpage: AddonModDataProvider.PER_PAGE,
|
perpage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
|
||||||
search: !this.search.searchingAdvanced ? this.search.text : '',
|
search: !this.search.searchingAdvanced ? this.search.text : '',
|
||||||
sort: this.search.sortBy,
|
sort: this.search.sortBy,
|
||||||
order: this.search.sortDirection,
|
order: this.search.sortDirection,
|
||||||
|
|
|
@ -13,3 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
export const ADDON_MOD_DATA_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModData';
|
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';
|
||||||
|
|
|
@ -62,4 +62,4 @@ const routes: Routes = [
|
||||||
AddonModDataEditPage,
|
AddonModDataEditPage,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AddonModDataLazyModule {}
|
export default class AddonModDataLazyModule {}
|
||||||
|
|
|
@ -21,25 +21,25 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
|
||||||
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
|
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
|
||||||
import { CoreCronDelegate } from '@services/cron';
|
import { CoreCronDelegate } from '@services/cron';
|
||||||
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
||||||
import { AddonModDataProvider } from './services/data';
|
|
||||||
import { ADDON_MOD_DATA_OFFLINE_SITE_SCHEMA } from './services/database/data';
|
import { ADDON_MOD_DATA_OFFLINE_SITE_SCHEMA } from './services/database/data';
|
||||||
import { AddonModDataApproveLinkHandler } from './services/handlers/approve-link';
|
import { AddonModDataApproveLinkHandler } from './services/handlers/approve-link';
|
||||||
import { AddonModDataDeleteLinkHandler } from './services/handlers/delete-link';
|
import { AddonModDataDeleteLinkHandler } from './services/handlers/delete-link';
|
||||||
import { AddonModDataEditLinkHandler } from './services/handlers/edit-link';
|
import { AddonModDataEditLinkHandler } from './services/handlers/edit-link';
|
||||||
import { AddonModDataIndexLinkHandler } from './services/handlers/index-link';
|
import { AddonModDataIndexLinkHandler } from './services/handlers/index-link';
|
||||||
import { AddonModDataListLinkHandler } from './services/handlers/list-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 { AddonModDataPrefetchHandler } from './services/handlers/prefetch';
|
||||||
import { AddonModDataShowLinkHandler } from './services/handlers/show-link';
|
import { AddonModDataShowLinkHandler } from './services/handlers/show-link';
|
||||||
import { AddonModDataSyncCronHandler } from './services/handlers/sync-cron';
|
import { AddonModDataSyncCronHandler } from './services/handlers/sync-cron';
|
||||||
import { AddonModDataTagAreaHandler } from './services/handlers/tag-area';
|
import { AddonModDataTagAreaHandler } from './services/handlers/tag-area';
|
||||||
import { AddonModDataFieldModule } from './fields/field.module';
|
import { AddonModDataFieldModule } from './fields/field.module';
|
||||||
import { CoreCourseHelper } from '@features/course/services/course-helper';
|
import { CoreCourseHelper } from '@features/course/services/course-helper';
|
||||||
|
import { ADDON_MOD_DATA_COMPONENT, ADDON_MOD_DATA_PAGE_NAME } from './constants';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: AddonModDataModuleHandlerService.PAGE_NAME,
|
path: ADDON_MOD_DATA_PAGE_NAME,
|
||||||
loadChildren: () => import('./data-lazy.module').then(m => m.AddonModDataLazyModule),
|
loadChildren: () => import('./data-lazy.module'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ const routes: Routes = [
|
||||||
CoreContentLinksDelegate.registerHandler(AddonModDataEditLinkHandler.instance);
|
CoreContentLinksDelegate.registerHandler(AddonModDataEditLinkHandler.instance);
|
||||||
CoreTagAreaDelegate.registerHandler(AddonModDataTagAreaHandler.instance);
|
CoreTagAreaDelegate.registerHandler(AddonModDataTagAreaHandler.instance);
|
||||||
|
|
||||||
CoreCourseHelper.registerModuleReminderClick(AddonModDataProvider.COMPONENT);
|
CoreCourseHelper.registerModuleReminderClick(ADDON_MOD_DATA_COMPONENT);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
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 { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
|
||||||
import { CoreFileSession } from '@services/file-session';
|
import { CoreFileSession } from '@services/file-session';
|
||||||
import { CoreFileEntry } from '@services/file-helper';
|
import { CoreFileEntry } from '@services/file-helper';
|
||||||
|
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to render data file field.
|
* Component to render data file field.
|
||||||
|
@ -59,7 +60,7 @@ export class AddonModDataFieldFileComponent extends AddonModDataFieldPluginBaseC
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.component = AddonModDataProvider.COMPONENT;
|
this.component = ADDON_MOD_DATA_COMPONENT;
|
||||||
this.componentId = this.database!.coursemodule;
|
this.componentId = this.database!.coursemodule;
|
||||||
|
|
||||||
this.updateValue(this.value);
|
this.updateValue(this.value);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
import {
|
import {
|
||||||
AddonModDataEntryField,
|
AddonModDataEntryField,
|
||||||
AddonModDataField,
|
AddonModDataField,
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModDataSearchEntriesAdvancedFieldFormatted,
|
AddonModDataSearchEntriesAdvancedFieldFormatted,
|
||||||
AddonModDataSubfieldData,
|
AddonModDataSubfieldData,
|
||||||
} from '@addons/mod/data/services/data';
|
} from '@addons/mod/data/services/data';
|
||||||
|
@ -29,6 +28,7 @@ import { makeSingleton, Translate } from '@singletons';
|
||||||
import { AddonModDataFieldFileComponent } from '../component/file';
|
import { AddonModDataFieldFileComponent } from '../component/file';
|
||||||
import { CoreFileEntry } from '@services/file-helper';
|
import { CoreFileEntry } from '@services/file-helper';
|
||||||
import type { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
|
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.
|
* Handler for file data field plugin.
|
||||||
|
@ -79,14 +79,14 @@ export class AddonModDataFieldFileHandlerService implements AddonModDataFieldHan
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
|
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
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
hasFieldDataChanged(field: AddonModDataField, inputData: CoreFormFields, originalFieldData: AddonModDataEntryField): boolean {
|
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) || [];
|
let originalFiles = (originalFieldData && originalFieldData.files) || [];
|
||||||
|
|
||||||
if (originalFiles.length) {
|
if (originalFiles.length) {
|
||||||
|
|
|
@ -12,13 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 { Component } from '@angular/core';
|
||||||
import { CoreFileEntry, CoreFileHelper } from '@services/file-helper';
|
import { CoreFileEntry, CoreFileHelper } from '@services/file-helper';
|
||||||
import { CoreFileSession } from '@services/file-session';
|
import { CoreFileSession } from '@services/file-session';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-field-plugin-component';
|
import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-field-plugin-component';
|
||||||
import { CoreFile } from '@services/file';
|
import { CoreFile } from '@services/file';
|
||||||
|
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to render data picture field.
|
* Component to render data picture field.
|
||||||
|
@ -82,7 +83,7 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginBa
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.component = AddonModDataProvider.COMPONENT;
|
this.component = ADDON_MOD_DATA_COMPONENT;
|
||||||
this.componentId = this.database!.coursemodule;
|
this.componentId = this.database!.coursemodule;
|
||||||
|
|
||||||
this.updateValue(this.value);
|
this.updateValue(this.value);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
import {
|
import {
|
||||||
AddonModDataEntryField,
|
AddonModDataEntryField,
|
||||||
AddonModDataField,
|
AddonModDataField,
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModDataSearchEntriesAdvancedFieldFormatted,
|
AddonModDataSearchEntriesAdvancedFieldFormatted,
|
||||||
AddonModDataSubfieldData,
|
AddonModDataSubfieldData,
|
||||||
} from '@addons/mod/data/services/data';
|
} from '@addons/mod/data/services/data';
|
||||||
|
@ -29,6 +28,7 @@ import { makeSingleton, Translate } from '@singletons';
|
||||||
import { AddonModDataFieldPictureComponent } from '../component/picture';
|
import { AddonModDataFieldPictureComponent } from '../component/picture';
|
||||||
import { CoreFileEntry } from '@services/file-helper';
|
import { CoreFileEntry } from '@services/file-helper';
|
||||||
import type { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
|
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.
|
* Handler for picture data field plugin.
|
||||||
|
@ -90,7 +90,7 @@ export class AddonModDataFieldPictureHandlerService implements AddonModDataField
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
|
getFieldEditFiles(field: AddonModDataField): CoreFileEntry[] {
|
||||||
return CoreFileSession.getFiles(AddonModDataProvider.COMPONENT, field.dataid + '_' + field.id);
|
return CoreFileSession.getFiles(ADDON_MOD_DATA_COMPONENT, field.dataid + '_' + field.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,9 +14,10 @@
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-field-plugin-component';
|
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 { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreWSFile } from '@services/ws';
|
import { CoreWSFile } from '@services/ws';
|
||||||
|
import { ADDON_MOD_DATA_COMPONENT } from '@addons/mod/data/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to render data number field.
|
* Component to render data number field.
|
||||||
|
@ -46,7 +47,7 @@ export class AddonModDataFieldTextareaComponent extends AddonModDataFieldPluginB
|
||||||
* Initialize field.
|
* Initialize field.
|
||||||
*/
|
*/
|
||||||
protected init(): void {
|
protected init(): void {
|
||||||
this.component = AddonModDataProvider.COMPONENT;
|
this.component = ADDON_MOD_DATA_COMPONENT;
|
||||||
this.componentId = this.database?.coursemodule;
|
this.componentId = this.database?.coursemodule;
|
||||||
|
|
||||||
if (this.displayMode) {
|
if (this.displayMode) {
|
||||||
|
|
|
@ -30,7 +30,6 @@ import { AddonModDataComponentsCompileModule } from '../../components/components
|
||||||
import {
|
import {
|
||||||
AddonModDataData,
|
AddonModDataData,
|
||||||
AddonModDataField,
|
AddonModDataField,
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModData,
|
AddonModData,
|
||||||
AddonModDataTemplateType,
|
AddonModDataTemplateType,
|
||||||
AddonModDataEntry,
|
AddonModDataEntry,
|
||||||
|
@ -45,6 +44,7 @@ import { AddonModDataEntryFieldInitialized } from '../../classes/base-field-plug
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreTime } from '@singletons/time';
|
import { CoreTime } from '@singletons/time';
|
||||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
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.
|
* Page that displays the view edit page.
|
||||||
|
@ -75,7 +75,7 @@ export class AddonModDataEditPage implements OnInit {
|
||||||
moduleId = 0;
|
moduleId = 0;
|
||||||
database?: AddonModDataData;
|
database?: AddonModDataData;
|
||||||
title = '';
|
title = '';
|
||||||
component = AddonModDataProvider.COMPONENT;
|
component = ADDON_MOD_DATA_COMPONENT;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
selectedGroup = 0;
|
selectedGroup = 0;
|
||||||
cssClass = '';
|
cssClass = '';
|
||||||
|
@ -369,7 +369,7 @@ export class AddonModDataEditPage implements OnInit {
|
||||||
try {
|
try {
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
CoreEvents.trigger(
|
CoreEvents.trigger(
|
||||||
AddonModDataProvider.ENTRY_CHANGED,
|
ADDON_MOD_DATA_ENTRY_CHANGED,
|
||||||
{ dataId: this.database!.id, entryId: this.entryId },
|
{ dataId: this.database!.id, entryId: this.entryId },
|
||||||
|
|
||||||
this.siteId,
|
this.siteId,
|
||||||
|
|
|
@ -25,7 +25,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||||
import { AddonModDataComponentsCompileModule } from '../../components/components-compile.module';
|
import { AddonModDataComponentsCompileModule } from '../../components/components-compile.module';
|
||||||
import { AddonModDataProvider,
|
import {
|
||||||
AddonModData,
|
AddonModData,
|
||||||
AddonModDataData,
|
AddonModDataData,
|
||||||
AddonModDataGetDataAccessInformationWSResponse,
|
AddonModDataGetDataAccessInformationWSResponse,
|
||||||
|
@ -35,9 +35,14 @@ import { AddonModDataProvider,
|
||||||
AddonModDataEntry,
|
AddonModDataEntry,
|
||||||
} from '../../services/data';
|
} from '../../services/data';
|
||||||
import { AddonModDataHelper } from '../../services/data-helper';
|
import { AddonModDataHelper } from '../../services/data-helper';
|
||||||
import { AddonModDataSyncProvider } from '../../services/data-sync';
|
|
||||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||||
import { CoreTime } from '@singletons/time';
|
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.
|
* Page that displays the view entry page.
|
||||||
|
@ -66,7 +71,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
offset?: number;
|
offset?: number;
|
||||||
title = '';
|
title = '';
|
||||||
moduleName = 'data';
|
moduleName = 'data';
|
||||||
component = AddonModDataProvider.COMPONENT;
|
component = ADDON_MOD_DATA_COMPONENT;
|
||||||
entryLoaded = false;
|
entryLoaded = false;
|
||||||
renderingEntry = false;
|
renderingEntry = false;
|
||||||
loadingComments = false;
|
loadingComments = false;
|
||||||
|
@ -102,7 +107,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
this.siteId = CoreSites.getCurrentSiteId();
|
this.siteId = CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
// Refresh data if this discussion is synchronized automatically.
|
// 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) {
|
if (data.entryId === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +125,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
}, this.siteId);
|
}, this.siteId);
|
||||||
|
|
||||||
// Refresh entry on change.
|
// 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.entryId == this.entryId && this.database?.id == data.dataId) {
|
||||||
if (data.deleted) {
|
if (data.deleted) {
|
||||||
// If deleted, go back.
|
// If deleted, go back.
|
||||||
|
@ -331,7 +336,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const perPage = AddonModDataProvider.PER_PAGE;
|
const perPage = ADDON_MOD_DATA_ENTRIES_PER_PAGE;
|
||||||
const page = this.offset !== undefined && this.offset >= 0
|
const page = this.offset !== undefined && this.offset >= 0
|
||||||
? Math.floor(this.offset / perPage)
|
? Math.floor(this.offset / perPage)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
|
@ -28,7 +28,6 @@ import { CoreEvents } from '@singletons/events';
|
||||||
import {
|
import {
|
||||||
AddonModDataEntry,
|
AddonModDataEntry,
|
||||||
AddonModData,
|
AddonModData,
|
||||||
AddonModDataProvider,
|
|
||||||
AddonModDataSearchEntriesOptions,
|
AddonModDataSearchEntriesOptions,
|
||||||
AddonModDataEntries,
|
AddonModDataEntries,
|
||||||
AddonModDataEntryFields,
|
AddonModDataEntryFields,
|
||||||
|
@ -44,6 +43,7 @@ import {
|
||||||
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
|
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
|
||||||
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
||||||
import { CoreFileEntry } from '@services/file-helper';
|
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.
|
* Service that provides helper functions for datas.
|
||||||
|
@ -171,7 +171,7 @@ export class AddonModDataHelperProvider {
|
||||||
|
|
||||||
await CoreUtils.ignoreErrors(Promise.all(promises));
|
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(
|
CoreDomUtils.showToast(
|
||||||
approve ? 'addon.mod_data.recordapproved' : 'addon.mod_data.recorddisapproved',
|
approve ? 'addon.mod_data.recordapproved' : 'addon.mod_data.recorddisapproved',
|
||||||
|
@ -878,7 +878,7 @@ export class AddonModDataHelperProvider {
|
||||||
// Ignore errors.
|
// 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);
|
CoreDomUtils.showToast('addon.mod_data.recorddeleted', true, ToastDuration.LONG);
|
||||||
|
|
||||||
|
@ -969,7 +969,7 @@ export class AddonModDataHelperProvider {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CoreFileUploader.uploadOrReuploadFiles(files, AddonModDataProvider.COMPONENT, itemId, siteId);
|
return CoreFileUploader.uploadOrReuploadFiles(files, ADDON_MOD_DATA_COMPONENT, itemId, siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,10 @@ import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { Translate, makeSingleton } from '@singletons';
|
import { Translate, makeSingleton } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { AddonModDataProvider, AddonModData, AddonModDataData, AddonModDataAction } from './data';
|
import { AddonModData, AddonModDataData, AddonModDataAction } from './data';
|
||||||
import { AddonModDataHelper } from './data-helper';
|
import { AddonModDataHelper } from './data-helper';
|
||||||
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
||||||
|
import { ADDON_MOD_DATA_AUTO_SYNCED, ADDON_MOD_DATA_COMPONENT } from '../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to sync databases.
|
* Service to sync databases.
|
||||||
|
@ -39,8 +40,6 @@ import { AddonModDataOffline, AddonModDataOfflineAction } from './data-offline';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModDataSyncResult> {
|
export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider<AddonModDataSyncResult> {
|
||||||
|
|
||||||
static readonly AUTO_SYNCED = 'addon_mod_data_autom_synced';
|
|
||||||
|
|
||||||
protected componentTranslatableString = 'data';
|
protected componentTranslatableString = 'data';
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -93,7 +92,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
||||||
|
|
||||||
if (result && result.updated) {
|
if (result && result.updated) {
|
||||||
// Sync done. Send event.
|
// Sync done. Send event.
|
||||||
CoreEvents.trigger(AddonModDataSyncProvider.AUTO_SYNCED, {
|
CoreEvents.trigger(ADDON_MOD_DATA_AUTO_SYNCED, {
|
||||||
dataId: dataId,
|
dataId: dataId,
|
||||||
warnings: result.warnings,
|
warnings: result.warnings,
|
||||||
}, siteId);
|
}, siteId);
|
||||||
|
@ -142,7 +141,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that database isn't blocked.
|
// 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.`);
|
this.logger.debug(`Cannot sync database '${dataId}' because it is blocked.`);
|
||||||
|
|
||||||
throw new CoreSyncBlockedError(Translate.instant('core.errorsyncblocked', { $a: this.componentTranslate }));
|
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> {
|
protected async performSyncDatabase(dataId: number, siteId: string): Promise<AddonModDataSyncResult> {
|
||||||
// Sync offline logs.
|
// Sync offline logs.
|
||||||
await CoreUtils.ignoreErrors(
|
await CoreUtils.ignoreErrors(
|
||||||
CoreCourseLogHelper.syncActivity(AddonModDataProvider.COMPONENT, dataId, siteId),
|
CoreCourseLogHelper.syncActivity(ADDON_MOD_DATA_COMPONENT, dataId, siteId),
|
||||||
);
|
);
|
||||||
|
|
||||||
const result: AddonModDataSyncResult = {
|
const result: AddonModDataSyncResult = {
|
||||||
|
@ -243,7 +242,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync done. Send event.
|
// Sync done. Send event.
|
||||||
CoreEvents.trigger(AddonModDataSyncProvider.AUTO_SYNCED, {
|
CoreEvents.trigger(ADDON_MOD_DATA_AUTO_SYNCED, {
|
||||||
dataId: database.id,
|
dataId: database.id,
|
||||||
entryId: syncEntryResult.entryId,
|
entryId: syncEntryResult.entryId,
|
||||||
offlineEntryId: syncEntryResult.offlineId,
|
offlineEntryId: syncEntryResult.offlineId,
|
||||||
|
|
|
@ -28,10 +28,14 @@ import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
|
import { AddonModDataFieldsDelegate } from './data-fields-delegate';
|
||||||
import { AddonModDataOffline } from './data-offline';
|
import { AddonModDataOffline } from './data-offline';
|
||||||
import { AddonModDataAutoSyncData, AddonModDataSyncProvider } from './data-sync';
|
import { AddonModDataAutoSyncData } from './data-sync';
|
||||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||||
|
import {
|
||||||
const ROOT_CACHE_KEY = 'mmaModData:';
|
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' {
|
declare module '@singletons/events' {
|
||||||
|
|
||||||
|
@ -41,8 +45,8 @@ declare module '@singletons/events' {
|
||||||
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
* @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
|
||||||
*/
|
*/
|
||||||
export interface CoreEventsData {
|
export interface CoreEventsData {
|
||||||
[AddonModDataSyncProvider.AUTO_SYNCED]: AddonModDataAutoSyncData;
|
[ADDON_MOD_DATA_AUTO_SYNCED]: AddonModDataAutoSyncData;
|
||||||
[AddonModDataProvider.ENTRY_CHANGED]: AddonModDataEntryChangedEventData;
|
[ADDON_MOD_DATA_ENTRY_CHANGED]: AddonModDataEntryChangedEventData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +94,7 @@ export enum AddonModDataTemplateMode {
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModDataProvider {
|
export class AddonModDataProvider {
|
||||||
|
|
||||||
static readonly COMPONENT = 'mmaModData';
|
protected static readonly ROOT_CACHE_KEY = 'mmaModData:';
|
||||||
static readonly PER_PAGE = 25;
|
|
||||||
static readonly ENTRY_CHANGED = 'addon_mod_data_entry_changed';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new entry to a database.
|
* Adds a new entry to a database.
|
||||||
|
@ -504,7 +506,7 @@ export class AddonModDataProvider {
|
||||||
options.siteId = options.siteId || CoreSites.getCurrentSiteId();
|
options.siteId = options.siteId || CoreSites.getCurrentSiteId();
|
||||||
options = Object.assign({
|
options = Object.assign({
|
||||||
page: 0,
|
page: 0,
|
||||||
perPage: AddonModDataProvider.PER_PAGE,
|
perPage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
return this.fetchEntriesRecursive(dataId, [], options);
|
return this.fetchEntriesRecursive(dataId, [], options);
|
||||||
|
@ -543,7 +545,7 @@ export class AddonModDataProvider {
|
||||||
* @returns Cache key.
|
* @returns Cache key.
|
||||||
*/
|
*/
|
||||||
protected getDatabaseDataCacheKey(courseId: number): string {
|
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.
|
* @returns Cache key.
|
||||||
*/
|
*/
|
||||||
protected getDatabaseDataPrefixCacheKey(dataId: number): string {
|
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 = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getDatabaseDataCacheKey(courseId),
|
cacheKey: this.getDatabaseDataCacheKey(courseId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
const response =
|
const response =
|
||||||
|
@ -660,7 +662,7 @@ export class AddonModDataProvider {
|
||||||
|
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getDatabaseAccessInformationDataCacheKey(dataId, options.groupId),
|
cacheKey: this.getDatabaseAccessInformationDataCacheKey(dataId, options.groupId),
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
componentId: options.cmId,
|
componentId: options.cmId,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
|
@ -681,7 +683,7 @@ export class AddonModDataProvider {
|
||||||
sort: 0,
|
sort: 0,
|
||||||
order: 'DESC',
|
order: 'DESC',
|
||||||
page: 0,
|
page: 0,
|
||||||
perPage: AddonModDataProvider.PER_PAGE,
|
perPage: ADDON_MOD_DATA_ENTRIES_PER_PAGE,
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const site = await CoreSites.getSite(options.siteId);
|
const site = await CoreSites.getSite(options.siteId);
|
||||||
|
@ -699,7 +701,7 @@ export class AddonModDataProvider {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getEntriesCacheKey(dataId, options.groupId),
|
cacheKey: this.getEntriesCacheKey(dataId, options.groupId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
componentId: options.cmId,
|
componentId: options.cmId,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
|
@ -757,7 +759,7 @@ export class AddonModDataProvider {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getEntryCacheKey(dataId, entryId),
|
cacheKey: this.getEntryCacheKey(dataId, entryId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
componentId: options.cmId,
|
componentId: options.cmId,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
|
@ -809,7 +811,7 @@ export class AddonModDataProvider {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getFieldsCacheKey(dataId),
|
cacheKey: this.getFieldsCacheKey(dataId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
componentId: options.cmId,
|
componentId: options.cmId,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
|
@ -911,7 +913,7 @@ export class AddonModDataProvider {
|
||||||
* @returns Promise resolved when the files are invalidated.
|
* @returns Promise resolved when the files are invalidated.
|
||||||
*/
|
*/
|
||||||
async invalidateFiles(moduleId: number, siteId?: string): Promise<void> {
|
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(
|
await CoreCourseLogHelper.log(
|
||||||
'mod_data_view_database',
|
'mod_data_view_database',
|
||||||
params,
|
params,
|
||||||
AddonModDataProvider.COMPONENT,
|
ADDON_MOD_DATA_COMPONENT,
|
||||||
id,
|
id,
|
||||||
siteId,
|
siteId,
|
||||||
);
|
);
|
||||||
|
@ -989,7 +991,7 @@ export class AddonModDataProvider {
|
||||||
options.sort = options.sort || 0;
|
options.sort = options.sort || 0;
|
||||||
options.order = options.order || 'DESC';
|
options.order = options.order || 'DESC';
|
||||||
options.page = options.page || 0;
|
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;
|
options.readingStrategy = options.readingStrategy || CoreSitesReadingStrategy.PREFER_NETWORK;
|
||||||
|
|
||||||
const params: AddonModDataSearchEntriesWSParams = {
|
const params: AddonModDataSearchEntriesWSParams = {
|
||||||
|
@ -1000,7 +1002,7 @@ export class AddonModDataProvider {
|
||||||
perpage: options.perPage,
|
perpage: options.perPage,
|
||||||
};
|
};
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
component: AddonModDataProvider.COMPONENT,
|
component: ADDON_MOD_DATA_COMPONENT,
|
||||||
componentId: options.cmId,
|
componentId: options.cmId,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets.
|
||||||
};
|
};
|
||||||
|
@ -1087,7 +1089,7 @@ export type AddonModDataGetEntriesOptions = CoreCourseCommonModWSOptions & {
|
||||||
// -4: timemodified
|
// -4: timemodified
|
||||||
order?: string; // The direction of the sorting: 'ASC' or 'DESC'. Defaults to 'DESC'.
|
order?: string; // The direction of the sorting: 'ASC' or 'DESC'. Defaults to 'DESC'.
|
||||||
page?: number; // Page of records to return. Defaults to 0.
|
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.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,8 +21,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModDataModuleHandlerService } from './module';
|
import { ADDON_MOD_DATA_FEATURE_NAME, ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
|
||||||
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content links handler for database add or edit entry.
|
* Content links handler for database add or edit entry.
|
||||||
|
@ -56,7 +55,7 @@ export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerB
|
||||||
};
|
};
|
||||||
|
|
||||||
await CoreNavigator.navigateToSitePath(
|
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 },
|
{ siteId, params: pageParams },
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { Injectable, Type } from '@angular/core';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
||||||
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
|
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
import { ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support data modules.
|
* Handler to support data modules.
|
||||||
|
@ -24,11 +25,9 @@ import { makeSingleton } from '@singletons';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModDataModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
export class AddonModDataModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
||||||
|
|
||||||
static readonly PAGE_NAME = 'mod_data';
|
|
||||||
|
|
||||||
name = 'AddonModData';
|
name = 'AddonModData';
|
||||||
modName = 'data';
|
modName = 'data';
|
||||||
protected pageName = AddonModDataModuleHandlerService.PAGE_NAME;
|
protected pageName = ADDON_MOD_DATA_PAGE_NAME;
|
||||||
|
|
||||||
supportedFeatures = {
|
supportedFeatures = {
|
||||||
[CoreConstants.FEATURE_GROUPS]: true,
|
[CoreConstants.FEATURE_GROUPS]: true,
|
||||||
|
|
|
@ -24,9 +24,10 @@ import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreWSFile } from '@services/ws';
|
import { CoreWSFile } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModDataProvider, AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
|
import { AddonModDataEntry, AddonModData, AddonModDataData } from '../data';
|
||||||
import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync';
|
import { AddonModDataSync, AddonModDataSyncResult } from '../data-sync';
|
||||||
import { ContextLevel } from '@/core/constants';
|
import { ContextLevel } from '@/core/constants';
|
||||||
|
import { ADDON_MOD_DATA_COMPONENT } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to prefetch databases.
|
* Handler to prefetch databases.
|
||||||
|
@ -36,7 +37,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
|
||||||
|
|
||||||
name = 'AddonModData';
|
name = 'AddonModData';
|
||||||
modName = 'data';
|
modName = 'data';
|
||||||
component = AddonModDataProvider.COMPONENT;
|
component = ADDON_MOD_DATA_COMPONENT;
|
||||||
updatesNames = /^configuration$|^.*files$|^entries$|^gradeitems$|^outcomes$|^comments$|^ratings/;
|
updatesNames = /^configuration$|^.*files$|^entries$|^gradeitems$|^outcomes$|^comments$|^ratings/;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,8 +21,7 @@ import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModDataModuleHandlerService } from './module';
|
import { ADDON_MOD_DATA_FEATURE_NAME, ADDON_MOD_DATA_PAGE_NAME } from '../../constants';
|
||||||
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content links handler for database show entry.
|
* Content links handler for database show entry.
|
||||||
|
@ -67,7 +66,7 @@ export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerB
|
||||||
}
|
}
|
||||||
|
|
||||||
await CoreNavigator.navigateToSitePath(
|
await CoreNavigator.navigateToSitePath(
|
||||||
`${AddonModDataModuleHandlerService.PAGE_NAME}/${module.course}/${module.id}/${rId}`,
|
`${ADDON_MOD_DATA_PAGE_NAME}/${module.course}/${module.id}/${rId}`,
|
||||||
{ siteId, params: pageParams },
|
{ siteId, params: pageParams },
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue