@sourceloop/search-client 1.1.2
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/.editorconfig +16 -0
- package/.prettierignore +4 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/angular.json +53 -0
- package/package.json +61 -0
- package/projects/search-lib/.prettierignore +2 -0
- package/projects/search-lib/.prettierrc +7 -0
- package/projects/search-lib/karma.conf.js +41 -0
- package/projects/search-lib/ng-package.json +7 -0
- package/projects/search-lib/package.json +25 -0
- package/projects/search-lib/src/lib/lib-configuration.ts +62 -0
- package/projects/search-lib/src/lib/search/search.component.html +183 -0
- package/projects/search-lib/src/lib/search/search.component.scss +301 -0
- package/projects/search-lib/src/lib/search/search.component.ts +313 -0
- package/projects/search-lib/src/lib/search-lib.module.ts +12 -0
- package/projects/search-lib/src/lib/types.ts +59 -0
- package/projects/search-lib/src/public-api.ts +8 -0
- package/projects/search-lib/src/test.ts +34 -0
- package/projects/search-lib/tsconfig.lib.json +20 -0
- package/projects/search-lib/tsconfig.lib.prod.json +11 -0
- package/projects/search-lib/tsconfig.spec.json +17 -0
- package/tsconfig.json +36 -0
- package/tslint.json +163 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Editor configuration, see https://editorconfig.org
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
charset = utf-8
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.ts]
|
|
12
|
+
quote_type = single
|
|
13
|
+
|
|
14
|
+
[*.md]
|
|
15
|
+
max_line_length = off
|
|
16
|
+
trim_trailing_whitespace = false
|
package/.prettierignore
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## <small>1.1.2 (2021-10-25)</small>
|
|
7
|
+
|
|
8
|
+
* docs(search-client): docs updated for versioning ([5192106](https://github.com/sourcefuse/loopback4-microservice-catalog/commit/5192106)), closes [#0](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/0)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## <small>1.1.1 (2021-10-25)</small>
|
|
15
|
+
|
|
16
|
+
* chore(core): fix package json ([094b79b](https://github.com/sourcefuse/loopback4-microservice-catalog/commit/094b79b)), closes [#0](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/0)
|
|
17
|
+
* Search client fix (#386) ([01a9c99](https://github.com/sourcefuse/loopback4-microservice-catalog/commit/01a9c99)), closes [#386](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/386)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 1.1.0 (2021-10-24)
|
|
24
|
+
|
|
25
|
+
* fix(core): fix all version problems ([7847008](https://github.com/sourcefuse/loopback4-microservice-catalog/commit/7847008)), closes [#0](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/0)
|
|
26
|
+
* feat(search): Initial code for search-lib (#381) ([bf99a13](https://github.com/sourcefuse/loopback4-microservice-catalog/commit/bf99a13)), closes [#381](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/381) [#346](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/346) [#346](https://github.com/sourcefuse/loopback4-microservice-catalog/issues/346)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2020] [SourceFuse]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Search Library
|
|
2
|
+
|
|
3
|
+
An Angular module that exports a component that can enable users to search over configured models using the search microservice provided in the sourceloop microservice catalog.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
First step is to clone the search folder inside the packages folder. Then navigate inside the search folder and run
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
ng build
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This will create a dist folder then navigate inside the dist folder and then to search-lib and run
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm pack
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This will create a Tar Package which can be installed by running the npm install command as follows
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install path-of-tar/name-of-tar.tgz
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Create a new Application using Angular CLI and import the SearchLibModule and add it to the imports array of the module. Also create a new service that implements the ISearchService interface exported by the search library. This service will be used by the exported component to make API calls whenever needed. You will have to update the providers section of your module with { provide: SEARCH_SERVICE_TOKEN, useExisting: Your_Service_Name }
|
|
28
|
+
Your module will then look something like this
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {NgModule} from '@angular/core';
|
|
32
|
+
import {BrowserModule} from '@angular/platform-browser';
|
|
33
|
+
|
|
34
|
+
import {AppComponent} from './app.component';
|
|
35
|
+
|
|
36
|
+
import {HttpClientModule} from '@angular/common/http';
|
|
37
|
+
import {XComponent} from './x/x.component';
|
|
38
|
+
import {ReactiveFormsModule} from '@angular/forms';
|
|
39
|
+
|
|
40
|
+
import {SearchLibModule, SEARCH_SERVICE_TOKEN} from 'search-lib';
|
|
41
|
+
import {SearchService} from './search.service';
|
|
42
|
+
@NgModule({
|
|
43
|
+
declarations: [AppComponent, XComponent],
|
|
44
|
+
imports: [
|
|
45
|
+
BrowserModule,
|
|
46
|
+
SearchLibModule, //import SearchLibModule
|
|
47
|
+
HttpClientModule,
|
|
48
|
+
ReactiveFormsModule,
|
|
49
|
+
],
|
|
50
|
+
providers: [{provide: SEARCH_SERVICE_TOKEN, useClass: SearchService}], //Add your service here
|
|
51
|
+
bootstrap: [AppComponent],
|
|
52
|
+
})
|
|
53
|
+
export class AppModule {}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Search Service
|
|
57
|
+
|
|
58
|
+
Create a new service using the Angular CLI. This service should implement ISearchService. You will have to implement searchApiRequest method which should return Observable<T[]>. Here T refers to the type of data returned from the search microservice. If you are using the default settings for the search microservice you can use IDefaultReturnType interface, else you need to pass your own return type interface.
|
|
59
|
+
searchApiRequest receives two parameters - requestParameters: ISearchQuery, saveInRecents: boolean,
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
export interface ISearchQuery {
|
|
63
|
+
match: string;
|
|
64
|
+
limit: number | null;
|
|
65
|
+
order: string | null;
|
|
66
|
+
limitByType: boolean | null;
|
|
67
|
+
offset: number | null;
|
|
68
|
+
sources: string[] | null;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Implementing the recentSearchApiRequest method is optional and its implementation depends on if you want recent search functionality as a part of the search suggestions dropdown
|
|
73
|
+
|
|
74
|
+
### Configuration
|
|
75
|
+
|
|
76
|
+
You need to provide some configuration for using the search component using its selector - '<sourceloop-search></sourceloop-search>'
|
|
77
|
+
This can be provided as an Object of Configuration type as input to the component. To do so, create a property/field in your component of type Configuration<IDefaultReturnType> (IDefaultReturnType can be replaced by your own return type interface). In the constructor initialize the Configuration object with the following properties:
|
|
78
|
+
|
|
79
|
+
- **displayPropertyName (keyof IDefaultReturnType/Your_Return_Type) :** This is one of the properties returned by the search microservice. It is the property whose value will be displayed in the search dropdown.
|
|
80
|
+
- **models ( Array<IModel>) :** You need to provide the list of models you used in your search microservice. You also need to provide the displayName for each Model, this will be used in the search dropdown and categorize button dropdown.
|
|
81
|
+
|
|
82
|
+
Apart from these there are some optional properties that you can give:
|
|
83
|
+
|
|
84
|
+
- **limit (number) :** The number of results you want to display. Default value is 20.
|
|
85
|
+
- **limitByType (boolean) :** Option to put limit on basis of model. Default value is false.
|
|
86
|
+
- **order (Array<string>) :** Array of strings that specify the order format for the request sent to search API. Example, you want your results to be sorted on basis of name property first and then description. In this case you can give order = ["name ASC", "description DESC"]. By default order = []
|
|
87
|
+
- **offset (number) :** Number of matched results to skip. Default is 0.
|
|
88
|
+
- **saveInRecents (boolean) :** Option for saving the search results of the user. Default value is true.
|
|
89
|
+
- **categorizeResults (boolean) :** Option for displaying results in search dropdown according to the Model they come from. Default value is true.
|
|
90
|
+
- **hideRecentSearch (boolean) :** Option to provide recent search functionality. Default value is false.
|
|
91
|
+
- **hideCategorizeButton (boolean) :** Option to hide the categorize button on the right of search dropdown. Default is false.
|
|
92
|
+
- **saveInRecentsOnlyOnEnter (boolean) :** Option to save search query in recent searches only when user presses enter key or changes the category he/she is searching on. Default value is false.
|
|
93
|
+
- **searchOnlyOnEnter (boolean) :** Option to call API to display search results only when user presses enter key. Default value is false.
|
|
94
|
+
|
|
95
|
+
Your component might look something like
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
export class XComponent implements OnInit {
|
|
99
|
+
config: Configuration<IDefaultReturnType>;
|
|
100
|
+
|
|
101
|
+
constructor(private fb: FormBuilder) {
|
|
102
|
+
this.config = new Configuration<IDefaultReturnType>({
|
|
103
|
+
displayPropertyName: 'name',
|
|
104
|
+
models: [
|
|
105
|
+
{
|
|
106
|
+
name: 'ToDo',
|
|
107
|
+
displayName: 'List',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'User',
|
|
111
|
+
displayName: 'Users',
|
|
112
|
+
imageUrl: 'https://picsum.photos/id/1/50',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
order: [`name ASC`, `description DESC`],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
ngOnInit(): void {}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Now in your template you can add the search library component selector like
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
<sourceloop-search [config]="config" [(ngModel)]="value"></sourceloop-search>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
You can access the value in the search input using [(ngModel)]. You can also listen to clicked and searched events.
|
|
130
|
+
Clicked event is of type ItemClickedEvent. It is emitted when user clicks one of the suggested results (including recent search sugestions). Searched event is emitted when request is made to the api when user types and relevant suggestinons are displayed. It is of type RecentSearchEvent.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
type ItemClickedEvent<T> = {
|
|
134
|
+
event: MouseEvent;
|
|
135
|
+
item: T;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
type RecentSearchEvent = {
|
|
139
|
+
event: KeyboardEvent | Event;
|
|
140
|
+
keyword: string;
|
|
141
|
+
category: 'All' | IModel;
|
|
142
|
+
};
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<sourceloop-search
|
|
147
|
+
[config]="config"
|
|
148
|
+
[(ngModel)]="value"
|
|
149
|
+
(clicked)="logItemClickedEvent($event)"
|
|
150
|
+
(searched)="logRecentSearchEvent($event)"
|
|
151
|
+
disabled="false"
|
|
152
|
+
></sourceloop-search>
|
|
153
|
+
```
|
package/angular.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
|
3
|
+
"cli": {
|
|
4
|
+
"analytics": false
|
|
5
|
+
},
|
|
6
|
+
"version": 1,
|
|
7
|
+
"newProjectRoot": "projects",
|
|
8
|
+
"projects": {
|
|
9
|
+
"search-lib": {
|
|
10
|
+
"projectType": "library",
|
|
11
|
+
"root": "projects/search-lib",
|
|
12
|
+
"sourceRoot": "projects/search-lib/src",
|
|
13
|
+
"prefix": "lib",
|
|
14
|
+
"architect": {
|
|
15
|
+
"build": {
|
|
16
|
+
"builder": "@angular-devkit/build-angular:ng-packagr",
|
|
17
|
+
"options": {
|
|
18
|
+
"project": "projects/search-lib/ng-package.json"
|
|
19
|
+
},
|
|
20
|
+
"configurations": {
|
|
21
|
+
"production": {
|
|
22
|
+
"tsConfig": "projects/search-lib/tsconfig.lib.prod.json"
|
|
23
|
+
},
|
|
24
|
+
"development": {
|
|
25
|
+
"tsConfig": "projects/search-lib/tsconfig.lib.json"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"defaultConfiguration": "production"
|
|
29
|
+
},
|
|
30
|
+
"test": {
|
|
31
|
+
"builder": "@angular-devkit/build-angular:karma",
|
|
32
|
+
"options": {
|
|
33
|
+
"main": "projects/search-lib/src/test.ts",
|
|
34
|
+
"tsConfig": "projects/search-lib/tsconfig.spec.json",
|
|
35
|
+
"karmaConfig": "projects/search-lib/karma.conf.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"lint": {
|
|
39
|
+
"builder": "@angular-devkit/build-angular:tslint",
|
|
40
|
+
"options": {
|
|
41
|
+
"tsConfig": [
|
|
42
|
+
"tsconfig.json"
|
|
43
|
+
],
|
|
44
|
+
"exclude": [
|
|
45
|
+
"**/node_modules/**"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"defaultProject": "search-lib"
|
|
53
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sourceloop/search-client",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "A global search component for search microservice",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"ng": "ng",
|
|
7
|
+
"start": "ng serve",
|
|
8
|
+
"build": "ng build",
|
|
9
|
+
"watch": "ng build --watch --configuration development",
|
|
10
|
+
"test": "echo \"No tests available !\"",
|
|
11
|
+
"lint": "ng lint && npm run prettier:check",
|
|
12
|
+
"prettier:cli": "prettier \"**/*.ts\" \"**/*.js\" \"**/*.html\"",
|
|
13
|
+
"prettier:check": "npm run prettier:cli -- -l",
|
|
14
|
+
"prettier:fix": "npm run prettier:cli -- --write",
|
|
15
|
+
"prepublishOnly": "ng-packagr -p projects/search-lib/package.json"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/sourcefuse/loopback4-microservice-catalog.git",
|
|
20
|
+
"directory": "packages/search"
|
|
21
|
+
},
|
|
22
|
+
"author": "Sourcefuse",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"private": false,
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@angular/animations": "~12.1.5",
|
|
27
|
+
"@angular/common": "~12.1.5",
|
|
28
|
+
"@angular/compiler": "~12.1.5",
|
|
29
|
+
"@angular/core": "~12.1.5",
|
|
30
|
+
"@angular/forms": "~12.1.5",
|
|
31
|
+
"@angular/platform-browser": "~12.1.5",
|
|
32
|
+
"@angular/platform-browser-dynamic": "~12.1.5",
|
|
33
|
+
"@angular/router": "~12.1.5",
|
|
34
|
+
"rxjs": "~6.6.0",
|
|
35
|
+
"tslib": "^2.2.0",
|
|
36
|
+
"zone.js": "~0.11.4"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@angular-devkit/build-angular": "~12.1.4",
|
|
40
|
+
"@angular/cli": "~12.1.3",
|
|
41
|
+
"@angular/compiler-cli": "~12.1.5",
|
|
42
|
+
"@types/jasmine": "~3.8.0",
|
|
43
|
+
"@types/node": "^12.11.1",
|
|
44
|
+
"codelyzer": "^6.0.2",
|
|
45
|
+
"jasmine-core": "~3.8.0",
|
|
46
|
+
"karma": "~6.3.0",
|
|
47
|
+
"karma-chrome-launcher": "~3.1.0",
|
|
48
|
+
"karma-coverage": "~2.0.3",
|
|
49
|
+
"karma-jasmine": "~4.0.0",
|
|
50
|
+
"karma-jasmine-html-reporter": "~1.7.0",
|
|
51
|
+
"ng-packagr": "^12.1.0",
|
|
52
|
+
"prettier": "^2.4.1",
|
|
53
|
+
"tslint": "^6.1.3",
|
|
54
|
+
"typescript": "~4.3.2"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"registry": "https://registry.npmjs.org/",
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "07e7c9f9ff2729c03457773f79c786a298f5157b"
|
|
61
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Karma configuration file, see link for more information
|
|
2
|
+
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
|
3
|
+
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
config.set({
|
|
6
|
+
basePath: '',
|
|
7
|
+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
|
8
|
+
plugins: [
|
|
9
|
+
require('karma-jasmine'),
|
|
10
|
+
require('karma-chrome-launcher'),
|
|
11
|
+
require('karma-jasmine-html-reporter'),
|
|
12
|
+
require('karma-coverage'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma'),
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
jasmine: {
|
|
17
|
+
// you can add configuration options for Jasmine here
|
|
18
|
+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
|
19
|
+
// for example, you can disable the random execution with `random: false`
|
|
20
|
+
// or set a specific seed with `seed: 4321`
|
|
21
|
+
},
|
|
22
|
+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
|
23
|
+
},
|
|
24
|
+
jasmineHtmlReporter: {
|
|
25
|
+
suppressAll: true, // removes the duplicated traces
|
|
26
|
+
},
|
|
27
|
+
coverageReporter: {
|
|
28
|
+
dir: require('path').join(__dirname, '../../coverage/my-lib'),
|
|
29
|
+
subdir: '.',
|
|
30
|
+
reporters: [{type: 'html'}, {type: 'text-summary'}],
|
|
31
|
+
},
|
|
32
|
+
reporters: ['progress', 'kjhtml'],
|
|
33
|
+
port: 9876,
|
|
34
|
+
colors: true,
|
|
35
|
+
logLevel: config.LOG_INFO,
|
|
36
|
+
autoWatch: true,
|
|
37
|
+
browsers: ['Chrome'],
|
|
38
|
+
singleRun: false,
|
|
39
|
+
restartOnFileChange: true,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sourceloop/search-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/animations": "~12.1.5",
|
|
6
|
+
"@angular/common": "^12.1.5",
|
|
7
|
+
"@angular/compiler": "~12.1.5",
|
|
8
|
+
"@angular/core": "^12.1.5",
|
|
9
|
+
"@angular/forms": "~12.1.5",
|
|
10
|
+
"@angular/platform-browser": "~12.1.5",
|
|
11
|
+
"@angular/platform-browser-dynamic": "~12.1.5",
|
|
12
|
+
"@angular/router": "~12.1.5",
|
|
13
|
+
"rxjs": "~6.6.0",
|
|
14
|
+
"zone.js": "~0.11.4"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"tslib": "^2.2.0"
|
|
18
|
+
},
|
|
19
|
+
"ngPackage": {
|
|
20
|
+
"lib": {
|
|
21
|
+
"entryFile": "src/public-api.ts"
|
|
22
|
+
},
|
|
23
|
+
"dest": "../../dist/search-lib"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {IDefaultReturnType, IModel} from './types';
|
|
2
|
+
export class Configuration<T = IDefaultReturnType> {
|
|
3
|
+
/** property to be displayed in the results */
|
|
4
|
+
displayPropertyName: keyof T;
|
|
5
|
+
/** list of model configuration to be render and categorize search results */
|
|
6
|
+
models: IModel[];
|
|
7
|
+
/** max number of results (based on limitByType option) */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** apply limit on individual models, or on overall results */
|
|
10
|
+
limitByType?: boolean;
|
|
11
|
+
/** apply a particular ordering on results */
|
|
12
|
+
order?: string[];
|
|
13
|
+
/** offset for results in case limit is used */
|
|
14
|
+
offset?: number;
|
|
15
|
+
/** save the search query in recent history */
|
|
16
|
+
saveInRecents?: boolean;
|
|
17
|
+
/** a placeholder to display in the search box */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** categorize results on the basis of models provided */
|
|
20
|
+
categorizeResults?: boolean;
|
|
21
|
+
/** hides the recent search list */
|
|
22
|
+
hideRecentSearch?: boolean;
|
|
23
|
+
/** hide the category selection button */
|
|
24
|
+
hideCategorizeButton?: boolean;
|
|
25
|
+
/** save value in recent search only on enter or change in category, if false, also saved on typing */
|
|
26
|
+
saveInRecentsOnlyOnEnter?: boolean;
|
|
27
|
+
/** search only on enter key or when category is changed */
|
|
28
|
+
searchOnlyOnEnter?: boolean;
|
|
29
|
+
|
|
30
|
+
constructor(d: Configuration<T>) {
|
|
31
|
+
if (
|
|
32
|
+
d.categorizeResults === false &&
|
|
33
|
+
(d.hideCategorizeButton === false || d.hideCategorizeButton === undefined)
|
|
34
|
+
) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'You must provide hideCategorizeButton:true as categorizeResults is false',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (d.saveInRecents === false && d.saveInRecentsOnlyOnEnter === true) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
'You must provide saveInRecents:true for saveInRecentsOnlyOnEnter:true',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
this.displayPropertyName = d.displayPropertyName;
|
|
45
|
+
this.models = d.models;
|
|
46
|
+
|
|
47
|
+
this.placeholder = d.placeholder ?? 'Search';
|
|
48
|
+
/* IRequestParameters - will be given default values before call is made in case undefined/null,
|
|
49
|
+
otherwise there ! is used on which sonar gives code smell */
|
|
50
|
+
this.limit = d.limit;
|
|
51
|
+
this.limitByType = d.limitByType;
|
|
52
|
+
this.order = d.order;
|
|
53
|
+
this.offset = d.offset;
|
|
54
|
+
this.saveInRecents = d.saveInRecents;
|
|
55
|
+
|
|
56
|
+
this.categorizeResults = d.categorizeResults ?? true;
|
|
57
|
+
this.hideRecentSearch = d.hideRecentSearch ?? false;
|
|
58
|
+
this.hideCategorizeButton = d.hideCategorizeButton ?? false;
|
|
59
|
+
this.saveInRecentsOnlyOnEnter = d.saveInRecentsOnlyOnEnter ?? false;
|
|
60
|
+
this.searchOnlyOnEnter = d.searchOnlyOnEnter ?? false;
|
|
61
|
+
}
|
|
62
|
+
}
|