Browse Source

Clone improvement. (#473)

* Clone improvement.

* Formatting fix.
pull/474/head
Sebastian Stehle 6 years ago
committed by GitHub
parent
commit
01297e8ca1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      frontend/app/features/content/pages/content/content-history-page.component.ts
  2. 34
      frontend/app/features/content/pages/content/content-page.component.ts
  3. 15
      frontend/app/features/content/pages/contents/contents-page.component.ts
  4. 1
      frontend/app/framework/internal.ts
  5. 2
      frontend/app/framework/module.ts
  6. 42
      frontend/app/framework/services/temp.service.spec.ts
  7. 29
      frontend/app/framework/services/temp.service.ts
  8. 4
      frontend/app/framework/services/title.service.ts
  9. 2
      frontend/app/shared/components/help.component.ts
  10. 2
      frontend/app/shared/components/history.component.ts

2
frontend/app/features/content/pages/content/content-history-page.component.ts

@ -30,7 +30,7 @@ import { ContentVersionSelected } from './../messages';
})
export class ContentHistoryPageComponent {
public get channel(): string {
let channelPath = this.route.snapshot.data['channel'];
let channelPath = this.route.snapshot.data.channel;
if (channelPath) {
const params = allParams(this.route);

34
frontend/app/features/content/pages/content/content-page.component.ts

@ -31,6 +31,7 @@ import {
ResourceOwner,
SchemaDetailsDto,
SchemasState,
TempService,
Version
} from '@app/shared';
@ -75,7 +76,8 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
private readonly messageBus: MessageBus,
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly schemasState: SchemasState
private readonly schemasState: SchemasState,
private readonly tempService: TempService
) {
super();
@ -111,21 +113,27 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
contentId: content ? content.id : undefined
};
const autosaved = this.autoSaveService.get(this.autoSaveKey);
if (content) {
this.loadContent(content.dataDraft, true);
}
if (autosaved && this.isOtherContent(content) && this.contentForm.hasChanges(autosaved)) {
this.dialogs.confirm('Unsaved changes', 'You have unsaved changes. Do you want to load them now?')
.subscribe(shouldLoad => {
if (shouldLoad) {
this.loadContent(autosaved, false);
} else {
this.autoSaveService.remove(this.autoSaveKey);
}
});
const clone = this.tempService.fetch();
if (clone) {
this.loadContent(clone, true);
} else {
const autosaved = this.autoSaveService.get(this.autoSaveKey);
if (autosaved && this.isOtherContent(content) && this.contentForm.hasChanges(autosaved)) {
this.dialogs.confirm('Unsaved changes', 'You have unsaved changes. Do you want to load them now?')
.subscribe(shouldLoad => {
if (shouldLoad) {
this.loadContent(autosaved, false);
} else {
this.autoSaveService.remove(this.autoSaveKey);
}
});
}
}
this.content = content;
@ -331,4 +339,4 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
public trackByField(index: number, field: FieldDto) {
return field.fieldId + this.schema.id;
}
}
}

15
frontend/app/features/content/pages/contents/contents-page.component.ts

@ -6,6 +6,7 @@
*/
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { onErrorResumeNext, switchMap, tap } from 'rxjs/operators';
import {
@ -23,6 +24,7 @@ import {
SchemaDetailsDto,
SchemasState,
TableFields,
TempService,
UIState
} from '@app/shared';
@ -63,8 +65,11 @@ export class ContentsPageComponent extends ResourceOwner implements OnInit {
constructor(
public readonly contentsState: ContentsState,
private readonly route: ActivatedRoute,
private readonly router: Router,
private readonly languagesState: LanguagesState,
private readonly schemasState: SchemasState,
private readonly tempService: TempService,
private readonly uiState: UIState
) {
super();
@ -128,10 +133,6 @@ export class ContentsPageComponent extends ResourceOwner implements OnInit {
this.changeContentItems(this.selectItems(c => c.status !== status), status);
}
public clone(content: ContentDto) {
this.contentsState.create(content.dataDraft, false);
}
private changeContentItems(contents: ReadonlyArray<ContentDto>, action: string) {
if (contents.length === 0) {
return;
@ -146,6 +147,12 @@ export class ContentsPageComponent extends ResourceOwner implements OnInit {
.subscribe();
}
public clone(content: ContentDto) {
this.tempService.put(content.dataDraft);
this.router.navigate(['new'], { relativeTo: this.route });
}
public search(query: Query) {
this.contentsState.search(query);
}

1
frontend/app/framework/internal.ts

@ -18,6 +18,7 @@ export * from './services/message-bus.service';
export * from './services/onboarding.service';
export * from './services/resource-loader.service';
export * from './services/shortcut.service';
export * from './services/temp.service';
export * from './services/title.service';
export * from './utils/array-helper';

2
frontend/app/framework/module.ts

@ -90,6 +90,7 @@ import {
SyncWidthDirective,
TagEditorComponent,
TemplateWrapperDirective,
TempService,
TitleComponent,
TitleService,
ToggleComponent,
@ -267,6 +268,7 @@ export class SqxFrameworkModule {
OnboardingService,
ResourceLoaderService,
ShortcutService,
TempService,
TitleService,
{
provide: HTTP_INTERCEPTORS,

42
frontend/app/framework/services/temp.service.spec.ts

@ -0,0 +1,42 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { TempService, TempServiceFactory } from './temp.service';
describe('TempService', () => {
it('should instantiate from factory', () => {
const tempService = TempServiceFactory();
expect(tempService).toBeDefined();
});
it('should instantiate', () => {
const tempService = new TempService();
expect(tempService).toBeDefined();
});
it('should return null when nothing is stored', () => {
const tempService = new TempService();
const temp = tempService.fetch();
expect(temp).toBeNull();
});
it('should return value once when something is stored', () => {
const tempService = new TempService();
tempService.put('Hello');
const temp1 = tempService.fetch();
const temp2 = tempService.fetch();
expect(temp1).toBe('Hello');
expect(temp2).toBeNull();
});
});

29
frontend/app/framework/services/temp.service.ts

@ -0,0 +1,29 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Injectable } from '@angular/core';
export const TempServiceFactory = () => {
return new TempService();
};
@Injectable()
export class TempService {
private value: any = null;
public put(value: any) {
this.value = value;
}
public fetch() {
const result = this.value;
this.value = null;
return result;
}
}

4
frontend/app/framework/services/title.service.ts

@ -5,6 +5,8 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
// tslint:disable: readonly-array
import { Injectable } from '@angular/core';
export class TitlesConfig {
@ -22,7 +24,6 @@ export const TitleServiceFactory = (titles: TitlesConfig) => {
@Injectable()
export class TitleService {
// tslint:disable-next-line: readonly-array
private readonly stack: any[] = [];
constructor(private readonly titles: TitlesConfig) {
@ -73,6 +74,5 @@ export class TitleService {
}
document.title = title;
}
}

2
frontend/app/shared/components/help.component.ts

@ -17,7 +17,7 @@ import { HelpService } from '@app/shared/internal';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HelpComponent {
public helpMarkdown = this.helpService.getHelp(this.route.snapshot.data['helpPage']);
public helpMarkdown = this.helpService.getHelp(this.route.snapshot.data.helpPage);
constructor(
private readonly helpService: HelpService,

2
frontend/app/shared/components/history.component.ts

@ -45,7 +45,7 @@ export class HistoryComponent {
}
private calculateChannel(): string {
let channel = this.route.snapshot.data['channel'];
let channel = this.route.snapshot.data.channel;
if (channel) {
const params = allParams(this.route);

Loading…
Cancel
Save