mirror of https://github.com/Squidex/squidex.git
19 changed files with 134 additions and 321 deletions
@ -1,40 +0,0 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { ErrorDto } from './http-extensions-impl'; |
|||
|
|||
describe('ErrorDto', () => { |
|||
it('Should create simple message when no details are specified.', () => { |
|||
const error = new ErrorDto(500, 'Error Message.'); |
|||
|
|||
expect(error.displayMessage).toBe('Error Message.'); |
|||
}); |
|||
|
|||
it('Should append dot to message', () => { |
|||
const error = new ErrorDto(500, 'Error Message'); |
|||
|
|||
expect(error.displayMessage).toBe('Error Message.'); |
|||
}); |
|||
|
|||
it('Should create simple message when detail has one item', () => { |
|||
const error = new ErrorDto(500, 'Error Message.', ['Detail Message.']); |
|||
|
|||
expect(error.displayMessage).toBe('Error Message: Detail Message.'); |
|||
}); |
|||
|
|||
it('Should create append do to simple message when detail has one item', () => { |
|||
const error = new ErrorDto(500, 'Error Message', ['Detail Message']); |
|||
|
|||
expect(error.displayMessage).toBe('Error Message: Detail Message.'); |
|||
}); |
|||
|
|||
it('Should create html list when error has more items.', () => { |
|||
const error = new ErrorDto(500, 'Error Message', ['Detail1.', 'Detail2.']); |
|||
|
|||
expect(error.displayMessage).toBe('Error Message.<ul><li>Detail1.</li><li>Detail2.</li></ul>'); |
|||
}); |
|||
}); |
|||
@ -1,26 +1,43 @@ |
|||
<form [formGroup]="createForm" (ngSubmit)="createApp()"> |
|||
<div *ngIf="createFormError"> |
|||
<div class="form-alert form-alert-error" [innerHTML]="createFormError"></div> |
|||
</div> |
|||
<div class="modal-dialog"> |
|||
<div class="modal-content"> |
|||
<form [formGroup]="createForm" (ngSubmit)="createApp()"> |
|||
<div class="modal-header"> |
|||
<h4 class="modal-title" *ngIf="template">Create {{template}} Sample</h4> |
|||
<h4 class="modal-title" *ngIf="!template">Create App</h4> |
|||
|
|||
<div class="form-group"> |
|||
<label for="appName">Name</label> |
|||
|
|||
<sqx-control-errors for="name" submitOnly="true" [submitted]="createFormSubmitted"></sqx-control-errors> |
|||
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="completed()"> |
|||
<span aria-hidden="true">×</span> |
|||
</button> |
|||
</div> |
|||
|
|||
<input type="text" class="form-control" id="appName" formControlName="name" autocomplete="off" sqxLowerCaseInput sqxFocusOnInit /> |
|||
|
|||
<small class="form-text text-muted"> |
|||
The app name becomes part of the api url,<br /> e.g {{apiUrl.buildUrl("api/content/")}}<b>{{appName | async}}</b>/. |
|||
</small> |
|||
|
|||
<small class="form-text text-muted"> |
|||
It must contain lower case letters (a-z), numbers and dashes only, and cannot be longer than 40 characters. The name cannot be changed later. |
|||
</small> |
|||
</div> |
|||
<div class="modal-body"> |
|||
<div *ngIf="createFormError"> |
|||
<div class="form-alert form-alert-error" [innerHTML]="createFormError"></div> |
|||
</div> |
|||
|
|||
<div class="form-group"> |
|||
<label for="appName">Name</label> |
|||
|
|||
<sqx-control-errors for="name" submitOnly="true" [submitted]="createFormSubmitted"></sqx-control-errors> |
|||
|
|||
<input type="text" class="form-control" id="appName" formControlName="name" autocomplete="off" sqxLowerCaseInput sqxFocusOnInit /> |
|||
|
|||
<small class="form-text text-muted"> |
|||
The app name becomes part of the api url,<br /> e.g {{apiUrl.buildUrl("api/content/")}}<b>{{appName | async}}</b>/. |
|||
</small> |
|||
|
|||
<small class="form-text text-muted"> |
|||
It must contain lower case letters (a-z), numbers and dashes only, and cannot be longer than 40 characters. The name cannot be changed later. |
|||
</small> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="form-group clearfix"> |
|||
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()" [disabled]="createFormSubmitted">Cancel</button> |
|||
<button type="submit" class="float-right btn btn-success">Create</button> |
|||
<div class="modal-footer"> |
|||
<div class="clearfix"> |
|||
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()" [disabled]="createFormSubmitted">Cancel</button> |
|||
<button type="submit" class="float-right btn btn-success">Create</button> |
|||
</div> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
@ -1,79 +0,0 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { Injectable } from '@angular/core'; |
|||
import { BehaviorSubject, Observable, Observer, ReplaySubject } from 'rxjs'; |
|||
|
|||
import { DateTime } from 'framework'; |
|||
|
|||
import { |
|||
AppDto, |
|||
AppsService, |
|||
CreateAppDto |
|||
} from './apps.service'; |
|||
|
|||
@Injectable() |
|||
export class AppsStoreService { |
|||
public readonly apps$ = new ReplaySubject<AppDto[]>(1); |
|||
public readonly app$ = new BehaviorSubject<AppDto | null>(null); |
|||
|
|||
public get apps(): Observable<AppDto[]> { |
|||
return this.apps$; |
|||
} |
|||
|
|||
public get selectedApp(): Observable<AppDto | null> { |
|||
return this.app$; |
|||
} |
|||
|
|||
constructor( |
|||
private readonly appsService: AppsService |
|||
) { |
|||
if (!appsService) { |
|||
return; |
|||
} |
|||
|
|||
this.appsService.getApps() |
|||
.subscribe(apps => { |
|||
this.apps$.next(apps); |
|||
}, error => { |
|||
this.apps$.next([]); |
|||
}); |
|||
} |
|||
|
|||
public selectApp(name: string | null): Observable<boolean> { |
|||
return Observable.create((observer: Observer<boolean>) => { |
|||
this.apps$.subscribe(apps => { |
|||
const app = apps.find(x => x.name === name) || null; |
|||
|
|||
this.app$.next(app); |
|||
|
|||
observer.next(app !== null); |
|||
observer.complete(); |
|||
}, error => { |
|||
observer.error(error); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
public createApp(dto: CreateAppDto, now?: DateTime): Observable<AppDto> { |
|||
return this.appsService.postApp(dto) |
|||
.do(app => { |
|||
this.apps$.take(1).subscribe(apps => { |
|||
this.apps$.next(apps.concat([app])); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
public deleteApp(appName: string): Observable<any> { |
|||
return this.appsService.deleteApp(appName) |
|||
.do(app => { |
|||
this.apps$.take(1).subscribe(apps => { |
|||
this.apps$.next(apps.filter(a => a.name !== appName)); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue