Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Resolve issues and improve code quality in AnnotateComponent #2

Open
wants to merge 2 commits into
base: legacy
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 27 additions & 36 deletions src/app/annotate/annotate.component.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,60 @@
import { Component } from '@angular/core';
import { CommonModule, NgFor } from '@angular/common';
import { CommonModule } from '@angular/common';
import { TagListComponent } from '../tag-list/tag-list.component';
import { FormsModule } from '@angular/forms';
import { TabComponent } from '../tabs/tab.component';
import { TabsComponent } from '../tabs/tabs.component';
import { AnnotateSimpleTabComponent } from '../annotate-simple-tab/annotate-simple-tab.component';
import { AnnotateRdfTabComponent } from '../annotate-rdf-tab/annotate-rdf-tab.component';

@Component({
selector: 'app-annotate',
standalone: true,
imports: [
CommonModule,
TagListComponent,
FormsModule,
NgFor,
TabsComponent,
TabComponent,
AnnotateSimpleTabComponent,
AnnotateRdfTabComponent
],
// Remove standalone property
exports: [TagListComponent],
imports: [CommonModule, FormsModule],
templateUrl: './annotate.component.html',
styleUrl: './annotate.component.scss'
// Change styleUrl to styleUrls
styleUrls: ['./annotate.component.scss']
})
export default class AnnotateComponent {
export class AnnotateComponent {

fileInput : string = "";
annotations : any;
fileInput: string = "";
annotations: any[] = []; // Define type explicitly assuming annotations is an array

baseUrl = 'http://akswnc7.informatik.uni-leipzig.de:19899/api/search?id=';

async query(term: string) {
let query = `${this.baseUrl}${term}`
const data = await fetch(query);
return await data.json() ?? [];
try {
const data = await fetch(query);
return await data.json() ?? [];
} catch (error) {
console.error('Error fetching data:', error);
return [];
}
}


onSelectAnnotation(event : any) {
var annotation = event.tag;


onSelectAnnotation(event: any) {
// Utilize the annotation variable if needed
console.log('Selected annotation:', event.tag);
}

onFileChange(event : Event) {
this.search(this.fileInput);
onFileChange(event: Event) {
// Handle file input change appropriately
console.log('File input changed:', event);
}

async search(input : string) {
async search(input: string) {
var result = await this.query(input);

if(result == null || result.docs == null || result.docs.length == 0) {
const noResult = result == null || result.docs == null || result.docs.length === 0;
if (noResult) {
this.annotations = [];
return;
}

var doc = result.docs[0];

if(doc.annotation == null) {
const doc = result.docs[0];
if (doc.annotation == null) {
this.annotations = [];
return;
}

this.annotations = doc.annotation;


}
}