From 17ce91f309bac4887cb9b16c8e33035f3db86955 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 12 Feb 2019 10:39:03 +0100 Subject: [PATCH] Fixed calllist by removing the attached data from the tree (fixes #4296) --- .../agenda/item-repository.service.ts | 4 +-- .../motions/motion-repository.service.ts | 2 +- .../src/app/core/ui-services/tree.service.ts | 30 +++++++++++++++++-- .../sorting-tree/sorting-tree.component.ts | 11 +++---- .../agenda-sort/agenda-sort.component.ts | 2 +- .../call-list/call-list.component.ts | 3 +- 6 files changed, 39 insertions(+), 13 deletions(-) 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 8543336bd..7d7f5ef20 100644 --- a/client/src/app/core/repositories/agenda/item-repository.service.ts +++ b/client/src/app/core/repositories/agenda/item-repository.service.ts @@ -234,7 +234,7 @@ export class ItemRepositoryService extends BaseRepository { */ public async delete(item: ViewItem): Promise { const restUrl = `/rest/${item.contentObject.collectionString}/${item.contentObject.id}/`; - return await this.httpService.delete(restUrl); + await this.httpService.delete(restUrl); } /** @@ -260,7 +260,7 @@ export class ItemRepositoryService extends BaseRepository { * * @param data The reordered data from the sorting */ - public async sortItems(data: OSTreeSortEvent): Promise { + public async sortItems(data: OSTreeSortEvent): Promise { const url = '/rest/agenda/item/sort/'; await this.httpService.post(url, data); } 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 15b52bd23..53dac078a 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -314,7 +314,7 @@ export class MotionRepositoryService extends BaseRepository * * @param data The reordered data from the sorting */ - public async sortMotions(data: OSTreeSortEvent): Promise { + public async sortMotions(data: OSTreeSortEvent): Promise { const url = '/rest/motions/motion/sort/'; await this.httpService.post(url, data); } diff --git a/client/src/app/core/ui-services/tree.service.ts b/client/src/app/core/ui-services/tree.service.ts index 9e1b98465..a554c2642 100644 --- a/client/src/app/core/ui-services/tree.service.ts +++ b/client/src/app/core/ui-services/tree.service.ts @@ -4,11 +4,18 @@ import { Displayable } from 'app/site/base/displayable'; import { Identifiable } from 'app/shared/models/base/identifiable'; /** - * A representation of nodes in our tree. Saves the displayed name, the id, the element and children to build a full tree. + * A basic representation of a tree node. This node does not stores any data. */ -export interface OSTreeNode { +export interface OSTreeNodeWithoutItem { name: string; id: number; + children?: OSTreeNodeWithoutItem[]; +} + +/** + * A representation of nodes with the item atached. + */ +export interface OSTreeNode extends OSTreeNodeWithoutItem { item: T; children?: OSTreeNode[]; } @@ -113,6 +120,25 @@ export class TreeService { } } + /** + * Removes `item` from the tree. + * + * @param tree The tree with items + * @returns The tree without items + */ + public stripTree(tree: OSTreeNode[]): OSTreeNodeWithoutItem[] { + return tree.map(node => { + const nodeWithoutItem: OSTreeNodeWithoutItem = { + name: node.name, + id: node.id + }; + if (node.children) { + nodeWithoutItem.children = this.stripTree(node.children); + } + return nodeWithoutItem; + }); + } + /** * Traverses items in pre-order givem (implicit) by the weight and parentId. * diff --git a/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts b/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts index 24814f657..0e6368815 100644 --- a/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts +++ b/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts @@ -7,16 +7,16 @@ import { Subscription, Observable } from 'rxjs'; import { Identifiable } from 'app/shared/models/base/identifiable'; import { Displayable } from 'app/site/base/displayable'; -import { OSTreeNode, TreeService } from 'app/core/ui-services/tree.service'; +import { OSTreeNode, TreeService, OSTreeNodeWithoutItem } from 'app/core/ui-services/tree.service'; /** * The data representation for the sort event. */ -export interface OSTreeSortEvent { +export interface OSTreeSortEvent { /** * Gives all nodes to be inserted below the parent_id. */ - nodes: OSTreeNode[]; + nodes: OSTreeNodeWithoutItem[]; /** * Provides the parent id for the nodes array. Do not provide it, if it's the @@ -85,7 +85,7 @@ export class SortingTreeComponent implemen * sorted part of the tree. */ @Output() - public readonly sort = new EventEmitter>(); + public readonly sort = new EventEmitter(); /** * Options for the tree. As a default drag and drop is allowed. @@ -159,6 +159,7 @@ export class SortingTreeComponent implemen to.parent.data.children = []; } transferArrayItem(fromArray, to.parent.data.children, from.index, to.index); - this.sort.emit({ nodes: to.parent.data.children, parent_id: parentId }); + const strippedNodes = this.treeService.stripTree(to.parent.data.children); + this.sort.emit({ nodes: strippedNodes, parent_id: parentId }); } } diff --git a/client/src/app/site/agenda/components/agenda-sort/agenda-sort.component.ts b/client/src/app/site/agenda/components/agenda-sort/agenda-sort.component.ts index d96bfb8b6..2545b1bf1 100644 --- a/client/src/app/site/agenda/components/agenda-sort/agenda-sort.component.ts +++ b/client/src/app/site/agenda/components/agenda-sort/agenda-sort.component.ts @@ -51,7 +51,7 @@ export class AgendaSortComponent extends BaseViewComponent { * @param data The event data. The representation fits the servers requirements, so it can directly * be send to the server via the repository. */ - public sort(data: OSTreeSortEvent): void { + public sort(data: OSTreeSortEvent): void { this.agendaRepo.sortItems(data).then(null, this.raiseError); } diff --git a/client/src/app/site/motions/components/call-list/call-list.component.ts b/client/src/app/site/motions/components/call-list/call-list.component.ts index f003e6201..2e5feaa55 100644 --- a/client/src/app/site/motions/components/call-list/call-list.component.ts +++ b/client/src/app/site/motions/components/call-list/call-list.component.ts @@ -9,7 +9,6 @@ import { BaseViewComponent } from '../../../base/base-view'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; import { MotionCsvExportService } from '../../services/motion-csv-export.service'; import { MotionPdfExportService } from '../../services/motion-pdf-export.service'; - import { ViewMotion } from '../../models/view-motion'; import { OSTreeSortEvent } from 'app/shared/components/sorting-tree/sorting-tree.component'; @@ -67,7 +66,7 @@ export class CallListComponent extends BaseViewComponent { * @param data The event data. The representation fits the servers requirements, so it can directly * be send to the server via the repository. */ - public sort(data: OSTreeSortEvent): void { + public sort(data: OSTreeSortEvent): void { this.motionRepo.sortMotions(data).then(null, this.raiseError); }