From 39da3daa3aa085600e2ad31968099e12ce28d2df Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 2 May 2017 20:02:21 +0200 Subject: [PATCH] Reload buttons. --- .../pages/users/users-page.component.html | 6 ++ .../pages/users/users-page.component.scss | 4 ++ .../pages/users/users-page.component.ts | 6 +- .../assets/pages/assets-page.component.html | 6 ++ .../assets/pages/assets-page.component.scss | 4 ++ .../assets/pages/assets-page.component.ts | 6 +- .../pages/content/content-page.component.ts | 2 +- .../contents/contents-page.component.html | 6 ++ .../pages/contents/contents-page.component.ts | 7 +- .../angular/image-source.directive.ts | 9 ++- .../resolve-app-languages.guard.spec.ts | 9 ++- .../guards/resolve-content.guard.spec.ts | 2 +- .../app/shared/services/schemas.service.ts | 22 +++--- .../app/shared/utils/file-helper.spec.ts | 72 +++++++++++++++++++ 14 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 src/Squidex/app/shared/utils/file-helper.spec.ts diff --git a/src/Squidex/app/features/administration/pages/users/users-page.component.html b/src/Squidex/app/features/administration/pages/users/users-page.component.html index 15d49ae4a..5e766b695 100644 --- a/src/Squidex/app/features/administration/pages/users/users-page.component.html +++ b/src/Squidex/app/features/administration/pages/users/users-page.component.html @@ -4,6 +4,12 @@
+ + + +
diff --git a/src/Squidex/app/features/administration/pages/users/users-page.component.scss b/src/Squidex/app/features/administration/pages/users/users-page.component.scss index a02bf784d..d9fb3b3e7 100644 --- a/src/Squidex/app/features/administration/pages/users/users-page.component.scss +++ b/src/Squidex/app/features/administration/pages/users/users-page.component.scss @@ -5,6 +5,10 @@ text-align: right; } +.form-inline { + display: inline-block; +} + .user { &-name, &-email { diff --git a/src/Squidex/app/features/administration/pages/users/users-page.component.ts b/src/Squidex/app/features/administration/pages/users/users-page.component.ts index 79877d0fc..053a6f92f 100644 --- a/src/Squidex/app/features/administration/pages/users/users-page.component.ts +++ b/src/Squidex/app/features/administration/pages/users/users-page.component.ts @@ -51,11 +51,15 @@ export class UsersPageComponent extends ComponentBase implements OnInit { this.load(); } - private load() { + private load(showInfo = false) { this.userManagementService.getUsers(this.usersPager.pageSize, this.usersPager.skip, this.usersQuery) .subscribe(dtos => { this.usersItems = ImmutableArray.of(dtos.items); this.usersPager = this.usersPager.setCount(dtos.total); + + if (showInfo) { + this.notifyInfo('Users reloaded.'); + } }, error => { this.notifyError(error); }); diff --git a/src/Squidex/app/features/assets/pages/assets-page.component.html b/src/Squidex/app/features/assets/pages/assets-page.component.html index c5c48b9aa..7a66fab4d 100644 --- a/src/Squidex/app/features/assets/pages/assets-page.component.html +++ b/src/Squidex/app/features/assets/pages/assets-page.component.html @@ -4,6 +4,12 @@
+ + + +
diff --git a/src/Squidex/app/features/assets/pages/assets-page.component.scss b/src/Squidex/app/features/assets/pages/assets-page.component.scss index 80feaf783..be44e4482 100644 --- a/src/Squidex/app/features/assets/pages/assets-page.component.scss +++ b/src/Squidex/app/features/assets/pages/assets-page.component.scss @@ -31,6 +31,10 @@ } } +.form-inline { + display: inline-block; +} + .btn { cursor: pointer; } diff --git a/src/Squidex/app/features/assets/pages/assets-page.component.ts b/src/Squidex/app/features/assets/pages/assets-page.component.ts index 691e44c2c..35b46d6a9 100644 --- a/src/Squidex/app/features/assets/pages/assets-page.component.ts +++ b/src/Squidex/app/features/assets/pages/assets-page.component.ts @@ -72,12 +72,16 @@ export class AssetsPageComponent extends AppComponentBase implements OnDestroy, this.load(); } - private load() { + private load(showInfo = false) { this.appName() .switchMap(app => this.assetsService.getAssets(app, this.assetsPager.pageSize, this.assetsPager.skip, this.assertQuery)) .subscribe(dtos => { this.assetsItems = ImmutableArray.of(dtos.items); this.assetsPager = this.assetsPager.setCount(dtos.total); + + if (showInfo) { + this.notifyInfo('Assets reloaded.'); + } }, error => { this.notifyError(error); }); diff --git a/src/Squidex/app/features/content/pages/content/content-page.component.ts b/src/Squidex/app/features/content/pages/content/content-page.component.ts index 0f527e064..7cd540ed0 100644 --- a/src/Squidex/app/features/content/pages/content/content-page.component.ts +++ b/src/Squidex/app/features/content/pages/content/content-page.component.ts @@ -46,7 +46,7 @@ export class ContentPageComponent extends AppComponentBase implements OnDestroy, public contentFormSubmitted = false; public contentForm: FormGroup; public contentData: any = null; - public contentId: string | undefined; + public contentId: string | null = null; public isNewMode = true; diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.html b/src/Squidex/app/features/content/pages/contents/contents-page.component.html index d41955281..1fb6d0bf9 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.html +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.html @@ -4,6 +4,12 @@
+ + + +
diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts index 5b324ea70..dcdf0b72b 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.ts +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.ts @@ -159,13 +159,16 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy } } - private load() { + private load(showInfo = false) { this.appName() .switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery)) .subscribe(dtos => { this.contentItems = ImmutableArray.of(dtos.items); - this.contentsPager = this.contentsPager.setCount(dtos.total); + + if (showInfo) { + this.notifyInfo('Contents reloaded.'); + } }, error => { this.notifyError(error); }); diff --git a/src/Squidex/app/framework/angular/image-source.directive.ts b/src/Squidex/app/framework/angular/image-source.directive.ts index ded6d2655..3ee9d722e 100644 --- a/src/Squidex/app/framework/angular/image-source.directive.ts +++ b/src/Squidex/app/framework/angular/image-source.directive.ts @@ -14,7 +14,7 @@ import { MathHelper } from './../utils/math-helper'; }) export class ImageSourceComponent implements OnChanges, OnInit, AfterViewInit { private retries = 0; - private query = MathHelper.guid(); + private query: string | null = null; @Input('sqxImageSource') public imageSource: string; @@ -32,6 +32,7 @@ export class ImageSourceComponent implements OnChanges, OnInit, AfterViewInit { } public ngOnChanges() { + this.query = null; this.retries = 0; this.setImageSource(); @@ -86,7 +87,11 @@ export class ImageSourceComponent implements OnChanges, OnInit, AfterViewInit { const h = Math.round(size.height); if (w > 0 && h > 0) { - const source = `${this.imageSource}&width=${w}&height=${h}&mode=Crop&q=${this.query}`; + let source = `${this.imageSource}&width=${w}&height=${h}&mode=Crop`; + + if (this.query !== null) { + source += `q=${this.query}`; + } this.renderer.setElementAttribute(this.element.nativeElement, 'src', source); } diff --git a/src/Squidex/app/shared/guards/resolve-app-languages.guard.spec.ts b/src/Squidex/app/shared/guards/resolve-app-languages.guard.spec.ts index 40c19615f..4fb5b8fec 100644 --- a/src/Squidex/app/shared/guards/resolve-app-languages.guard.spec.ts +++ b/src/Squidex/app/shared/guards/resolve-app-languages.guard.spec.ts @@ -15,8 +15,11 @@ import { RouterMockup } from './router-mockup'; describe('ResolveAppLanguagesGuard', () => { const route = { - params: { - appName: 'my-app' + params: { }, + parent: { + params: { + appName: 'my-app' + } } }; @@ -64,7 +67,7 @@ describe('ResolveAppLanguagesGuard', () => { }); }); - it('should return schema if loading succeeded', (done) => { + it('should return languages if loading succeeded', (done) => { const languages: AppLanguageDto[] = []; appLanguagesService.setup(x => x.getLanguages('my-app')) diff --git a/src/Squidex/app/shared/guards/resolve-content.guard.spec.ts b/src/Squidex/app/shared/guards/resolve-content.guard.spec.ts index f0ea8c9b8..9f5194319 100644 --- a/src/Squidex/app/shared/guards/resolve-content.guard.spec.ts +++ b/src/Squidex/app/shared/guards/resolve-content.guard.spec.ts @@ -74,7 +74,7 @@ describe('ResolveContentGuard', () => { }); }); - it('should return schema if loading succeeded', (done) => { + it('should return content if loading succeeded', (done) => { const schema = {}; appsStore.setup(x => x.getContent('my-app', 'my-schema', '123')) diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index fe6a7d7d7..ba29ffa1a 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -71,7 +71,7 @@ export class SchemaDto { constructor( public readonly id: string, public readonly name: string, - public readonly label: string | undefined, + public readonly label: string | null, public readonly isPublished: boolean, public readonly createdBy: string, public readonly lastModifiedBy: string, @@ -113,9 +113,9 @@ export class FieldDto { export abstract class FieldPropertiesDto { constructor( public readonly fieldType: string, - public readonly label: string | undefined, - public readonly hints: string | undefined, - public readonly placeholder: string | undefined, + public readonly label: string | null, + public readonly hints: string | null, + public readonly placeholder: string | null, public readonly isRequired: boolean, public readonly isListField: boolean, public readonly isLocalizable: boolean @@ -124,7 +124,7 @@ export abstract class FieldPropertiesDto { } export class StringFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean, @@ -141,7 +141,7 @@ export class StringFieldPropertiesDto extends FieldPropertiesDto { } export class NumberFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean, @@ -156,7 +156,7 @@ export class NumberFieldPropertiesDto extends FieldPropertiesDto { } export class DateTimeFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean, @@ -171,7 +171,7 @@ export class DateTimeFieldPropertiesDto extends FieldPropertiesDto { } export class BooleanFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean, @@ -183,7 +183,7 @@ export class BooleanFieldPropertiesDto extends FieldPropertiesDto { } export class GeolocationFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean, @@ -194,7 +194,7 @@ export class GeolocationFieldPropertiesDto extends FieldPropertiesDto { } export class AssetsFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean @@ -204,7 +204,7 @@ export class AssetsFieldPropertiesDto extends FieldPropertiesDto { } export class JsonFieldPropertiesDto extends FieldPropertiesDto { - constructor(label: string | undefined, hints: string | undefined, placeholder: string | undefined, + constructor(label: string | null, hints: string | null, placeholder: string | null, isRequired: boolean, isListField: boolean, isLocalizable: boolean diff --git a/src/Squidex/app/shared/utils/file-helper.spec.ts b/src/Squidex/app/shared/utils/file-helper.spec.ts new file mode 100644 index 000000000..b21302c69 --- /dev/null +++ b/src/Squidex/app/shared/utils/file-helper.spec.ts @@ -0,0 +1,72 @@ +/* + * Squidex Headless CMS + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved + */ + +import { ApiUrlConfig, Version } from 'framework'; + +import { FileHelper } from './file-helper'; +import { AssetDto } from './../services/assets.service'; + +describe('FileHelper', () => { + it('should calculate correct human file size', () => { + expect(FileHelper.fileSize(50)).toBe('50 B'); + expect(FileHelper.fileSize(1024)).toBe('1.0 kB'); + expect(FileHelper.fileSize(1260000)).toBe('1.2 MB'); + }); + + it('should calculate icon', () => { + expect(FileHelper.fileIcon('video/mp4')).toBe('/images/asset_video.png'); + expect(FileHelper.fileIcon('application/text')).toBe('/images/asset_generic.png'); + expect(FileHelper.fileIcon('application/msword')).toBe('/images/asset_doc.png'); + }); + + it('should calculate file type', () => { + expect(FileHelper.fileType('video/mp4', 'test.mp4')).toBe('mp4'); + expect(FileHelper.fileType('video/mp4', undefined)).toBe('mp4'); + expect(FileHelper.fileType('application/text', 'test.txt')).toBe('txt'); + expect(FileHelper.fileType('application/text', undefined)).toBe('text'); + + expect(FileHelper.fileType('invalid', undefined)).toBeUndefined(); + expect(FileHelper.fileType(undefined, undefined)).toBeUndefined(); + }); + + it('should calculate asset info for image asset', () => { + const asset = new AssetDto('1', undefined, undefined, undefined, undefined, 'File.png', 50, 1, 'image/png', true, 100, 20, undefined); + + expect(FileHelper.assetInfo(asset)).toBe('100x20px, 50 B'); + }); + + it('should calculate asset info for text asset', () => { + const asset = new AssetDto('1', undefined, undefined, undefined, undefined, 'File.txt', 50, 1, 'text/plain', false, 0, 0, undefined); + + expect(FileHelper.assetInfo(asset)).toBe('50 B'); + }); + + it('should return empty string for invalid asset', () => { + expect(FileHelper.assetInfo(undefined)).toBe(''); + expect(FileHelper.assetInfo(null)).toBe(''); + }); + + it('should return asset name', () => { + const asset = new AssetDto('1', undefined, undefined, undefined, undefined, 'File.txt', 50, 1, 'text/plain', false, 0, 0, undefined); + + expect(FileHelper.assetName(asset)).toBe('File.txt'); + }); + + it('should return preview url', () => { + const apiUrl = new ApiUrlConfig('my/'); + const asset = new AssetDto('1', undefined, undefined, undefined, undefined, 'File.txt', 50, 1, 'text/plain', false, 0, 0, new Version('123')); + + expect(FileHelper.assetPreviewUrl(apiUrl, asset)).toBe('my/api/assets/1?version=123'); + }); + + it('should return download url', () => { + const apiUrl = new ApiUrlConfig('my/'); + const asset = new AssetDto('1', undefined, undefined, undefined, undefined, 'File.txt', 50, 1, 'text/plain', false, 0, 0, new Version('123')); + + expect(FileHelper.assetUrl(apiUrl, asset).startsWith('my/api/assets/1?q=')).toBeTruthy(); + }); +}); \ No newline at end of file