Load schemas from json file

parent a6e70c76
......@@ -15,33 +15,13 @@
</ng-select>
</div>
<div *ngIf="formGroupSearch.value.schema">
<div *ngIf="selectedSchema">
<div>Schema Properties</div>
<hr><br>
<div class="form-group">
<label>Number of injured</label>
<input type="text" class="form-control" placeholder="Enter a value">
</div>
<div class="form-group">
<label>Number of survivors</label>
<input type="text" class="form-control" placeholder="Enter a value">
</div>
<div class="form-group">
<label>Number of deaths</label>
<input type="text" class="form-control" placeholder="Enter a value">
</div>
<div class="form-group">
<label>Operator</label>
<input type="text" class="form-control" placeholder="Enter a value">
</div>
<div class="form-group">
<label>Aircraft registration</label>
<input type="text" class="form-control" placeholder="Enter a value">
</div>
<div class="form-group">
<label>Flight number</label>
<input type="text" class="form-control" placeholder="Enter a value">
<div class="form-group" *ngFor="let prop of selectedSchema.data.properties">
<label>{{ prop.property }}</label>
<input type="text" class="form-control" placeholder="Enter a value" [formControlName]="'schema_property_' + prop.property_ID">
</div>
</div>
......
......@@ -31,6 +31,7 @@ export class HomeComponent implements OnInit {
subjectCodes: NgOption[] = [];
locations: NgOption[] = [];
schemas: NgOption[] = [];
selectedSchema: any = null;
annotations: any = [{
id: 'http://adel.eurecom.fr/Stanford/Location',
label: 'Location',
......@@ -106,7 +107,19 @@ export class HomeComponent implements OnInit {
this.search.searchParams.subjects = form.selectedSubjectCodes;
this.search.searchParams.location = form.location ? form.location.trim() : null;
this.search.searchParams.keywords = form.keywords ? form.keywords.trim() : null;
this.search.searchParams.schema = form.schema ? form.schema : null;
this.search.searchParams.schemaProperties = [];
// Schema properties
if (form.schema) {
Object.keys(form).forEach(key => {
if (key.startsWith('schema_property_')) {
this.search.searchParams.schemaProperties.push({
name: key.substr('schema_property_'.length),
value: form[key]
});
}
});
}
this.search.searchParams.annotations = [];
this.annotations.forEach((annotation: any) => {
......@@ -115,6 +128,37 @@ export class HomeComponent implements OnInit {
}
});
// Schema
if (form.schema) {
// Remove previous schema property form controls
if (this.selectedSchema) {
this.selectedSchema.data.properties.forEach((prop: any) => {
this.formGroupSearch.removeControl('schema_property_' + prop.property_ID);
});
}
// Set new active schema
this.selectedSchema = this.schemas.filter(schema => {
return schema.id === form.schema;
}).pop();
// Add new schema property form controls
if (this.selectedSchema) {
this.selectedSchema.data.properties.forEach((prop: any) => {
this.formGroupSearch.addControl('schema_property_' + prop.property_ID, new FormControl(''));
});
}
} else {
// Remove previous schema property form controls
if (this.selectedSchema) {
this.selectedSchema.data.properties.forEach((prop: any) => {
this.formGroupSearch.removeControl('schema_property_' + prop.property_ID);
});
}
this.selectedSchema = null;
}
this.doSearch();
});
......@@ -135,11 +179,14 @@ export class HomeComponent implements OnInit {
});
});
// Define schemas
this.schemas = [{
id: 'aviation-accident',
label: 'Aviation accident'
}];
// Load schemas
this.newsService.getSchemas().subscribe((data: any) => {
this.schemas = Object.entries(data).map(s => {
return { id: s[0], label: s[0], data: s[1] };
}).sort((a: any, b: any) => {
return a.label.localeCompare(b.label);
});
});
// Load news from URL ID
this.sub = this.route.params.subscribe(params => {
......
......@@ -19,6 +19,7 @@ export interface NewsContext {
keywords?: string;
annotations?: Array<any>;
schema?: string;
schemaProperties?: Array<any>;
}
@Injectable()
......@@ -260,7 +261,12 @@ export class NewsService {
let keywordsFilter = context.keywords ? 'FILTER(CONTAINS(?description, ' + JSON.stringify(context.keywords) + ')) ' : '';
// Schema filter
let schemaFilter = context.schema ? '?s wdt:P1120 ?p1120 .' : '';
let schemaFilter = '';
if (context.schemaProperties) {
context.schemaProperties.forEach(prop => {
schemaFilter += `?s wdt:${prop.name} ${JSON.stringify(prop.value)} . `
})
}
// Annotations filter
let annotationsFilter = '';
......@@ -325,6 +331,10 @@ export class NewsService {
return this.http.get('assets/data/limsi/' + identifier.replace(/:/g, '_') + '.json');
}
getSchemas(): Observable<any> {
return this.http.get('assets/schemas.json');
}
static getAnnotationColor(annotationType: string) {
switch (annotationType) {
case 'http://adel.eurecom.fr/Stanford/Person':
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment