PageRenderTime 345ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/facete-client/src/main/webapp/resources/js/org/aksw/qa-dashboard/app/controllers/AppController.js

https://github.com/GeoKnow/Facete
JavaScript | 958 lines | 370 code | 319 blank | 269 comment | 11 complexity | 5f9bc227caba223c909a395daaf6b2c4 MD5 | raw file
  1. (function($) {
  2. /**
  3. * TODO: Create sliders for numeric values:
  4. * rangeDefinition = {
  5. * defined: {min: 0, max: 1}, // The defined range for the property
  6. * dataset: {min: 0.1, max: 0.5}, // The range for the current dataset
  7. * context: {min: 0.5, max: 0.6}, // The range considering the context of the current facet constraints
  8. * }
  9. *
  10. * TODO: We have the focus and the navigation path, but we need to separate: the resources to return, and the facets to filter
  11. *
  12. */
  13. /*
  14. * Disable Backbone sync
  15. */
  16. Backbone.sync = function(method, model, options) {
  17. options.success();
  18. };
  19. var sparql = Namespace("org.aksw.ssb.sparql.syntax");
  20. var facets = Namespace("org.aksw.ssb.facets");
  21. var qt = Namespace("org.aksw.ssb.collections.QuadTree");
  22. var qtm = Namespace("org.aksw.ssb.collections.QuadTreeModel");
  23. var qtc = Namespace("org.aksw.ssb.collections.QuadTreeCache");
  24. var geo = Namespace("org.aksw.ssb.vocabs.wgs84");
  25. var geovocab = Namespace("org.aksw.ssb.vocabs.geovocab");
  26. var appvocab = Namespace("org.aksw.ssb.vocabs.appvocab");
  27. var rdf = Namespace("org.aksw.ssb.vocabs.rdf");
  28. var rdfs = Namespace("org.aksw.ssb.vocabs.rdfs");
  29. var backboneUtils = Namespace("org.aksw.utils.backbone");
  30. var labelUtils = Namespace("org.aksw.ssb.utils");
  31. var queryUtils = Namespace("org.aksw.ssb.facets.QueryUtils");
  32. var facetbox = Namespace("org.aksw.ssb.widgets.facetbox");
  33. var widgets = Namespace("org.aksw.ssb.widgets");
  34. var collections = Namespace("org.aksw.ssb.collections");
  35. var config = Namespace("org.aksw.ssb.config");
  36. var charts = Namespace("org.aksw.qa-dashboard.charts");
  37. var chartUtils = Namespace("org.aksw.utils.charts");
  38. var ns = Namespace("org.aksw.qa-dashboard.app.controllers");
  39. /**
  40. * A view which supports changing the renderer of a collection,
  41. * such as switching between a thumbnail and list view.
  42. *
  43. * TODO Switching between views may change the "itemsPerPage" constant.
  44. *
  45. * NOT WORKING YET
  46. *
  47. */
  48. ns.MetaView = Backbone.View.extend({
  49. tagName: 'li',
  50. attributes: {style: 'float: left'},
  51. events: {
  52. // 'click span.swap': 'swap',
  53. // 'click span.delete': 'remove'
  54. },
  55. initialize: function() {
  56. _.bindAll(this, 'render', 'unrender', 'remove'); // every function that uses 'this' as the current object should be in here
  57. this.model.bind('change', this.render, this);
  58. this.model.bind('remove', this.unrender, this);
  59. },
  60. render: function(){
  61. //html = '<span style="color:black;">' + JSON.stringify(this.model.attributes) + '</span>';
  62. // var precision = parseFloat(this.model.get("precision").value);
  63. // var recall = parseFloat(this.model.get("recall").value);
  64. var data = {
  65. name: this.model.get("projectName"),
  66. author: this.model.get("authorName"),
  67. precision: parseFloat(this.model.get("precision").value),
  68. recall: parseFloat(this.model.get("recall").value)
  69. };
  70. var chartSpec = charts.createLinksetChartSpec(data);
  71. var imgUrl = chartUtils.chartToImage(chartSpec, 300, 200);
  72. var html =
  73. '<div style="float: left; margin: 5px">' +
  74. ' <a href="#">' +
  75. ' <img src="' + imgUrl + '" /><br />' +
  76. ' <div class="warning-icon-tiny" /> x 4' + //'<div style="clear:both; float:left;" />' +
  77. ' <div class="error-icon-tiny" /> x 5' +
  78. ' </a>' +
  79. '</div>';
  80. //html = '<span style="color:black;">' + precision + " " + recall + '</span>';
  81. $(this.el).html(html);
  82. return this;
  83. },
  84. unrender: function() {
  85. $(this.el).remove();
  86. },
  87. remove: function(){
  88. this.model.destroy();
  89. }
  90. });
  91. /**
  92. *
  93. * @param fnPromise A function that returns a promise that upon completion return the new state
  94. */
  95. /*
  96. ns.slaveCollection = function(masterCollection, slaveCollection, fnPromise) {
  97. masterCollection.on("add", function(model) {
  98. var clone = jQuery.extend(true, {}, model.attributes);
  99. var promise = fnPromise(clone);
  100. $.when(promise).done(function(newState) {
  101. // TODO Treat request order properly
  102. slaveCollection.add(newState);
  103. //var newState = fn(model.attributes);
  104. });
  105. });
  106. masterCollection.on("remove", function(model) {
  107. // TODO Delete by id AND/OR cid
  108. slaveCollection.remove(model.id);
  109. });
  110. };
  111. */
  112. /* Now in ListWidgetBase
  113. ns.ItemRendererBackbone = function(viewCtor) {
  114. this.viewCtor = viewCtor;
  115. };
  116. ns.ItemRendererBackbone.prototype.create = function(model, parent) {
  117. var view = new this.viewCtor({model: model});
  118. return view.render().el;
  119. };
  120. */
  121. ns.ConstraintModel = Backbone.Model.extend({
  122. defaults: {
  123. value: null,
  124. /*label: "" // FIXME As there could be many ways for crafting constraint labels,
  125. //associating a label only makes sense for view-models;*/
  126. }
  127. });
  128. ns.ConstraintCollection = Backbone.Collection.extend({
  129. model: ns.ConstraintModel
  130. });
  131. ns.ItemViewLinksetThumbnail = Backbone.View.extend({
  132. tagName: 'li',
  133. attributes: {style: 'float: left'},
  134. events: {
  135. // 'click a':
  136. // 'click span.swap': 'swap',
  137. // 'click span.delete': 'remove'
  138. },
  139. initialize: function(){
  140. _.bindAll(this, 'render', 'unrender', 'remove'); // every function that uses 'this' as the current object should be in here
  141. this.model.bind('change', this.render, this);
  142. this.model.bind('remove', this.unrender, this);
  143. },
  144. render: function(){
  145. //html = '<span style="color:black;">' + JSON.stringify(this.model.attributes) + '</span>';
  146. // var precision = parseFloat(this.model.get("precision").value);
  147. // var recall = parseFloat(this.model.get("recall").value);
  148. var data = {
  149. name: this.model.get("projectName"),
  150. author: this.model.get("authorName"),
  151. precision: parseFloat(this.model.get("precision").value),
  152. recall: parseFloat(this.model.get("recall").value)
  153. };
  154. var chartSpec = charts.createLinksetChartSpec(data);
  155. var imgUrl = chartUtils.chartToImage(chartSpec, 300, 200);
  156. var html =
  157. '<div style="float: left; margin: 5px">' +
  158. ' <a href="#">' +
  159. ' <img src="' + imgUrl + '" /><br />' +
  160. ' <div class="warning-icon-tiny" /> x 4' + //'<div style="clear:both; float:left;" />' +
  161. ' <div class="error-icon-tiny" /> x 5' +
  162. ' </a>' +
  163. '</div>';
  164. //html = '<span style="color:black;">' + precision + " " + recall + '</span>';
  165. $(this.el).html(html);
  166. return this;
  167. },
  168. unrender: function() {
  169. $(this.el).remove();
  170. },
  171. remove: function(){
  172. this.model.destroy();
  173. }
  174. });
  175. ns.AppController = function(options) {
  176. this.sparqlService = options.sparqlService;
  177. this.labelFetcher = new labelUtils.LabelFetcher(this.sparqlService);
  178. };
  179. ns.AppController.prototype.run = function() {
  180. this.loadDatasetWidget();
  181. };
  182. /**
  183. *
  184. */
  185. ns.LinksetPreviewRenderer = function() {
  186. };
  187. ns.instanciateJson = function(resultSet, template) {
  188. };
  189. /*
  190. ns.getLabel = function(uri, labelInfo) {
  191. var label = labelInfo.uriToLabel[uri.value];
  192. var result = label ? label.value : "" + uri;
  193. return result;
  194. };
  195. */
  196. ns.AppController.prototype.loadDatasetWidget = function() {
  197. /*
  198. Actually, sparql-json bindings would be nice
  199. var jsonTemplate {
  200. evaluations: [{}]
  201. posEstPrecLow: new facets.Path.fromString("http://qa.linkeddata.org/ontology/assessment http://qa.linkeddata.org/ontology/posEstPrecLow")
  202. }
  203. */
  204. /*
  205. var jsonTemplate = {
  206. id: 'http://qa.linkeddata.org/ontology/assessment',
  207. precision: {
  208. collection: 'array',
  209. //types: 'double',
  210. value: 'http://qa.linkeddata.org/ontology/assessment http://qa.linkeddata.org/ontology/posEstPrecLow',
  211. },
  212. recall: 'http://qa.linkeddata.org/ontology/assessment http://qa.linkeddata.org/ontology/posRec'
  213. };
  214. */
  215. var self = this;
  216. this.itemsPerPage = 8;
  217. // Resource search
  218. {
  219. var conceptVar = sparql.Node.v("c");
  220. var conceptElement = new sparql.ElementTriplesBlock([new sparql.Triple(conceptVar, rdf.type, sparql.Node.uri("http://qa.linkeddata.org/ontology/Project"))]);
  221. //var conceptElement = queryUtils.createElementAnyResource(conceptVar);
  222. var concept = new facets.ConceptInt(conceptElement, conceptVar);
  223. this.queryGenerator = new widgets.QueryGenerator(concept);
  224. var queryProjector = new widgets.QueryProjector(this.queryGenerator);
  225. this.queryGeneratorFacets = new widgets.QueryGenerator(concept);
  226. this.queryGeneratorFacets.setNavigationPath(facets.Path.fromString("http://qa.linkeddata.org/ontology/assessment"));
  227. var q = this.queryGeneratorFacets.createQueryValues();
  228. console.log("Query " + q);
  229. queryProjector.addPath(new facets.Path(), sparql.Node.v('project'));
  230. queryProjector.addPath(new facets.Path.fromString("http://qa.linkeddata.org/ontology/assessment http://qa.linkeddata.org/ontology/posEstPrecLow"), sparql.Node.v('precision'));
  231. queryProjector.addPath(new facets.Path.fromString("http://qa.linkeddata.org/ontology/assessment http://qa.linkeddata.org/ontology/posRec"), sparql.Node.v('recall'));
  232. queryProjector.addPath(new facets.Path.fromString("http://qa.linkeddata.org/ontology/linkset http://purl.org/dc/terms/creator"), sparql.Node.v('author'));
  233. $("#search").on("change", function(event, value) {
  234. var text = $("#search").val();
  235. //console.log(event);
  236. //alert("text " + value);
  237. });
  238. //var q = queryProjector.createQueryRows();
  239. //alert(q.toString());
  240. /*
  241. * Create a model for the paginator.
  242. */
  243. this.paginatorModel = new widgets.PaginatorModel({maxSlotCount: 15});
  244. this.executor = new widgets.TableQueryExecutor(this.sparqlService, queryProjector);
  245. var viewModel = new widgets.TableModelExecutor(this.executor, this.itemsPerPage);
  246. //var viewModel = new widgets.TableQueryExecutor(this.executor, queryPro);
  247. /*
  248. this.syncer = new backboneUtils.BackboneSyncQueryCollection([], {
  249. sparqlService: this.sparqlService,
  250. //postProcessor: backboneUtils.createDefaultPostProcessor(this.labelFetcher)
  251. });
  252. */
  253. //this.syncer = new widgets.TableModelBackboneSync(this.executor);
  254. this.syncer = new widgets.TableModelBackboneSync(viewModel); //this.viemModel);
  255. var collection = this.syncer.getCollection();
  256. var viewCollection = new Backbone.Collection();
  257. // Bind the viewCollection so that author and project uri are resolved
  258. backboneUtils.slaveCollection(collection, viewCollection, function(data) {
  259. //console.log("Slave data", data);
  260. var projectUri = data["project"];
  261. var authorUri = data["author"];
  262. var uriStrs = [projectUri.value, authorUri.value];
  263. var promise = self.labelFetcher.fetch(uriStrs).pipe(function(labelInfo) {
  264. data.projectName = ns.getLabel(projectUri, labelInfo);
  265. data.authorName = ns.getLabel(authorUri, labelInfo);
  266. return data;
  267. });
  268. return promise;
  269. });
  270. /**
  271. * Clicking a thumbnail shows the detail page.
  272. *
  273. */
  274. var CustomLinksetThumbnail = ns.ItemViewLinksetThumbnail.extend({
  275. events: {
  276. 'click a': function(event) {
  277. //event.preventDefault();
  278. var projectUri = this.model.get("project");
  279. self.showDetailPage(projectUri.value);
  280. }
  281. }
  282. });
  283. var listView = new widgets.ListView({
  284. el: $("#list"),
  285. attributes: {style: {'list-style': 'none'}},
  286. collection: viewCollection,
  287. itemRenderer: new widgets.ItemRendererBackbone(CustomLinksetThumbnail)
  288. });
  289. $.when(this.executor.fetchCountRows()).then(function(countInfo) {
  290. var pageCount = parseInt(countInfo.count / self.itemsPerPage + 0.5);
  291. self.paginatorModel.set({pageCount: pageCount});
  292. });
  293. this.paginatorModel.bind('change', function(model) {
  294. var currentPage = model.get("currentPage");
  295. var offset = self.itemsPerPage * (currentPage - 1);
  296. console.log("Set offset", offset, self.itemsPerPage, model);
  297. viewModel.setOffset(offset);
  298. //console.log("This is myself:", self);
  299. self.syncer.sync();
  300. var executor = new widgets.QueryExecutor(self.sparqlService, self.queryGeneratorFacets);
  301. self.updateFacets(executor, self.facetBox);
  302. });
  303. // self.executor = new widgets.QueryExecutor(self.sparqlService, queryGenerator);
  304. // self.updateFacets();
  305. console.log("PaginatorModel is: ", this.paginatorModel);
  306. var paginator = new widgets.ViewPaginator({el: null, model: this.paginatorModel});//$$(widgets.Paginator); //widgets.createPaginatorWidget(5);
  307. $(paginator).bind('change-page', function(event, pageRequest) {
  308. if(pageRequest == -1) {
  309. var userInput = window.prompt("Jump to page:", "");
  310. pageRequest = parseInt(userInput);
  311. }
  312. console.log('changeRequest', pageRequest);
  313. self.paginatorModel.set({currentPage: pageRequest});
  314. });
  315. $("#list-paginator").append(paginator.render().el);
  316. /*
  317. * Facets
  318. */
  319. this.constraintSelections = new widgets.SelectionCollection();
  320. /**
  321. * TODO Make this constraint collection an extension of a backbone collection with some convenience methods
  322. *
  323. */
  324. this.constraints = new ns.ConstraintCollection();
  325. var constraintItemRenderer = new widgets.RendererItemView(
  326. this.constraintSelections,
  327. null,
  328. widgets.ItemViewLabel, {
  329. label: "simpleLabel"
  330. }
  331. );
  332. this.constraintWidget = new widgets.ListView({
  333. el: $("#ssb-constraints"),
  334. collection: this.constraints,
  335. itemRenderer: constraintItemRenderer
  336. });
  337. this.constraintWidget.render();
  338. $(this.constraintWidget).bind("click", function(ev, payload) {
  339. var id = payload.model.get("id");
  340. self.constraints.remove(id);
  341. });
  342. //$("#ssb-constraints").append(this.constraintWidget.render().el);
  343. // Fetch labels
  344. var constraintTextBuilder = new widgets.ConstraintTextBuilder(this.labelFetcher);
  345. this.constraints.bind("add", function(model) {
  346. constraint = model.get("value");
  347. var task = constraintTextBuilder.fetchSimpleText(constraint);
  348. $.when(task).then(function(labelStr) {
  349. model.set({simpleLabel: labelStr});
  350. }).fail(function() {
  351. console.error("Error fetching label for model: ", model);
  352. //alert("Error fetching label for " + model.get("id"));
  353. });
  354. });
  355. this.constraints.bind("add", function(model) {
  356. var id = model.id;
  357. self.constraintSelections.add(new widgets.SelectionModel({id: id, isSelected: true}));
  358. self.updateConstraints();
  359. });
  360. this.constraints.bind("remove", function(model) {
  361. var id = model.id;
  362. var model = self.constraintSelections.get(id);
  363. if(model) {
  364. model.destroy();
  365. }
  366. self.updateConstraints();
  367. });
  368. this.facetBox = facetbox.createFacetBox(this.constraintSelections); //tmpSelMod); //this.constraintSelections);
  369. this.facetBox.view.$().autoHeight();
  370. /**
  371. * This is the callback when the values of a facet should be displayed.
  372. *
  373. */
  374. this.facetBox.bind("clickFacetValues", function(ev, payload) {
  375. //console.log("PAYLOAD", payload.model);
  376. var path = payload.model.get("path");
  377. var queryGeneratorTmp = self.queryGeneratorFacets.navigateToPath(path);
  378. var queryGenerator = queryGeneratorTmp.copyExcludeConstraint(path);
  379. //var relativePath = payload.model.get("path");
  380. //var basePath = self.queryGeneratorGeo.getNavigationPath();
  381. //var path = basePath.concat(relativePath);
  382. var widget = payload;
  383. var executor = new widgets.QueryExecutor(self.sparqlService, queryGenerator);
  384. /*
  385. $.when(executor.fetchValues()).then(function(r) {
  386. console.log("Fetched someting", r);
  387. });
  388. */
  389. widget = payload.getFacetValues();
  390. //console.log("Widget is", widget);
  391. //var viewModel = new widgets.ListModelExecutor(executor, 50);
  392. widget.setLabelFetcher(self.labelFetcher);
  393. widget.getModel().limit = self.itemsPerPage;
  394. widget.getModel().setExecutor(executor);
  395. widget.refresh();
  396. });
  397. this.facetBox.bind("clickConstraint", function(ev, payload) {
  398. /* What exactly should this method do?
  399. * a) Return a specification on what do display as the facet values
  400. * { type: checklist, executor: executor } or { type:dualslider, executor: executor }
  401. *
  402. * b) A widget to use as in the facet value area
  403. * payload.area.set(new SparqlListWidget(executor)))
  404. */
  405. var path = payload.path;
  406. //console.log("payload", payload.item);
  407. var item = payload.item;
  408. var facetValue = item.model.get("data").data;
  409. //console.log("facetValue", facetValue);
  410. var constraints = self.queryGeneratorFacets.getConstraints();
  411. //var constraints = self.constraints;
  412. //console.log("path is", path);
  413. var constraint =
  414. new facets.PathConstraint(path,
  415. new facets.ConstraintEquals(new sparql.NodeValue(facetValue)));
  416. //var xxxx = constraint.createConstraintElement(self.queryGenerator.pathManager);
  417. //alert(xxxx.getExpr());
  418. var id = "" + constraint;
  419. //console.log("ConstraintID" + id);
  420. var model = new ns.ConstraintModel({id: id, value: constraint});
  421. //console.log("Setting constraint", constraint);
  422. //var isEnabled = !this.model.get("isEnabled");
  423. // console.log("Enabled:", isEnabled, id);
  424. if (item.isSelected()) {
  425. //alert("boo");
  426. //constraints.add(constraint);
  427. self.constraints.add(model);
  428. } else {
  429. self.constraints.remove(id);
  430. //constraints.remove(constraint);
  431. }
  432. //alert("Constraints", self.constraints);
  433. });
  434. this.facetBox.bind("pivot", function(ev, payload) {
  435. //console.log(payload.model.get("data"));
  436. var path = payload.model.get("data").path;
  437. var currentPath = self.executor.getNavigationPath();
  438. //this.queryGeneratorGeo.setNavigationPath(path);
  439. if(!currentPath) {
  440. currentPath = new facets.Path();
  441. }
  442. var concat = currentPath.concat(path);
  443. //alert("" + path);
  444. self.setNavigationPath(concat);
  445. //alert("Pivot");
  446. });
  447. //facetbox.createFacetBox();
  448. //this.facetbox = facetbox.createFacetBox(this.facetConfig, queryGenerator, basePath, facetBoxBackend, callbacks);
  449. //$('#tabs a:eq(3)').tab('show');
  450. $$.document.append(this.facetBox, "#facets");
  451. //this.setPaginator(paginator);
  452. //$$.document.append(paginator, );
  453. //paginator.refresh();
  454. //console.log("List el", listView.el);
  455. //$('#list').append(listView.el);
  456. /*
  457. var task = viewModel.fetchData();
  458. $.when(task).then(function(data) {
  459. alert("yay:" + data);
  460. }).fail(function() {
  461. console.error("Fail!");
  462. });
  463. */
  464. /*
  465. var renderer = new widgets.RendererString(function(binding, metadata) { return "test" + binding; }, {label: function(data) { return "" + data.label; }
  466. });
  467. var executorController = new widgets.TableExecutorController(renderer);
  468. */
  469. /*
  470. var executorWidget = new widgets.ExecutorListWidget(viewModel, renderer, this.labelFetcher);
  471. executorWidget.getView().getListWidget().bind("click", function(ev, payload) {
  472. /*
  473. var node = payload.data.data;
  474. self.showDescription([node]);
  475. * /
  476. //$("#box-facts").show();
  477. //console.log("payload", payload);
  478. /*
  479. alert("yay");
  480. var data = payload.item.model.get("data").data;
  481. if(payload.checked) {
  482. self.classSelectionModel[data] = {data: data, isSelected: true};
  483. } else {
  484. delete self.classSelectionModel[data];
  485. }
  486. console.log("classSelection:" , self.classSelectionModel);
  487. * /
  488. });
  489. */
  490. /*
  491. $$.document.append(executorWidget.getView(), $("#datasets"));
  492. //executorWidget.getView().getListWidget().refresh();
  493. executorWidget.refresh();
  494. */
  495. }
  496. // TODO [HACK] Not sure why we need this hack of switching tabs
  497. // But without it, the facets do not show from the start; only after switching the incoming/outgoing tabs
  498. this.facetBox.view.$('a:eq(1)').tab('show');
  499. this.facetBox.view.$('a:first').tab('show');
  500. };
  501. ns.AppController.prototype.updateFacets = function(executor, facetBox) {
  502. if(!executor) {
  503. console.log("No executor set (yet)");
  504. return;
  505. }
  506. this.updateFacetsRec(executor, facetBox);
  507. };
  508. ns.AppController.prototype.updateFacetsRec = function(executor, view) {
  509. var path = new facets.Path(); //executor.getNavigationPath();
  510. executorIncoming = executor.navigateToFacets(-1);
  511. executorOutgoing = executor.navigateToFacets(1);
  512. this.updateFacetsRecDir(executorOutgoing, view.getOutgoing(), false, path);
  513. this.updateFacetsRecDir(executorIncoming, view.getIncoming(), true, path);
  514. };
  515. ns.AppController.prototype.updateFacetsRecDir = function(executor, view, isInverse, path) {
  516. var self = this;
  517. //var pivotFacets = executor.fetchPivotFacets();
  518. var pivotFacetsTask = $.Deferred();
  519. pivotFacetsTask.resolve({});
  520. $.when(executor.fetchValuesCounted(), pivotFacetsTask).then(function(facetCollection, pivotFacets) {
  521. var promise = ns.postProcessFacets(facetCollection, pivotFacets, self.labelFetcher);
  522. $.when(promise).then(function(facetCollection) {
  523. _.each(facetCollection, function(item) {
  524. var propertyName = item.node.value;
  525. var step = new facets.Step(propertyName, isInverse);
  526. item.path = path.copyAppendStep(step);
  527. });
  528. //console.log("FacetSatus", facetCollection);
  529. //view.setCollection(facetCollection);
  530. view.getModel().setData(facetCollection);
  531. view.refresh();
  532. });
  533. });
  534. };
  535. /* TODO Such high level function might make sense; but not sure how to realize that yet.
  536. ns.AppController.prototype.updateFacets = function() {
  537. if(!this.executor) {
  538. console.warn("No executor set (yet)");
  539. return;
  540. }
  541. this.updateFacetsRec(this.executor, this.facetBox);
  542. };
  543. */
  544. /**
  545. * Create the model for the facet box
  546. *
  547. */
  548. ns.postProcessFacets = function(facets, pivotFacets, labelFetcher) {
  549. // Index pivot facets
  550. var pivotStrs = {};
  551. _.each(pivotFacets.facets, function(item) {
  552. if(item.isUri()) {
  553. pivotStrs[item.value] = true;
  554. }
  555. });
  556. // Check pivot state
  557. //var collection = [];
  558. _.each(facets, function(item) {
  559. // Note: Facets must all be URIs, but better check
  560. var isPivotable = true;
  561. //var isPivotable = false;
  562. if(item.node.isUri()) {
  563. var str = item.node.value;
  564. if(str in pivotStrs) {
  565. isPivotable = true;
  566. }
  567. }
  568. item.countStr = "" + item.count;
  569. item.isPivotable = isPivotable;
  570. });
  571. // Fetch labels
  572. var uriStrs = [];
  573. _.each(facets, function(item) {
  574. if(item.node.isUri()) {
  575. uriStrs.push(item.node.value);
  576. }
  577. });
  578. var promise = labelFetcher.fetch(uriStrs).pipe(function(labels) {
  579. _.each(facets, function(item) {
  580. var label = labels.uriToLabel[item.node.value];
  581. item.label = label ? label.value : "" + item.node;
  582. });
  583. return facets;
  584. });
  585. return promise;
  586. };
  587. ns.AppController.prototype.updateConstraints = function() {
  588. var self = this;
  589. var csR = this.queryGenerator.getConstraints();
  590. var csF = this.queryGeneratorFacets.getConstraints();
  591. csF.clear();
  592. csR.clear();
  593. var assessmentPath = facets.Path.fromString("http://qa.linkeddata.org/ontology/assessment");
  594. this.constraints.each(function(item) {
  595. var c = item.get("value");
  596. //alert("" + typeof(item) + " " + JSON.stringify(item));
  597. //console.log("dammit", item);
  598. var tmp = new facets.PathConstraint(assessmentPath.concat(c.getPath()), c.getConstraint());
  599. console.log("Path is now " + tmp);
  600. csR.add(tmp);
  601. //console.log("Tmp: ", tmp);
  602. csF.add(tmp);
  603. });
  604. //self.constraintWidget.refresh();
  605. //self.repaint();
  606. this.refresh();
  607. };
  608. ns.AppController.prototype.refresh = function() {
  609. var self = this;
  610. $.when(this.executor.fetchCountRows()).then(function(countInfo) {
  611. var pageCount = parseInt(countInfo.count / self.itemsPerPage + 0.5);
  612. self.paginatorModel.set({pageCount: pageCount});
  613. });
  614. this.syncer.sync();
  615. };
  616. ns.AppController.prototype.showDetailPage = function(uriStr) {
  617. app.renderDetailPage();
  618. //var element =
  619. };
  620. })(jQuery);