diff --git a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html index 87659fb3d..52622b4d3 100644 --- a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html +++ b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.html @@ -1,40 +1,11 @@
-

Files

- -
- - - Required - - - - - Hidden - Visible - - -
+

Files

@@ -214,3 +185,47 @@ + + +

{{ 'Edit details for' | translate }}

+
+
+ + + Required + + + + + Hidden + Visible + + +
+
+
+ + +
+
diff --git a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.scss b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.scss index cdabeaaea..a8da0aaee 100644 --- a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.scss +++ b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.scss @@ -33,12 +33,6 @@ white-space: pre-line !important; } -.edit-file-form { - mat-form-field + mat-form-field { - margin: 1em; - } -} - // duplicate. Put into own file .file-info-cell { display: grid; diff --git a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts index 98700735b..8d1a69c58 100644 --- a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts +++ b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts @@ -1,8 +1,8 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { FormGroup, Validators, FormBuilder } from '@angular/forms'; import { Title } from '@angular/platform-browser'; -import { MatSnackBar } from '@angular/material'; +import { MatSnackBar, MatDialog } from '@angular/material'; import { TranslateService } from '@ngx-translate/core'; @@ -78,6 +78,12 @@ export class MediafileListComponent extends ListViewBaseComponent; + /** * Constructs the component * @@ -107,7 +113,9 @@ export class MediafileListComponent extends ListViewBaseComponent { this.logoActions = action; @@ -161,24 +164,31 @@ export class MediafileListComponent extends ListViewBaseComponent { + if (event.key === 'Enter' && event.shiftKey && this.fileEditForm.valid) { + this.onSaveEditedFile(this.fileEditForm.value); + } + }); } /** * Click on the save button in edit mode */ - public onSaveEditedFile(): void { - if (!this.fileEditForm.value || !this.fileEditForm.valid) { - return; - } - const updateData = new Mediafile({ - title: this.fileEditForm.value.title, - hidden: this.fileEditForm.value.hidden - }); - - this.repo.update(updateData, this.fileToEdit).then(() => { - this.editFile = false; + public onSaveEditedFile(value: { title: string; hidden: any }): void { + this.repo.update(value, this.fileToEdit).then(() => { + this.dialog.closeAll(); }, this.raiseError); } diff --git a/client/src/app/site/users/components/group-list/group-list.component.html b/client/src/app/site/users/components/group-list/group-list.component.html index 5e09fd5af..555d0e71e 100644 --- a/client/src/app/site/users/components/group-list/group-list.component.html +++ b/client/src/app/site/users/components/group-list/group-list.component.html @@ -1,26 +1,9 @@ - +
-

Groups

- -
- - - Required - -
+

Groups

- - -
- -
-
@@ -67,3 +50,35 @@
+ + +

+ {{ 'New group name' | translate }} +

+
+
+ + + Required + +
+
+
+ + + +
+
diff --git a/client/src/app/site/users/components/group-list/group-list.component.ts b/client/src/app/site/users/components/group-list/group-list.component.ts index 1da2ee52e..a2985114a 100644 --- a/client/src/app/site/users/components/group-list/group-list.component.ts +++ b/client/src/app/site/users/components/group-list/group-list.component.ts @@ -1,8 +1,8 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit, ViewChild, TemplateRef } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; -import { MatTableDataSource, MatSnackBar } from '@angular/material'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { MatTableDataSource, MatSnackBar, MatDialog } from '@angular/material'; +import { FormGroup, Validators, FormBuilder } from '@angular/forms'; import { GroupRepositoryService, AppPermissions } from 'app/core/repositories/users/group-repository.service'; import { ViewGroup } from '../../models/view-group'; @@ -47,6 +47,12 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { @ViewChild('groupForm') public groupForm: FormGroup; + /** + * Reference to the template + */ + @ViewChild('groupEditDialog') + public groupEditDialog: TemplateRef; + public get appPermissions(): AppPermissions[] { return this.repo.appPermissions; } @@ -64,8 +70,10 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { titleService: Title, protected translate: TranslateService, // protected required for ng-translate-extract matSnackBar: MatSnackBar, + private dialog: MatDialog, private repo: GroupRepositoryService, - private promptService: PromptService + private promptService: PromptService, + private fb: FormBuilder ) { super(titleService, translate, matSnackBar); } @@ -79,19 +87,34 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { this.editGroup = editMode; this.newGroup = newGroup; - if (!editMode) { - this.cancelEditing(); - } + const name = this.selectedGroup ? this.selectedGroup.name : ''; + + this.groupForm = this.fb.group({ + name: [name, Validators.required] + }); + + const dialogRef = this.dialog.open(this.groupEditDialog, { + width: '400px', + maxWidth: '90vw', + maxHeight: '90vh', + disableClose: true + }); + + dialogRef.keydownEvents().subscribe((event: KeyboardEvent) => { + if (event.key === 'Enter' && event.shiftKey && this.groupForm.valid) { + this.saveGroup(this.groupForm.value); + } + }); } /** * Creates or updates a group. */ - public saveGroup(): void { + public saveGroup(value: { name: string }): void { if (this.editGroup && this.newGroup) { - this.submitNewGroup(); + this.repo.create(value as Group).then(() => this.cancelEditing(), this.raiseError); } else if (this.editGroup && !this.newGroup) { - this.submitEditedGroup(); + this.repo.update(value, this.selectedGroup).then(() => this.cancelEditing(), this.raiseError); } } @@ -101,34 +124,6 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { public selectGroup(group: ViewGroup): void { this.selectedGroup = group; this.setEditMode(true, false); - this.groupForm.setValue({ name: this.selectedGroup.name }); - } - - /** - * Saves a newly created group. - */ - public submitNewGroup(): void { - if (!this.groupForm.value || !this.groupForm.valid) { - return; - } - this.repo.create(this.groupForm.value as Group).then(() => { - this.groupForm.reset(); - this.cancelEditing(); - }, this.raiseError); - } - - /** - * Saves an edited group. - */ - public submitEditedGroup(): void { - if (!this.groupForm.value || !this.groupForm.valid) { - return; - } - const updateData = new Group({ name: this.groupForm.value.name }); - - this.repo.update(updateData, this.selectedGroup).then(() => { - this.cancelEditing(); - }, this.raiseError); } /** @@ -146,9 +141,10 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { * Cancel the editing */ public cancelEditing(): void { + this.dialog.closeAll(); this.newGroup = false; this.editGroup = false; - this.groupForm.reset(); + this.selectedGroup = null; } /** @@ -214,7 +210,6 @@ export class GroupListComponent extends BaseViewComponent implements OnInit { */ public ngOnInit(): void { super.setTitle('Groups'); - this.groupForm = new FormGroup({ name: new FormControl('', Validators.required) }); this.repo.getViewModelListObservable().subscribe(newViewGroups => { if (newViewGroups) { this.groups = newViewGroups;