Skip to content

Commit 4d65dfb

Browse files
committed
Make TableService generic
RemoteTableService and StaticTableService are generic. CustomRemoteTableService if generated on request
1 parent cb0dac4 commit 4d65dfb

File tree

19 files changed

+564
-235
lines changed

19 files changed

+564
-235
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/** <%= options.generationDisclaimerText %> **/
2+
<%
3+
var serviceName = options.enableRemoteDataHandling ? 'RemoteTableService' : 'StaticTableService';
4+
%>
25
import {Injectable} from '@angular/core';
3-
import {HttpClient} from '@angular/common/http';
4-
import {<%= classify(options.name) %>Service} from './<%= dasherize(options.name) %>.service';
5-
import { TranslocoService } from '@jsverse/transloco';
6+
import {<%= serviceName %>} from '@esmf/semantic-ui-schematic';
67

78
/**
89
* Custom service which extend the original API service for fetching
@@ -14,11 +15,5 @@ import { TranslocoService } from '@jsverse/transloco';
1415
* generating the table component again, also in combination with
1516
* the cli parameter '--force'.
1617
*/
17-
@Injectable({
18-
providedIn: 'root'
19-
})
20-
export class Custom<%= classify(options.name) %>Service extends <%= classify(options.name) %>Service {
21-
constructor(http: HttpClient, translationService: TranslocoService) {
22-
super(http, translationService);
23-
}
24-
}
18+
@Injectable()
19+
export class Custom<%= classify(options.name) %>Service<T> extends <%= serviceName %><T> {}

libs/schematic/generators/ng-generate/components/shared/generators/services/general/files/__name@dasherize__.service.ts.template

Lines changed: 0 additions & 104 deletions
This file was deleted.

libs/schematic/generators/ng-generate/components/shared/generators/services/general/index.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

libs/schematic/generators/ng-generate/components/shared/generators/services/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,3 @@
1313

1414
export * from './custom/index';
1515
export * from './filter/index';
16-
export * from './general/index';
17-
export * from './paginator-select-config/index';

libs/schematic/generators/ng-generate/components/shared/generators/services/paginator-select-config/files/paginator-select-config.provider.ts.template

Lines changed: 0 additions & 15 deletions
This file was deleted.

libs/schematic/generators/ng-generate/components/shared/generators/services/paginator-select-config/index.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

libs/schematic/generators/ng-generate/components/shared/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import ora from 'ora';
3030
import {
3131
generateCustomService,
3232
generateFilterService,
33-
generateGeneralService,
3433
generateGeneralStyle,
3534
generateHorizontalOverflowDirective,
3635
generateShowDescriptionPipe,
@@ -240,7 +239,6 @@ export function generateGeneralFilesRules(): Array<Rule> {
240239
generateGeneralStyle(options),
241240
generateTranslationFiles(options, false),
242241
wrapBuildComponentExecution(options),
243-
generateGeneralService(options),
244242
generateCustomService(options),
245243
generateValidateInputDirective(options),
246244
generateHorizontalOverflowDirective(options),
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import {<% if (options.customRemoteService) { %>Custom<% } %><%= classify(options.name) %>Service} from './<% if (options.customRemoteService) { %>custom<% } %>-<%= dasherize(options.name) %>.service';
1+
<% if (options.customRemoteService) { %>
2+
import {Custom<%= classify(name) %>Service} from './custom-<%= dasherize(name) %>.service';
3+
<% } else { %>
4+
import {RemoteTableService} from '@esmf/semantic-ui-schematic';
5+
<% } %>
6+
27
import {<%= options.aspectModel.name %>Response} from './<%= dasherize(options.name) %>.service';
38
import {AbstractArrayNode, AbstractNode, And, Eq, Limit, Query, QueryStringifier, Sort} from 'rollun-ts-rql';
49
import {SortOptions} from "rollun-ts-rql/dist/nodes/Sort";

libs/schematic/generators/ng-generate/components/shared/methods/remote-handling/requestData.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private requestData() {
8484
this.requestSubscription.unsubscribe();
8585
}
8686

87-
this.requestSubscription = this.<%= camelize((options.customRemoteService ? 'custom' : '') + '-' + options.name) %>Service.requestData(this.remoteAPI, {query: rqlStringTemp})
87+
this.requestSubscription = this.tableService.requestData(this.remoteAPI, {query: rqlStringTemp})
8888
.pipe(
8989
tap((movementResponse: <%= classify(options.aspectModel.name) %>Response) => {
9090
this.dataLoadError = false;

libs/schematic/generators/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.ts.template

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
var cmpFileName = dasherize(name);
55
var hasCustomRowActions = options.customRowActions.length > 0;
66
var customRowActionNames = options.customRowActions.map(action => `'${action.replace(/\.[^/.]+$/, '')}'`);
7+
var tableServiceName = options.enableRemoteDataHandling ? (options.customRemoteService ? `Custom${classify(name)}Service` : 'RemoteTableService') : 'StaticTableService';
78
%>
89
import {
910
AfterViewInit,
@@ -21,6 +22,7 @@ import {
2122
TemplateRef,
2223
ElementRef,
2324
ViewEncapsulation,
25+
inject,
2426
<% if (options.enableRemoteDataHandling || options.hasSearchBar) { %>OnDestroy,<% } %>
2527
<% if (options.changeDetection) { %>ChangeDetectionStrategy,<% } %>
2628
} from '@angular/core';
@@ -29,7 +31,7 @@ import { MatSort, SortDirection } from '@angular/material/sort';
2931
import { MatTable } from '@angular/material/table';
3032

3133
<% if (options.hasFilters || options.hasSearchBar) { %>
32-
import { FilterEnums, <%= options.filterServiceName %>} from './<%= dasherize(name) %>-filter.service';
34+
import { FilterEnums, <%= options.filterServiceName %>} from './<%= cmpFileName %>-filter.service';
3335
<% } %>
3436

3537
<% if (options.addCommandBar) { %>
@@ -47,7 +49,7 @@ import {
4749
, <%= enumProperties %>
4850
<% } %>
4951
} from '<%= options.typePath %>';
50-
import {<%= classify(name) %>DataSource} from './<%= dasherize(name) %>-datasource';
52+
import {<%= classify(name) %>DataSource} from './<%= cmpFileName %>-datasource';
5153

5254
<% if (options.isDateQuickFilter) { %>
5355
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
@@ -62,11 +64,11 @@ import {SelectionModel} from '@angular/cdk/collections';
6264
import { TranslocoService } from '@jsverse/transloco';
6365
import {PaginatorSelectConfigInjector} from "<% if (options.enableVersionSupport) { %>../<% } %>../../services/paginator-select-config.provider";
6466
import {JSSdkLocalStorageService} from "<% if (options.enableVersionSupport) { %>../<% } %>../../services/storage.service";
65-
import {<%= classify(name) %>CommandBarComponent} from "./<%= dasherize(name) %>-command-bar.component";
66-
import {<%= classify(name) %>ColumnMenuComponent} from './<%= dasherize(name) %>-column-menu.component';
67+
import {<%= classify(name) %>CommandBarComponent} from "./<%= cmpFileName %>-command-bar.component";
68+
import {<%= classify(name) %>ColumnMenuComponent} from './<%= cmpFileName %>-column-menu.component';
6769

6870
<% if (options.hasSearchBar) { %>
69-
import {<%= classify(name) %>ConfigMenuComponent} from './<%= dasherize(name) %>-config-menu.component';
71+
import {<%= classify(name) %>ConfigMenuComponent} from './<%= cmpFileName %>-config-menu.component';
7072
<% } %>
7173

7274
<% if (options.hasFilters) { %>
@@ -83,7 +85,9 @@ import {<% if (options.enableRemoteDataHandling) { %>catchError, finalize, tap,
8385
<%= options.include('/remote-handling/imports.ts.template') %>
8486
<%= options.include('/remote-handling/custom-rql-filter-extensions.ts.template') %>
8587
<% } else { %>
86-
import {<%= classify(name) %>Service, <%= classify(aspectModelName) %>Response} from './<%= dasherize(name) %>.service';
88+
// TODO remove the commented line bellow
89+
// import {<%= classify(name) %>Service, <%= classify(aspectModelName) %>Response} from './<%= cmpFileName %>.service';
90+
import {StaticTableService} from '@esmf/semantic-ui-schematic';
8791
<% } %>
8892

8993
<% if (options.hasSearchBar) { %>
@@ -119,13 +123,18 @@ export const NON_DATA_COLUMNS: <%= tableColumnsEnumName %>[] = [
119123

120124
@Component({
121125
selector: '<%= options.selector %>',
122-
templateUrl: './<%= dasherize(name) %>.component.html',
123-
styleUrls: ['./<%= dasherize(name) %>.component.<%= options.style %>'],
126+
templateUrl: './<%= cmpFileName %>.component.html',
127+
styleUrls: ['./<%= cmpFileName %>.component.<%= options.style %>'],
128+
providers: [
129+
<%= tableServiceName %>
130+
],
124131
standalone: false
125132
<% if (options.changeDetection) { %>, changeDetection: ChangeDetectionStrategy.<%= options.changeDetection %><% } %>
126133
<% if (options.viewEncapsulation) { %>,encapsulation: ViewEncapsulation.<%= options.viewEncapsulation %><% } else { %>,encapsulation: ViewEncapsulation.None<% } %>
127134
})
128135
export class <%= classify(name) %>Component implements OnInit, AfterViewInit, AfterViewChecked, OnChanges<% if (options.hasSearchBar || options.enableRemoteDataHandling) { %>, OnDestroy<% } %> {
136+
private tableService = inject(<%= tableServiceName %><<%= options.aspectModelTypeName %>>);
137+
129138
<% if (options.hasSearchBar) { %>@Input() initialSearchString = '';<% } %>
130139
<%= customRowActionInput %>
131140
<% if (options.dateProperties) { %>@Input() tableDateFormat = 'short';<% } %>
@@ -253,14 +262,14 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
253262
private requestSubscription: Subscription = new Subscription();
254263
<% } %>
255264

265+
256266
<% if (options.enableRemoteDataHandling) { %>
257-
constructor(<%= commonImports %>
258-
private <% if (options.customRemoteService) { %>custom<% } %><%= classify(name) %>Service: <% if (options.customRemoteService) { %>Custom<% } %><%= classify(name) %>Service) {
267+
constructor(<%= commonImports %>) {
259268
this.dataSource = new <%= classify(name) %>DataSource();
260269
<%= sharedCustomRows %>
261270
}
262271
<% } else { %>
263-
constructor(<%= commonImports %> private <%= camelize(name) %>Service: <%= classify(name) %>Service) {
272+
constructor(<%= commonImports %>) {
264273
this.dataSource = new <%= classify(name) %>DataSource(this.translateService);
265274
<%= sharedCustomRows %>
266275
}

0 commit comments

Comments
 (0)