@partium/js-sdk 14.0.3 → 14.2.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.
- package/catalog/index.js +21 -1
- package/catalog/models/catalog-image-info.js +22 -1
- package/catalog/models/catalog-image.js +40 -1
- package/catalog/models/upsert-catalog-images-dto.js +3 -1
- package/catalog/models/upsert-images-result.js +3 -1
- package/catalog/services/images.service.js +62 -1
- package/core/constants/constants.js +16 -1
- package/core/decorators/injection-identifier.js +19 -1
- package/core/factories/paginated-request-service.factory.js +33 -1
- package/core/index.js +63 -1
- package/core/integration-defaults/http/fetch-api-http-error-helper.js +129 -1
- package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +138 -1
- package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +210 -1
- package/core/integration-defaults/http/handle-axios-error-helper.js +79 -1
- package/core/integration-defaults/http/https-client/axios-https-client.service.js +182 -1
- package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +198 -1
- package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +32 -1
- package/core/integration-defaults/js-p-file.js +36 -1
- package/core/integration-defaults/session/js-oauth-api-key-session.service.js +206 -1
- package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +64 -1
- package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +257 -1
- package/core/integration-defaults/web-device-status.service.js +125 -1
- package/core/integration-defaults/web-file.service.js +135 -1
- package/core/integration-defaults/web-indexeddb.service.js +142 -1
- package/core/integration-defaults/web-local-storage.service.js +310 -1
- package/core/models/api-object.js +16 -1
- package/core/models/auth-config.js +72 -1
- package/core/models/device-info.js +34 -1
- package/core/models/error.js +107 -1
- package/core/models/formatted-string.js +14 -1
- package/core/models/i18n-map.js +61 -1
- package/core/models/i18n-string.js +35 -1
- package/core/models/log.js +137 -1
- package/core/models/organization.js +159 -1
- package/core/models/p-file.js +23 -1
- package/core/models/paginated-list.js +41 -1
- package/core/models/partium-config.js +43 -1
- package/core/models/user-token.js +11 -1
- package/core/models/user.d.ts +2 -1
- package/core/models/user.js +89 -1
- package/core/services/backend-status.service.js +147 -1
- package/core/services/base-login-init.service.js +57 -1
- package/core/services/base.service.js +37 -1
- package/core/services/device-status.service.interface.js +117 -1
- package/core/services/file.service.interface.js +61 -1
- package/core/services/http/file-transfer/file-transfer.service.interface.js +125 -1
- package/core/services/http/https-client/https-client.service.interface.js +152 -1
- package/core/services/http/https.service.interface.js +294 -1
- package/core/services/http/oauth-https.service.js +218 -1
- package/core/services/local-storage.service.interface.js +378 -1
- package/core/services/log.service.js +139 -1
- package/core/services/organization.service.js +202 -1
- package/core/services/paginated-request.service.js +160 -1
- package/core/services/recent-parts.service.js +194 -1
- package/core/services/service-provider.js +114 -1
- package/core/services/session/oauth-session.service.js +104 -1
- package/core/services/session/session.service.interface.js +367 -1
- package/core/utils/general-helper.js +110 -1
- package/data/index.js +44 -1
- package/data/models/announcement.js +70 -1
- package/data/models/assembly-hierarchy-node-breadcrumb.js +51 -1
- package/data/models/assembly-hierarchy-node.js +46 -1
- package/data/models/attribute.js +106 -1
- package/data/models/csa-request-search.js +46 -1
- package/data/models/csa-request-status.js +51 -1
- package/data/models/csa-request.js +112 -1
- package/data/models/document.js +17 -1
- package/data/models/filter-key.js +36 -1
- package/data/models/filter-option-value.js +41 -1
- package/data/models/image.d.ts +3 -1
- package/data/models/image.js +77 -1
- package/data/models/inquiry.js +71 -1
- package/data/models/mounting-location.js +58 -1
- package/data/models/multiple-expert-searches.js +40 -1
- package/data/models/part-enrichment-data.js +50 -1
- package/data/models/part.js +168 -1
- package/data/models/shopping-cart.js +60 -1
- package/data/services/announcement.service.js +89 -1
- package/data/services/assembly-hierarchy-nodes.service.js +193 -1
- package/data/services/csa-helper.service.js +158 -1
- package/data/services/customer-service-assistance.service.js +276 -1
- package/data/services/filter.service.js +97 -1
- package/data/services/inquiry.service.js +68 -1
- package/data/services/part-attribute.service.js +118 -1
- package/data/services/part-enrichment.service.js +56 -1
- package/data/services/part.service.js +182 -1
- package/data/services/related-parts.service.js +83 -1
- package/data/services/shopping-cart.service.js +152 -1
- package/find/index.js +51 -1
- package/find/models/assets/asset.js +32 -1
- package/find/models/search-filter.js +205 -1
- package/find/models/search-input.js +3 -1
- package/find/models/search-output.js +3 -1
- package/find/models/search-result-status.js +40 -1
- package/find/models/search-session-log-object.js +22 -1
- package/find/models/search-status/cv-search-status.js +22 -1
- package/find/models/search-status/search-filter-status.js +36 -1
- package/find/models/search-status/search-status.js +56 -1
- package/find/models/search-status/tag-search-status.js +23 -1
- package/find/models/search-status/text-search-status.js +18 -1
- package/find/models/search-tag.js +16 -1
- package/find/models/smart-filter.js +49 -1
- package/find/models/tagable/i18n-tagable.js +37 -1
- package/find/models/tagable/tagable-base.js +22 -1
- package/find/models/tagable/tagable.js +37 -1
- package/find/models/text-search-config.js +70 -1
- package/find/models/text-search-manipulator.js +90 -1
- package/find/models/text-search-result-item/text-search-error.js +12 -1
- package/find/models/text-search-result-item/text-search-result-item-document.js +34 -1
- package/find/models/text-search-result-item/text-search-result-item-part.js +36 -1
- package/find/models/text-search-result-item/text-search-result-item-recent-query.js +35 -1
- package/find/models/text-search-result-item/text-search-result-item-unknown.js +38 -1
- package/find/models/text-search-result-item/text-search-result-item.js +22 -1
- package/find/services/asset.service.js +348 -1
- package/find/services/filter-uploaders/filter-uploader.js +3 -1
- package/find/services/filter-uploaders/update-filters-uploader.js +77 -1
- package/find/services/filter-uploaders/update-filters.model.js +7 -1
- package/find/services/search/cv-search.service.js +214 -1
- package/find/services/search/recent-text-search-queries.service.js +260 -1
- package/find/services/search/search-result.service.js +539 -1
- package/find/services/search/search.service.js +514 -1
- package/find/services/search/tag-search.service.js +124 -1
- package/find/services/search/text-search.service.js +316 -1
- package/find/services/search-filter.service.js +292 -1
- package/find/utils/search-helper.js +75 -1
- package/gen/sdk-version.d.ts +1 -1
- package/gen/sdk-version.js +5 -1
- package/index.js +392 -1
- package/management/index.js +21 -1
- package/management/models/api-key-list-response.js +3 -1
- package/management/models/api-key-type.js +9 -1
- package/management/models/api-key.js +3 -1
- package/management/services/api-key.service.js +53 -1
- package/ocr/index.js +20 -1
- package/ocr/models/detect-response.js +3 -1
- package/ocr/models/detected-text-entry.js +3 -1
- package/ocr/services/ocr.service.js +59 -1
- package/package.json +1 -1
- package/user-data/index.js +21 -1
- package/user-data/models/part-with-nullable.js +3 -1
- package/user-data/models/request-list/request-list.js +63 -1
- package/user-data/services/favorite/favorite.service.js +108 -1
- package/user-data/services/request-list/request-list.service.js +133 -1
|
@@ -1,2 +1,540 @@
|
|
|
1
1
|
// Copyright © 2022-2025 Partium, Inc. DBA Partium
|
|
2
|
-
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])},e(t,s)};return function(t,s){if("function"!=typeof s&&null!==s)throw new TypeError("Class extends value "+String(s)+" is not a constructor or null");function r(){this.constructor=t}e(t,s),t.prototype=null===s?Object.create(s):(r.prototype=s.prototype,new r)}}(),__decorate=this&&this.__decorate||function(e,t,s,r){var a,i=arguments.length,c=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,s):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,s,r);else for(var u=e.length-1;u>=0;u--)(a=e[u])&&(c=(i<3?a(c):i>3?a(t,s,c):a(t,s))||c);return i>3&&c&&Object.defineProperty(t,s,c),c},__spreadArray=this&&this.__spreadArray||function(e,t,s){if(s||2===arguments.length)for(var r,a=0,i=t.length;a<i;a++)!r&&a in t||(r||(r=Array.prototype.slice.call(t,0,a)),r[a]=t[a]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SearchResultService=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),_=require("lodash"),search_tag_1=require("../../models/search-tag"),tag_search_service_1=require("./tag-search.service"),search_result_status_1=require("../../models/search-result-status"),text_search_service_1=require("./text-search.service"),cv_search_service_1=require("./cv-search.service"),search_filter_service_1=require("../search-filter.service"),part_1=require("../../../data/models/part"),injection_identifier_1=require("../../../core/decorators/injection-identifier"),base_service_1=require("../../../core/services/base.service"),https_service_interface_1=require("../../../core/services/http/https.service.interface"),error_1=require("../../../core/models/error"),part_service_1=require("../../../data/services/part.service"),i18n_string_1=require("../../../core/models/i18n-string"),smart_filter_1=require("../../models/smart-filter"),data_1=require("../../../data"),search_filter_1=require("../../models/search-filter"),SearchResultService=function(e){function t(t){var s=e.call(this,t)||this;return s.POLLING_INTERVAL=1e3,s.MAX_REQUEST_TIMEOUT=2e4,s.MAX_POLLING_TIMEOUT=6e4,s.searchErrors=[],s.RESULT_LIST_LIMIT=20,s.resultListSkip=0,s.curResultList$=new rxjs_1.BehaviorSubject({results:null,moreResultsAvailable:!1}),s.searchResultStatus$=new rxjs_1.BehaviorSubject(null),s.curSmartFilters$=new rxjs_1.BehaviorSubject([]),s}return __extends(t,e),t.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService),this.filterService=this.serviceProvider.getService(data_1.FilterServiceImpl),this.partService=this.serviceProvider.getService(part_service_1.PartServiceImpl),this.tagSearchService=this.serviceProvider.getService(tag_search_service_1.TagSearchServiceImpl),this.cvSearchService=this.serviceProvider.getService(cv_search_service_1.CvSearchServiceImpl),this.textSearchService=this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl),this.searchFilterService=this.serviceProvider.getService(search_filter_service_1.SearchFilterServiceImpl)},t.prototype.reset=function(e){this.searchStatus=e,this.updateCurResultList([],!1),this.stopPollingForResults(),this.searchErrors=[],this.prevSearchResultTimestamp=null,this.prevProposedTagsUpdatedTimestamp=null,this.prevSmartFiltersUpdateTimestamp=null,this.searchResultStatus$.next(this.searchStatus.searchResultStatus)},t.prototype.startPollingForResults=function(){var e=this;if(this.searchStatus){this.searchStatus.searchResultStatus.status=search_result_status_1.SEARCH_RESULT_STATUS.RUNNING,this.searchResultStatus$.next(this.searchStatus.searchResultStatus),this.stopPollingForResults(),this.resultListSkip=0,this.loadMoreResultsSubscription&&this.loadMoreResultsSubscription.unsubscribe();var t=Math.round(this.MAX_POLLING_TIMEOUT/this.POLLING_INTERVAL);this.pollingSubscription=(0,rxjs_1.timer)(0,this.POLLING_INTERVAL).pipe((0,operators_1.tap)((function(e){if(e>t)throw new error_1.SdkError(error_1.SDK_ERROR_CODES.SEARCH_RESULT_TIMEOUT,null)})),(0,operators_1.exhaustMap)((function(){return e.httpsService.get("search/".concat(e.searchStatus.searchSessionID),[{skip:e.resultListSkip},{limit:e.RESULT_LIST_LIMIT}]).pipe((0,operators_1.timeout)(e.MAX_REQUEST_TIMEOUT),(0,operators_1.catchError)((function(e){return console.log("Error during polling: ",e),(0,rxjs_1.of)({})})))})),(0,operators_1.tap)((function(t){if(t.status===search_result_status_1.SEARCH_RESULT_STATUS.RUNNING||t.status===search_result_status_1.SEARCH_RESULT_STATUS.FINISHED){var s=e.searchStatus.searchResultStatus.asyncTagsStatus===search_result_status_1.ASYNC_TAG_STATUS.PENDING&&t.asyncTagsStatus===search_result_status_1.ASYNC_TAG_STATUS.RECEIVED;e.updateProposedTags(t,s),e.updateSearchResults(t),e.updateSearchInput(t),e.updateSmartFilters(t),e.updateFilters(t),e.updateErrors(t),e.searchStatus.searchResultStatus.status=t.status,e.searchStatus.searchResultStatus.asyncTagsStatus=t.asyncTagsStatus,e.searchStatus.searchResultStatus.asyncResultsStatus=t.asyncResultsStatus,e.searchStatus.searchResultStatus.asyncSmartFiltersStatus=t.asyncSmartFiltersStatus,e.searchResultStatus$.next(e.searchStatus.searchResultStatus)}})),(0,operators_1.filter)((function(e){return e.status===search_result_status_1.SEARCH_RESULT_STATUS.FINISHED||e.status===search_result_status_1.SEARCH_RESULT_STATUS.CREATED})),(0,operators_1.take)(1)).subscribe((function(){}),(function(t){console.log("Error in polling subscription:",t),t instanceof error_1.SdkError&&e.curResultList$.next(t),e.searchStatus.searchResultStatus.status=search_result_status_1.SEARCH_RESULT_STATUS.FINISHED,e.searchResultStatus$.next(e.searchStatus.searchResultStatus)}))}},t.prototype.stopPollingForResults=function(){this.pollingSubscription&&this.pollingSubscription.unsubscribe()},t.prototype.getCurResultList=function(){return this.curResultList$.asObservable()},t.prototype.getSearchResultStatus=function(){return this.searchResultStatus$.asObservable()},t.prototype.getCurResultListLength=function(){return this.searchStatus.curResultList.length},t.prototype.getCurResultListValue=function(){return this.searchStatus.curResultList},t.prototype.getSmartFilters=function(){return this.curSmartFilters$.asObservable()},t.prototype.updateProposedTags=function(e,t){if(void 0===t&&(t=!1),e.timestamps&&e.timestamps.proposedTagsUpdate&&(!this.prevProposedTagsUpdatedTimestamp||this.prevProposedTagsUpdatedTimestamp<new Date(e.timestamps.proposedTagsUpdate))&&e.proposedTags){for(var s,r=this.searchStatus.tagSearchStatus.proposedSearchTags||[],a=(e.proposedTags||[]).slice(0),i=function(e){var t=a.findIndex((function(t){return t.value===r[e].value}));t>=0?(Object.assign(r[e],a[t]),a.splice(t,1)):(r.splice(e,1),e--),s=e},c=0;c<r.length;c++)i(c),c=s;for(var u=0,o=a;u<o.length;u++){var n=o[u];r.push(new search_tag_1.SearchTag(Object.assign(n,{isAsync:t})))}var l=function(t){var s=r.findIndex((function(s){return s.value===e.proposedTags[t].value})),a=r.splice(s,1)[0];r.splice(t,0,a)};for(c=0;c<r.length;c++)l(c);this.tagSearchService.updateProposedTags(r),this.prevProposedTagsUpdatedTimestamp=new Date(e.timestamps.proposedTagsUpdate)}},t.prototype.updateSearchResults=function(e){if(e.timestamps&&e.timestamps.resultsUpdate&&(!this.prevSearchResultTimestamp||this.prevSearchResultTimestamp<new Date(e.timestamps.resultsUpdate))){if(e.results&&e.results.entities){var t=[];t=this.processSearchResults(e.results.entities),t=_.orderBy(t,["confidence"],["desc"]),this.updateCurResultList(t.map((function(e){return e.part})),!e.lastResultsPage)}this.prevSearchResultTimestamp=new Date(e.timestamps.resultsUpdate)}},t.prototype.updateSearchInput=function(e){var t;e.searchInputs&&(e.searchInputs.image&&e.searchInputs.image!==(null===(t=this.searchStatus.cvSearchStatus.cvImage)||void 0===t?void 0:t.referenceId)&&this.cvSearchService.setStatusExternal(this.searchStatus,e.searchInputs.image,e.searchInputs.cropArea),e.searchInputs.text&&e.searchInputs.text!==this.searchStatus.textSearchStatus.searchQuery&&this.textSearchService.setStatusExternal(this.searchStatus,e.searchInputs.text),e.searchInputs.textSearch&&!_.isEqual(e.searchInputs.textSearch,this.searchStatus.textSearchStatus.searchQueries)&&this.textSearchService.setStatusExternal(this.searchStatus,null,null,e.searchInputs.textSearch))},t.prototype.updateSmartFilters=function(e){if(e.timestamps&&e.timestamps.smartFiltersUpdate&&(!this.prevSmartFiltersUpdateTimestamp||this.prevSmartFiltersUpdateTimestamp<new Date(e.timestamps.smartFiltersUpdate))&&e.smartFilters){var t=e.smartFilters.map((function(e){return smart_filter_1.SmartFilter.fromAPIResponse(e)}));this.curSmartFilters$.next(t),this.prevSmartFiltersUpdateTimestamp=new Date(e.timestamps.smartFiltersUpdate)}},t.prototype.updateFilters=function(e){var t=e.searchInputs&&e.searchInputs.filters&&Object.keys(e.searchInputs.filters).length>0,s=t&&e.searchInputs.filters.hardFilters?e.searchInputs.filters.hardFilters:[],r=this.checkIfFiltersChanged(s);t&&r?this.setMappedFilters(e):this.searchFilterService.searchFiltersLoaded$.next(!0)},t.prototype.checkIfFiltersChanged=function(e){var t=!1,s=e.map((function(e){return e.label})).sort(),r=[];if(Object.values(this.searchStatus.filterStatus.filtersMap).forEach((function(e){if("hierarchy-partium-id"!==e.key){var t=e;r.push(t.label)}})),r.sort(),0===r.length)t=!0;else for(var a=0;a<r.length;a++)if(!1===s.includes(r[a])){t=!0;break}return t},t.prototype.setMappedFilters=function(e){var t=this,s=e.searchInputs.filters,r=s.hardFilters,a=s.hierarchy,i=1;r&&(i=Object.keys(e.searchInputs.filters.hardFilters).length),this.filterService.searchMultipleFilterKeys(e.searchInputs.filters,e.language||this.searchStatus.searchLanguage,500).pipe((0,operators_1.last)(),(0,operators_1.mergeMap)((function(e){t.filterKeys=e;var s=t.mapSelectedFilters(e,r,a);return(0,rxjs_1.of)(s)})),(0,operators_1.take)(Math.max(i,1))).subscribe((function(e){e&&t.searchFilterService.setStatusExternal(t.searchStatus,e)}))},t.prototype.mapSelectedFilters=function(e,t,s){var r=[];return e&&e.length>0&&e.forEach((function(e){if(e){var s=t.find((function(t){return t.label===e.name}));r.push(new search_filter_1.KvpHardFilter(e.partiumId,e.name,s.values))}})),this.searchFilterService.mapFiltersToUploadFilterFormat(r,s)},t.prototype.updateErrors=function(e){if(e.errors&&e.errors.length>0)for(var t=function(e){if(!s.searchErrors.find((function(t){return t.code===e.code&&t.detail&&t.detail.timestamp===e.timestamp}))){var t=new error_1.SdkError(e.code,e,e.message);t.code===error_1.SDK_ERROR_CODES.IMAGE_SEARCH_ERROR&&s.searchStatus.cvSearchStatus.setImage(null),s.curResultList$.next(t),s.searchErrors.push(t)}},s=this,r=0,a=e.errors;r<a.length;r++){t(a[r])}},t.prototype.updateCurResultList=function(e,t){void 0===t&&(t=!0),this.searchStatus?(this.searchStatus.curResultList=e,this.curResultList$.next({results:this.searchStatus.curResultList,moreResultsAvailable:t})):this.curResultList$.next(null)},t.prototype.processSearchResults=function(e){return e.filter((function(e){return e.confidence>0})).map((function(e){return{part:new part_1.Part({name:new i18n_string_1.i18nString(e.name),partiumId:e.partiumId,externalId:e.externalId,externalPayload:e.externalPayload,dataOrigin:part_1.DATA_ORIGIN.PARTIAL}),confidence:e.confidence}}))},t.prototype.loadMoreResults=function(){var e=this;console.log("Loading more results...",this.searchStatus.searchSessionID),this.resultListSkip+=this.RESULT_LIST_LIMIT,this.loadMoreResultsSubscription=this.httpsService.get("search/".concat(this.searchStatus.searchSessionID),[{skip:this.resultListSkip},{limit:this.RESULT_LIST_LIMIT}]).pipe((0,operators_1.map)((function(t){if((t.status===search_result_status_1.SEARCH_RESULT_STATUS.RUNNING||t.status===search_result_status_1.SEARCH_RESULT_STATUS.FINISHED)&&t.timestamps&&t.timestamps.resultsUpdate&&e.prevSearchResultTimestamp<=new Date(t.timestamps.resultsUpdate)){var s=e.processSearchResults(t.results.entities).map((function(e){return e.part}));e.searchStatus.curResultList instanceof Array&&e.updateCurResultList(__spreadArray(__spreadArray([],e.searchStatus.curResultList,!0),s,!0),!t.lastResultsPage)}})),(0,operators_1.catchError)((function(e){return(0,rxjs_1.of)({moreResultsAvailable:!0,error:e,newResults:[]})}))).subscribe()},t=__decorate([(0,injection_identifier_1.InjectionIdentifier)("SearchResultService")],t)}(base_service_1.BaseService);exports.SearchResultService=SearchResultService;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
+
if (ar || !(i in from)) {
|
|
27
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
+
ar[i] = from[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.SearchResultService = void 0;
|
|
35
|
+
var rxjs_1 = require("rxjs");
|
|
36
|
+
var operators_1 = require("rxjs/operators");
|
|
37
|
+
var _ = require("lodash");
|
|
38
|
+
var search_tag_1 = require("../../models/search-tag");
|
|
39
|
+
var tag_search_service_1 = require("./tag-search.service");
|
|
40
|
+
var search_result_status_1 = require("../../models/search-result-status");
|
|
41
|
+
var text_search_service_1 = require("./text-search.service");
|
|
42
|
+
var cv_search_service_1 = require("./cv-search.service");
|
|
43
|
+
var search_filter_service_1 = require("../search-filter.service");
|
|
44
|
+
var part_1 = require("../../../data/models/part");
|
|
45
|
+
var injection_identifier_1 = require("../../../core/decorators/injection-identifier");
|
|
46
|
+
var base_service_1 = require("../../../core/services/base.service");
|
|
47
|
+
var https_service_interface_1 = require("../../../core/services/http/https.service.interface");
|
|
48
|
+
var error_1 = require("../../../core/models/error");
|
|
49
|
+
var part_service_1 = require("../../../data/services/part.service");
|
|
50
|
+
var i18n_string_1 = require("../../../core/models/i18n-string");
|
|
51
|
+
var smart_filter_1 = require("../../models/smart-filter");
|
|
52
|
+
var data_1 = require("../../../data");
|
|
53
|
+
var search_filter_1 = require("../../models/search-filter");
|
|
54
|
+
/**
|
|
55
|
+
* Service that is responsible for polling for Search-Results, as well as
|
|
56
|
+
* Tags and provide both to listeners.
|
|
57
|
+
*
|
|
58
|
+
* @deprecated use SearchService.performSearch instead
|
|
59
|
+
*/
|
|
60
|
+
var SearchResultService = /** @class */ (function (_super) {
|
|
61
|
+
__extends(SearchResultService, _super);
|
|
62
|
+
function SearchResultService(serviceProvider) {
|
|
63
|
+
var _this = _super.call(this, serviceProvider) || this;
|
|
64
|
+
_this.POLLING_INTERVAL = 1000; // result polling interval in ms
|
|
65
|
+
_this.MAX_REQUEST_TIMEOUT = 20 * 1000; // when to timeout each polling request
|
|
66
|
+
_this.MAX_POLLING_TIMEOUT = 60 * 1000; // when to stop polling if no result is coming in.
|
|
67
|
+
_this.searchErrors = []; // during search-processing in backend errors can appear. These errors will be coming along with the search result and don't necessarily mean that the whole search failed
|
|
68
|
+
_this.RESULT_LIST_LIMIT = 20; // How many results items would be retrieve from each API search request
|
|
69
|
+
_this.resultListSkip = 0; // How many results items would be skip from API search request
|
|
70
|
+
_this.curResultList$ = new rxjs_1.BehaviorSubject({ results: null, moreResultsAvailable: false });
|
|
71
|
+
_this.searchResultStatus$ = new rxjs_1.BehaviorSubject(null);
|
|
72
|
+
_this.curSmartFilters$ = new rxjs_1.BehaviorSubject([]);
|
|
73
|
+
return _this;
|
|
74
|
+
}
|
|
75
|
+
SearchResultService.prototype.onCreate = function () {
|
|
76
|
+
this.httpsService = this.serviceProvider.getService(https_service_interface_1.HttpsService);
|
|
77
|
+
this.filterService = this.serviceProvider.getService(data_1.FilterServiceImpl);
|
|
78
|
+
this.partService = this.serviceProvider.getService(part_service_1.PartServiceImpl);
|
|
79
|
+
this.tagSearchService = this.serviceProvider.getService(tag_search_service_1.TagSearchServiceImpl);
|
|
80
|
+
this.cvSearchService = this.serviceProvider.getService(cv_search_service_1.CvSearchServiceImpl);
|
|
81
|
+
this.textSearchService = this.serviceProvider.getService(text_search_service_1.TextSearchServiceImpl);
|
|
82
|
+
this.searchFilterService = this.serviceProvider.getService(search_filter_service_1.SearchFilterServiceImpl);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Called when new search-session is started
|
|
86
|
+
*
|
|
87
|
+
* @param searchStatus a new search-status
|
|
88
|
+
*/
|
|
89
|
+
SearchResultService.prototype.reset = function (searchStatus) {
|
|
90
|
+
this.searchStatus = searchStatus;
|
|
91
|
+
this.updateCurResultList([], false);
|
|
92
|
+
this.stopPollingForResults();
|
|
93
|
+
this.searchErrors = [];
|
|
94
|
+
this.prevSearchResultTimestamp = null;
|
|
95
|
+
this.prevProposedTagsUpdatedTimestamp = null;
|
|
96
|
+
this.prevSmartFiltersUpdateTimestamp = null;
|
|
97
|
+
this.searchResultStatus$.next(this.searchStatus.searchResultStatus);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Start poll for results of the current search.
|
|
101
|
+
* Polling will be continued until it is cancelled again.
|
|
102
|
+
*/
|
|
103
|
+
SearchResultService.prototype.startPollingForResults = function () {
|
|
104
|
+
var _this = this;
|
|
105
|
+
if (!this.searchStatus) {
|
|
106
|
+
return; // no search currently active
|
|
107
|
+
}
|
|
108
|
+
// this.searchStatus = new SearchStatus(this.installationLocationService);
|
|
109
|
+
this.searchStatus.searchResultStatus.status = search_result_status_1.SEARCH_RESULT_STATUS.RUNNING;
|
|
110
|
+
this.searchResultStatus$.next(this.searchStatus.searchResultStatus);
|
|
111
|
+
this.stopPollingForResults(); // try to stop polling if it is already running
|
|
112
|
+
this.resultListSkip = 0;
|
|
113
|
+
if (this.loadMoreResultsSubscription) {
|
|
114
|
+
this.loadMoreResultsSubscription.unsubscribe(); // stop to load more results in case they are already requested
|
|
115
|
+
}
|
|
116
|
+
var retryCnt = -1;
|
|
117
|
+
var MAX_RETRY_CNT = Math.round(this.MAX_POLLING_TIMEOUT / this.POLLING_INTERVAL);
|
|
118
|
+
/* polling happens in an interval of POLLING_INTERVAL.
|
|
119
|
+
sometimes the requests take longer, because of bigger load or slow connection,
|
|
120
|
+
in this case we would never get results when we'd use switchMap, that's why we
|
|
121
|
+
use exhaustMap, which does not cancel requests that take longer than POLLING_INTERVAL.
|
|
122
|
+
Since we want to prevent a request from getting stuck or taking too long, we timeout
|
|
123
|
+
them after max MAX_REQUEST_TIMEOUT anyhow.
|
|
124
|
+
We use retryCnt to cancel the polling after a maximal time of MAX_RETRY_CNT. In this
|
|
125
|
+
case, an error is thrown.
|
|
126
|
+
*/
|
|
127
|
+
this.pollingSubscription = (0, rxjs_1.timer)(0, this.POLLING_INTERVAL)
|
|
128
|
+
.pipe((0, operators_1.tap)(function (cnt) {
|
|
129
|
+
retryCnt = cnt;
|
|
130
|
+
if (retryCnt > MAX_RETRY_CNT) {
|
|
131
|
+
throw new error_1.SdkError(error_1.SDK_ERROR_CODES.SEARCH_RESULT_TIMEOUT, null);
|
|
132
|
+
}
|
|
133
|
+
}), (0, operators_1.exhaustMap)(function () {
|
|
134
|
+
return _this.httpsService
|
|
135
|
+
.get("search/".concat(_this.searchStatus.searchSessionID), [
|
|
136
|
+
{
|
|
137
|
+
skip: _this.resultListSkip,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
limit: _this.RESULT_LIST_LIMIT,
|
|
141
|
+
},
|
|
142
|
+
])
|
|
143
|
+
.pipe(
|
|
144
|
+
// extra layer, so that the timer is not stopped when an error appears during the GET
|
|
145
|
+
(0, operators_1.timeout)(_this.MAX_REQUEST_TIMEOUT), // throws TimeoutError
|
|
146
|
+
(0, operators_1.catchError)(function (error) {
|
|
147
|
+
// swallow errors as long as the polling timeout is not exceeded
|
|
148
|
+
console.log('Error during polling: ', error);
|
|
149
|
+
return (0, rxjs_1.of)({});
|
|
150
|
+
}));
|
|
151
|
+
}), (0, operators_1.tap)(function (res) {
|
|
152
|
+
// check if search-results or search-tags were updated and spread the change to listeners, if needed
|
|
153
|
+
if (res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.RUNNING || res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.FINISHED) {
|
|
154
|
+
var asyncTagsJustArrived = _this.searchStatus.searchResultStatus.asyncTagsStatus === search_result_status_1.ASYNC_TAG_STATUS.PENDING &&
|
|
155
|
+
res['asyncTagsStatus'] === search_result_status_1.ASYNC_TAG_STATUS.RECEIVED;
|
|
156
|
+
// Update proposed search tags
|
|
157
|
+
_this.updateProposedTags(res, asyncTagsJustArrived);
|
|
158
|
+
// Update search results
|
|
159
|
+
_this.updateSearchResults(res);
|
|
160
|
+
// Update search inputs (relevant if search-session changed on BE side or if search-session is reloaded at later point)
|
|
161
|
+
_this.updateSearchInput(res);
|
|
162
|
+
// Update smart filters
|
|
163
|
+
_this.updateSmartFilters(res);
|
|
164
|
+
// Update filters
|
|
165
|
+
_this.updateFilters(res);
|
|
166
|
+
// Update Errors
|
|
167
|
+
_this.updateErrors(res);
|
|
168
|
+
// also update the current search-result-status and notify subscribers
|
|
169
|
+
_this.searchStatus.searchResultStatus.status = res['status'];
|
|
170
|
+
_this.searchStatus.searchResultStatus.asyncTagsStatus = res['asyncTagsStatus'];
|
|
171
|
+
_this.searchStatus.searchResultStatus.asyncResultsStatus = res['asyncResultsStatus'];
|
|
172
|
+
_this.searchStatus.searchResultStatus.asyncSmartFiltersStatus = res['asyncSmartFiltersStatus'];
|
|
173
|
+
_this.searchResultStatus$.next(_this.searchStatus.searchResultStatus);
|
|
174
|
+
}
|
|
175
|
+
}), (0, operators_1.filter)(
|
|
176
|
+
// If a search session with no input was created, it will only return the CREATED status.
|
|
177
|
+
// We need to stop the polling if there aren't any inputs.
|
|
178
|
+
function (res) { return res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.FINISHED || res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.CREATED; }), (0, operators_1.take)(1))
|
|
179
|
+
.subscribe(function () {
|
|
180
|
+
// current final result received -> polling stopped
|
|
181
|
+
}, function (err) {
|
|
182
|
+
console.log('Error in polling subscription:', err);
|
|
183
|
+
if (err instanceof error_1.SdkError) {
|
|
184
|
+
_this.curResultList$.next(err);
|
|
185
|
+
}
|
|
186
|
+
_this.searchStatus.searchResultStatus.status = search_result_status_1.SEARCH_RESULT_STATUS.FINISHED;
|
|
187
|
+
_this.searchResultStatus$.next(_this.searchStatus.searchResultStatus);
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Stop polling.
|
|
192
|
+
*/
|
|
193
|
+
SearchResultService.prototype.stopPollingForResults = function () {
|
|
194
|
+
// console.log("try stop polling");
|
|
195
|
+
if (this.pollingSubscription) {
|
|
196
|
+
this.pollingSubscription.unsubscribe();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Get an observable that always emits the current result list (paginated) every
|
|
201
|
+
* time it changes.
|
|
202
|
+
*
|
|
203
|
+
* If an error happens during the search-process in the backend, those errors will also be emitted
|
|
204
|
+
* via this Observable. An error does not necessarily mean, that the whole search failed, search-
|
|
205
|
+
* results might still be emitted. More information can be drawn out of the thrown error.
|
|
206
|
+
*
|
|
207
|
+
* @returns Observable that emits an Object of type CurResultList, every
|
|
208
|
+
* time the results change. CurResults contains the paginated list of
|
|
209
|
+
* results, as well as a boolean, whether more results can be loaded,
|
|
210
|
+
* or the last page was already reached.
|
|
211
|
+
* Emits an SdkError when an error happens during
|
|
212
|
+
* processing of the search result on the backend side.
|
|
213
|
+
|
|
214
|
+
*/
|
|
215
|
+
SearchResultService.prototype.getCurResultList = function () {
|
|
216
|
+
// TODO remove "| SdkError" as soon as polling is removed, then this error should already be thrown when .performCV() is executed asynchronously
|
|
217
|
+
return this.curResultList$.asObservable();
|
|
218
|
+
};
|
|
219
|
+
SearchResultService.prototype.getSearchResultStatus = function () {
|
|
220
|
+
return this.searchResultStatus$.asObservable();
|
|
221
|
+
};
|
|
222
|
+
SearchResultService.prototype.getCurResultListLength = function () {
|
|
223
|
+
return this.searchStatus.curResultList.length;
|
|
224
|
+
};
|
|
225
|
+
SearchResultService.prototype.getCurResultListValue = function () {
|
|
226
|
+
return this.searchStatus.curResultList;
|
|
227
|
+
};
|
|
228
|
+
SearchResultService.prototype.getSmartFilters = function () {
|
|
229
|
+
return this.curSmartFilters$.asObservable();
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Check the response to identify if the proposed search-tags have
|
|
233
|
+
* changed, to emit new ones if necessary
|
|
234
|
+
*
|
|
235
|
+
* @param response the response of a polling request
|
|
236
|
+
* @param newTagsAreAsyncTags true if the newly received tags are async
|
|
237
|
+
*/
|
|
238
|
+
SearchResultService.prototype.updateProposedTags = function (response, newTagsAreAsyncTags) {
|
|
239
|
+
if (newTagsAreAsyncTags === void 0) { newTagsAreAsyncTags = false; }
|
|
240
|
+
if (response['timestamps'] &&
|
|
241
|
+
response['timestamps']['proposedTagsUpdate'] &&
|
|
242
|
+
(!this.prevProposedTagsUpdatedTimestamp ||
|
|
243
|
+
this.prevProposedTagsUpdatedTimestamp < new Date(response['timestamps']['proposedTagsUpdate']))) {
|
|
244
|
+
// new proposed tags available
|
|
245
|
+
if (response['proposedTags']) {
|
|
246
|
+
var tags_1 = this.searchStatus.tagSearchStatus.proposedSearchTags || [];
|
|
247
|
+
var newTagsData = (response['proposedTags'] || []).slice(0); // clone array
|
|
248
|
+
var _loop_1 = function (i) {
|
|
249
|
+
var idx = newTagsData.findIndex(function (newTagData) { return newTagData.value === tags_1[i].value; });
|
|
250
|
+
if (idx >= 0) {
|
|
251
|
+
// tag still available -> update tag
|
|
252
|
+
Object.assign(tags_1[i], newTagsData[idx]);
|
|
253
|
+
newTagsData.splice(idx, 1);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// tag not available anymore -> delete
|
|
257
|
+
tags_1.splice(i, 1);
|
|
258
|
+
i--;
|
|
259
|
+
}
|
|
260
|
+
out_i_1 = i;
|
|
261
|
+
};
|
|
262
|
+
var out_i_1;
|
|
263
|
+
for (var i = 0; i < tags_1.length; i++) {
|
|
264
|
+
_loop_1(i);
|
|
265
|
+
i = out_i_1;
|
|
266
|
+
}
|
|
267
|
+
// add all new tags
|
|
268
|
+
for (var _i = 0, newTagsData_1 = newTagsData; _i < newTagsData_1.length; _i++) {
|
|
269
|
+
var newTagData = newTagsData_1[_i];
|
|
270
|
+
tags_1.push(new search_tag_1.SearchTag(Object.assign(newTagData, { isAsync: newTagsAreAsyncTags })));
|
|
271
|
+
}
|
|
272
|
+
var _loop_2 = function (i) {
|
|
273
|
+
var idx = tags_1.findIndex(function (tag) { return tag.value === response['proposedTags'][i].value; });
|
|
274
|
+
// remove item
|
|
275
|
+
var tag = tags_1.splice(idx, 1)[0];
|
|
276
|
+
// insert item
|
|
277
|
+
tags_1.splice(i, 0, tag);
|
|
278
|
+
};
|
|
279
|
+
// reorder tags (order determined by new tags-order) (we don't order by score, because the async tags should always be in the front, but might have lower score)
|
|
280
|
+
for (var i = 0; i < tags_1.length; i++) {
|
|
281
|
+
_loop_2(i);
|
|
282
|
+
}
|
|
283
|
+
this.tagSearchService.updateProposedTags(tags_1);
|
|
284
|
+
this.prevProposedTagsUpdatedTimestamp = new Date(response['timestamps']['proposedTagsUpdate']);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Check the response to identify if it contains new search-results
|
|
290
|
+
* that have not been emitted before.
|
|
291
|
+
*
|
|
292
|
+
* @param response the response of a polling request
|
|
293
|
+
*/
|
|
294
|
+
SearchResultService.prototype.updateSearchResults = function (response) {
|
|
295
|
+
if (response['timestamps'] &&
|
|
296
|
+
response['timestamps']['resultsUpdate'] &&
|
|
297
|
+
(!this.prevSearchResultTimestamp ||
|
|
298
|
+
this.prevSearchResultTimestamp < new Date(response['timestamps']['resultsUpdate']))) {
|
|
299
|
+
// new results available
|
|
300
|
+
if (response['results'] && response['results'].entities) {
|
|
301
|
+
var searchResult = [];
|
|
302
|
+
// process results
|
|
303
|
+
searchResult = this.processSearchResults(response['results'].entities);
|
|
304
|
+
searchResult = _.orderBy(searchResult, ['confidence'], ['desc']);
|
|
305
|
+
this.updateCurResultList(searchResult.map(function (item) { return item.part; }), !response['lastResultsPage']);
|
|
306
|
+
}
|
|
307
|
+
this.prevSearchResultTimestamp = new Date(response['timestamps']['resultsUpdate']);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Update the current search-input status to the values provided from the BE
|
|
312
|
+
* search-session. This can be used to load an older search-session and even
|
|
313
|
+
* allows to continue it.
|
|
314
|
+
*
|
|
315
|
+
* TODO This function is currently only used to load the search-results of an
|
|
316
|
+
* older search-session. Loading of the search-inputs is not fully working yet
|
|
317
|
+
* and should therefore not yet be used.
|
|
318
|
+
*
|
|
319
|
+
* @param response response of the GET search-session request to find
|
|
320
|
+
*
|
|
321
|
+
* @beta
|
|
322
|
+
*/
|
|
323
|
+
SearchResultService.prototype.updateSearchInput = function (response) {
|
|
324
|
+
var _a;
|
|
325
|
+
if (response['searchInputs']) {
|
|
326
|
+
// update search image
|
|
327
|
+
if (response['searchInputs']['image']) {
|
|
328
|
+
if (response['searchInputs']['image'] !== ((_a = this.searchStatus.cvSearchStatus.cvImage) === null || _a === void 0 ? void 0 : _a.referenceId)) {
|
|
329
|
+
this.cvSearchService.setStatusExternal(this.searchStatus, response['searchInputs']['image'], response['searchInputs']['cropArea']);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// update text-search query
|
|
333
|
+
if (response['searchInputs']['text']) {
|
|
334
|
+
if (response['searchInputs']['text'] !== this.searchStatus.textSearchStatus.searchQuery) {
|
|
335
|
+
this.textSearchService.setStatusExternal(this.searchStatus, response['searchInputs']['text']); // TODO misses to also set the searchConfig of the text-search, but this configuration is currently not provided from the backend
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (response['searchInputs']['textSearch'] &&
|
|
339
|
+
!_.isEqual(response['searchInputs']['textSearch'], this.searchStatus.textSearchStatus.searchQueries)) {
|
|
340
|
+
this.textSearchService.setStatusExternal(this.searchStatus, null, null, response['searchInputs']['textSearch']);
|
|
341
|
+
// TODO misses to also set the searchConfig of the text-search, but this configuration is currently not provided from the backend
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Check the response to identify if the smart filters have
|
|
347
|
+
* changed, to emit new ones if necessary
|
|
348
|
+
*
|
|
349
|
+
* @param response the response of a polling request
|
|
350
|
+
*/
|
|
351
|
+
SearchResultService.prototype.updateSmartFilters = function (response) {
|
|
352
|
+
if (response['timestamps'] &&
|
|
353
|
+
response['timestamps']['smartFiltersUpdate'] &&
|
|
354
|
+
(!this.prevSmartFiltersUpdateTimestamp ||
|
|
355
|
+
this.prevSmartFiltersUpdateTimestamp < new Date(response['timestamps']['smartFiltersUpdate']))) {
|
|
356
|
+
// new smart filters available
|
|
357
|
+
if (response['smartFilters']) {
|
|
358
|
+
var smartFilters = response['smartFilters'].map(function (rawFilter) {
|
|
359
|
+
return smart_filter_1.SmartFilter.fromAPIResponse(rawFilter);
|
|
360
|
+
});
|
|
361
|
+
this.curSmartFilters$.next(smartFilters);
|
|
362
|
+
this.prevSmartFiltersUpdateTimestamp = new Date(response['timestamps']['smartFiltersUpdate']);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
SearchResultService.prototype.updateFilters = function (response) {
|
|
367
|
+
var hasFilters = response['searchInputs'] &&
|
|
368
|
+
response['searchInputs']['filters'] &&
|
|
369
|
+
Object.keys(response['searchInputs']['filters']).length > 0;
|
|
370
|
+
var hardFilters = hasFilters && response['searchInputs']['filters']['hardFilters']
|
|
371
|
+
? response['searchInputs']['filters']['hardFilters']
|
|
372
|
+
: [];
|
|
373
|
+
var isFiltersChanged = this.checkIfFiltersChanged(hardFilters);
|
|
374
|
+
if (hasFilters && isFiltersChanged) {
|
|
375
|
+
this.setMappedFilters(response);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
this.searchFilterService.searchFiltersLoaded$.next(true);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
SearchResultService.prototype.checkIfFiltersChanged = function (hardFilters) {
|
|
382
|
+
var isFiltersChanged = false;
|
|
383
|
+
var responseHardFiltersLabels = hardFilters.map(function (filter) { return filter.label; }).sort();
|
|
384
|
+
var sdkHardFilters = [];
|
|
385
|
+
Object.values(this.searchStatus.filterStatus.filtersMap).forEach(function (filter) {
|
|
386
|
+
if (filter.key !== 'hierarchy-partium-id') {
|
|
387
|
+
var hardFilter = filter;
|
|
388
|
+
sdkHardFilters.push(hardFilter.label);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
sdkHardFilters.sort();
|
|
392
|
+
if (sdkHardFilters.length === 0) {
|
|
393
|
+
isFiltersChanged = true;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
for (var i = 0; i < sdkHardFilters.length; i++) {
|
|
397
|
+
if (responseHardFiltersLabels.includes(sdkHardFilters[i]) === false) {
|
|
398
|
+
isFiltersChanged = true;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return isFiltersChanged;
|
|
404
|
+
};
|
|
405
|
+
SearchResultService.prototype.setMappedFilters = function (res) {
|
|
406
|
+
var _this = this;
|
|
407
|
+
var _a = res['searchInputs']['filters'], hardFilters = _a.hardFilters, hierarchy = _a.hierarchy;
|
|
408
|
+
var appliedFiltersSize = 1;
|
|
409
|
+
if (hardFilters) {
|
|
410
|
+
appliedFiltersSize = Object.keys(res['searchInputs']['filters']['hardFilters']).length;
|
|
411
|
+
}
|
|
412
|
+
var mappedFilters$;
|
|
413
|
+
mappedFilters$ = this.filterService.searchMultipleFilterKeys(res['searchInputs']['filters'], res['language'] || this.searchStatus.searchLanguage, 500);
|
|
414
|
+
mappedFilters$
|
|
415
|
+
.pipe((0, operators_1.last)(), (0, operators_1.mergeMap)(function (filterKeys) {
|
|
416
|
+
_this.filterKeys = filterKeys;
|
|
417
|
+
var mappedFilters = _this.mapSelectedFilters(filterKeys, hardFilters, hierarchy);
|
|
418
|
+
return (0, rxjs_1.of)(mappedFilters);
|
|
419
|
+
}), (0, operators_1.take)(Math.max(appliedFiltersSize, 1)))
|
|
420
|
+
.subscribe(function (mappedFilters) {
|
|
421
|
+
if (mappedFilters) {
|
|
422
|
+
_this.searchFilterService.setStatusExternal(_this.searchStatus, mappedFilters);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
SearchResultService.prototype.mapSelectedFilters = function (filterKeys, hardFilters, hierarchy) {
|
|
427
|
+
var selectedHardFilters = [];
|
|
428
|
+
if (filterKeys && filterKeys.length > 0) {
|
|
429
|
+
filterKeys.forEach(function (filterKey) {
|
|
430
|
+
if (filterKey) {
|
|
431
|
+
var hardFilter = hardFilters.find(function (hardFilter) { return hardFilter.label === filterKey.name; });
|
|
432
|
+
selectedHardFilters.push(new search_filter_1.KvpHardFilter(filterKey.partiumId, filterKey.name, hardFilter.values));
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
var mappedFilters = this.searchFilterService.mapFiltersToUploadFilterFormat(selectedHardFilters, hierarchy);
|
|
437
|
+
return mappedFilters;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Check the response to identify new errors that have not been emitted before.
|
|
441
|
+
*
|
|
442
|
+
* @param response the response of a polling request
|
|
443
|
+
*/
|
|
444
|
+
SearchResultService.prototype.updateErrors = function (response) {
|
|
445
|
+
if (response['errors'] && response['errors'].length > 0) {
|
|
446
|
+
var _loop_3 = function (newErr) {
|
|
447
|
+
if (!this_1.searchErrors.find(function (err) { return err.code === newErr['code'] && err.detail && err.detail['timestamp'] === newErr['timestamp']; })) {
|
|
448
|
+
// is new error -> emit // TODO test with real backend
|
|
449
|
+
var error = new error_1.SdkError(newErr['code'], newErr, newErr['message']);
|
|
450
|
+
if (error.code === error_1.SDK_ERROR_CODES.IMAGE_SEARCH_ERROR) {
|
|
451
|
+
this_1.searchStatus.cvSearchStatus.setImage(null); // remove the corrupted image from the search status, to allow the user to upload a new one
|
|
452
|
+
}
|
|
453
|
+
this_1.curResultList$.next(error);
|
|
454
|
+
this_1.searchErrors.push(error);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
var this_1 = this;
|
|
458
|
+
// check for new errors (new if timestamp+code unknown)
|
|
459
|
+
for (var _i = 0, _a = response['errors']; _i < _a.length; _i++) {
|
|
460
|
+
var newErr = _a[_i];
|
|
461
|
+
_loop_3(newErr);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
SearchResultService.prototype.updateCurResultList = function (newList, moreResultsAvailable) {
|
|
466
|
+
if (moreResultsAvailable === void 0) { moreResultsAvailable = true; }
|
|
467
|
+
if (this.searchStatus) {
|
|
468
|
+
this.searchStatus.curResultList = newList;
|
|
469
|
+
this.curResultList$.next({
|
|
470
|
+
results: this.searchStatus.curResultList,
|
|
471
|
+
moreResultsAvailable: moreResultsAvailable,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
this.curResultList$.next(null);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* Process raw search results to format as a list of parts with confidences
|
|
480
|
+
*
|
|
481
|
+
* @param results The raw response of a search result request
|
|
482
|
+
* @returns The processed part with confidences list
|
|
483
|
+
*/
|
|
484
|
+
SearchResultService.prototype.processSearchResults = function (results) {
|
|
485
|
+
return (results
|
|
486
|
+
// filter all items with confidence of 0 (= apply hard filter)
|
|
487
|
+
.filter(function (item) { return item.confidence > 0; })
|
|
488
|
+
.map(function (item) { return ({
|
|
489
|
+
part: new part_1.Part({
|
|
490
|
+
name: new i18n_string_1.i18nString(item.name),
|
|
491
|
+
// description: new i18nString(item.part.description),
|
|
492
|
+
// images: item.part.images,
|
|
493
|
+
partiumId: item.partiumId,
|
|
494
|
+
externalId: item.externalId,
|
|
495
|
+
externalPayload: item.externalPayload,
|
|
496
|
+
dataOrigin: part_1.DATA_ORIGIN.PARTIAL,
|
|
497
|
+
}),
|
|
498
|
+
confidence: item.confidence,
|
|
499
|
+
}); }));
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Load more results of the current result list, based on RESULT_LIST_LIMIT and resultListSkip values
|
|
503
|
+
* The newly loaded results will emit via the getCurResultList-Observable,
|
|
504
|
+
* along with the already known results.
|
|
505
|
+
*/
|
|
506
|
+
SearchResultService.prototype.loadMoreResults = function () {
|
|
507
|
+
var _this = this;
|
|
508
|
+
console.log('Loading more results...', this.searchStatus.searchSessionID);
|
|
509
|
+
this.resultListSkip += this.RESULT_LIST_LIMIT;
|
|
510
|
+
this.loadMoreResultsSubscription = this.httpsService
|
|
511
|
+
.get("search/".concat(this.searchStatus.searchSessionID), [
|
|
512
|
+
{
|
|
513
|
+
skip: this.resultListSkip,
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
limit: this.RESULT_LIST_LIMIT,
|
|
517
|
+
},
|
|
518
|
+
])
|
|
519
|
+
.pipe((0, operators_1.map)(function (res) {
|
|
520
|
+
if (res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.RUNNING || res['status'] === search_result_status_1.SEARCH_RESULT_STATUS.FINISHED) {
|
|
521
|
+
// Only update the result list when the timestamps is equal to the prevSearchResultTimestamp
|
|
522
|
+
if (res['timestamps'] &&
|
|
523
|
+
res['timestamps']['resultsUpdate'] &&
|
|
524
|
+
_this.prevSearchResultTimestamp <= new Date(res['timestamps']['resultsUpdate'])) {
|
|
525
|
+
var newResults = _this.processSearchResults(res['results'].entities).map(function (item) { return item.part; });
|
|
526
|
+
if (_this.searchStatus.curResultList instanceof Array) {
|
|
527
|
+
_this.updateCurResultList(__spreadArray(__spreadArray([], _this.searchStatus.curResultList, true), newResults, true), !res['lastResultsPage']);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}), (0, operators_1.catchError)(function (error) { return (0, rxjs_1.of)({ moreResultsAvailable: true, error: error, newResults: [] }); }))
|
|
532
|
+
.subscribe();
|
|
533
|
+
};
|
|
534
|
+
SearchResultService = __decorate([
|
|
535
|
+
(0, injection_identifier_1.InjectionIdentifier)('SearchResultService')
|
|
536
|
+
], SearchResultService);
|
|
537
|
+
return SearchResultService;
|
|
538
|
+
}(base_service_1.BaseService));
|
|
539
|
+
exports.SearchResultService = SearchResultService;
|
|
540
|
+
//# sourceMappingURL=search-result.service.js.map
|