mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
used date-fns instead of moment.js in code as well as in test cases
This commit is contained in:
@@ -28,9 +28,10 @@ import { RenditionService } from '../common/services/rendition.service';
|
|||||||
|
|
||||||
import { SharedLinksApiService } from './services/shared-links-api.service';
|
import { SharedLinksApiService } from './services/shared-links-api.service';
|
||||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||||
import moment from 'moment';
|
|
||||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import endOfDay from 'date-fns/endOfDay';
|
||||||
|
|
||||||
describe('ShareDialogComponent', () => {
|
describe('ShareDialogComponent', () => {
|
||||||
let node;
|
let node;
|
||||||
@@ -256,7 +257,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls['time'].setValue(moment());
|
component.form.controls['time'].setValue(new Date());
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@@ -305,7 +306,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
|
|
||||||
it('should update node with input date and end of day time when type is `date`', fakeAsync(() => {
|
it('should update node with input date and end of day time when type is `date`', fakeAsync(() => {
|
||||||
const dateTimePickerType = 'date';
|
const dateTimePickerType = 'date';
|
||||||
const date = moment('2525-01-01 13:00:00');
|
const date = new Date('2525-01-01 13:00:00');
|
||||||
spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType as any);
|
spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType as any);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -316,9 +317,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
tick(500);
|
tick(500);
|
||||||
|
|
||||||
let expiryDate = date.endOf('day').utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
const expiryDate = format(endOfDay(date as Date), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
|
||||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
|
||||||
|
|
||||||
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
||||||
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
||||||
@@ -329,7 +328,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
|
|
||||||
it('should update node with input date and time when type is `datetime`', fakeAsync(() => {
|
it('should update node with input date and time when type is `datetime`', fakeAsync(() => {
|
||||||
const dateTimePickerType = 'datetime';
|
const dateTimePickerType = 'datetime';
|
||||||
const date = moment('2525-01-01 13:00:00');
|
const date = new Date('2525-01-01 13:00:00');
|
||||||
spyOn(appConfigService, 'get').and.returnValue(dateTimePickerType);
|
spyOn(appConfigService, 'get').and.returnValue(dateTimePickerType);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -340,9 +339,7 @@ describe('ShareDialogComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
tick(100);
|
tick(100);
|
||||||
|
|
||||||
let expiryDate = date.utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
const expiryDate = format((new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
|
||||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
|
||||||
|
|
||||||
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
||||||
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalledWith({
|
||||||
|
|||||||
@@ -35,10 +35,13 @@ import { ContentService } from '../common/services/content.service';
|
|||||||
import { SharedLinksApiService } from './services/shared-links-api.service';
|
import { SharedLinksApiService } from './services/shared-links-api.service';
|
||||||
import { SharedLinkBodyCreate, SharedLinkEntry } from '@alfresco/js-api';
|
import { SharedLinkBodyCreate, SharedLinkEntry } from '@alfresco/js-api';
|
||||||
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
||||||
import moment from 'moment';
|
|
||||||
import { ContentNodeShareSettings } from './content-node-share.settings';
|
import { ContentNodeShareSettings } from './content-node-share.settings';
|
||||||
import { takeUntil, debounceTime } from 'rxjs/operators';
|
import { takeUntil, debounceTime } from 'rxjs/operators';
|
||||||
import { RenditionService } from '../common/services/rendition.service';
|
import { RenditionService } from '../common/services/rendition.service';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import add from 'date-fns/add';
|
||||||
|
import endOfDay from 'date-fns/endOfDay';
|
||||||
|
|
||||||
|
|
||||||
type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
|
type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
|
||||||
|
|
||||||
@@ -51,7 +54,7 @@ type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
|
|||||||
})
|
})
|
||||||
export class ShareDialogComponent implements OnInit, OnDestroy {
|
export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
minDate = moment().add(1, 'd');
|
minDate = add(new Date(), { days: 1 });
|
||||||
sharedId: string;
|
sharedId: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
baseShareUrl: string;
|
baseShareUrl: string;
|
||||||
@@ -112,10 +115,9 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
takeUntil(this.onDestroy$)
|
takeUntil(this.onDestroy$)
|
||||||
)
|
)
|
||||||
.subscribe(value => this.onTimeChanged(value));
|
.subscribe(value => this.onTimeChanged(value));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onTimeChanged(date: moment.Moment) {
|
onTimeChanged(date: Date | string) {
|
||||||
this.updateNode(date);
|
this.updateNode(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,19 +275,19 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.form.setValue({
|
this.form.setValue({
|
||||||
sharedUrl: `${this.baseShareUrl}${this.sharedId}`,
|
sharedUrl: `${this.baseShareUrl}${this.sharedId}`,
|
||||||
time: expiryDate ? moment(expiryDate).local() : null
|
time: expiryDate ? new Date(expiryDate) : null
|
||||||
}, { emitEvent: false });
|
}, { emitEvent: false });
|
||||||
|
|
||||||
return expiryDate;
|
return expiryDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateNode(date: moment.Moment) {
|
private updateNode(date: Date | string) {
|
||||||
let expiryDate: Date | string;
|
let expiryDate: Date | string;
|
||||||
if (date) {
|
if (date) {
|
||||||
if (this.type === 'date') {
|
if (this.type === 'date') {
|
||||||
expiryDate = date.endOf('day').utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
expiryDate = format(endOfDay(date as Date), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||||
} else {
|
} else {
|
||||||
expiryDate = date.utc().format('YYYY-MM-DDTHH:mm:ss.SSSZ');
|
expiryDate = format((new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
expiryDate = null;
|
expiryDate = null;
|
||||||
@@ -309,24 +311,19 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sharedLinkWithExpirySettings(expiryDate: Date | string) {
|
private sharedLinkWithExpirySettings(expiryDate: Date | string) {
|
||||||
if (typeof expiryDate === 'string') {
|
|
||||||
const lastIndex = expiryDate?.lastIndexOf(':');
|
|
||||||
expiryDate = expiryDate?.substring(0, lastIndex) + expiryDate?.substring(lastIndex + 1, expiryDate?.length);
|
|
||||||
}
|
|
||||||
const nodeObject: SharedLinkBodyCreate = {
|
const nodeObject: SharedLinkBodyCreate = {
|
||||||
nodeId: this.data.node.entry.id,
|
nodeId: this.data.node.entry.id,
|
||||||
expiresAt: expiryDate as Date
|
expiresAt: expiryDate as Date
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createSharedLinks(nodeObject);
|
this.createSharedLinks(nodeObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateEntryExpiryDate(date: moment.Moment) {
|
private updateEntryExpiryDate(date: Date | string) {
|
||||||
const {properties} = this.data.node.entry;
|
const {properties} = this.data.node.entry;
|
||||||
|
|
||||||
if (properties) {
|
if (properties) {
|
||||||
properties['qshare:expiryDate'] = date
|
properties['qshare:expiryDate'] = date
|
||||||
? date.local()
|
? new Date(date)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
"apollo-angular": "^4.2.1",
|
"apollo-angular": "^4.2.1",
|
||||||
"chart.js": "2.9.4",
|
"chart.js": "2.9.4",
|
||||||
"cropperjs": "1.5.13",
|
"cropperjs": "1.5.13",
|
||||||
|
"date-fns": "^2.30.0",
|
||||||
"dotenv-expand": "^5.1.0",
|
"dotenv-expand": "^5.1.0",
|
||||||
"editorjs-html": "3.4.2",
|
"editorjs-html": "3.4.2",
|
||||||
"editorjs-paragraph-with-alignment": "3.0.0",
|
"editorjs-paragraph-with-alignment": "3.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user