Skip to content

Commit 52dc850

Browse files
committed
fix: missing readonly states
- entry-list-select - datetime
1 parent ac83326 commit 52dc850

File tree

10 files changed

+84
-79
lines changed

10 files changed

+84
-79
lines changed

packages/calendar/src/lib/calendar/calendar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@
5151
</li>
5252
</ul>
5353
<ec-month [disableDragStart]="disableDragStart" [disableDragEnd]="disableDragEnd" (spanChanged)="spanChanged.emit($event)"
54-
[timespan]="timespan" [heatmap]="heatmap" [date]="date" (dayClicked)="select($event)" #grid></ec-month>
54+
[timespan]="timespan" [disabled]="disabled" [heatmap]="heatmap" [date]="date" (dayClicked)="select($event)" #grid></ec-month>
5555
</div>
5656
</div>

packages/calendar/src/lib/calendar/calendar.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class CalendarComponent extends MonthComponent implements ControlValueAcc
3434
public weekdays: string[];
3535
/** The input's placeholder */
3636
@Input() placeholder = '';
37+
/** If true, the date cannot be changed */
38+
@Input() disabled;
3739
/** If true, the time will not be displayed nor will be editable. */
3840
@Input() disableTime: boolean;
3941
/** Allowed date input patterns. The first one will be standard. */
@@ -45,9 +47,8 @@ export class CalendarComponent extends MonthComponent implements ControlValueAcc
4547
constructor(
4648
@Inject('moment.format.date') public defaultDateFormat,
4749
@Inject('moment.format.time') public defaultTimeFormat,
48-
@Inject('moment.format.month') protected defaultMonthFormat,
49-
) /* public symbol: SymbolService */
50-
{
50+
@Inject('moment.format.month') protected defaultMonthFormat /* public symbol: SymbolService */,
51+
) {
5152
/* super(symbol); */
5253
super(defaultMonthFormat);
5354
// pattern localization
@@ -76,6 +77,10 @@ export class CalendarComponent extends MonthComponent implements ControlValueAcc
7677

7778
/** Updates the value with the given moment and propagates the change. */
7879
select(selected) {
80+
if (this.disabled) {
81+
console.warn('cannot select date: calendar is set to disabled=true');
82+
return;
83+
}
7984
if (this.value && selected.hour() === 0 && selected.minute() === 0) {
8085
const previous = moment(this.value, this.patterns, true);
8186
selected.hour(previous.hour());
@@ -132,4 +137,8 @@ export class CalendarComponent extends MonthComponent implements ControlValueAcc
132137

133138
/** registerOnTouched implementation of ControlValueAccessor */
134139
registerOnTouched() {}
140+
141+
setDisabledState(isDisabled) {
142+
this.disabled = isDisabled;
143+
}
135144
}

packages/calendar/src/lib/calendar/month.component.ts

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
Component,
3-
EventEmitter,
4-
Input,
5-
OnChanges,
6-
OnInit,
7-
Output,
8-
Inject
9-
} from '@angular/core';
1+
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, Inject } from '@angular/core';
102
/* import { SymbolService } from '../../symbol/symbol.service'; */
113
import moment from 'moment-es6';
124
import { debounceTime } from 'rxjs/operators';
@@ -39,7 +31,7 @@ export interface Day {
3931
/** Displays the days of a month in a calendarish table. */
4032
@Component({
4133
selector: 'ec-month',
42-
templateUrl: 'month.component.html'
34+
templateUrl: 'month.component.html',
4335
})
4436
export class MonthComponent implements OnInit, OnChanges {
4537
dragged: any;
@@ -59,6 +51,8 @@ export class MonthComponent implements OnInit, OnChanges {
5951
@Input() disableDragStart = false;
6052
/** If true, the timespan end cannot be dragged */
6153
@Input() disableDragEnd = false;
54+
/** If true, nothing can be changed */
55+
@Input() disabled;
6256
/** The current month as string */
6357
public formatted: string;
6458
/** The cells containing the days */
@@ -80,18 +74,15 @@ export class MonthComponent implements OnInit, OnChanges {
8074
this.drag
8175
.asObservable()
8276
.pipe(debounceTime(100))
83-
.subscribe(day => this.dropDay(day));
77+
.subscribe((day) => this.dropDay(day));
8478
this.changeSpan
8579
.asObservable()
8680
.pipe(debounceTime(800))
87-
.subscribe(timespan => this.spanChanged.emit(this.timespan));
81+
.subscribe((timespan) => this.spanChanged.emit(this.timespan));
8882
}
8983

9084
dropDay(day: Day) {
91-
if (
92-
!this.dragged ||
93-
((day.first && this.dragged.first) || (day.last && this.dragged.last))
94-
) {
85+
if (!this.dragged || ((day.first && this.dragged.first) || (day.last && this.dragged.last))) {
9586
return;
9687
}
9788
const newTimespan = [].concat(this.timespan);
@@ -113,10 +104,7 @@ export class MonthComponent implements OnInit, OnChanges {
113104
}
114105

115106
dragStart(day, e) {
116-
if (
117-
(this.disableDragStart && day.first) ||
118-
(this.disableDragEnd && day.last)
119-
) {
107+
if ((this.disableDragStart && day.first) || (this.disableDragEnd && day.last)) {
120108
return;
121109
}
122110
this.dragged = day;
@@ -196,38 +184,37 @@ export class MonthComponent implements OnInit, OnChanges {
196184
return {
197185
index,
198186
date,
199-
type:
200-
date.format('MM YYYY') === day.format('MM YYYY')
201-
? 'current'
202-
: 'other',
203-
active:
204-
this.timespan &&
205-
date.isBetween(this.timespan[0], this.timespan[1], 'days', '[]'),
187+
type: date.format('MM YYYY') === day.format('MM YYYY') ? 'current' : 'other',
188+
active: this.timespan && date.isBetween(this.timespan[0], this.timespan[1], 'days', '[]'),
206189
first: isStart,
207190
last: isEnd,
208-
draggable:
209-
(!this.disableDragStart && isStart) ||
210-
(!this.disableDragEnd && isEnd),
191+
draggable: (!this.disableDragStart && isStart) || (!this.disableDragEnd && isEnd),
211192
color: this.getDayColor(date),
212193
heat: this.getDayHeat(date),
213194
format: date.format('DD'),
214195
today:
215196
moment()
216197
.startOf('day')
217-
.diff(date, 'days') === 0
198+
.diff(date, 'days') === 0,
218199
};
219200
});
220201
}
221202

222203
/** Sets the calendars viewed date to the given moment's month. Renders always 42 cells to keep the layout consistent. */
223204
setDate(date: moment.Moment = this.selected || this.date || moment()) {
205+
if (this.disabled) {
206+
return;
207+
}
224208
this.date = date.clone();
225209
this.formatted = date.format(this.monthFormat);
226210
this.cells = this.getMonth(date.clone(), 'current');
227211
}
228212

229213
/** Selects the day of the given moment. */
230214
selectDay(_moment: moment.Moment, emit = true): void {
215+
if (this.disabled) {
216+
return;
217+
}
231218
this.setDate(_moment);
232219
this.selected = _moment;
233220
if (emit) {
@@ -253,12 +240,7 @@ export class MonthComponent implements OnInit, OnChanges {
253240
return true;
254241
}
255242
const newDate = this.date.clone().add(value, span);
256-
return newDate.isBetween(
257-
this.timespan[0],
258-
this.timespan[1],
259-
'months',
260-
'[]'
261-
);
243+
return newDate.isBetween(this.timespan[0], this.timespan[1], 'months', '[]');
262244
}
263245

264246
/** Updates the viewed date to reflect the given relative changes. */

packages/data/src/lib/entry-list-select/entry-list-select.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<ec-list [config]="selectionConfig" [items]="items" (columnClicked)="entryPop.edit($event.getBody())" #selectionList></ec-list>
33
<ec-entry-pop [model]="model" #entryPop (submitted)="formSubmitted($event)" (deleted)="removeItem($event)"></ec-entry-pop>
44

5-
<a class="btn btn_clear" (click)="entryPop.create()" *ngIf="model">
5+
<a class="btn btn_clear" (click)="entryPop.create()" *ngIf="!disabled&&model">
66
<ec-icon name="add"></ec-icon>
77
</a>
8-
<a class="btn btn_clear" (click)="entryListPop.show()">
8+
<a class="btn btn_clear" (click)="entryListPop.show()" *ngIf="!disabled">
99
<ec-icon name="find"></ec-icon>
1010
</a>

packages/data/src/lib/entry-list-select/entry-list-select.component.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,42 +70,44 @@ export class EntryListSelectComponent extends InputComponent implements ControlV
7070
if (this.field && !this.model) {
7171
this.model = this.field.relation;
7272
}
73-
if (this.model) {
74-
this.modelConfig.generateConfig(this.model, (this.listConfig || {}).fields).then((config) => {
75-
this.listConfig = config;
76-
this.selectionConfig = Object.assign({}, this.listConfig, {
77-
disableHeader: false,
78-
defaultFilter: false,
79-
hidePagination: true,
80-
fields: Object.assign(
81-
{},
82-
this.listConfig.fields,
83-
{
84-
_modified: Object.assign({}, config.fields._modified, { hideInList: true }),
85-
},
86-
{
87-
button: {
88-
label: this.symbol.resolve('entry.select.remove'),
89-
form: false,
90-
resolve: () => ' ',
91-
view: 'link',
92-
class: 'btn btn_clear',
93-
icon: 'close-x',
94-
action: (item, property) => {
95-
this.selection.remove(item);
96-
},
73+
if (!this.model) {
74+
return;
75+
}
76+
this.modelConfig.generateConfig(this.model, (this.listConfig || {}).fields).then((config) => {
77+
this.listConfig = config;
78+
this.selectionConfig = Object.assign({}, this.listConfig, {
79+
disableHeader: false,
80+
defaultFilter: false,
81+
hidePagination: true,
82+
fields: Object.assign(
83+
{},
84+
this.listConfig.fields,
85+
{
86+
_modified: Object.assign({}, config.fields._modified, { hideInList: true }),
87+
},
88+
{
89+
button: {
90+
label: this.symbol.resolve('entry.select.remove'),
91+
form: false,
92+
resolve: () => ' ',
93+
view: 'link',
94+
class: 'btn btn_clear',
95+
icon: 'close-x',
96+
action: (item, property) => {
97+
this.selection.remove(item);
9798
},
99+
hideInList: this.disabled,
98100
},
99-
),
100-
});
101-
Object.keys(this.selectionConfig.fields).forEach((key) => {
102-
if (this.selectionConfig.fields[key].type !== 'text') {
103-
this.selectionConfig.fields[key].filterable = false;
104-
}
105-
});
106-
this.initSelection();
101+
},
102+
),
107103
});
108-
}
104+
Object.keys(this.selectionConfig.fields).forEach((key) => {
105+
if (this.selectionConfig.fields[key].type !== 'text') {
106+
this.selectionConfig.fields[key].filterable = false;
107+
}
108+
});
109+
this.initSelection();
110+
});
109111
}
110112

111113
/** Initializes the selection with listConfig. Propagates change */

packages/data/src/lib/entry-select/entry-select.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<a (click)="editItem(selection?.display[0],$event)" class="btn btn_clear" *ngIf="solo&&!config?.disableCreatePop&&hasMethod('put')&&!selection?.isEmpty()">
5050
<ec-icon name="pencil"></ec-icon>
5151
</a>
52-
<a (click)="entryPop.create()" class="btn btn_clear" *ngIf="!config?.disableCreatePop&&hasMethod('post')&&(!solo||selection?.isEmpty())">
52+
<a (click)="entryPop.create()" class="btn btn_clear" *ngIf="!disabled&&!config?.disableCreatePop&&hasMethod('post')&&(!solo||selection?.isEmpty())">
5353
<ec-icon name="add"></ec-icon>
5454
</a>
5555
<a (click)="entryListPop.show($event)" class="btn btn_clear" *ngIf="!config?.disableListPop&&hasMethod('get')&&!disabled">

packages/data/src/lib/resource-select/resource-select.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*ngIf="solo&&hasMethod('put')&&!selection?.isEmpty()">
3838
<ec-icon name="pencil"></ec-icon>
3939
</a>
40-
<a (click)="resourcePop.create()" class="btn btn_clear" *ngIf="!config?.disableCreatePop&&hasMethod('post')">
40+
<a (click)="resourcePop.create()" class="btn btn_clear" *ngIf="!disabled&&!config?.disableCreatePop&&hasMethod('post')">
4141
<ec-icon name="add"></ec-icon>
4242
</a>
4343
<a (click)="resourceListPop.show($event)" class="btn btn_clear" *ngIf="!config?.disableListPop&&hasMethod('get')&&!disabled">

packages/ui/src/lib/form/datetime/datetime.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="ec-datetime-picker">
22
<div class="input-group">
33
<input class="input" [value]="calendar.inputValue" (input)="calendar.input($event.target.value)"
4-
(focus)="calendarPop.show()" (blur)="calendarPop.hide()" [placeholder]="placeholder">
4+
(focus)="calendarPop.show()" (blur)="calendarPop.hide()" [placeholder]="placeholder" [disabled]="disabled">
55
<div class="input-group__addon">
66
<a (click)="calendarPop.toggle()">
77
<ec-icon name="calendar"></ec-icon>

packages/ui/src/lib/form/datetime/datetime.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class DatetimeComponent implements ControlValueAccessor {
3232
@Input() disableTime: boolean;
3333
/** The input's placeholder */
3434
@Input() placeholder = '';
35+
/** If true, the time cannot be changed */
36+
disabled: boolean;
3537

3638
/** Selects the given Date when the model changes. */
3739
writeValue(value: Date) {
@@ -48,4 +50,8 @@ export class DatetimeComponent implements ControlValueAccessor {
4850

4951
/** registerOnTouched implementation of ControlValueAccessor */
5052
registerOnTouched() {}
53+
54+
setDisabledState(isDisabled) {
55+
this.disabled = isDisabled;
56+
}
5157
}

packages/ui/src/lib/io/input/input.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { debounceTime } from 'rxjs/operators';
3030
export class InputComponent extends DynamicSlotComponent implements ControlValueAccessor, OnChanges {
3131
/** The belonging form group */
3232
@Input() group: FormGroup;
33+
/** If true, the input is readonly. Is set by ControlValueAccessor#setDisabled */
34+
disabled: FormGroup;
3335
/** The belonging form control. This is not required if you pass in a field and group. */
3436
@Input() control: AbstractControl;
3537
/** The changed ouput emits whenever the form control of the input changes. */
@@ -143,4 +145,8 @@ export class InputComponent extends DynamicSlotComponent implements ControlValue
143145
}
144146

145147
registerOnTouched() {}
148+
149+
setDisabledState(isDisabled) {
150+
this.disabled = isDisabled;
151+
}
146152
}

0 commit comments

Comments
 (0)