Browse Source

DateTime fix.

pull/389/head
Sebastian Stehle 7 years ago
parent
commit
fefed6ad65
  1. 67
      src/Squidex/app/framework/angular/forms/date-time-editor.component.ts
  2. 4
      src/Squidex/app/framework/angular/modals/onboarding-tooltip.component.html
  3. 2
      src/Squidex/app/framework/angular/modals/onboarding-tooltip.component.ts

67
src/Squidex/app/framework/angular/forms/date-time-editor.component.ts

@ -28,8 +28,8 @@ export const SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR: any = {
})
export class DateTimeEditorComponent extends StatefulControlComponent<{}, string | null> implements OnInit, AfterViewInit {
private picker: any;
private timeValue: any | null = null;
private dateValue: any | null = null;
private timeValue: moment.Moment | null = null;
private dateValue: moment.Moment | null = null;
private suppressEvents = false;
@Input()
@ -65,10 +65,10 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
if (!value || value.length === 0) {
this.timeValue = null;
} else {
this.timeValue = moment(value, 'HH:mm:ss');
this.timeValue = moment.utc(value, 'HH:mm:ss');
}
this.updateValue();
this.callChangeFormatted();
}));
this.own(
@ -76,10 +76,10 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
if (!value || value.length === 0) {
this.dateValue = null;
} else {
this.dateValue = moment(value, 'YYYY-MM-DD');
this.dateValue = moment.utc(value, 'YYYY-MM-DD');
}
this.updateValue();
this.callChangeFormatted();
}));
}
@ -87,10 +87,10 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
if (Types.isString(obj) && obj.length > 0) {
const parsed = moment.parseZone(obj);
this.dateValue = moment(parsed);
this.dateValue = parsed;
if (this.showTime) {
this.timeValue = moment(parsed);
this.timeValue = parsed;
}
} else {
this.timeValue = null;
@ -128,7 +128,7 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
}
this.dateValue = this.picker.getMoment();
this.updateValue();
this.callChangeFormatted();
this.callTouched();
}
});
@ -140,7 +140,7 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
this.writeValue(new Date().toUTCString());
this.updateControls();
this.updateValue();
this.callChangeFormatted();
this.callTouched();
return false;
@ -158,26 +158,30 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
return false;
}
private updateValue() {
let result: string | null;
private callChangeFormatted() {
this.callChange(this.getValue());
}
if ((this.dateValue && !this.dateValue.isValid()) || (this.timeValue && !this.timeValue.isValid())) {
result = null;
} else if (!this.dateValue && !this.timeValue) {
result = null;
} else {
result = this.dateValue.format('YYYY-MM-DD');
if (this.showTime && this.timeValue) {
result += 'T';
result += this.timeValue.format('HH:mm:ss');
result += 'Z';
} else if (this.enforceTime) {
result += 'T00:00:00Z';
}
private getValue(): string | null {
if (!this.dateValue || !this.dateValue.isValid()) {
return null;
}
if (this.timeValue && !this.timeValue.isValid()) {
return null;
}
this.callChange(result);
let result = this.dateValue.format('YYYY-MM-DD');
if (this.showTime && this.timeValue) {
result += 'T';
result += this.timeValue.format('HH:mm:ss');
result += 'Z';
} else if (this.enforceTime) {
result += 'T00:00:00Z';
}
return result;
}
private updateControls() {
@ -190,13 +194,16 @@ export class DateTimeEditorComponent extends StatefulControlComponent<{}, string
}
if (this.dateValue && this.dateValue.isValid() && this.picker) {
this.dateControl.setValue(this.dateValue.format('YYYY-MM-DD'), { emitEvent: false });
const dateString = this.dateValue.format('YYYY-MM-DD');
const dateLocal = moment(dateString);
this.dateControl.setValue(dateString, { emitEvent: false });
this.picker.setMoment(this.dateValue);
this.picker.setMoment(dateLocal);
} else {
this.dateControl.setValue(null, { emitEvent: false });
}
this.suppressEvents = false;
}
}
}

4
src/Squidex/app/framework/angular/modals/onboarding-tooltip.component.html

@ -1,6 +1,6 @@
<ng-container *sqxModal="tooltipModal;closeAuto:false">
<div class="onboarding-rect" [sqxAnchoredTo]="for" [offset]="4" position="full"></div>
<div class="onboarding-help" [sqxAnchoredTo]="for" [offset]="4" @fade>
<div class="onboarding-rect" [sqxAnchoredTo]="for" [offset]="4" [position]="'full'"></div>
<div class="onboarding-help" [sqxAnchoredTo]="for" [offset]="4" [position]="position" @fade>
<div class="onboarding-text">
<ng-content></ng-content>
</div>

2
src/Squidex/app/framework/angular/modals/onboarding-tooltip.component.ts

@ -58,7 +58,7 @@ export class OnboardingTooltipComponent extends StatefulComponent implements OnD
if (this.for && this.helpId && Types.isFunction(this.for.addEventListener)) {
this.own(
timer(this.after).subscribe(() => {
if (true || this.onboardingService.shouldShow(this.helpId)) {
if (this.onboardingService.shouldShow(this.helpId)) {
const forRect = this.for.getBoundingClientRect();
const x = forRect.left + 0.5 * forRect.width;

Loading…
Cancel
Save