Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 43f8eea

Browse files
committed
feat(srcgen): Change "web-grid" to "web-entity" and update template for rucken@2.0.0
1 parent 4792340 commit 43f8eea

59 files changed

Lines changed: 545 additions & 830 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/bin/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ export class App {
112112
await (new MakeTsListCommand(_.merge(this.program, command, dummy))).process();
113113
});
114114
this.program
115-
.command('grid')
116-
.option('-t, --template [name]', 'template folder name or path', 'web-grid')
115+
.command('entity')
116+
.option('-t, --template [name]', 'template folder name or path', 'web-entity')
117117
.option('-n, --entity-name [name]', 'entity name')
118118
.option('-p, --pk-field [name]', 'primary key name', 'id')
119119
.option('-f, --fields [names]', 'fields of entity', '\'name\',\'title\',\'createdAt\',\'updatedAt\'')
@@ -124,7 +124,7 @@ export class App {
124124
.option('-pf, --platform-folder [path]', 'platform library path')
125125
.description('scaffold model, service, grid, lookup input, modal for edit row in grid, modal for select items from grid with items')
126126
.action(async (dummy, command) => {
127-
await (new GeneratorCommand(_.merge(this.program, command, dummy))).processGrid();
127+
await (new GeneratorCommand(_.merge(this.program, command, dummy))).processEntity();
128128
});
129129
this.program
130130
.command('page')

src/commands/generator.command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FrameGenerator } from '../generators/frame';
2-
import { GridGenerator } from '../generators/grid';
2+
import { EntityGenerator } from '../generators/entity';
33
import { PageGenerator } from '../generators/page';
44
import { PageAndFrameGenerator } from '../generators/page-and-frame';
55
import { BaseCommand } from './base.command';
@@ -9,9 +9,9 @@ export class GeneratorCommand extends BaseCommand {
99
constructor(public options: any) {
1010
super(options);
1111
}
12-
async processGrid() {
12+
async processEntity() {
1313
this.log('generator').info('Run generator for ' + this.rootFolder);
14-
const gen = new GridGenerator(this.rootFolder);
14+
const gen = new EntityGenerator(this.rootFolder);
1515
gen.debug = this.debug;
1616
const result = false;
1717
return await new Promise<boolean>((resolve: any) =>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { Base } from '../lib/base';
66
import { Project } from '../lib/project';
77

88

9-
export class GridGenerator extends Base {
9+
export class EntityGenerator extends Base {
1010

11-
name = 'grid';
11+
name = 'entity';
1212

1313
constructor(public rootFolder?: string) {
1414
super(null, rootFolder);
@@ -53,7 +53,7 @@ export class GridGenerator extends Base {
5353
(customOptions && customOptions.project.libsConfigs[1] && customOptions &&
5454
customOptions.project.libsConfigs[1].localPath) ?
5555
customOptions && customOptions.project.libsConfigs[1].localPath : 'web';
56-
let template: string = 'web-grid';
56+
let template: string = 'web-entity';
5757
let pkField: string = 'id';
5858
let fields: string[] = [
5959
'name',
@@ -111,7 +111,7 @@ export class GridGenerator extends Base {
111111
'coreFolder': coreFolder,
112112
'platformFolder': platformFolder
113113
},
114-
'grid': {
114+
'entity': {
115115
'list': {
116116
'name': {
117117
'kebab': _.kebabCase(inflection.pluralize(entityName)),
@@ -151,7 +151,7 @@ export class GridGenerator extends Base {
151151
);
152152
return await this.srcgen(
153153
rootFolder,
154-
'generatorGrid',
154+
'generatorEntity',
155155
template,
156156
options,
157157
rootFolder
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Injectable } from '@angular/core';
2+
import { plainToClass } from 'class-transformer';
3+
import { IRestProviderOptions, PaginationMeta, ProviderActionEnum } from 'ngx-repository';
4+
import { <%=entity.name.camel%> } from '../models/<%=entity.name.kebab%>';
5+
6+
@Injectable()
7+
export class <%=entity.list.name.camel%>Config implements IRestProviderOptions<Permission> {
8+
name = '<%=entity.name.snake%>';
9+
pluralName = '<%=entity.list.name.snake%>';
10+
autoload = true;
11+
paginationMeta = {
12+
perPage: 5
13+
};
14+
actionOptions = {
15+
responseData: (data: any, action: ProviderActionEnum) => {
16+
if (action === ProviderActionEnum.Delete) {
17+
return true;
18+
} else {
19+
if (action === ProviderActionEnum.LoadAll) {
20+
return plainToClass(<%=entity.name.camel%>, data.body.<%=entity.list.name.lower.camel%>);
21+
} else {
22+
return plainToClass(<%=entity.name.camel%>, data.body.<%=entity.name.lower.camel%>);
23+
}
24+
}
25+
},
26+
responsePaginationMeta: (data: any, action: ProviderActionEnum): PaginationMeta => {
27+
return { totalResults: data.body.meta.totalResults, perPage: undefined };
28+
}
29+
};
30+
restOptions = {
31+
limitQueryParam: 'per_page',
32+
pageQueryParam: 'cur_page',
33+
searchTextQueryParam: 'q'
34+
};
35+
constructor() { }
36+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { IModel } from 'ngx-repository';
2+
import { translate } from '@rucken/core';
3+
4+
export class <%=entity.name.camel%> extends IModel {
5+
static strings: any = {
6+
<%=entity.table.pk.name %>: translate('<%=_.upperFirst(entity.table.pk.name)%>'),
7+
<%for (var i = 0; i < entity.table.fields.names.length; i++) {%> <%=entity.table.fields.names[i] + ': translate(\'' + _.upperFirst(entity.table.fields.names[i]) + '\'),\n' %><%}%>
8+
};
9+
10+
<%=entity.table.pk.name %>: <%=entity.table.pk.name === 'id' ? 'number' : 'string' %>;
11+
<%for (var i = 0; i < entity.table.fields.names.length; i++) { if (entity.table.fields.dates.indexOf(entity.table.fields.names[i]) === -1) {%> <%=entity.table.fields.names[i] + ': string;\n' %><%}else {%> <%=entity.table.fields.names[i] + ': Date;\n' %><%}}%>
12+
toString() {
13+
return this.title;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<entity-grid-modal [title]="title" [yesTitle]="yesTitle" [readonly]="readonly" [disabled]="!(grid?.selected?.length>0)" [noTitle]="noTitle"
2+
(yes)="onYesClick()" (no)="onNoClick()" [processing]="processing">
3+
<<%=entity.list.name.kebab%>-grid [apiUrl]="apiUrl" #grid>
4+
</<%=entity.list.name.kebab%>-grid>
5+
</entity-grid-modal>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Component, Input, ViewChild } from '@angular/core';
2+
import { <%=entity.name.camel%> } from '<%=libs.core%>';
3+
import { BsModalRef } from 'ngx-bootstrap/modal';
4+
import { BaseEntityListModalComponent } from '@rucken/core';
5+
import { <%=entity.list.name.camel%>GridComponent } from '../<%=entity.list.name.kebab%>-grid/<%=entity.list.name.kebab%>-grid.component';
6+
7+
@Component({
8+
selector: '<%=entity.list.name.kebab%>-grid-modal',
9+
templateUrl: './<%=entity.list.name.kebab%>-grid-modal.component.html'
10+
})
11+
export class <%=entity.list.name.camel%>GridModalComponent extends BaseEntityListModalComponent<<%=entity.name.camel%>> {
12+
13+
@ViewChild('grid')
14+
grid: <%=entity.list.name.camel%>GridComponent;
15+
@Input()
16+
apiUrl?: string;
17+
18+
constructor(
19+
protected bsModalRef: BsModalRef
20+
) {
21+
super(bsModalRef);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { CommonModule } from '@angular/common';
2+
import { ModuleWithProviders, NgModule } from '@angular/core';
3+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4+
import { TranslateModule } from '@ngx-translate/core';
5+
import { EntityGridModalModule } from '@rucken/core';
6+
import { <%=entity.list.name.camel%>GridModule } from '../<%=entity.list.name.kebab%>-grid/<%=entity.list.name.kebab%>-grid.module';
7+
import { <%=entity.list.name.camel%>GridModalComponent } from './<%=entity.list.name.kebab%>-grid-modal.component';
8+
9+
@NgModule({
10+
imports: [
11+
CommonModule,
12+
ReactiveFormsModule,
13+
FormsModule,
14+
TranslateModule.forChild(),
15+
EntityGridModalModule,
16+
<%=entity.list.name.camel%>GridModule
17+
],
18+
declarations: [
19+
<%=entity.list.name.camel%>GridModalComponent
20+
],
21+
entryComponents: [
22+
<%=entity.list.name.camel%>GridModalComponent
23+
],
24+
exports: [
25+
<%=entity.list.name.camel%>GridModalComponent
26+
]
27+
})
28+
export class <%=entity.list.name.camel%>GridModalModule {
29+
static forRoot(): ModuleWithProviders {
30+
return {
31+
ngModule: <%=entity.list.name.camel%>GridModalModule,
32+
providers: []
33+
};
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<entity-grid title="<%=entity.list.name.caption%>" [items]="repository.items$ | async" [(selected)]="selected"
2+
[columns]="['<%=entity.table.fields.names.join('\',\'')%>', 'action']" [readonly]="readonly" [strings]="strings" (create)="onCreateClick()" (update)="onUpdateClick($event)"
3+
(delete)="onDeleteClick($event)" (view)="onViewClick($event)" (search)="onChangeFilter({searchText:$event})" (changeOrder)="onChangeFilter({sort:$event})"
4+
[paginationMeta]="repository.paginationMeta$ | async" [enableCreate]="'add_<%=entity.name.kebab%>' | perm | async" [enableUpdate]="'change_<%=entity.name.kebab%>' | perm | async"
5+
[enableDelete]="'delete_<%=entity.name.kebab%>' | perm | async" (changePage)="onChangePage($event)" [processing]="processing">
6+
</entity-grid>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
3+
import { ErrorsExtractor, translate } from '@rucken/core';
4+
import { <%=entity.name.camel%>, <%=entity.list.name.camel%>Config } from '<%=libs.core%>';
5+
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
6+
import { DynamicRepository, PaginationMeta } from 'ngx-repository';
7+
import { BaseEntityListComponent } from '@rucken/core';
8+
import { <%=entity.name.camel%>ModalComponent } from '../<%=entity.name.kebab%>-modal/<%=entity.name.kebab%>-modal.component';
9+
10+
11+
@Component({
12+
selector: '<%=entity.list.name.kebab%>-grid',
13+
templateUrl: './<%=entity.list.name.kebab%>-grid.component.html'
14+
})
15+
export class <%=entity.list.name.camel%>GridComponent extends BaseEntityListComponent<<%=entity.name.camel%>> implements OnInit {
16+
17+
public paginationMeta: PaginationMeta;
18+
constructor(
19+
public modalService: BsModalService,
20+
protected errorsExtractor: ErrorsExtractor,
21+
protected translateService: TranslateService,
22+
protected dynamicRepository: DynamicRepository,
23+
protected <%=entity.list.name.lower.camel%>Config: <%=entity.list.name.camel%>Config
24+
) {
25+
super(
26+
dynamicRepository.fork<<%=entity.name.camel%>>(<%=entity.name.camel%>),
27+
modalService,
28+
<%=entity.name.camel%>
29+
);
30+
}
31+
ngOnInit() {
32+
if (!this.mockedItems) {
33+
this.repository.useRest({
34+
apiUrl: this.apiUrl,
35+
...this.<%=entity.list.name.lower.camel%>Config
36+
});
37+
}
38+
if (this.mockedItems) {
39+
this.repository.useMock({
40+
items: this.mockedItems,
41+
...this.<%=entity.list.name.lower.camel%>Config
42+
});
43+
}
44+
}
45+
createDeleteModal(item: <%=entity.name.camel%>): BsModalRef {
46+
return this.modalService.show(<%=entity.name.camel%>ModalComponent, {
47+
class: 'modal-md',
48+
initialState: {
49+
title: this.strings.deleteTitle,
50+
message: this.strings.deleteMessage,
51+
yesTitle: translate('Delete'),
52+
data: item,
53+
apiUrl: this.apiUrl
54+
}
55+
});
56+
}
57+
createCreateModal(): BsModalRef {
58+
const item = new <%=entity.name.camel%>();
59+
return this.modalService.show(<%=entity.name.camel%>ModalComponent, {
60+
class: 'modal-md',
61+
initialState: {
62+
title: this.strings.createTitle,
63+
yesTitle: translate('Create'),
64+
data: item,
65+
apiUrl: this.apiUrl
66+
}
67+
});
68+
}
69+
createUpdateModal(item?: <%=entity.name.camel%>): BsModalRef {
70+
return this.modalService.show(<%=entity.name.camel%>ModalComponent, {
71+
class: 'modal-md',
72+
initialState: {
73+
title: this.strings.updateTitle,
74+
yesTitle: translate('Save'),
75+
data: item,
76+
apiUrl: this.apiUrl
77+
}
78+
});
79+
}
80+
createViewModal(item?: <%=entity.name.camel%>): BsModalRef {
81+
return this.modalService.show(<%=entity.name.camel%>ModalComponent, {
82+
class: 'modal-md',
83+
initialState: {
84+
title: this.strings.viewTitle,
85+
noTitle: translate('Close'),
86+
readonly: true,
87+
data: item,
88+
apiUrl: this.apiUrl
89+
}
90+
});
91+
}
92+
}

0 commit comments

Comments
 (0)