shout-angular-query-builder
Advanced tools
Comparing version 0.7.12 to 0.8.0-alpha
@@ -0,0 +0,0 @@ /* |
@@ -11,3 +11,3 @@ import { AbstractControl, ControlValueAccessor, ValidationErrors, Validator } from '@angular/forms'; | ||
import { QueryArrowIconDirective } from './query-arrow-icon.directive'; | ||
import { ButtonGroupContext, Entity, Field, SwitchGroupContext, EntityContext, FieldContext, InputContext, LocalRuleMeta, OperatorContext, QueryBuilderClassNames, QueryBuilderConfig, RemoveButtonContext, ArrowIconContext, Rule, RuleSet, EmptyWarningContext } from './query-builder.interfaces'; | ||
import { ButtonGroupContext, Entity, Field, SwitchGroupContext, EntityContext, FieldContext, InputContext, LocalRuleMeta, OperatorContext, QueryBuilderClassNames, QueryBuilderConfig, RemoveButtonContext, ArrowIconContext, Rule, RuleSet, EmptyWarningContext, Operator } from './query-builder.interfaces'; | ||
import { ChangeDetectorRef, OnChanges, OnInit, QueryList, SimpleChanges, TemplateRef, ElementRef } from '@angular/core'; | ||
@@ -24,3 +24,3 @@ import * as i0 from "@angular/core"; | ||
defaultOperatorMap: { | ||
[key: string]: string[]; | ||
[key: string]: Operator[]; | ||
}; | ||
@@ -64,3 +64,2 @@ disabled: boolean; | ||
private defaultPersistValueTypes; | ||
private defaultEmptyList; | ||
private operatorsCache; | ||
@@ -86,3 +85,3 @@ private inputContextCache; | ||
findQueryInput(type: string): QueryInputDirective; | ||
getOperators(field: string): string[]; | ||
getOperators(field: string): Operator[]; | ||
getFields(entity: string): Field[]; | ||
@@ -94,2 +93,3 @@ getInputType(field: string, operator: string): string; | ||
getDefaultOperator(field: Field): string; | ||
getOperatorValue(operator: Operator): string; | ||
addRule(parent?: RuleSet): void; | ||
@@ -96,0 +96,0 @@ removeRule(rule: Rule, parent?: RuleSet): void; |
@@ -20,2 +20,7 @@ export interface RuleSet { | ||
} | ||
export interface LocalizedOperator { | ||
localized: string; | ||
value: string; | ||
} | ||
export type Operator = string | LocalizedOperator; | ||
export interface Field { | ||
@@ -27,3 +32,3 @@ name: string; | ||
options?: Option[]; | ||
operators?: string[]; | ||
operators?: Operator[]; | ||
defaultValue?: any; | ||
@@ -84,3 +89,3 @@ defaultOperator?: any; | ||
allowEmptyRulesets?: boolean; | ||
getOperators?: (fieldName: string, field: Field) => string[]; | ||
getOperators?: (fieldName: string, field: Field) => Operator[]; | ||
getInputType?: (field: string, operator: string) => string; | ||
@@ -125,3 +130,3 @@ getOptions?: (field: string) => Option[]; | ||
getDisabledState: () => boolean; | ||
operators: string[]; | ||
operators: Operator[]; | ||
$implicit: Rule; | ||
@@ -128,0 +133,0 @@ } |
@@ -11,2 +11,3 @@ { | ||
"@angular/forms": ">=8.0.0", | ||
"@angular/localize": ">=8.0.0", | ||
"rxjs": ">=6.0.0" | ||
@@ -13,0 +14,0 @@ }, |
{ | ||
"name": "shout-angular-query-builder", | ||
"version": "0.7.12", | ||
"version": "0.8.0-alpha", | ||
"description": "A modernized Angular 16+ query builder based on jquery QueryBuilder", | ||
@@ -72,5 +72,5 @@ "module": "./dist/shout-angular-query-builder/fesm2022/shout-angular-query-builder.mjs", | ||
"devDependencies": { | ||
"@angular-devkit/architect": "^0.1602.6", | ||
"@angular-devkit/build-angular": "^16.2.6", | ||
"@angular-eslint/builder": "^16.2.0", | ||
"@angular-devkit/architect": "^0.1602.6", | ||
"@angular-eslint/eslint-plugin": "^16.2.0", | ||
@@ -85,2 +85,3 @@ "@angular-eslint/schematics": "^16.2.0", | ||
"@angular/language-service": "^16.2.10", | ||
"@angular/localize": "^16.2.10", | ||
"@angular/platform-browser": "^16.2.10", | ||
@@ -87,0 +88,0 @@ "@angular/platform-browser-dynamic": "^16.2.10", |
// Karma configuration file, see link for more information | ||
// https://karma-runner.github.io/1.0/config/configuration-file.html | ||
process.env.CHROME_BIN = require('puppeteer').executablePath() | ||
process.env.CHROME_BIN = require('puppeteer').executablePath(); | ||
module.exports = function (config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine', '@angular-devkit/build-angular'], | ||
plugins: [ | ||
require('karma-jasmine'), | ||
require('karma-chrome-launcher'), | ||
require('karma-jasmine-html-reporter'), | ||
require('karma-coverage-istanbul-reporter'), | ||
require('@angular-devkit/build-angular/plugins/karma') | ||
], | ||
client: { | ||
clearContext: false // leave Jasmine Spec Runner output visible in browser | ||
}, | ||
// custom ChromeHeadless launcher | ||
browsers: ['ChromeHeadless'], | ||
customLaunchers: { | ||
ChromeHeadlessNoSandbox: { | ||
base: 'ChromeHeadless', | ||
flags: ['--no-sandbox'] | ||
} | ||
}, | ||
coverageIstanbulReporter: { | ||
dir: require('path').join(__dirname, '../../coverage/angular2-query-builder'), | ||
reports: ['html', 'lcovonly'], | ||
fixWebpackSourcePaths: true | ||
}, | ||
reporters: ['progress', 'kjhtml'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
singleRun: false, | ||
restartOnFileChange: true | ||
}); | ||
module.exports = function(config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine', '@angular-devkit/build-angular'], | ||
plugins: [ | ||
require('karma-jasmine'), | ||
require('karma-chrome-launcher'), | ||
require('karma-jasmine-html-reporter'), | ||
require('karma-coverage-istanbul-reporter'), | ||
require('@angular-devkit/build-angular/plugins/karma') | ||
], | ||
client: { | ||
clearContext: false // leave Jasmine Spec Runner output visible in browser | ||
}, | ||
// custom ChromeHeadless launcher | ||
browsers: ['ChromeHeadless'], | ||
customLaunchers: { | ||
ChromeHeadlessNoSandbox: { | ||
base: 'ChromeHeadless', | ||
flags: ['--no-sandbox'] | ||
} | ||
}, | ||
coverageIstanbulReporter: { | ||
dir: require('path').join(__dirname, '../../coverage/angular2-query-builder'), | ||
reports: ['html', 'lcovonly'], | ||
fixWebpackSourcePaths: true | ||
}, | ||
reporters: ['progress', 'kjhtml'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
singleRun: false, | ||
restartOnFileChange: true | ||
}); | ||
}; |
@@ -11,4 +11,5 @@ { | ||
"@angular/forms": ">=8.0.0", | ||
"@angular/localize": ">=8.0.0", | ||
"rxjs": ">=6.0.0" | ||
} | ||
} |
@@ -35,3 +35,3 @@ import { | ||
RuleSet, | ||
EmptyWarningContext, | ||
EmptyWarningContext, Operator, | ||
} from './query-builder.interfaces'; | ||
@@ -53,2 +53,3 @@ import { | ||
} from '@angular/core'; | ||
import {$localize} from '@angular/localize/init'; | ||
@@ -108,8 +109,8 @@ export const CONTROL_VALUE_ACCESSOR: any = { | ||
}; | ||
public defaultOperatorMap: { [key: string]: string[] } = { | ||
string: ['=', '!=', 'contains', 'like'], | ||
public defaultOperatorMap: { [key: string]: Operator[] } = { | ||
string: ['=', '!=', {value: 'contains', localized: $localize`contains`}, {value: 'like', localized: $localize`like`}], | ||
number: ['=', '!=', '>', '>=', '<', '<='], | ||
time: ['=', '!=', '>', '>=', '<', '<='], | ||
date: ['=', '!=', '>', '>=', '<', '<='], | ||
category: ['=', '!=', 'in', 'not in'], | ||
category: ['=', '!=', {value: 'in', localized: $localize`in`}, {value: 'not in', localized: $localize`not in`}], | ||
boolean: ['='] | ||
@@ -126,3 +127,3 @@ }; | ||
@Input() allowCollapse: boolean = false; | ||
@Input() emptyMessage: string = 'A ruleset cannot be empty. Please add a rule or remove it all together.'; | ||
@Input() emptyMessage: string = $localize`A ruleset cannot be empty. Please add a rule or remove it all together.`; | ||
@Input() classNames: QueryBuilderClassNames; | ||
@@ -161,4 +162,3 @@ @Input() operatorMap: { [key: string]: string[] }; | ||
'string', 'number', 'time', 'date', 'boolean']; | ||
private defaultEmptyList: string[] = []; | ||
private operatorsCache: { [key: string]: string[] }; | ||
private operatorsCache: { [key: string]: Operator[] }; | ||
private inputContextCache = new Map<Rule, InputContext>(); | ||
@@ -274,7 +274,7 @@ private operatorContextCache = new Map<Rule, OperatorContext>(); | ||
getOperators(field: string): string[] { | ||
getOperators(field: string): Operator[] { | ||
if (this.operatorsCache[field]) { | ||
return this.operatorsCache[field]; | ||
} | ||
let operators = this.defaultEmptyList; | ||
let operators = [] as Operator[]; | ||
const fieldObject = this.config.fields[field]; | ||
@@ -291,3 +291,3 @@ | ||
} else if (type) { | ||
operators = (this.operatorMap && this.operatorMap[type]) || this.defaultOperatorMap[type] || this.defaultEmptyList; | ||
operators = (this.operatorMap && this.operatorMap[type]) || this.defaultOperatorMap[type] || []; | ||
if (operators.length === 0) { | ||
@@ -344,3 +344,3 @@ console.warn( | ||
} | ||
return this.config.fields[field].options || this.defaultEmptyList; | ||
return this.config.fields[field].options || []; | ||
} | ||
@@ -373,7 +373,7 @@ | ||
if (field && field.defaultOperator !== undefined) { | ||
return this.getDefaultValue(field.defaultOperator); | ||
return this.getOperatorValue(this.getDefaultValue(field.defaultOperator) as Operator); | ||
} else { | ||
const operators = this.getOperators(field.value); | ||
if (operators && operators.length) { | ||
return operators[0]; | ||
return this.getOperatorValue(operators[0]); | ||
} else { | ||
@@ -387,2 +387,10 @@ console.warn(`No operators found for field '${field.value}'. ` + | ||
getOperatorValue(operator: Operator): string { | ||
if (typeof operator === 'string') { | ||
return operator; | ||
} else { | ||
return operator?.value; | ||
} | ||
} | ||
addRule(parent?: RuleSet): void { | ||
@@ -389,0 +397,0 @@ if (this.disabled) { |
@@ -26,2 +26,9 @@ import { ValidationErrors } from '@angular/forms'; | ||
export interface LocalizedOperator { | ||
localized: string; | ||
value: string; | ||
} | ||
export type Operator = string | LocalizedOperator; | ||
export interface Field { | ||
@@ -33,3 +40,3 @@ name: string; | ||
options?: Option[]; | ||
operators?: string[]; | ||
operators?: Operator[]; | ||
defaultValue?: any; | ||
@@ -95,3 +102,3 @@ defaultOperator?: any; | ||
allowEmptyRulesets?: boolean; | ||
getOperators?: (fieldName: string, field: Field) => string[]; | ||
getOperators?: (fieldName: string, field: Field) => Operator[]; | ||
getInputType?: (field: string, operator: string) => string; | ||
@@ -144,3 +151,3 @@ getOptions?: (field: string) => Option[]; | ||
getDisabledState: () => boolean; | ||
operators: string[]; | ||
operators: Operator[]; | ||
$implicit: Rule; | ||
@@ -147,0 +154,0 @@ } |
@@ -42,7 +42,8 @@ # Angular-QueryBuilder | ||
@NgModule(imports: [ | ||
..., | ||
QueryBuilderModule, | ||
IonicModule.forRoot(AppComponent) // (Optional) for IonicFramework 2+ | ||
]) | ||
@NgModule({ | ||
imports: [ | ||
QueryBuilderModule, | ||
IonicModule.forRoot(AppComponent) // (Optional) for IonicFramework 2+ | ||
] | ||
}) | ||
export class AppModule { } | ||
@@ -85,3 +86,3 @@ ``` | ||
``` | ||
~~~~ | ||
## Custom Input Components | ||
@@ -109,5 +110,5 @@ | ||
fields: { | ||
birthday: {name: 'Birthday', type: 'date', operators: ['=', '<=', '>'] | ||
defaultValue: (() => return new Date()) | ||
}, | ||
birthday: {name: 'Birthday', type: 'date', operators: ['=', '<=', '>'], | ||
defaultValue: (() => new Date()) | ||
} | ||
} | ||
@@ -114,0 +115,0 @@ } |
@@ -17,2 +17,5 @@ { | ||
], | ||
"types": [ | ||
"@angular/localize" | ||
], | ||
"allowUnreachableCode": false, | ||
@@ -19,0 +22,0 @@ "allowUnusedLabels": false, |
@@ -7,3 +7,5 @@ { | ||
"inlineSources": true, | ||
"types": [], | ||
"types": [ | ||
"@angular/localize" | ||
], | ||
"target": "ES2022", | ||
@@ -10,0 +12,0 @@ "module": "esnext", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
560651
5563
328
45