From 6d9597f9ea6eacb0eb2a5d74f301c139643f46e7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Oct 2020 12:12:04 +0200 Subject: [PATCH 1/5] Fix spelling errors. --- backend/i18n/frontend_en.json | 8 ++++---- backend/i18n/frontend_it.json | 8 ++++---- backend/i18n/frontend_nl.json | 8 ++++---- backend/i18n/source/backend_en.json | 2 +- backend/i18n/source/backend_it.json | 2 +- backend/i18n/source/backend_nl.json | 2 +- backend/i18n/source/frontend_en.json | 8 ++++---- backend/i18n/source/frontend_it.json | 8 ++++---- backend/i18n/source/frontend_nl.json | 8 ++++---- .../Apps/AppDomainObject.cs | 2 +- backend/src/Squidex.Shared/Texts.it.resx | 2 +- backend/src/Squidex.Shared/Texts.nl.resx | 2 +- backend/src/Squidex.Shared/Texts.resx | 2 +- .../schema/common/schema-edit-form.component.html | 2 +- .../settings/pages/more/more-page.component.html | 10 +++++----- .../features/settings/pages/roles/role.component.html | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/backend/i18n/frontend_en.json b/backend/i18n/frontend_en.json index c5655d7a0..0d6294d72 100644 --- a/backend/i18n/frontend_en.json +++ b/backend/i18n/frontend_en.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "The app name cannot be changed later.", "apps.appsButtonCreate": "Apps Overview", "apps.appsButtonFallbackTitle": "Apps Overview", - "apps.archieve": "Archive App", - "apps.archieveConfirmText": "Remove pattern", - "apps.archieveConfirmTitle": "Do you really want to archive this app?", - "apps.archieveWarning": "Once you archive an app, there is no going back. Please be certain.", + "apps.archive": "Archive App", + "apps.archiveConfirmText": "Do you really want to archive this app?", + "apps.archiveConfirmTitle": "Archive App", "apps.archiveFailed": "Failed to archive app. Please reload.", + "apps.archiveWarning": "Once you archive an app, there is no going back. Please be certain.", "apps.create": "Create App", "apps.createBlankApp": "New App.", "apps.createBlankAppDescription": "Create a new blank app without content and schemas.", diff --git a/backend/i18n/frontend_it.json b/backend/i18n/frontend_it.json index 4176a6bf6..9911e7aab 100644 --- a/backend/i18n/frontend_it.json +++ b/backend/i18n/frontend_it.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "Il nome della app non potrà essere cambiato in un secondo momento.", "apps.appsButtonCreate": "Nuova App", "apps.appsButtonFallbackTitle": "Lista App", - "apps.archieve": "Archivia l'App", - "apps.archieveConfirmText": "Rimuovi il pattern", - "apps.archieveConfirmTitle": "Sei sicuro di voler archiviare questa app?", - "apps.archieveWarning": "Una volta archiviata una App, non è possibile tornare indietro. Sii certo.", + "apps.archive": "Archivia l'App", + "apps.archiveConfirmText": "Rimuovi il pattern", + "apps.archiveConfirmTitle": "Sei sicuro di voler archiviare questa app?", "apps.archiveFailed": "Non è stato possibile archiviare l'app. Per favore ricarica.", + "apps.archiveWarning": "Una volta archiviata una App, non è possibile tornare indietro. Sii certo.", "apps.create": "Crea un'App", "apps.createBlankApp": "Nuova App.", "apps.createBlankAppDescription": "Crea una app vuota senza contenuti o schema.", diff --git a/backend/i18n/frontend_nl.json b/backend/i18n/frontend_nl.json index a90523bcb..bc87bc775 100644 --- a/backend/i18n/frontend_nl.json +++ b/backend/i18n/frontend_nl.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "De app-naam kan later niet worden gewijzigd.", "apps.appsButtonCreate": "Apps-overzicht", "apps.appsButtonFallbackTitle": "Apps-overzicht", - "apps.archieve": "App archiveren", - "apps.archieveConfirmText": "Patroon verwijderen", - "apps.archieveConfirmTitle": "Wil je deze app echt archiveren?", - "apps.archieveWarning": "Zodra je een app archiveert, is er geen weg meer terug. Wees alsjeblieft zeker.", + "apps.archive": "App archiveren", + "apps.archiveConfirmText": "Patroon verwijderen", + "apps.archiveConfirmTitle": "Wil je deze app echt archiveren?", "apps.archiveFailed": "Kan app niet archiveren. Laad opnieuw.", + "apps.archiveWarning": "Zodra je een app archiveert, is er geen weg meer terug. Wees alsjeblieft zeker.", "apps.create": "App maken", "apps.createBlankApp": "Nieuwe app.", "apps.createBlankAppDescription": "Maak een nieuwe lege app zonder inhoud en schema's.", diff --git a/backend/i18n/source/backend_en.json b/backend/i18n/source/backend_en.json index 4d6b3dd2c..0f2d5dd4d 100644 --- a/backend/i18n/source/backend_en.json +++ b/backend/i18n/source/backend_en.json @@ -7,7 +7,7 @@ "annotations_Required": "The field {name|lower} is required.", "annotations_StringLength": "The field {name|lower} must be a string with a maximum length of {max}.", "annotations_StringLengthMinimum": "The field {name|lower} must be a string with a minimum length of {min} and a maximum length of {max}.", - "apps.alreadyArchieved": "App has already been archived.", + "apps.alreadyArchived": "App has already been archived.", "apps.clients.idAlreadyExists": "A client with the same id already exists.", "apps.contributors.cannotChangeYourself": "You cannot change your own role.", "apps.contributors.maxReached": "You have reached the maximum number of contributors for your plan.", diff --git a/backend/i18n/source/backend_it.json b/backend/i18n/source/backend_it.json index 5c7236d20..14b48d178 100644 --- a/backend/i18n/source/backend_it.json +++ b/backend/i18n/source/backend_it.json @@ -7,7 +7,7 @@ "annotations_Required": "Il campo è {name|lower} obbligatorio.", "annotations_StringLength": "The field {name|lower} must be a string with a maximum length of {max}.", "annotations_StringLengthMinimum": "The field {name|lower} must be a string with a minimum length of {min} and a maximum length of {max}.", - "apps.alreadyArchieved": "La App è stata già archiviata.", + "apps.alreadyArchived": "La App è stata già archiviata.", "apps.clients.idAlreadyExists": "Un client con lo stesso id esiste già.", "apps.contributors.cannotChangeYourself": "Non puoi cambiare il tuo ruolo.", "apps.contributors.maxReached": "Hai raggiunto il numero massimo di contributori previsto per il tuo piano.", diff --git a/backend/i18n/source/backend_nl.json b/backend/i18n/source/backend_nl.json index 40a9745d2..33c3ab800 100644 --- a/backend/i18n/source/backend_nl.json +++ b/backend/i18n/source/backend_nl.json @@ -7,7 +7,7 @@ "annotations_Required": "Het veld {name|lower} is verplicht.", "annotations_StringLength": "Het veld {name|lower} moet een string zijn met een maximale lengte van {max}.", "annotations_StringLengthMinimum": "Het veld {name|lower} moet een string zijn met een minimum lengte van {min} en een maximum lengte van {max}.", - "apps.alreadyArchieved": "App is al gearchiveerd.", + "apps.alreadyArchived": "App is al gearchiveerd.", "apps.clients.idAlreadyExists": "Er bestaat al een client met dezelfde id.", "apps.contributors.cannotChangeYourself": "Je kunt jouw eigen rol niet wijzigen.", "apps.contributors.maxReached": "Je heeft het maximale aantal bijdragers voor jouw plan bereikt.", diff --git a/backend/i18n/source/frontend_en.json b/backend/i18n/source/frontend_en.json index c5655d7a0..0d6294d72 100644 --- a/backend/i18n/source/frontend_en.json +++ b/backend/i18n/source/frontend_en.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "The app name cannot be changed later.", "apps.appsButtonCreate": "Apps Overview", "apps.appsButtonFallbackTitle": "Apps Overview", - "apps.archieve": "Archive App", - "apps.archieveConfirmText": "Remove pattern", - "apps.archieveConfirmTitle": "Do you really want to archive this app?", - "apps.archieveWarning": "Once you archive an app, there is no going back. Please be certain.", + "apps.archive": "Archive App", + "apps.archiveConfirmText": "Do you really want to archive this app?", + "apps.archiveConfirmTitle": "Archive App", "apps.archiveFailed": "Failed to archive app. Please reload.", + "apps.archiveWarning": "Once you archive an app, there is no going back. Please be certain.", "apps.create": "Create App", "apps.createBlankApp": "New App.", "apps.createBlankAppDescription": "Create a new blank app without content and schemas.", diff --git a/backend/i18n/source/frontend_it.json b/backend/i18n/source/frontend_it.json index a7db499d6..5277abf10 100644 --- a/backend/i18n/source/frontend_it.json +++ b/backend/i18n/source/frontend_it.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "Il nome della app non potrà essere cambiato in un secondo momento.", "apps.appsButtonCreate": "Nuova App", "apps.appsButtonFallbackTitle": "Lista App", - "apps.archieve": "Archivia l'App", - "apps.archieveConfirmText": "Rimuovi il pattern", - "apps.archieveConfirmTitle": "Sei sicuro di voler archiviare questa app?", - "apps.archieveWarning": "Una volta archiviata una App, non è possibile tornare indietro. Sii certo.", + "apps.archive": "Archivia l'App", + "apps.archiveConfirmText": "Rimuovi il pattern", + "apps.archiveConfirmTitle": "Sei sicuro di voler archiviare questa app?", "apps.archiveFailed": "Non è stato possibile archiviare l'app. Per favore ricarica.", + "apps.archiveWarning": "Una volta archiviata una App, non è possibile tornare indietro. Sii certo.", "apps.create": "Crea un'App", "apps.createBlankApp": "Nuova App.", "apps.createBlankAppDescription": "Crea una app vuota senza contenuti o schema.", diff --git a/backend/i18n/source/frontend_nl.json b/backend/i18n/source/frontend_nl.json index 4f0afdfb9..5ab379cad 100644 --- a/backend/i18n/source/frontend_nl.json +++ b/backend/i18n/source/frontend_nl.json @@ -12,11 +12,11 @@ "apps.appNameWarning": "De app-naam kan later niet worden gewijzigd.", "apps.appsButtonCreate": "Apps-overzicht", "apps.appsButtonFallbackTitle": "Apps-overzicht", - "apps.archieve": "App archiveren", - "apps.archieveConfirmText": "Patroon verwijderen", - "apps.archieveConfirmTitle": "Wil je deze app echt archiveren?", - "apps.archieveWarning": "Zodra je een app archiveert, is er geen weg meer terug. Wees alsjeblieft zeker.", + "apps.archive": "App archiveren", + "apps.archiveConfirmText": "Patroon verwijderen", + "apps.archiveConfirmTitle": "Wil je deze app echt archiveren?", "apps.archiveFailed": "Kan app niet archiveren. Laad opnieuw.", + "apps.archiveWarning": "Zodra je een app archiveert, is er geen weg meer terug. Wees alsjeblieft zeker.", "apps.create": "App maken", "apps.createBlankApp": "Nieuwe app.", "apps.createBlankAppDescription": "Maak een nieuwe lege app zonder inhoud en schema's.", diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs index 898a7db95..b1351b07b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs @@ -461,7 +461,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { if (Snapshot.IsArchived) { - throw new DomainException(T.Get("apps.alreadyArchieved")); + throw new DomainException(T.Get("apps.alreadyArchived")); } } diff --git a/backend/src/Squidex.Shared/Texts.it.resx b/backend/src/Squidex.Shared/Texts.it.resx index 3f0baa6ef..6ea7f0a30 100644 --- a/backend/src/Squidex.Shared/Texts.it.resx +++ b/backend/src/Squidex.Shared/Texts.it.resx @@ -106,7 +106,7 @@ The field {0} must be a string with a minimum length of {1} and a maximum length of {2}. - + La App è stata già archiviata. diff --git a/backend/src/Squidex.Shared/Texts.nl.resx b/backend/src/Squidex.Shared/Texts.nl.resx index 3dd42d21f..10a62710a 100644 --- a/backend/src/Squidex.Shared/Texts.nl.resx +++ b/backend/src/Squidex.Shared/Texts.nl.resx @@ -106,7 +106,7 @@ Het veld {0} moet een string zijn met een minimum lengte van {1} en een maximum lengte van {2}. - + App is al gearchiveerd. diff --git a/backend/src/Squidex.Shared/Texts.resx b/backend/src/Squidex.Shared/Texts.resx index 3d7c7e09f..7526025c7 100644 --- a/backend/src/Squidex.Shared/Texts.resx +++ b/backend/src/Squidex.Shared/Texts.resx @@ -106,7 +106,7 @@ The field {0} must be a string with a minimum length of {1} and a maximum length of {2}. - + App has already been archived. diff --git a/frontend/app/features/schemas/pages/schema/common/schema-edit-form.component.html b/frontend/app/features/schemas/pages/schema/common/schema-edit-form.component.html index 4f014effe..67074d7cd 100644 --- a/frontend/app/features/schemas/pages/schema/common/schema-edit-form.component.html +++ b/frontend/app/features/schemas/pages/schema/common/schema-edit-form.component.html @@ -37,7 +37,7 @@ - {{ 'schemas.contentsSidebarUrl' | sqxTranslate }} + {{ 'schemas.contentsSidebarUrlHint' | sqxTranslate }}
diff --git a/frontend/app/features/settings/pages/more/more-page.component.html b/frontend/app/features/settings/pages/more/more-page.component.html index 408f9e91f..09ee2551a 100644 --- a/frontend/app/features/settings/pages/more/more-page.component.html +++ b/frontend/app/features/settings/pages/more/more-page.component.html @@ -90,18 +90,18 @@
-
{{ 'apps.archieve' | sqxTranslate }}
+
{{ 'apps.archive' | sqxTranslate }}
- {{ 'apps.archieveWarning' | sqxTranslate }} + {{ 'apps.archiveWarning' | sqxTranslate }}
diff --git a/frontend/app/features/settings/pages/roles/role.component.html b/frontend/app/features/settings/pages/roles/role.component.html index e50a25b6c..21f0efdc9 100644 --- a/frontend/app/features/settings/pages/roles/role.component.html +++ b/frontend/app/features/settings/pages/roles/role.component.html @@ -81,7 +81,7 @@
+ placeholder="{{ 'roles.permissionsPlaceholder' | sqxTranslate }}">
From f4687c01a8e12a16432d00369c6a2f88c547ef24 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Oct 2020 14:01:28 +0200 Subject: [PATCH 2/5] Middleware fix. --- .../Frontend/Middlewares/IndexExtensions.cs | 20 +++++++------ .../Frontend/Middlewares/IndexMiddleware.cs | 11 ++++++-- .../Frontend/Middlewares/WebpackMiddleware.cs | 28 ++----------------- backend/src/Squidex/Areas/Frontend/Startup.cs | 6 ++-- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/backend/src/Squidex/Areas/Frontend/Middlewares/IndexExtensions.cs b/backend/src/Squidex/Areas/Frontend/Middlewares/IndexExtensions.cs index 60c709362..c4ae98280 100644 --- a/backend/src/Squidex/Areas/Frontend/Middlewares/IndexExtensions.cs +++ b/backend/src/Squidex/Areas/Frontend/Middlewares/IndexExtensions.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Concurrent; using System.Globalization; using System.IO; +using System.Net; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -33,20 +34,23 @@ namespace Squidex.Areas.Frontend.Middlewares return context.Request.Path.Value.EndsWith(".html", StringComparison.OrdinalIgnoreCase); } - public static bool IsHtml(this HttpContext context) + public static bool IsNotModified(this HttpResponse response) { - return context.Response.ContentType?.ToLower().Contains("text/html") == true; + return response.StatusCode == (int)HttpStatusCode.NotModified; } - public static string AdjustHtml(this string html, HttpContext httpContext) + public static string AdjustBase(this string html, HttpContext httpContext) { - var result = html; - if (httpContext.Request.PathBase.HasValue) { - result = result.Replace("", $""); + html = html.Replace("", $""); } + return html; + } + + public static string AddOptions(this string html, HttpContext httpContext) + { var uiOptions = httpContext.RequestServices.GetService>()?.Value; if (uiOptions != null) @@ -72,10 +76,10 @@ namespace Squidex.Areas.Frontend.Middlewares var texts = GetText(CultureInfo.CurrentUICulture.Name); - result = result.Replace("", $"\n"); + html = html.Replace("", $"\n"); } - return result; + return html; } private static string GetText(string culture) diff --git a/backend/src/Squidex/Areas/Frontend/Middlewares/IndexMiddleware.cs b/backend/src/Squidex/Areas/Frontend/Middlewares/IndexMiddleware.cs index 4ba2db152..25c055be7 100644 --- a/backend/src/Squidex/Areas/Frontend/Middlewares/IndexMiddleware.cs +++ b/backend/src/Squidex/Areas/Frontend/Middlewares/IndexMiddleware.cs @@ -23,7 +23,7 @@ namespace Squidex.Areas.Frontend.Middlewares public async Task InvokeAsync(HttpContext context) { - if (context.IsHtmlPath() && context.Response.StatusCode != 304) + if (context.IsHtmlPath() && !context.Response.IsNotModified()) { var responseBuffer = new MemoryStream(); var responseBody = context.Response.Body; @@ -32,13 +32,18 @@ namespace Squidex.Areas.Frontend.Middlewares await next(context); - if (context.Response.StatusCode != 304) + if (!context.Response.IsNotModified()) { context.Response.Body = responseBody; var html = Encoding.UTF8.GetString(responseBuffer.ToArray()); - html = html.AdjustHtml(context); + html = html.AdjustBase(context); + + if (context.IsIndex()) + { + html = html.AddOptions(context); + } context.Response.ContentLength = Encoding.UTF8.GetByteCount(html); context.Response.Body = responseBody; diff --git a/backend/src/Squidex/Areas/Frontend/Middlewares/WebpackMiddleware.cs b/backend/src/Squidex/Areas/Frontend/Middlewares/WebpackMiddleware.cs index 7d2ac538c..694167c1f 100644 --- a/backend/src/Squidex/Areas/Frontend/Middlewares/WebpackMiddleware.cs +++ b/backend/src/Squidex/Areas/Frontend/Middlewares/WebpackMiddleware.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.IO; +using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -26,7 +27,7 @@ namespace Squidex.Areas.Frontend.Middlewares public async Task InvokeAsync(HttpContext context) { - if (context.IsIndex() && context.Response.StatusCode != 304) + if (context.IsIndex() && !context.Response.IsNotModified()) { var handler = new HttpClientHandler { @@ -43,35 +44,12 @@ namespace Squidex.Areas.Frontend.Middlewares { var html = await result.Content.ReadAsStringAsync(); - html = html.AdjustHtml(context); + html = html.AdjustBase(context); await context.Response.WriteAsync(html); } } } - else if (context.IsHtmlPath() && context.Response.StatusCode != 304) - { - var responseBuffer = new MemoryStream(); - var responseBody = context.Response.Body; - - context.Response.Body = responseBuffer; - - await next(context); - - if (context.Response.StatusCode != 304) - { - context.Response.Body = responseBody; - - var html = Encoding.UTF8.GetString(responseBuffer.ToArray()); - - html = html.AdjustHtml(context); - - context.Response.ContentLength = Encoding.UTF8.GetByteCount(html); - context.Response.Body = responseBody; - - await context.Response.WriteAsync(html); - } - } else { await next(context); diff --git a/backend/src/Squidex/Areas/Frontend/Startup.cs b/backend/src/Squidex/Areas/Frontend/Startup.cs index 2d8edf0ac..6c3f5f74c 100644 --- a/backend/src/Squidex/Areas/Frontend/Startup.cs +++ b/backend/src/Squidex/Areas/Frontend/Startup.cs @@ -52,14 +52,12 @@ namespace Squidex.Areas.Frontend return next(); }); + app.UseMiddleware(); + if (environment.IsDevelopment()) { app.UseMiddleware(); } - else - { - app.UseMiddleware(); - } app.UseStaticFiles(new StaticFileOptions { From 96027525973bc9609ee3784a3c0d04a9673d02de Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Oct 2020 15:14:35 +0200 Subject: [PATCH 3/5] Small style fix. --- frontend/app/features/apps/pages/apps-page.component.html | 4 ++-- .../app/shared/components/assets/asset-folder.component.scss | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/app/features/apps/pages/apps-page.component.html b/frontend/app/features/apps/pages/apps-page.component.html index 7cea6473d..66209487f 100644 --- a/frontend/app/features/apps/pages/apps-page.component.html +++ b/frontend/app/features/apps/pages/apps-page.component.html @@ -1,8 +1,8 @@ -
+
-

{{ 'apps.welcomeTitle' | sqxTranslate: { user: authState.user?.displayName } }}

+

{{ 'apps.welcomeTitle' | sqxTranslate: { user: user.displayName } }}

{{ 'apps.welcomeSubtitle' | sqxTranslate }} diff --git a/frontend/app/shared/components/assets/asset-folder.component.scss b/frontend/app/shared/components/assets/asset-folder.component.scss index fbd449dfd..a2d87a346 100644 --- a/frontend/app/shared/components/assets/asset-folder.component.scss +++ b/frontend/app/shared/components/assets/asset-folder.component.scss @@ -14,6 +14,7 @@ img { & { border-bottom-width: 1px; border-width: 1px; + cursor: default; width: $asset-width; } From 66163a87cd973a34c4ffed9799d55e3a30b9fa10 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Oct 2020 15:32:50 +0200 Subject: [PATCH 4/5] Small null ref fix. --- backend/src/Squidex.Domain.Users/PwnedPasswordValidator.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/src/Squidex.Domain.Users/PwnedPasswordValidator.cs b/backend/src/Squidex.Domain.Users/PwnedPasswordValidator.cs index 9f34fdf65..ecd5125a6 100644 --- a/backend/src/Squidex.Domain.Users/PwnedPasswordValidator.cs +++ b/backend/src/Squidex.Domain.Users/PwnedPasswordValidator.cs @@ -29,6 +29,11 @@ namespace Squidex.Domain.Users public async Task ValidateAsync(UserManager manager, IdentityUser user, string password) { + if (string.IsNullOrWhiteSpace(password)) + { + return IdentityResult.Success; + } + try { var isBreached = await client.IsPasswordPwned(password); From b6f8cce27547b4d69d9dcd6d3c34b1ab8b9c1ed6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 16 Oct 2020 15:56:18 +0200 Subject: [PATCH 5/5] Fix for router sync. --- .../angular/routers/router-2-state.spec.ts | 33 +++--- .../angular/routers/router-2-state.ts | 11 +- frontend/app/shared/state/query.spec.ts | 107 +++++++++++++++++- frontend/app/shared/state/query.ts | 4 + 4 files changed, 136 insertions(+), 19 deletions(-) diff --git a/frontend/app/framework/angular/routers/router-2-state.spec.ts b/frontend/app/framework/angular/routers/router-2-state.spec.ts index 0b0b9fde6..500fcf0ea 100644 --- a/frontend/app/framework/angular/routers/router-2-state.spec.ts +++ b/frontend/app/framework/angular/routers/router-2-state.spec.ts @@ -23,17 +23,17 @@ describe('Router2State', () => { synchronizer.writeValue(value, params); - expect(params['key']).toEqual('my-string'); + expect(params).toEqual({ key: 'my-string' }); }); - it('should not write value to route when not a string', () => { + it('Should write undefined when not a string', () => { const params: Params = {}; const value = 123; synchronizer.writeValue(value, params); - expect(params).toEqual({}); + expect(params).toEqual({ key: undefined }); }); it('should get string from route', () => { @@ -60,27 +60,27 @@ describe('Router2State', () => { synchronizer.writeValue(value, params); - expect(params['key']).toEqual('flag1,flag2'); + expect(params).toEqual({ key: 'flag1,flag2' }); }); - it('should write empty object to route', () => { + it('Should write undefined when empty', () => { const params: Params = {}; const value = {}; synchronizer.writeValue(value, params); - expect(params['key']).toEqual(''); + expect(params).toEqual({ key: undefined }); }); - it('should not write value to route when not an object', () => { + it('Should write undefined when not an object', () => { const params: Params = {}; const value = 123; synchronizer.writeValue(value, params); - expect(params).toEqual({}); + expect(params).toEqual({ key: undefined }); }); it('should get object from route', () => { @@ -117,45 +117,44 @@ describe('Router2State', () => { synchronizer.writeValue(value, params); - expect(params['page']).toEqual('10'); - expect(params['take']).toEqual('20'); + expect(params).toEqual({ take: '20', page: '10' }); localStore.verify(x => x.setInt('contents.pageSize', 20), Times.once()); }); - it('should not write page if zero', () => { + it('Should write undefined when page number is zero', () => { const params: Params = {}; const value = new Pager(0, 0, 20, true); synchronizer.writeValue(value, params); - expect(params['page']).toBeUndefined(); - expect(params['take']).toEqual('20'); + expect(params).toEqual({ take: '20', page: undefined }); localStore.verify(x => x.setInt('contents.pageSize', 20), Times.once()); }); - it('should not write value to route when not pager', () => { + it('should write undefined when value not a pager', () => { const params: Params = {}; const value = 123; synchronizer.writeValue(value, params); - expect(params).toEqual({}); + expect(params).toEqual({ take: undefined, page: undefined }); localStore.verify(x => x.setInt('contents.pageSize', 20), Times.never()); }); - it('should not write value to route when null', () => { + it('should write undefined when value is null', () => { const params: Params = {}; const value = null; synchronizer.writeValue(value, params); - expect(params).toEqual({}); + expect(params).toEqual({ take: undefined, page: undefined }); + localStore.verify(x => x.setInt('contents.pageSize', 20), Times.never()); }); diff --git a/frontend/app/framework/angular/routers/router-2-state.ts b/frontend/app/framework/angular/routers/router-2-state.ts index 4b5abf78e..d47616305 100644 --- a/frontend/app/framework/angular/routers/router-2-state.ts +++ b/frontend/app/framework/angular/routers/router-2-state.ts @@ -54,6 +54,9 @@ export class PagerSynchronizer implements RouteSynchronizer { } public writeValue(state: any, params: Params) { + params['page'] = undefined; + params['take'] = undefined; + if (Types.is(state, Pager)) { if (state.page > 0) { params['page'] = state.page.toString(); @@ -81,6 +84,8 @@ export class StringSynchronizer implements RouteSynchronizer { } public writeValue(state: any, params: Params) { + params[this.name] = undefined; + if (Types.isString(state)) { params[this.name] = state; } @@ -110,10 +115,14 @@ export class StringKeysSynchronizer implements RouteSynchronizer { } public writeValue(state: any, params: Params) { + params[this.name] = undefined; + if (Types.isObject(state)) { const value = Object.keys(state).join(','); - params[this.name] = value; + if (value.length > 0) { + params[this.name] = value; + } } } } diff --git a/frontend/app/shared/state/query.spec.ts b/frontend/app/shared/state/query.spec.ts index f2ead7f8b..0165115ca 100644 --- a/frontend/app/shared/state/query.spec.ts +++ b/frontend/app/shared/state/query.spec.ts @@ -1,3 +1,4 @@ +import { Params } from '@angular/router'; /* * Squidex Headless CMS * @@ -6,7 +7,7 @@ */ import { Query } from '@app/shared/internal'; -import { equalsQuery } from './query'; +import { equalsQuery, QueryFullTextSynchronizer, QuerySynchronizer } from './query'; describe('equalsQuery', () => { it('should return true when comparing with empty query', () => { @@ -53,4 +54,108 @@ describe('equalsQuery', () => { expect(equalsQuery(lhs, rhs)).toBeTruthy(); }); +}); + +describe('QueryFullTextSynchronizer', () => { + const synchronizer = new QueryFullTextSynchronizer(); + + it('should write full text to route', () => { + const params: Params = {}; + + const value = { fullText: 'my-query' }; + + synchronizer.writeValue(value, params); + + expect(params).toEqual({ query: 'my-query' }); + }); + + it('Should write undefined when not a query', () => { + const params: Params = {}; + + const value = 123; + + synchronizer.writeValue(value, params); + + expect(params).toEqual({ query: undefined }); + }); + + it('Should write undefined query has no full text', () => { + const params: Params = {}; + + const value = { fullText: '' }; + + synchronizer.writeValue(value, params); + + expect(params).toEqual({ query: undefined }); + }); + + it('should get query from route', () => { + const params: Params = { + query: 'my-query' + }; + + const value = synchronizer.getValue(params); + + expect(value).toEqual({ fullText: 'my-query' }); + }); + + it('should get query as undefined from route', () => { + const params: Params = {}; + + const value = synchronizer.getValue(params); + + expect(value).toBeUndefined(); + }); +}); + +describe('QuerySynchronizer', () => { + const synchronizer = new QuerySynchronizer(); + + it('should write query to route', () => { + const params: Params = {}; + + const value = { filter: 'my-filter' }; + + synchronizer.writeValue(value, params); + + expect(params).toEqual({ query: '{"filter":"my-filter","sort":[]}' }); + }); + + it('Should write undefined when not a query', () => { + const params: Params = {}; + + const value = 123; + + synchronizer.writeValue(value, params); + + expect(params).toEqual({ query: undefined }); + }); + + it('should get query from route', () => { + const params: Params = { + query: '{"filter":"my-filter"}' + }; + + const value = synchronizer.getValue(params) as any; + + expect(value).toEqual({ filter: 'my-filter' }); + }); + + it('should get query full text from route', () => { + const params: Params = { + query: 'my-query' + }; + + const value = synchronizer.getValue(params); + + expect(value).toEqual({ fullText: 'my-query' }); + }); + + it('should get query as undefined from route', () => { + const params: Params = {}; + + const value = synchronizer.getValue(params); + + expect(value).toBeUndefined(); + }); }); \ No newline at end of file diff --git a/frontend/app/shared/state/query.ts b/frontend/app/shared/state/query.ts index 79c0cfb4a..f3d6e4385 100644 --- a/frontend/app/shared/state/query.ts +++ b/frontend/app/shared/state/query.ts @@ -128,6 +128,8 @@ export class QueryFullTextSynchronizer implements RouteSynchronizer { } public writeValue(state: any, params: Params) { + params['query'] = undefined; + if (Types.isObject(state) && Types.isString(state.fullText) && state.fullText.length > 0) { params['query'] = state.fullText; } @@ -144,6 +146,8 @@ export class QuerySynchronizer implements RouteSynchronizer { } public writeValue(state: any, params: Params) { + params['query'] = undefined; + if (Types.isObject(state)) { params['query'] = serializeQuery(state); }