@knora/search
Version:
Knora ui module: search
656 lines (628 loc) • 122 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/overlay'), require('@angular/cdk/portal'), require('@angular/core'), require('@angular/material'), require('@angular/router'), require('@knora/api'), require('@knora/core'), require('@angular/forms'), require('@angular/material/core'), require('@angular/material/datepicker'), require('jdnconvertiblecalendardateadapter'), require('@angular/material/input'), require('@angular/platform-browser/animations'), require('@angular/material/autocomplete'), require('@angular/material/button'), require('@angular/material/checkbox'), require('@angular/material/expansion'), require('@angular/material/form-field'), require('@angular/material/icon'), require('@angular/common'), require('@angular/material/list'), require('@angular/material/menu'), require('@angular/material/select'), require('@angular/material/tooltip'), require('@knora/action'), require('@knora/viewer')) :
typeof define === 'function' && define.amd ? define('@knora/search', ['exports', '@angular/cdk/overlay', '@angular/cdk/portal', '@angular/core', '@angular/material', '@angular/router', '@knora/api', '@knora/core', '@angular/forms', '@angular/material/core', '@angular/material/datepicker', 'jdnconvertiblecalendardateadapter', '@angular/material/input', '@angular/platform-browser/animations', '@angular/material/autocomplete', '@angular/material/button', '@angular/material/checkbox', '@angular/material/expansion', '@angular/material/form-field', '@angular/material/icon', '@angular/common', '@angular/material/list', '@angular/material/menu', '@angular/material/select', '@angular/material/tooltip', '@knora/action', '@knora/viewer'], factory) :
(global = global || self, factory((global.knora = global.knora || {}, global.knora.search = {}), global.ng.cdk.overlay, global.ng.cdk.portal, global.ng.core, global.ng.material, global.ng.router, global.api, global['@knora/core'], global.ng.forms, global.ng.material.core, global.ng.material.datepicker, global.jdnconvertiblecalendardateadapter, global.ng.material.input, global.ng.platformBrowser.animations, global.ng.material.autocomplete, global.ng.material.button, global.ng.material.checkbox, global.ng.material.expansion, global.ng.material['form-field'], global.ng.material.icon, global.ng.common, global.ng.material.list, global.ng.material.menu, global.ng.material.select, global.ng.material.tooltip, global['@knora/action'], global['@knora/viewer']));
}(this, (function (exports, overlay, portal, core, material, router, api, core$1, forms, core$2, datepicker, jdnconvertiblecalendardateadapter, input, animations, autocomplete, button, checkbox, expansion, formField, icon, common, list, menu, select, tooltip, action, viewer) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
*
*/
var FulltextSearchComponent = /** @class */ (function () {
function FulltextSearchComponent(knoraApiConnection, _overlay, _router, _viewContainerRef) {
this.knoraApiConnection = knoraApiConnection;
this._overlay = _overlay;
this._router = _router;
this._viewContainerRef = _viewContainerRef;
/**
*
* @param {string} route Route to navigate after search.
* This route path should contain a component for search results.
*/
this.route = '/search';
/**
*
* @param {boolean} [projectfilter] If true it shows the selection
* of projects to filter by one of them
*/
this.projectfilter = false;
this.showState = new core.EventEmitter();
// previous search = full-text search history
this.prevSearch = JSON.parse(localStorage.getItem('prevSearch'));
this.defaultProjectLabel = 'All projects';
this.projectLabel = this.defaultProjectLabel;
// is search panel focused?
this.searchPanelFocus = false;
// do not show the following projects: default system projects from knora
this.doNotDisplay = [
api.Constants.SystemProjectIRI,
api.Constants.DefaultSharedOntologyIRI
];
}
FulltextSearchComponent.prototype.ngOnInit = function () {
// this.setFocus();
if (this.filterbyproject) {
this.getProject(this.filterbyproject);
}
if (this.projectfilter) {
this.getAllProjects();
if (localStorage.getItem('currentProject') !== null) {
this.setProject(JSON.parse(localStorage.getItem('currentProject')));
}
}
};
FulltextSearchComponent.prototype.openPanelWithBackdrop = function () {
var _this = this;
var config = new overlay.OverlayConfig({
hasBackdrop: true,
backdropClass: 'cdk-overlay-transparent-backdrop',
// backdropClass: 'cdk-overlay-dark-backdrop',
positionStrategy: this.getOverlayPosition(),
scrollStrategy: this._overlay.scrollStrategies.block()
});
this.overlayRef = this._overlay.create(config);
this.overlayRef.attach(new portal.TemplatePortal(this.searchMenu, this._viewContainerRef));
this.overlayRef.backdropClick().subscribe(function () {
_this.searchPanelFocus = false;
_this.overlayRef.detach();
});
};
FulltextSearchComponent.prototype.getOverlayPosition = function () {
var positions = [
new overlay.ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }),
new overlay.ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' })
];
var overlayPosition = this._overlay.position().flexibleConnectedTo(this.searchPanel).withPositions(positions).withLockedPosition(false);
return overlayPosition;
};
FulltextSearchComponent.prototype.getAllProjects = function () {
var _this = this;
this.knoraApiConnection.admin.projectsEndpoint.getProjects().subscribe(function (response) {
_this.projects = response.body.projects;
// this.loadSystem = false;
if (localStorage.getItem('currentProject') !== null) {
_this.project = JSON.parse(localStorage.getItem('currentProject'));
}
}, function (error) {
console.error(error);
_this.error = error;
});
};
FulltextSearchComponent.prototype.getProject = function (id) {
var _this = this;
this.knoraApiConnection.admin.projectsEndpoint.getProjectByIri(id).subscribe(function (project) {
_this.setProject(project.body.project);
}, function (error) {
console.error(error);
});
};
// set current project and switch focus to input field
FulltextSearchComponent.prototype.setProject = function (project) {
if (!project) {
// set default project: all
this.projectLabel = this.defaultProjectLabel;
this.projectIri = undefined;
localStorage.removeItem('currentProject');
}
else {
// set current project shortname and id
this.projectLabel = project.shortname;
this.projectIri = project.id;
localStorage.setItem('currentProject', JSON.stringify(project));
}
};
FulltextSearchComponent.prototype.doSearch = function () {
var e_1, _a;
if (this.searchQuery !== undefined && this.searchQuery !== null) {
if (this.projectIri !== undefined) {
this._router.navigate([
this.route +
'/fulltext/' +
this.searchQuery +
'/' +
encodeURIComponent(this.projectIri)
]);
}
else {
this._router.navigate([
this.route + '/fulltext/' + this.searchQuery
]);
}
// push the search query into the local storage prevSearch array (previous search)
// to have a list of recent search requests
var existingPrevSearch = JSON.parse(localStorage.getItem('prevSearch'));
if (existingPrevSearch === null) {
existingPrevSearch = [];
}
var i = 0;
try {
for (var existingPrevSearch_1 = __values(existingPrevSearch), existingPrevSearch_1_1 = existingPrevSearch_1.next(); !existingPrevSearch_1_1.done; existingPrevSearch_1_1 = existingPrevSearch_1.next()) {
var entry = existingPrevSearch_1_1.value;
// remove entry, if exists already
if (this.searchQuery === entry.query && this.projectIri === entry.projectIri) {
existingPrevSearch.splice(i, 1);
}
i++;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (existingPrevSearch_1_1 && !existingPrevSearch_1_1.done && (_a = existingPrevSearch_1.return)) _a.call(existingPrevSearch_1);
}
finally { if (e_1) throw e_1.error; }
}
// A search value is expected to have at least length of 3
if (this.searchQuery.length > 2) {
var currentQuery = {
query: this.searchQuery
};
if (this.projectIri) {
currentQuery = {
projectIri: this.projectIri,
projectLabel: this.projectLabel,
query: this.searchQuery
};
}
existingPrevSearch.push(currentQuery);
localStorage.setItem('prevSearch', JSON.stringify(existingPrevSearch));
}
}
this.resetSearch();
this.overlayRef.detach();
this.show = false;
this.showState.emit(this.show);
};
FulltextSearchComponent.prototype.resetSearch = function () {
this.searchPanelFocus = false;
this.searchInput.nativeElement.blur();
this.overlayRef.detach();
};
FulltextSearchComponent.prototype.setFocus = function () {
this.prevSearch = JSON.parse(localStorage.getItem('prevSearch'));
this.searchPanelFocus = true;
this.openPanelWithBackdrop();
};
FulltextSearchComponent.prototype.doPrevSearch = function (prevSearch) {
this.searchQuery = prevSearch.query;
if (prevSearch.projectIri !== undefined) {
this.projectIri = prevSearch.projectIri;
this.projectLabel = prevSearch.projectLabel;
this._router.navigate([this.route + '/fulltext/' + this.searchQuery + '/' + encodeURIComponent(prevSearch.projectIri)]);
}
else {
this.projectIri = undefined;
this.projectLabel = this.defaultProjectLabel;
this._router.navigate([this.route + '/fulltext/' + this.searchQuery]);
}
this.resetSearch();
this.overlayRef.detach();
};
FulltextSearchComponent.prototype.resetPrevSearch = function (prevSearch) {
if (prevSearch) {
// delete only this item with the name ...
var i = this.prevSearch.indexOf(prevSearch);
this.prevSearch.splice(i, 1);
localStorage.setItem('prevSearch', JSON.stringify(this.prevSearch));
}
else {
// delete the whole "previous search" array
localStorage.removeItem('prevSearch');
}
this.prevSearch = JSON.parse(localStorage.getItem('prevSearch'));
};
FulltextSearchComponent.prototype.changeFocus = function () {
this.selectProject.closeMenu();
this.searchInput.nativeElement.focus();
this.setFocus();
};
FulltextSearchComponent.ctorParameters = function () { return [
{ type: api.KnoraApiConnection, decorators: [{ type: core.Inject, args: [core$1.KnoraApiConnectionToken,] }] },
{ type: overlay.Overlay },
{ type: router.Router },
{ type: core.ViewContainerRef }
]; };
__decorate([
core.Input(),
__metadata("design:type", String)
], FulltextSearchComponent.prototype, "route", void 0);
__decorate([
core.Input(),
__metadata("design:type", Boolean)
], FulltextSearchComponent.prototype, "projectfilter", void 0);
__decorate([
core.Input(),
__metadata("design:type", String)
], FulltextSearchComponent.prototype, "filterbyproject", void 0);
__decorate([
core.Input(),
__metadata("design:type", Boolean)
], FulltextSearchComponent.prototype, "show", void 0);
__decorate([
core.Output(),
__metadata("design:type", Object)
], FulltextSearchComponent.prototype, "showState", void 0);
__decorate([
core.ViewChild('fulltextSearchPanel', { static: false }),
__metadata("design:type", core.ElementRef)
], FulltextSearchComponent.prototype, "searchPanel", void 0);
__decorate([
core.ViewChild('fulltextSearchInput', { static: false }),
__metadata("design:type", core.ElementRef)
], FulltextSearchComponent.prototype, "searchInput", void 0);
__decorate([
core.ViewChild('fulltextSearchMenu', { static: false }),
__metadata("design:type", core.TemplateRef)
], FulltextSearchComponent.prototype, "searchMenu", void 0);
__decorate([
core.ViewChild('btnToSelectProject', { static: false }),
__metadata("design:type", material.MatMenuTrigger)
], FulltextSearchComponent.prototype, "selectProject", void 0);
FulltextSearchComponent = __decorate([
core.Component({
selector: 'kui-fulltext-search',
template: "<!-- full-text search panel -->\n<div class=\"kui-fulltext-search-panel\" [class.active]=\"searchPanelFocus\" [class.with-project-filter]=\"projectfilter\"\n #fulltextSearchPanel cdkOverlayOrigin>\n\n <!-- DESKTOP / TABLET VERSION -->\n <div class=\"kui-project-filter\" *ngIf=\"projectfilter\">\n <button mat-button class=\"kui-project-filter-button\" [matMenuTriggerFor]=\"selectProject\"\n #btnToSelectProject=\"matMenuTrigger\" isIconButton>\n <p class=\"mat-caption placeholder\">Filter by project</p>\n <p class=\"label\">{{projectLabel}}</p>\n <mat-icon class=\"icon\" matSuffix>keyboard_arrow_down</mat-icon>\n </button>\n <mat-menu #selectProject=\"matMenu\">\n <div class=\"kui-project-filter-menu\">\n <button mat-menu-item class=\"center\"\n (click)=\"setProject();changeFocus()\">{{defaultProjectLabel}}</button>\n <mat-divider></mat-divider>\n <span *ngFor=\"let project of projects | kuiSortBy: 'shortname'\">\n <button mat-menu-item *ngIf=\"!doNotDisplay.includes(project.id)\"\n (click)=\"setProject(project);changeFocus()\" [matTooltip]=\"project.longname\"\n [matTooltipPosition]=\"'after'\">{{project.shortname}}</button>\n </span>\n </div>\n </mat-menu>\n </div>\n\n <div class=\"kui-fulltext-search\" [class.with-project-filter]=\"projectfilter\">\n <div class=\"kui-fulltext-search-field\">\n <input #fulltextSearchInput class=\"kui-fulltext-search-input\" type=\"search\" [(ngModel)]=\"searchQuery\"\n name=\"search\" minlength=\"3\" autocomplete=\"off\" [placeholder]=\"'Search'\" (keyup.esc)=\"resetSearch()\"\n (keyup.enter)=\"doSearch()\" (click)=\"setFocus()\">\n </div>\n <button class=\"kui-fulltext-search-button suffix\" (click)=\"doSearch()\" type=\"submit\">\n <mat-icon>search</mat-icon>\n </button>\n </div>\n\n <!-- PHONE VERSION *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** -->\n <div class=\"kui-project-filter-mobile\" *ngIf=\"projectfilter\">\n <button mat-stroked-button class=\"kui-project-filter-button kui-project-filter-button-mobile\"\n [matMenuTriggerFor]=\"selectProject\" #btnToSelectProject=\"matMenuTrigger\" isIconButton>\n <p class=\"mat-caption placeholder\">Filter by project</p>\n <p class=\"label\">{{projectLabel}}</p>\n <mat-icon class=\"icon\" matSuffix>keyboard_arrow_down</mat-icon>\n </button>\n <mat-menu #selectProject=\"matMenu\">\n <div class=\"kui-project-filter-menu-mobile\">\n <button mat-menu-item class=\"center\"\n (click)=\"setProject();changeFocus()\">{{defaultProjectLabel}}</button>\n <mat-divider></mat-divider>\n <span *ngFor=\"let project of projects | kuiSortBy: 'shortname'\">\n <button mat-menu-item *ngIf=\"!doNotDisplay.includes(project.id)\"\n (click)=\"setProject(project);changeFocus()\" [matTooltip]=\"project.longname\"\n [matTooltipPosition]=\"'after'\">{{project.shortname}}</button>\n </span>\n </div>\n </mat-menu>\n <!-- <mat-form-field class=\"kui-project-filter-select-mobile\">\n <mat-select [(ngModel)]=\"All projects\">\n <mat-option *ngFor=\"let project of projects | kuiSortBy: 'shortname'\" [value]=\"project.shortname\">\n {{project.shortname}}\n </mat-option>\n </mat-select>\n </mat-form-field> -->\n </div>\n\n <div class=\"kui-fulltext-search-mobile\" [class.with-project-filter]=\"projectfilter\">\n <div class=\"kui-fulltext-search-field-mobile\">\n <input #fulltextSearchInput class=\"kui-fulltext-search-input-mobile\" type=\"search\" [(ngModel)]=\"searchQuery\"\n name=\"search\" minlength=\"3\" autocomplete=\"off\" [placeholder]=\"'Search'\" (keyup.esc)=\"resetSearch()\"\n (keyup.enter)=\"doSearch()\" (click)=\"setFocus()\">\n </div>\n <button mat-stroked-button class=\"kui-fulltext-search-button-mobile suffix-mobile\" (click)=\"doSearch()\"\n type=\"submit\">\n Search\n </button>\n </div>\n <!-- *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** -->\n\n</div>\n\n<!-- full-text search menu - only for desktop/tablet versions -->\n<ng-template #fulltextSearchMenu>\n\n <div class=\"kui-search-menu\" [class.with-project-filter]=\"projectfilter\">\n <div class=\"kui-menu-content\">\n <mat-list class=\"kui-previous-search-list\">\n <div *ngFor=\"let item of prevSearch | kuiReverse; let i=index\">\n <mat-list-item *ngIf=\"i<10\">\n <h4 mat-line (click)=\"doPrevSearch(item)\" class=\"kui-previous-search-item\">\n <div class=\"kui-project-filter-label\" [class.not-empty]=\"item.projectIri\"\n *ngIf=\"projectfilter && !error && projects?.length > 0\">\n <span *ngIf=\"item.projectIri\">{{item.projectLabel}}</span>\n </div>\n <div class=\"kui-previous-search-query\" [class.fix-width]=\"projectfilter\">\n {{item.query}}\n </div>\n </h4>\n <button mat-icon-button (click)=\"resetPrevSearch(item)\">\n <mat-icon class=\"mat-list-close-icon\" aria-label=\"close\">close</mat-icon>\n </button>\n </mat-list-item>\n </div>\n </mat-list>\n </div>\n\n <div class=\"kui-menu-action\" *ngIf=\"prevSearch\">\n <mat-divider></mat-divider>\n <button mat-button color=\"primary\" class=\"center\" (click)=\"resetPrevSearch()\">Clear list\n </button>\n </div>\n </div>\n\n</ng-template>\n",
styles: ["input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration,input[type=search]::-webkit-search-results-button,input[type=search]::-webkit-search-results-decoration{display:none}input[type=search]{-moz-appearance:none;-webkit-appearance:none}.center{text-align:center}.kui-fulltext-search-panel{border-radius:4px;display:-webkit-box;display:flex;height:40px;position:relative;width:480px;z-index:100;background-color:#f9f9f9}.kui-fulltext-search-panel.active{box-shadow:0 1px 3px rgba(0,0,0,.5)}.kui-fulltext-search-panel.with-project-filter{width:calc(480px + 160px)}.kui-fulltext-search-panel .kui-project-filter-button{font-size:inherit;overflow:hidden;text-overflow:ellipsis;width:160px;margin:1px;border-radius:4px 0 0 4px}.kui-fulltext-search-panel .kui-fulltext-search{background-color:#f9f9f9;border-radius:4px;display:-webkit-inline-box;display:inline-flex;position:relative;z-index:10}.kui-fulltext-search-panel .kui-fulltext-search.with-project-filter{width:calc(480px + 160px);border-top-left-radius:0;border-bottom-left-radius:0}.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-field{-webkit-box-flex:1;flex:1;width:calc(480px - 40px);margin:1px}.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-field .kui-fulltext-search-input{border-style:none;font-size:14pt;height:38px;position:absolute;padding-left:12px;width:calc(100% - 40px)}.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-field .kui-fulltext-search-input.with-project-filter{width:calc(100% - 40px - 160px)}.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-field .kui-fulltext-search-input:active,.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-field .kui-fulltext-search-input:focus{outline:0}.kui-fulltext-search-panel .kui-fulltext-search .kui-fulltext-search-button{background-color:#fff}.kui-fulltext-search-panel .kui-fulltext-search .suffix{margin:1px 0 1px -3px;border-radius:0 4px 4px 0}.kui-fulltext-search-panel .kui-fulltext-search .prefix{margin:1px 0 1px 3px;border-radius:4px 0 0 4px}.kui-fulltext-search-panel .kui-fulltext-search .prefix,.kui-fulltext-search-panel .kui-fulltext-search .suffix{border-style:none;color:rgba(41,41,41,.4);cursor:pointer;height:38px;outline:0;position:relative;width:39px}.kui-fulltext-search-panel .kui-fulltext-search .prefix.disabled,.kui-fulltext-search-panel .kui-fulltext-search .suffix.disabled{cursor:auto}.kui-fulltext-search-panel .kui-fulltext-search .prefix:active,.kui-fulltext-search-panel .kui-fulltext-search .suffix:active{color:#515151}.kui-search-menu{height:100%}.kui-search-menu .kui-menu-content{display:block}.kui-search-menu .kui-menu-content .mat-list{padding-bottom:8px}.kui-search-menu .kui-menu-content .mat-list .kui-previous-search-query{overflow:hidden;text-overflow:ellipsis}.kui-search-menu .kui-menu-content .mat-list .kui-previous-search-query.fix-width{width:calc(100% - 160px)}.kui-project-filter-button{height:38px!important;display:block;text-align:left}.kui-project-filter-button .placeholder{margin:0;padding:0;font-size:x-small}.kui-project-filter-button .icon,.kui-project-filter-button .label{display:inline;position:relative}.kui-project-filter-button .label{top:-12px;font-size:smaller;text-transform:capitalize}.kui-project-filter-button .icon{top:-6px;float:right}.kui-project-filter-button.kui-project-filter-button-mobile{height:100%!important}.kui-project-filter-button.kui-project-filter-button-mobile .icon,.kui-project-filter-button.kui-project-filter-button-mobile .label{top:0;font-size:inherit}@media (min-width:576px){.kui-fulltext-search-mobile,.kui-fulltext-search-mobile.with-project-filter,.kui-project-filter-mobile{display:none}}@media (max-width:576px){.kui-fulltext-search,.kui-project-filter{display:none}.kui-fulltext-search.with-project-filter{display:none!important}.kui-search-menu{display:none}.kui-search-menu.with-project-filter{display:none!important}.kui-fulltext-search-panel{height:100vh!important;background-color:rgba(220,218,218,.9);position:relative;width:100%!important;z-index:100;display:block;border-radius:0}.kui-fulltext-search-panel.with-project-filter{width:100%!important}.kui-fulltext-search-panel .kui-project-filter-mobile{height:54px;margin:0 2% 5%;padding-top:3%}.kui-fulltext-search-panel .kui-project-filter-mobile.mat-stroked-button{padding:0}.kui-fulltext-search-panel .kui-project-filter-mobile .kui-project-filter-button-mobile{width:calc(100% - 16px);margin:8px;height:100%;background-color:#b8b8b8;cursor:pointer}.kui-fulltext-search-panel .kui-project-filter-mobile .kui-project-filter-menu-mobile{width:calc(100% - 32px)!important;max-width:100%;margin:0 8px;height:100%!important}.kui-fulltext-search-panel .kui-fulltext-search-mobile{display:-webkit-box;display:flex;height:64px;margin-top:5%;margin-right:4%;margin-left:4%}.kui-fulltext-search-panel .kui-fulltext-search-mobile .kui-fulltext-search-field-mobile{width:80%;margin-right:2px}.kui-fulltext-search-panel .kui-fulltext-search-mobile .kui-fulltext-search-field-mobile .kui-fulltext-search-input-mobile{width:72%;height:64px;font-size:14pt;position:absolute;padding-left:12px;border-radius:5px;border:.6px solid #b8b8b8}.kui-fulltext-search-panel .kui-fulltext-search-mobile .kui-fulltext-search-field-mobile .kui-fulltext-search-input-mobile:active,.kui-fulltext-search-panel .kui-fulltext-search-mobile .kui-fulltext-search-field-mobile .kui-fulltext-search-input-mobile:focus{outline:0}.kui-fulltext-search-panel .kui-fulltext-search-mobile .kui-fulltext-search-button-mobile{background-color:#fff;width:20%;height:64px;padding:0;margin-left:2px;border-radius:5px;border:.8px solid #b8b8b8}.kui-fulltext-search-panel .kui-fulltext-search-mobile .suffix{margin:1px 0 1px -3px;border-radius:0 4px 4px 0}.kui-fulltext-search-panel .kui-fulltext-search-mobile .prefix,.kui-fulltext-search-panel .kui-fulltext-search-mobile .suffix{border-style:none;color:rgba(41,41,41,.4);cursor:pointer;height:100%;outline:0;position:relative;width:20%}.kui-fulltext-search-panel .kui-fulltext-search-mobile .prefix.disabled,.kui-fulltext-search-panel .kui-fulltext-search-mobile .suffix.disabled{cursor:auto}.kui-fulltext-search-panel .kui-fulltext-search-mobile .prefix:active,.kui-fulltext-search-panel .kui-fulltext-search-mobile .suffix:active{color:#515151}::ng-deep .cdk-overlay-pane .mat-menu-panel{box-shadow:none}::ng-deep .cdk-overlay-pane .mat-select-panel-wrap{margin-top:20%}::ng-deep .cdk-overlay-pane .mat-select-panel-wrap .mat-select-panel{max-height:100%!important}}"]
}),
__param(0, core.Inject(core$1.KnoraApiConnectionToken)),
__metadata("design:paramtypes", [api.KnoraApiConnection,
overlay.Overlay,
router.Router,
core.ViewContainerRef])
], FulltextSearchComponent);
return FulltextSearchComponent;
}());
/**
* The search-panel contains the kui-fulltext-search and the kui-extended-search components.
*/
var SearchPanelComponent = /** @class */ (function () {
function SearchPanelComponent(_overlay, _viewContainerRef) {
this._overlay = _overlay;
this._viewContainerRef = _viewContainerRef;
/**
* @param {string} route Route to navigate after search. This route path should contain a component for search results.
*/
this.route = '/search';
/**
*@param {boolean} [projectfilter] If true it shows the selection of projects to filter by one of them
*/
this.projectfilter = false;
/**
* @param {boolean} [advanced] Adds the extended / advanced search to the panel
*/
this.advanced = false;
/**
* @param {boolean} [expert] Adds the expert search / gravsearch editor to the panel
*/
this.expert = false;
}
SearchPanelComponent.prototype.openPanelWithBackdrop = function (type) {
var _this = this;
this.showAdvanced = (type === 'advanced');
var config = new overlay.OverlayConfig({
hasBackdrop: true,
backdropClass: 'cdk-overlay-transparent-backdrop',
// backdropClass: 'cdk-overlay-dark-backdrop',
positionStrategy: this.getOverlayPosition(),
scrollStrategy: this._overlay.scrollStrategies.block()
});
this.overlayRef = this._overlay.create(config);
this.overlayRef.attach(new portal.TemplatePortal(this.searchMenu, this._viewContainerRef));
this.overlayRef.backdropClick().subscribe(function () {
_this.overlayRef.detach();
});
};
SearchPanelComponent.prototype.getOverlayPosition = function () {
var positions = [
new overlay.ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }),
new overlay.ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' })
];
var overlayPosition = this._overlay.position().flexibleConnectedTo(this.searchPanel).withPositions(positions).withLockedPosition(false);
return overlayPosition;
};
SearchPanelComponent.prototype.closeMenu = function () {
this.overlayRef.detach();
};
SearchPanelComponent.ctorParameters = function () { return [
{ type: overlay.Overlay },
{ type: core.ViewContainerRef }
]; };
__decorate([
core.Input(),
__metadata("design:type", String)
], SearchPanelComponent.prototype, "route", void 0);
__decorate([
core.Input(),
__metadata("design:type", Boolean)
], SearchPanelComponent.prototype, "projectfilter", void 0);
__decorate([
core.Input(),
__metadata("design:type", String)
], SearchPanelComponent.prototype, "filterbyproject", void 0);
__decorate([
core.Input(),
__metadata("design:type", Boolean)
], SearchPanelComponent.prototype, "advanced", void 0);
__decorate([
core.Input(),
__metadata("design:type", Boolean)
], SearchPanelComponent.prototype, "expert", void 0);
__decorate([
core.ViewChild('fullSearchPanel', { static: false }),
__metadata("design:type", core.ElementRef)
], SearchPanelComponent.prototype, "searchPanel", void 0);
__decorate([
core.ViewChild('searchMenu', { static: false }),
__metadata("design:type", core.TemplateRef)
], SearchPanelComponent.prototype, "searchMenu", void 0);
SearchPanelComponent = __decorate([
core.Component({
selector: 'kui-search-panel',
template: "<div class=\"kui-search-panel\" #fullSearchPanel cdkOverlayOrigin>\n\n <!-- DESKTOP VERSION -->\n <kui-fulltext-search class=\"kui-fulltext-search\" [route]=\"route\" [projectfilter]=\"projectfilter\"\n [filterbyproject]=\"filterbyproject\">\n </kui-fulltext-search>\n\n <!-- advanced search button: if advanced === true -->\n <button mat-button *ngIf=\"advanced && !expert\" color=\"primary\"\n (click)=\"openPanelWithBackdrop('advanced')\">advanced</button>\n\n <!-- expert search button: if expert === true -->\n <button mat-button *ngIf=\"!advanced && expert\" color=\"primary\"\n (click)=\"openPanelWithBackdrop('expert')\">expert</button>\n\n <!-- button to select advanced or expert search: if advanced AND expert === true; open menu to select -->\n <button mat-button *ngIf=\"advanced && expert\" [matMenuTriggerFor]=\"selectSearch\">\n <mat-icon>filter_list</mat-icon>\n </button>\n <mat-menu #selectSearch=\"matMenu\">\n <button mat-menu-item (click)=\"openPanelWithBackdrop('advanced')\">\n <span>Advanced search</span>\n </button>\n <button mat-menu-item (click)=\"openPanelWithBackdrop('expert')\">\n <span>Expert search</span>\n </button>\n </mat-menu>\n\n</div>\n\n<!-- full-text search menu -->\n<ng-template #searchMenu>\n <div class=\"kui-search-menu with-extended-search\" [class.with-project-filter]=\"projectfilter\">\n <div class=\"kui-menu-header\">\n <span class=\"kui-menu-title\">\n <h4 *ngIf=\"showAdvanced\">Advanced search</h4>\n <h4 *ngIf=\"!showAdvanced\">Expert search</h4>\n </span>\n <span class=\"fill-remaining-space\"></span>\n <span class=\"kui-menu-close\">\n <button mat-icon-button (click)=\"closeMenu()\">\n <mat-icon>close</mat-icon>\n </button>\n </span>\n </div>\n <div class=\"kui-menu-content\">\n <kui-extended-search *ngIf=\"showAdvanced\" [route]=\"route\" (toggleExtendedSearchForm)=\"closeMenu()\">\n </kui-extended-search>\n <kui-expert-search *ngIf=\"!showAdvanced\" [route]=\"route\" (toggleExpertSearchForm)=\"closeMenu()\">\n </kui-expert-search>\n </div>\n </div>\n</ng-template>\n",
styles: [".advanced-btn{margin-left:10px}.kui-search-panel{display:-webkit-box;display:flex;position:relative;z-index:100}.extended-search-box{margin:12px}@media (max-width:576px){.kui-fulltext-search{height:100%;width:100%!important}}"]
}),
__metadata("design:paramtypes", [overlay.Overlay,
core.ViewContainerRef])
], SearchPanelComponent);
return SearchPanelComponent;
}());
// https://stackoverflow.com/questions/45661010/dynamic-nested-reactive-form-expressionchangedafterithasbeencheckederror
var resolvedPromise = Promise.resolve(null);
var SelectResourceClassComponent = /** @class */ (function () {
function SelectResourceClassComponent(fb) {
this.fb = fb;
// event emitted to parent component once a resource class is selected by the user
this.resourceClassSelectedEvent = new core.EventEmitter();
}
Object.defineProperty(SelectResourceClassComponent.prototype, "resourceClasses", {
// getter method for resource classes (used in template)
get: function () {
return this._resourceClasses;
},
// setter method for resource classes when being updated by parent component
set: function (value) {
this.resourceClassSelected = undefined; // reset on updates
this._resourceClasses = value;
},
enumerable: true,
configurable: true
});
/**
* Returns the Iri of the selected resource class.
*
* @returns the Iri of the selected resource class or false in case no resource class is selected.
*/
SelectResourceClassComponent.prototype.getResourceClassSelected = function () {
if (this.resourceClassSelected !== undefined && this.resourceClassSelected !== null) {
return this.resourceClassSelected;
}
else {
return false;
}
};
/**
* Initalizes the FormGroup for the resource class selection.
* The initial value is set to null.
*/
SelectResourceClassComponent.prototype.initForm = function () {
var _this = this;
// build a form for the resource class selection
this.form = this.fb.group({
resourceClass: [null] // resource class selection is optional
});
// store and emit Iri of the resource class when selected
this.form.valueChanges.subscribe(function (data) {
_this.resourceClassSelected = data.resourceClass;
_this.resourceClassSelectedEvent.emit(_this.resourceClassSelected);
});
};
SelectResourceClassComponent.prototype.ngOnInit = function () {
this.initForm();
// add form to the parent form group
this.formGroup.addControl('resourceClass', this.form);
};
SelectResourceClassComponent.prototype.ngOnChanges = function () {
var _this = this;
if (this.form !== undefined) {
// resource classes have been reinitialized
// reset form
resolvedPromise.then(function () {
// remove this form from the parent form group
_this.formGroup.removeControl('resourceClass');
_this.initForm();
// add form to the parent form group
_this.formGroup.addControl('resourceClass', _this.form);
});
}
};
SelectResourceClassComponent.ctorParameters = function () { return [
{ type: forms.FormBuilder, decorators: [{ type: core.Inject, args: [forms.FormBuilder,] }] }
]; };
__decorate([
core.Input(),
__metadata("design:type", forms.FormGroup)
], SelectResourceClassComponent.prototype, "formGroup", void 0);
__decorate([
core.Input(),
__metadata("design:type", Array),
__metadata("design:paramtypes", [Array])
], SelectResourceClassComponent.prototype, "resourceClasses", null);
__decorate([
core.Output(),
__metadata("design:type", Object)
], SelectResourceClassComponent.prototype, "resourceClassSelectedEvent", void 0);
SelectResourceClassComponent = __decorate([
core.Component({
selector: 'kui-select-resource-class',
template: "<mat-form-field *ngIf=\"resourceClasses.length > 0\" class=\"large-field\">\n <mat-select placeholder=\"Select a Resource Class (optional)\" [formControl]=\"form.controls['resourceClass']\">\n <mat-option [value]=\"null\">no selection</mat-option>\n <!-- undo selection of a resource class -->\n <mat-option *ngFor=\"let resourceClass of resourceClasses\" [value]=\"resourceClass.id\">{{ resourceClass.label }}\n </mat-option>\n </mat-select>\n</mat-form-field>\n",