Code Monkey home page Code Monkey logo

djangoql-completion's Introduction

DjangoQL completion widget

An autocompletion widget for DjangoQL that you can embed inside your own custom JavaScript application.

Installation

The DjangoQL completion widget is available at npm as djangoql-completion. You can install it using npm or yarn.

Using npm:

$ npm i --save djangoql-completion

Version compatibility

  • For DjangoQL v0.16.0+ please use djangoql-completion v0.5.0+;
  • DjangoQL v0.15.4 and older: the latest version of djangoql-completion that supports these releases is v0.4.0.

Usage

  1. Somewhere on your page, create a <textarea> element that can receive user input and provide DjangoQL syntax completions. You can optionally pre-populate its contents with an existing query that users can edit:
<textarea name="q">name ~ "war" and author.name = "Tolstoy"</textarea>
  1. Load the completion widget styles. If you're using Webpack with css-loader, you can import the styles right from your JavaScript code:
import 'djangoql-completion/dist/completion.css';

Feel free to override the default styles to make the widget look right for your project.

  1. Finally, initialize the completion widget for the <textarea> that you created:
import DjangoQL from 'djangoql-completion';

// Initialize completion widget
const djangoQL = new DjangoQL({
  // Enable completion features upon initialization (true by default)
  completionEnabled: true,
  
  // DjangoQL introspection schema, either as a JavaScript object,
  // or as an URL from which it can be fetched
  introspections: 'introspections/',
  
  // CSS selector for the <textarea> element that you created above
  selector: 'textarea[name=q]',
  
  // For long query inputs, automatically resize the <textarea> vertically
  autoResize: true,
  
  // URL for the syntax help page (optional)
  syntaxHelp: null,
  
  onSubmit: function(value) {
    // Callback for the submit event. Receives the textarea value as a parameter 
  },
});

// Once the completion widget is initialized, you can control it using the
// following methods:
//
// Popup the completions dialog (this might be useful to do immediately after
// initialization, to show users that completion is available):
//     djangoQL.popupCompletion();
//
// Disable completion widget:
//     djangoQL.disableCompletion();
//
// Enable completion widget:
//     djangoQL.enableCompletion();

That's it! You should be ready to go. If you need help with DjangoQL itself, please refer to its docs.

License

MIT

djangoql-completion's People

Contributors

mattdodsonenglish avatar skulden13 avatar stebunovd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djangoql-completion's Issues

Partial completion based on user input?

Hi!

We are using DjangoQL and the completion library to query a large dataset. We noticed that the entire dataset is returned by the DjangoQLSchemaSerializer which causes the response body to exceed 200 MB.

Would it be possible to load suggestions as the user is typing and using the partial input as a filter? There are a couple of cues in the library that seem to suggest that such functionality is possible, but I am not sure whether this is fully implemented or how to enable this.

Add option to set HTTP headers, for APIs behind authentication

Some APIs require authentication parameters to be set.
In its current form, the djangoql api has no extension points to add such headers or parameters.

It would be good if the getJson function had an optional callback function where the user can modify the self.request object before sending the request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.