Skip to content

Commit

Permalink
allow to display SPARQL queries next to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ali1k committed Feb 8, 2017
1 parent 86f99ef commit 27bc888
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 25 deletions.
21 changes: 15 additions & 6 deletions components/dataset/Dataset.js
Expand Up @@ -56,12 +56,21 @@ class Dataset extends React.Component {
return (
<div className="ui page grid" ref="dataset">
<div className="ui column">
<div className="ui segment top attached">
<h3>{this.props.total ? <a target="_blank" href={'/export/NTriples/' + encodeURIComponent(this.props.datasetURI)}><span className="ui big blue circular label">{this.state.searchMode ? this.addCommas(this.props.resources.length) + '/' :''}{this.addCommas(this.props.total)}</span></a> : ''} Resources of type {typeSt} in {datasetTitle ? datasetTitle : ' all local datasets'}</h3>
<ResourceList enableAuthentication={this.props.enableAuthentication} resources={this.props.resources} datasetURI={this.props.datasetURI} isBig={true} config={this.props.config} onCloneResource={this.props.onCloneResource}/>
</div>
<div className= "ui secondary segment bottom attached">
<ResourceListPager onSearchMode={this.handleSearchMode.bind(this)} datasetURI={this.props.datasetURI} visibleResourcesTotal={this.props.resources.length} total={this.props.total} threshold={10} currentPage={this.props.page} maxNumberOfResourcesOnPage={this.props.config.maxNumberOfResourcesOnPage}/>
<h3 className="ui header">
{this.props.total ? <a target="_blank" href={'/export/NTriples/' + encodeURIComponent(this.props.datasetURI)}><span className="ui big blue circular label">{this.state.searchMode ? this.addCommas(this.props.resources.length) + '/' :''}{this.addCommas(this.props.total)}</span></a> : ''} Resources of type {typeSt} in {datasetTitle ? datasetTitle : ' all local datasets'}
</h3>
<div className="ui segments">
<div className="ui segment">
<ResourceList enableAuthentication={this.props.enableAuthentication} resources={this.props.resources} datasetURI={this.props.datasetURI} isBig={true} config={this.props.config} onCloneResource={this.props.onCloneResource}/>
</div>
<div className="ui secondary segment">
<ResourceListPager onSearchMode={this.handleSearchMode.bind(this)} datasetURI={this.props.datasetURI} visibleResourcesTotal={this.props.resources.length} total={this.props.total} threshold={10} currentPage={this.props.page} maxNumberOfResourcesOnPage={this.props.config.maxNumberOfResourcesOnPage}/>
</div>
{this.props.config && this.props.config.displayQueries ?
<div className= "ui tertiary segment">
{this.props.resourceQuery}
</div>
: ''}
</div>
<div className= "ui bottom attached">
{createResourceDIV}
Expand Down
17 changes: 12 additions & 5 deletions components/dataset/FacetedBrowser.js
Expand Up @@ -277,11 +277,18 @@ class FacetedBrowser extends React.Component {
<h3 className="ui header">
{this.props.FacetedBrowserStore.total ? <a target="_blank" href={'/export/NTriples/' + encodeURIComponent(this.props.FacetedBrowserStore.datasetURI)}><span className="ui blue circular label">{this.state.searchMode ? this.addCommas(this.props.FacetedBrowserStore.resources.length) + '/' :''}{this.addCommas(this.props.FacetedBrowserStore.total)}</span></a> : ''} Resources {typeSt ? <span>of type{typeSt}</span>: ''} from {datasetTitle}
</h3>
<div className="ui segment top attached">
<ResourceList resources={this.props.FacetedBrowserStore.resources} datasetURI={this.props.FacetedBrowserStore.datasetURI} OpenInNewTab={true} isBig={!showFactes} config={dcnf}/>
</div>
<div className= "ui secondary segment bottom attached">
<ResourceListPager onSearchMode={this.handleSearchMode.bind(this)} visibleResourcesTotal={this.props.FacetedBrowserStore.resources.length} selection={{prevSelection: this.state.selection}} onExpandCollapse={this.toggleResourceCol.bind(this)} handleClick={this.gotoPage.bind(this)} datasetURI={this.props.FacetedBrowserStore.datasetURI} total={this.props.FacetedBrowserStore.total} threshold={pagerSize} currentPage={this.props.FacetedBrowserStore.page} maxNumberOfResourcesOnPage={dcnf.maxNumberOfResourcesOnPage}/>
<div className="ui segments">
<div className="ui segment">
<ResourceList resources={this.props.FacetedBrowserStore.resources} datasetURI={this.props.FacetedBrowserStore.datasetURI} OpenInNewTab={true} isBig={!showFactes} config={dcnf}/>
</div>
<div className= "ui secondary segment ">
<ResourceListPager onSearchMode={this.handleSearchMode.bind(this)} visibleResourcesTotal={this.props.FacetedBrowserStore.resources.length} selection={{prevSelection: this.state.selection}} onExpandCollapse={this.toggleResourceCol.bind(this)} handleClick={this.gotoPage.bind(this)} datasetURI={this.props.FacetedBrowserStore.datasetURI} total={this.props.FacetedBrowserStore.total} threshold={pagerSize} currentPage={this.props.FacetedBrowserStore.page} maxNumberOfResourcesOnPage={dcnf.maxNumberOfResourcesOnPage}/>
</div>
{dcnf.displayQueries ?
<div className= "ui tertiary segment">
{this.props.FacetedBrowserStore.resourceQuery}
</div>
: ''}
</div>
</div>;
}
Expand Down
5 changes: 3 additions & 2 deletions components/reactors/DatasetReactor.js
Expand Up @@ -40,14 +40,15 @@ class DatasetReactor extends React.Component {
let total = this.props.DatasetStore.dataset.total;
let isComplete = this.props.DatasetStore.isComplete;
let config = this.props.DatasetStore.dataset.config;
let resourceQuery = this.props.DatasetStore.dataset.resourceQuery;
let datasetReactor;
if(config && config.datasetReactor){
switch(config.datasetReactor[0]){
case 'Dataset':
datasetReactor = <Dataset enableAuthentication={enableAuthentication} datasetURI={datasetURI} resources={resources} page={page} total={total} config={this.configMinus(config, ['datasetReactor'])} onCloneResource={this.handleCloneResource.bind(this)} onCreateResource={this.handleCreateResource.bind(this)}/>;
datasetReactor = <Dataset enableAuthentication={enableAuthentication} datasetURI={datasetURI} resources={resources} page={page} total={total} config={this.configMinus(config, ['datasetReactor'])} resourceQuery={resourceQuery} onCloneResource={this.handleCloneResource.bind(this)} onCreateResource={this.handleCreateResource.bind(this)}/>;
break;
default:
datasetReactor = <Dataset enableAuthentication={enableAuthentication} datasetURI={datasetURI} resources={resources} page={page} total={total} config={this.configMinus(config, ['datasetReactor'])} onCloneResource={this.handleCloneResource.bind(this)} onCreateResource={this.handleCreateResource.bind(this)}/>;
datasetReactor = <Dataset enableAuthentication={enableAuthentication} datasetURI={datasetURI} resources={resources} page={page} total={total} config={this.configMinus(config, ['datasetReactor'])} resourceQuery={resourceQuery} onCloneResource={this.handleCloneResource.bind(this)} onCreateResource={this.handleCreateResource.bind(this)}/>;
}
}

Expand Down
1 change: 1 addition & 0 deletions data/autocompletes.js
Expand Up @@ -56,6 +56,7 @@ module.exports = {
{title: 'ldr:allowResourceNew'},
{title: 'ldr:allowPropertyNew'},
{title: 'ldr:allowNewValue'},
{title: 'ldr:displayQueries'},
{title: 'ldr:allowInlineConfig'},
{title: 'ldr:allowExtension'},
{title: 'ldr:hasBlankNode'},
Expand Down
13 changes: 7 additions & 6 deletions services/dataset.js
Expand Up @@ -13,7 +13,7 @@ const outputFormat = 'application/sparql-results+json';
const headers = {'Accept': 'application/sparql-results+json'};
let user;
/*-----------------------------------*/
let endpointParameters, datasetURI, dg, graphName, query, queryObject, utilObject, configurator, propertyURI;
let endpointParameters, datasetURI, dg, graphName, query, query2, queryObject, utilObject, configurator, propertyURI;
queryObject = new DatasetQuery();
utilObject = new DatasetUtil();
configurator = new Configurator();
Expand All @@ -27,7 +27,7 @@ export default {
//control access on authentication
if(enableAuthentication){
if(!req.user){
callback(null, {datasetURI: datasetURI, graphName: graphName, resources: [], page: params.page, config: rconfig});
callback(null, {datasetURI: datasetURI, graphName: graphName, resources: [], page: params.page, config: rconfig, resourceQuery: ''});
return 0;
}else{
user = req.user;
Expand All @@ -46,20 +46,21 @@ export default {
let page = params.page ? params.page : 1;
let offset = (page - 1) * maxOnPage;
let searchTerm = params.searchTerm ? params.searchTerm : '';
query = queryObject.getResourcesByType(endpointParameters, graphName, searchTerm,rconfig, maxOnPage, offset);
query2 = queryObject.getResourcesByType(endpointParameters, graphName, searchTerm,rconfig, maxOnPage, offset);
//build http uri
//send request
rp.get({uri: getHTTPGetURL(getHTTPQuery('read', query, endpointParameters, outputFormat)), headers: headers}).then(function(res){
rp.get({uri: getHTTPGetURL(getHTTPQuery('read', query2, endpointParameters, outputFormat)), headers: headers}).then(function(res){
callback(null, {
datasetURI: datasetURI,
graphName: graphName,
resources: utilObject.parseResourcesByType(user, res, datasetURI),
page: page,
config: rconfig
config: rconfig,
resourceQuery: query2
});
}).catch(function (err) {
console.log(err);
callback(null, {datasetURI: datasetURI, graphName: graphName, resources: [], page: page, config: rconfig});
callback(null, {datasetURI: datasetURI, graphName: graphName, resources: [], page: page, config: rconfig, resourceQuery: ''});
});
});
});
Expand Down
11 changes: 6 additions & 5 deletions services/facet.js
Expand Up @@ -108,7 +108,7 @@ export default {
//control access on authentication
if(enableAuthentication){
if(!req.user){
callback(null, {datasetURI: datasetURI, graphName: '', facets: {}, total: 0, page: 1});
callback(null, {datasetURI: datasetURI, graphName: '', facets: {}, total: 0, page: 1, resourceQuery: ''});
}else{
user = req.user;
}
Expand Down Expand Up @@ -138,23 +138,24 @@ export default {
//send request
rp.get({uri: getHTTPGetURL(getHTTPQuery('read', query, endpointParameters, outputFormat)), headers: headers}).then(function(res){
let query2 = queryObject.getSecondLevelPropertyValues(endpointParameters, graphName, searchTerm, rftconfig, params.selection.prevSelection, maxOnPage, page);
//console.log(query2);
//console.log(query2);
rp.get({uri: getHTTPGetURL(getHTTPQuery('read', query2, endpointParameters, outputFormat)), headers: headers}).then(function(res2){
callback(null, {
datasetURI: datasetURI,
graphName: graphName,
resourceFocusType: rftconfig.type,
page: page,
facets: {items: utilObject.parseSecondLevelPropertyValues(user, datasetURI, res2)},
total: utilObject.parseCountResourcesByType(res)
total: utilObject.parseCountResourcesByType(res),
resourceQuery: query2
});
}).catch(function (err2) {
console.log(err2);
callback(null, {datasetURI: datasetURI, graphName: graphName, facets: {}, total: 0, page: 1});
callback(null, {datasetURI: datasetURI, graphName: graphName, facets: {}, total: 0, page: 1, resourceQuery: query2});
});
}).catch(function (err) {
console.log(err);
callback(null, {datasetURI: datasetURI, graphName: graphName, facets: {}, total: 0, page: 1});
callback(null, {datasetURI: datasetURI, graphName: graphName, facets: {}, total: 0, page: 1, resourceQuery: ''});
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion stores/DatasetStore.js
Expand Up @@ -18,7 +18,8 @@ class DatasetStore extends BaseStore {
resources: payload.resources,
page: payload.page,
config: payload.config,
total: this.dataset.total
total: this.dataset.total,
resourceQuery: payload.resourceQuery
};
this.emitChange();
}
Expand Down
4 changes: 4 additions & 0 deletions stores/FacetedBrowserStore.js
Expand Up @@ -9,6 +9,7 @@ class FacetedBrowserStore extends BaseStore {
this.facets = {};
this.resources = [];
this.total = 0;
this.resourceQuery = '';
this.page = 1;
this.graphName = '';
this.datasetURI = '';
Expand Down Expand Up @@ -74,6 +75,7 @@ class FacetedBrowserStore extends BaseStore {
this.page = payload.page;
this.graphName = payload.graphName;
this.datasetURI = payload.datasetURI;
this.resourceQuery = payload.resourceQuery;
this.emitChange();
}
updateMasterFacets(payload) {
Expand Down Expand Up @@ -105,6 +107,7 @@ class FacetedBrowserStore extends BaseStore {
config: this.config,
resources: this.resources,
total: this.total,
resourceQuery: this.resourceQuery,
page: this.page
};
}
Expand All @@ -120,6 +123,7 @@ class FacetedBrowserStore extends BaseStore {
this.resources = state.resources;
this.total = state.total;
this.page = state.page;
this.resourceQuery = state.resourceQuery;
}
}

Expand Down

0 comments on commit 27bc888

Please sign in to comment.