017.1 Typescript Classes for the First View (Material UI) - chempkovsky/CS82ANGULAR GitHub Wiki
- 01 Run JavaScripts Wizard
- 01 First page of the Wizard
- 01 Second page of the Wizard
- 01 Third page of the Wizard
- 01 Fourth page of the Wizard
- 01 Batch Action dialog
- 01 After script finished
- 02 Run JavaScripts Wizard
- 02 First page of the Wizard
- 02 Second page of the Wizard
- 02 Third page of the Wizard
- 02 Fourth page of the Wizard
- 02 Batch Action dialog
- 02 After script finished
- 06 Run Visual Studio Code
- 06 Temporary Modify AppModule
- 06 Temporary Modify AppCmponentHtml
- 06 Modify PhbkDbContext
- 06 Run PhBkWebApp
- 06 Run Angular App
- 06 Remove Temporary Modification
PhbkPhoneTypeView
-View is our very first View.
- According to the agreement specified in the article 016 Naming the folders we have created two subfolders
Click to show the picture
- To generate interfaces
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/components/phbk-phone-type-view
of thesrc
-project (Angular project) and selectJavaScripts Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
Click to show the picture
- On the first page of the dialog the destination folder is shown. The destination folder is the folder in which the generated file will be created. Click
Next
-button
Click to show the picture
- On the second page of the Wizard we select DbContext that will be used to choose the entity for the View. Select PhBkContext.csproj and the PhBkContext class using the drop-down lists. Click
Next
-button.
Click to show the picture
- On the third page of the Wizard
- select the View for which we need to get the name
- in our case we have selected
PhbkPhoneTypeView
-View
- in our case we have selected
- select the View for which we need to get the name
Click to show the picture
- After
PhbkPhoneTypeView
-View selected- On the left panel click
UI List properties
-node- On the right panel you define the view of the tabled data
- with Up/Down buttons you define the order of the columns to be shown
- with
Shown
-checkboxes you define which columns will be available to the user - with
New Line
-checkboxes you define which columns will be shown by default
- On the right panel you define the view of the tabled data
- On the left panel click
Click to show the picture
- After
PhbkPhoneTypeView
-View selected- On the left panel click
UI Form properties
-node- On the right panel you define the view and functionality of the Add/Update/Delete/View Item forms
- with Up/Down buttons you define the order of the controls to be shown
- with
Shown
-checkboxes you define which properties will be available to the user - with
New Line
-checkboxes you define how to layout the controls on the form - with
Input type xxx
-combo-boxes you define which type of controls to use for each property of the current ModelView
- On the right panel you define the view and functionality of the Add/Update/Delete/View Item forms
- On the left panel click
Click to show the picture
-
Note:
-
SearchDialog
,Typeahead
andCombo
input types can only be applied when the property is used by master-detail relations
-
- After
UI Form properties
andUI List properties
are defined clickNext
-button and go to the Fourth page
Click to show the picture
- On the Fourth page of the Wizard click
batch processing
-button
Click to show the picture
- On the
Batch Action
-dialog of the Wizard- select
01100-Interfaces.json
- click
start
-button
- select
Click to show the picture
- After script finished
- close
Batch Action
-dialog - close
JavaScripts Wizard
-dialog
- close
- New
interfaces
-subfolder has been added- three files have been added
Click to show the picture
-
Only after script finished
-
UI Form properties
andUI List properties
settings becomes persistent. So you don't need to set them again the next script is executed.
-
- To generate interfaces
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/services/phbk-phone-type-view
of thesrc
-project (Angular project) and selectJavaScripts Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
Click to show the picture
- On the first page of the dialog the destination folder is shown. The destination folder is the folder in which the generated file will be created. Click
Next
-button
Click to show the picture
Repeat the actions of the 01 Second page of the Wizard
Repeat the actions of the 01 Third page of the Wizard
-
Note: you do not need to set up
UI Form properties
andUI List properties
again. After running any script, these settings become permanent and will be available the next time you run the wizard.
Repeat the actions of the 01 Fourth page of the Wizard
- On the
Batch Action
-dialog of the Wizard- select
01400-WebApiService.json
- click
start
-button
- select
Click to show the picture
- After script finished
- close
Batch Action
-dialog - close
JavaScripts Wizard
-dialog
- close
- New
interfaces
-subfolder has been added- two files have been added
Click to show the picture
-
Sform-component (search form) is a tabled presentation of the data for the given ModelView. With Sform-component the uses can define the search filter and send request for the data.
-
Sform-component is used by
- Sdlg-dialog
- Lform-component
- RList-component
- RDList-component
-
To generate Sform
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/components/phbk-phone-type-view
of thesrc
-project (Angular project) and selectJavaScripts Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
-
repeat the steps as they described at 01 Generating interfaces until
Batch Action dialog
-
Note: you do not need to set up
UI Form properties
andUI List properties
again.
-
Note: you do not need to set up
- On the Batch Action-dialog of the Wizard
- select 01420-SForm.json
- click start-button
Click to show the picture
- After script finished
- close
Batch Action
-dialog - close
JavaScripts Wizard
-dialog
- close
- New
interfaces
-subfolder has been added- seven files have been added
-
sform
-folder -
sdlg
-folder -
phbk-phone-type-view-s.module.ts
-file, which declares Angular module
-
- seven files have been added
Click to show the picture
- To generate SForm.module.service
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/services/phbk-phone-type-view
of the src-project (Angular project) and select JavaScripts Wizard menu item to open the Wizard dialog
- Run Visual Studio and Open
- repeat the steps as they described at 02 Generating service and datasource until
Batch Action dialog
-
Note: you do not need to set up
UI Form properties
andUI List properties
again.
-
Note: you do not need to set up
- On the Batch Action-dialog of the Wizard
- select 01420-SForm.module.service.json
- click start-button
- select 01420-SForm.module.service.json
- Aform, Uform, Dform, Vform are the components, which implement Add, Update, Delete, View item action
- To generate Aform, Uform, Dform, Vform
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/components/phbk-phone-type-view
of thesrc
-project (Angular project) and selectJavaScripts Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
- repeat the steps as they described at 01 Generating interfaces until
Batch Action dialog
-
Note: you do not need to set up
UI Form properties
andUI List properties
again.
-
Note: you do not need to set up
- On the Batch Action-dialog of the Wizard
- select 01500-Vform.json
- click start-button
- select 01502-Aform.json
- click start-button
- select 01504-Uform.json
- click start-button
- select 01506-Dform.json
- click start-button
- select 01500-Vform.json
- As a result
-
aform
andadlg
folders andphbk-phone-type-view-a.module.ts
have been created for AForm -
uform
andudlg
folders andphbk-phone-type-view-u.module.ts
have been created for UForm -
dform
andddlg
folders andphbk-phone-type-view-d.module.ts
have been created for DForm -
vform
andvdlg
folders andphbk-phone-type-view-v.module.ts
have been created for VForm
- To generate
XXX
Form.module.service- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/services/phbk-phone-type-view
of the src-project (Angular project) and select JavaScripts Wizard menu item to open the Wizard dialog
- Run Visual Studio and Open
- repeat the steps as they described at 02 Generating service and datasource until
Batch Action dialog
-
Note: you do not need to set up
UI Form properties
andUI List properties
again.
-
Note: you do not need to set up
- On the Batch Action-dialog of the Wizard
- select 01550-Vform.module.service.json
- click start-button
- select 01552-Aform.module.service.json
- click start-button
- select 01554-Uform.module.service.json
- click start-button
- select 01556-Dform.module.service.json
- click start-button
- select 01550-Vform.module.service.json
- Lform is a static form which
- uses SForm to show tabular data
- uses adlg, udlg, ddlg, vdlg to modify data items for the given view
- To generate Lform
- Run Visual Studio and Open
PhonebookSolution
solution - Right Click
src/app/components/phbk-phone-type-view
of thesrc
-project (Angular project) and selectJavaScripts Wizard
menu item to open the Wizard dialog
- Run Visual Studio and Open
- repeat the steps as they described at 01 Generating interfaces until
Batch Action dialog
-
Note: you do not need to set up
UI Form properties
andUI List properties
again.
-
Note: you do not need to set up
- On the Batch Action-dialog of the Wizard
- select 01600-Lform.json
- click start-button
- select 01600-Lform.json
- at first run
cmd
(command prompt) - with the command prompt execute the commands
- the last command has
.
(dot sign) at the end
- the last command has
C:\Users\yury>e:
E:\>cd E:\Development\PhonebookSolution\AngularPhonebook
E:\Development\PhonebookSolution\AngularPhonebook>code .
- with Visual Studio Code open
app.module.ts
-file- at the begining of the file add the line of code
import { PhbkPhoneTypeViewLModule } from './components/phbk-phone-type-view/phbk-phone-type-view-l.module';
- modify
imports: [...]
-section: Add reference ontoPhbkPhoneTypeViewLModule
-module.
imports: [
...
PhbkPhoneTypeViewLModule,
],
- with Visual Studio Code open
app.component.html
-file- at the end of the file
- comment
<router-outlet></router-outlet>
-line - add
<app-phbk-phone-type-view-lform></app-phbk-phone-type-view-lform>
-line
- comment
- at the end of the file
...
</mat-toolbar>
<!-- <router-outlet></router-outlet> -->
<app-phbk-phone-type-view-lform></app-phbk-phone-type-view-lform>
</mat-sidenav-content>
</mat-sidenav-container>
- With Visual Studio 2022 open the
PhbkDbContext.cs
-file ofPhBkContext.csproj
-project - Add the constructor to the class
- Modify
OnModelCreating(ModelBuilder modelBuilder)
-method
Click to show the code
public PhbkDbContext(DbContextOptions<PhbkDbContext> options)
: base(options)
{
Database.EnsureCreated();
}
...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PhbkPhoneType>().HasKey(p => p.PhoneTypeId);
modelBuilder.Entity<PhbkPhoneType>().HasData(new { PhoneTypeId = 1, PhoneTypeName = "Office phone", PhoneTypeDesc = "Office phone (one or more than one)" });
modelBuilder.Entity<PhbkPhoneType>().HasData(new { PhoneTypeId = 2, PhoneTypeName = "Home phone", PhoneTypeDesc = "Home phone (one or more than one)" });
modelBuilder.Entity<PhbkPhoneType>().HasData(new { PhoneTypeId = 3, PhoneTypeName = "Office mobile", PhoneTypeDesc = "Office mobile phone (one or more than one)" });
modelBuilder.Entity<PhbkPhoneType>().HasData(new { PhoneTypeId = 4, PhoneTypeName = "Personal mobile", PhoneTypeDesc = "Personal mobile phone (one or more than one)" });
}
- With Visual Studio 2022 launch
PhBkWebApp
-app
- save changes of the
app.module.ts
-file - save changes of the
app.component.html
-file - with Visual Studio Code open the terminal and run the command
ng serve -o
- Take a look at the picture:
Click to show the picture
The port of the request is equal to 4200
instead of 5165
, which is defined in the file assets/app-config.json
and which is expected.
http://localhost:4200/phbkphonetypeviewwebapi/getmanybyrepprim?phoneTypeIdOprtr=eq&page=0&pagesize=10
In the shared/services/app-glbl-settings.service.ts
-file find the getWebApiPrefix(vwNm: string): string
-method, which returns the port with a help of this._settings.config.webApiUrl
-property.
Click to show the code
constructor(private _snackBar: MatSnackBar, protected _settings: AppConfigService) {}
...
public getWebApiPrefix(vwNm: string): string {
let reslt: string = '';
if(!(vwNm === null)) {
if(!(vwNm === null)) {
//
// here: defining url by ViewName
//
reslt = this._settings.config.webApiUrl;
}
}
return reslt;
}
_settings
-param is of type AppConfigService
. AppConfigService
is defined In the shared/services/app-config.service.ts
- file:
Click to show the code
@Injectable()
export class AppConfigService {
public _appConfig: IAppConfig = {
webApiUrl: '',
securityUrl: '',
permissionWebApi: '',
};
constructor (private injector: Injector) { }
loadAppConfig() {
let http = this.injector.get(HttpClient);
firstValueFrom(http.get<IAppConfig>('/assets/app-config.json')).then((data) => {
this._appConfig = data;
}).catch(()=>{
console.warn("Error loading app-config.json, using envrionment file instead");
});
}
get config(): IAppConfig {
return this._appConfig;
}
}
-
Conclusion: there is not enough time to load the '/assets/app-config.json'-file before the
app-phbk-phone-type-view-lform
-component starts.
- Let's temporary modify
getWebApiPrefix()
-method in theshared/services/app-glbl-settings.service.ts
-file as it is shown below
Click to show the code
constructor(private _snackBar: MatSnackBar, protected _settings: AppConfigService) {}
...
public getWebApiPrefix(vwNm: string): string {
let reslt: string = '';
if(!(vwNm === null)) {
if(!(vwNm === null)) {
//
// here: defining url by ViewName
//
// reslt = this._settings.config.webApiUrl;
reslt = 'http://localhost:5165/';
}
}
return reslt;
}
- save changes of the
shared/services/app-glbl-settings.service.ts
-file - save changes of the
app.module.ts
-file - save changes of the
app.component.html
-file - start Angular project
- Here is a result
- the component is shown
-
Add/Update/Delete/View Item
-functions are avaiilable
Click to show the picture
- The layout of the forms is responsive
Click to show the picture
- filtering by Primary key
Click to show the picture
- full scan filtering.
- for the table with a few rows
full scan filtering
is acceptable. For the big tables we should deny such a functionality. After adding thesecurity feature
to the project we will shown how to do it without modifying the code. Removing fragments of code is not a good idea, sincefull scan filtering
may be useful for administrators and advanced users.
- for the table with a few rows
Click to show the picture
- stop running app
- Open
app.component.html
-file- uncomment
router-outlet
- remove
<app-phbk-phone-type-view-lform></app-phbk-phone-type-view-lform>
- the end of the file must be as follows:
- uncomment
Click to show the code
...
</mat-toolbar>
<router-outlet></router-outlet>
</mat-sidenav-content>
</mat-sidenav-container>
- Open
shared/services/app-glbl-settings.service.ts
-file and remove modification ofgetWebApiPrefix()
-method. It must be as follows:
Click to show the code
public getWebApiPrefix(vwNm: string): string {
let reslt: string = '';
if(!(vwNm === null)) {
if(!(vwNm === null)) {
//
// here: defining url by ViewName
//
reslt = this._settings.config.webApiUrl;
}
}
return reslt;
}
- Open
app.module.ts
-file and removeimport { PhbkPhoneTypeViewLModule } from ...
-operator. The line to be removed:
import { PhbkPhoneTypeViewLModule } from './components/phbk-phone-type-view/phbk-phone-type-view-l.module';
- Open
app.module.ts
-file and removePhbkPhoneTypeViewLModule
fromimports: [...]
-array. It must become as follows:
Click to show the code
...
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
AppMaterialModule,
AppFormatterModule,
AppFlexLayoutModule,
HttpClientModule,
],
...