Skip to content

Commit 07eaad2

Browse files
committed
update schema.json
1 parent 6f375c9 commit 07eaad2

474 files changed

Lines changed: 9364 additions & 6334 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.

.github/workflows/publish.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
jobs:
99
publish:
1010
runs-on: ubuntu-latest
11+
1112
steps:
1213
- name: ⬇️ Checkout
1314
uses: actions/checkout@v3
@@ -17,15 +18,20 @@ jobs:
1718
with:
1819
node-version: 18
1920
registry-url: https://npm.pkg.github.com/
20-
scope: "@your-scope"
21+
scope: "@ktrdev2020"
22+
23+
- name: 📦 Install dependencies
24+
run: npm install
25+
26+
- name: 🧱 Build schematic
27+
run: npm run build
2128

22-
- name: 🛠 Install & Test
29+
- name: ✅ Test schematic locally
2330
run: |
2431
npm install -g @angular-devkit/schematics-cli
25-
npm install
26-
schematics .:crud --name=test --model="id:number,name:string"
32+
schematics ./dist:crud --name=test --model="id:number,name:string"
2733
28-
- name: 🚀 Publish to GitHub Packages (GHCR)
34+
- name: 🚀 Publish to GHCR
2935
run: npm publish
3036
env:
3137
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
.npmrc
2-
.npmrc
3-
.npmrc

crud/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
{
32
"$schema": "http://json-schema.org/schema",
4-
"id": "CrudSchema",
3+
"$id": "CrudSchema",
54
"title": "Crud Schema",
65
"type": "object",
76
"properties": {

dist/collection.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {
4+
"crud": {
5+
"description": "Generate Ionic + NgRx Entity CRUD Module",
6+
"factory": "./crud/index#crud",
7+
"schema": "./crud/schema.json"
8+
}
9+
}
10+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<ion-header>
3+
<ion-toolbar color="primary">
4+
<ion-title>เพิ่มข้อมูล</ion-title>
5+
</ion-toolbar>
6+
</ion-header>
7+
8+
<ion-content>
9+
<form [formGroup]="form" (ngSubmit)="onSubmit()">
10+
<% modelFields.forEach(field => { if (field.key !== 'id') { %>
11+
<ion-item>
12+
<ion-label position="stacked"><%= field.key %></ion-label>
13+
<ion-input formControlName="<%= field.key %>" type="text"></ion-input>
14+
</ion-item>
15+
<% } }) %>
16+
17+
<ion-button expand="block" type="submit" [disabled]="form.invalid">บันทึก</ion-button>
18+
</form>
19+
</ion-content>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
<ion-header>
3+
<ion-toolbar color="primary">
4+
<ion-title>แก้ไขข้อมูล</ion-title>
5+
</ion-toolbar>
6+
</ion-header>
7+
8+
<ion-content>
9+
<form [formGroup]="form" (ngSubmit)="onSubmit()">
10+
<% modelFields.forEach(field => { if (field.key !== 'id') { %>
11+
<ion-item>
12+
<ion-label position="stacked"><%= field.key %></ion-label>
13+
<ion-input formControlName="<%= field.key %>" type="text"></ion-input>
14+
</ion-item>
15+
<% } }) %>
16+
17+
<ion-button expand="block" type="submit" [disabled]="form.invalid">บันทึก</ion-button>
18+
</form>
19+
</ion-content>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
<ion-header>
3+
<ion-toolbar color="primary">
4+
<ion-title><%= classify(name) %> List</ion-title>
5+
<ion-buttons slot="end">
6+
<ion-button [routerLink]="['/add']">เพิ่ม</ion-button>
7+
</ion-buttons>
8+
</ion-toolbar>
9+
</ion-header>
10+
11+
<ion-content>
12+
<ion-list *ngIf="(items$ | async) as items">
13+
<ion-item *ngFor="let item of items" [routerLink]="['/item', item.id]">
14+
{{ item.id }} - {{ item.name }}
15+
</ion-item>
16+
</ion-list>
17+
</ion-content>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
export interface <%= classify(name) %> {
3+
<% modelFields.forEach(field => { %>
4+
<%= field.key %>: <%= field.type %>;
5+
<% }); %>
6+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import { Injectable } from '@angular/core';
3+
import { HttpClient } from '@angular/common/http';
4+
import { <%= classify(name) %> } from '../models/<%= dasherize(name) %>.model';
5+
import { Observable } from 'rxjs';
6+
import { EnvironmentService } from 'src/app/shared/services/environment.service';
7+
8+
@Injectable({ providedIn: 'root' })
9+
export class <%= classify(name) %>Service {
10+
private baseUrl = this.env.apiUrl + '/<%= classify(name) %>';
11+
12+
constructor(private http: HttpClient, private env: EnvironmentService) {}
13+
14+
getAll(): Observable<<%= classify(name) %>[]> {
15+
return this.http.get<<%= classify(name) %>[]>(this.baseUrl);
16+
}
17+
18+
getById(id: number | string): Observable<<%= classify(name) %>> {
19+
return this.http.get<<%= classify(name) %>>(`${this.baseUrl}/${id}`);
20+
}
21+
22+
create(data: <%= classify(name) %>): Observable<any> {
23+
return this.http.post(this.baseUrl, data);
24+
}
25+
26+
update(id: number | string, data: <%= classify(name) %>): Observable<any> {
27+
return this.http.put(`${this.baseUrl}/${id}`, data);
28+
}
29+
30+
delete(id: number | string): Observable<any> {
31+
return this.http.delete(`${this.baseUrl}/${id}`);
32+
}
33+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import { createAction, props } from '@ngrx/store';
3+
import { <%= classify(name) %> } from '../../models/<%= dasherize(name) %>.model';
4+
5+
export const load<%= classify(name) %>s = createAction('[<%= classify(name) %>] Load');
6+
export const load<%= classify(name) %>sSuccess = createAction('[<%= classify(name) %>] Load Success', props<{ data: <%= classify(name) %>[] }>());
7+
export const load<%= classify(name) %>sFailure = createAction('[<%= classify(name) %>] Load Failure', props<{ error: any }>());
8+
9+
export const load<%= classify(name) %>ById = createAction('[<%= classify(name) %>] Load By Id', props<{ id: number | string }>());
10+
export const load<%= classify(name) %>ByIdSuccess = createAction('[<%= classify(name) %>] Load By Id Success', props<{ data: <%= classify(name) %> }>());
11+
export const load<%= classify(name) %>ByIdFailure = createAction('[<%= classify(name) %>] Load By Id Failure', props<{ error: any }>());
12+
13+
export const create<%= classify(name) %> = createAction('[<%= classify(name) %>] Create', props<{ data: <%= classify(name) %> }>());
14+
export const update<%= classify(name) %> = createAction('[<%= classify(name) %>] Update', props<{ id: number | string, data: <%= classify(name) %> }>());
15+
export const delete<%= classify(name) %> = createAction('[<%= classify(name) %>] Delete', props<{ id: number | string }>());

0 commit comments

Comments
 (0)