mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +00:00
[DURACOM-247] Refactored by using a map of promises
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
take,
|
take,
|
||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
|
|
||||||
import { APP_DATA_SERVICES_MAP } from '../../../../config/app-config.interface';
|
import { APP_DATA_SERVICES_MAP, LazyDataServicesMap } from '../../../../config/app-config.interface';
|
||||||
import { TestDataService } from '../../../shared/testing/test-data-service.mock';
|
import { TestDataService } from '../../../shared/testing/test-data-service.mock';
|
||||||
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
||||||
import { HALLink } from '../../shared/hal-link.model';
|
import { HALLink } from '../../shared/hal-link.model';
|
||||||
@@ -37,9 +37,9 @@ class TestModel implements HALResource {
|
|||||||
successor?: TestModel;
|
successor?: TestModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockDataServiceMap: any = {
|
const mockDataServiceMap: any = new Map([
|
||||||
[TEST_MODEL.value]: () => import('../../../shared/testing/test-data-service.mock').then(m => m.TestDataService),
|
[TEST_MODEL.value, () => import('../../../shared/testing/test-data-service.mock').then(m => m.TestDataService)],
|
||||||
};
|
]);
|
||||||
|
|
||||||
let testDataService: TestDataService;
|
let testDataService: TestDataService;
|
||||||
|
|
||||||
|
@@ -69,7 +69,75 @@ import { CLAIMED_TASK } from './tasks/models/claimed-task-object.resource-type';
|
|||||||
import { POOL_TASK } from './tasks/models/pool-task-object.resource-type';
|
import { POOL_TASK } from './tasks/models/pool-task-object.resource-type';
|
||||||
import { WORKFLOW_ACTION } from './tasks/models/workflow-action-object.resource-type';
|
import { WORKFLOW_ACTION } from './tasks/models/workflow-action-object.resource-type';
|
||||||
|
|
||||||
export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
|
export const LAZY_DATA_SERVICES: LazyDataServicesMap = new Map([
|
||||||
|
[AUTHORIZATION.value, () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService)],
|
||||||
|
[BROWSE_DEFINITION.value, () => import('./browse/browse-definition-data.service').then(m => m.BrowseDefinitionDataService)],
|
||||||
|
[BULK_ACCESS_CONDITION_OPTIONS.value, () => import('./config/bulk-access-config-data.service').then(m => m.BulkAccessConfigDataService)],
|
||||||
|
[METADATA_SCHEMA.value, () => import('./data/metadata-schema-data.service').then(m => m.MetadataSchemaDataService)],
|
||||||
|
[SUBMISSION_UPLOADS_TYPE.value, () => import('./config/submission-uploads-config-data.service').then(m => m.SubmissionUploadsConfigDataService)],
|
||||||
|
[BITSTREAM.value, () => import('./data/bitstream-data.service').then(m => m.BitstreamDataService)],
|
||||||
|
[SUBMISSION_ACCESSES_TYPE.value, () => import('./config/submission-accesses-config-data.service').then(m => m.SubmissionAccessesConfigDataService)],
|
||||||
|
[SYSTEMWIDEALERT.value, () => import('./data/system-wide-alert-data.service').then(m => m.SystemWideAlertDataService)],
|
||||||
|
[USAGE_REPORT.value, () => import('./statistics/usage-report-data.service').then(m => m.UsageReportDataService)],
|
||||||
|
[ACCESS_STATUS.value, () => import('./data/access-status-data.service').then(m => m.AccessStatusDataService)],
|
||||||
|
[COLLECTION.value, () => import('./data/collection-data.service').then(m => m.CollectionDataService)],
|
||||||
|
[CLAIMED_TASK.value, () => import('./tasks/claimed-task-data.service').then(m => m.ClaimedTaskDataService)],
|
||||||
|
[VOCABULARY_ENTRY.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
|
||||||
|
[ITEM_TYPE.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
|
||||||
|
[LICENSE.value, () => import('./data/href-only-data.service').then(m => m.HrefOnlyDataService)],
|
||||||
|
[SUBSCRIPTION.value, () => import('../shared/subscriptions/subscriptions-data.service').then(m => m.SubscriptionsDataService)],
|
||||||
|
[COMMUNITY.value, () => import('./data/community-data.service').then(m => m.CommunityDataService)],
|
||||||
|
[VOCABULARY.value, () => import('./submission/vocabularies/vocabulary.data.service').then(m => m.VocabularyDataService)],
|
||||||
|
[BUNDLE.value, () => import('./data/bundle-data.service').then(m => m.BundleDataService)],
|
||||||
|
[CONFIG_PROPERTY.value, () => import('./data/configuration-data.service').then(m => m.ConfigurationDataService)],
|
||||||
|
[POOL_TASK.value, () => import('./tasks/pool-task-data.service').then(m => m.PoolTaskDataService)],
|
||||||
|
[CLAIMED_TASK.value, () => import('./tasks/claimed-task-data.service').then(m => m.ClaimedTaskDataService)],
|
||||||
|
[SUPERVISION_ORDER.value, () => import('./supervision-order/supervision-order-data.service').then(m => m.SupervisionOrderDataService)],
|
||||||
|
[WORKSPACEITEM.value, () => import('./submission/workspaceitem-data.service').then(m => m.WorkspaceitemDataService)],
|
||||||
|
[WORKFLOWITEM.value, () => import('./submission/workflowitem-data.service').then(m => m.WorkflowItemDataService)],
|
||||||
|
[VOCABULARY.value, () => import('./submission/vocabularies/vocabulary.data.service').then(m => m.VocabularyDataService)],
|
||||||
|
[VOCABULARY_ENTRY_DETAIL.value, () => import('./submission/vocabularies/vocabulary-entry-details.data.service').then(m => m.VocabularyEntryDetailsDataService)],
|
||||||
|
[SUBMISSION_CC_LICENSE_URL.value, () => import('./submission/submission-cc-license-url-data.service').then(m => m.SubmissionCcLicenseUrlDataService)],
|
||||||
|
[SUBMISSION_CC_LICENSE.value, () => import('./submission/submission-cc-license-data.service').then(m => m.SubmissionCcLicenseDataService)],
|
||||||
|
[USAGE_REPORT.value, () => import('./statistics/usage-report-data.service').then(m => m.UsageReportDataService)],
|
||||||
|
[RESOURCE_POLICY.value, () => import('./resource-policy/resource-policy-data.service').then(m => m.ResourcePolicyDataService)],
|
||||||
|
[RESEARCHER_PROFILE.value, () => import('./profile/researcher-profile-data.service').then(m => m.ResearcherProfileDataService)],
|
||||||
|
[ORCID_QUEUE.value, () => import('./orcid/orcid-queue-data.service').then(m => m.OrcidQueueDataService)],
|
||||||
|
[ORCID_HISTORY.value, () => import('./orcid/orcid-history-data.service').then(m => m.OrcidHistoryDataService)],
|
||||||
|
[FEEDBACK.value, () => import('./feedback/feedback-data.service').then(m => m.FeedbackDataService)],
|
||||||
|
[GROUP.value, () => import('./eperson/group-data.service').then(m => m.GroupDataService)],
|
||||||
|
[EPERSON.value, () => import('./eperson/eperson-data.service').then(m => m.EPersonDataService)],
|
||||||
|
[WORKFLOW_ACTION.value, () => import('./data/workflow-action-data.service').then(m => m.WorkflowActionDataService)],
|
||||||
|
[VERSION_HISTORY.value, () => import('./data/version-history-data.service').then(m => m.VersionHistoryDataService)],
|
||||||
|
[SITE.value, () => import('./data/site-data.service').then(m => m.SiteDataService)],
|
||||||
|
[ROOT.value, () => import('./data/root-data.service').then(m => m.RootDataService)],
|
||||||
|
[RELATIONSHIP_TYPE.value, () => import('./data/relationship-type-data.service').then(m => m.RelationshipTypeDataService)],
|
||||||
|
[RELATIONSHIP.value, () => import('./data/relationship-data.service').then(m => m.RelationshipDataService)],
|
||||||
|
[SCRIPT.value, () => import('./data/processes/script-data.service').then(m => m.ScriptDataService)],
|
||||||
|
[PROCESS.value, () => import('./data/processes/process-data.service').then(m => m.ProcessDataService)],
|
||||||
|
[METADATA_FIELD.value, () => import('./data/metadata-field-data.service').then(m => m.MetadataFieldDataService)],
|
||||||
|
[ITEM.value, () => import('./data/item-data.service').then(m => m.ItemDataService)],
|
||||||
|
[VERSION.value, () => import('./data/version-data.service').then(m => m.VersionDataService)],
|
||||||
|
[IDENTIFIERS.value, () => import('./data/identifier-data.service').then(m => m.IdentifierDataService)],
|
||||||
|
[FEATURE.value, () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService)],
|
||||||
|
[DSPACE_OBJECT.value, () => import('./data/dspace-object-data.service').then(m => m.DSpaceObjectDataService)],
|
||||||
|
[BITSTREAM_FORMAT.value, () => import('./data/bitstream-format-data.service').then(m => m.BitstreamFormatDataService)],
|
||||||
|
[SUBMISSION_COAR_NOTIFY_CONFIG.value, () => import('../submission/sections/section-coar-notify/coar-notify-config-data.service').then(m => m.CoarNotifyConfigDataService)],
|
||||||
|
[LDN_SERVICE_CONSTRAINT_FILTERS.value, () => import('../admin/admin-ldn-services/ldn-services-data/ldn-itemfilters-data.service').then(m => m.LdnItemfiltersService)],
|
||||||
|
[LDN_SERVICE.value, () => import('../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service').then(m => m.LdnServicesService)],
|
||||||
|
[ADMIN_NOTIFY_MESSAGE.value, () => import('../admin/admin-notify-dashboard/services/admin-notify-messages.service').then(m => m.AdminNotifyMessagesService)],
|
||||||
|
[SUBMISSION_FORMS_TYPE.value, () => import('./config/submission-forms-config-data.service').then(m => m.SubmissionFormsConfigDataService)],
|
||||||
|
[NOTIFYREQUEST.value, () => import('./data/notify-services-status-data.service').then(m => m.NotifyRequestsStatusDataService)],
|
||||||
|
[QUALITY_ASSURANCE_EVENT_OBJECT.value, () => import('./notifications/qa/events/quality-assurance-event-data.service').then(m => m.QualityAssuranceEventDataService)],
|
||||||
|
[QUALITY_ASSURANCE_SOURCE_OBJECT.value, () => import('./notifications/qa/source/quality-assurance-source-data.service').then(m => m.QualityAssuranceSourceDataService)],
|
||||||
|
[QUALITY_ASSURANCE_TOPIC_OBJECT.value, () => import('./notifications/qa/topics/quality-assurance-topic-data.service').then(m => m.QualityAssuranceTopicDataService)],
|
||||||
|
[SUGGESTION.value, () => import('./notifications/suggestions-data.service').then(m => m.SuggestionsDataService)],
|
||||||
|
[SUGGESTION_SOURCE.value, () => import('./notifications/source/suggestion-source-data.service').then(m => m.SuggestionSourceDataService)],
|
||||||
|
[SUGGESTION_TARGET.value, () => import('./notifications/target/suggestion-target-data.service').then(m => m.SuggestionTargetDataService)],
|
||||||
|
[DUPLICATE.value, () => import('./submission/submission-duplicate-data.service').then(m => m.SubmissionDuplicateDataService)],
|
||||||
|
[CorrectionType.type.value, () => import('./submission/correctiontype-data.service').then(m => m.CorrectionTypeDataService)],
|
||||||
|
]);
|
||||||
|
/*export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
|
||||||
[AUTHORIZATION.value]: () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService),
|
[AUTHORIZATION.value]: () => import('./data/feature-authorization/authorization-data.service').then(m => m.AuthorizationDataService),
|
||||||
[BROWSE_DEFINITION.value]: () => import('./browse/browse-definition-data.service').then(m => m.BrowseDefinitionDataService),
|
[BROWSE_DEFINITION.value]: () => import('./browse/browse-definition-data.service').then(m => m.BrowseDefinitionDataService),
|
||||||
[BULK_ACCESS_CONDITION_OPTIONS.value]: () => import('./config/bulk-access-config-data.service').then(m => m.BulkAccessConfigDataService),
|
[BULK_ACCESS_CONDITION_OPTIONS.value]: () => import('./config/bulk-access-config-data.service').then(m => m.BulkAccessConfigDataService),
|
||||||
@@ -136,6 +204,6 @@ export const LAZY_DATA_SERVICES: LazyDataServicesMap = {
|
|||||||
[SUGGESTION_TARGET.value]: () => import('./notifications/target/suggestion-target-data.service').then(m => m.SuggestionTargetDataService),
|
[SUGGESTION_TARGET.value]: () => import('./notifications/target/suggestion-target-data.service').then(m => m.SuggestionTargetDataService),
|
||||||
[DUPLICATE.value]: () => import('./submission/submission-duplicate-data.service').then(m => m.SubmissionDuplicateDataService),
|
[DUPLICATE.value]: () => import('./submission/submission-duplicate-data.service').then(m => m.SubmissionDuplicateDataService),
|
||||||
[CorrectionType.type.value]: () => import('./submission/correctiontype-data.service').then(m => m.CorrectionTypeDataService),
|
[CorrectionType.type.value]: () => import('./submission/correctiontype-data.service').then(m => m.CorrectionTypeDataService),
|
||||||
};
|
};*/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -8,13 +8,12 @@ import {
|
|||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
|
|
||||||
import { LazyDataServicesMap } from '../../config/app-config.interface';
|
import { LazyDataServicesMap } from '../../config/app-config.interface';
|
||||||
import { isNotEmpty } from '../shared/empty.util';
|
|
||||||
import { HALDataService } from './data/base/hal-data-service.interface';
|
import { HALDataService } from './data/base/hal-data-service.interface';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a service lazily. The service is loaded when the observable is subscribed to.
|
* Loads a service lazily. The service is loaded when the observable is subscribed to.
|
||||||
*
|
*
|
||||||
* @param map A map of promises returning the data services to load
|
* @param dataServicesMap A map of promises returning the data services to load
|
||||||
* @param key The key of the service
|
* @param key The key of the service
|
||||||
* @param injector The injector to use to load the service. If not provided, the current injector is used.
|
* @param injector The injector to use to load the service. If not provided, the current injector is used.
|
||||||
* @returns An observable of the service.
|
* @returns An observable of the service.
|
||||||
@@ -27,13 +26,13 @@ import { HALDataService } from './data/base/hal-data-service.interface';
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function lazyDataService<T>(
|
export function lazyDataService<T>(
|
||||||
map: LazyDataServicesMap,
|
dataServicesMap: LazyDataServicesMap,
|
||||||
key: string,
|
key: string,
|
||||||
injector: Injector,
|
injector: Injector,
|
||||||
): Observable<T> {
|
): Observable<T> {
|
||||||
return defer(() => {
|
return defer(() => {
|
||||||
if (isNotEmpty(map[key]) && typeof map[key] === 'function') {
|
if (dataServicesMap.has(key) && typeof dataServicesMap.get(key) === 'function') {
|
||||||
const loader: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }> = map[key];
|
const loader: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }> = dataServicesMap.get(key);
|
||||||
return loader()
|
return loader()
|
||||||
.then((serviceOrDefault) => {
|
.then((serviceOrDefault) => {
|
||||||
if ('default' in serviceOrDefault) {
|
if ('default' in serviceOrDefault) {
|
||||||
|
@@ -38,9 +38,9 @@ const REINSTATE_BTN = 'reinstate';
|
|||||||
const SAVE_BTN = 'save';
|
const SAVE_BTN = 'save';
|
||||||
const DISCARD_BTN = 'discard';
|
const DISCARD_BTN = 'discard';
|
||||||
|
|
||||||
const mockDataServiceMap: any = {
|
const mockDataServiceMap: any = new Map([
|
||||||
[ITEM.value]: () => import('../../shared/testing/test-data-service.mock').then(m => m.TestDataService),
|
[ITEM.value, () => import('../../shared/testing/test-data-service.mock').then(m => m.TestDataService)],
|
||||||
};
|
]);
|
||||||
|
|
||||||
describe('DsoEditMetadataComponent', () => {
|
describe('DsoEditMetadataComponent', () => {
|
||||||
let component: DsoEditMetadataComponent;
|
let component: DsoEditMetadataComponent;
|
||||||
|
@@ -17,7 +17,10 @@ import { cold } from 'jasmine-marbles';
|
|||||||
import uniqueId from 'lodash/uniqueId';
|
import uniqueId from 'lodash/uniqueId';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
import { APP_DATA_SERVICES_MAP } from '../../../config/app-config.interface';
|
import {
|
||||||
|
APP_DATA_SERVICES_MAP,
|
||||||
|
LazyDataServicesMap,
|
||||||
|
} from '../../../config/app-config.interface';
|
||||||
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
|
||||||
import { buildPaginatedList } from '../../core/data/paginated-list.model';
|
import { buildPaginatedList } from '../../core/data/paginated-list.model';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
import { RequestService } from '../../core/data/request.service';
|
||||||
@@ -41,10 +44,10 @@ import { SearchEvent } from './eperson-group-list-event-type';
|
|||||||
import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component';
|
import { EpersonSearchBoxComponent } from './eperson-search-box/eperson-search-box.component';
|
||||||
import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component';
|
import { GroupSearchBoxComponent } from './group-search-box/group-search-box.component';
|
||||||
|
|
||||||
const mockDataServiceMap: any = {
|
const mockDataServiceMap: LazyDataServicesMap = new Map([
|
||||||
[EPERSON.value]: () => import('../../core/eperson/eperson-data.service').then(m => m.EPersonDataService),
|
[EPERSON.value, () => import('../../core/eperson/eperson-data.service').then(m => m.EPersonDataService)],
|
||||||
[GROUP.value]: () => import('../../core/eperson/group-data.service').then(m => m.GroupDataService),
|
[GROUP.value, () => import('../../core/eperson/group-data.service').then(m => m.GroupDataService)],
|
||||||
};
|
]);
|
||||||
|
|
||||||
describe('EpersonGroupListComponent test suite', () => {
|
describe('EpersonGroupListComponent test suite', () => {
|
||||||
let comp: EpersonGroupListComponent;
|
let comp: EpersonGroupListComponent;
|
||||||
|
@@ -73,9 +73,7 @@ const APP_CONFIG = new InjectionToken<AppConfig>('APP_CONFIG');
|
|||||||
|
|
||||||
const APP_CONFIG_STATE = makeStateKey<AppConfig>('APP_CONFIG_STATE');
|
const APP_CONFIG_STATE = makeStateKey<AppConfig>('APP_CONFIG_STATE');
|
||||||
|
|
||||||
export interface LazyDataServicesMap {
|
export type LazyDataServicesMap = Map<string, () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }>>;
|
||||||
[type: string]: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const APP_DATA_SERVICES_MAP: InjectionToken<LazyDataServicesMap> = new InjectionToken<LazyDataServicesMap>('APP_DATA_SERVICES_MAP');
|
export const APP_DATA_SERVICES_MAP: InjectionToken<LazyDataServicesMap> = new InjectionToken<LazyDataServicesMap>('APP_DATA_SERVICES_MAP');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user