Compare commits

..

3 Commits

Author SHA1 Message Date
Rainer Killinger
436e1471a7 docs: update changelogs for release
ci: publish release
2024-12-02 11:26:24 +01:00
Rainer Killinger
4c9d330c88 fix: update jsonpath-plus depenency 2024-12-02 11:08:58 +01:00
Thea Schöbl
580ebee362 fix: user gets logged out when their token expires
Closes #230
2024-11-28 18:04:08 +00:00
29 changed files with 237 additions and 300 deletions

View File

@@ -8,7 +8,8 @@ const config = {
database: { database: {
name: 'elasticsearch', name: 'elasticsearch',
query: { query: {
fields: ["name"] minMatch: '60%',
queryType: 'query_string',
}, },
}, },
}, },

View File

@@ -39,7 +39,7 @@ const boostings = {
type: SCThingType.AcademicEvent, type: SCThingType.AcademicEvent,
}, },
{ {
factor: 2, factor: 1.6,
type: SCThingType.Building, type: SCThingType.Building,
}, },
{ {
@@ -85,7 +85,7 @@ const boostings = {
], ],
place: [ place: [
{ {
factor: 3, factor: 2,
type: SCThingType.Building, type: SCThingType.Building,
}, },
{ {

View File

@@ -17,21 +17,12 @@ const config = {
name: 'elasticsearch', name: 'elasticsearch',
version: '8.4.2', version: '8.4.2',
query: { query: {
type: 'best_fields', minMatch: '75%',
fields: [ queryType: 'dis_max',
'identifiers^20', matchBoosting: 1.3,
'name^10', fuzziness: 'AUTO',
'translations.*.name^10', cutoffFrequency: 0,
'alternateNames^10', tieBreaker: 0,
'translations.*.alternateNames^10',
'description^2',
'translations.*.description^2',
'categories^5',
],
},
searchAsYouTypeQuery: {
type: 'phrase_prefix',
fields: ['name.completion', 'name.completion._2gram', 'name.completion._3gram'],
}, },
}, },
}, },

View File

@@ -20,8 +20,6 @@ import {
IndicesGetAliasResponse, IndicesGetAliasResponse,
SearchHit, SearchHit,
SearchResponse, SearchResponse,
SearchTermSuggest,
SearchTermSuggestOption,
} from '@elastic/elasticsearch/lib/api/types.js'; } from '@elastic/elasticsearch/lib/api/types.js';
import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCUuid} from '@openstapps/core'; import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCUuid} from '@openstapps/core';
import {Logger} from '@openstapps/logger'; import {Logger} from '@openstapps/logger';
@@ -49,9 +47,6 @@ import {
import {noUndefined} from './util/no-undefined.js'; import {noUndefined} from './util/no-undefined.js';
import {retryCatch, RetryOptions} from './util/retry.js'; import {retryCatch, RetryOptions} from './util/retry.js';
import {Feature, Point, Polygon} from 'geojson'; import {Feature, Point, Polygon} from 'geojson';
import {parseSuggestions} from './util/parse-suggestions.js';
import {buildScoringFunctions} from './query/boost/scoring-functions.js';
import {buildFilter} from './query/filter.js';
/** /**
* A database interface for elasticsearch * A database interface for elasticsearch
@@ -360,39 +355,6 @@ export class Elasticsearch implements Database {
throw new Error('You tried to PUT an non-existing object. PUT is only supported on existing objects.'); throw new Error('You tried to PUT an non-existing object. PUT is only supported on existing objects.');
} }
public async searchAsYouType(parameters: SCSearchQuery): Promise<SCSearchResponse> {
const result = await this.client.search({
_source: 'name',
query: {
function_score: {
functions: buildScoringFunctions(this.config.internal.boostings, parameters.context),
query: {
bool: {
must: {
multi_match: {
query: parameters.query,
type: 'bool_prefix',
fields: ['name.completion', 'name.completion._2gram', 'name.completion._3gram'],
},
},
should: [],
filter: parameters.filter === undefined ? undefined : buildFilter(parameters.filter),
},
},
score_mode: 'max',
boost_mode: 'multiply',
},
},
index: ACTIVE_INDICES_ALIAS,
allow_no_indices: true,
size: 5,
});
const suggestions = result.hits.hits.map(it => (it._source as any).name);
console.log(suggestions);
console.log(result.took);
}
/** /**
* Search all indexed data * Search all indexed data
* @param parameters search query * @param parameters search query
@@ -402,23 +364,18 @@ export class Elasticsearch implements Database {
throw new TypeError('Database is undefined. You have to configure the query build'); throw new TypeError('Database is undefined. You have to configure the query build');
} }
const esConfig = this.config.internal.database as object as ElasticsearchConfig; const esConfig: ElasticsearchConfig = {
name: this.config.internal.database.name as 'elasticsearch',
version: this.config.internal.database.version as string,
query: this.config.internal.database.query as
| ElasticsearchQueryDisMaxConfig
| ElasticsearchQueryQueryStringConfig
| undefined,
};
const response: SearchResponse<SCThings> = await this.client.search({ const response: SearchResponse<SCThings> = await this.client.search({
aggs: aggregations, aggs: aggregations,
query: buildQuery(parameters, this.config, esConfig), query: buildQuery(parameters, this.config, esConfig),
suggest:
parameters.query === undefined
? undefined
: {
text: parameters.query,
terms: {
term: {
field: 'name',
suggest_mode: 'missing',
},
},
},
from: parameters.from, from: parameters.from,
index: ACTIVE_INDICES_ALIAS, index: ACTIVE_INDICES_ALIAS,
allow_no_indices: true, allow_no_indices: true,
@@ -438,7 +395,6 @@ export class Elasticsearch implements Database {
response.aggregations === undefined response.aggregations === undefined
? [] ? []
: parseAggregations(response.aggregations as Record<AggregateName, AggregationsMultiTermsBucket>), : parseAggregations(response.aggregations as Record<AggregateName, AggregationsMultiTermsBucket>),
suggestions: response.suggest === undefined ? undefined : parseSuggestions(response.suggest),
pagination: { pagination: {
count: response.hits.hits.length, count: response.hits.hits.length,
offset: typeof parameters.from === 'number' ? parameters.from : 0, offset: typeof parameters.from === 'number' ? parameters.from : 0,

View File

@@ -30,21 +30,84 @@ export const buildQuery = function buildQuery(
defaultConfig: SCConfigFile, defaultConfig: SCConfigFile,
elasticsearchConfig: ElasticsearchConfig, elasticsearchConfig: ElasticsearchConfig,
): QueryDslQueryContainer { ): QueryDslQueryContainer {
return { // if config provides a minMatch parameter, we use query_string instead of a match query
let query;
if (elasticsearchConfig.query === undefined) {
query = {
query_string: {
analyzer: 'search_german',
default_field: 'name',
minimum_should_match: '90%',
query: typeof parameters.query === 'string' ? parameters.query : '*',
},
};
} else if (elasticsearchConfig.query.queryType === 'query_string') {
query = {
query_string: {
analyzer: 'search_german',
default_field: 'name',
minimum_should_match: elasticsearchConfig.query.minMatch,
query: typeof parameters.query === 'string' ? parameters.query : '*',
},
};
} else if (elasticsearchConfig.query.queryType === 'dis_max') {
if (typeof parameters.query === 'string' && parameters.query !== '*') {
query = {
dis_max: {
boost: 1.2,
queries: [
{
match: {
name: {
boost: elasticsearchConfig.query.matchBoosting,
fuzziness: elasticsearchConfig.query.fuzziness,
query: parameters.query,
},
},
},
{
query_string: {
default_field: 'name',
minimum_should_match: elasticsearchConfig.query.minMatch,
query: parameters.query,
},
},
],
tie_breaker: elasticsearchConfig.query.tieBreaker,
},
};
}
} else {
throw new Error(
'Unsupported query type. Check your config file and reconfigure your elasticsearch query',
);
}
const functionScoreQuery: QueryDslQueryContainer = {
function_score: { function_score: {
functions: buildScoringFunctions(defaultConfig.internal.boostings, parameters.context), functions: buildScoringFunctions(defaultConfig.internal.boostings, parameters.context),
query: { query: {
bool: { bool: {
must: minimum_should_match: 0, // if we have no should, nothing can match
parameters.query === undefined || parameters.query === '' || parameters.query === '*' must: [],
? {match_all: {}}
: {multi_match: {...elasticsearchConfig.query, query: parameters.query}},
should: [], should: [],
filter: parameters.filter === undefined ? undefined : buildFilter(parameters.filter),
}, },
}, },
score_mode: 'max', score_mode: 'multiply',
boost_mode: 'multiply',
}, },
}; };
const mustMatch = functionScoreQuery.function_score?.query?.bool?.must;
if (Array.isArray(mustMatch)) {
if (query !== undefined) {
mustMatch.push(query);
}
if (parameters.filter !== undefined) {
mustMatch.push(buildFilter(parameters.filter));
}
}
return functionScoreQuery;
}; };

View File

@@ -13,7 +13,68 @@
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {QueryDslMultiMatchQuery} from '@elastic/elasticsearch/lib/api/types.js'; /**
* A configuration for using the Dis Max Query
*
* See https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-dis-max-query.html for further
* explanation of what the parameters mean
*/
export interface ElasticsearchQueryDisMaxConfig {
/**
* Relative (to a total number of documents) or absolute number to exclude meaningless matches that frequently appear
*/
cutoffFrequency: number;
/**
* The maximum allowed Levenshtein Edit Distance (or number of edits)
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/common-options.html#fuzziness
*/
fuzziness: number | string;
/**
* Increase the importance (relevance score) of a field
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/mapping-boost.html
*/
matchBoosting: number;
/**
* Minimal number (or percentage) of words that should match in a query
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-minimum-should-match.html
*/
minMatch: string;
/**
* Type of the query - in this case 'dis_max' which is a union of its subqueries
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-dis-max-query.html
*/
queryType: 'dis_max';
/**
* Changes behavior of default calculation of the score when multiple results match
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-multi-match-query.html#tie-breaker
*/
tieBreaker: number;
}
/**
* A configuration for using Query String Query
*
* See https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html for further
* explanation of what the parameters mean
*/
export interface ElasticsearchQueryQueryStringConfig {
/**
* Minimal number (or percentage) of words that should match in a query
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-minimum-should-match.html
*/
minMatch: string;
/**
* Type of the query - in this case 'query_string' which uses a query parser in order to parse content
* @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html
*/
queryType: 'query_string';
}
/** /**
* An config file for the elasticsearch database interface * An config file for the elasticsearch database interface
@@ -44,12 +105,7 @@ export interface ElasticsearchConfig {
/** /**
* Configuration for using queries * Configuration for using queries
*/ */
query: Omit<QueryDslMultiMatchQuery, 'query'>; query?: ElasticsearchQueryDisMaxConfig | ElasticsearchQueryQueryStringConfig;
/**
*
*/
searchAsYouTypeQuery: Omit<QueryDslMultiMatchQuery, 'query'>;
/** /**
* Version of the used elasticsearch * Version of the used elasticsearch

View File

@@ -1,28 +0,0 @@
import {
SearchSuggest,
SearchTermSuggest,
SearchTermSuggestOption,
SuggestionName,
} from '@elastic/elasticsearch/lib/api/types.js';
import {SCSearchSuggestions} from '@openstapps/core';
/**
* Parse ES Suggestions to SC Search Suggestions
*/
export function parseSuggestions(suggest: Record<SuggestionName, SearchSuggest[]>): SCSearchSuggestions {
const termsSuggestions =
suggest.terms === undefined
? []
: (suggest.terms as SearchTermSuggest[])
?.map(
({text, options}) =>
[
text,
(options as SearchTermSuggestOption[] | undefined)?.map(({text}) => text) ?? [],
] as const,
)
.filter(([, suggestions]) => suggestions.length > 0) ?? [];
return {
terms: termsSuggestions.length === 0 ? undefined : Object.fromEntries(termsSuggestions),
};
}

View File

@@ -1,5 +1,11 @@
# @openstapps/app # @openstapps/app
## 3.3.5
### Patch Changes
- 4c9d330c: fix user logout when token expires
## 3.3.4 ## 3.3.4
### Minor Changes ### Minor Changes

View File

@@ -1,7 +1,7 @@
{ {
"name": "@openstapps/app", "name": "@openstapps/app",
"description": "The generic app tailored to fulfill needs of German universities, written using Ionic Framework.", "description": "The generic app tailored to fulfill needs of German universities, written using Ionic Framework.",
"version": "3.3.4", "version": "3.3.5",
"private": true, "private": true,
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>", "author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
@@ -97,7 +97,7 @@
"form-data": "4.0.0", "form-data": "4.0.0",
"geojson": "0.5.0", "geojson": "0.5.0",
"ionic-appauth": "0.9.0", "ionic-appauth": "0.9.0",
"jsonpath-plus": "10.0.6", "jsonpath-plus": "10.0.7",
"maplibre-gl": "4.0.2", "maplibre-gl": "4.0.2",
"material-symbols": "0.17.1", "material-symbols": "0.17.1",
"moment": "2.30.1", "moment": "2.30.1",

View File

@@ -86,6 +86,8 @@ export abstract class AuthService implements IAuthService {
private _authenticatedSubject = new BehaviorSubject<boolean>(false); private _authenticatedSubject = new BehaviorSubject<boolean>(false);
private _loggedInSubject = new BehaviorSubject<boolean>(false);
private _initComplete = new BehaviorSubject<boolean>(false); private _initComplete = new BehaviorSubject<boolean>(false);
protected tokenHandler: TokenRequestHandler; protected tokenHandler: TokenRequestHandler;
@@ -133,6 +135,13 @@ export abstract class AuthService implements IAuthService {
return this._authenticatedSubject.asObservable(); return this._authenticatedSubject.asObservable();
} }
/**
* Similar to isAuthenticated$, but will also return true if the token is expired
*/
get isLoggedIn$(): Observable<boolean> {
return this._loggedInSubject.asObservable();
}
get initComplete$(): Observable<boolean> { get initComplete$(): Observable<boolean> {
return this._initComplete.asObservable(); return this._initComplete.asObservable();
} }
@@ -183,19 +192,20 @@ export abstract class AuthService implements IAuthService {
protected notifyActionListers(action: IAuthAction) { protected notifyActionListers(action: IAuthAction) {
/* eslint-disable unicorn/no-useless-undefined */ /* eslint-disable unicorn/no-useless-undefined */
switch (action.action) { switch (action.action) {
case AuthActions.RefreshFailed:
case AuthActions.SignInFailed: case AuthActions.SignInFailed:
case AuthActions.SignOutSuccess: case AuthActions.SignOutSuccess:
case AuthActions.SignOutFailed: { case AuthActions.SignOutFailed: {
this._tokenSubject.next(undefined); this._tokenSubject.next(undefined);
this._userSubject.next(undefined); this._userSubject.next(undefined);
this._authenticatedSubject.next(false); this._authenticatedSubject.next(false);
this._loggedInSubject.next(false);
break; break;
} }
case AuthActions.LoadTokenFromStorageFailed: { case AuthActions.LoadTokenFromStorageFailed: {
this._tokenSubject.next(undefined); this._tokenSubject.next(undefined);
this._userSubject.next(undefined); this._userSubject.next(undefined);
this._authenticatedSubject.next(false); this._authenticatedSubject.next(false);
this._loggedInSubject.next(false);
this._initComplete.next(true); this._initComplete.next(true);
break; break;
} }
@@ -203,11 +213,13 @@ export abstract class AuthService implements IAuthService {
case AuthActions.RefreshSuccess: { case AuthActions.RefreshSuccess: {
this._tokenSubject.next(action.tokenResponse); this._tokenSubject.next(action.tokenResponse);
this._authenticatedSubject.next(true); this._authenticatedSubject.next(true);
this._loggedInSubject.next(true);
break; break;
} }
case AuthActions.LoadTokenFromStorageSuccess: { case AuthActions.LoadTokenFromStorageSuccess: {
this._tokenSubject.next(action.tokenResponse); this._tokenSubject.next(action.tokenResponse);
this._authenticatedSubject.next((action.tokenResponse as TokenResponse).isValid(0)); this._authenticatedSubject.next((action.tokenResponse as TokenResponse).isValid(0));
this._loggedInSubject.next(true);
this._initComplete.next(true); this._initComplete.next(true);
break; break;
} }
@@ -442,7 +454,6 @@ export abstract class AuthService implements IAuthService {
public async refreshToken() { public async refreshToken() {
await this.requestTokenRefresh().catch(error => { await this.requestTokenRefresh().catch(error => {
this.storage.removeItem(TOKEN_RESPONSE_KEY);
this.notifyActionListers(AuthActionBuilder.RefreshFailed(error)); this.notifyActionListers(AuthActionBuilder.RefreshFailed(error));
}); });
} }

View File

@@ -81,6 +81,8 @@ export class PAIAAuthService {
private _authenticatedSubject = new BehaviorSubject<boolean>(false); private _authenticatedSubject = new BehaviorSubject<boolean>(false);
private _loggedIn = new BehaviorSubject<boolean>(false);
private _initComplete = new BehaviorSubject<boolean>(false); private _initComplete = new BehaviorSubject<boolean>(false);
protected tokenHandler: PAIATokenRequestHandler; protected tokenHandler: PAIATokenRequestHandler;
@@ -118,6 +120,13 @@ export class PAIAAuthService {
return this._authenticatedSubject.asObservable(); return this._authenticatedSubject.asObservable();
} }
/**
* Similar to isAuthenticated$, but will also return true if the token is expired
*/
get isLoggedIn$(): Observable<boolean> {
return this._loggedIn.asObservable();
}
get initComplete$(): Observable<boolean> { get initComplete$(): Observable<boolean> {
return this._initComplete.asObservable(); return this._initComplete.asObservable();
} }
@@ -170,23 +179,27 @@ export class PAIAAuthService {
this._tokenSubject.next(undefined); this._tokenSubject.next(undefined);
this._userSubject.next(undefined); this._userSubject.next(undefined);
this._authenticatedSubject.next(false); this._authenticatedSubject.next(false);
this._loggedIn.next(false);
break; break;
} }
case AuthActions.LoadTokenFromStorageFailed: { case AuthActions.LoadTokenFromStorageFailed: {
this._tokenSubject.next(undefined); this._tokenSubject.next(undefined);
this._userSubject.next(undefined); this._userSubject.next(undefined);
this._authenticatedSubject.next(false); this._authenticatedSubject.next(false);
this._loggedIn.next(false);
this._initComplete.next(true); this._initComplete.next(true);
break; break;
} }
case AuthActions.SignInSuccess: { case AuthActions.SignInSuccess: {
this._tokenSubject.next(action.tokenResponse); this._tokenSubject.next(action.tokenResponse);
this._authenticatedSubject.next(true); this._authenticatedSubject.next(true);
this._loggedIn.next(true);
break; break;
} }
case AuthActions.LoadTokenFromStorageSuccess: { case AuthActions.LoadTokenFromStorageSuccess: {
this._tokenSubject.next(action.tokenResponse); this._tokenSubject.next(action.tokenResponse);
this._authenticatedSubject.next((action.tokenResponse as TokenResponse).isValid(0)); this._authenticatedSubject.next((action.tokenResponse as TokenResponse).isValid(0));
this._loggedIn.next(true);
this._initComplete.next(true); this._initComplete.next(true);
break; break;
} }

View File

@@ -24,7 +24,6 @@ import {
SCSearchQuery, SCSearchQuery,
SCSearchSort, SCSearchSort,
SCThings, SCThings,
SCSearchSuggestions,
} from '@openstapps/core'; } from '@openstapps/core';
import {NGXLogger} from 'ngx-logger'; import {NGXLogger} from 'ngx-logger';
import {combineLatest, Subject} from 'rxjs'; import {combineLatest, Subject} from 'rxjs';
@@ -111,8 +110,6 @@ export class SearchPageComponent implements OnInit {
*/ */
items: Promise<SCThings[]>; items: Promise<SCThings[]>;
suggestions: SCSearchSuggestions | undefined;
/** /**
* Page size of queries * Page size of queries
*/ */
@@ -222,7 +219,6 @@ export class SearchPageComponent implements OnInit {
try { try {
const result = await this.dataProvider.search(searchOptions); const result = await this.dataProvider.search(searchOptions);
this.suggestions = result.suggestions;
this.singleTypeResponse = result.facets.find(facet => facet.field === 'type')?.buckets.length === 1; this.singleTypeResponse = result.facets.find(facet => facet.field === 'type')?.buckets.length === 1;
if (append) { if (append) {
// append results // append results
@@ -287,12 +283,6 @@ export class SearchPageComponent implements OnInit {
this.contextMenuService.updateContextFilter(facets); this.contextMenuService.updateContextFilter(facets);
} }
applySuggestion(target: string, suggestion: string) {
this.queryText = this.queryText.replaceAll(target, suggestion);
this.suggestions = undefined;
this.searchStringChanged(this.queryText);
}
ngOnInit(defaultListeners = true) { ngOnInit(defaultListeners = true) {
this.initialize(); this.initialize();
this.contextMenuService.setContextSort({ this.contextMenuService.setContextSort({

View File

@@ -69,23 +69,7 @@
</ion-header> </ion-header>
<ion-content class="content"> <ion-content class="content">
<div class="suggestions">
@if (suggestions?.terms; as terms) {
<span>{{ 'search.SUGGESTIONS' | translate }}: </span>
@for (suggestion of terms | keyvalue; track suggestion) {
@for (term of suggestion.value; track term) {
@if ($index == 0) {
<b (click)="applySuggestion(suggestion.key, term)" class="suggestion">{{ term }}</b>
} @else {
<span (click)="applySuggestion(suggestion.key, term)" class="suggestion">{{ term }}</span>
}
}
}
}
</div>
<div <div
class="hint"
[class.no-results]="!showDefaultData && !items && !loading" [class.no-results]="!showDefaultData && !items && !loading"
[style.display]="!showDefaultData && !items && !loading ? 'block' : 'none'" [style.display]="!showDefaultData && !items && !loading ? 'block' : 'none'"
> >

View File

@@ -46,7 +46,7 @@ ion-content {
--background: var(--ion-background-color); --background: var(--ion-background-color);
} }
.content > .hint { .content > div {
height: 100%; height: 100%;
ion-label.centered-message-container { ion-label.centered-message-container {
@@ -60,19 +60,3 @@ ion-content {
ion-header { ion-header {
background: var(--ion-color-primary); background: var(--ion-color-primary);
} }
.suggestions {
padding: var(--spacing-md);
padding-block-end: 0;
}
.suggestion {
cursor: pointer;
}
.suggestion + .suggestion::before {
cursor: text;
content: ',';
padding-inline-end: 0.25ch;
font-weight: normal;
}

View File

@@ -23,9 +23,9 @@ export class IdCardsProvider {
this.encryptedStorageProvider.get<SCIdCard[]>('id-cards') as Promise<SCIdCard[]>, this.encryptedStorageProvider.get<SCIdCard[]>('id-cards') as Promise<SCIdCard[]>,
).pipe(filter(it => it !== undefined)); ).pipe(filter(it => it !== undefined));
return auth.isAuthenticated$.pipe( return auth.isLoggedIn$.pipe(
mergeMap(isAuthenticated => mergeMap(isLoggedIn =>
isAuthenticated isLoggedIn
? feature ? feature
? storedIdCards.pipe( ? storedIdCards.pipe(
concatWith( concatWith(

View File

@@ -7,7 +7,7 @@ import {SCAuthorizationProviderType} from '@openstapps/core';
import {EncryptedStorageProvider} from '../storage/encrypted-storage.provider'; import {EncryptedStorageProvider} from '../storage/encrypted-storage.provider';
class FakeAuth { class FakeAuth {
isAuthenticated$ = new BehaviorSubject(false); isLoggedIn$ = new BehaviorSubject(false);
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
getValidToken() {} getValidToken() {}
@@ -42,7 +42,7 @@ describe('IdCards', () => {
}); });
it('should emit network result when logged in', async () => { it('should emit network result when logged in', async () => {
fakeAuth.isAuthenticated$.next(true); fakeAuth.isLoggedIn$.next(true);
httpClient.get = jasmine.createSpy().and.returnValue(of(['abc'])); httpClient.get = jasmine.createSpy().and.returnValue(of(['abc']));
fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'}); fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'});
const provider = new IdCardsProvider(authHelper, configProvider, httpClient, encryptedStorageProvider); const provider = new IdCardsProvider(authHelper, configProvider, httpClient, encryptedStorageProvider);
@@ -63,7 +63,7 @@ describe('IdCards', () => {
expect(await firstValueFrom(observable)).toEqual([]); expect(await firstValueFrom(observable)).toEqual([]);
httpClient.get = jasmine.createSpy().and.returnValue(of(['abc'])); httpClient.get = jasmine.createSpy().and.returnValue(of(['abc']));
fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'}); fakeAuth.getValidToken = jasmine.createSpy().and.resolveTo({accessToken: 'fake-token'});
fakeAuth.isAuthenticated$.next(true); fakeAuth.isLoggedIn$.next(true);
// this is counter-intuitive, but because we unsubscribed above the first value // this is counter-intuitive, but because we unsubscribed above the first value
// will now contain the network result. // will now contain the network result.
expect(await firstValueFrom(observable)).toEqual(['abc' as never]); expect(await firstValueFrom(observable)).toEqual(['abc' as never]);

View File

@@ -6,74 +6,56 @@
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAr purpose. see the gnu general public license for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License along with * you should have received a copy of the gnu general public license along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. if not, see <https://www.gnu.org/licenses/>.
*/ */
import {Component, DestroyRef, inject, Input, OnInit} from '@angular/core'; import {Component, inject, input} from '@angular/core';
import {SCSection} from '../../../../config/profile-page-sections'; import {SCSection} from '../../../../config/profile-page-sections';
import {AuthHelperService} from '../../auth/auth-helper.service'; import {AuthHelperService} from '../../auth/auth-helper.service';
import {Observable} from 'rxjs'; import {mergeMap, of} from 'rxjs';
import {SCAuthorizationProviderType} from '@openstapps/core';
import Swiper from 'swiper'; import Swiper from 'swiper';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import {toObservable, toSignal} from '@angular/core/rxjs-interop';
@Component({ @Component({
selector: 'stapps-profile-page-section', selector: 'stapps-profile-page-section',
templateUrl: 'profile-page-section.html', templateUrl: 'profile-page-section.html',
styleUrls: ['profile-page-section.scss'], styleUrls: ['profile-page-section.scss'],
}) })
export class ProfilePageSectionComponent implements OnInit { export class ProfilePageSectionComponent {
@Input() item: SCSection; item = input.required<SCSection>();
@Input() minSlideWidth = 110; minSlideWidth = input(110);
isLoggedIn: boolean; authHelper = inject(AuthHelperService);
loggedIn = toSignal(
toObservable(this.item).pipe(
mergeMap(item =>
item.authProvider ? this.authHelper.getProvider(item.authProvider).isLoggedIn$ : of(false),
),
),
);
isEnd = false; isEnd = false;
isBeginning = true; isBeginning = true;
slidesPerView: number; slidesPerView?: number;
slidesFillScreen = false; slidesFillScreen = false;
data: {
[key in SCAuthorizationProviderType]: {loggedIn$: Observable<boolean>};
} = {
default: {
loggedIn$: this.authHelper.getProvider('default').isAuthenticated$,
},
paia: {
loggedIn$: this.authHelper.getProvider('paia').isAuthenticated$,
},
};
destroy$ = inject(DestroyRef);
constructor(private authHelper: AuthHelperService) {}
ngOnInit() {
if (this.item.authProvider) {
this.data[this.item.authProvider].loggedIn$
.pipe(takeUntilDestroyed(this.destroy$))
.subscribe(loggedIn => {
this.isLoggedIn = loggedIn;
});
}
}
activeIndexChange(swiper: Swiper) { activeIndexChange(swiper: Swiper) {
this.isBeginning = swiper.isBeginning; this.isBeginning = swiper.isBeginning;
this.isEnd = swiper.isEnd; this.isEnd = swiper.isEnd;
this.slidesFillScreen = this.slidesPerView >= swiper.slides.length; this.slidesFillScreen = this.slidesPerView! >= swiper.slides.length;
} }
resizeSwiper(resizeEvent: ResizeObserverEntry, swiper: Swiper) { resizeSwiper(resizeEvent: ResizeObserverEntry, swiper: Swiper) {
const slidesPerView = const slidesPerView =
Math.floor((resizeEvent.contentRect.width - this.minSlideWidth / 2) / this.minSlideWidth) + 0.5; Math.floor((resizeEvent.contentRect.width - this.minSlideWidth() / 2) / this.minSlideWidth()) + 0.5;
if (slidesPerView > 1 && slidesPerView !== this.slidesPerView) { if (slidesPerView > 1 && slidesPerView !== this.slidesPerView) {
this.slidesPerView = slidesPerView; this.slidesPerView = slidesPerView;
@@ -84,16 +66,13 @@ export class ProfilePageSectionComponent implements OnInit {
} }
async toggleLogIn() { async toggleLogIn() {
if (!this.item.authProvider) return; const providerType = this.item().authProvider;
await (this.isLoggedIn ? this.signOut(this.item.authProvider) : this.signIn(this.item.authProvider)); if (!providerType) return;
} if (this.loggedIn()) {
await this.authHelper.getProvider(providerType).signOut();
async signIn(providerType: SCAuthorizationProviderType) { await this.authHelper.endBrowserSession(providerType);
await this.authHelper.getProvider(providerType).signIn(); } else {
} await this.authHelper.getProvider(providerType).signIn();
}
async signOut(providerType: SCAuthorizationProviderType) {
await this.authHelper.getProvider(providerType).signOut();
await this.authHelper.endBrowserSession(providerType);
} }
} }

View File

@@ -13,24 +13,24 @@
~ this program. If not, see <https://www.gnu.org/licenses/>. ~ this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<stapps-section [title]="'name' | translateSimple: item"> <stapps-section [title]="'name' | translateSimple: item()">
@if (item.authProvider) { @if (item().authProvider) {
<ion-button slot="button-end" fill="clear" color="dark" (click)="toggleLogIn()"> <ion-button slot="button-end" fill="clear" color="dark" (click)="toggleLogIn()">
@if (isLoggedIn) { @if (loggedIn()) {
<ion-icon slot="end" name="logout"></ion-icon> <ion-icon slot="end" name="logout"></ion-icon>
} @else { } @else {
<ion-icon slot="end" name="login"></ion-icon> <ion-icon slot="end" name="login"></ion-icon>
} }
<ion-label>{{ 'profile.buttons.default.log_' + (isLoggedIn ? 'out' : 'in') | translate }}</ion-label> <ion-label>{{ 'profile.buttons.default.log_' + (loggedIn() ? 'out' : 'in') | translate }}</ion-label>
</ion-button> </ion-button>
} }
<simple-swiper> <simple-swiper>
@for (link of item.links; track link) { @for (link of item().links; track link) {
<ion-item <ion-item
lines="none" lines="none"
[routerLink]="link.link" [routerLink]="link.link"
[disabled]="link.needsAuth && !isLoggedIn" [disabled]="link.needsAuth && !loggedIn()"
[detail]="false" [detail]="false"
> >
<div> <div>

View File

@@ -425,8 +425,7 @@
"placeholder": "Veranstaltungen, Personen, Orte und mehr" "placeholder": "Veranstaltungen, Personen, Orte und mehr"
}, },
"instruction": "Finde alle Informationen rund ums Studium und den Campus", "instruction": "Finde alle Informationen rund ums Studium und den Campus",
"nothing_found": "Keine Ergebnisse", "nothing_found": "Keine Ergebnisse"
"SUGGESTIONS": "Meintest du"
}, },
"hebisSearch": { "hebisSearch": {
"title": "Bibliothekssuche", "title": "Bibliothekssuche",

View File

@@ -425,8 +425,7 @@
"placeholder": "Events, places, persons and more" "placeholder": "Events, places, persons and more"
}, },
"instruction": "Find all information related to your studies and campus", "instruction": "Find all information related to your studies and campus",
"nothing_found": "No results", "nothing_found": "No results"
"SUGGESTIONS": "Did you mean"
}, },
"hebisSearch": { "hebisSearch": {
"title": "Library Search", "title": "Library Search",

View File

@@ -18,7 +18,7 @@
// The list of which env maps to which file can be found in `.angular-cli.json`. // The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = { export const environment = {
backend_url: 'http://localhost:3000', backend_url: 'https://mobile.server.uni-frankfurt.de',
app_host: 'mobile.app.uni-frankfurt.de', app_host: 'mobile.app.uni-frankfurt.de',
custom_url_scheme: 'de.anyschool.app', custom_url_scheme: 'de.anyschool.app',
backend_version: '999.0.0', backend_version: '999.0.0',

View File

@@ -23,7 +23,7 @@ node ./lib/cli.js e2e http://localhost:3000
Example to clone the full database Example to clone the full database
```shell ```shell
node app.js copy "*" -a "999.0.0" https://mobile.server.uni-frankfurt.de http://localhost:3000 100 node app.js copy "*" https://mobile.app.uni-frankfurt.de http://localhost:3000 100
``` ```
### Program arguments ### Program arguments

View File

@@ -97,8 +97,6 @@
"date", "date",
"validatable", "validatable",
"filterable", "filterable",
"suggestable",
"completable",
"inheritTags", "inheritTags",
"minLength", "minLength",
"pattern", "pattern",

View File

@@ -24,11 +24,6 @@ export interface SCSearchResult {
*/ */
data: SCThings[]; data: SCThings[];
/**
* Suggestions for query corrections
*/
suggestions?: SCSearchSuggestions;
/** /**
* Facets (aggregations over all matching data) * Facets (aggregations over all matching data)
*/ */
@@ -45,18 +40,6 @@ export interface SCSearchResult {
stats: SCSearchResultSearchEngineStats; stats: SCSearchResultSearchEngineStats;
} }
/**
* Seach suggestions
*
* Not to be confused with search-as-you-type suggestions
*/
export interface SCSearchSuggestions {
/**
* Suggestions for query terms that might have been misspelled
*/
terms?: Record<string, string[]>;
}
/** /**
* Stores information about Pagination * Stores information about Pagination
*/ */

View File

@@ -63,7 +63,7 @@ export interface SCThingWithoutReferences {
/** /**
* Alternate names of the thing * Alternate names of the thing
* @filterable * @filterable
* @text * @keyword
*/ */
alternateNames?: string[]; alternateNames?: string[];
@@ -92,8 +92,6 @@ export interface SCThingWithoutReferences {
* @filterable * @filterable
* @minLength 1 * @minLength 1
* @sortable ducet * @sortable ducet
* @completable
* @suggestable
* @text * @text
*/ */
name: string; name: string;
@@ -242,8 +240,6 @@ export interface SCThingTranslatableProperties {
* Translation of the name of the thing * Translation of the name of the thing
* @sortable ducet * @sortable ducet
* @text * @text
* @suggestable
* @completable
*/ */
name?: string; name?: string;
/** /**

View File

@@ -43,27 +43,6 @@ export const fieldmap: ElasticsearchFieldmap = {
}, },
ignore: ['price'], ignore: ['price'],
}, },
suggestable: {
default: {
trigram: {
type: 'text',
analyzer: 'trigram',
},
reverse: {
type: 'text',
analyzer: 'reverse',
},
},
ignore: [],
},
completable: {
default: {
completion: {
type: 'search_as_you_type',
},
},
ignore: [],
},
}; };
export const filterableTagName = 'filterable'; export const filterableTagName = 'filterable';

View File

@@ -19,27 +19,4 @@ export const settings: IndicesPutTemplateRequest['settings'] = {
'max_result_window': 30_000, 'max_result_window': 30_000,
'number_of_replicas': 0, 'number_of_replicas': 0,
'number_of_shards': 1, 'number_of_shards': 1,
'index': {
analysis: {
analyzer: {
trigram: {
type: 'custom',
tokenizer: 'standard',
filter: ['lowercase', 'shingle'],
},
reverse: {
type: 'custom',
tokenizer: 'standard',
filter: ['lowercase', 'reverse'],
},
},
filter: {
shingle: {
type: 'shingle',
min_shingle_size: 2,
max_shingle_size: 3,
},
},
},
},
}; };

8
pnpm-lock.yaml generated
View File

@@ -837,8 +837,8 @@ importers:
specifier: 0.9.0 specifier: 0.9.0
version: 0.9.0(rxjs@7.8.1) version: 0.9.0(rxjs@7.8.1)
jsonpath-plus: jsonpath-plus:
specifier: 10.0.6 specifier: 10.0.7
version: 10.0.6 version: 10.0.7
maplibre-gl: maplibre-gl:
specifier: 4.0.2 specifier: 4.0.2
version: 4.0.2 version: 4.0.2
@@ -15039,8 +15039,8 @@ packages:
engines: {'0': node >= 0.2.0} engines: {'0': node >= 0.2.0}
dev: true dev: true
/jsonpath-plus@10.0.6: /jsonpath-plus@10.0.7:
resolution: {integrity: sha512-Q0KCash90S0WQnPnE/W0uVXQSww4NkO34COfs+gbq0fk+Kv03FYpZ+uU2I7soLLaS4d/ywsm9PxplZsTMmfBmg==} resolution: {integrity: sha512-GDA8d8fu9+s4QzAzo5LMGiLL/9YjecAX+ytlnqdeXYpU55qME57StDgaHt9R2pA7Dr8U31nwzxNJMJiHkrkRgw==}
engines: {node: '>=18.0.0'} engines: {node: '>=18.0.0'}
hasBin: true hasBin: true
dependencies: dependencies: