Remove the deprecation warning in the CollectionStringModelMapperService

This commit is contained in:
FinnStutzenstein 2018-11-02 08:34:33 +01:00
parent 5b3e63ac82
commit b749231213
15 changed files with 77 additions and 48 deletions

View File

@ -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<BaseModel> } = {};
/**
* 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<BaseModel>): string {
return Object.keys(CollectionStringModelMapperService.collectionStringsTypeMapping).find(
(collectionString: string) => {
return ctor === CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString];
}
);
}
private collectionStringsTypeMapping: { [collectionString: string]: ModelConstructor<BaseModel> } = {};
/**
* 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<BaseModel>): 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<BaseModel> {
return CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString];
return this.collectionStringsTypeMapping[collectionString];
}
/**
@ -55,10 +42,8 @@ export class CollectionStringModelMapperService {
* @param ctor
*/
public getCollectionString(ctor: ModelConstructor<BaseModel>): 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];
});
}
}

View File

@ -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]
});
});

View File

@ -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<ViewItem, Item> {
public constructor(DS: DataStoreService) {
super(DS, Item);
public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, mapperService, Item);
}
/**

View File

@ -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,
* Constructor for the Assignment Repository.
*
*/
public constructor(DS: DataStoreService) {
super(DS, Assignment, [User, Item, Tag]);
public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, mapperService, Assignment, [User, Item, Tag]);
}
public async update(assignment: Partial<Assignment>, viewAssignment: ViewAssignment): Promise<void> {

View File

@ -30,6 +30,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
*/
public constructor(
protected DS: DataStoreService,
protected collectionStringModelMapperService: CollectionStringModelMapperService,
protected baseModelCtor: ModelConstructor<M>,
protected depsModelCtors?: ModelConstructor<BaseModel>[]
) {
@ -67,7 +68,7 @@ export abstract class BaseRepository<V extends BaseViewModel, M extends BaseMode
// Watch the Observables for deleting
this.DS.deletedObservable.subscribe(model => {
if (model.collection === CollectionStringModelMapperService.getCollectionString(this.baseModelCtor)) {
if (model.collection === this.collectionStringModelMapperService.getCollectionString(this.baseModelCtor)) {
delete this.viewModelStore[model.id];
this.updateAllObservables(model.id);
}

View File

@ -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<ViewConfig, Config>
/**
* 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<ViewConfig, Config>
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);
}
/**

View File

@ -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<ViewMediafile, Me
* Consturctor for the file repo
* @param DS the DataStore
*/
public constructor(DS: DataStoreService) {
super(DS, Mediafile, [User]);
public constructor(DS: DataStoreService, mapperService: CollectionStringModelMapperService) {
super(DS, mapperService, Mediafile, [User]);
}
/**

View File

@ -8,6 +8,7 @@ import { Motion } from '../../../shared/models/motions/motion';
import { CategoryNumbering } from '../models/category-numbering';
import { HttpService } from '../../../core/services/http.service';
import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/**
* Repository Services for Categories
@ -31,10 +32,11 @@ export class CategoryRepositoryService extends BaseRepository<ViewCategory, Cate
*/
public constructor(
protected DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService,
private httpService: HttpService
) {
super(DS, Category);
super(DS, mapperService, Category);
}
protected createViewModel(category: Category): ViewCategory {

View File

@ -11,6 +11,7 @@ import { DataStoreService } from '../../../core/services/data-store.service';
import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco';
import { ViewChangeReco } from '../models/view-change-reco';
import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/**
* Repository Services for change recommendations
@ -34,8 +35,12 @@ export class ChangeRecommendationRepositoryService extends BaseRepository<ViewCh
* @param DS
* @param dataSend
*/
public constructor(DS: DataStoreService, private dataSend: DataSendService) {
super(DS, MotionChangeReco, [Category, User, Workflow]);
public constructor(
DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, MotionChangeReco, [Category, User, Workflow]);
}
/**

View File

@ -6,6 +6,7 @@ import { ViewMotionCommentSection } from '../models/view-motion-comment-section'
import { MotionCommentSection } from '../../../shared/models/motions/motion-comment-section';
import { Group } from '../../../shared/models/users/group';
import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/**
* Repository Services for Categories
@ -30,8 +31,12 @@ export class MotionCommentSectionRepositoryService extends BaseRepository<
* Handles CRUD using an observer to the DataStore
* @param DataSend
*/
public constructor(protected DS: DataStoreService, private dataSend: DataSendService) {
super(DS, MotionCommentSection, [Group]);
public constructor(
protected DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, MotionCommentSection, [Group]);
}
protected createViewModel(section: MotionCommentSection): ViewMotionCommentSection {

View File

@ -15,6 +15,7 @@ import { ViewChangeReco } from '../models/view-change-reco';
import { MotionChangeReco } from '../../../shared/models/motions/motion-change-reco';
import { ViewUnifiedChange } from '../models/view-unified-change';
import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/**
* Repository Services for motions (and potentially categories)
@ -42,11 +43,12 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
*/
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]);
}
/**

View File

@ -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<ViewStatut
* Handles CRUD using an observer to the DataStore
* @param DataSend
*/
public constructor(protected DS: DataStoreService, private dataSend: DataSendService) {
super(DS, StatuteParagraph);
public constructor(
DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService
) {
super(DS, mapperService, StatuteParagraph);
}
protected createViewModel(statuteParagraph: StatuteParagraph): ViewStatuteParagraph {

View File

@ -5,6 +5,7 @@ import { DataSendService } from '../../../core/services/data-send.service';
import { DataStoreService } from '../../../core/services/data-store.service';
import { BaseRepository } from '../../base/base-repository';
import { Identifiable } from '../../../shared/models/base/identifiable';
import { CollectionStringModelMapperService } from '../../../core/services/collectionStringModelMapper.service';
/**
* Repository Services for Tags
@ -26,8 +27,12 @@ export class TagRepositoryService extends BaseRepository<ViewTag, Tag> {
* 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 {

View File

@ -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<ViewGroup, Group> {
* @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();
}

View File

@ -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<ViewUser, User> {
/**
* 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]);
}
/**