From 53bddad8337b920fdfd14d7dec76cc156bd203d9 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 1 Apr 2020 14:54:38 +0100 Subject: [PATCH] fix shared link dialog regressions (#5585) * code fixes * fix typo --- .../content-node-share.dialog.ts | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/content-services/src/lib/content-node-share/content-node-share.dialog.ts b/lib/content-services/src/lib/content-node-share/content-node-share.dialog.ts index b73804a49e..479f4c51b2 100644 --- a/lib/content-services/src/lib/content-node-share/content-node-share.dialog.ts +++ b/lib/content-services/src/lib/content-node-share/content-node-share.dialog.ts @@ -26,12 +26,6 @@ import { import { MAT_DIALOG_DATA, MatDialogRef, MatDialog, MatSlideToggleChange } from '@angular/material'; import { FormGroup, FormControl, AbstractControl } from '@angular/forms'; import { Observable, Subject } from 'rxjs'; -import { - skip, - distinctUntilChanged, - mergeMap, - takeUntil -} from 'rxjs/operators'; import { SharedLinksApiService, NodesApiService, @@ -43,6 +37,9 @@ import { SharedLinkEntry, Node } from '@alfresco/js-api'; import { ConfirmDialogComponent } from '../dialogs/confirm.dialog'; import moment from 'moment-es6'; import { ContentNodeShareSettings } from './content-node-share.settings'; +import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; + +type DatePickerType = 'date' | 'time' | 'month' | 'datetime'; @Component({ selector: 'adf-share-dialog', @@ -63,7 +60,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy { sharedUrl: new FormControl(''), time: new FormControl({ value: '', disabled: true }) }); - type = 'datetime'; + type: DatePickerType = 'datetime'; @ViewChild('slideToggleExpirationDate') slideToggleExpirationDate; @@ -85,27 +82,12 @@ export class ShareDialogComponent implements OnInit, OnDestroy { ) {} ngOnInit() { - this.type = this.appConfigService.get('sharedLinkDateTimePickerType', 'datetime'); - - if (!this.canUpdate) { - this.time.disable(); - } - - this.time.valueChanges - .pipe( - skip(1), - distinctUntilChanged(), - mergeMap( - (updates) => this.updateNode(updates), - (formUpdates) => formUpdates - ), - takeUntil(this.onDestroy$) - ) - .subscribe(updates => this.updateEntryExpiryDate(updates)); + this.type = this.appConfigService.get('sharedLinkDateTimePickerType', 'datetime'); if (this.data.node && this.data.node.entry) { this.fileName = this.data.node.entry.name; this.baseShareUrl = this.data.baseShareUrl; + const properties = this.data.node.entry.properties; if (!properties || !properties['qshare:sharedId']) { @@ -116,6 +98,19 @@ export class ShareDialogComponent implements OnInit, OnDestroy { this.updateForm(); } } + + this.time.valueChanges + .pipe( + distinctUntilChanged(), + takeUntil(this.onDestroy$) + ) + .subscribe(value => this.onTimeChanged(value)); + } + + onTimeChanged(date: moment.Moment) { + this.updateNode(date).subscribe( + () => this.updateEntryExpiryDate(date) + ); } get time(): AbstractControl { @@ -276,11 +271,13 @@ export class ShareDialogComponent implements OnInit, OnDestroy { } private updateNode(date: moment.Moment): Observable { + const expiryDate = date + ? (this.type === 'date' ? date.endOf('day').utc().format() : date.utc().format()) + : null; + return this.nodesApiService.updateNode(this.data.node.entry.id, { properties: { - 'qshare:expiryDate': date ? - (this.type === 'date' ? date.endOf('day').utc().format() : date.utc().format()) : - null + 'qshare:expiryDate': expiryDate } }); }