mirror of
https://github.com/bec-project/bec_atlas.git
synced 2025-07-13 22:51:49 +02:00
fix: fix updateUserData and patch
This commit is contained in:
@ -58,18 +58,26 @@ export class RemoteDataService {
|
|||||||
/**
|
/**
|
||||||
* Base method for making a PATCH request to the server
|
* Base method for making a PATCH request to the server
|
||||||
* @param path path to the endpoint
|
* @param path path to the endpoint
|
||||||
|
* @param paramId unique identifier for the resource
|
||||||
* @param payload payload to send
|
* @param payload payload to send
|
||||||
* @param headers additional headers
|
* @param headers additional headers
|
||||||
* @returns response from the server
|
* @returns response from the server
|
||||||
*/
|
*/
|
||||||
protected patch<T>(path: string, payload: any, headers: HttpHeaders) {
|
protected patch<T>(
|
||||||
return this.httpClient.patch<T>(
|
path: string,
|
||||||
this.serverSettings.getServerAddress() + path,
|
paramInput: Record<string, string>,
|
||||||
payload,
|
payload: any,
|
||||||
{
|
headers: HttpHeaders
|
||||||
headers,
|
) {
|
||||||
}
|
let param = Object.keys(paramInput);
|
||||||
);
|
let id = paramInput[param[0]];
|
||||||
|
let fullPath =
|
||||||
|
this.serverSettings.getServerAddress() + path + '?' + param[0] + '=' + id;
|
||||||
|
console.log('Full path', fullPath, 'payload', payload);
|
||||||
|
|
||||||
|
return this.httpClient.patch<T>(fullPath, payload, {
|
||||||
|
headers,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,8 +217,8 @@ export class ScanCountService extends RemoteDataService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for updating the user data for a scan
|
* Method for updating the user data for a scan
|
||||||
* @param scanId Unique identifier for the scan
|
* @param scanId Unique identifier for the scan, type string
|
||||||
* @param userData User data to update
|
* @param userData User data to update, type ScanUserData
|
||||||
* @returns response from the server
|
* @returns response from the server
|
||||||
* @throws HttpErrorResponse if the request fails
|
* @throws HttpErrorResponse if the request fails
|
||||||
* @throws TimeoutError if the request takes too long
|
* @throws TimeoutError if the request takes too long
|
||||||
@ -218,9 +226,11 @@ export class ScanCountService extends RemoteDataService {
|
|||||||
updateUserData(scanId: string, userData: ScanUserData) {
|
updateUserData(scanId: string, userData: ScanUserData) {
|
||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
|
||||||
return this.post<string>(
|
console.log('Updating user data', userData);
|
||||||
|
return this.patch<string>(
|
||||||
'scans/user_data',
|
'scans/user_data',
|
||||||
{ scan_id: scanId, ...userData },
|
{ scan_id: scanId },
|
||||||
|
userData,
|
||||||
headers
|
headers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
<!-- Table -->
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<mat-card>
|
<mat-card>
|
||||||
|
<!-- Toolbar -->
|
||||||
<mat-toolbar color="primary">
|
<mat-toolbar color="primary">
|
||||||
Table with Scan Data
|
Table with Scan Data
|
||||||
<span class="spacer"></span>
|
<span class="spacer"></span>
|
||||||
@ -12,39 +14,45 @@
|
|||||||
<button mat-icon-button (click)="openDialog()">
|
<button mat-icon-button (click)="openDialog()">
|
||||||
<mat-icon>settings</mat-icon>
|
<mat-icon>settings</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<!--
|
|
||||||
<mat-menu #menu="matMenu">
|
|
||||||
@for (column of availableColumns(); track column) {
|
|
||||||
<mat-checkbox class="checkbox" (change)="handleColumnSelection(column)">{{ column }}</mat-checkbox>
|
|
||||||
}
|
|
||||||
</mat-menu> -->
|
|
||||||
</mat-toolbar>
|
</mat-toolbar>
|
||||||
<table mat-table *ngIf="tableData() as data" [dataSource]="data" class="mat-elevation-z8">
|
<!-- Table -->
|
||||||
|
<table mat-table *ngIf="tableData() as data" [dataSource]="data" class="mat-elevation-z8">
|
||||||
|
@for (column of displayedColumns(); track column) {
|
||||||
|
<ng-container [matColumnDef]="column">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{ column | titlecase }}</th>
|
||||||
|
<td mat-cell class="table-cell" *matCellDef="let element">
|
||||||
|
@if (column === 'timestamp') {
|
||||||
|
{{ element[column] * 1000 | date :'HH:mm:ss'}}
|
||||||
|
<br>
|
||||||
|
{{ element[column] * 1000 | date :'dd/MM/yyyy'}}
|
||||||
|
}
|
||||||
|
@else if (column === 'user_rating') {
|
||||||
|
<star-rating
|
||||||
|
[starType]="'svg'"
|
||||||
|
[hoverEnabled]="true"
|
||||||
|
(ratingChange)="handleOnRatingChanged($event, element)"
|
||||||
|
[rating]="element[column]">
|
||||||
|
</star-rating>
|
||||||
|
}
|
||||||
|
@else if (column === 'user_comments') {
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<textarea matInput ></textarea>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
<!-- Create table data dynamically -->
|
}
|
||||||
<ng-container *ngFor="let column of displayedColumns()" [matColumnDef]="column">
|
@else{
|
||||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> {{ column | titlecase }} </th>
|
<p> {{ element[column] }}</p>
|
||||||
<td mat-cell *matCellDef="let element">
|
}
|
||||||
@if (column === 'timestamp') {
|
</ng-container>
|
||||||
{{ element[column] * 1000 | date :'HH:mm:ss'}}
|
}
|
||||||
<br>
|
<!-- Header Row -->
|
||||||
{{ element[column] * 1000 | date :'dd/MM/yyyy'}}
|
<tr mat-header-row *matHeaderRowDef="displayedColumns(); sticky: true"></tr>
|
||||||
}
|
<!-- Data Rows -->
|
||||||
@else if (column === 'user_rating') {
|
<tr mat-row *matRowDef="let row; columns: displayedColumns()"></tr>
|
||||||
<star-rating [starType]="'svg'" [rating]="element[column]"></star-rating>
|
|
||||||
}
|
|
||||||
@else{
|
|
||||||
<p> {{ element[column] }}</p>
|
|
||||||
}
|
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
<!-- Header Row -->
|
|
||||||
<tr mat-header-row *matHeaderRowDef="displayedColumns(); sticky: true"></tr>
|
|
||||||
<!-- Data Rows -->
|
|
||||||
<tr mat-row *matRowDef="let row; columns: displayedColumns()"></tr>
|
|
||||||
</table>
|
</table>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Paginator -->
|
||||||
<div class="table-paginator">
|
<div class="table-paginator">
|
||||||
<mat-paginator
|
<mat-paginator
|
||||||
#paginator
|
#paginator
|
||||||
|
@ -14,4 +14,26 @@
|
|||||||
|
|
||||||
.spacer {
|
.spacer {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.table-cell {
|
||||||
|
max-height: 200px
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
resize: none;
|
||||||
|
min-height: 32px; /* Initial height */
|
||||||
|
max-height: 200px; /* Maximum height */
|
||||||
|
overflow-y: auto; /* Enable scroll when max height is reached */
|
||||||
|
width: 100%;
|
||||||
|
padding:0px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-form-field {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.2;
|
||||||
|
padding-top: 16px;
|
||||||
|
max-height: var(max-height);
|
||||||
|
}
|
@ -29,6 +29,8 @@ import { MatMenuModule } from '@angular/material/menu';
|
|||||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { ColumnSelectionDialogComponent } from './column-selection-dialog/column-selection-dialog.component';
|
import { ColumnSelectionDialogComponent } from './column-selection-dialog/column-selection-dialog.component';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
|
||||||
export interface ResourceStatus {
|
export interface ResourceStatus {
|
||||||
status: any;
|
status: any;
|
||||||
@ -55,6 +57,8 @@ export interface ResourceLoaderParams {
|
|||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatInputModule,
|
||||||
],
|
],
|
||||||
templateUrl: './scan-table.component.html',
|
templateUrl: './scan-table.component.html',
|
||||||
styleUrl: './scan-table.component.scss',
|
styleUrl: './scan-table.component.scss',
|
||||||
@ -67,6 +71,7 @@ export class ScanTableComponent {
|
|||||||
sessionId = signal<string>('');
|
sessionId = signal<string>('');
|
||||||
dialog = inject(MatDialog);
|
dialog = inject(MatDialog);
|
||||||
pageEvent: PageEvent = new PageEvent();
|
pageEvent: PageEvent = new PageEvent();
|
||||||
|
isEditingUserComments: boolean = false;
|
||||||
sorting: number = -1;
|
sorting: number = -1;
|
||||||
displayedColumns = signal<string[]>([
|
displayedColumns = signal<string[]>([
|
||||||
'scan_number',
|
'scan_number',
|
||||||
@ -77,6 +82,7 @@ export class ScanTableComponent {
|
|||||||
'dataset_number',
|
'dataset_number',
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'user_rating',
|
'user_rating',
|
||||||
|
'user_comments',
|
||||||
]);
|
]);
|
||||||
allColumns: string[] = [
|
allColumns: string[] = [
|
||||||
'scan_id',
|
'scan_id',
|
||||||
@ -135,6 +141,7 @@ export class ScanTableComponent {
|
|||||||
? 'user_data'
|
? 'user_data'
|
||||||
: element
|
: element
|
||||||
);
|
);
|
||||||
|
columns.push('scan_id'); // always include scan_id
|
||||||
console.log('Columns', columns);
|
console.log('Columns', columns);
|
||||||
return firstValueFrom(
|
return firstValueFrom(
|
||||||
this.scanData.getScanData(
|
this.scanData.getScanData(
|
||||||
@ -227,4 +234,23 @@ export class ScanTableComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleColumnSelection(event: any) {}
|
handleColumnSelection(event: any) {}
|
||||||
|
|
||||||
|
toggleAllEdit() {}
|
||||||
|
|
||||||
|
async handleOnRatingChanged(event: any, element: ScanDataResponse) {
|
||||||
|
console.log('Event', event, 'Element', element);
|
||||||
|
let scanId = element.scan_id;
|
||||||
|
let userData = {
|
||||||
|
user_rating: event.rating,
|
||||||
|
user_comments: element.user_comments || '',
|
||||||
|
system_rating: element.system_rating || 0,
|
||||||
|
system_comments: element.system_comments || '',
|
||||||
|
name: element.name || '',
|
||||||
|
};
|
||||||
|
console.log('Scan ID', scanId);
|
||||||
|
if (scanId) {
|
||||||
|
console.log('Updating user data', userData);
|
||||||
|
await firstValueFrom(this.scanData.updateUserData(scanId, userData));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user