Skip to content

Commit bfd6a9a

Browse files
committed
fix code style
1 parent 5aff64a commit bfd6a9a

File tree

5 files changed

+217
-201
lines changed

5 files changed

+217
-201
lines changed

apps/demos/Demos/Scheduler/Templates/Angular/app/app.component.html

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ <h3>DXCinema Show Times</h3>
44
<dx-scheduler
55
timeZone="America/Los_Angeles"
66
[dataSource]="data"
7-
[views]="['day', 'week', 'timelineDay']"
7+
[views]="views"
88
currentView="day"
99
[currentDate]="currentDate"
1010
[firstDayOfWeek]="0"
1111
[startDayHour]="9"
1212
[endDayHour]="23"
1313
[showAllDayPanel]="false"
1414
[height]="600"
15-
[groups]="['theatreId']"
15+
[groups]="groups"
1616
[crossScrollingEnabled]="true"
1717
[cellDuration]="20"
1818
appointmentTemplate="appointment-template"
@@ -30,49 +30,34 @@ <h3>DXCinema Show Times</h3>
3030

3131
<dxo-scheduler-editing
3232
[allowAdding]="false"
33-
[popup]="{
34-
maxWidth: 440,
35-
onOptionChanged: onPopupOptionChanged
36-
}"
33+
[popup]="popupOptions"
3734
>
38-
<dxo-scheduler-form [onInitialized]="onFormInitialized">
35+
<dxo-scheduler-form (onInitialized)="onFormInitialized($event)">
3936
<dxi-scheduler-item
4037
template="movie-info-form-template"
4138
></dxi-scheduler-item>
4239

4340
<dxi-scheduler-item
4441
itemType="group"
4542
[colCount]="2"
46-
[colCountByScreen]="{ xs: 2 }"
43+
[colCountByScreen]="colCountByScreen"
4744
>
4845
<dxi-scheduler-item
4946
dataField="movieId"
5047
editorType="dxSelectBox"
51-
[label]="{ text: 'Movie' }"
5248
[colSpan]="1"
53-
[editorOptions]="{
54-
items: moviesData,
55-
displayExpr: 'text',
56-
valueExpr: 'id',
57-
stylingMode: getEditorStylingMode(),
58-
onValueChanged: onMovieValueChanged,
59-
onContentReady: onMovieEditorContentReady
60-
}"
49+
[editorOptions]="movieEditorOptions"
6150
>
51+
<dxi-scheduler-label>Movie</dxi-scheduler-label>
6252
</dxi-scheduler-item>
6353

6454
<dxi-scheduler-item
6555
dataField="price"
6656
editorType="dxSelectBox"
67-
[label]="{ text: 'Price' }"
6857
[colSpan]="1"
69-
[editorOptions]="{
70-
items: [5, 10, 15, 20],
71-
displayExpr: priceDisplayExpr,
72-
stylingMode: getEditorStylingMode(),
73-
onContentReady: onPriceEditorContentReady
74-
}"
58+
[editorOptions]="priceEditorOptions"
7559
>
60+
<dxi-scheduler-label>Price</dxi-scheduler-label>
7661
</dxi-scheduler-item>
7762
</dxi-scheduler-item>
7863

apps/demos/Demos/Scheduler/Templates/Angular/app/app.component.ts

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,43 @@ export class AppComponent {
4646

4747
theatreData: TheatreData[];
4848

49+
views: string[] = ['day', 'week', 'timelineDay'];
50+
51+
groups: string[] = ['theatreId'];
52+
4953
formInstance: dxForm | null = null;
5054

5155
currentSelectedMovie: MovieData | null = null;
5256

57+
movieEditorOptions: DxSelectBoxTypes.Options;
58+
59+
priceEditorOptions: DxSelectBoxTypes.Options;
60+
5361
constructor(service: Service) {
5462
this.data = service.getData();
5563
this.moviesData = service.getMoviesData();
5664
this.theatreData = service.getTheatreData();
65+
66+
this.movieEditorOptions = {
67+
items: this.moviesData,
68+
displayExpr: 'text',
69+
valueExpr: 'id',
70+
stylingMode: this.getEditorStylingMode(),
71+
onValueChanged: this.onMovieValueChanged,
72+
onContentReady: this.onCustomEditorContentReady,
73+
};
74+
75+
this.priceEditorOptions = {
76+
items: [5, 10, 15, 20],
77+
displayExpr: this.priceDisplayExpr,
78+
stylingMode: this.getEditorStylingMode(),
79+
onContentReady: this.onCustomEditorContentReady,
80+
};
5781
}
5882

59-
getMovieById = (id: number): MovieData | undefined => query(this.moviesData).filter(['id', '=', id]).toArray()[0];
83+
getMovieById = (id: number | undefined): MovieData | undefined => id
84+
? query(this.moviesData).filter(['id', '=', id]).toArray()[0]
85+
: null;
6086

6187
getEditorStylingMode = (): 'filled' | 'outlined' => {
6288
const isMaterialOrFluent = document.querySelector('.dx-theme-fluent, .dx-theme-material');
@@ -65,23 +91,7 @@ export class AppComponent {
6591

6692
priceDisplayExpr = (value: number): string => `$${value}`;
6793

68-
onMovieValueChanged = (e: DxSelectBoxTypes.ValueChangedEvent): void => {
69-
const movie = this.getMovieById(e.value);
70-
this.currentSelectedMovie = movie;
71-
72-
if (this.formInstance && movie) {
73-
this.formInstance.updateData('director', movie.director);
74-
this.updateEndDate(this.formInstance, movie);
75-
}
76-
};
77-
78-
onMovieEditorContentReady = (e: DxSelectBoxTypes.ContentReadyEvent): void => {
79-
e.component.option('stylingMode', this.getEditorStylingMode());
80-
};
81-
82-
onPriceEditorContentReady = (e: DxSelectBoxTypes.ContentReadyEvent): void => {
83-
e.component.option('stylingMode', this.getEditorStylingMode());
84-
};
94+
colCountByScreen = { xs: 2 };
8595

8696
onPopupOptionChanged = (e: DxPopupTypes.OptionChangedEvent): void => {
8797
if (e.fullName === 'toolbarItems' && e.value) {
@@ -93,39 +103,55 @@ export class AppComponent {
93103
}
94104
};
95105

96-
updateEndDate = (form: dxForm, movie: MovieData): void => {
106+
popupOptions: DxPopupTypes.Options = {
107+
maxWidth: 440,
108+
onOptionChanged: this.onPopupOptionChanged,
109+
};
110+
111+
updateEndDate = (movie: MovieData): void => {
112+
const form = this.formInstance!;
97113
const formData = form.option('formData');
98114
const { startDate } = formData;
99-
if (startDate && movie?.duration) {
115+
116+
if (startDate) {
100117
const newEndDate = new Date(startDate.getTime() + 60 * 1000 * movie.duration);
101118
form.updateData('endDate', newEndDate);
102119
}
103120
};
104121

105122
onFormInitialized = (e: DxFormTypes.InitializedEvent): void => {
123+
console.log('form initialized');
106124
const form = e.component;
107-
this.formInstance = form;
108-
109125
const formData = form.option('formData');
110-
if (formData?.movieId) {
111-
const movie = this.getMovieById(formData.movieId);
112-
this.currentSelectedMovie = movie;
113-
} else {
114-
this.currentSelectedMovie = null;
115-
}
126+
127+
this.formInstance = form;
128+
this.currentSelectedMovie = this.getMovieById(formData?.movieId);
116129

117130
form.on('fieldDataChanged', (fieldEvent: DxFormTypes.FieldDataChangedEvent) => {
118131
if (fieldEvent.dataField === 'startDate') {
119132
const currentFormData = form.option('formData');
120-
if (currentFormData.movieId) {
121-
const movie = this.getMovieById(currentFormData.movieId);
122-
if (movie) {
123-
this.updateEndDate(form, movie);
124-
}
133+
const movie = this.getMovieById(currentFormData?.movieId);
134+
135+
if (movie) {
136+
this.updateEndDate(movie);
125137
}
126138
}
127139
});
128140
};
141+
142+
onMovieValueChanged = (e: DxSelectBoxTypes.ValueChangedEvent): void => {
143+
const movie = this.getMovieById(e.value);
144+
this.currentSelectedMovie = movie;
145+
146+
if (movie) {
147+
this.formInstance.updateData('director', movie.director);
148+
this.updateEndDate(movie);
149+
}
150+
};
151+
152+
onCustomEditorContentReady = (e: DxSelectBoxTypes.ContentReadyEvent): void => {
153+
e.component.option('stylingMode', this.getEditorStylingMode());
154+
};
129155
}
130156

131157
@NgModule({

0 commit comments

Comments
 (0)