+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ (currentTag ? 'Edit tag' : 'New tag') | translate }}
+
+
+
diff --git a/client/src/app/site/tags/components/tag-list/tag-list.component.ts b/client/src/app/site/tags/components/tag-list/tag-list.component.ts
index ae424b516..8150d68d1 100644
--- a/client/src/app/site/tags/components/tag-list/tag-list.component.ts
+++ b/client/src/app/site/tags/components/tag-list/tag-list.component.ts
@@ -1,5 +1,6 @@
-import { Component, OnInit, ViewChild } from '@angular/core';
-import { FormControl, FormGroup, Validators } from '@angular/forms';
+import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { MatDialog, MatDialogRef } from '@angular/material';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Title } from '@angular/platform-browser';
@@ -13,7 +14,7 @@ import { BaseListViewComponent } from 'app/site/base/base-list-view';
import { ViewTag } from '../../models/view-tag';
/**
- * Listview for the complete lsit of available Tags
+ * Listview for the complete list of available Tags
* ### Usage:
* ```html
*
@@ -25,12 +26,19 @@ import { ViewTag } from '../../models/view-tag';
styleUrls: ['./tag-list.component.scss']
})
export class TagListComponent extends BaseListViewComponent
implements OnInit {
- public editTag = false;
- public newTag = false;
- public selectedTag: ViewTag;
+ @ViewChild('tagDialog', { static: true })
+ private tagDialog: TemplateRef;
- @ViewChild('tagForm', { static: true })
- public tagForm: FormGroup;
+ private tagForm: FormGroup = this.formBuilder.group({
+ name: ['', [Validators.required]]
+ });
+
+ private dialogRef: MatDialogRef;
+
+ /**
+ * Holds the tag that's currently being edited, or null.
+ */
+ public currentTag: ViewTag;
/**
* Define the columns to show
@@ -39,6 +47,14 @@ export class TagListComponent extends BaseListViewComponent implements
{
prop: 'name',
width: 'auto'
+ },
+ {
+ prop: 'edit',
+ width: this.singleButtonWidth
+ },
+ {
+ prop: 'delete',
+ width: this.singleButtonWidth
}
];
@@ -55,7 +71,9 @@ export class TagListComponent extends BaseListViewComponent implements
matSnackBar: MatSnackBar,
public repo: TagRepositoryService,
protected translate: TranslateService, // protected required for ng-translate-extract
- private promptService: PromptService
+ private promptService: PromptService,
+ private dialog: MatDialog,
+ private formBuilder: FormBuilder
) {
super(titleService, translate, matSnackBar);
}
@@ -66,93 +84,48 @@ export class TagListComponent extends BaseListViewComponent implements
*/
public ngOnInit(): void {
super.setTitle('Tags');
- this.tagForm = new FormGroup({ name: new FormControl('', Validators.required) });
}
/**
- * Sends a new or updates tag to the dataStore
+ * sets the given tag as the current and opens the tag dialog.
+ * @param tag the current tag, or null if a new tag is to be created
*/
- public saveTag(): void {
- if (this.editTag && this.newTag) {
- this.submitNewTag();
- } else if (this.editTag && !this.newTag) {
- this.submitEditedTag();
- }
- }
-
- /**
- * Saves a newly created tag.
- */
- public submitNewTag(): void {
- if (!this.tagForm.value || !this.tagForm.valid) {
- return;
- }
- this.repo.create(this.tagForm.value).then(() => {
- this.tagForm.reset();
- this.cancelEditing();
- }, this.raiseError);
- }
-
- /**
- * Saves an edited tag.
- */
- public submitEditedTag(): void {
- if (!this.tagForm.value || !this.tagForm.valid) {
- return;
- }
- const updateData = new Tag({ name: this.tagForm.value.name });
-
- this.repo.update(updateData, this.selectedTag).then(() => this.cancelEditing(), this.raiseError);
- }
-
- /**
- * Deletes the selected Tag after a successful confirmation.
- */
- public async deleteSelectedTag(): Promise {
- const title = this.translate.instant('Are you sure you want to delete this tag?');
- const content = this.selectedTag.name;
- if (await this.promptService.open(title, content)) {
- this.repo.delete(this.selectedTag).then(() => this.cancelEditing(), this.raiseError);
- }
- }
-
- /**
- * Cancels the editing
- */
- public cancelEditing(): void {
- this.newTag = false;
- this.editTag = false;
+ public openTagDialog(tag?: ViewTag): void {
+ this.currentTag = tag;
this.tagForm.reset();
+ this.tagForm.get('name').setValue(this.currentTag ? this.currentTag.name : '');
+ this.dialogRef = this.dialog.open(this.tagDialog, {
+ width: '400px',
+ maxWidth: '90vw',
+ maxHeight: '90vh',
+ disableClose: true
+ });
}
/**
- * Handler for a click on a row in the table
- * @param viewTag
+ * Submit the form and create or update a tag.
*/
- public selectTag(viewTag: ViewTag): void {
- this.selectedTag = viewTag;
- this.setEditMode(true, false);
- this.tagForm.setValue({ name: this.selectedTag.name });
- }
-
- public setEditMode(mode: boolean, newTag: boolean = true): void {
- this.editTag = mode;
- this.newTag = newTag;
- if (!mode) {
- this.cancelEditing();
+ public onSubmit(): void {
+ if (!this.tagForm.value || !this.tagForm.valid) {
+ return;
+ }
+ if (this.currentTag) {
+ this.repo
+ .update(new Tag(this.tagForm.value), this.currentTag)
+ .then(() => this.dialogRef.close(), this.raiseError);
+ } else {
+ this.repo.create(this.tagForm.value).then(() => this.dialogRef.close(), this.raiseError);
}
}
/**
- * Handles keyboard events. On enter, the editing is canceled.
- * @param event
+ * Deletes the given Tag after a successful confirmation.
*/
- public keyDownFunction(event: KeyboardEvent): void {
- if (event.key === 'Enter' && event.shiftKey) {
- this.submitNewTag();
- }
- if (event.key === 'Escape') {
- this.cancelEditing();
+ public async onDeleteButton(tag: ViewTag): Promise {
+ const title = this.translate.instant('Are you sure you want to delete this tag?');
+ const content = tag.name;
+ if (await this.promptService.open(title, content)) {
+ this.repo.delete(tag).catch(this.raiseError);
}
}
}
diff --git a/openslides/core/views.py b/openslides/core/views.py
index 11f71b968..71ef04fc8 100644
--- a/openslides/core/views.py
+++ b/openslides/core/views.py
@@ -186,6 +186,7 @@ class ProjectorViewSet(ModelViewSet):
If `reset_scroll` is True, the scoll of the projector will reset.
"""
projector = self.get_object()
+ projector.scroll = 0
elements = request.data.get("elements")
preview = request.data.get("preview")
history_element = request.data.get("append_to_history")