@sekrab/bin 0.0.0-stage → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/package.json +29 -4
  2. package/readme.md +84 -0
  3. package/tasks/angular/angular.js +295 -0
  4. package/tasks/angular/angulardmart/component.dialog.template +24 -0
  5. package/tasks/angular/angulardmart/component.form.template +57 -0
  6. package/tasks/angular/angulardmart/component.partial.template +21 -0
  7. package/tasks/angular/angulardmart/component.template +21 -0
  8. package/tasks/angular/angulardmart/config.template +7 -0
  9. package/tasks/angular/angulardmart/directive.standalone.template +19 -0
  10. package/tasks/angular/angulardmart/model.template +61 -0
  11. package/tasks/angular/angulardmart/module.template +17 -0
  12. package/tasks/angular/angulardmart/pipe.standalone.template +11 -0
  13. package/tasks/angular/angulardmart/route.standalone.template +6 -0
  14. package/tasks/angular/angulardmart/route.template +4 -0
  15. package/tasks/angular/angulardmart/routeModule.template +21 -0
  16. package/tasks/angular/angulardmart/service.template +66 -0
  17. package/tasks/angular/angulardmart/state.template +10 -0
  18. package/tasks/angular/angulardmart/view.form.template +48 -0
  19. package/tasks/angular/angulardmart/view.partial.template +1 -0
  20. package/tasks/angular/angulardmart/view.template +5 -0
  21. package/tasks/angular/angulartemplates/component.dialog.template +24 -0
  22. package/tasks/angular/angulartemplates/component.form.template +56 -0
  23. package/tasks/angular/angulartemplates/component.partial.template +21 -0
  24. package/tasks/angular/angulartemplates/component.template +21 -0
  25. package/tasks/angular/angulartemplates/config.template +7 -0
  26. package/tasks/angular/angulartemplates/directive.standalone.template +19 -0
  27. package/tasks/angular/angulartemplates/model.template +39 -0
  28. package/tasks/angular/angulartemplates/module.template +17 -0
  29. package/tasks/angular/angulartemplates/pipe.standalone.template +11 -0
  30. package/tasks/angular/angulartemplates/route.standalone.template +6 -0
  31. package/tasks/angular/angulartemplates/route.template +4 -0
  32. package/tasks/angular/angulartemplates/routeModule.template +21 -0
  33. package/tasks/angular/angulartemplates/service.template +80 -0
  34. package/tasks/angular/angulartemplates/state.template +10 -0
  35. package/tasks/angular/angulartemplates/view.form.template +48 -0
  36. package/tasks/angular/angulartemplates/view.partial.template +1 -0
  37. package/tasks/angular/angulartemplates/view.template +5 -0
  38. package/tasks/angular/cli.js +27 -0
  39. package/tasks/angular/extract.js +115 -0
  40. package/tasks/cli.js +27 -0
  41. package/tasks/config.json +43 -0
  42. package/tasks/files.js +22 -0
  43. package/tasks/index.js +19 -0
  44. package/tasks/shut/cli.js +12 -0
  45. package/tasks/shut/critical.js +28 -0
  46. package/tasks/shut/shut.icons.js +78 -0
  47. package/tasks/shut/shut.js +87 -0
  48. package/tasks/svelte/translate.js +51 -0
  49. package/README.md +0 -3
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@sekrab/bin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "6.0.0",
4
+ "description": "sekrab tasks shared amongst shut cricket and other libs",
5
+ "main": "tasks/index.js",
6
+ "bin": {
7
+ "shut": "tasks/shut/cli.js",
8
+ "sekrab": "tasks/angular/cli.js"
9
+ },
10
+ "dependencies": {
11
+ "clean-css": "^4.2.3",
12
+ "less": "^4.1.3",
13
+ "minimist": "^1.2.8"
14
+ },
15
+ "scripts": {
16
+ "public": "npm publish --access public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/ayyash/gulpbin.git"
21
+ },
22
+ "keywords": [
23
+ "shut"
24
+ ],
25
+ "author": "Ayyash",
26
+ "license": "ISC",
27
+ "bugs": {
28
+ "url": "https://github.com/ayyash/gulpbin/issues"
29
+ },
30
+ "homepage": "https://github.com/ayyash/gulpbin#readme"
31
+ }
package/readme.md ADDED
@@ -0,0 +1,84 @@
1
+ ### Sekrab and shut tasks
2
+
3
+ This is a list of tasks used for multiple projects that I find handy, though they are only garnish to the projects that use them. Currently used in [Shut framework](https://npmjs.com/package/shut) and [Cricket starter](https://github.com/ayyash/cricket)
4
+
5
+ 1. To install
6
+
7
+ ```
8
+ npm install @sekrab/bin --save-dev
9
+ ```
10
+
11
+ > This package was previously published as `sekrab-gulpbin`, which ran on gulp. From 6.0.0 it is `@sekrab/bin`, and it runs on plain node, so gulp is no longer needed.
12
+
13
+ 2. Add `config.json` [example config](client/config.json)
14
+
15
+ Find in code, example client of those two files.
16
+
17
+ ## Commands for Angular
18
+
19
+ You can optionally use these instead of the angular cli packaged commands (or you can create files manually). here is a quick explanation of each command under ng.js, with the most useful at the top
20
+
21
+ > general rule: name, and major name should start with uppercase letter: like Example, the file names and selectors generated are all lowercase
22
+
23
+ > To know what each one generates, have a look under */angulartemplates* folder
24
+
25
+ ### Generate
26
+
27
+ - `npx sekrab component --name Example --major Container --ispartial false --isform false --standalone false --isdialog false`
28
+ **Useful and common** This task creates a component inside a folder indicated in *major* (could be a folder path like Container/SubContainer), with the name `example.component.ts`. The folder is placed under */app/components*
29
+
30
+ If **ispartial** is set to true, the file name is `example.partial.ts` (and it specifies a selector `cr-example` ready to be used). This is a standalone component.
31
+
32
+ If **isform** is set to true, the code is ready with minimum form elements. This is a standalone component. It's better coupled with **ispartial**.
33
+
34
+ The task aslo adds the component to the correct route under */routes/major.route.ts* (creates it if it does not exist), and adds a dummy route for it if it were not partial, nor dialog, and declares the component.
35
+
36
+ If **standalone** is set to true, it creates a standalone component with basic **CommonModule** and **RouteModule** as imports
37
+
38
+ If **standalone** is set to true and **ispartial** is set to false, the component gets its route in */routes/major.route.ts*.
39
+
40
+ Creating a componetn with **standalone** and **ispartial** is ideal for creating shared components.
41
+
42
+ If **isdialog** is set to true, the file name is `example.dialog.ts` and it's a standalone component that implements the cricket service `DialogService`. The component class name is `MajorMainDialog`.
43
+
44
+ Leaving out *--major* property, failes silently
45
+
46
+ Choosing *--major* to **Common** or **Layout** excludes the major name from file and component name. It also does not declare the generated component in any module. You must declare it manually anywhere you see fit. (Usually, common and layout components are included in the most base app module, which I intentionally do not touch dynamically.)
47
+
48
+ Your job is to implement the component, and head to `src/app/app.routes.ts` (root routing module) to add the lazy loaded path to the new module or standalone route.
49
+
50
+
51
+ - `npx sekrab model --name Example`
52
+ Creates an `example.model.ts` in */models* folder with a single property 'id', your job is to implement it.
53
+
54
+ - `npx sekrab service --name Example`
55
+ Creates an `example.service.ts` in */services* folder with the basic get, post, delete, and put functions. The service is `providedIn: root`. Your job is to implement the service correctly and create an api mapping points in *config.ts*
56
+
57
+ - `npx sekrab fullService --name Example`
58
+ **Useful but rare** In addition to the creating the model, and service and injecting them in their correct locations, it also creates an api config point in *config.ts*. Your job is to implement the service as requested. The service is ready to be injected in any component.
59
+
60
+ - `npx sekrab pipe --name Example`
61
+ Create an `example.pipe.ts` as as standalone pipe.
62
+
63
+ - `npx sekrab directive --name Example`
64
+ Create an `example.directive.ts` as a standalone directive. The selector of the directive is prefixed with configuration property: **prefix**.
65
+
66
+
67
+
68
+ ## Assets
69
+
70
+ To generate assets after changing less files (this is a very critical task, you should not modify styles unless 100% sure of what you're doing)
71
+
72
+ - `npx shut rawless`: prepares *src/assets/css/cr.css* and *cr.rtl.css*
73
+ - `npx shut watch`: does the same as rawless while watching sh.\*.less, ui.\*.less and rtl.\*.less in *mockups* less folder (change in config)
74
+ - `npx shut icons`: this takes files from the icomoon generated files and copies them in */dummy* folder in preparetion to generate icons, then generates icons produced by icomoon tool in `dummy/iconset.html` and in `mockup/less/ui.icons.less`, run `npx shut rawless` afterwords to generate the css files. Browse to `localhost/~projectname/mockup/dummy/iconset.html` to see a list of icons generated.
75
+ - `npx shut critical`: generates four files: `cr.general.css` and `cr.critical.css`, `cr.general.rtl.css` and `cr.critical.rtl.css` into `assets` folder (in addition to the cr.css and cr.rtl.css). The general files are injected through `angular.json` into html, the critical files are added to html header (they are referenced in `placeholder.html`). This is to downsize the initial style file, and have better performance. The rules of which what gets placed in critical is very basic, any group of styles in any `mockup/less/*.less` file wrapped inside `/* CRITICAL BEGIN */` and `/* CRITICAL END */`.
76
+
77
+
78
+
79
+ > PS: Using less in components, is possible, remember to start with `@import "sh.vars.less"`; and avoid styles that need to be mirrored for RTL.
80
+
81
+ Notes:
82
+
83
+ - `all.less` and `all.rtl.less` in */mockup/less* are auto generated by the shut tasks, do not update directly
84
+ - icons rely on files generated by icomoon app: https://icomoon.io/app
@@ -0,0 +1,295 @@
1
+ // Angular generators: create components, views, routes, pipes, directives, models and services
2
+ // from the templates folder. Plain node, no gulp. Same behavior as ng.js.
3
+ // Usage from a client project (see angular/cli.js):
4
+ // npx sekrab component --major Projects --name List [--ispartial] [--isform] [--isdialog] [--standalone]
5
+ // npx sekrab fullService --name Project [--withstate]
6
+ // or in code:
7
+ // const ng = require('@sekrab/bin/tasks/angular/angular.js')(config);
8
+ // await ng.createComponent({ major: 'Projects', name: 'List' });
9
+ // Each function takes the params object; it defaults to the command line arguments.
10
+
11
+ // This version: all pipes directives and partial components are standalone
12
+ // default imports: CommonModule
13
+
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+ const argv = require('minimist')(process.argv.slice(2));
17
+
18
+ module.exports = function (config) {
19
+ const prefix = config.prefix;
20
+ const appPath = config.ng.appPath;
21
+ const templatesDir = path.join(__dirname, config.ng.templates || '/angulartemplates/');
22
+
23
+ const templates = {
24
+ Components: 'component.template',
25
+ DialogComponents: 'component.dialog.template',
26
+ FormComponents: 'component.form.template',
27
+ PartialComponents: 'component.partial.template',
28
+ Views: 'view.template',
29
+ PartialViews: 'view.partial.template',
30
+ FormViews: 'view.form.template',
31
+ Directives: 'directive.standalone.template',
32
+ Pipes: 'pipe.standalone.template',
33
+ Route: 'route.template',
34
+ RouteModule: 'routeModule.template',
35
+ RouteStandalone: 'route.standalone.template',
36
+ Module: 'module.template',
37
+ Model: 'model.template',
38
+ Service: 'service.template',
39
+ State: 'state.template',
40
+ ApiConfig: 'config.template',
41
+ };
42
+ for (const key in templates) templates[key] = path.join(templatesDir, templates[key]);
43
+ const declaration = 'MajorNamePartialComponent';
44
+
45
+ const destinations = {
46
+ Components: path.join(appPath, 'components'),
47
+ Views: path.join(appPath, 'components'),
48
+ Directives: path.join(appPath, 'lib/directives'),
49
+ Pipes: path.join(appPath, 'lib/pipes'),
50
+ Routes: path.join(appPath, 'routes'),
51
+ Models: path.join(appPath, 'services'),
52
+ Services: path.join(appPath, 'services'),
53
+ };
54
+ const apiConfigFile = path.join(appPath, 'config.ts');
55
+
56
+ // a string search replaces every occurrence, with no special $ patterns (like gulp-replace);
57
+ // a regex search uses String.replace
58
+ const replace = (text, search, replacement) =>
59
+ typeof search === 'string' ? text.split(search).join(replacement) : text.replace(search, replacement);
60
+
61
+ // apply [search, replacement] pairs in order; a pair of null is skipped (a false condition)
62
+ const replaceAll = (text, pairs) =>
63
+ pairs.reduce((t, pair) => (pair ? replace(t, pair[0], pair[1]) : t), text);
64
+
65
+ const read = (file) => fs.readFileSync(file, 'utf8');
66
+
67
+ // write a new file; never overwrite one that exists
68
+ const create = (dir, fileName, content) => {
69
+ const file = path.join(dir, fileName);
70
+ if (fs.existsSync(file)) {
71
+ console.log('exists, skipped', file);
72
+ return;
73
+ }
74
+ fs.mkdirSync(dir, { recursive: true });
75
+ fs.writeFileSync(file, content);
76
+ console.log('created', file);
77
+ };
78
+
79
+ // change a file that exists
80
+ const update = (file, content) => {
81
+ fs.writeFileSync(file, content);
82
+ console.log('updated', file);
83
+ };
84
+
85
+ // "Projects/Active/List" => first: "Projects", last: "List"
86
+ const firstPart = (name) => name.split('/')[0];
87
+ const lastPart = (name) => name.substring(name.lastIndexOf('/') + 1);
88
+
89
+ // models, services and states go into a folder named after the first part, unless there is only one part
90
+ const serviceDest = (root, name) =>
91
+ firstPart(name) === lastPart(name) ? root : path.join(root, firstPart(name));
92
+
93
+ const createRouteModule = async (params = argv) => {
94
+ const { major, standalone, ispartial, isdialog } = params;
95
+ if (!major || ispartial || isdialog) return;
96
+
97
+ const majorName = firstPart(major);
98
+ // if common or layouts, do not create module
99
+ if (majorName === 'Common' || majorName === 'Layouts') return;
100
+
101
+ // avoid modules, keep adding to the same route file
102
+ // if the route file is new, its kind follows the first component created
103
+ const src = standalone ? templates.RouteStandalone : templates.RouteModule;
104
+ create(destinations.Routes, `${majorName.toLowerCase()}.route.ts`, replace(read(src), 'Major', majorName));
105
+ };
106
+
107
+ // add component to the route file of its major
108
+ const addComponentToRoute = async (params = argv) => {
109
+ const { major, name, ispartial, isdialog, standalone } = params;
110
+ if (!major || ispartial || isdialog) return;
111
+
112
+ const majorName = firstPart(major);
113
+ const subMajorName = lastPart(major); // could be the same
114
+ if (majorName === 'Common' || majorName === 'Layouts') return;
115
+
116
+ const routeFile = path.join(destinations.Routes, `${majorName.toLowerCase()}.route.ts`);
117
+ if (!fs.existsSync(routeFile)) return;
118
+
119
+ // route: path and component (first occurrence only)
120
+ const route = read(templates.Route)
121
+ .replace('major', subMajorName.toLowerCase())
122
+ .replace('name', name.toLowerCase())
123
+ .replace('Major', subMajorName)
124
+ .replace('Name', name);
125
+
126
+ // the first route is empty, like this: /projects instead of /projects/list
127
+ const firsttimeRoute = route.replace(name.toLowerCase(), '');
128
+
129
+ let component = declaration.replace('Major', subMajorName).replace('Name', name);
130
+ if (!ispartial) component = component.replace('Partial', '');
131
+
132
+ const importStatement = `import { ${component} } from '../components/${major.toLowerCase()}/${name.toLowerCase()}.${ispartial ? 'partial' : 'component'}';`;
133
+
134
+ const when = (condition, search, replacement) => (condition ? [search, replacement] : null);
135
+
136
+ update(routeFile, replaceAll(read(routeFile), [
137
+ // if it is not partial force a route for it, even if standalone
138
+ when(!ispartial, '// **gulproute**', ',' + route + '\n// **gulproute**'),
139
+ // if first time adding, the route has no name
140
+ when(!ispartial, '// **gulproute_first**', firsttimeRoute + '\n// **gulproute**'),
141
+ // if not standalone place in declarations
142
+ when(!standalone, '// **gulpcomponent**', ', ' + component + '\n// **gulpcomponent**'),
143
+ when(!standalone, '// **gulpcomponent_first**', component + '\n// **gulpcomponent**'),
144
+ // if standalone place in imports
145
+ when(standalone, '// **gulpcomponent_standalone**', component + ', ' + '\n// **gulpcomponent_standalone**'),
146
+ // if standalone, check if not partial before adding
147
+ when(!(standalone && ispartial), '// **gulpimport**', importStatement + '\n// **gulpimport**'),
148
+ ]));
149
+ };
150
+
151
+ const createView = async (params = argv) => {
152
+ const { major, name, ispartial, isform, isdialog } = params;
153
+ if (!major) return;
154
+ // major can be Something/Something, the view goes into destination views + that path
155
+ const majorName = lastPart(major);
156
+
157
+ let src = templates.Views;
158
+ if (isform) src = templates.FormViews;
159
+ if (ispartial && !isform) src = templates.PartialViews;
160
+ if (isdialog) src = templates.PartialViews;
161
+
162
+ const suffix = isdialog ? '.dialog' : ispartial ? '.partial' : '';
163
+ create(
164
+ path.join(destinations.Views, major.toLowerCase()),
165
+ `${name.toLowerCase()}${suffix}.html`,
166
+ replaceAll(read(src), [
167
+ ['Major', majorName],
168
+ ['major', majorName.toLowerCase()],
169
+ ])
170
+ );
171
+ };
172
+
173
+ const createComponentFile = async (params = argv) => {
174
+ const { major, name, ispartial, isform, standalone, isdialog } = params;
175
+ if (!major) return;
176
+
177
+ // partial, form and dialog are always standalone
178
+ const standaloneBlock = /\/\* STANDALONE \*\/[\s\S]*?\/\* ENDSTANDALONE \*\//gim;
179
+ const standaloneComments = /(\/\* STANDALONE \*\/\s\s*|\/\* ENDSTANDALONE \*\/\s\s*)/gim;
180
+
181
+ let isStandalone = standalone;
182
+ let viewSuffix = '';
183
+ let suffix = '.component';
184
+
185
+ let majorName = lastPart(major);
186
+ // if common, or layout dont include name
187
+ if (majorName === 'Common' || majorName === 'Layouts') majorName = '';
188
+ const selector = `selector: '${prefix}${majorName ? '-' + majorName.toLowerCase() : ''}-${name.toLowerCase()}',`;
189
+
190
+ if (ispartial) {
191
+ isStandalone = true;
192
+ viewSuffix = '.partial';
193
+ suffix = '.partial';
194
+ }
195
+ if (isdialog) {
196
+ isStandalone = true;
197
+ viewSuffix = '.dialog';
198
+ suffix = '.dialog';
199
+ }
200
+
201
+ let src = templates.Components;
202
+ if (isform) src = templates.FormComponents;
203
+ if (ispartial && !isform) src = templates.PartialComponents;
204
+ if (isdialog) src = templates.DialogComponents;
205
+
206
+ create(
207
+ path.join(destinations.Components, major.toLowerCase()),
208
+ `${name.toLowerCase()}${suffix}.ts`,
209
+ replaceAll(read(src), [
210
+ ['Major', majorName],
211
+ ['Name', name],
212
+ ['major', majorName.toLowerCase()],
213
+ ['viewpath', name.toLowerCase() + viewSuffix],
214
+ ['_selector_', selector],
215
+ isStandalone ? null : [standaloneBlock, ''],
216
+ // remove comments
217
+ [standaloneComments, ''],
218
+ ])
219
+ );
220
+ };
221
+
222
+ // a template that only needs _Name_ and _name_
223
+ const fromTemplate = (src, dir, name, suffix) =>
224
+ create(dir, `${name.toLowerCase()}${suffix}.ts`, replaceAll(read(src), [
225
+ ['_Name_', name],
226
+ ['_name_', name.toLowerCase()],
227
+ ]));
228
+
229
+ const createPipe = async (params = argv) => {
230
+ if (!params.name) return;
231
+ fromTemplate(templates.Pipes, destinations.Pipes, params.name, '.pipe');
232
+ };
233
+
234
+ const createDirective = async (params = argv) => {
235
+ if (!params.name) return;
236
+ fromTemplate(templates.Directives, destinations.Directives, params.name, '.directive');
237
+ };
238
+
239
+ const createModel = async (params = argv) => {
240
+ const { name } = params;
241
+ if (!name) return;
242
+ fromTemplate(templates.Model, serviceDest(destinations.Models, name), lastPart(name), '.model');
243
+ };
244
+
245
+ const createService = async (params = argv) => {
246
+ const { name } = params;
247
+ if (!name) return;
248
+ // limitation: when in sub folder, the config.API.name is not defined
249
+ fromTemplate(templates.Service, serviceDest(destinations.Services, name), lastPart(name), '.service');
250
+ };
251
+
252
+ const createState = async (params = argv) => {
253
+ const { name, withstate } = params;
254
+ if (!name || !withstate) return;
255
+ fromTemplate(templates.State, serviceDest(destinations.Services, name), lastPart(name), '.state');
256
+ };
257
+
258
+ // add a node to config.ts for the new service
259
+ const addToConfig = async (params = argv) => {
260
+ const { name } = params;
261
+ // if in subfolder, ignore
262
+ if (!name || name.indexOf('/') > -1) return;
263
+ if (!fs.existsSync(apiConfigFile)) {
264
+ console.log('not found, skipped', apiConfigFile);
265
+ return;
266
+ }
267
+ const apiconfig = read(templates.ApiConfig).replace(/_name_/gim, name.toLowerCase());
268
+ update(apiConfigFile, replace(read(apiConfigFile), '// **gulpmodel**', ', ' + apiconfig + '\n// **gulpmodel**'));
269
+ };
270
+
271
+ // view, component and route file first, then add the component to the route file
272
+ const createComponent = async (params = argv) => {
273
+ await createView(params);
274
+ await createComponentFile(params);
275
+ await createRouteModule(params);
276
+ await addComponentToRoute(params);
277
+ };
278
+
279
+ const createFullService = async (params = argv) => {
280
+ await createModel(params);
281
+ await createService(params);
282
+ await addToConfig(params);
283
+ await createState(params);
284
+ };
285
+
286
+ return {
287
+ createRouteModule,
288
+ createComponent,
289
+ createPipe,
290
+ createDirective,
291
+ createModel,
292
+ createService,
293
+ createFullService,
294
+ };
295
+ };
@@ -0,0 +1,24 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
3
+ import { RouterModule } from '@angular/router';
4
+ import { DialogPartial } from '../../lib/dialog/partial';
5
+
6
+
7
+ @Component({
8
+ _selector_
9
+ templateUrl: './viewpath.html'
10
+ , changeDetection: ChangeDetectionStrategy.OnPush
11
+ , imports: [CommonModule, RouterModule]
12
+ })
13
+ export class MajorNameDialog implements OnInit {
14
+
15
+ data!: any;
16
+ dialog!: DialogPartial;
17
+
18
+ constructor() {
19
+ //
20
+ }
21
+ ngOnInit(): void {
22
+ //
23
+ }
24
+ }
@@ -0,0 +1,57 @@
1
+ import { ChangeDetectionStrategy, Component, input, OnInit, output } from '@angular/core';
2
+ import { FormGroup, FormBuilder, ReactiveFormsModule } from '@angular/forms';
3
+ import { Toast } from '../../lib/toast/toast.state';
4
+ import { IViewMode } from '../../models/viewmode.model';
5
+ import { CommonModule } from '@angular/common';
6
+ import { RouterModule } from '@angular/router';
7
+ import { InputDirective } from 'src/app/lib/input/input.directive';
8
+ import { OlInputPartial } from 'src/app/lib/input/input.partial';
9
+
10
+ @Component({
11
+ _selector_
12
+ templateUrl: './viewpath.html',
13
+ changeDetection: ChangeDetectionStrategy.OnPush
14
+ , imports: [CommonModule, RouterModule, ReactiveFormsModule, OlInputPartial, InputDirective]
15
+ })
16
+ export class MajorNameFormPartial implements OnInit {
17
+
18
+ mode = input<IViewMode>({ forNew: true });
19
+ onSave = output<any>();
20
+
21
+
22
+ majorForm: FormGroup;
23
+
24
+ constructor(private fb: FormBuilder, private toast: Toast) {
25
+ //
26
+ }
27
+ ngOnInit(): void {
28
+ //
29
+ this.majorForm = this.fb.group({
30
+ name: [],
31
+ currency: [],
32
+ notes: []
33
+ });
34
+ }
35
+
36
+ // use to compare for initial select... keep '=='
37
+ compareFn(c1: any, c2: any): boolean {
38
+ return c1 && c2 ? c1.id == c2.id : false;
39
+ }
40
+
41
+ saveMajor(): void {
42
+ this.toast.Hide();
43
+
44
+
45
+ if (this.majorForm.valid) {
46
+ // clone into a new object
47
+ const _value = this.majorForm.value;
48
+
49
+ const _major = { ..._value};
50
+
51
+ // then emit
52
+ this.onSave.emit(_major);
53
+ } else {
54
+ this.toast.ShowError('INVALID_FORM');
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,21 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ChangeDetectionStrategy, Component, input, output, OnInit } from '@angular/core';
3
+ import { RouterModule } from '@angular/router';
4
+ @Component({
5
+ _selector_
6
+ templateUrl: './viewpath.html'
7
+ , changeDetection: ChangeDetectionStrategy.OnPush
8
+ , imports: [CommonModule, RouterModule]
9
+ })
10
+ export class MajorNamePartial implements OnInit {
11
+
12
+ id = input.required<string>();
13
+ onSomething = output<any>();
14
+
15
+ constructor() {
16
+ //
17
+ }
18
+ ngOnInit(): void {
19
+ //
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import { Component, OnInit, ChangeDetectionStrategy, input } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { RouterModule } from '@angular/router';
4
+
5
+ @Component({
6
+ _selector_
7
+ templateUrl: './viewpath.html'
8
+ , changeDetection: ChangeDetectionStrategy.OnPush
9
+ , imports: [CommonModule, RouterModule]
10
+ })
11
+ export class MajorNameComponent implements OnInit {
12
+
13
+ mode = input<string>(); // param
14
+
15
+ constructor() {
16
+ //
17
+ }
18
+ ngOnInit(): void {
19
+ //
20
+ }
21
+ }
@@ -0,0 +1,7 @@
1
+ _name_: {
2
+ list: '/_name_s/?:options',
3
+ details: '/_name_s/:id',
4
+ create: '/_name_s', // POST
5
+ save: '/_name_s/:id', // PUT
6
+ delete: '/_name_s/:id', // DELETE
7
+ }
@@ -0,0 +1,19 @@
1
+ import { OnInit, Directive, ElementRef, Input, Renderer2 } from '@angular/core';
2
+
3
+
4
+ @Directive({
5
+ selector: '[_name_]',
6
+ exportAs: '_name_'
7
+ })
8
+ export class _Name_Directive implements OnInit {
9
+
10
+ @Input() _name_: string;
11
+
12
+ constructor(private el: ElementRef, private renderer: Renderer2) {
13
+ //
14
+ }
15
+
16
+ ngOnInit() {
17
+ //
18
+ }
19
+ }
@@ -0,0 +1,61 @@
1
+ import { IResource, Resource } from 'src/app/models/resource.model';
2
+ import { EnumContentType, EnumRequestType } from 'src/app/utils/param.model';
3
+ import { Config } from 'src/app/config';
4
+ import { DataList, IList } from 'src/app/models/list.model';
5
+
6
+
7
+ export interface I_Name_ extends IResource {
8
+ custom?: any;
9
+ }
10
+
11
+ export class _Name_ {
12
+
13
+ static NewInstance(_name_: any): I_Name_ {
14
+ const res = Resource.NewInstance(_name_, Config.API.rootSpace);
15
+ return {
16
+ ...res,
17
+ custom: _name_.custom
18
+ }
19
+ }
20
+ static NewInstances(data: any[]): I_Name_[] {
21
+ if (!data?.length) return [];
22
+ return data.map(_Name_.NewInstance);
23
+ }
24
+
25
+ static NewList(dataset: any): IList<I_Name_> {
26
+ const dl = new DataList<I_Name_>();
27
+ dl.mapper = _Name_.NewInstance;
28
+ return dl.NewDataList(dataset);
29
+ }
30
+
31
+ static PrepPost(data: I_Name_): any {
32
+
33
+ const payload = {
34
+ payload: {
35
+ content_type: EnumContentType.json,
36
+ // optional schema_shortname: '_name_',
37
+ body: {
38
+ // add body
39
+ custom: data.custom
40
+ },
41
+ }
42
+ };
43
+
44
+ const ret = Resource.PrepPayload(data, payload);
45
+
46
+ return {
47
+ ...ret,
48
+ shortname: data.shortname || Config.API.autoShortname,
49
+ subpath: Config.API._name_.list,
50
+ };
51
+ }
52
+
53
+ static PrepRequest(_name_: I_Name_, request: EnumRequestType): any {
54
+ return {
55
+ space_name: Config.API.rootSpace,
56
+ request_type: request,
57
+ records: [this.PrepPost(_name_)],
58
+ };
59
+ }
60
+
61
+ }
@@ -0,0 +1,17 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { RouterModule } from '@angular/router';
3
+ // **gulpimport**
4
+
5
+ @NgModule({
6
+ imports: [
7
+ RouterModule
8
+ ],
9
+ declarations: [
10
+ // **gulpcomponent_first**
11
+ ],
12
+ exports: [
13
+ // **gulpcomponent_first**
14
+ ]
15
+ })
16
+
17
+ export class MajorModule { }
@@ -0,0 +1,11 @@
1
+ import { Pipe, PipeTransform } from '@angular/core';
2
+
3
+ @Pipe({ name: '_name_' })
4
+ export class _Name_Pipe implements PipeTransform {
5
+
6
+ transform(_name_: string): string {
7
+ return _name_;
8
+
9
+ }
10
+ }
11
+
@@ -0,0 +1,6 @@
1
+ import { Routes } from '@angular/router';
2
+ // **gulpimport**
3
+
4
+ export const MajorRoutes: Routes = [
5
+ // **gulproute_first**
6
+ ];
@@ -0,0 +1,4 @@
1
+ {
2
+ path: 'name',
3
+ component: MajorNameComponent
4
+ }