Merge pull request #4126 from MaximilianKrambach/follow_motionblock

simplify followRecommendation for motionBlock
This commit is contained in:
Sean 2019-01-18 20:39:42 +01:00 committed by GitHub
commit f7bc087c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View File

@ -8,7 +8,6 @@ import { TranslateService } from '@ngx-translate/core';
import { ListViewBaseComponent } from 'app/site/base/list-view-base';
import { MotionBlockRepositoryService } from '../../services/motion-block-repository.service';
import { MotionRepositoryService } from '../../services/motion-repository.service';
import { MotionBlock } from 'app/shared/models/motions/motion-block';
import { ViewMotionBlock } from '../../models/view-motion-block';
import { ViewMotion } from '../../models/view-motion';
@ -53,7 +52,6 @@ export class MotionBlockDetailComponent extends ListViewBaseComponent<ViewMotion
* @param router navigating
* @param route determine the blocks ID by the route
* @param repo the motion blocks repository
* @param motionRepo the motion repository
* @param promptService the displaying prompts before deleting
*/
public constructor(
@ -63,7 +61,6 @@ export class MotionBlockDetailComponent extends ListViewBaseComponent<ViewMotion
private router: Router,
private route: ActivatedRoute,
private repo: MotionBlockRepositoryService,
private motionRepo: MotionRepositoryService,
private promptService: PromptService
) {
super(titleService, translate, matSnackBar);
@ -128,11 +125,7 @@ export class MotionBlockDetailComponent extends ListViewBaseComponent<ViewMotion
`Are you sure you want to override the state of all motions of this motion block?`
);
if (await this.promptService.open(this.block.title, content)) {
for (const motion of this.motions) {
if (!motion.isInFinalState()) {
this.motionRepo.setState(motion, motion.recommendation_id);
}
}
this.repo.followRecommendation(this.block);
}
}

View File

@ -2,16 +2,17 @@ import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { MotionBlock } from 'app/shared/models/motions/motion-block';
import { ViewMotionBlock } from '../models/view-motion-block';
import { BaseRepository } from 'app/site/base/base-repository';
import { DataStoreService } from 'app/core/services/data-store.service';
import { CollectionStringModelMapperService } from 'app/core/services/collectionStringModelMapper.service';
import { DataSendService } from 'app/core/services/data-send.service';
import { DataStoreService } from 'app/core/services/data-store.service';
import { HttpService } from 'app/core/services/http.service';
import { Identifiable } from 'app/shared/models/base/identifiable';
import { Motion } from 'app/shared/models/motions/motion';
import { ViewMotion } from '../models/view-motion';
import { MotionBlock } from 'app/shared/models/motions/motion-block';
import { MotionRepositoryService } from './motion-repository.service';
import { ViewMotion } from '../models/view-motion';
import { ViewMotionBlock } from '../models/view-motion-block';
/**
* Repository service for motion blocks
@ -27,12 +28,14 @@ export class MotionBlockRepositoryService extends BaseRepository<ViewMotionBlock
* @param mapperService Mapping collection strings to classes
* @param dataSend Send models to the server
* @param motionRepo Accessing the motion repository
* @param httpService Sending a request directly
*/
public constructor(
DS: DataStoreService,
mapperService: CollectionStringModelMapperService,
private dataSend: DataSendService,
private motionRepo: MotionRepositoryService
private motionRepo: MotionRepositoryService,
private httpService: HttpService
) {
super(DS, mapperService, MotionBlock);
}
@ -121,4 +124,14 @@ export class MotionBlockRepositoryService extends BaseRepository<ViewMotionBlock
public getMotionBlockByTitle(title: string): MotionBlock {
return this.DS.find(MotionBlock, block => block.title === title);
}
/**
* Signals the acceptance of the current recommendation of this motionBlock
*
* @param motionBlock
*/
public async followRecommendation(motionBlock: ViewMotionBlock): Promise<void> {
const restPath = `/rest/motions/motion-block/${motionBlock.id}/follow_recommendations/`;
await this.httpService.post(restPath);
}
}