diff --git a/app/scripts/main/main-ctrl.ls b/app/scripts/main/main-ctrl.ls index b60682c..8357b8b 100644 --- a/app/scripts/main/main-ctrl.ls +++ b/app/scripts/main/main-ctrl.ls @@ -104,20 +104,46 @@ angular.module('app').controller('MainCtrl', ($scope, $http, toastr, $stateParam $scope.errorMessage = response.data $scope.showError = true canceler = null - !function updateGraphs - if (canceler?) then canceler.resolve! - canceler := $q.defer! - response <-! sparql.query($scope.sparqlEndpoint,''' - SELECT ?graphIRI (COUNT(*) AS ?triples) { + $scope.$watch('graphIRI', (newValue,oldValue) -> + if (!allGraphsFetched) then updateGraphs! + ) + graphQuery = ''' + SELECT DISTINCT ?graphIRI ?triples { + { { - GRAPH ?graphIRI { ?s ?p ?o } - } UNION { - ?s ?p ?o + SELECT (COUNT(*) AS ?triples) { + ?s ?p ?o + } + } + } UNION { + { + SELECT ?graphIRI (COUNT(*) AS ?triples) { + GRAPH ?graphIRI { } + FILTER STRSTARTS(STR(?graphIRI),"") + GRAPH ?graphIRI { ?s ?p ?o } + } + GROUP BY ?graphIRI + ORDER BY DESC(?triples) + } + } UNION { + { + SELECT ?graphIRI (COUNT(*) AS ?triples) { + GRAPH ?graphIRI { ?s ?p ?o } + } + GROUP BY ?graphIRI + ORDER BY DESC(?triples) } } - GROUP BY ?graphIRI - ''',{timeout: canceler.promise}).then(_,handleError) + } + LIMIT 500 + ''' + allGraphsFetched = true + !function updateGraphs + if (canceler?) then canceler.resolve! + canceler := $q.defer! + response <-! sparql.query($scope.sparqlEndpoint,graphQuery.replace("",$scope.graphIRI ? ""),{timeout: canceler.promise}).then(_) $scope.graphs = response.data.results.bindings + if ($scope.graphs.length<500) then allGraphsFetched := true else allGraphsFetched := false function getLineAfterPrefixes(data) pos = 0 i = 0