Skip to content

Commit

Permalink
SVY-18890 upgrade to angular 17.x and also change the builder to the
Browse files Browse the repository at this point in the history
"application" (esbuild) builder

moved to the new application builder

hard coded the locales of the calendar component (tempus-dominus)
because of evanw/esbuild#700
this is needed, esbuild doesn't handle the dynamic part yet
  • Loading branch information
jcompagner committed Feb 20, 2024
1 parent 8b4d8a5 commit 9f54c2b
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions aggrid/projects/nggrids/src/editors/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DOCUMENT } from '@angular/common';
import { Deferred, Format, FormattingService, getFirstDayOfWeek, MaskFormat, ServoyPublicService } from '@servoy/public';
import { DateTime as DateTimeLuxon} from 'luxon';
import { DateTime, Namespace, Options, TempusDominus } from '@eonasdan/tempus-dominus';
import { NULL_VALUE } from '../datagrid/datagrid';

@Component({
selector: 'aggrid-datepicker',
Expand Down Expand Up @@ -57,7 +56,8 @@ export class DatePicker extends EditorDirective {
format: Format;
maskFormat : MaskFormat;

constructor(private _renderer: Renderer2, servoyService: ServoyPublicService, @Inject(DOCUMENT) private doc: Document, private formattingService: FormattingService) {
constructor(private _renderer: Renderer2, servoyService: ServoyPublicService, @Inject(DOCUMENT) private doc: Document,
private formattingService: FormattingService) {
super();
this.config.localization.startOfTheWeek = getFirstDayOfWeek(servoyService.getLocaleObject() ? servoyService.getLocaleObject().full : servoyService.getLocale());
const lts = DateTimeLuxon.now().setLocale(servoyService.getLocale()).toLocaleString(DateTimeLuxon.DATETIME_FULL).toUpperCase();
Expand Down Expand Up @@ -187,19 +187,41 @@ export class DatePicker extends EditorDirective {
private loadCalendarLocale(locale: string): Deferred<any> {
const localeDefer = new Deferred();
const index = locale.indexOf('-');
let language = locale;
if (index > 0) {
let language = locale.toLowerCase();
if (index > 0 && language !== 'ar-sa' && language !== 'sr-latn') {
language = locale.substring(0, index);
}
language = language.toLowerCase();
import(`@eonasdan/tempus-dominus/dist/locales/${language}.js`).then(
(module: { localization: { [key: string]: string } }) => {
this.config.localization = module.localization;
localeDefer.resolve(locale);
},
() => {
localeDefer.resolve('');
});
const moduleLoader = (module: { default: { localization: { [key: string]: string | number} }}) => {
const copy = Object.assign({}, module.default.localization);
copy.startOfTheWeek = this.config.localization.startOfTheWeek;
copy.hourCycle = this.config.localization.hourCycle;
this.config.localization = copy;
localeDefer.resolve(locale);
}
const errorHandler = () => {
localeDefer.resolve('');
}
switch(language) {
case 'ar-sa': import('@eonasdan/tempus-dominus/dist/locales/ar-SA.js').then(moduleLoader,errorHandler); break;
case 'ar': import('@eonasdan/tempus-dominus/dist/locales/ar.js').then(moduleLoader,errorHandler); break;
case 'ca': import('@eonasdan/tempus-dominus/dist/locales/ca.js').then(moduleLoader,errorHandler); break;
case 'cs': import('@eonasdan/tempus-dominus/dist/locales/cs.js').then(moduleLoader,errorHandler); break;
case 'de': import('@eonasdan/tempus-dominus/dist/locales/de.js').then(moduleLoader,errorHandler); break;
case 'es': import('@eonasdan/tempus-dominus/dist/locales/es.js').then(moduleLoader,errorHandler); break;
case 'fi': import('@eonasdan/tempus-dominus/dist/locales/fi.js').then(moduleLoader,errorHandler); break;
case 'fr': import('@eonasdan/tempus-dominus/dist/locales/fr.js').then(moduleLoader,errorHandler); break;
case 'hr': import('@eonasdan/tempus-dominus/dist/locales/hr.js').then(moduleLoader,errorHandler); break;
case 'hy': import('@eonasdan/tempus-dominus/dist/locales/hy.js').then(moduleLoader,errorHandler); break;
case 'it': import('@eonasdan/tempus-dominus/dist/locales/it.js').then(moduleLoader,errorHandler); break;
case 'nl': import('@eonasdan/tempus-dominus/dist/locales/nl.js').then(moduleLoader,errorHandler); break;
case 'pl': import('@eonasdan/tempus-dominus/dist/locales/pl.js').then(moduleLoader,errorHandler); break;
case 'ro': import('@eonasdan/tempus-dominus/dist/locales/ro.js').then(moduleLoader,errorHandler); break;
case 'ru': import('@eonasdan/tempus-dominus/dist/locales/ru.js').then(moduleLoader,errorHandler); break;
case 'sl': import('@eonasdan/tempus-dominus/dist/locales/sl.js').then(moduleLoader,errorHandler); break;
case 'sr': import('@eonasdan/tempus-dominus/dist/locales/sr.js').then(moduleLoader,errorHandler); break;
case 'sr-latn': import('@eonasdan/tempus-dominus/dist/locales/sr-Latn.js').then(moduleLoader,errorHandler); break;
case 'tr': import('@eonasdan/tempus-dominus/dist/locales/tr.js').then(moduleLoader,errorHandler); break;
}
return localeDefer;
}
}

0 comments on commit 9f54c2b

Please sign in to comment.