arlas-web-core 18.1.0 → 19.3.0-dev0

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 (43) hide show
  1. package/.editorconfig +13 -0
  2. package/.gitlab-ci.yml +19 -0
  3. package/.travis.yml +27 -0
  4. package/CHANGELOG.md +446 -0
  5. package/CONTRIBUTING.md +48 -0
  6. package/{LICENSE → LICENSE.txt} +0 -0
  7. package/NOTICE.txt +10 -0
  8. package/README-NPM.md +78 -0
  9. package/README.md +2 -2
  10. package/arlas-web-core-19.3.0-dev0.tgz +0 -0
  11. package/build.sh +9 -0
  12. package/jsconfig.json +13 -0
  13. package/mkDocs.sh +18 -0
  14. package/package-release.json +25 -0
  15. package/package.json +13 -7
  16. package/release.sh +429 -0
  17. package/{index.js → src/index.ts} +7 -4
  18. package/{models/collaboration.js → src/models/collaboration.ts} +30 -6
  19. package/src/models/contributor.ts +161 -0
  20. package/src/models/projections.ts +58 -0
  21. package/{services/collaborativesearch.service.js → src/services/collaborativesearch.service.ts} +383 -176
  22. package/{services/config.service.js → src/services/config.service.ts} +15 -11
  23. package/src/utils/utils.ts +80 -0
  24. package/tsconfig-build.json +21 -0
  25. package/tsconfig.json +15 -0
  26. package/tslint.json +116 -0
  27. package/index.d.ts +0 -6
  28. package/index.js.map +0 -1
  29. package/models/collaboration.d.ts +0 -29
  30. package/models/collaboration.js.map +0 -1
  31. package/models/contributor.d.ts +0 -56
  32. package/models/contributor.js +0 -116
  33. package/models/contributor.js.map +0 -1
  34. package/models/projections.d.ts +0 -35
  35. package/models/projections.js +0 -38
  36. package/models/projections.js.map +0 -1
  37. package/services/collaborativesearch.service.d.ts +0 -313
  38. package/services/collaborativesearch.service.js.map +0 -1
  39. package/services/config.service.d.ts +0 -31
  40. package/services/config.service.js.map +0 -1
  41. package/utils/utils.d.ts +0 -18
  42. package/utils/utils.js +0 -63
  43. package/utils/utils.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ /*
2
+ * Licensed to Gisaïa under one or more contributor
3
+ * license agreements. See the NOTICE.txt file distributed with
4
+ * this work for additional information regarding copyright
5
+ * ownership. Gisaïa licenses this file to you under
6
+ * the Apache License, Version 2.0 (the "License"); you may
7
+ * not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ import { ConfigService } from '../services/config.service';
21
+ import { CollaborativesearchService } from '../services/collaborativesearch.service';
22
+ import { CollaborationEvent, Collaboration } from './collaboration';
23
+ import { Observable, Subject } from 'rxjs';
24
+ import { map, finalize, filter, debounceTime } from 'rxjs/operators';
25
+ import { CollectionAggField, hasAtLeastOneCommon as hasAtLeastOneCommon } from '../utils/utils';
26
+
27
+ export abstract class Contributor {
28
+
29
+ private name: string;
30
+ private fetchedData: any;
31
+ private _updateData = true;
32
+ public isDataUpdating = false;
33
+ public collection: string;
34
+ public collections: CollectionAggField[];
35
+ public endCollaborationEvent = new Subject();
36
+ protected cacheDuration: number;
37
+
38
+
39
+ /**
40
+ * @param identifier string identifier of the contributor.
41
+ * @param configService configService of the contributor.
42
+ */
43
+ constructor(public identifier: string,
44
+ public configService: ConfigService,
45
+ public collaborativeSearcheService: CollaborativesearchService, collection?: string) {
46
+ if (!!collection) {
47
+ this.collection = collection;
48
+ } else {
49
+ this.collection = this.collaborativeSearcheService.defaultCollection;
50
+ }
51
+ const configDebounceTime = this.configService.getValue('arlas.server.debounceCollaborationTime');
52
+ const debounceDuration = configDebounceTime !== undefined ? configDebounceTime : 750;
53
+ const configName = this.getConfigValue('name');
54
+ const configCacheDuration = this.getConfigValue('cache_duration');
55
+ this.cacheDuration = configCacheDuration ? configCacheDuration : this.collaborativeSearcheService.max_age;
56
+ this.name = configName ? configName : this.identifier;
57
+ // Register the contributor in collaborativeSearcheService registry
58
+ this.collaborativeSearcheService.register(this.identifier, this);
59
+ // Subscribe a bus to update data and selection
60
+ this.collaborativeSearcheService.collaborationBus.pipe(debounceTime(debounceDuration))
61
+ .subscribe(collaborationEvent => {
62
+ // Update only contributor of same collection that the current collaboration or on the init whit the url
63
+ let collaborationCollections;
64
+ if (!!this.collaborativeSearcheService.registry.get(collaborationEvent.id)) {
65
+ collaborationCollections = this.collaborativeSearcheService.registry.get(collaborationEvent.id).collections;
66
+ }
67
+ const cs1 = !!this.collections ? this.collections.map(c => c.collectionName) : [];
68
+ const cs2 = !!collaborationCollections ? collaborationCollections.map(c => c.collectionName) : [];
69
+ const update = collaborationEvent.id === 'url' || collaborationEvent.id === 'all' || hasAtLeastOneCommon(cs1, cs2) ;
70
+ if (this._updateData && update) {
71
+ this.updateFromCollaboration(<CollaborationEvent>collaborationEvent);
72
+ }
73
+ },
74
+ error => this.collaborativeSearcheService.collaborationErrorBus.next(error)
75
+ );
76
+ }
77
+ /**
78
+ * @returns package name of contributor used in configuration.
79
+ */
80
+ public abstract getPackageName(): string;
81
+
82
+ /**
83
+ * @param key a `key` defined in configuration.
84
+ * @returns value of the `key` in configuration.
85
+ */
86
+ public getConfigValue(key: string): any {
87
+ let configValue = null;
88
+ const contributor = this.configService.getValue('arlas.web.contributors').find(
89
+ contrib => contrib.identifier === this.identifier
90
+ );
91
+ if (contributor) {
92
+ configValue = contributor[key];
93
+ }
94
+ return configValue;
95
+ }
96
+
97
+ /**
98
+ * @returns name of contributor set in configuration.
99
+ */
100
+ public getName(): string {
101
+ return this.name;
102
+ }
103
+
104
+ /**
105
+ * @returns set the name of the contributor
106
+ */
107
+ public setName(name: string): void {
108
+ this.name = name;
109
+ }
110
+
111
+ /**
112
+ * @returns whether the data of contributor should be updated.
113
+ */
114
+ public get updateData(): boolean {
115
+ return this._updateData;
116
+ }
117
+
118
+ /**
119
+ * @param value set if the data of contributor should be updated or not.
120
+ */
121
+ public set updateData(value) {
122
+ this._updateData = value;
123
+ }
124
+
125
+
126
+ /**
127
+ * @returns name and live informations about filter contributor.
128
+ */
129
+ public abstract getFilterDisplayName(): string;
130
+
131
+ public abstract fetchData(collaborationEvent: CollaborationEvent): Observable<any>;
132
+
133
+ public abstract computeData(data: any): any;
134
+
135
+ public abstract setData(data: any): any;
136
+
137
+ public abstract setSelection(data: any, c: Collaboration): any;
138
+
139
+ public updateFromCollaboration(collaborationEvent: CollaborationEvent) {
140
+ this.collaborativeSearcheService.ongoingSubscribe.next(1);
141
+ this.isDataUpdating = true;
142
+ this.fetchData(collaborationEvent)
143
+ .pipe(
144
+ map(f => this.computeData(f)),
145
+ map(f => { this.fetchedData = f; this.setData(f); }),
146
+ finalize(() => {
147
+ this.setSelection(this.fetchedData, this.collaborativeSearcheService.getCollaboration(this.identifier));
148
+ this.collaborativeSearcheService.contribFilterBus
149
+ .next(this.collaborativeSearcheService.registry.get(this.identifier));
150
+ this.collaborativeSearcheService.ongoingSubscribe.
151
+ next(-1);
152
+ this.isDataUpdating = false;
153
+ this.endCollaborationEvent.next({});
154
+ })
155
+ )
156
+ .subscribe(
157
+ data => data,
158
+ error => this.collaborativeSearcheService.collaborationErrorBus.next(error)
159
+ );
160
+ }
161
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Licensed to Gisaïa under one or more contributor
3
+ * license agreements. See the NOTICE.txt file distributed with
4
+ * this work for additional information regarding copyright
5
+ * ownership. Gisaïa licenses this file to you under
6
+ * the Apache License, Version 2.0 (the "License"); you may
7
+ * not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ import { Search, Aggregation } from 'arlas-api';
21
+
22
+ /**
23
+ * Enum ARLAS SERVER type of request.
24
+ */
25
+ export enum projType {
26
+ aggregate,
27
+ geoaggregate,
28
+ geohashgeoaggregate,
29
+ geotilegeoaggregate,
30
+ count,
31
+ search,
32
+ geosearch,
33
+ tiledgeosearch,
34
+ /**range is deprecated and will be removed in v13.0.0 */
35
+ range,
36
+ compute,
37
+ shapesearch,
38
+ shapeaggregate
39
+ }
40
+
41
+ export interface TiledSearch {
42
+ search: Search;
43
+ x: number;
44
+ y: number;
45
+ z: number;
46
+ }
47
+
48
+ export interface GeohashAggregation {
49
+ geohash: string;
50
+ aggregations: Array<Aggregation>;
51
+ }
52
+
53
+ export interface GeoTileAggregation {
54
+ x: number;
55
+ y: number;
56
+ z: number;
57
+ aggregations: Array<Aggregation>;
58
+ }