From 31db70980e78daffa3d5ddea6f8ec0a983f7a17e Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sat, 2 Dec 2017 20:01:57 +0100 Subject: [PATCH] RX error fixed. --- ...Squidex.Domain.Apps.Core.Operations.csproj | 4 +- src/Squidex/Squidex.csproj | 4 +- src/Squidex/app-config/webpack.run.prod.js | 4 +- .../angular/http-extensions-impl.spec.ts | 40 +++++++++++++ .../framework/angular/http-extensions-impl.ts | 32 +++++++---- .../app/framework/angular/sorted.directive.ts | 36 ++++++------ .../app/shared/components/app-context.ts | 2 +- .../shared/components/app-form.component.html | 4 +- .../guards/must-be-authenticated.guard.ts | 2 +- .../guards/must-be-not-authenticated.guard.ts | 2 +- .../shared/interceptors/auth.interceptor.ts | 2 +- .../app/shared/services/apps-store.service.ts | 2 +- src/Squidex/app/theme/_forms.scss | 4 ++ src/Squidex/package.json | 56 +++++++++---------- 14 files changed, 125 insertions(+), 69 deletions(-) create mode 100644 src/Squidex/app/framework/angular/http-extensions-impl.spec.ts diff --git a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index e57722909..bd76d3726 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -13,10 +13,10 @@ - + - + diff --git a/src/Squidex/Squidex.csproj b/src/Squidex/Squidex.csproj index 6af8f926a..ebc86a383 100644 --- a/src/Squidex/Squidex.csproj +++ b/src/Squidex/Squidex.csproj @@ -68,9 +68,9 @@ - + - + diff --git a/src/Squidex/app-config/webpack.run.prod.js b/src/Squidex/app-config/webpack.run.prod.js index d68d2ff22..d5f989ab5 100644 --- a/src/Squidex/app-config/webpack.run.prod.js +++ b/src/Squidex/app-config/webpack.run.prod.js @@ -1,7 +1,7 @@  var webpack = require('webpack'), webpackMerge = require('webpack-merge'), ExtractTextPlugin = require('extract-text-webpack-plugin'), - AotPlugin = require('@ngtools/webpack').AotPlugin, + ngToolsWebpack = require('@ngtools/webpack'), runConfig = require('./webpack.run.base.js'), helpers = require('./helpers'); @@ -105,7 +105,7 @@ module.exports = webpackMerge(runConfig, { comments: false }), - new AotPlugin({ + new ngToolsWebpack.AngularCompilerPlugin({ tsConfigPath: './tsconfig.json', entryModule: 'app/app.module#AppModule' }), diff --git a/src/Squidex/app/framework/angular/http-extensions-impl.spec.ts b/src/Squidex/app/framework/angular/http-extensions-impl.spec.ts new file mode 100644 index 000000000..7db932c5d --- /dev/null +++ b/src/Squidex/app/framework/angular/http-extensions-impl.spec.ts @@ -0,0 +1,40 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. 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.
  • Detail1.
  • Detail2.
'); + }); +}); \ No newline at end of file diff --git a/src/Squidex/app/framework/angular/http-extensions-impl.ts b/src/Squidex/app/framework/angular/http-extensions-impl.ts index ae3aba1a4..b8dcc9bcc 100644 --- a/src/Squidex/app/framework/angular/http-extensions-impl.ts +++ b/src/Squidex/app/framework/angular/http-extensions-impl.ts @@ -19,29 +19,41 @@ export class Versioned { } function formatMessage(message: string, details?: string[]) { - const format = (row: string) => { + const appendLast = (row: string, char: string) => { const last = row[row.length - 1]; - if (last !== '.') { - return row + '.'; + if (last !== char) { + return row + char; } else { return row; } }; - let result = format(message); + const removeLast = (row: string, char: string) => { + const last = row[row.length - 1]; + + if (last === char) { + return row.substr(0, row.length - 1); + } else { + return row; + } + }; - if (details) { - result = result + '
    '; + if (details && details.length > 1) { + let result = appendLast(message, '.') + '
      '; - for (let d of details) { - result += `
    • ${format(d)}
    • `; + for (let detail of details) { + result += `
    • ${appendLast(detail, '.')}
    • `; } result = result + '
    '; - } - return result; + return result; + } else if (details && details.length === 1) { + return `${appendLast(removeLast(message, '.'), ':')} ${appendLast(details[0], '.')}`; + } else { + return appendLast(message, '.'); + } } export class ErrorDto { diff --git a/src/Squidex/app/framework/angular/sorted.directive.ts b/src/Squidex/app/framework/angular/sorted.directive.ts index 36e041d8f..56f9d0c7b 100644 --- a/src/Squidex/app/framework/angular/sorted.directive.ts +++ b/src/Squidex/app/framework/angular/sorted.directive.ts @@ -30,30 +30,32 @@ export class SortedDirective { ) { const oldDragStartCallback = sortableComponent._onDragStartCallback.bind(sortableComponent); - sortableComponent._onDragStartCallback = () => { - oldDragStartCallback(); + if (Array.isArray(sortableContainer.sortableData)) { + sortableComponent._onDragStartCallback = () => { + oldDragStartCallback(); - this.oldArray = [...sortableContainer.sortableData]; - }; + this.oldArray = [...sortableContainer.sortableData]; + }; - const oldDropCallback = sortableComponent._onDropCallback.bind(sortableComponent); + const oldDropCallback = sortableComponent._onDropCallback.bind(sortableComponent); - sortableComponent._onDropCallback = (event: Event) => { - oldDropCallback(event); + sortableComponent._onDropCallback = (event: Event) => { + oldDropCallback(event); - if (sortableDragDropService.isDragged) { - const newArray = sortableContainer.sortableData; - const oldArray = this.oldArray; + if (sortableDragDropService.isDragged) { + const newArray: any[] = sortableContainer.sortableData; + const oldArray = this.oldArray; - if (newArray && oldArray && newArray.length === oldArray.length) { - for (let i = 0; i < oldArray.length; i++) { - if (oldArray[i] !== newArray[i]) { - this.sorted.emit(newArray); - break; + if (newArray && oldArray && newArray.length === oldArray.length) { + for (let i = 0; i < oldArray.length; i++) { + if (oldArray[i] !== newArray[i]) { + this.sorted.emit(newArray); + break; + } } } } - } - }; + }; + } } } diff --git a/src/Squidex/app/shared/components/app-context.ts b/src/Squidex/app/shared/components/app-context.ts index 00dc8f9b5..bee564796 100644 --- a/src/Squidex/app/shared/components/app-context.ts +++ b/src/Squidex/app/shared/components/app-context.ts @@ -58,7 +58,7 @@ export class AppContext implements OnDestroy { public readonly bus: MessageBus ) { this.appSubscription = - this.appsStore.selectedApp.first().subscribe(app => { + this.appsStore.selectedApp.take(1).subscribe(app => { this.appField = app; }); } diff --git a/src/Squidex/app/shared/components/app-form.component.html b/src/Squidex/app/shared/components/app-form.component.html index 112e1a648..18c17a752 100644 --- a/src/Squidex/app/shared/components/app-form.component.html +++ b/src/Squidex/app/shared/components/app-form.component.html @@ -1,8 +1,6 @@
    -
    - {{createFormError}} -
    +
    diff --git a/src/Squidex/app/shared/guards/must-be-authenticated.guard.ts b/src/Squidex/app/shared/guards/must-be-authenticated.guard.ts index 95edea329..c6109a6c9 100644 --- a/src/Squidex/app/shared/guards/must-be-authenticated.guard.ts +++ b/src/Squidex/app/shared/guards/must-be-authenticated.guard.ts @@ -20,7 +20,7 @@ export class MustBeAuthenticatedGuard implements CanActivate { } public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return this.authService.userChanges.first() + return this.authService.userChanges.take(1) .do(user => { if (!user) { this.router.navigate(['']); diff --git a/src/Squidex/app/shared/guards/must-be-not-authenticated.guard.ts b/src/Squidex/app/shared/guards/must-be-not-authenticated.guard.ts index 9f11076e8..9d7557f45 100644 --- a/src/Squidex/app/shared/guards/must-be-not-authenticated.guard.ts +++ b/src/Squidex/app/shared/guards/must-be-not-authenticated.guard.ts @@ -20,7 +20,7 @@ export class MustBeNotAuthenticatedGuard implements CanActivate { } public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return this.authService.userChanges.first() + return this.authService.userChanges.take(1) .do(user => { if (user) { this.router.navigate(['app']); diff --git a/src/Squidex/app/shared/interceptors/auth.interceptor.ts b/src/Squidex/app/shared/interceptors/auth.interceptor.ts index 860f142fb..fd37bfe10 100644 --- a/src/Squidex/app/shared/interceptors/auth.interceptor.ts +++ b/src/Squidex/app/shared/interceptors/auth.interceptor.ts @@ -24,7 +24,7 @@ export class AuthInterceptor implements HttpInterceptor { public intercept(req: HttpRequest, next: HttpHandler): Observable> { if (req.url.indexOf(this.baseUrl) === 0 && !req.headers.has('NoAuth')) { - return this.authService.userChanges.first().switchMap(user => { + return this.authService.userChanges.take(1).switchMap(user => { return this.makeRequest(req, next, user, true); }); } else { diff --git a/src/Squidex/app/shared/services/apps-store.service.ts b/src/Squidex/app/shared/services/apps-store.service.ts index f9590f77c..4ef9fe436 100644 --- a/src/Squidex/app/shared/services/apps-store.service.ts +++ b/src/Squidex/app/shared/services/apps-store.service.ts @@ -62,7 +62,7 @@ export class AppsStoreService { public createApp(dto: CreateAppDto, now?: DateTime): Observable { return this.appsService.postApp(dto) .do(app => { - this.apps$.first().subscribe(apps => { + this.apps$.take(1).subscribe(apps => { this.apps$.next(apps.concat([app])); }); }); diff --git a/src/Squidex/app/theme/_forms.scss b/src/Squidex/app/theme/_forms.scss index c6507c14a..4f4f1f5b1 100644 --- a/src/Squidex/app/theme/_forms.scss +++ b/src/Squidex/app/theme/_forms.scss @@ -82,6 +82,10 @@ &-success { background: $color-theme-green-dark; } + + ul { + margin: 0; + } } // diff --git a/src/Squidex/package.json b/src/Squidex/package.json index 88402f9ea..8ea7b3e2b 100644 --- a/src/Squidex/package.json +++ b/src/Squidex/package.json @@ -8,52 +8,52 @@ "test": "karma start", "test:coverage": "karma start karma.coverage.conf.js", "test:clean": "rimraf _test-output", - "dev": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ & cpx node_modules/redoc/dist/redoc.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000", + "dev": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/ && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000", "build": "webpack --config app-config/webpack.run.prod.js --display-error-details --bail", "build:nobail": "webpack --config app-config/webpack.run.prod.js --display-error-details", "build:copy": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/", "build:clean": "rimraf wwwroot/build" }, "dependencies": { - "@angular/animations": "4.4.6", - "@angular/common": "4.4.6", - "@angular/compiler": "4.4.6", - "@angular/core": "4.4.6", - "@angular/forms": "4.4.6", - "@angular/http": "4.4.6", - "@angular/platform-browser": "4.4.6", - "@angular/platform-browser-dynamic": "4.4.6", - "@angular/platform-server": "4.4.6", - "@angular/router": "4.4.6", - "angular2-chartjs": "0.3.0", + "@angular/animations": "5.0.5", + "@angular/common": "5.0.5", + "@angular/compiler": "5.0.5", + "@angular/core": "5.0.5", + "@angular/forms": "5.0.5", + "@angular/http": "5.0.5", + "@angular/platform-browser": "5.0.5", + "@angular/platform-browser-dynamic": "5.0.5", + "@angular/platform-server": "5.0.5", + "@angular/router": "5.0.5", + "angular2-chartjs": "0.4.1", "babel-polyfill": "6.26.0", "bootstrap": "4.0.0-alpha.6", "core-js": "2.5.1", "graphiql": "0.11.10", - "moment": "2.19.1", + "moment": "2.19.3", "mousetrap": "1.6.1", - "ng2-dnd": "4.2.0", + "ng2-dnd": "5.0.2", "oidc-client": "1.4.1", "pikaday": "1.6.1", "progressbar.js": "1.0.1", - "react": "16.0.0", - "react-dom": "16.0.0", + "react": "16.2.0", + "react-dom": "16.2.0", "rxjs": "5.5.2", "zone.js": "0.8.18" }, "devDependencies": { - "@angular/compiler-cli": "4.4.6", - "@angular/tsc-wrapped": "4.4.6", - "@ngtools/webpack": "1.7.2", + "@angular/compiler": "5.0.5", + "@angular/compiler-cli": "5.0.5", + "@ngtools/webpack": "1.8.5", "@types/core-js": "0.9.35", "@types/jasmine": "2.5.45", "@types/mousetrap": "1.5.34", "@types/node": "7.0.5", - "@types/react": "15.6.4", - "@types/react-dom": "15.5.6", + "@types/react": "16.0.25", + "@types/react-dom": "16.0.3", "angular2-router-loader": "0.3.5", "angular2-template-loader": "0.6.2", - "awesome-typescript-loader": "3.3.0", + "awesome-typescript-loader": "3.4.1", "codelyzer": "4.0.1", "cpx": "1.5.0", "css-loader": "0.28.7", @@ -70,13 +70,13 @@ "karma-cli": "1.0.1", "karma-coverage": "1.1.1", "karma-htmlfile-reporter": "0.3.5", - "karma-jasmine": "1.1.0", + "karma-jasmine": "1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "karma-mocha-reporter": "2.2.5", "karma-phantomjs-launcher": "1.0.4", "karma-sourcemap-loader": "0.3.7", - "karma-webpack": "2.0.5", - "node-sass": "4.5.3", + "karma-webpack": "2.0.6", + "node-sass": "4.7.2", "noop-loader": "^1.0.0", "null-loader": "0.1.1", "phantomjs-prebuilt": "2.1.16", @@ -88,10 +88,10 @@ "tslint": "5.8.0", "tslint-loader": "3.5.3", "typemoq": "2.1.0", - "typescript": "2.5.3", + "typescript": "2.4.2", "underscore": "1.8.3", - "webpack": "3.8.1", - "webpack-dev-server": "2.9.4", + "webpack": "3.9.1", + "webpack-dev-server": "2.9.5", "webpack-merge": "4.1.1" } }