Skip to content

Commit 9143228

Browse files
authored
Feature/sem ex improvements (eclipse-esmf#132)
* Remove outdated code * Minor code clean-up * Correct adding date filter at *-FilterService * Fix date range filter format at *-FilterService
1 parent f61a5f6 commit 9143228

File tree

4 files changed

+52
-56
lines changed

4 files changed

+52
-56
lines changed

Diff for: src/ng-generate/components/shared/generators/services/filter/files/__name@dasherize__-filter.service.ts.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class <%= classify(name) %>FilterService {
320320
<% } %>
321321

322322
private createDateAsUTC(date: Date) {
323-
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
323+
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
324324
}
325325

326326
private getFormattedDate(theDate: string) {

Diff for: src/ng-generate/components/shared/generators/services/filter/index.ts

+42-46
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ const getChipLabelEnum = (filterProp: PropValue) => {
274274

275275
function getDateRemote(values: PropValue[]): string {
276276
const template = (value: any) => `
277-
this.applyFilterForTime(query, '${value.propertyName}');
277+
if(this.${value.propertyName}Group.valid) {
278+
const {fromControl, toControl} = this.${value.propertyName}Group.value;
279+
this.applySingleDateFilter(query, fromControl, toControl, '${value.propertyName}');
280+
}
278281
`;
279282

280283
const activeFilters = values.map(template).join('');
@@ -284,61 +287,54 @@ function getDateRemote(values: PropValue[]): string {
284287
${activeFilters}
285288
}
286289
287-
applyFilterForTime(query: AbstractLogicalNode, timeType: string): void {
290+
private applySingleDateFilter(query: AbstractLogicalNode, from: number, to: number, filterPropName: string): void {
288291
const conditions = [];
289-
const group = (this as any)[\`\${timeType}Group\`];
290-
291-
if (group.invalid) {
292-
return;
293-
}
294-
295-
const {fromControl, toControl} = group.value;
296-
297-
const startDateUTC: string | null = fromControl ? this.createDateAsUTC(new Date(fromControl)).toISOString() : null;
298-
let endDateUTC: Date | null = toControl ? this.createDateAsUTC(new Date(toControl)) : null;
292+
293+
const fromDateUTC: string | null = from ? this.createDateAsUTC(new Date(from)).toISOString() : null;
294+
let toDateUTC: string | null = null;
295+
let toDate: Date | null = to ? this.createDateAsUTC(new Date(to)) : null;
299296
300-
if (endDateUTC) {
301-
endDateUTC = new Date(endDateUTC.setHours(23, 59, 59, 999));
297+
if (toDate) {
298+
toDateUTC = this.createDateAsUTC(new Date(toDate.setHours(23, 59, 59, 999))).toISOString();
302299
}
303300
304-
if (startDateUTC) {
305-
conditions.push(new Ge(timeType, \`\${startDateUTC}\`));
301+
if (fromDateUTC) {
302+
conditions.push(new Ge(filterPropName, fromDateUTC));
306303
}
307-
if (endDateUTC) {
308-
conditions.push(new Le(timeType, \`\${endDateUTC.toISOString()}\`));
304+
if (toDateUTC) {
305+
conditions.push(new Le(filterPropName, toDateUTC));
309306
}
310307
if (conditions.length > 0) {
311-
query.addNode(conditions.length > 1 ? new And(conditions) : conditions[0]);
308+
query.addNode(conditions.length > 1 ? new And(conditions) : conditions[0]);
312309
}
313-
314-
let label = this.translateService.translate(\`${sharedOptions.translationPath}\${timeType}.preferredName\`);
315-
316-
if (startDateUTC && endDateUTC) {
317-
label += \`: \${this.getFormattedDate(startDateUTC)} - \${this.getFormattedDate(endDateUTC.toISOString())}\`;
318-
this.updateActiveFilters(timeType, label);
319-
} else if (endDateUTC) {
320-
label += \`: to \${this.getFormattedDate(endDateUTC.toISOString())}\`;
321-
this.updateActiveFilters(timeType, label);
322-
} else if (startDateUTC) {
323-
label += \`: from \${this.getFormattedDate(startDateUTC)}\`;
324-
this.updateActiveFilters(timeType, label);
325-
}
326-
}
327310
328-
updateActiveFilters(prop: string, label: string) {
329-
const filter = this.activeFilters.find(af => af.prop === prop);
330-
if (!filter) {
331-
this.activeFilters.push(<FilterType>{
332-
removable: true,
333-
type: FilterEnums.Date,
334-
label: label,
335-
prop: prop
336-
});
337-
} else {
338-
filter.label = label;
311+
// DCV-SPECIFIC: wrap the rest of the code in if condition to avoid chip list not updating or removing
312+
if (fromDateUTC || toDateUTC) {
313+
const filterIndex = this.activeFilters.findIndex(af => af.prop === filterPropName);
314+
315+
let label = this.translateService.translate('batch.v030.' + filterPropName + '.preferredName');
316+
317+
if (fromDateUTC && toDateUTC) {
318+
label += ' ' + this.getFormattedDate(fromDateUTC) + ' - ' + this.getFormattedDate(toDate.toISOString());
319+
} else if (toDateUTC) {
320+
label += ' to ' + this.getFormattedDate(toDate.toISOString());
321+
} else if (fromDateUTC) {
322+
label += ' from ' + this.getFormattedDate(fromDateUTC);
323+
}
324+
325+
if (filterIndex === -1) {
326+
this.activeFilters.push({
327+
removable: true,
328+
type: FilterEnums.Date,
329+
label,
330+
prop: filterPropName
331+
});
332+
} else {
333+
this.activeFilters[filterIndex].label = label;
334+
}
339335
}
340-
}
341-
`;
336+
}
337+
`;
342338
}
343339

344340
function getDateNotRemote(values: PropValue[]): string {

Diff for: src/ng-generate/components/shared/methods/remote-handling/requestData.ts.template

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ private requestData() {
109109
catchError((error: any) => {
110110
this.dataLoadError = false;
111111
<% if (options.componentType === 'card') { %>
112-
this.dataToShow = [];
113-
this.dataSource.data = [];
112+
this.dataSource.setData([]);
114113
<% } else { %>
115-
const dataToShow = [];
116114
this.dataSource.setData([]);
117115
<% } %>
118116

Diff for: src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.ts.template

+8-6
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,15 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
677677
}
678678
<% } %>
679679

680-
protected isAvailableRowAction(action: RowAction, rowData: <%= options.aspectModelTypeName %>): boolean {
681-
if (!this.actionResolvers || !this.actionResolvers[action]) {
682-
return true;
683-
}
680+
<% if (hasCustomRowActions) { %>
681+
protected isAvailableRowAction(action: RowAction, rowData: <%= options.aspectModelTypeName %>): boolean {
682+
if (!this.actionResolvers || !this.actionResolvers[action]) {
683+
return true;
684+
}
684685

685-
return this.actionResolvers[action](rowData) ?? true;
686-
}
686+
return this.actionResolvers[action](rowData) ?? true;
687+
}
688+
<% } %>
687689

688690
<% if (options.hasSearchBar) { %>
689691
private initializeHighlightConfig(): void {

0 commit comments

Comments
 (0)