ngrx-entity-crud 13.1.0-beta.2 → 13.1.0-beta.3
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.
- package/package.json +1 -1
- package/schematics/ng-add/files/app/core/directive/ng-let.directive.ts +32 -0
- package/schematics/ng-add/files/app/core/pipe/json-form.pipe.ts +30 -0
- package/schematics/ng-add/files/app/core/pipe/pipes.module.ts +24 -0
- package/schematics/ng-add/files/app/core/utils/j-utils.ts +83 -0
- package/schematics/ng-add/files/app/main/components/search/search.component.ts +30 -0
- package/schematics/ng-add/files/app/main/components/search/search.module.ts +17 -0
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {Directive, Input, NgModule, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
|
|
2
|
+
|
|
3
|
+
export class NgLetContext {
|
|
4
|
+
$implicit: any = null;
|
|
5
|
+
ngLet: any = null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@Directive({
|
|
9
|
+
selector: '[ngLet]'
|
|
10
|
+
})
|
|
11
|
+
export class NgLetDirective implements OnInit {
|
|
12
|
+
private _context = new NgLetContext();
|
|
13
|
+
|
|
14
|
+
@Input()
|
|
15
|
+
set ngLet(value: any) {
|
|
16
|
+
this._context.$implicit = this._context.ngLet = value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(private _vcr: ViewContainerRef, private _templateRef: TemplateRef<NgLetContext>) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ngOnInit() {
|
|
23
|
+
this._vcr.createEmbeddedView(this._templateRef, this._context);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@NgModule({
|
|
28
|
+
declarations: [NgLetDirective],
|
|
29
|
+
exports: [NgLetDirective]
|
|
30
|
+
})
|
|
31
|
+
export class NgLetModule {
|
|
32
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {Pipe, PipeTransform} from '@angular/core';
|
|
2
|
+
import {FormGroup} from '@angular/forms';
|
|
3
|
+
|
|
4
|
+
@Pipe({
|
|
5
|
+
name: 'jsonForm', pure: false
|
|
6
|
+
})
|
|
7
|
+
export class JsonFormPipe implements PipeTransform {
|
|
8
|
+
|
|
9
|
+
transform(value: FormGroup, args?: any): any {
|
|
10
|
+
const result = {
|
|
11
|
+
errors: value.errors,
|
|
12
|
+
controls: [],
|
|
13
|
+
value: value.value,
|
|
14
|
+
rawValue: value.getRawValue(),
|
|
15
|
+
status: value.status,
|
|
16
|
+
touched: value.touched,
|
|
17
|
+
valid: value.valid,
|
|
18
|
+
};
|
|
19
|
+
for (const key in value.controls) {
|
|
20
|
+
const val = {};
|
|
21
|
+
val[key] = value.controls[key].errors;
|
|
22
|
+
if (!!val[key] && !!val[key].getMessage) {
|
|
23
|
+
val[key]._messageRendered = val[key].getMessage();
|
|
24
|
+
}
|
|
25
|
+
result.controls.push(val);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {NgModule} from '@angular/core';
|
|
2
|
+
import {CommonModule} from '@angular/common';
|
|
3
|
+
import {JsonFormPipe} from './json-form.pipe';
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
imports: [
|
|
7
|
+
CommonModule
|
|
8
|
+
],
|
|
9
|
+
declarations: [
|
|
10
|
+
JsonFormPipe,
|
|
11
|
+
],
|
|
12
|
+
exports: [
|
|
13
|
+
CommonModule,
|
|
14
|
+
JsonFormPipe,
|
|
15
|
+
]
|
|
16
|
+
})
|
|
17
|
+
export class PipesModule {
|
|
18
|
+
static forRoot() {
|
|
19
|
+
return {
|
|
20
|
+
ngModule: PipesModule,
|
|
21
|
+
providers: [],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function evalData<T>(fn: Function, def: any = null): T {
|
|
2
|
+
try {
|
|
3
|
+
return fn();
|
|
4
|
+
} catch (e) {
|
|
5
|
+
return def;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function stringifyCompare(a: any, b: any): boolean {
|
|
10
|
+
return evalData(() => JSON.stringify(a) === JSON.stringify(b), false);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getUrlParam = (key) => {
|
|
14
|
+
const matches = window.location.href.match(new RegExp(`[?&]${key}=([^&#]+)\\b`));
|
|
15
|
+
return (matches && matches.length > 0) ? matches[1] : null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function clone<T>(value: T): T {
|
|
19
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getFlattenInObject<T, R>(propertyName, inputArray: T[], distinct: boolean): R[] {
|
|
23
|
+
let result = [];
|
|
24
|
+
inputArray.forEach(item => {
|
|
25
|
+
if (!distinct || (distinct && result.indexOf(item[propertyName]) === -1)) {
|
|
26
|
+
result.push(item[propertyName]);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getDuplicateInObject<T>(propertyName, inputArray: T[]): T[] {
|
|
33
|
+
|
|
34
|
+
var sorted_arr = [...inputArray].sort(function(a, b) {
|
|
35
|
+
return ('' + a[propertyName]).localeCompare(b[propertyName]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
var results: T[] = [];
|
|
39
|
+
for (var i = 0; i < sorted_arr.length - 1; i++) {
|
|
40
|
+
if (sorted_arr[i + 1][propertyName] == sorted_arr[i][propertyName] && !results.find(item => item[propertyName] === sorted_arr[i][propertyName])) {
|
|
41
|
+
results.push(sorted_arr[i]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return results;
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export function debounce(func, wait, immediate) {
|
|
51
|
+
let timeout;
|
|
52
|
+
return function() {
|
|
53
|
+
let context = this, args = arguments;
|
|
54
|
+
let later = function() {
|
|
55
|
+
timeout = null;
|
|
56
|
+
if (!immediate) {
|
|
57
|
+
func.apply(context, args);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
let callNow = immediate && !timeout;
|
|
61
|
+
clearTimeout(timeout);
|
|
62
|
+
timeout = setTimeout(later, wait);
|
|
63
|
+
if (callNow) {
|
|
64
|
+
func.apply(context, args);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const parseQueryString = (qs) => {
|
|
70
|
+
const items = qs.split('&');
|
|
71
|
+
return items.reduce((data, item) => {
|
|
72
|
+
const [key, value] = item.split('=');
|
|
73
|
+
if (data[key] !== undefined) {
|
|
74
|
+
if (!Array.isArray(data[key])) {
|
|
75
|
+
data[key] = [data[key]];
|
|
76
|
+
}
|
|
77
|
+
data[key].push(value);
|
|
78
|
+
} else {
|
|
79
|
+
data[key] = value;
|
|
80
|
+
}
|
|
81
|
+
return data;
|
|
82
|
+
}, {});
|
|
83
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {Component, Input, OnInit} from '@angular/core';
|
|
2
|
+
import {Store} from '@ngrx/store';
|
|
3
|
+
import {RootStoreState} from '@root-store/index';
|
|
4
|
+
import {parseQueryString} from '@core/utils/j-utils';
|
|
5
|
+
import {Actions} from 'ngrx-entity-crud';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'app-search',
|
|
9
|
+
template: `
|
|
10
|
+
<input #search type="text" (keyup.enter)="onSearch(search.value)"/>
|
|
11
|
+
`,
|
|
12
|
+
styles: []
|
|
13
|
+
})
|
|
14
|
+
export class SearchComponent implements OnInit {
|
|
15
|
+
|
|
16
|
+
@Input()
|
|
17
|
+
actions: Actions<any>;
|
|
18
|
+
|
|
19
|
+
constructor(protected store$: Store<RootStoreState.State>) {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ngOnInit() {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onSearch(value: string) {
|
|
26
|
+
this.store$.dispatch(this.actions.SearchRequest({queryParams: parseQueryString(value)}));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {NgModule} from '@angular/core';
|
|
2
|
+
import {CommonModule} from '@angular/common';
|
|
3
|
+
import {SearchComponent} from './search.component';
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
declarations: [
|
|
7
|
+
SearchComponent
|
|
8
|
+
],
|
|
9
|
+
imports: [
|
|
10
|
+
CommonModule
|
|
11
|
+
],
|
|
12
|
+
exports: [
|
|
13
|
+
SearchComponent
|
|
14
|
+
]
|
|
15
|
+
})
|
|
16
|
+
export class SearchModule {
|
|
17
|
+
}
|