Browse Source

Fix language cookies and localize pikaday.

pull/604/head
Sebastian 5 years ago
parent
commit
2ce33ffc5e
  1. 8
      backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/IUpsertCommand.cs
  2. 3
      backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/UpsertSchemaDto.cs
  3. 37
      frontend/app/framework/angular/forms/editors/date-time-editor.component.ts
  4. 1
      frontend/app/framework/internal.ts
  5. 26
      frontend/app/framework/utils/cookies.ts
  6. 5
      frontend/app/shell/pages/internal/profile-menu.component.ts

8
backend/src/Squidex.Domain.Apps.Entities/Schemas/Commands/IUpsertCommand.cs

@ -21,16 +21,16 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands
SchemaField[]? Fields { get; set; }
SchemaScripts? Scripts { get; set; }
SchemaProperties Properties { get; set; }
FieldNames? FieldsInReferences { get; set; }
FieldNames? FieldsInLists { get; set; }
FieldRuleCommand[]? FieldRules { get; set; }
SchemaScripts? Scripts { get; set; }
SchemaProperties Properties { get; set; }
Dictionary<string, string>? PreviewUrls { get; set; }
Schema ToSchema(string name, bool isSingleton)

3
backend/src/Squidex/Areas/Api/Controllers/Schemas/Models/UpsertSchemaDto.cs

@ -54,8 +54,7 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models
/// </summary>
public bool IsPublished { get; set; }
public static TCommand ToCommand<TCommand, TDto>(TDto dto, TCommand command)
where TCommand : SchemaCommand, IUpsertCommand where TDto : UpsertSchemaDto
public static T ToCommand<T, TSoure>(TSoure dto, T command) where T : SchemaCommand, IUpsertCommand where TSoure : UpsertSchemaDto
{
SimpleMapper.Map(dto, command);

37
frontend/app/framework/angular/forms/editors/date-time-editor.component.ts

@ -8,6 +8,7 @@
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Input, OnInit, Output, ViewChild } from '@angular/core';
import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { DateHelper, DateTime, StatefulControlComponent, UIOptions } from '@app/framework/internal';
import format from 'date-fns/format';
import * as Pikaday from 'pikaday/pikaday';
import { FocusComponent } from './../forms-helper';
@ -136,7 +137,12 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
}
public ngAfterViewInit() {
this.picker = new Pikaday({field: this.dateInput.nativeElement, format: 'YYYY-MM-DD',
const i18n = getLocalizationSettings();
this.picker = new Pikaday({
field: this.dateInput.nativeElement,
i18n,
format: 'YYYY-MM-DD',
onSelect: () => {
if (this.suppressEvents) {
return;
@ -242,4 +248,33 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
public setCompact(isCompact: boolean) {
this.next(s => ({ ...s, isCompact }));
}
}
let localizedValues: any;
function getLocalizationSettings() {
if (!localizedValues) {
localizedValues = {
months: [],
weekdays: [],
weekdaysShort: []
};
const options = { locale: DateHelper.getFnsLocale() };
for (let i = 0; i < 12; i++) {
const firstOfMonth = new Date(2020, i, 1);
localizedValues.months.push(format(firstOfMonth, 'LLLL', options));
}
for (let i = 1; i <= 7; i++) {
const weekDay = new Date(2020, 11, i);
localizedValues.weekdays.push(format(weekDay, 'EEEE', options));
localizedValues.weekdaysShort.push(format(weekDay, 'EEE', options));
}
}
return localizedValues;
}

1
frontend/app/framework/internal.ts

@ -24,6 +24,7 @@ export * from './services/temp.service';
export * from './services/title.service';
export * from './services/localizer.service';
export * from './utils/array-helper';
export * from './utils/cookies';
export * from './utils/date-helper';
export * from './utils/date-time';
export * from './utils/duration';

26
frontend/app/framework/utils/cookies.ts

@ -0,0 +1,26 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
export module Cookies {
export function set(name: string, value: string, days: number) {
let expires = '';
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = `${name}=${value || ''}${expires}; path=/`;
}
export function remove(name: string) {
document.cookie = `${name}=; Max-Age=-99999999;`;
}
}

5
frontend/app/shell/pages/internal/profile-menu.component.ts

@ -6,7 +6,7 @@
*/
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ApiUrlConfig, AuthService, fadeAnimation, ModalModel, StatefulComponent, UILanguages, UIOptions, UIState } from '@app/shared';
import { ApiUrlConfig, AuthService, Cookies, fadeAnimation, ModalModel, StatefulComponent, UILanguages, UIOptions, UIState } from '@app/shared';
interface State {
// The display name of the user.
@ -71,7 +71,8 @@ export class ProfileMenuComponent extends StatefulComponent<State> implements On
}
public changeLanguage(code: string) {
document.cookie = `.AspNetCore.Culture=c=${code}|uic=${code}`;
Cookies.remove('.AspNetCore.Culture');
Cookies.set('.AspNetCore.Culture', `c=${code}|uic=${code}`, 365);
location.reload();
}

Loading…
Cancel
Save