From 9198058bd7d551e342d7c048dea8040d1486c09c Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 4 Mar 2019 13:14:09 +0100 Subject: [PATCH] Search in related objects --- .../shared/models/motions/motion-comment.ts | 15 --------------- .../src/app/shared/models/motions/motion.ts | 19 +++++++------------ .../components/search/search.component.ts | 2 +- .../src/app/site/config/models/view-config.ts | 4 ---- .../site/mediafiles/models/view-mediafile.ts | 6 +++++- .../motion-comments.component.ts | 2 +- .../app/site/motions/models/view-category.ts | 7 ------- .../models/view-motion-comment-section.ts | 7 ------- .../app/site/motions/models/view-motion.ts | 18 ++++++++++++++---- .../motions/models/view-statute-paragraph.ts | 11 ++--------- .../app/site/motions/models/view-workflow.ts | 7 ------- 11 files changed, 30 insertions(+), 68 deletions(-) delete mode 100644 client/src/app/shared/models/motions/motion-comment.ts diff --git a/client/src/app/shared/models/motions/motion-comment.ts b/client/src/app/shared/models/motions/motion-comment.ts deleted file mode 100644 index 69c1379ee..000000000 --- a/client/src/app/shared/models/motions/motion-comment.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Deserializer } from '../base/deserializer'; - -/** - * Representation of a Motion Comment. - */ -export class MotionComment extends Deserializer { - public id: number; - public comment: string; - public section_id: number; - public read_groups_id: number[]; - - public constructor(input?: any) { - super(input); - } -} diff --git a/client/src/app/shared/models/motions/motion.ts b/client/src/app/shared/models/motions/motion.ts index 9ea666dfb..8bbeb0950 100644 --- a/client/src/app/shared/models/motions/motion.ts +++ b/client/src/app/shared/models/motions/motion.ts @@ -1,8 +1,14 @@ import { MotionSubmitter } from './motion-submitter'; -import { MotionComment } from './motion-comment'; import { MotionPoll } from './motion-poll'; import { BaseModel } from '../base/base-model'; +export interface MotionComment { + id: number; + comment: string; + section_id: number; + read_groups_id: number[]; +} + /** * Representation of Motion. * @@ -57,15 +63,4 @@ export class Motion extends BaseModel { }) .map((submitter: MotionSubmitter) => submitter.user_id); } - - public deserialize(input: any): void { - Object.assign(this, input); - - this.comments = []; - if (input.comments instanceof Array) { - input.comments.forEach(commentData => { - this.comments.push(new MotionComment(commentData)); - }); - } - } } diff --git a/client/src/app/site/common/components/search/search.component.ts b/client/src/app/site/common/components/search/search.component.ts index c6639c3f6..e55eb7926 100644 --- a/client/src/app/site/common/components/search/search.component.ts +++ b/client/src/app/site/common/components/search/search.component.ts @@ -80,7 +80,7 @@ export class SearchComponent extends BaseViewComponent implements OnInit { this.registeredModels = this.searchService.getRegisteredModels().map(rm => ({ ...rm, enabled: true })); - this.DS.changedOrDeletedObservable.pipe(auditTime(1)).subscribe(() => this.search()); + this.DS.changedOrDeletedObservable.pipe(auditTime(100)).subscribe(() => this.search()); this.quickSearchSubject.pipe(debounceTime(250)).subscribe(query => this.search(query)); } diff --git a/client/src/app/site/config/models/view-config.ts b/client/src/app/site/config/models/view-config.ts index 793a2bfb5..d7bfe6ce9 100644 --- a/client/src/app/site/config/models/view-config.ts +++ b/client/src/app/site/config/models/view-config.ts @@ -140,8 +140,4 @@ export class ViewConfig extends BaseViewModel { } this._hasConstantsInfo = true; } - - public copy(): ViewConfig { - return new ViewConfig(this._config); - } } diff --git a/client/src/app/site/mediafiles/models/view-mediafile.ts b/client/src/app/site/mediafiles/models/view-mediafile.ts index 5a17ca0eb..935910d26 100644 --- a/client/src/app/site/mediafiles/models/view-mediafile.ts +++ b/client/src/app/site/mediafiles/models/view-mediafile.ts @@ -81,7 +81,11 @@ export class ViewMediafile extends BaseProjectableViewModel implements Searchabl }; public formatForSearch(): SearchRepresentation { - return [this.title]; + const searchValues = [this.title]; + if (this.uploader) { + searchValues.push(this.uploader.full_name); + } + return searchValues; } public getDetailStateURL(): string { diff --git a/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts b/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts index 893e13bf9..14b821d25 100644 --- a/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts +++ b/client/src/app/site/motions/components/motion-comments/motion-comments.component.ts @@ -8,10 +8,10 @@ import { TranslateService } from '@ngx-translate/core'; import { MotionCommentSectionRepositoryService } from 'app/core/repositories/motions/motion-comment-section-repository.service'; import { ViewMotionCommentSection } from '../../models/view-motion-comment-section'; import { OperatorService } from 'app/core/core-services/operator.service'; -import { MotionComment } from 'app/shared/models/motions/motion-comment'; import { ViewMotion } from '../../models/view-motion'; import { BaseViewComponent } from 'app/site/base/base-view'; import { MotionPdfExportService } from '../../services/motion-pdf-export.service'; +import { MotionComment } from 'app/shared/models/motions/motion'; /** * Component for the motion comments view diff --git a/client/src/app/site/motions/models/view-category.ts b/client/src/app/site/motions/models/view-category.ts index 9caa0ceee..2daaf88ea 100644 --- a/client/src/app/site/motions/models/view-category.ts +++ b/client/src/app/site/motions/models/view-category.ts @@ -70,11 +70,4 @@ export class ViewCategory extends BaseViewModel implements Searchable { * @param update */ public updateDependencies(update: BaseViewModel): void {} - - /** - * Duplicate this motion into a copy of itself - */ - public copy(): ViewCategory { - return new ViewCategory(this._category); - } } 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 183ea9453..ef8c0cc29 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 @@ -79,11 +79,4 @@ export class ViewMotionCommentSection extends BaseViewModel { public updateGroup(group: ViewGroup): void { console.log('implement update group of motion comment section'); } - - /** - * Duplicate this motion into a copy of itself - */ - public copy(): ViewMotionCommentSection { - return new ViewMotionCommentSection(this._section, this._readGroups, this._writeGroups); - } } diff --git a/client/src/app/site/motions/models/view-motion.ts b/client/src/app/site/motions/models/view-motion.ts index 8c1059815..2730d9483 100644 --- a/client/src/app/site/motions/models/view-motion.ts +++ b/client/src/app/site/motions/models/view-motion.ts @@ -1,5 +1,4 @@ -import { MotionComment } from 'app/shared/models/motions/motion-comment'; -import { Motion } from 'app/shared/models/motions/motion'; +import { Motion, MotionComment } from 'app/shared/models/motions/motion'; import { PersonalNoteContent } from 'app/shared/models/users/personal-note'; import { ViewMotionCommentSection } from './view-motion-comment-section'; import { WorkflowState } from 'app/shared/models/motions/workflow-state'; @@ -397,8 +396,6 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { /** * Formats the category for search * - * TODO!!!! - * * @override */ public formatForSearch(): SearchRepresentation { @@ -406,6 +403,19 @@ export class ViewMotion extends BaseAgendaViewModel implements Searchable { if (this.amendment_paragraphs) { searchValues = searchValues.concat(this.amendment_paragraphs.filter(x => !!x)); } + searchValues = searchValues.concat(this.submitters.map(user => user.full_name)); + searchValues = searchValues.concat(this.supporters.map(user => user.full_name)); + searchValues = searchValues.concat(this.tags.map(tag => tag.getTitle())); + searchValues = searchValues.concat(this.motion.comments.map(comment => comment.comment)); + if (this.motion_block) { + searchValues.push(this.motion_block.getTitle()); + } + if (this.category) { + searchValues.push(this.category.getTitle()); + } + if (this.state) { + searchValues.push(this.state.name); + } return searchValues; } 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 f841be61d..915af954b 100644 --- a/client/src/app/site/motions/models/view-statute-paragraph.ts +++ b/client/src/app/site/motions/models/view-statute-paragraph.ts @@ -50,11 +50,11 @@ export class ViewStatuteParagraph extends BaseViewModel implements Searchable { }; public formatForSearch(): SearchRepresentation { - throw new Error('TODO'); + return [this.title]; } public getDetailStateURL(): string { - throw new Error('TODO'); + return '/motions/statute-paragraphs'; } /** @@ -62,11 +62,4 @@ export class ViewStatuteParagraph extends BaseViewModel implements Searchable { * @param section */ public updateDependencies(update: BaseViewModel): void {} - - /** - * Duplicate this motion into a copy of itself - */ - public copy(): ViewStatuteParagraph { - return new ViewStatuteParagraph(this._paragraph); - } } diff --git a/client/src/app/site/motions/models/view-workflow.ts b/client/src/app/site/motions/models/view-workflow.ts index 1149c81a9..583959fcf 100644 --- a/client/src/app/site/motions/models/view-workflow.ts +++ b/client/src/app/site/motions/models/view-workflow.ts @@ -57,13 +57,6 @@ export class ViewWorkflow extends BaseViewModel { return this.name; }; - /** - * Duplicate this motion into a copy of itself - */ - public copy(): ViewWorkflow { - return new ViewWorkflow(this._workflow); - } - /** * Updates the local objects if required *