diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/controller/SearchController.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/controller/SearchController.kt index fd35d6f..dbb3356 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/controller/SearchController.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/controller/SearchController.kt @@ -252,9 +252,6 @@ class SearchController( ) } - // Filter privileged fields - - val schema = SearchSchema(fields) return ResponseEntity.ok(schema) } @@ -269,7 +266,11 @@ class SearchController( var baseQuery = DSL.noCondition() for (query in request.queries.filter { it.predicates.isNotEmpty() }) { val condition = buildCondition(query) - baseQuery = baseQuery.and(condition) + baseQuery = when (query.logicalOperator.lowercase()) { + "and" -> baseQuery.and(condition) + "or" -> baseQuery.or(condition) + else -> throw IllegalArgumentException("Invalid logical operator") + } } val results = dslContext.select( @@ -473,6 +474,8 @@ class SearchController( "number" -> buildNumberCondition(field as Field, predicate.operator.operatorType, predicate.value.toDouble()) "string" -> buildStringCondition(field as Field, predicate.operator.operatorType, predicate.value) "boolean" -> buildBooleanCondition(field as Field, predicate.operator.operatorType, predicate.value.toBoolean()) + "flag" -> buildStringCondition(field as Field, predicate.operator.operatorType, predicate.value) + "grade" -> buildGradeCondition(field as Field, predicate.operator.operatorType, predicate.value) else -> throw IllegalArgumentException("Invalid field type") } } @@ -550,6 +553,24 @@ class SearchController( } } + private fun buildGradeCondition(field: Field, operator: String, value: String): Condition { + return when (value) { + "SS", "S", "A", "B", "C", "D" -> { + val valuesToMatch = when (value) { + "SS" -> listOf("Grade.SS", "Grade.SSH") + "S" -> listOf("Grade.S", "Grade.SH") + else -> listOf("Grade.$value") + } + when (operator) { + "=" -> field.`in`(valuesToMatch) + "!=" -> field.notIn(valuesToMatch) + else -> throw IllegalArgumentException("Invalid operator") + } + } + else -> throw IllegalArgumentException("Invalid grade value") + } + } + private fun buildNumberCondition(field: Field, operator: String, value: Double): Condition { return when (operator) { "=" -> field.eq(value) diff --git a/nise-frontend/src/app/app.component.html b/nise-frontend/src/app/app.component.html index fd4b692..a630f16 100644 --- a/nise-frontend/src/app/app.component.html +++ b/nise-frontend/src/app/app.component.html @@ -15,7 +15,7 @@
-
+
hi, {{this.userService.currentUser?.username}} Logout diff --git a/nise-frontend/src/app/search/search.component.html b/nise-frontend/src/app/search/search.component.html index d9c4f2f..0d1f7bf 100644 --- a/nise-frontend/src/app/search/search.component.html +++ b/nise-frontend/src/app/search/search.component.html @@ -1,142 +1,149 @@

/k/ - Advanced Search

-
- Table columns - -
- {{ category }} - -
- -
-
-
-
- -
- -
- -
- -
- sorting - - - - -
- -
- - - -
-
- -
- - +
-

Loading...

+

Loading schema...

+ +
+ Table columns + +
+ {{ category }} + +
+ +
+
+
+
-
-

Looks like something went wrong... :(

-

I'll look into what caused the error - but feel free to get in touch.

-
+
- - -
-

No results for your query - try different parameters.

+
+ +
+ +
+ sorting + + + + +
+ +
+ + + +
+
+ +
+ + +
+

Loading...

- -
- tools -
- - - -
-
-
- - - - - - - - - - - -
- {{ column.shortName }} -
- - {{ getValue(entry, column.name) | number }} - - - {{ countryCodeToFlag(getValue(entry, column.name)) }} - - - - - - - ✓ - - - ✗ - - - - {{ getValue(entry, column.name) }} - -
-
+
+

Looks like something went wrong... :(

+

I'll look into what caused the error - but feel free to get in touch.

+
-
-

Total results: {{ response.pagination.totalResults | number }}

-

Page: {{ response.pagination.currentPage | number }} / {{ response.pagination.totalPages | number }}

-
- - ... - - ... - + + +
+

No results for your query - try different parameters.

- - -
+ + + +
+ tools +
+ + + +
+
+
+ + + + + + + + + + + +
+ {{ column.shortName }} +
+ + {{ getValue(entry, column.name) | number }} + + + {{ countryCodeToFlag(getValue(entry, column.name)) }} + + + + + + + ✓ + + + ✗ + + + + {{ getValue(entry, column.name) }} + +
+
+ +
+

Total results: {{ response.pagination.totalResults | number }}

+

Page: {{ response.pagination.currentPage | number }} / {{ response.pagination.totalPages | number }}

+
+ + ... + + ... + +
+ + +
+
+ - - +
diff --git a/nise-frontend/src/app/search/search.component.ts b/nise-frontend/src/app/search/search.component.ts index 81c38bd..17d1ae4 100644 --- a/nise-frontend/src/app/search/search.component.ts +++ b/nise-frontend/src/app/search/search.component.ts @@ -102,6 +102,7 @@ export class SearchComponent implements OnInit { isError = false; isLoading = false; + isLoadingSchema = true; response: SearchResponse | null = null; fields: SchemaField[] = []; @@ -110,10 +111,12 @@ export class SearchComponent implements OnInit { queries: Query[] | null = null; ngOnInit(): void { + this.isLoadingSchema = true; this.httpClient.get(`${environment.apiUrl}/search`,).subscribe({ next: (response) => { this.fields = response.fields; this.loadPreviousFromLocalStorage(); + this.isLoadingSchema = false; }, error: () => { alert('Error fetching schema'); diff --git a/nise-frontend/src/corelib/components/query-builder/query-builder.component.ts b/nise-frontend/src/corelib/components/query-builder/query-builder.component.ts index 7403412..cd6a07a 100644 --- a/nise-frontend/src/corelib/components/query-builder/query-builder.component.ts +++ b/nise-frontend/src/corelib/components/query-builder/query-builder.component.ts @@ -5,7 +5,7 @@ import {QueryComponent} from "../query/query.component"; export type FieldType = 'number' | 'string' | 'flag' | 'grade' | 'boolean'; export type OperatorType = '=' | '>' | '<' | 'contains' | 'like' | '>=' | '<=' | '!='; -export type ValueType = 'any' | 'boolean'; +export type ValueType = 'any' | 'boolean' | 'flag' | 'grade'; export interface Field { name: string; diff --git a/nise-frontend/src/corelib/components/query/query.component.html b/nise-frontend/src/corelib/components/query/query.component.html index 1fc3caf..9aa5a8f 100644 --- a/nise-frontend/src/corelib/components/query/query.component.html +++ b/nise-frontend/src/corelib/components/query/query.component.html @@ -41,6 +41,276 @@
+ + + + + + + + + + + + + diff --git a/nise-frontend/src/corelib/components/query/query.component.ts b/nise-frontend/src/corelib/components/query/query.component.ts index 5d4644b..c967ade 100644 --- a/nise-frontend/src/corelib/components/query/query.component.ts +++ b/nise-frontend/src/corelib/components/query/query.component.ts @@ -1,5 +1,5 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; -import {Field, FieldType, Operator, OperatorType, Predicate, Query} from "../query-builder/query-builder.component"; +import {Field, FieldType, Operator, Predicate, Query} from "../query-builder/query-builder.component"; import {JsonPipe, NgForOf, NgIf} from "@angular/common"; import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import { v4 as uuidv4 } from 'uuid'; @@ -45,6 +45,12 @@ export class QueryComponent { case 'boolean': return ['=', '!='] .map((operatorType: String) => ({ operatorType: operatorType, acceptsValues: 'boolean'}) as Operator); + case 'flag': + return ['=', '!='] + .map((operatorType: String) => ({ operatorType: operatorType, acceptsValues: 'flag'}) as Operator); + case 'grade': + return ['=', '!='] + .map((operatorType: String) => ({ operatorType: operatorType, acceptsValues: 'grade'}) as Operator); default: return []; }