From b74923121307f90ed88f220961adb74aa0461821 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 2 Nov 2018 08:34:33 +0100 Subject: [PATCH] Remove the deprecation warning in the CollectionStringModelMapperService --- .../collectionStringModelMapper.service.ts | 27 +++++-------------- .../agenda-repository.service.spec.ts | 2 ++ .../services/agenda-repository.service.ts | 5 ++-- .../services/assignment-repository.service.ts | 5 ++-- client/src/app/site/base/base-repository.ts | 3 ++- .../services/config-repository.service.ts | 15 ++++++----- .../services/mediafile-repository.service.ts | 5 ++-- .../services/category-repository.service.ts | 4 ++- ...hange-recommendation-repository.service.ts | 9 +++++-- ...tion-comment-section-repository.service.ts | 9 +++++-- .../services/motion-repository.service.ts | 4 ++- .../statute-paragraph-repository.service.ts | 9 +++++-- .../tags/services/tag-repository.service.ts | 9 +++++-- .../services/group-repository.service.ts | 10 +++++-- .../users/services/user-repository.service.ts | 9 +++++-- 15 files changed, 77 insertions(+), 48 deletions(-) diff --git a/client/src/app/core/services/collectionStringModelMapper.service.ts b/client/src/app/core/services/collectionStringModelMapper.service.ts index 0cea0511f..9c749f085 100644 --- a/client/src/app/core/services/collectionStringModelMapper.service.ts +++ b/client/src/app/core/services/collectionStringModelMapper.service.ts @@ -12,20 +12,7 @@ export class CollectionStringModelMapperService { * Mapps collection strings to model constructors. Accessed by {@method registerCollectionElement} and * {@method getCollectionStringType}. */ - private static collectionStringsTypeMapping: { [collectionString: string]: ModelConstructor } = {}; - - /** - * Returns the collection string of a given ModelConstructor or undefined, if it is not registered. - * @param ctor - * @deprecated Should inject this service and don't use the static functions. - */ - public static getCollectionString(ctor: ModelConstructor): string { - return Object.keys(CollectionStringModelMapperService.collectionStringsTypeMapping).find( - (collectionString: string) => { - return ctor === CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString]; - } - ); - } + private collectionStringsTypeMapping: { [collectionString: string]: ModelConstructor } = {}; /** * Constructor to create the NotifyService. Registers itself to the WebsocketService. @@ -39,7 +26,7 @@ export class CollectionStringModelMapperService { * @param type */ public registerCollectionElement(collectionString: string, type: ModelConstructor): void { - CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString] = type; + this.collectionStringsTypeMapping[collectionString] = type; } /** @@ -47,7 +34,7 @@ export class CollectionStringModelMapperService { * @param collectionString the requested collection */ public getModelConstructor(collectionString: string): ModelConstructor { - return CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString]; + return this.collectionStringsTypeMapping[collectionString]; } /** @@ -55,10 +42,8 @@ export class CollectionStringModelMapperService { * @param ctor */ public getCollectionString(ctor: ModelConstructor): string { - return Object.keys(CollectionStringModelMapperService.collectionStringsTypeMapping).find( - (collectionString: string) => { - return ctor === CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString]; - } - ); + return Object.keys(this.collectionStringsTypeMapping).find((collectionString: string) => { + return ctor === this.collectionStringsTypeMapping[collectionString]; + }); } } diff --git a/client/src/app/site/agenda/services/agenda-repository.service.spec.ts b/client/src/app/site/agenda/services/agenda-repository.service.spec.ts index 870d49958..ab4c893ae 100644 --- a/client/src/app/site/agenda/services/agenda-repository.service.spec.ts +++ b/client/src/app/site/agenda/services/agenda-repository.service.spec.ts @@ -1,10 +1,12 @@ import { TestBed, inject } from '@angular/core/testing'; import { AgendaRepositoryService } from './agenda-repository.service'; +import { E2EImportsModule } from 'e2e-imports.module'; describe('AgendaRepositoryService', () => { beforeEach(() => { TestBed.configureTestingModule({ + imports: [E2EImportsModule], providers: [AgendaRepositoryService] }); }); diff --git a/client/src/app/site/agenda/services/agenda-repository.service.ts b/client/src/app/site/agenda/services/agenda-repository.service.ts index 7cb6029dc..a747179ff 100644 --- a/client/src/app/site/agenda/services/agenda-repository.service.ts +++ b/client/src/app/site/agenda/services/agenda-repository.service.ts @@ -7,6 +7,7 @@ import { ViewItem } from '../models/view-item'; import { AgendaBaseModel } from '../../../shared/models/base/agenda-base-model'; import { BaseModel } from '../../../shared/models/base/base-model'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Repository service for users @@ -17,8 +18,8 @@ import { Identifiable } from '../../../shared/models/base/identifiable'; providedIn: 'root' }) export class AgendaRepositoryService extends BaseRepository { - public constructor(DS: DataStoreService) { - super(DS, Item); + public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) { + super(DS, mapperService, Item); } /** diff --git a/client/src/app/site/assignments/services/assignment-repository.service.ts b/client/src/app/site/assignments/services/assignment-repository.service.ts index 54b1c3c3d..4d00e5431 100644 --- a/client/src/app/site/assignments/services/assignment-repository.service.ts +++ b/client/src/app/site/assignments/services/assignment-repository.service.ts @@ -7,6 +7,7 @@ import { Item } from '../../../shared/models/agenda/item'; import { BaseRepository } from '../../base/base-repository'; import { DataStoreService } from '../../../core/services/data-store.service'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Repository Service for Assignments. @@ -21,8 +22,8 @@ export class AssignmentRepositoryService extends BaseRepository, viewAssignment: ViewAssignment): Promise { diff --git a/client/src/app/site/base/base-repository.ts b/client/src/app/site/base/base-repository.ts index c98d9ba57..7327891f4 100644 --- a/client/src/app/site/base/base-repository.ts +++ b/client/src/app/site/base/base-repository.ts @@ -30,6 +30,7 @@ export abstract class BaseRepository, protected depsModelCtors?: ModelConstructor[] ) { @@ -67,7 +68,7 @@ export abstract class BaseRepository { - if (model.collection === CollectionStringModelMapperService.getCollectionString(this.baseModelCtor)) { + if (model.collection === this.collectionStringModelMapperService.getCollectionString(this.baseModelCtor)) { delete this.viewModelStore[model.id]; this.updateAllObservables(model.id); } diff --git a/client/src/app/site/config/services/config-repository.service.ts b/client/src/app/site/config/services/config-repository.service.ts index afdde0a24..25fbcb10e 100644 --- a/client/src/app/site/config/services/config-repository.service.ts +++ b/client/src/app/site/config/services/config-repository.service.ts @@ -8,6 +8,7 @@ import { DataStoreService } from '../../../core/services/data-store.service'; import { ConstantsService } from '../../../core/services/constants.service'; import { HttpService } from '../../../core/services/http.service'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Holds a single config item. @@ -86,8 +87,13 @@ export class ConfigRepositoryService extends BaseRepository /** * Constructor for ConfigRepositoryService. Requests the constants from the server and creates the config group structure. */ - public constructor(DS: DataStoreService, private constantsService: ConstantsService, private http: HttpService) { - super(DS, Config); + public constructor( + DS: DataStoreService, + mapperService: CollectionStringModelMapperService, + private constantsService: ConstantsService, + private http: HttpService + ) { + super(DS, mapperService, Config); this.constantsService.get('OpenSlidesConfigVariables').subscribe(constant => { this.createConfigStructure(constant); @@ -186,10 +192,7 @@ export class ConfigRepositoryService extends BaseRepository updatedConfig.patchValues(viewConfig.config); updatedConfig.patchValues(config); // TODO: Use datasendService, if it can switch correctly between put, post and patch - await this.http.put( - 'rest/' + updatedConfig.collectionString + '/' + updatedConfig.key + '/', - updatedConfig - ); + await this.http.put('rest/' + updatedConfig.collectionString + '/' + updatedConfig.key + '/', updatedConfig); } /** diff --git a/client/src/app/site/mediafiles/services/mediafile-repository.service.ts b/client/src/app/site/mediafiles/services/mediafile-repository.service.ts index 0b48b564e..b5c71ac70 100644 --- a/client/src/app/site/mediafiles/services/mediafile-repository.service.ts +++ b/client/src/app/site/mediafiles/services/mediafile-repository.service.ts @@ -6,6 +6,7 @@ import { Mediafile } from '../../../shared/models/mediafiles/mediafile'; import { User } from '../../../shared/models/users/user'; import { DataStoreService } from '../../../core/services/data-store.service'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Repository for files @@ -18,8 +19,8 @@ export class MediafileRepositoryService extends BaseRepository */ public constructor( DS: DataStoreService, + mapperService: CollectionStringModelMapperService, private dataSend: DataSendService, private readonly lineNumbering: LinenumberingService, private readonly diff: DiffService ) { - super(DS, Motion, [Category, User, Workflow]); + super(DS, mapperService, Motion, [Category, User, Workflow]); } /** diff --git a/client/src/app/site/motions/services/statute-paragraph-repository.service.ts b/client/src/app/site/motions/services/statute-paragraph-repository.service.ts index 8d959dfea..c3625c79f 100644 --- a/client/src/app/site/motions/services/statute-paragraph-repository.service.ts +++ b/client/src/app/site/motions/services/statute-paragraph-repository.service.ts @@ -5,6 +5,7 @@ import { BaseRepository } from '../../base/base-repository'; import { ViewStatuteParagraph } from '../models/view-statute-paragraph'; import { StatuteParagraph } from '../../../shared/models/motions/statute-paragraph'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Repository Services for statute paragraphs @@ -23,8 +24,12 @@ export class StatuteParagraphRepositoryService extends BaseRepository { * Handles CRUD using an observer to the DataStore * @param DataSend */ - public constructor(protected DS: DataStoreService, private dataSend: DataSendService) { - super(DS, Tag); + public constructor( + protected DS: DataStoreService, + mapperService: CollectionStringModelMapperService, + private dataSend: DataSendService + ) { + super(DS, mapperService, Tag); } protected createViewModel(tag: Tag): ViewTag { diff --git a/client/src/app/site/users/services/group-repository.service.ts b/client/src/app/site/users/services/group-repository.service.ts index a3c3c91a2..9ea9b17a8 100644 --- a/client/src/app/site/users/services/group-repository.service.ts +++ b/client/src/app/site/users/services/group-repository.service.ts @@ -7,6 +7,7 @@ import { DataStoreService } from '../../../core/services/data-store.service'; import { DataSendService } from '../../../core/services/data-send.service'; import { ConstantsService } from '../../../core/services/constants.service'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Set rules to define the shape of an app permission @@ -35,8 +36,13 @@ export class GroupRepositoryService extends BaseRepository { * @param DS Store * @param dataSend Sending Data */ - public constructor(DS: DataStoreService, private dataSend: DataSendService, private constants: ConstantsService) { - super(DS, Group); + public constructor( + DS: DataStoreService, + mapperService: CollectionStringModelMapperService, + private dataSend: DataSendService, + private constants: ConstantsService + ) { + super(DS, mapperService, Group); this.sortPermsPerApp(); } diff --git a/client/src/app/site/users/services/user-repository.service.ts b/client/src/app/site/users/services/user-repository.service.ts index 401d92163..2153d2be7 100644 --- a/client/src/app/site/users/services/user-repository.service.ts +++ b/client/src/app/site/users/services/user-repository.service.ts @@ -7,6 +7,7 @@ import { Group } from '../../../shared/models/users/group'; import { DataStoreService } from '../../../core/services/data-store.service'; import { DataSendService } from '../../../core/services/data-send.service'; import { Identifiable } from '../../../shared/models/base/identifiable'; +import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service'; /** * Repository service for users @@ -20,8 +21,12 @@ export class UserRepositoryService extends BaseRepository { /** * Constructor calls the parent constructor */ - public constructor(DS: DataStoreService, private dataSend: DataSendService) { - super(DS, User, [Group]); + public constructor( + DS: DataStoreService, + mapperService: CollectionStringModelMapperService, + private dataSend: DataSendService + ) { + super(DS, mapperService, User, [Group]); } /**