diff --git a/client/src/app/core/repositories/agenda/item-repository.service.ts b/client/src/app/core/repositories/agenda/item-repository.service.ts index 7071a52df..9be72a73b 100644 --- a/client/src/app/core/repositories/agenda/item-repository.service.ts +++ b/client/src/app/core/repositories/agenda/item-repository.service.ts @@ -19,6 +19,7 @@ import { BaseAgendaViewModel } from 'app/site/base/base-agenda-view-model'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { BaseViewModel } from 'app/site/base/base-view-model'; import { ViewUser } from 'app/site/users/models/view-user'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository service for users @@ -46,11 +47,39 @@ export class ItemRepositoryService extends BaseRepository { private httpService: HttpService, private config: ConfigService, private dataSend: DataSendService, - private treeService: TreeService + private treeService: TreeService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, Item); } + protected setupDependencyObservation(): void { + this.DS.secondaryModelChangeSubject.subscribe(model => { + const viewModel = this.viewModelStoreService.get(model.collectionString, model.id); + const somethingChanged = this.getViewModelList().some(ownViewModel => { + return ownViewModel.updateDependencies(viewModel); + }); + if (somethingChanged) { + this.updateAllObservables(model.id); + } + }); + } + + /** + * Creates the viewItem out of a given item + * + * @param item the item that should be converted to view item + * @returns a new view item + */ + public createViewModel(item: Item): ViewItem { + const contentObject = this.getContentObject(item); + const viewItem = new ViewItem(item, contentObject); + viewItem.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Items' : 'Item'); + }; + return viewItem; + } + /** * Returns the corresponding content object to a given {@link Item} as an {@link AgendaBaseViewModel} * Used dynamically because of heavy race conditions @@ -216,17 +245,6 @@ export class ItemRepositoryService extends BaseRepository { throw new Error('Method not implemented.'); } - /** - * Creates the viewItem out of a given item - * - * @param item the item that should be converted to view item - * @returns a new view item - */ - public createViewModel(item: Item): ViewItem { - const contentObject = this.getContentObject(item); - return new ViewItem(item, contentObject); - } - /** * Get agenda visibility from the config * diff --git a/client/src/app/core/repositories/agenda/topic-repository.service.ts b/client/src/app/core/repositories/agenda/topic-repository.service.ts index 8e4e3d83d..bb9eabc9a 100644 --- a/client/src/app/core/repositories/agenda/topic-repository.service.ts +++ b/client/src/app/core/repositories/agenda/topic-repository.service.ts @@ -13,6 +13,7 @@ import { CreateTopic } from 'app/site/agenda/models/create-topic'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewMediafile } from 'app/site/mediafiles/models/view-mediafile'; import { ViewItem } from 'app/site/agenda/models/view-item'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository for topics @@ -32,7 +33,8 @@ export class TopicRepositoryService extends BaseRepository { DS: DataStoreService, mapperService: CollectionStringMapperService, viewModelStoreService: ViewModelStoreService, - private dataSend: DataSendService + private dataSend: DataSendService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, Topic, [Mediafile, Item]); } @@ -46,7 +48,11 @@ export class TopicRepositoryService extends BaseRepository { public createViewModel(topic: Topic): ViewTopic { const attachments = this.viewModelStoreService.getMany(ViewMediafile, topic.attachments_id); const item = this.viewModelStoreService.get(ViewItem, topic.agenda_item_id); - return new ViewTopic(topic, attachments, item); + const viewTopic = new ViewTopic(topic, attachments, item); + viewTopic.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Topics' : 'Topic'); + }; + return viewTopic; } /** diff --git a/client/src/app/core/repositories/assignments/assignment-repository.service.ts b/client/src/app/core/repositories/assignments/assignment-repository.service.ts index 07a29da2b..536c81dee 100644 --- a/client/src/app/core/repositories/assignments/assignment-repository.service.ts +++ b/client/src/app/core/repositories/assignments/assignment-repository.service.ts @@ -12,6 +12,7 @@ import { ViewModelStoreService } from 'app/core/core-services/view-model-store.s import { ViewItem } from 'app/site/agenda/models/view-item'; import { ViewUser } from 'app/site/users/models/view-user'; import { ViewTag } from 'app/site/tags/models/view-tag'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository Service for Assignments. @@ -31,11 +32,24 @@ export class AssignmentRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Elections' : 'Election'); + }; + return viewAssignment; + } + public async update(assignment: Partial, viewAssignment: ViewAssignment): Promise { return null; } @@ -47,12 +61,4 @@ export class AssignmentRepositoryService extends BaseRepository { return null; } - - public createViewModel(assignment: Assignment): ViewAssignment { - const relatedUser = this.viewModelStoreService.getMany(ViewUser, assignment.candidateIds); - const agendaItem = this.viewModelStoreService.get(ViewItem, assignment.agenda_item_id); - const tags = this.viewModelStoreService.getMany(ViewTag, assignment.tags_id); - - return new ViewAssignment(assignment, relatedUser, agendaItem, tags); - } } diff --git a/client/src/app/core/repositories/base-repository.ts b/client/src/app/core/repositories/base-repository.ts index fe5279bf2..4a319074f 100644 --- a/client/src/app/core/repositories/base-repository.ts +++ b/client/src/app/core/repositories/base-repository.ts @@ -78,6 +78,24 @@ export abstract class BaseRepository { + if ( + model.collection === + this.collectionStringMapperService.getCollectionStringFromModelConstructor(this.baseModelCtor) + ) { + delete this.viewModelStore[model.id]; + this.updateAllObservables(model.id); + } + }); + } + + protected setupDependencyObservation(): void { if (this.depsModelCtors) { this.DS.secondaryModelChangeSubject.subscribe(model => { const dependencyChanged: boolean = this.depsModelCtors.some(ctor => { @@ -94,20 +112,6 @@ export abstract class BaseRepository { - if ( - model.collection === - this.collectionStringMapperService.getCollectionStringFromModelConstructor(this.baseModelCtor) - ) { - delete this.viewModelStore[model.id]; - this.updateAllObservables(model.id); - } - }); } /** diff --git a/client/src/app/core/repositories/common/chatmessage-repository.service.ts b/client/src/app/core/repositories/common/chatmessage-repository.service.ts index 405b1eae1..0c1fd75d0 100644 --- a/client/src/app/core/repositories/common/chatmessage-repository.service.ts +++ b/client/src/app/core/repositories/common/chatmessage-repository.service.ts @@ -6,6 +6,7 @@ import { CollectionStringMapperService } from '../../core-services/collectionStr import { ChatMessage } from 'app/shared/models/core/chat-message'; import { ViewChatMessage } from 'app/site/common/models/view-chatmessage'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; @Injectable({ providedIn: 'root' @@ -14,13 +15,18 @@ export class ChatMessageRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Chatmessages' : 'Chatmessage'); + }; + return viewChatMessage; } public async create(message: ChatMessage): Promise { diff --git a/client/src/app/core/repositories/config/config-repository.service.ts b/client/src/app/core/repositories/config/config-repository.service.ts index 9fb892ddd..a30c0726d 100644 --- a/client/src/app/core/repositories/config/config-repository.service.ts +++ b/client/src/app/core/repositories/config/config-repository.service.ts @@ -11,6 +11,7 @@ import { Identifiable } from 'app/shared/models/base/identifiable'; import { CollectionStringMapperService } from 'app/core/core-services/collectionStringMapper.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewConfig } from 'app/site/config/models/view-config'; +import { TranslateService } from '@ngx-translate/core'; /** * Holds a single config item. @@ -99,7 +100,8 @@ export class ConfigRepositoryService extends BaseRepository mapperService: CollectionStringMapperService, viewModelStoreService: ViewModelStoreService, private constantsService: ConstantsService, - private http: HttpService + private http: HttpService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, Config); @@ -110,6 +112,18 @@ export class ConfigRepositoryService extends BaseRepository }); } + /** + * Creates a new ViewConfig of a given Config object + * @param config + */ + public createViewModel(config: Config): ViewConfig { + const viewConfig = new ViewConfig(config); + viewConfig.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Configs' : 'Config'); + }; + return viewConfig; + } + /** * Overwritten setup. Does only care about the custom list observable and inserts changed configs into the * config group structure. @@ -223,14 +237,6 @@ export class ConfigRepositoryService extends BaseRepository throw new Error('Config variables cannot be created'); } - /** - * Creates a new ViewConfig of a given Config object - * @param config - */ - public createViewModel(config: Config): ViewConfig { - return new ViewConfig(config); - } - /** * initially create the config structure from the given constant. * @param constant diff --git a/client/src/app/core/repositories/history/history-repository.service.ts b/client/src/app/core/repositories/history/history-repository.service.ts index b3c0f2aa9..c0b93a2cb 100644 --- a/client/src/app/core/repositories/history/history-repository.service.ts +++ b/client/src/app/core/repositories/history/history-repository.service.ts @@ -11,6 +11,7 @@ import { ViewHistory } from 'app/site/history/models/view-history'; import { TimeTravelService } from 'app/core/core-services/time-travel.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { ViewUser } from 'app/site/users/models/view-user'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository for the history. @@ -34,11 +35,27 @@ export class HistoryRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Histories' : 'History'); // Whats about the plural case?? + }; + return viewHistory; + } + /** * Clients usually do not need to create a history object themselves * @ignore @@ -79,17 +96,6 @@ export class HistoryRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Files' : 'File'); + }; + return viewMediafile; + } + /** * Alter a given mediaFile * Usually just i.e change the name and the hidden flag. @@ -83,15 +100,4 @@ export class MediafileRepositoryService extends BaseRepository(restPath, file, {}, emptyHeader); } - - /** - * Creates mediafile ViewModels out of given mediafile objects - * - * @param file mediafile to convert - * @returns a new mediafile ViewModel - */ - public createViewModel(file: Mediafile): ViewMediafile { - const uploader = this.viewModelStoreService.get(ViewUser, file.uploader_id); - return new ViewMediafile(file, uploader); - } } diff --git a/client/src/app/core/repositories/motions/category-repository.service.ts b/client/src/app/core/repositories/motions/category-repository.service.ts index 77f4fde24..96114c361 100644 --- a/client/src/app/core/repositories/motions/category-repository.service.ts +++ b/client/src/app/core/repositories/motions/category-repository.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core'; + import { BehaviorSubject, Observable } from 'rxjs'; import { TranslateService } from '@ngx-translate/core'; @@ -53,7 +54,11 @@ export class CategoryRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Categories' : 'Category'); + }; + return viewCategory; } public async create(newCategory: Category): Promise { diff --git a/client/src/app/core/repositories/motions/change-recommendation-repository.service.ts b/client/src/app/core/repositories/motions/change-recommendation-repository.service.ts index 224a0a94e..0585377a3 100644 --- a/client/src/app/core/repositories/motions/change-recommendation-repository.service.ts +++ b/client/src/app/core/repositories/motions/change-recommendation-repository.service.ts @@ -14,6 +14,7 @@ import { ViewMotionChangeRecommendation } from 'app/site/motions/models/view-cha import { Identifiable } from 'app/shared/models/base/identifiable'; import { CollectionStringMapperService } from 'app/core/core-services/collectionStringMapper.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository Services for change recommendations @@ -46,11 +47,25 @@ export class ChangeRecommendationRepositoryService extends BaseRepository< DS: DataStoreService, mapperService: CollectionStringMapperService, viewModelStoreService: ViewModelStoreService, - private dataSend: DataSendService + private dataSend: DataSendService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, MotionChangeRecommendation, [Category, User, Workflow]); } + /** + * Creates this view wrapper based on an actual Change Recommendation model + * + * @param {MotionChangeRecommendation} model + */ + protected createViewModel(model: MotionChangeRecommendation): ViewMotionChangeRecommendation { + const viewMotionChangeRecommendation = new ViewMotionChangeRecommendation(model); + viewMotionChangeRecommendation.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Change recommendations' : 'Change recommendation'); + }; + return viewMotionChangeRecommendation; + } + /** * Creates a change recommendation * Creates a (real) change recommendation and delegates it to the {@link DataSendService} @@ -70,15 +85,6 @@ export class ChangeRecommendationRepositoryService extends BaseRepository< return await this.dataSend.createModel(view.changeRecommendation); } - /** - * Creates this view wrapper based on an actual Change Recommendation model - * - * @param {MotionChangeRecommendation} model - */ - protected createViewModel(model: MotionChangeRecommendation): ViewMotionChangeRecommendation { - return new ViewMotionChangeRecommendation(model); - } - /** * Deleting a change recommendation. * diff --git a/client/src/app/core/repositories/motions/motion-block-repository.service.ts b/client/src/app/core/repositories/motions/motion-block-repository.service.ts index 598922b44..82975e168 100644 --- a/client/src/app/core/repositories/motions/motion-block-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-block-repository.service.ts @@ -17,6 +17,7 @@ import { ViewMotionBlock } from 'app/site/motions/models/view-motion-block'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; import { Item } from 'app/shared/models/agenda/item'; import { ViewItem } from 'app/site/agenda/models/view-item'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository service for motion blocks @@ -40,11 +41,27 @@ export class MotionBlockRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Motion blocks' : 'Motion block'); + }; + return viewMotionBlock; + } + /** * Updates a given motion block * @@ -77,17 +94,6 @@ export class MotionBlockRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Comment sections' : 'Comment section'); + }; + return viewMotionCommentSection; } /** diff --git a/client/src/app/core/repositories/motions/motion-repository.service.ts b/client/src/app/core/repositories/motions/motion-repository.service.ts index 6d7568f15..3874fb4f6 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -114,7 +114,7 @@ export class MotionRepositoryService extends BaseRepository if (workflow) { state = workflow.getStateById(motion.state_id); } - return new ViewMotion( + const viewMotion = new ViewMotion( motion, category, submitters, @@ -127,6 +127,26 @@ export class MotionRepositoryService extends BaseRepository tags, parent ); + viewMotion.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Motions' : 'Motion'); + }; + viewMotion.getAgendaTitle = () => { + // if the identifier is set, the title will be 'Motion '. + if (viewMotion.identifier) { + return this.translate.instant('Motion') + ' ' + viewMotion.identifier; + } else { + return viewMotion.getTitle(); + } + }; + viewMotion.getAgendaTitleWithType = () => { + // Append the verbose name only, if not the special format 'Motion ' is used. + if (viewMotion.identifier) { + return this.translate.instant('Motion') + ' ' + viewMotion.identifier; + } else { + return viewMotion.getTitle() + ' (' + viewMotion.getVerboseName() + ')'; + } + }; + return viewMotion; } /** diff --git a/client/src/app/core/repositories/motions/statute-paragraph-repository.service.ts b/client/src/app/core/repositories/motions/statute-paragraph-repository.service.ts index 3fa433ed4..1c3297ad5 100644 --- a/client/src/app/core/repositories/motions/statute-paragraph-repository.service.ts +++ b/client/src/app/core/repositories/motions/statute-paragraph-repository.service.ts @@ -8,6 +8,7 @@ import { StatuteParagraph } from 'app/shared/models/motions/statute-paragraph'; import { Identifiable } from 'app/shared/models/base/identifiable'; import { CollectionStringMapperService } from '../../core-services/collectionStringMapper.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository Services for statute paragraphs @@ -33,13 +34,18 @@ export class StatuteParagraphRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Statute paragraphs' : 'Statute paragraph'); + }; + return viewStatuteParagraph; } public async create(statuteParagraph: StatuteParagraph): Promise { diff --git a/client/src/app/core/repositories/motions/workflow-repository.service.ts b/client/src/app/core/repositories/motions/workflow-repository.service.ts index 291c2b9aa..efdc01c4d 100644 --- a/client/src/app/core/repositories/motions/workflow-repository.service.ts +++ b/client/src/app/core/repositories/motions/workflow-repository.service.ts @@ -11,6 +11,7 @@ import { WorkflowState } from 'app/shared/models/motions/workflow-state'; import { ViewMotion } from 'app/site/motions/models/view-motion'; import { HttpService } from 'app/core/core-services/http.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository Services for Categories @@ -45,7 +46,8 @@ export class WorkflowRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Workflows' : 'Workflow'); + }; + return viewWorkflow; } /** diff --git a/client/src/app/core/repositories/projector/countdown-repository.service.ts b/client/src/app/core/repositories/projector/countdown-repository.service.ts index b74700884..b978f1518 100644 --- a/client/src/app/core/repositories/projector/countdown-repository.service.ts +++ b/client/src/app/core/repositories/projector/countdown-repository.service.ts @@ -7,6 +7,7 @@ import { CollectionStringMapperService } from '../../core-services/collectionStr import { ViewCountdown } from 'app/site/projector/models/view-countdown'; import { Countdown } from 'app/shared/models/core/countdown'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; @Injectable({ providedIn: 'root' @@ -16,13 +17,18 @@ export class CountdownRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Countdowns' : 'Countdown'); + }; + return viewCountdown; } public async create(countdown: Countdown): Promise { diff --git a/client/src/app/core/repositories/projector/projector-repository.service.ts b/client/src/app/core/repositories/projector/projector-repository.service.ts index d47b25000..bbff447e7 100644 --- a/client/src/app/core/repositories/projector/projector-repository.service.ts +++ b/client/src/app/core/repositories/projector/projector-repository.service.ts @@ -9,6 +9,7 @@ import { ViewProjector } from 'app/site/projector/models/view-projector'; import { Projector } from 'app/shared/models/core/projector'; import { HttpService } from 'app/core/core-services/http.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Directions for scale and scroll requests. @@ -39,11 +40,20 @@ export class ProjectorRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Projectors' : 'Projector'); + }; + return viewProjector; + } + /** * Creates a new projector. Adds the clock as default, stable element */ @@ -73,10 +83,6 @@ export class ProjectorRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Messages' : 'Message'); + }; + return viewProjectorMessage; } public async create(message: ProjectorMessage): Promise { diff --git a/client/src/app/core/repositories/tags/tag-repository.service.ts b/client/src/app/core/repositories/tags/tag-repository.service.ts index 1d2380d62..39129fb3b 100644 --- a/client/src/app/core/repositories/tags/tag-repository.service.ts +++ b/client/src/app/core/repositories/tags/tag-repository.service.ts @@ -8,6 +8,7 @@ import { BaseRepository } from '../base-repository'; import { Identifiable } from 'app/shared/models/base/identifiable'; import { CollectionStringMapperService } from '../../core-services/collectionStringMapper.service'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Repository Services for Tags @@ -36,13 +37,18 @@ export class TagRepositoryService extends BaseRepository { protected DS: DataStoreService, mapperService: CollectionStringMapperService, viewModelStoreService: ViewModelStoreService, - private dataSend: DataSendService + private dataSend: DataSendService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, Tag); } protected createViewModel(tag: Tag): ViewTag { - return new ViewTag(tag); + const viewTag = new ViewTag(tag); + viewTag.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Tags' : 'Tag'); + }; + return viewTag; } public async create(update: Tag): Promise { diff --git a/client/src/app/core/repositories/users/group-repository.service.ts b/client/src/app/core/repositories/users/group-repository.service.ts index 542787a1f..3eaf5a0eb 100644 --- a/client/src/app/core/repositories/users/group-repository.service.ts +++ b/client/src/app/core/repositories/users/group-repository.service.ts @@ -9,6 +9,7 @@ import { Group } from 'app/shared/models/users/group'; import { Identifiable } from 'app/shared/models/base/identifiable'; import { ViewGroup } from 'app/site/users/models/view-group'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** * Shape of a permission @@ -52,12 +53,21 @@ export class GroupRepositoryService extends BaseRepository { mapperService: CollectionStringMapperService, viewModelStoreService: ViewModelStoreService, private dataSend: DataSendService, - private constants: ConstantsService + private constants: ConstantsService, + private translate: TranslateService ) { super(DS, mapperService, viewModelStoreService, Group); this.sortPermsPerApp(); } + public createViewModel(group: Group): ViewGroup { + const viewGroup = new ViewGroup(group); + viewGroup.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Groups' : 'Group'); + }; + return viewGroup; + } + /** * Add an entry to appPermissions * @@ -180,8 +190,4 @@ export class GroupRepositoryService extends BaseRepository { public async delete(viewGroup: ViewGroup): Promise { await this.dataSend.deleteModel(viewGroup.group); } - - public createViewModel(group: Group): ViewGroup { - return new ViewGroup(group); - } } diff --git a/client/src/app/core/repositories/users/personal-note-repository.service.ts b/client/src/app/core/repositories/users/personal-note-repository.service.ts index 15726c1d8..960e46831 100644 --- a/client/src/app/core/repositories/users/personal-note-repository.service.ts +++ b/client/src/app/core/repositories/users/personal-note-repository.service.ts @@ -7,6 +7,7 @@ import { PersonalNote } from 'app/shared/models/users/personal-note'; import { Identifiable } from 'app/shared/models/base/identifiable'; import { ViewPersonalNote } from 'app/site/users/models/view-personal-note'; import { ViewModelStoreService } from 'app/core/core-services/view-model-store.service'; +import { TranslateService } from '@ngx-translate/core'; /** */ @@ -21,13 +22,18 @@ export class PersonalNoteRepositoryService extends BaseRepository { + return this.translate.instant(plural ? 'Personal notes' : 'Personal note'); + }; + return viewPersonalNote; } public async create(personalNote: PersonalNote): Promise { diff --git a/client/src/app/core/repositories/users/user-repository.service.ts b/client/src/app/core/repositories/users/user-repository.service.ts index f061848d7..a571c096d 100644 --- a/client/src/app/core/repositories/users/user-repository.service.ts +++ b/client/src/app/core/repositories/users/user-repository.service.ts @@ -49,6 +49,15 @@ export class UserRepositoryService extends BaseRepository { super(DS, mapperService, viewModelStoreService, User, [Group]); } + public createViewModel(user: User): ViewUser { + const groups = this.viewModelStoreService.getMany(ViewGroup, user.groups_id); + const viewUser = new ViewUser(user, groups); + viewUser.getVerboseName = (plural: boolean = false) => { + return this.translate.instant(plural ? 'Users' : 'User'); + }; + return viewUser; + } + /** * Updates a the selected user with the form values. * @@ -106,11 +115,6 @@ export class UserRepositoryService extends BaseRepository { return await this.dataSend.createModel(newUser); } - public createViewModel(user: User): ViewUser { - const groups = this.viewModelStoreService.getMany(ViewGroup, user.groups_id); - return new ViewUser(user, groups); - } - /** * Generates a random password * diff --git a/client/src/app/core/ui-services/search.service.ts b/client/src/app/core/ui-services/search.service.ts index 63b7e6cb8..1c766177c 100644 --- a/client/src/app/core/ui-services/search.service.ts +++ b/client/src/app/core/ui-services/search.service.ts @@ -82,11 +82,11 @@ export class SearchService { ctor: new (...args: any[]) => Searchable & BaseViewModel, displayOrder: number ): void { - const instance = new ctor(); + // const instance = new ctor(); this.searchModels.push({ collectionString: collectionString, - verboseNameSingular: instance.getVerboseName(), - verboseNamePlural: instance.getVerboseName(true), + verboseNameSingular: 'TODO', // instance.getVerboseName(), + verboseNamePlural: 'TODO', // instance.getVerboseName(true), displayOrder: displayOrder }); this.searchModels.sort((a, b) => a.displayOrder - b.displayOrder); diff --git a/client/src/app/shared/components/empty-selectable.ts b/client/src/app/shared/components/empty-selectable.ts index 44e316ae6..4bd8a6f63 100644 --- a/client/src/app/shared/components/empty-selectable.ts +++ b/client/src/app/shared/components/empty-selectable.ts @@ -1,6 +1,7 @@ -import { Selectable } from './selectable'; import { TranslateService } from '@ngx-translate/core'; +import { Selectable } from './selectable'; + /** * Class to display an "empty" Selectable */ @@ -19,20 +20,10 @@ export class EmptySelectable implements Selectable { /** * gets the title */ - public getTitle(): string { - if (this.translate) { - return this.translate.instant('None'); - } - return 'None'; - } + public getTitle = () => (this.translate ? this.translate.instant('None') : 'None'); /** * gets the list title */ - public getListTitle(): string { - if (this.translate) { - return this.translate.instant('None'); - } - return 'None'; - } + public getListTitle = () => this.getTitle(); } diff --git a/client/src/app/shared/components/sorting-tree/sorting-tree.component.spec.ts b/client/src/app/shared/components/sorting-tree/sorting-tree.component.spec.ts index 3a2b78135..2f9aff9d9 100644 --- a/client/src/app/shared/components/sorting-tree/sorting-tree.component.spec.ts +++ b/client/src/app/shared/components/sorting-tree/sorting-tree.component.spec.ts @@ -17,13 +17,9 @@ class TestModel implements Identifiable, Displayable { public parent_id: number | null ) {} - public getTitle(): string { - return this.name; - } + public getTitle = () => this.name; - public getListTitle(): string { - return this.getTitle(); - } + public getListTitle = () => this.getTitle(); } describe('SortingTreeComponent', () => { diff --git a/client/src/app/shared/models/agenda/item.ts b/client/src/app/shared/models/agenda/item.ts index ce9d18179..c5d501f9f 100644 --- a/client/src/app/shared/models/agenda/item.ts +++ b/client/src/app/shared/models/agenda/item.ts @@ -25,6 +25,8 @@ export const itemVisibilityChoices = [ * @ignore */ export class Item extends BaseModel { + public static COLLECTIONSTRING = 'agenda/item'; + public id: number; public item_number: string; public title: string; @@ -41,7 +43,7 @@ export class Item extends BaseModel { public parent_id: number; public constructor(input?: any) { - super('agenda/item', input); + super(Item.COLLECTIONSTRING, input); } public deserialize(input: any): void { diff --git a/client/src/app/shared/models/assignments/assignment.ts b/client/src/app/shared/models/assignments/assignment.ts index f0702a826..c5442d384 100644 --- a/client/src/app/shared/models/assignments/assignment.ts +++ b/client/src/app/shared/models/assignments/assignment.ts @@ -13,6 +13,7 @@ export const assignmentPhase = [ * @ignore */ export class Assignment extends BaseModel { + public static COLLECTIONSTRING = 'assignments/assignment'; public id: number; public title: string; public description: string; @@ -25,7 +26,7 @@ export class Assignment extends BaseModel { public tags_id: number[]; public constructor(input?: any) { - super('assignments/assignment', input); + super(Assignment.COLLECTIONSTRING, input); } public get candidateIds(): number[] { diff --git a/client/src/app/shared/models/mediafiles/mediafile.ts b/client/src/app/shared/models/mediafiles/mediafile.ts index 58570b746..58cf99046 100644 --- a/client/src/app/shared/models/mediafiles/mediafile.ts +++ b/client/src/app/shared/models/mediafiles/mediafile.ts @@ -6,6 +6,7 @@ import { BaseModel } from '../base/base-model'; * @ignore */ export class Mediafile extends BaseModel { + public static COLLECTIONSTRING = 'mediafiles/mediafile'; public id: number; public title: string; public mediafile: File; @@ -16,7 +17,7 @@ export class Mediafile extends BaseModel { public timestamp: string; public constructor(input?: any) { - super('mediafiles/mediafile', input); + super(Mediafile.COLLECTIONSTRING, input); } public deserialize(input: any): void { diff --git a/client/src/app/shared/models/users/group.ts b/client/src/app/shared/models/users/group.ts index 40b269de5..0390220fe 100644 --- a/client/src/app/shared/models/users/group.ts +++ b/client/src/app/shared/models/users/group.ts @@ -6,6 +6,7 @@ import { BaseModel } from '../base/base-model'; */ export class Group extends BaseModel { public static COLLECTIONSTRING = 'users/group'; + public id: number; public name: string; public permissions: string[]; @@ -17,8 +18,4 @@ export class Group extends BaseModel { this.permissions = []; } } - - public getTitle(): string { - return this.name; - } } diff --git a/client/src/app/shared/models/users/personal-note.ts b/client/src/app/shared/models/users/personal-note.ts index 538ebeb45..48610c7ea 100644 --- a/client/src/app/shared/models/users/personal-note.ts +++ b/client/src/app/shared/models/users/personal-note.ts @@ -58,8 +58,4 @@ export class PersonalNote extends BaseModel implements PersonalNot public constructor(input: any) { super(PersonalNote.COLLECTIONSTRING, input); } - - public getTitle(): string { - return 'Personal note'; - } } diff --git a/client/src/app/site/agenda/models/view-create-topic.ts b/client/src/app/site/agenda/models/view-create-topic.ts index 70766167e..4fc9382a2 100644 --- a/client/src/app/site/agenda/models/view-create-topic.ts +++ b/client/src/app/site/agenda/models/view-create-topic.ts @@ -107,4 +107,8 @@ export class ViewCreateTopic extends ViewTopic { public constructor(topic: CreateTopic) { super(topic); } + + public getVerboseName = () => { + throw new Error('This should not be used'); + }; } diff --git a/client/src/app/site/agenda/models/view-item.ts b/client/src/app/site/agenda/models/view-item.ts index 063b494bc..48da0747b 100644 --- a/client/src/app/site/agenda/models/view-item.ts +++ b/client/src/app/site/agenda/models/view-item.ts @@ -1,7 +1,7 @@ import { BaseViewModel } from '../../base/base-view-model'; import { Item } from 'app/shared/models/agenda/item'; import { Speaker } from 'app/shared/models/agenda/speaker'; -import { BaseAgendaViewModel } from 'app/site/base/base-agenda-view-model'; +import { BaseAgendaViewModel, isAgendaBaseModel } from 'app/site/base/base-agenda-view-model'; export class ViewItem extends BaseViewModel { private _item: Item; @@ -29,52 +29,46 @@ export class ViewItem extends BaseViewModel { } public get id(): number { - return this.item ? this.item.id : null; + return this.item.id; } public get itemNumber(): string { - return this.item ? this.item.item_number : null; + return this.item.item_number; } public get duration(): number { - return this.item ? this.item.duration : null; + return this.item.duration; } public get waitingSpeakerAmount(): number { - return this.item ? this.item.waitingSpeakerAmount : null; + return this.item.waitingSpeakerAmount; } public get type(): number { - return this.item ? this.item.type : null; + return this.item.type; } public get closed(): boolean { - return this.item ? this.item.closed : null; + return this.item.closed; } public get comment(): string { - if (this.item && this.item.comment) { - return this.item.comment; - } - return ''; + return this.item.comment; } public get verboseType(): string { - if (this.item && this.item.verboseType) { - return this.item.verboseType; - } - return ''; + return this.item.verboseType; } public get verboseCsvType(): string { - return this.item ? this.item.verboseCsvType : ''; + return this.item.verboseCsvType; } /** * TODO: make the repository set the ViewSpeakers here. */ public get speakers(): Speaker[] { - return this.item ? this.item.speakers : []; + return this.item.speakers; } /** @@ -82,29 +76,34 @@ export class ViewItem extends BaseViewModel { * it's own hierarchy level (items sharing a parent) */ public get weight(): number { - return this.item ? this.item.weight : null; + return this.item.weight; } /** * @returns the parent's id of that item (0 if no parent is set). */ public get parent_id(): number { - return this.item ? this.item.parent_id : null; + return this.item.parent_id; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(item: Item, contentObject: BaseAgendaViewModel) { - super('Item'); + super(Item.COLLECTIONSTRING); this._item = item; this._contentObject = contentObject; } - public getTitle(): string { + public getTitle = () => { if (this.contentObject) { return this.contentObject.getAgendaTitle(); } else { return this.item ? this.item.title : null; } - } + }; /** * Create the list view title. @@ -112,16 +111,27 @@ export class ViewItem extends BaseViewModel { * * @returns the agenda list title as string */ - public getListTitle(): string { - const contentObject: BaseAgendaViewModel = this.contentObject; + public getListTitle = () => { const numberPrefix = this.itemNumber ? `${this.itemNumber} ยท ` : ''; - if (contentObject) { - return numberPrefix + contentObject.getAgendaTitleWithType(); + if (this.contentObject) { + return numberPrefix + this.contentObject.getAgendaTitleWithType(); } else { - return this.item ? numberPrefix + this.item.title_with_type : null; + return numberPrefix + this.item.title_with_type; } - } + }; - public updateDependencies(update: BaseViewModel): void {} + public updateDependencies(update: BaseViewModel): boolean { + if ( + update.collectionString === this.item.content_object.collection && + update.id === this.item.content_object.id + ) { + if (!isAgendaBaseModel(update)) { + throw new Error('The item is not an BaseAgendaViewModel:' + update); + } + this._contentObject = update as BaseAgendaViewModel; + return true; + } + return false; + } } diff --git a/client/src/app/site/agenda/models/view-speaker.ts b/client/src/app/site/agenda/models/view-speaker.ts index 33e1d2802..4d998e495 100644 --- a/client/src/app/site/agenda/models/view-speaker.ts +++ b/client/src/app/site/agenda/models/view-speaker.ts @@ -55,15 +55,20 @@ export class ViewSpeaker extends BaseViewModel { return this.user ? this.user.gender : ''; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(speaker: Speaker, user?: ViewUser) { - super('Speaker'); + super('TODO'); this._speaker = speaker; this._user = user; } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; /** * Speaker is not a base model, diff --git a/client/src/app/site/agenda/models/view-topic.ts b/client/src/app/site/agenda/models/view-topic.ts index 9c715732d..c037da9b2 100644 --- a/client/src/app/site/agenda/models/view-topic.ts +++ b/client/src/app/site/agenda/models/view-topic.ts @@ -47,25 +47,30 @@ export class ViewTopic extends BaseAgendaViewModel { return this.topic.text; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(topic: Topic, attachments?: ViewMediafile[], item?: ViewItem) { - super('Topic'); + super(Topic.COLLECTIONSTRING); this._topic = topic; this._attachments = attachments; this._agendaItem = item; } - public getTitle(): string { + public getTitle = () => { return this.title; - } + }; public getAgendaItem(): ViewItem { return this.agendaItem; } - public getAgendaTitleWithType(): string { + public getAgendaTitleWithType = () => { // Do not append ' (Topic)' to the title. return this.getAgendaTitle(); - } + }; /** * Formats the category for search diff --git a/client/src/app/site/assignments/models/view-assignment.ts b/client/src/app/site/assignments/models/view-assignment.ts index 9b2a198c2..394e11ee0 100644 --- a/client/src/app/site/assignments/models/view-assignment.ts +++ b/client/src/app/site/assignments/models/view-assignment.ts @@ -44,8 +44,13 @@ export class ViewAssignment extends BaseAgendaViewModel { return this.candidates ? this.candidates.length : 0; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(assignment: Assignment, relatedUser?: ViewUser[], agendaItem?: ViewItem, tags?: ViewTag[]) { - super('Election'); + super(Assignment.COLLECTIONSTRING); this._assignment = assignment; this._relatedUser = relatedUser; this._agendaItem = agendaItem; @@ -60,9 +65,9 @@ export class ViewAssignment extends BaseAgendaViewModel { return this.agendaItem; } - public getTitle(): string { + public getTitle = () => { return this.assignment.title; - } + }; public formatForSearch(): SearchRepresentation { throw new Error('TODO'); diff --git a/client/src/app/site/base/agenda-information.ts b/client/src/app/site/base/agenda-information.ts index 2568f10fd..8eec50204 100644 --- a/client/src/app/site/base/agenda-information.ts +++ b/client/src/app/site/base/agenda-information.ts @@ -8,12 +8,12 @@ export interface AgendaInformation extends DetailNavigable { /** * Should return the title for the agenda list view. */ - getAgendaTitle(): string; + getAgendaTitle: () => string; /** * Should return the title for the list of speakers view. */ - getAgendaTitleWithType(): string; + getAgendaTitleWithType: () => string; /** * An (optional) descriptive text to be exported in the CSV. diff --git a/client/src/app/site/base/base-agenda-view-model.ts b/client/src/app/site/base/base-agenda-view-model.ts index f24e953b4..821680a53 100644 --- a/client/src/app/site/base/base-agenda-view-model.ts +++ b/client/src/app/site/base/base-agenda-view-model.ts @@ -3,26 +3,40 @@ import { BaseProjectableViewModel } from './base-projectable-view-model'; import { SearchRepresentation } from 'app/core/ui-services/search.service'; import { ViewItem } from '../agenda/models/view-item'; +export function isAgendaBaseModel(obj: object): obj is BaseAgendaViewModel { + const agendaViewModel = obj; + return ( + agendaViewModel.getAgendaTitle !== undefined && + agendaViewModel.getAgendaTitleWithType !== undefined && + agendaViewModel.getCSVExportText !== undefined && + agendaViewModel.getAgendaItem !== undefined && + agendaViewModel.getDetailStateURL !== undefined + ); +} + /** * Base view class for projectable models. */ export abstract class BaseAgendaViewModel extends BaseProjectableViewModel implements AgendaInformation { + /** + * @returns the contained agenda item + */ public abstract getAgendaItem(): ViewItem; /** * @returns the agenda title */ - public getAgendaTitle(): string { + public getAgendaTitle = () => { return this.getTitle(); - } + }; /** * @return the agenda title with the verbose name of the content object */ - public getAgendaTitleWithType(): string { + public getAgendaTitleWithType = () => { // Return the agenda title with the model's verbose name appended return this.getAgendaTitle() + ' (' + this.getVerboseName() + ')'; - } + }; /** * @returns the (optional) descriptive text to be exported in the CSV. diff --git a/client/src/app/site/base/base-projectable-view-model.ts b/client/src/app/site/base/base-projectable-view-model.ts index 9ff9f736b..3911fa849 100644 --- a/client/src/app/site/base/base-projectable-view-model.ts +++ b/client/src/app/site/base/base-projectable-view-model.ts @@ -5,9 +5,5 @@ import { BaseViewModel } from './base-view-model'; * Base view class for projectable models. */ export abstract class BaseProjectableViewModel extends BaseViewModel implements Projectable { - public constructor(verboseName: string) { - super(verboseName); - } - public abstract getSlide(): ProjectorElementBuildDeskriptor; } diff --git a/client/src/app/site/base/base-view-model.ts b/client/src/app/site/base/base-view-model.ts index a5b34e80a..b26661021 100644 --- a/client/src/app/site/base/base-view-model.ts +++ b/client/src/app/site/base/base-view-model.ts @@ -1,50 +1,60 @@ import { Displayable } from './displayable'; import { Identifiable } from '../../shared/models/base/identifiable'; +import { Collection } from 'app/shared/models/base/collection'; export type ViewModelConstructor = new (...args: any[]) => T; /** * Base class for view models. alls view models should have titles. */ -export abstract class BaseViewModel implements Displayable, Identifiable { +export abstract class BaseViewModel implements Displayable, Identifiable, Collection { /** * Force children to have an id. */ public abstract id: number; /** - * Children should also have a verbose name for generic display purposes + * force children of BaseModel to have a collectionString. + * + * Has a getter but no setter. */ - protected _verboseName: string; - - public constructor(verboseName: string) { - this._verboseName = verboseName; - } + protected _collectionString: string; /** - * Returns the verbose name. Makes it plural by adding a 's'. + * returns the collectionString. + * + * The server and the dataStore use it to identify the collection. + */ + public get collectionString(): string { + return this._collectionString; + } + + public abstract getTitle: () => string; + + /** + * Returns the verbose name. * * @param plural If the name should be plural * @returns the verbose name of the model */ - public getVerboseName(plural: boolean = false): string { - if (plural) { - return this._verboseName + 's'; // I love english. This works for all our models (participantS, electionS, - // topicS, motionS, (media)fileS, motion blockS, commentS, personal noteS, projectorS, messageS, countdownS, ...) - // Just categorIES need to overwrite this... - } else { - return this._verboseName; - } + public abstract getVerboseName: (plural?: boolean) => string; + + /** + * TODO: Remove verboseName, this must be overwritten by repos.. + * + * @param verboseName + * @param collectionString + */ + public constructor(collectionString: string) { + this._collectionString = collectionString; } + public getListTitle: () => string = () => { + return this.getTitle(); + }; + public abstract updateDependencies(update: BaseViewModel): void; - public abstract getTitle(): string; - - public getListTitle(): string { - return this.getTitle(); - } - public toString(): string { return this.getTitle(); } diff --git a/client/src/app/site/base/displayable.ts b/client/src/app/site/base/displayable.ts index 9be35f9f4..205476829 100644 --- a/client/src/app/site/base/displayable.ts +++ b/client/src/app/site/base/displayable.ts @@ -3,12 +3,12 @@ */ export interface Displayable { /** - * Should return the title. Alway used except for list view, the agenda and in the projector. + * Should return the title. Always used except for list view, the agenda and in the projector. */ - getTitle(): string; + getTitle: () => string; /** * Should return the title for the list view. */ - getListTitle(): string; + getListTitle: () => string; } diff --git a/client/src/app/site/common/models/view-chatmessage.ts b/client/src/app/site/common/models/view-chatmessage.ts index 88b5f0681..e4e1759ea 100644 --- a/client/src/app/site/common/models/view-chatmessage.ts +++ b/client/src/app/site/common/models/view-chatmessage.ts @@ -4,6 +4,11 @@ import { BaseViewModel } from 'app/site/base/base-view-model'; export class ViewChatMessage extends BaseViewModel { private _chatMessage: ChatMessage; + /** + * This is set by the repository + */ + public getVerboseName; + public get chatmessage(): ChatMessage { return this._chatMessage; } @@ -17,13 +22,13 @@ export class ViewChatMessage extends BaseViewModel { } public constructor(message?: ChatMessage) { - super('Chatmessage'); + super(ChatMessage.COLLECTIONSTRING); this._chatMessage = message; } - public getTitle(): string { + public getTitle = () => { return 'Chatmessage'; - } + }; public updateDependencies(message: BaseViewModel): void {} } diff --git a/client/src/app/site/config/models/view-config.ts b/client/src/app/site/config/models/view-config.ts index c6e653015..484b0ec5e 100644 --- a/client/src/app/site/config/models/view-config.ts +++ b/client/src/app/site/config/models/view-config.ts @@ -93,14 +93,19 @@ export class ViewConfig extends BaseViewModel { return this._defaultValue; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(config: Config) { - super('Config'); + super(Config.COLLECTIONSTRING); this._config = config; } - public getTitle(): string { + public getTitle = () => { return this.label; - } + }; public updateDependencies(update: BaseViewModel): void {} diff --git a/client/src/app/site/history/models/view-history.ts b/client/src/app/site/history/models/view-history.ts index 930b77c5d..4dbaf99e8 100644 --- a/client/src/app/site/history/models/view-history.ts +++ b/client/src/app/site/history/models/view-history.ts @@ -68,6 +68,11 @@ export class ViewHistory extends BaseViewModel { return this.history.now; } + /** + * This is set by the repository + */ + public getVerboseName; + /** * Construction of a ViewHistory * @@ -75,7 +80,7 @@ export class ViewHistory extends BaseViewModel { * @param user the real user BaseModel */ public constructor(history: History, user?: ViewUser) { - super('History'); + super(History.COLLECTIONSTRING); this._history = history; this._user = user; } @@ -112,9 +117,9 @@ export class ViewHistory extends BaseViewModel { * * @returns history.getTitle which returns the element_id */ - public getTitle(): string { + public getTitle = () => { return this.element_id; - } + }; /** * Updates the history object with new values diff --git a/client/src/app/site/mediafiles/models/view-mediafile.ts b/client/src/app/site/mediafiles/models/view-mediafile.ts index dc13f8dcc..804e76faf 100644 --- a/client/src/app/site/mediafiles/models/view-mediafile.ts +++ b/client/src/app/site/mediafiles/models/view-mediafile.ts @@ -61,15 +61,20 @@ export class ViewMediafile extends BaseViewModel implements Searchable { return this.mediafile.hidden; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(mediafile: Mediafile, uploader?: ViewUser) { - super('Mediafile'); + super(Mediafile.COLLECTIONSTRING); this._mediafile = mediafile; this._uploader = uploader; } - public getTitle(): string { + public getTitle = () => { return this.title; - } + }; public formatForSearch(): SearchRepresentation { return [this.title]; diff --git a/client/src/app/site/motions/models/view-category.ts b/client/src/app/site/motions/models/view-category.ts index 54aa382f7..cc40b76e5 100644 --- a/client/src/app/site/motions/models/view-category.ts +++ b/client/src/app/site/motions/models/view-category.ts @@ -41,29 +41,19 @@ export class ViewCategory extends BaseViewModel implements Searchable { return this.prefix ? this.prefix + ' - ' + this.name : this.name; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(category: Category) { - super('Category'); + super(Category.COLLECTIONSTRING); this._category = category; } - /** - * Returns the verbose name of this model. - * - * @override - * @param plural If the name should be plural - * @param The verbose name - */ - public getVerboseName(plural: boolean = false): string { - if (plural) { - return 'Categories'; - } else { - return this._verboseName; - } - } - - public getTitle(): string { + public getTitle = () => { return this.prefixedName; - } + }; public formatForSearch(): SearchRepresentation { return [this.name, this.prefix]; diff --git a/client/src/app/site/motions/models/view-change-recommendation.ts b/client/src/app/site/motions/models/view-change-recommendation.ts index 0fd02b74a..b4dc647d4 100644 --- a/client/src/app/site/motions/models/view-change-recommendation.ts +++ b/client/src/app/site/motions/models/view-change-recommendation.ts @@ -21,14 +21,19 @@ export class ViewMotionChangeRecommendation extends BaseViewModel implements Vie return this._changeRecommendation; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(changeReco: MotionChangeRecommendation) { - super('Change recommendation'); + super(MotionChangeRecommendation.COLLECTIONSTRING); this._changeRecommendation = changeReco; } - public getTitle(): string { + public getTitle = () => { return 'Changerecommendation'; - } + }; public updateDependencies(update: BaseViewModel): void {} diff --git a/client/src/app/site/motions/models/view-create-motion.ts b/client/src/app/site/motions/models/view-create-motion.ts index c31e8d356..293bb40dc 100644 --- a/client/src/app/site/motions/models/view-create-motion.ts +++ b/client/src/app/site/motions/models/view-create-motion.ts @@ -46,6 +46,10 @@ export class ViewCreateMotion extends ViewMotion { super(motion, category, submitters, supporters, workflow, state, item, block, null); } + public getVerboseName = () => { + throw new Error('This should not be used'); + }; + /** * Duplicate this motion into a copy of itself */ diff --git a/client/src/app/site/motions/models/view-motion-block.ts b/client/src/app/site/motions/models/view-motion-block.ts index 35e6b840a..de69aaf7a 100644 --- a/client/src/app/site/motions/models/view-motion-block.ts +++ b/client/src/app/site/motions/models/view-motion-block.ts @@ -34,8 +34,13 @@ export class ViewMotionBlock extends BaseAgendaViewModel implements Searchable { return this.motionBlock.agenda_item_id; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(motionBlock: MotionBlock, agendaItem?: ViewItem) { - super('Motion block'); + super(MotionBlock.COLLECTIONSTRING); this._motionBlock = motionBlock; this._agendaItem = agendaItem; } @@ -68,9 +73,9 @@ export class ViewMotionBlock extends BaseAgendaViewModel implements Searchable { } } - public getTitle(): string { + public getTitle = () => { return this.title; - } + }; public getSlide(): ProjectorElementBuildDeskriptor { throw new Error('todo'); diff --git a/client/src/app/site/motions/models/view-motion-comment-section.ts b/client/src/app/site/motions/models/view-motion-comment-section.ts index 9820651a7..9baf6015c 100644 --- a/client/src/app/site/motions/models/view-motion-comment-section.ts +++ b/client/src/app/site/motions/models/view-motion-comment-section.ts @@ -47,16 +47,21 @@ export class ViewMotionCommentSection extends BaseViewModel { this._section.name = name; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(section: MotionCommentSection, readGroups: ViewGroup[], writeGroups: ViewGroup[]) { - super('Comment section'); + super(MotionCommentSection.COLLECTIONSTRING); this._section = section; this._readGroups = readGroups; this._writeGroups = writeGroups; } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; /** * Updates the local objects if required diff --git a/client/src/app/site/motions/models/view-motion.ts b/client/src/app/site/motions/models/view-motion.ts index e47febd00..d78bc6f97 100644 --- a/client/src/app/site/motions/models/view-motion.ts +++ b/client/src/app/site/motions/models/view-motion.ts @@ -318,6 +318,21 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { return this.personalNote && this.personalNote.note ? true : false; } + /** + * This is set by the repository + */ + public getAgendaTitle; + + /** + * This is set by the repository + */ + public getAgendaTitleWithType; + + /** + * This is set by the repository + */ + public getVerboseName; + public constructor( motion: Motion, category?: ViewCategory, @@ -331,7 +346,7 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { tags?: ViewTag[], parent?: ViewMotion ) { - super('Motion'); + super(Motion.COLLECTIONSTRING); this._motion = motion; this._category = category; this._submitters = submitters; @@ -345,36 +360,18 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { this._parent = parent; } - public getTitle(): string { + public getTitle = () => { if (this.identifier) { return this.identifier + ': ' + this.title; } else { return this.title; } - } + }; public getAgendaItem(): ViewItem { return this.item; } - public getAgendaTitle(): string { - // if the identifier is set, the title will be 'Motion '. - if (this.identifier) { - return 'Motion ' + this.identifier; - } else { - return this.getTitle(); - } - } - - public getAgendaTitleWithType(): string { - // Append the verbose name only, if not the special format 'Motion ' is used. - if (this.identifier) { - return 'Motion ' + this.identifier; - } else { - return this.getTitle() + ' (' + this.getVerboseName() + ')'; - } - } - /** * Formats the category for search * diff --git a/client/src/app/site/motions/models/view-statute-paragraph.ts b/client/src/app/site/motions/models/view-statute-paragraph.ts index fd21b4fc0..2e5240d58 100644 --- a/client/src/app/site/motions/models/view-statute-paragraph.ts +++ b/client/src/app/site/motions/models/view-statute-paragraph.ts @@ -33,14 +33,19 @@ export class ViewStatuteParagraph extends BaseViewModel implements Searchable { return this.statuteParagraph.weight; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(paragraph: StatuteParagraph) { - super('Statute paragraph'); + super(StatuteParagraph.COLLECTIONSTRING); this._paragraph = paragraph; } - public getTitle(): string { + public getTitle = () => { return this.title; - } + }; public formatForSearch(): SearchRepresentation { throw new Error('TODO'); diff --git a/client/src/app/site/motions/models/view-workflow.ts b/client/src/app/site/motions/models/view-workflow.ts index 1990353a8..027bee33c 100644 --- a/client/src/app/site/motions/models/view-workflow.ts +++ b/client/src/app/site/motions/models/view-workflow.ts @@ -33,14 +33,19 @@ export class ViewWorkflow extends BaseViewModel { return this.getStateById(this.first_state_id); } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(workflow: Workflow) { - super('Workflow'); + super(Workflow.COLLECTIONSTRING); this._workflow = workflow; } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; /** * Duplicate this motion into a copy of itself diff --git a/client/src/app/site/projector/models/view-countdown.ts b/client/src/app/site/projector/models/view-countdown.ts index b2ba96df1..a06bcb542 100644 --- a/client/src/app/site/projector/models/view-countdown.ts +++ b/client/src/app/site/projector/models/view-countdown.ts @@ -18,14 +18,19 @@ export class ViewCountdown extends BaseProjectableViewModel { return this.countdown.description; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(countdown: Countdown) { - super('Countdown'); + super(Countdown.COLLECTIONSTRING); this._countdown = countdown; } - public getTitle(): string { + public getTitle = () => { return this.description; - } + }; public updateDependencies(update: BaseViewModel): void {} diff --git a/client/src/app/site/projector/models/view-projector.ts b/client/src/app/site/projector/models/view-projector.ts index 8fefab0df..8009ebf59 100644 --- a/client/src/app/site/projector/models/view-projector.ts +++ b/client/src/app/site/projector/models/view-projector.ts @@ -52,14 +52,19 @@ export class ViewProjector extends BaseViewModel { return this.projector.reference_projector_id; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(projector?: Projector) { - super('Projector'); + super(Projector.COLLECTIONSTRING); this._projector = projector; } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; public updateDependencies(update: BaseViewModel): void {} } diff --git a/client/src/app/site/projector/models/view-projectormessage.ts b/client/src/app/site/projector/models/view-projectormessage.ts index e682a6266..092677f9c 100644 --- a/client/src/app/site/projector/models/view-projectormessage.ts +++ b/client/src/app/site/projector/models/view-projectormessage.ts @@ -18,14 +18,19 @@ export class ViewProjectorMessage extends BaseProjectableViewModel { return this.projctormessage.message; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(message: ProjectorMessage) { - super('Message'); + super(ProjectorMessage.COLLECTIONSTRING); this._message = message; } - public getTitle(): string { + public getTitle = () => { return 'Message'; - } + }; public updateDependencies(update: BaseViewModel): void {} diff --git a/client/src/app/site/tags/models/view-tag.ts b/client/src/app/site/tags/models/view-tag.ts index a1779f1a6..fb5b07e4c 100644 --- a/client/src/app/site/tags/models/view-tag.ts +++ b/client/src/app/site/tags/models/view-tag.ts @@ -25,14 +25,19 @@ export class ViewTag extends BaseViewModel implements Searchable { return this.tag.name; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(tag: Tag) { - super('Tag'); + super(Tag.COLLECTIONSTRING); this._tag = tag; } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; public formatForSearch(): SearchRepresentation { return [this.name]; diff --git a/client/src/app/site/users/models/view-group.ts b/client/src/app/site/users/models/view-group.ts index 89b33fbaa..f972b6dcb 100644 --- a/client/src/app/site/users/models/view-group.ts +++ b/client/src/app/site/users/models/view-group.ts @@ -29,8 +29,13 @@ export class ViewGroup extends BaseViewModel { return this.group.permissions; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(group?: Group) { - super('Group'); + super(Group.COLLECTIONSTRING); this._group = group; } @@ -65,9 +70,9 @@ export class ViewGroup extends BaseViewModel { return this.permissions.includes(perm); } - public getTitle(): string { + public getTitle = () => { return this.name; - } + }; public updateDependencies(update: BaseViewModel): void { console.log('ViewGroups wants to update Values with : ', update); diff --git a/client/src/app/site/users/models/view-personal-note.ts b/client/src/app/site/users/models/view-personal-note.ts index 0edc632b2..c35b4a6e3 100644 --- a/client/src/app/site/users/models/view-personal-note.ts +++ b/client/src/app/site/users/models/view-personal-note.ts @@ -12,14 +12,19 @@ export class ViewPersonalNote extends BaseViewModel { return this.personalNote ? this.personalNote.id : null; } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(personalNote?: PersonalNote) { - super('Personal note'); + super(PersonalNote.COLLECTIONSTRING); this._personalNote = personalNote; } - public getTitle(): string { + public getTitle = () => { return this.personalNote ? this.personalNote.toString() : null; - } + }; public updateDependencies(update: BaseViewModel): void { throw new Error('Todo'); diff --git a/client/src/app/site/users/models/view-user.ts b/client/src/app/site/users/models/view-user.ts index 3ce83d2df..bddeac5ec 100644 --- a/client/src/app/site/users/models/view-user.ts +++ b/client/src/app/site/users/models/view-user.ts @@ -160,8 +160,13 @@ export class ViewUser extends BaseProjectableViewModel implements Searchable { return name.trim(); } + /** + * This is set by the repository + */ + public getVerboseName; + public constructor(user: User, groups?: ViewGroup[]) { - super('Participant'); + super(User.COLLECTIONSTRING); this._user = user; this._groups = groups; } @@ -195,9 +200,9 @@ export class ViewUser extends BaseProjectableViewModel implements Searchable { /** * required by BaseViewModel. Don't confuse with the users title. */ - public getTitle(): string { + public getTitle = () => { return this.full_name; - } + }; /** * TODO: Implement