$twigkit

Description

Twigkit factory with methods for accessing the Twigkit API.

Methods

  • cancelAllResponses()

    Fires an event to cancel the current response being requested from the backend.

    Example

    $twigkit.cancelAllResponses();

  • deleteBookmark(id)

    Sends a request to delete a bookmark to the API.

    Parameters
    Param Type Details
    id string

    The id of the bookmark to delete.

    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.deleteBookmark(id);

  • deleteComment(platform, id)

    Sends a request to delete a comment to the API.

    Parameters
    Param Type Details
    platform Object

    The platform object (retrievable from Platform Service).

    id string

    The id of the comment to delete.

    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.deleteComment(platform, id);

  • deleteLike(platform, id)

    Sends a request to delete a like to the API.

    Parameters
    Param Type Details
    platform Object

    The platform object (retrievable from Platform Service).

    id string

    The id of the bookmark to delete.

    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.deleteLike(platform,id);

  • deleteSavedQuery(id)

    Sends a request to delete a saved query to the API.

    Parameters
    Param Type Details
    id string

    The id of the saved query to delete.

    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.deleteSavedQuery(id);

  • deleteTopic(id)

    Sends a request to delete a topic to the API.

    Parameters
    Param Type Details
    id string

    The id of the topic to delete.

    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.deleteTopic(id);

  • getComments(platform, target, collection, topic)

    Sends a request to get comments from the API.

    Parameters
    Param Type Details
    platform Object

    The platform object (retrievable from Platform Service).

    target
    (optional)
    string

    Returns all comments that apply to the specified target document.

    collection
    (optional)
    string
    topic
    (optional)
    string
    Returns
    HttpPromise

    Returns a promise which will resolve depending on the response from the API.

    Example

    $twigkit.getComments(platform, target);

  • getConstant(defaultValue)

    Gets a constant declared to the lightning module.

    A constant can be added to your application like so

    angular
    .module('lightning').constant('contextPath', 'My Constant Value');
    

    You can then get this value in your controller and apply it to the scope or rootScope (if applied to the rootScope you can use {{$root.myConstant}} in your views.

    angular.module('twigkitLightApp')
    
    controller('MainCtrl', ['$scope', '$stateParams','$twigkit', function ($scope, $stateParams,$twigkit) {
    $scope.params = $stateParams;
      $scope.test123 = $twigkit.getConstant('test','No 123 Found Here');
      $rootScope.test = $twigkit.getConstant('test','');
      }]);
    </code></pre></div><h5 id="methods_getconstant_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>defaultValue</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getconstant-page"><p>Value to be returned if context path does not exist.</p>
    </div></td></tr></tbody></table><h5 id="methods_getconstant_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getconstant-page"><p>Returns the constant value.</p>
    </div></td></tr></table><h4 id="methods_getconstant_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-getconstant-page"><p>$twigkit.getConstant(defaultValue);</p>
    </div></div>
    </div>
    </li>
    <li><h3 id="methods_getcontextpath">getContextPath(defaultValue)</h3>
    <div class="getcontextpath"><div class="lightning-services-twigkit-getcontextpath-page"><p>Gets the context path if it is available.</p>
    </div><h5 id="methods_getcontextpath_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>defaultValue <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getcontextpath-page"><p>Value to be returned if context path does not exist. Defaults to &#39;/&#39;</p>
    </div></td></tr></tbody></table><h5 id="methods_getcontextpath_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getcontextpath-page"><p>Returns a string of the context path or the default value.</p>
    </div></td></tr></table><h4 id="methods_getcontextpath_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-getcontextpath-page"><p>$twigkit.getContextPath(defaultValue);</p>
    </div></div>
    </div>
    </li>
    <li><h3 id="methods_getgraphfacet">getGraphFacet(query, platform, source-field, target-field, measure, measure-field)</h3>
    <div class="getgraphfacet"><div class="lightning-services-twigkit-getgraphfacet-page"><p>Gets graph data for a facet</p>
    </div><h5 id="methods_getgraphfacet_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>query</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>The query to use against the platform.</p>
    </div></td></tr><tr><td>platform</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>The name of the platform to use.</p>
    </div></td></tr><tr><td>source-field</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>Name of a primary field to facet on (for example &quot;Country&quot;). The values of this facet will define the set of graph nodes with outgoing edges.</p>
    </div></td></tr><tr><td>target-field</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>Name of a secondary field to facet on (for example &quot;City&quot;), for every facet value of the primary field.
    The values of this facet will define the set of graph nodes with incoming edges. For example, say the primary facet
    (source-field) has values for Country=Germany and Country=France and the secondary facet (target-field) has values for City=Berlin,
    City=Munich and City=Paris. Then we add graph edges Germany--&gt;Berlin, Germany--&gt;Munich and France--&gt;Paris.</p>
    </div></td></tr><tr><td>measure <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>Name of a numerical measure that defines the weight of each graph edge. When omitted, this defaults to the counts of the facets defined
    by the target-field. Some possible measures include &quot;sum&quot;, &quot;mean&quot; and &quot;min&quot;. (Only applicable if not using <code>data</code> attribute).</p>
    </div></td></tr><tr><td>measure-field <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>Field to measure, when the &quot;measure&quot; option is specified.</p>
    </div></td></tr></tbody></table><h5 id="methods_getgraphfacet_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-getgraphfacet-page"><p>Returns a promise which will resolve depending on the response from the API.</p>
    </div></td></tr></table><h4 id="methods_getgraphfacet_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-getgraphfacet-page"><p>$twigkit.getGraphFacet(&#39;query&#39;, &#39;platform&#39;, &#39;facet&#39;);</p>
    </div></div>
    </div>
    </li>
    <li><h3 id="methods_getlikes">getLikes(options)</h3>
    <div class="getlikes"><div class="lightning-services-twigkit-getlikes-page"><p>Sends a request to get a likes from the API.</p>
    </div><h5 id="methods_getlikes_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>options</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-getlikes-page"><p>Object containing options to be sent in the get request. Like target, collection, topic etc.</p>
    </div></td></tr></tbody></table><h5 id="methods_getlikes_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-getlikes-page"><p>Returns a promise which will resolve depending on the response from the API.</p>
    </div></td></tr></table><h4 id="methods_getlikes_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-getlikes-page"><p>$twigkit.getLikes(options);</p>
    </div></div>
    </div>
    </li>
    <li><h3 id="methods_getuser">getUser()</h3>
    <div class="getuser"><div class="lightning-services-twigkit-getuser-page"><p>Calls the Twigkit API to return the current user</p>
    <p>To enable this you need to make sure that your security.conf file contains the line <code>webservice-enabled: true</code></p>
    <p>Your security.conf file can be found in &#39;resources/conf/security/security.conf&#39;.</p>
    <p>For spring security you will need the following rule to allow access to the user api, if parts of the site are public.</p>
    <p><code>&lt;intercept-url pattern=&quot;/twigkit/api/user&quot; access=&quot;isAnonymous() or isAuthenticated()&quot;/&gt;</code></p>
    </div><h5 id="methods_getuser_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-getuser-page"><p>Returns a promise which will resolve depending on the response from the API.</p>
    </div></td></tr></table><h4 id="methods_getuser_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-getuser-page"><p>$twigkit.getUser();</p>
    </div></div>
    </div>
    </li>
    <li><h3 id="methods_oncancelallresponses">onCancelAllResponses(callback, scope)</h3>
    <div class="oncancelallresponses"><div class="lightning-services-twigkit-oncancelallresponses-page"><p>When the cancel response event is fired the callback function will be called.</p>
    </div><h5 id="methods_oncancelallresponses_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>callback</td><td><a href="" class="label type-hint type-hint-function">Function</a></td><td><div class="lightning-services-twigkit-oncancelallresponses-page"><p>The function to be called when the cancel event is fired.</p>
    </div></td></tr><tr><td>scope</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-oncancelallresponses-page"><p>The <code>$scope</code> object for unsubscribing to the event when the scope is destroyed.</p>
    </div></td></tr></tbody></table><h4 id="methods_oncancelallresponses_example">Example</h4>
    <div class="example"><div class="lightning-services-twigkit-oncancelallresponses-page"><pre><code>$twigkit.onCancelAllResponses(function () {
     console.log(&#39;Responses have been cancelled&#39;);
    }, $scope);

    $twigkit.cancelAllResponses(); </code></pre></div></div> </div> </li> <li><h3 id="methods_postlike">postLike(platform, id, target, topic, collection)</h3> <div class="postlike"><div class="lightning-services-twigkit-postlike-page"><p>Sends a request to create a like to the API.</p> </div><h5 id="methods_postlike_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>platform</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>The platform object (retrievable from <a href="/api/lightning.PlatformService">Platform Service</a>).</p> </div></td></tr><tr><td>id</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>The id of the bookmark to delete.</p> </div></td></tr><tr><td>target</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>A unique identifier for a document that is being bookmarked. Example values: document123 Maximum length: 2083 characters</p> </div></td></tr><tr><td>topic <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-number">number</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>A topic to which the new bookmark should belong.</p> </div></td></tr><tr><td>collection <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>The collection to which the target document belongs.</p> </div></td></tr></tbody></table><h5 id="methods_postlike_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-postlike-page"><p>Returns a promise which will resolve depending on the response from the API.</p> </div></td></tr></table><h4 id="methods_postlike_example">Example</h4> <div class="example"><div class="lightning-services-twigkit-postlike-page"><p>$twigkit.postLike(platform, id, target, topic, collection);</p> </div></div> </div> </li> <li><h3 id="methods_search">search(searchQuery, platform, params, ignore-loading-bar, canceller)</h3> <div class="search"><div class="lightning-services-twigkit-search-page"><p>Search method sends a query to a Twigkit Platform endpoint and gets a result.</p> </div><h5 id="methods_search_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>searchQuery</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-search-page"><p>The search term to search against the results.</p> </div></td></tr><tr><td>platform</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-search-page"><p>The platform object (retrievable from <a href="/api/lightning.PlatformService">Platform Service</a>).</p> </div></td></tr><tr><td>params <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-search-page"><p>Other parameters to pass to the API.</p> </div></td></tr><tr><td>ignore-loading-bar <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-boolean">boolean</a></td><td><div class="lightning-services-twigkit-search-page"><p>Whether the loading bar across the top of the page should be included for this http request. Default:true</p> </div></td></tr><tr><td>canceller <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-promise">Promise</a></td><td><div class="lightning-services-twigkit-search-page"><p>A promise object (<code>$q.defer()</code>) used to cancel the request by using <code>canceller.promise()</code></p> </div></td></tr></tbody></table><h5 id="methods_search_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-search-page"><p>Returns a promise which will resolve depending on the response from the API.</p> </div></td></tr></table><h4 id="methods_search_example">Example</h4> <div class="example"><div class="lightning-services-twigkit-search-page"><p>$twigkit.search(query, platform, params);</p> </div></div> </div> </li> <li><h3 id="methods_searchfacet">searchFacet(facet, platform, query, rpp, facetQuery, removeFilters, facetField)</h3> <div class="searchfacet"><div class="lightning-services-twigkit-searchfacet-page"><p>Calls the Twigkit API to return filters from a specific facet based on the searchQuery.</p> </div><h5 id="methods_searchfacet_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>facet</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>The name of the facet to search.</p> </div></td></tr><tr><td>platform</td><td><a href="" class="label type-hint type-hint-object">Object</a><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>The platform object (retrievable from <a href="/api/lightning.PlatformService">Platform Service</a>) or the name of the platform.</p> </div></td></tr><tr><td>query</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>The query object.</p> </div></td></tr><tr><td>rpp</td><td><a href="" class="label type-hint type-hint-number">Number</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>The number of filters to be returned by the API.</p> </div></td></tr><tr><td>facetQuery</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>The facet query to use against the API end point.</p> </div></td></tr><tr><td>removeFilters <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-boolean">boolean</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>Whether to remove the current filters for the facet when performing the search.</p> </div></td></tr><tr><td>facetField <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>If provided this field may be used to create a filter on the facet which may not be the same as the facet name itself.</p> </div></td></tr></tbody></table><h5 id="methods_searchfacet_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-searchfacet-page"><p>Returns a promise which will resolve depending on the response from the API.</p> </div></td></tr></table><h4 id="methods_searchfacet_example">Example</h4> <div class="example"><div class="lightning-services-twigkit-searchfacet-page"><p>$twigkit.searchFacet(facet,platform,query,facetQuery);</p> </div></div> </div> </li> <li><h3 id="methods_searchseriesfacet">searchSeriesFacet(query, platform, facet, measure, rpp)</h3> <div class="searchseriesfacet"><div class="lightning-services-twigkit-searchseriesfacet-page"><p>Gets series data for a facet.</p> </div><h5 id="methods_searchseriesfacet_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>query</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>The query to use against the platform.</p> </div></td></tr><tr><td>platform</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>The platform object (retrievable from <a href="/api/lightning.PlatformService">Platform Service</a>).</p> </div></td></tr><tr><td>facet</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>The facet to search upon.</p> </div></td></tr><tr><td>measure</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>What fact to use as an alternative to count as quantitative value for a filter.</p> </div></td></tr><tr><td>rpp</td><td><a href="" class="label type-hint type-hint-number">Number</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>The number of results to fetch.</p> </div></td></tr></tbody></table><h5 id="methods_searchseriesfacet_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-searchseriesfacet-page"><p>Returns a promise which will resolve depending on the response from the API.</p> </div></td></tr></table><h4 id="methods_searchseriesfacet_example">Example</h4> <div class="example"><div class="lightning-services-twigkit-searchseriesfacet-page"><p>$twigkit.searchSeriesFacet(query, platform, facet);</p> </div></div> </div> </li> <li><h3 id="methods_searchseriesfields">searchSeriesFields(query, platform, fields, rpp)</h3> <div class="searchseriesfields"><div class="lightning-services-twigkit-searchseriesfields-page"><p>Gets series data for a result list.</p> </div><h5 id="methods_searchseriesfields_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>query</td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="lightning-services-twigkit-searchseriesfields-page"><p>The query to use against the platform.</p> </div></td></tr><tr><td>platform</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-searchseriesfields-page"><p>The platform object (retrievable from <a href="#/api/lightning.PlatformService">Platform Service</a>).</p> </div></td></tr><tr><td>fields</td><td><a href="" class="label type-hint type-hint-object">Object</a></td><td><div class="lightning-services-twigkit-searchseriesfields-page"><p>The facet to fields upon.</p> </div></td></tr><tr><td>rpp</td><td><a href="" class="label type-hint type-hint-number">Number</a></td><td><div class="lightning-services-twigkit-searchseriesfields-page"><p>The number of results to fetch.</p> </div></td></tr></tbody></table><h5 id="methods_searchseriesfields_returns">Returns</h5><table class="variables-matrix"><tr><td><a href="" class="label type-hint type-hint-httppromise">HttpPromise</a></td><td><div class="lightning-services-twigkit-searchseriesfields-page"><p>Returns a promise which will resolve depending on the response from the API.</p> </div></td></tr></table><h4 id="methods_searchseriesfields_example">Example</h4> <div class="example"><div class="lightning-services-twigkit-searchseriesfields-page"><p>$twigkit.searchSeriesFacet(query, platform, fields);</p> </div></div> </div> </li> </ul> </div> </div>