From 69b6aec288aa5e7955a1927d97b4ccd1e237acc2 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Wed, 24 Apr 2019 13:36:17 +0200 Subject: [PATCH] Implements a dialog to edit meta information of one motion --- .../motion-list/motion-list.component.html | 80 +++++++++++---- .../motion-list/motion-list.component.ts | 97 ++++++++++++++++++- .../user-list/user-list.component.html | 5 +- .../styles/global-components-style.scss | 4 + 4 files changed, 160 insertions(+), 26 deletions(-) diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html index 547b08620..fb3bf1348 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.html @@ -103,22 +103,24 @@ State - -
-
- device_hub - {{ motion.category }} -
-
- widgets - {{ motion.motion_block.title }} -
-
- local_offer - - {{ tag.getTitle() }} - - + +
+
+
+ device_hub + {{ motion.category }} +
+
+ widgets + {{ motion.motion_block.title }} +
+
+ local_offer + + {{ tag.getTitle() }} + + +
@@ -245,7 +247,7 @@ Set status
+ + + +

+ {{ 'Edit details for' | translate }} {{ infoDialog.title }} +

+
+ + + + - + + {{ category.getTitle() | translate }} + + + + + + + - + + {{ block.getTitle() | translate }} + + + + + + + + {{ tag.getTitle() | translate }} + + + +
+ +
+ + +
+
diff --git a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts index eaa63f597..495600d90 100644 --- a/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts +++ b/client/src/app/site/motions/modules/motion-list/components/motion-list/motion-list.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { MatSnackBar, MatDialog } from '@angular/material'; @@ -31,6 +31,32 @@ import { MotionXlsxExportService } from 'app/site/motions/services/motion-xlsx-e import { LocalPermissionsService } from 'app/site/motions/services/local-permissions.service'; import { StorageService } from 'app/core/core-services/storage.service'; +/** + * Interface to describe possible values and changes for + * meta information dialog. + */ +interface InfoDialog { + /** + * The title of the motion + */ + title: string; + + /** + * The motion block id + */ + motionBlock: number; + + /** + * The category id + */ + category: number; + + /** + * The motions tag ids + */ + tags: number[]; +} + /** * Component that displays all the motions in a Table using DataSource. */ @@ -40,6 +66,17 @@ import { StorageService } from 'app/core/core-services/storage.service'; styleUrls: ['./motion-list.component.scss'] }) export class MotionListComponent extends ListViewBaseComponent implements OnInit { + /** + * Reference to the dialog for quick editing meta information. + */ + @ViewChild('motionInfoDialog') + private motionInfoDialog: TemplateRef; + + /** + * Interface to hold meta information. + */ + public infoDialog: InfoDialog; + /** * Columns to display in table when desktop view is available */ @@ -55,7 +92,7 @@ export class MotionListComponent extends ListViewBaseComponent('motions_statutes_enabled') .subscribe(enabled => (this.statutesEnabled = enabled)); - this.configService - .get('motions_recommendations_by') - .subscribe(recommender => (this.recomendationEnabled = !!recommender)); + this.configService.get('motions_recommendations_by').subscribe(recommender => { + this.recommendationEnabled = !!recommender; + }); this.motionBlockRepo.getViewModelListObservable().subscribe(mBs => (this.motionBlocks = mBs)); this.categoryRepo.getViewModelListObservable().subscribe(cats => (this.categories = cats)); this.tagRepo.getViewModelListObservable().subscribe(tags => (this.tags = tags)); @@ -341,4 +378,54 @@ export class MotionListComponent extends ListViewBaseComponent { + ev.stopPropagation(); + + // The interface holding the current information from motion. + this.infoDialog = { + title: motion.title, + motionBlock: motion.motion_block_id, + category: motion.category_id, + tags: motion.tags_id + }; + + // Copies the interface to check, if changes were made. + const copyDialog = { ...this.infoDialog }; + + const dialogRef = this.dialog.open(this.motionInfoDialog, { + width: '400px', + maxWidth: '90vw', + maxHeight: '90vh', + disableClose: true + }); + + dialogRef.keydownEvents().subscribe((event: KeyboardEvent) => { + if (event.key === 'Enter' && event.shiftKey) { + dialogRef.close(this.infoDialog); + } + }); + + // After closing the dialog: Goes through the fields and check if they are changed + // TODO: Logic like this should be handled in a service + dialogRef.afterClosed().subscribe(async (result: InfoDialog) => { + if (result) { + const partialUpdate = { + category_id: result.category !== copyDialog.category ? result.category : undefined, + motion_block_id: result.motionBlock !== copyDialog.motionBlock ? result.motionBlock : undefined, + tags_id: JSON.stringify(result.tags) !== JSON.stringify(copyDialog.tags) ? result.tags : undefined + }; + // TODO: "only update if different" was another repo-todo + if (!Object.keys(partialUpdate).every(key => partialUpdate[key] === undefined)) { + await this.motionRepo.update(partialUpdate, motion).then(null, this.raiseError); + } + } + }); + } } diff --git a/client/src/app/site/users/components/user-list/user-list.component.html b/client/src/app/site/users/components/user-list/user-list.component.html index b8e458d50..6c5c2a2b0 100644 --- a/client/src/app/site/users/components/user-list/user-list.component.html +++ b/client/src/app/site/users/components/user-list/user-list.component.html @@ -61,10 +61,7 @@
- - flag - {{ user.structure_level }} - + flag{{ user.structure_level }}
diff --git a/client/src/assets/styles/global-components-style.scss b/client/src/assets/styles/global-components-style.scss index e3e462967..5736b907d 100644 --- a/client/src/assets/styles/global-components-style.scss +++ b/client/src/assets/styles/global-components-style.scss @@ -84,4 +84,8 @@ background-color: mat-color($background, hover); color: mat-color($foreground, text) !important; } + + input[readonly] { + cursor: default; + } }