Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Mar 1, 2024
2 parents f9c1e61 + 9ecd6f5 commit ba463d7
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ E.g., if it was used in a menu and the menu is red, the circle would be red.
## Changelog
### **WORK IN PROGRESS**
* (foxriver76) allow to use `widgetOid` in bindings
* (foxriver76) fixed various problems with Date Picker widget
* (foxriver76) made default option of Date Picker human readable and added option for full parseable date

### 2.9.37 (2024-02-28)
* (foxriver76) TimePicker widget now saves the time instead of date by default, if you want old behavior use checkbox `asDate`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@mui/styles';

import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';
Expand All @@ -31,7 +30,9 @@ import 'dayjs/locale/pl';
import 'dayjs/locale/pt';
import 'dayjs/locale/nl';

// eslint-disable-next-line import/no-cycle
import type { GetRxDataFromWidget, RxRenderWidgetProps } from '@/types';
import type { TextFieldVariants } from '@mui/material';
import dayjs from 'dayjs';
import VisRxWidget from '../../visRxWidget';

const styles = {
Expand All @@ -43,7 +44,12 @@ const styles = {
},
};

class JQuiInputDate extends VisRxWidget {
type RxData = GetRxDataFromWidget<typeof JQuiInputDate>

class JQuiInputDate extends VisRxWidget<RxData> {
/** If user does not want to use full date */
private readonly EASY_DATE_FORMAT = 'DD.MM.YYYY';

static getWidgetInfo() {
return {
id: 'tplJquiInputDate',
Expand Down Expand Up @@ -97,6 +103,11 @@ class JQuiInputDate extends VisRxWidget {
type: 'checkbox',
hidden: '!!data.disableFuture',
},
{
name: 'asFullDate',
label: 'jqui_asFullDate',
type: 'checkbox',
},
{
name: 'displayWeekNumber',
label: 'jqui_displayWeekNumber',
Expand All @@ -114,32 +125,37 @@ class JQuiInputDate extends VisRxWidget {
width: 250,
height: 56,
},
};
} as const;
}

// eslint-disable-next-line class-methods-use-this
getWidgetInfo() {
return JQuiInputDate.getWidgetInfo();
}

renderWidgetBody(props) {
renderWidgetBody(props: RxRenderWidgetProps) {
super.renderWidgetBody(props);

return <div
className="vis-widget-body"
onClick={this.state.rxData.html ? () => this.onClick() : undefined}
>
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={this.props.context.lang}>
<DatePicker
value={this.state.values[`${this.state.rxData.oid}.val`] || ''}
value={this.state.rxData.asFullDate ? dayjs(this.state.values[`${this.state.rxData.oid}.val`]) || '' : dayjs(this.state.values[`${this.state.rxData.oid}.val`], this.EASY_DATE_FORMAT)}
label={this.state.rxData.widgetTitle || null}
autoFocus={this.state.rxData.autoFocus || false}
onChange={newValue => this.props.context.setValue(this.state.rxData.oid, newValue)}
onChange={newValue => {
if (!newValue) {
return;
}

const val = this.state.rxData.asFullDate ? newValue.toDate() : newValue.format(this.EASY_DATE_FORMAT);
this.props.context.setValue(this.state.rxData.oid, val);
}}
formatDensity={this.state.rxData.wideFormat ? 'spacious' : 'dense'}
slotProps={{
textField: {
variant: this.state.rxData.variant || 'standard',
size: this.state.rxData.small ? 'small' : undefined,
variant: this.state.rxData.variant as TextFieldVariants || 'standard',
style: {
width: '100%',
height: '100%',
Expand All @@ -159,12 +175,4 @@ class JQuiInputDate extends VisRxWidget {
}
}

JQuiInputDate.propTypes = {
id: PropTypes.string.isRequired,
context: PropTypes.object.isRequired,
view: PropTypes.string.isRequired,
editMode: PropTypes.bool.isRequired,
tpl: PropTypes.string.isRequired,
};

export default withStyles(styles)(JQuiInputDate);
5 changes: 5 additions & 0 deletions src/src/Vis/visFormatUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ class VisFormatUtils {
try {
// eslint-disable-next-line no-new-func
value = new Function(string)();

if (value && typeof value === 'object') {
value = JSON.stringify(value);
}
} catch (e) {
console.error(`Error in eval[value]: ${format}`);
console.error(`Error in eval[script]: ${string}`);
Expand Down Expand Up @@ -498,6 +502,7 @@ class VisFormatUtils {
} // for

format = format.replace(/{{/g, '{').replace(/}}/g, '}');

return format;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Aktive Farbe",
"jqui_ampm": "Vormittags/Nachmittags",
"jqui_asDate": "Als Datum",
"jqui_asFullDate": "Verwendung des vollständig analysierbaren Datums",
"jqui_as_string": "Als String",
"jqui_auto": "Auto",
"jqui_binary_control": "Binäre Steuerung",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Active color",
"jqui_ampm": "Am/Pm",
"jqui_asDate": "As date",
"jqui_asFullDate": "Usage of full parseable date",
"jqui_as_string": "As string",
"jqui_auto": "auto",
"jqui_binary_control": "Binary control",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "color activo",
"jqui_ampm": "Am PM",
"jqui_asDate": "como fecha",
"jqui_asFullDate": "Uso de fecha analizable completa",
"jqui_as_string": "Como cuerda",
"jqui_auto": "auto",
"jqui_binary_control": "control binario",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Couleur active",
"jqui_ampm": "Matin après-midi",
"jqui_asDate": "Comme date",
"jqui_asFullDate": "Utilisation de la date analysable complète",
"jqui_as_string": "En tant que chaîne",
"jqui_auto": "auto",
"jqui_binary_control": "Contrôle binaire",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Colore attivo",
"jqui_ampm": "Am PM",
"jqui_asDate": "Come data",
"jqui_asFullDate": "Utilizzo della data intera analizzabile",
"jqui_as_string": "Come stringa",
"jqui_auto": "auto",
"jqui_binary_control": "Controllo binario",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Actieve kleur",
"jqui_ampm": "AM PM",
"jqui_asDate": "Als datum",
"jqui_asFullDate": "Gebruik van volledige parseerbare datum",
"jqui_as_string": "Als touwtje",
"jqui_auto": "auto",
"jqui_binary_control": "Binaire controle",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Aktywny kolor",
"jqui_ampm": "Jestem/Po południu",
"jqui_asDate": "Jako data",
"jqui_asFullDate": "Użycie pełnej daty możliwej do analizy",
"jqui_as_string": "Jako ciąg",
"jqui_auto": "automatyczny",
"jqui_binary_control": "Sterowanie binarne",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Cor ativa",
"jqui_ampm": "Manhã tarde",
"jqui_asDate": "Como data",
"jqui_asFullDate": "Uso de data analisável completa",
"jqui_as_string": "Como corda",
"jqui_auto": "auto",
"jqui_binary_control": "Controle binário",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Активный цвет",
"jqui_ampm": "До полудня после полудня",
"jqui_asDate": "Как дата",
"jqui_asFullDate": "Использование полной анализируемой даты",
"jqui_as_string": "Как строка",
"jqui_auto": "авто",
"jqui_binary_control": "Двоичное управление",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "Активний колір",
"jqui_ampm": "Дообіду, після обіду",
"jqui_asDate": "Як дата",
"jqui_asFullDate": "Використання повної аналізованої дати",
"jqui_as_string": "Як рядок",
"jqui_auto": "авто",
"jqui_binary_control": "Двійковий контроль",
Expand Down
1 change: 1 addition & 0 deletions src/src/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@
"jqui_active_color": "活性颜色",
"jqui_ampm": "上午下午",
"jqui_asDate": "截至日期",
"jqui_asFullDate": "使用完整的可解析日期",
"jqui_as_string": "作为字符串",
"jqui_auto": "汽车",
"jqui_binary_control": "二元控制",
Expand Down

0 comments on commit ba463d7

Please sign in to comment.