Commit d0244ee8 authored by Thibault Ehrhart's avatar Thibault Ehrhart

Fix schema selection

parent 0fadc3b8
......@@ -90,6 +90,7 @@ export class HomeComponent implements OnInit {
this.inDetailsView = val.urlAfterRedirects !== '/home';
}
});
this.selectedSchema = null;
}
ngOnInit() {
......@@ -135,31 +136,36 @@ export class HomeComponent implements OnInit {
// Schema
if (form.schema) {
let isNewSchema = false;
// Remove previous schema property form controls
if (this.selectedSchema) {
if (!this.selectedSchema) {
isNewSchema = true;
} else if (this.selectedSchema.id !== form.schema) {
isNewSchema = true;
this.selectedSchema.data.properties.forEach((prop: any) => {
this.formGroupSearch.removeControl('schema_property_' + prop.property_ID);
this.formGroupSearch.removeControl('schema_property_' + prop.property_ID);
});
}
// Set new active schema
this.selectedSchema = this.schemas.filter(schema => {
return schema.id === form.schema;
}).pop();
if (this.schemas.length > 0) {
this.selectedSchema = this.schemas.filter(schema => {
return schema.id === form.schema;
}).pop();
}
// Add new schema property form controls
if (this.selectedSchema) {
if (this.selectedSchema && isNewSchema) {
this.selectedSchema.data.properties.forEach((prop: any) => {
this.formGroupSearch.addControl('schema_property_' + prop.property_ID, new FormControl(''));
});
}
} else {
} else if (this.selectedSchema) {
// 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.data.properties.forEach((prop: any) => {
this.formGroupSearch.removeControl('schema_property_' + prop.property_ID);
});
this.selectedSchema = null;
}
......
......@@ -280,7 +280,9 @@ export class NewsService {
let schemaFilter = '';
if (context.schemaProperties) {
context.schemaProperties.forEach(prop => {
schemaFilter += `?s wdt:${prop.name} ${JSON.stringify(prop.value)} . `
if (prop.value.length > 0) {
schemaFilter += `?s wdt:${prop.name} ?wdt_${prop.name} . FILTER(?wdt_${prop.name} >= ${JSON.stringify(prop.value)}) `
}
})
}
......
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