Browse Source

Temporary version.

pull/107/head
Sebastian Stehle 9 years ago
parent
commit
ae30891525
  1. 2
      src/Squidex.Domain.Apps.Read.MongoDb/History/MongoHistoryEventRepository.cs
  2. 2
      src/Squidex/app/features/content/pages/content/content-history.component.html
  3. 6
      src/Squidex/app/features/content/pages/content/content-history.component.ts
  4. 4
      src/Squidex/app/features/content/pages/content/content-page.component.html
  5. 27
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  6. 1
      src/Squidex/app/features/content/pages/messages.ts
  7. 30
      src/Squidex/app/shared/services/contents.service.spec.ts
  8. 20
      src/Squidex/app/shared/services/contents.service.ts

2
src/Squidex.Domain.Apps.Read.MongoDb/History/MongoHistoryEventRepository.cs

@ -70,7 +70,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.History
{
var historyEventEntities =
await Collection.Find(x => x.AppId == appId && x.Channel == channelPrefix)
.SortByDescending(x => x.Created).ThenBy(x => x.Version).Limit(count)
.SortByDescending(x => x.Created).ThenByDescending(x => x.Version).Limit(count)
.ToListAsync();
return historyEventEntities.Select(x => (IHistoryEventEntity)new ParsedHistoryEvent(x, texts)).ToList();

2
src/Squidex/app/features/content/pages/content/content-history.component.html

@ -21,7 +21,7 @@
</div>
<div class="event-created">{{event.created | sqxFromNow}}</div>
<a class="event-load">Load this Version</a>
<a class="event-load" (click)="loadVersion(event.version)">Load this Version</a>
</div>
</div>
</div>

6
src/Squidex/app/features/content/pages/content/content-history.component.ts

@ -21,6 +21,8 @@ import {
UsersProviderService
} from 'shared';
import { ContentVersionSelected } from './../messages';
const REPLACEMENT_TEMP = '$TEMP$';
@Component({
@ -76,6 +78,10 @@ export class ContentHistoryComponent extends AppComponentBase {
}
}
public loadVersion(version: number) {
this.messageBus.emit(new ContentVersionSelected(version));
}
public format(message: string): Observable<string> {
let foundUserId: string | null = null;

4
src/Squidex/app/features/content/pages/content/content-page.component.html

@ -38,6 +38,10 @@
<div class="panel-main">
<div class="panel-content panel-content-scroll">
<div class="panel-alert panel-alert-danger">
You have not created the subscription. Therefore you cannot change the plan.
</div>
<div *ngFor="let field of schema.fields">
<sqx-content-field [field]="field" [fieldForm]="contentForm.controls[field.name]" [languages]="languages" [contentFormSubmitted]="contentFormSubmitted"></sqx-content-field>
</div>

27
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -13,7 +13,8 @@ import { Observable, Subscription } from 'rxjs';
import {
ContentCreated,
ContentDeleted,
ContentUpdated
ContentUpdated,
ContentVersionSelected
} from './../messages';
import {
@ -38,6 +39,7 @@ import {
})
export class ContentPageComponent extends AppComponentBase implements CanComponentDeactivate, OnDestroy, OnInit {
private contentDeletedSubscription: Subscription;
private contentVersionSelectedSubscription: Subscription;
private version = new Version('');
private content: ContentDto;
@ -63,6 +65,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
}
public ngOnDestroy() {
this.contentVersionSelectedSubscription.unsubscribe();
this.contentDeletedSubscription.unsubscribe();
}
@ -71,6 +74,12 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
this.languages = routeData['appLanguages'];
this.contentVersionSelectedSubscription =
this.messageBus.of(ContentVersionSelected)
.subscribe(message => {
this.loadVersion(message.version);
});
this.contentDeletedSubscription =
this.messageBus.of(ContentDeleted)
.subscribe(message => {
@ -146,6 +155,22 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
}
}
private loadVersion(version: number) {
if (!this.isNewMode && this.content) {
this.appNameOnce()
.switchMap(app => this.contentsService.getVersionData(app, this.schema.name, this.contentId!, new Version(version.toString())))
.subscribe(dto => {
this.content = this.content.setData(dto);
this.emitContentUpdated(this.content);
this.notifyInfo('Content version loaded successfully.');
this.populateContentForm();
}, error => {
this.notifyError(error);
});
}
}
private back() {
this.router.navigate(['../'], { relativeTo: this.route, replaceUrl: true });
}

1
src/Squidex/app/features/content/pages/messages.ts

@ -30,7 +30,6 @@ export class ContentDeleted {
export class ContentVersionSelected {
constructor(
public readonly id: string,
public readonly version: number
) {
}

30
src/Squidex/app/shared/services/contents.service.spec.ts

@ -51,6 +51,15 @@ describe('ContentDto', () => {
expect(content_2.lastModified).toEqual(now);
expect(content_2.lastModifiedBy).toEqual('me');
});
it('should update data property when setting data', () => {
const newData = {};
const content_1 = new ContentDto('1', true, false, 'other', 'other', DateTime.now(), DateTime.now(), { data: 1 }, null);
const content_2 = content_1.setData(newData);
expect(content_2.data).toBe(newData);
});
});
describe('ContentsService', () => {
@ -270,6 +279,27 @@ describe('ContentsService', () => {
new Version('11')));
}));
it('should make get request to get versioned content data',
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => {
const response = {};
let data: any | null = null;
contentsService.getVersionData('my-app', 'my-schema', 'content1', version).subscribe(result => {
data = result;
});
const req = httpMock.expectOne('http://service/p/api/content/my-app/my-schema/content1/1');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toBe(version.value);
req.flush(response);
expect(data).toBe(response);
}));
it('should make put request to update content',
inject([ContentsService, HttpTestingController], (contentsService: ContentsService, httpMock: HttpTestingController) => {

20
src/Squidex/app/shared/services/contents.service.ts

@ -41,6 +41,19 @@ export class ContentDto {
) {
}
public setData(data: any): ContentDto {
return new ContentDto(
this.id,
this.isPublished,
this.isDeleted,
this.createdBy,
this.lastModifiedBy,
this.created,
this.lastModified,
data,
this.version);
}
public publish(user: string, now?: DateTime): ContentDto {
return new ContentDto(
this.id,
@ -204,6 +217,13 @@ export class ContentsService {
.pretifyError('Failed to delete content. Please reload.');
}
public getVersionData(appName: string, schemaName: string, id: string, version?: Version): Observable<any> {
const url = this.apiUrl.buildUrl(`/api/content/${appName}/${schemaName}/${id}/${version.value}`);
return HTTP.getVersioned(this.http, url, version)
.pretifyError('Failed to load data. Please reload.');
}
public publishContent(appName: string, schemaName: string, id: string, version?: Version): Observable<any> {
const url = this.apiUrl.buildUrl(`/api/content/${appName}/${schemaName}/${id}/publish`);

Loading…
Cancel
Save