query-controller.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Controller for the embedded Qonsole component.
  3. *
  4. * Note: unlike some Qonsole installations, the endpoint URL selector dropdown
  5. * has been removed in favour of the dataset selector control higher up the page.
  6. **/
  7. define(
  8. function( require ) {
  9. var Marionette = require( "marionette" ),
  10. Backbone = require( "backbone" ),
  11. _ = require( "underscore" ),
  12. fui = require( "app/fui" ),
  13. qonsole = require( "qonsole" ),
  14. pageUtils = require( "app/util/page-utils" );
  15. var QueryController = function() {
  16. this.initEvents();
  17. };
  18. // add the behaviours defined on the controller
  19. _.extend( QueryController.prototype, {
  20. initEvents: function() {
  21. _.bindAll( this, "onServerModelReady", "onDatasetChanged" );
  22. if (fui.models.fusekiServer && fui.models.fusekiServer.get( "ready" )) {
  23. this.onServerModelReady();
  24. }
  25. else {
  26. fui.vent.on( "models.fuseki-server.ready", this.onServerModelReady );
  27. }
  28. fui.vent.on( "dataset.changed", this.onDatasetChanged );
  29. },
  30. /** Initialise the qonsole component */
  31. initQonsole: function( datasetsConfig ) {
  32. var qonfig = require( "app/qonsole-config" );
  33. qonsole.init( qonfig );
  34. var dsName = fui.models.fusekiServer.selectedDatasetName();
  35. if (dsName) {
  36. this.setEndpointURL( dsName );
  37. }
  38. },
  39. /** When the fuseki server is ready, we can init the qonsole */
  40. onServerModelReady: function( event ) {
  41. var fusekiServer = fui.models.fusekiServer;
  42. var endpoints = {};
  43. var datasets = fusekiServer.datasets();
  44. this.initQonsole( {} );
  45. },
  46. /** When notified that the selected dataset name has changed, update the endpoint URL */
  47. onDatasetChanged: function( dsName ) {
  48. this.setEndpointURL( dsName );
  49. },
  50. /** Set the endpoint URL based on the selected dataset name */
  51. setEndpointURL: function( dsName ) {
  52. var dataset = fui.models.fusekiServer.dataset( dsName );
  53. qonsole.setCurrentEndpoint( dataset.queryURL() );
  54. }
  55. } );
  56. return QueryController;
  57. }
  58. );