Browse Source

Guards removed

pull/271/head
Sebastian Stehle 8 years ago
parent
commit
0bb18c5f7d
  1. 16
      src/Squidex/app/app.component.html
  2. 3
      src/Squidex/app/features/administration/declarations.ts
  3. 87
      src/Squidex/app/features/administration/guards/resolve-user.guard.spec.ts
  4. 24
      src/Squidex/app/features/administration/guards/unset-user.guard.ts
  5. 44
      src/Squidex/app/features/administration/guards/user-must-exist.guard.ts
  6. 14
      src/Squidex/app/features/administration/module.ts
  7. 70
      src/Squidex/app/features/administration/pages/users/user-page.component.html
  8. 21
      src/Squidex/app/features/administration/pages/users/user-page.component.ts
  9. 5
      src/Squidex/app/features/administration/pages/users/users-page.component.ts
  10. 2
      src/Squidex/app/features/schemas/pages/schema/types/references-validation.component.ts
  11. 79
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html
  12. 31
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts
  13. 23
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html
  14. 11
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  15. 2
      src/Squidex/app/framework/angular/dialog-renderer.component.html
  16. 8
      src/Squidex/app/framework/angular/modal-view.directive.ts
  17. 21
      src/Squidex/app/framework/angular/root-view.component.ts
  18. 27
      src/Squidex/app/framework/angular/root-view.directive.spec.ts
  19. 19
      src/Squidex/app/framework/angular/root-view.directive.ts
  20. 3
      src/Squidex/app/framework/declarations.ts
  21. 8
      src/Squidex/app/framework/module.ts
  22. 43
      src/Squidex/app/framework/services/root-view.service.spec.ts
  23. 25
      src/Squidex/app/framework/services/root-view.service.ts
  24. 3
      src/Squidex/app/shell/pages/internal/internal-area.component.html

16
src/Squidex/app/app.component.html

@ -1,9 +1,13 @@
<main>
<router-outlet (activate)="isLoaded = true">
<div class="loading" *ngIf="!isLoaded">
<img src="/images/loader.gif" />
<sqx-root-view>
<sqx-dialog-renderer>
<router-outlet (activate)="isLoaded = true">
<div class="loading" *ngIf="!isLoaded">
<img src="/images/loader.gif" />
<div>Loading Squidex</div>
</div>
</router-outlet>
<div>Loading Squidex</div>
</div>
</router-outlet>
</sqx-dialog-renderer>
</sqx-root-view>
</main>

3
src/Squidex/app/features/administration/declarations.ts

@ -7,9 +7,6 @@
export * from './administration-area.component';
export * from './guards/user-must-exist.guard';
export * from './guards/unset-user.guard';
export * from './pages/event-consumers/event-consumers-page.component';
export * from './pages/users/user-page.component';
export * from './pages/users/users-page.component';

87
src/Squidex/app/features/administration/guards/resolve-user.guard.spec.ts

@ -1,87 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
/*
import { IMock, Mock } from 'typemoq';
import { Observable } from 'rxjs';
import { UserManagementService } from 'shared';
import { ResolveUserGuard } from './resolve-user.guard';
import { RouterMockup } from './router-mockup';
describe('ResolveUserGuard', () => {
const route = {
params: {},
parent: {
params: {
userId: 'my-user'
}
}
};
let usersService: IMock<UserManagementService>;
beforeEach(() => {
usersService = Mock.ofType(UserManagementService);
});
it('should throw if route does not contain parameter', () => {
const guard = new ResolveUserGuard(usersService.object, <any>new RouterMockup());
expect(() => guard.resolve(<any>{ params: {} }, <any>{})).toThrow('Route must contain user id.');
});
it('should navigate to 404 page if user is not found', (done) => {
usersService.setup(x => x.getUser('my-user'))
.returns(() => Observable.of(null!));
const router = new RouterMockup();
const guard = new ResolveUserGuard(usersService.object, <any>router);
guard.resolve(<any>route, <any>{})
.subscribe(result => {
expect(result).toBeFalsy();
expect(router.lastNavigation).toEqual(['/404']);
done();
});
});
it('should navigate to 404 page if user loading fails', (done) => {
usersService.setup(x => x.getUser('my-user'))
.returns(() => Observable.throw(null!));
const router = new RouterMockup();
const guard = new ResolveUserGuard(usersService.object, <any>router);
guard.resolve(<any>route, <any>{})
.subscribe(result => {
expect(result).toBeFalsy();
expect(router.lastNavigation).toEqual(['/404']);
done();
});
});
it('should return user if loading succeeded', (done) => {
const user: any = {};
usersService.setup(x => x.getUser('my-user'))
.returns(() => Observable.of(user));
const router = new RouterMockup();
const guard = new ResolveUserGuard(usersService.object, <any>router);
guard.resolve(<any>route, <any>{})
.subscribe(result => {
expect(result).toBe(user);
done();
});
});
});
*/

24
src/Squidex/app/features/administration/guards/unset-user.guard.ts

@ -1,24 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { UsersState } from './../state/users.state';
@Injectable()
export class UnsetUserGuard implements CanActivate {
constructor(
private readonly usersState: UsersState
) {
}
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return this.usersState.selectUser(null).map(u => u === null);
}
}

44
src/Squidex/app/features/administration/guards/user-must-exist.guard.ts

@ -1,44 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { allParams } from 'framework';
import { UsersState } from './../state/users.state';
@Injectable()
export class UserMustExistGuard implements CanActivate {
constructor(
private readonly usersState: UsersState,
private readonly router: Router
) {
}
public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
const params = allParams(route);
const userId = params['userId'];
if (!userId) {
throw 'Route must contain user id.';
}
const result =
this.usersState.selectUser(userId)
.do(dto => {
if (!dto) {
this.router.navigate(['/404']);
}
})
.map(u => u !== null);
return result;
}
}

14
src/Squidex/app/features/administration/module.ts

@ -17,12 +17,9 @@ import {
AdministrationAreaComponent,
EventConsumersPageComponent,
EventConsumersService,
UnsetUserGuard,
UserPageComponent,
UserMustExistGuard,
UsersPageComponent,
UsersService,
UsersState
UsersService
} from './declarations';
const routes: Routes = [
@ -43,13 +40,11 @@ const routes: Routes = [
children: [
{
path: 'new',
component: UserPageComponent,
canActivate: [UnsetUserGuard]
component: UserPageComponent
},
{
path: ':userId',
component: UserPageComponent,
canActivate: [UserMustExistGuard]
component: UserPageComponent
}
]
}
@ -75,8 +70,7 @@ const routes: Routes = [
EventConsumersService,
UnsetUserGuard,
UserMustExistGuard,
UsersService,
UsersState
UsersService
]
})
export class SqxFeatureAdministrationModule { }

70
src/Squidex/app/features/administration/pages/users/user-page.component.html

@ -1,27 +1,24 @@
<sqx-title message="User Management"></sqx-title>
<form [formGroup]="userForm" (ngSubmit)="save()">
<input style="display:none" type="password" name="foilautofill"/>
<input style="display:none" type="password" name="foilautofill" />
<sqx-panel desiredWidth="26rem">
<div class="panel-header">
<div class="panel-title-row">
<div class="float-right">
<div class="float-right" *ngIf="!isNotFound">
<button type="submit" class="btn btn-primary" title="CTRL + S">
Save
</button>
</div>
<sqx-shortcut keys="ctrl+s" (trigger)="save()"></sqx-shortcut>
<h3 class="panel-title" *ngIf="!user">
New User
</h3>
<h3 class="panel-title" *ngIf="user">
Edit User
<h3 class="panel-title">
{{isNotFound || user ? 'Edit User' : 'New User'}}
</h3>
</div>
<sqx-shortcut keys="ctrl+s" (trigger)="save()"></sqx-shortcut>
<a class="panel-close" sqxParentLink>
@ -31,43 +28,52 @@
<div class="panel-main">
<div class="panel-content panel-content-blank">
<div *ngIf="userFormError">
<div class="form-alert form-alert-error" [innerHTML]="userFormError"></div>
<div *ngIf="isNotFound">
The user does not exist.
</div>
<div class="form-group">
<label for="email">Email</label>
<sqx-control-errors for="email" [submitted]="userFormSubmitted"></sqx-control-errors>
<input type="email" class="form-control" id="email" maxlength="100" formControlName="email" autocomplete="false" />
</div>
<div class="form-group">
<label for="displayName">Display Name</label>
<div *ngIf="!isNotFound">
<div *ngIf="userFormError">
<div class="form-alert form-alert-error" [innerHTML]="userFormError"></div>
</div>
<sqx-control-errors for="displayName" [submitted]="userFormSubmitted"></sqx-control-errors>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="displayName" maxlength="100" formControlName="displayName" autocomplete="false" />
</div>
<sqx-control-errors for="email" [submitted]="userFormSubmitted"></sqx-control-errors>
<div class="form-group form-group-password" [class.hidden]="isCurrentUser">
<input type="email" class="form-control" id="email" maxlength="100" formControlName="email" autocomplete="false" />
</div>
<div class="form-group">
<label for="password">Password</label>
<label for="displayName">Display Name</label>
<sqx-control-errors for="password" [submitted]="userFormSubmitted"></sqx-control-errors>
<sqx-control-errors for="displayName" [submitted]="userFormSubmitted"></sqx-control-errors>
<input type="password" class="form-control" id="password" maxlength="100" formControlName="password" autocomplete="false" />
<input type="text" class="form-control" id="displayName" maxlength="100" formControlName="displayName" autocomplete="false"
/>
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<div class="form-group form-group-password" [class.hidden]="isCurrentUser">
<div class="form-group">
<label for="password">Password</label>
<sqx-control-errors for="password" [submitted]="userFormSubmitted"></sqx-control-errors>
<input type="password" class="form-control" id="password" maxlength="100" formControlName="password" autocomplete="false"
/>
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<sqx-control-errors for="passwordConfirm" [submitted]="userFormSubmitted"></sqx-control-errors>
<sqx-control-errors for="passwordConfirm" [submitted]="userFormSubmitted"></sqx-control-errors>
<input type="password" class="form-control" id="passwordConfirm" maxlength="100" formControlName="passwordConfirm" autocomplete="false" />
<input type="password" class="form-control" id="passwordConfirm" maxlength="100" formControlName="passwordConfirm" autocomplete="false"
/>
</div>
</div>
</div>
</div>
</div>
</sqx-panel>
</form>
</form>

21
src/Squidex/app/features/administration/pages/users/user-page.component.ts

@ -5,10 +5,9 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AuthService, ValidatorsEx } from 'shared';
@ -20,9 +19,7 @@ import { UsersState } from './../../state/users.state';
styleUrls: ['./user-page.component.scss'],
templateUrl: './user-page.component.html'
})
export class UserPageComponent implements OnDestroy, OnInit {
private selectedUserSubscription: Subscription;
export class UserPageComponent implements OnInit {
public userFormSubmitted = false;
public userFormError = '';
public userForm =
@ -51,6 +48,7 @@ export class UserPageComponent implements OnDestroy, OnInit {
public user: UserDto | null;
public isCurrentUser = false;
public isNotFound = false;
constructor(
private readonly authService: AuthService,
@ -61,13 +59,14 @@ export class UserPageComponent implements OnDestroy, OnInit {
) {
}
public ngOnDestroy() {
this.selectedUserSubscription.unsubscribe();
}
public ngOnInit() {
this.selectedUserSubscription =
this.usersState.selectedUser.subscribe(user => this.setupAndPopulateForm(user!));
this.route.params.map(p => p['userId'])
.switchMap(id => this.usersState.selectUser(id).map(u => { return { user: u, expected: !!id }; }))
.subscribe(result => {
this.isNotFound = !result.user && result.expected;
this.setupAndPopulateForm(result.user);
});
}
public save() {

5
src/Squidex/app/features/administration/pages/users/users-page.component.ts

@ -16,7 +16,10 @@ import { UsersState } from './../../state/users.state';
@Component({
selector: 'sqx-users-page',
styleUrls: ['./users-page.component.scss'],
templateUrl: './users-page.component.html'
templateUrl: './users-page.component.html',
providers: [
UsersState
]
})
export class UsersPageComponent implements OnInit {
public usersFilter = new FormControl();

2
src/Squidex/app/features/schemas/pages/schema/types/references-validation.component.ts

@ -10,7 +10,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ReferencesFieldPropertiesDto } from 'shared';
import { SchemasState } from './../../..';
import { SchemasState } from './../../../state/schemas.state';
@Component({
selector: 'sqx-references-validation',

79
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html

@ -1,36 +1,51 @@
<form [formGroup]="createForm" (ngSubmit)="createSchema()">
<div *ngIf="createFormError">
<div class="form-alert form-alert-error" [innerHTML]="createFormError"></div>
</div>
<div class="form-group">
<label for="schemaName">Name</label>
<sqx-control-errors for="name" submitOnly="true" [submitted]="createFormSubmitted"></sqx-control-errors>
<div class="modal-dialog">
<div class="modal-content">
<form [formGroup]="createForm" (ngSubmit)="createSchema()">
<div class="modal-header">
<h4 class="modal-title" *ngIf="import">Clone Schema</h4>
<h4 class="modal-title" *ngIf="!import">Create Schema</h4>
<input type="text" class="form-control" id="schemaName" formControlName="name" autocomplete="off" sqxLowerCaseInput sqxFocusOnInit />
<small class="form-text text-muted">
The schema name becomes part of the api url,<br /> e.g {{apiUrl.buildUrl("api/content/")}}{{ctx.appName}}/<b>{{schemaName | 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="form-group clearfix">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button>
<button type="submit" class="float-right btn btn-success">Create</button>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="complete()">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="showImport">
Import schema
</button>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="!showImport">
Hide
</button>
<div class="modal-body">
<div *ngIf="createFormError">
<div class="form-alert form-alert-error" [innerHTML]="createFormError"></div>
</div>
<div class="form-group">
<label for="schemaName">Name</label>
<sqx-control-errors for="name" submitOnly="true" [submitted]="createFormSubmitted"></sqx-control-errors>
<input type="text" class="form-control" id="schemaName" formControlName="name" autocomplete="off" sqxLowerCaseInput sqxFocusOnInit />
<small class="form-text text-muted">
The schema name becomes part of the api url,<br /> e.g {{apiUrl.buildUrl("api/content/")}}{{ctx.appName}}/<b>{{schemaName | 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>
<sqx-json-editor *ngIf="showImport" formControlName="import"></sqx-json-editor>
<div class="form-group clearfix">
<button type="reset" class="float-left btn btn-secondary" (click)="complete()">Cancel</button>
<button type="submit" class="float-right btn btn-success">Create</button>
</div>
<div>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="showImport">
Import schema
</button>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="!showImport">
Hide
</button>
<sqx-json-editor *ngIf="showImport" formControlName="import"></sqx-json-editor>
</div>
</div>
</form>
</div>
</form>
</div>

31
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts

@ -8,11 +8,7 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import {
ApiUrlConfig,
AppContext,
ValidatorsEx
} from 'shared';
import { ApiUrlConfig, ValidatorsEx } from 'shared';
import { SchemasState } from './../../state/schemas.state';
@ -21,10 +17,7 @@ const FALLBACK_NAME = 'my-schema';
@Component({
selector: 'sqx-schema-form',
styleUrls: ['./schema-form.component.scss'],
templateUrl: './schema-form.component.html',
providers: [
AppContext
]
templateUrl: './schema-form.component.html'
})
export class SchemaFormComponent implements OnInit {
@Output()
@ -54,7 +47,6 @@ export class SchemaFormComponent implements OnInit {
constructor(
public readonly apiUrl: ApiUrlConfig,
public readonly ctx: AppContext,
private readonly schemasState: SchemasState,
private readonly formBuilder: FormBuilder
) {
@ -72,9 +64,8 @@ export class SchemaFormComponent implements OnInit {
return false;
}
public cancel() {
this.emitCompleted();
this.resetCreateForm();
public complete() {
this.completed.emit();
}
public createSchema() {
@ -88,27 +79,15 @@ export class SchemaFormComponent implements OnInit {
this.schemasState.create(schemaDto)
.subscribe(dto => {
this.emitCompleted();
this.resetCreateForm();
this.complete();
}, error => {
this.enableCreateForm(error.displayMessage);
});
}
}
private emitCompleted() {
this.completed.emit();
}
private enableCreateForm(message: string) {
this.createForm.enable();
this.createFormError = message;
}
private resetCreateForm() {
this.createFormError = '';
this.createForm.reset();
this.createFormSubmitted = false;
}
}

23
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html

@ -1,4 +1,4 @@
<sqx-title message="{app} | Schemas" parameter1="app" [value1]="ctx.appName"></sqx-title>
<sqx-title message="{app} | Schemas" parameter1="app" [value1]="appsState.selectedApp.value.name"></sqx-title>
<sqx-panel theme="dark" desiredWidth="30rem">
<div class="panel-header">
@ -55,23 +55,10 @@
<div class="modal" *sqxModalView="addSchemaDialog;onRoot:true" @fade>
<div class="modal-backdrop"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" *ngIf="import">Clone Schema</h4>
<h4 class="modal-title" *ngIf="!import">Create Schema</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="addSchemaDialog.hide()">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<sqx-schema-form [import]="import" (completed)="addSchemaDialog.hide()">
</sqx-schema-form>
</div>
</div>
</div>
<sqx-schema-form [import]="import"
(completed)="addSchemaDialog.hide()">
</sqx-schema-form>
</div>
<router-outlet></router-outlet>

11
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -7,9 +7,10 @@
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import {
AppContext,
AppsState,
fadeAnimation,
ModalView
} from 'shared';
@ -20,9 +21,6 @@ import { SchemasState } from './../../state/schemas.state';
selector: 'sqx-schemas-page',
styleUrls: ['./schemas-page.component.scss'],
templateUrl: './schemas-page.component.html',
providers: [
AppContext
],
animations: [
fadeAnimation
]
@ -44,13 +42,14 @@ export class SchemasPageComponent implements OnInit {
public import: any;
constructor(public readonly ctx: AppContext,
constructor(public readonly appsState: AppsState,
private readonly route: ActivatedRoute,
private readonly schemasState: SchemasState
) {
}
public ngOnInit() {
this.ctx.route.params.map(q => q['showDialog'])
this.route.params.map(q => q['showDialog'])
.subscribe(showDialog => {
if (showDialog) {
this.addSchemaDialog.show();

2
src/Squidex/app/framework/angular/dialog-renderer.component.html

@ -1,3 +1,5 @@
<ng-content></ng-content>
<div class="modal" *sqxModalView="dialogView;onRoot:true">
<div class="modal-backdrop"></div>
<div class="modal-dialog">

8
src/Squidex/app/framework/angular/modal-view.directive.ts

@ -10,7 +10,7 @@ import { Subscription } from 'rxjs';
import { ModalView } from './../utils/modal-view';
import { RootViewService } from './../services/root-view.service';
import { RootViewComponent } from './root-view.component';
@Directive({
selector: '[sqxModalView]'
@ -33,7 +33,7 @@ export class ModalViewDirective implements OnChanges, OnDestroy {
private readonly templateRef: TemplateRef<any>,
private readonly renderer: Renderer,
private readonly viewContainer: ViewContainerRef,
private readonly rootContainer: RootViewService
private readonly rootView: RootViewComponent
) {
}
@ -72,7 +72,7 @@ export class ModalViewDirective implements OnChanges, OnDestroy {
if (isOpen && !this.renderedView) {
if (this.placeOnRoot) {
this.renderedView = this.rootContainer.createEmbeddedView(this.templateRef);
this.renderedView = this.rootView.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.renderedView = this.viewContainer.createEmbeddedView(this.templateRef);
}
@ -85,7 +85,7 @@ export class ModalViewDirective implements OnChanges, OnDestroy {
this.renderedView = null;
if (this.placeOnRoot) {
this.rootContainer.clear();
this.rootView.viewContainer.clear();
} else {
this.viewContainer.clear();
}

21
src/Squidex/app/framework/angular/root-view.component.ts

@ -0,0 +1,21 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Component, ViewChild, ViewContainerRef } from '@angular/core';
@Component({
selector: 'sqx-root-view',
template: `
<div #element></div>
<ng-content></ng-content>
`
})
export class RootViewComponent {
@ViewChild('element')
public viewContainer: ViewContainerRef;
}

27
src/Squidex/app/framework/angular/root-view.directive.spec.ts

@ -1,27 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { RootViewDirective } from './../';
/* tslint:disable:no-unused-expression */
describe('RootViewDirective', () => {
it('should call init of service in ctor', () => {
let viewRef = {};
let viewRefPassed: any = null;
const service = {
init: (ref: any) => {
viewRefPassed = ref;
}
};
new RootViewDirective(<any>viewRef, <any>service);
expect(viewRef).toBe(viewRefPassed);
});
});

19
src/Squidex/app/framework/angular/root-view.directive.ts

@ -1,19 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Directive, ViewContainerRef } from '@angular/core';
import { RootViewService } from './../services/root-view.service';
@Directive({
selector: '[sqxRootView]'
})
export class RootViewDirective {
constructor(public viewContainer: ViewContainerRef, rootViewService: RootViewService) {
rootViewService.init(viewContainer);
}
}

3
src/Squidex/app/framework/declarations.ts

@ -36,7 +36,7 @@ export * from './angular/panel-container.directive';
export * from './angular/parent-link.directive';
export * from './angular/popup-link.directive';
export * from './angular/progress-bar.component';
export * from './angular/root-view.directive';
export * from './angular/root-view.component';
export * from './angular/router-utils';
export * from './angular/scroll-active.directive';
export * from './angular/shortcut.component';
@ -60,7 +60,6 @@ export * from './services/local-store.service';
export * from './services/message-bus.service';
export * from './services/onboarding.service';
export * from './services/resource-loader.service';
export * from './services/root-view.service';
export * from './services/shortcut.service';
export * from './services/title.service';

8
src/Squidex/app/framework/module.ts

@ -53,8 +53,7 @@ import {
PopupLinkDirective,
ProgressBarComponent,
ResourceLoaderService,
RootViewDirective,
RootViewService,
RootViewComponent,
ScrollActiveDirective,
ShortcutComponent,
ShortcutService,
@ -115,7 +114,7 @@ import {
ParentLinkDirective,
PopupLinkDirective,
ProgressBarComponent,
RootViewDirective,
RootViewComponent,
ScrollActiveDirective,
ShortcutComponent,
ShortDatePipe,
@ -170,7 +169,7 @@ import {
PopupLinkDirective,
ProgressBarComponent,
ReactiveFormsModule,
RootViewDirective,
RootViewComponent,
ScrollActiveDirective,
ShortcutComponent,
ShortDatePipe,
@ -200,7 +199,6 @@ export class SqxFrameworkModule {
MessageBus,
OnboardingService,
ResourceLoaderService,
RootViewService,
ShortcutService,
TitleService
]

43
src/Squidex/app/framework/services/root-view.service.spec.ts

@ -1,43 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { RootViewService } from './../';
describe('RootViewService', () => {
const rootViewService = new RootViewService();
it('should call view when clearing element', () => {
let isClearCalled = false;
const viewRef = {
clear: () => {
isClearCalled = true;
}
};
rootViewService.init(<any>viewRef);
rootViewService.clear();
expect(isClearCalled).toBeTruthy();
});
it('should call view when creating element', () => {
const view = {};
const viewRef = {
createEmbeddedView: () => {
return view;
}
};
rootViewService.init(<any>viewRef);
const result = rootViewService.createEmbeddedView(<any>{});
expect(result).toBe(view);
});
});

25
src/Squidex/app/framework/services/root-view.service.ts

@ -1,25 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { EmbeddedViewRef, Injectable, TemplateRef, ViewContainerRef } from '@angular/core';
@Injectable()
export class RootViewService {
private rootView: ViewContainerRef;
public init(view: ViewContainerRef) {
this.rootView = view;
}
public createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C> {
return this.rootView.createEmbeddedView(templateRef, context, index);
}
public clear() {
this.rootView.clear();
}
}

3
src/Squidex/app/shell/pages/internal/internal-area.component.html

@ -23,6 +23,3 @@
</a>
<sqx-user-report></sqx-user-report>
<sqx-dialog-renderer></sqx-dialog-renderer>
<div sqxRootView></div>

Loading…
Cancel
Save