// The Client object is how people should access the Helix Web Services server // via AJAX calls (that uses jQuery). // // The API here is promise-oriented, which makes it slightly different to work // with than the Ruby or Qt SDKs. //---------------------------------------------------------------------------- // Node-specific initialization //---------------------------------------------------------------------------- // Uglyness, see if we can move this out of this file to just use this line //var $ = require('jquery'); var $ = require('jquery')(require("jsdom").jsdom().parentWindow); var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; $.support.cors = true; $.ajaxSettings.xhr = function() { return new XMLHttpRequest(); }; var btoa = require('btoa'); //---------------------------------------------------------------------------- // End node-specific initialization //---------------------------------------------------------------------------- var assign = require('object-assign'); // Construct a new HelixWebServicesClient interface function HelixWebServicesClient(options) { options = options || {}; this.url = options.url; this.user = options.user; this.prefix = options.prefix || ""; this.session_token = options.session_token; } assign(HelixWebServicesClient.prototype, { //------------------------------------------------------------------------- // Asynchronous Methods //------------------------------------------------------------------------- // Creates a new session token. Before done is called back, we cache the // session on this object. // // Returns a promise: // // - done: -> (session) {} // - fail: -> (error) {} logIn: function(user, password) { if (!password) { password = user; user = this.user; } // TODO we very likely want to configure ajax for common error handling var ajax = $.post( this.urlTo('/auth/v1/sessions'), { user: this.user, password: password } ); // We wrap the promise in order to cache the session before done() is // invoked. var deferred = $.Deferred(); var self = this; ajax.done(function(data, textStatus, jqXHR) { self.session_token = data; deferred.resolve(self.session_token); }); ajax.fail(function() { console.log('failed', arguments); deferred.reject('bonk'); }); return deferred.promise(); }, // Destroys the session (on the server) // // Returns a promise: // // - done: -> () {} // - fail: -> (error) {} logOut: function() { var self = this; var ajax = $.ajax({ method: 'DELETE', url: this.urlTo('/auth/v1/sessions/' + this.session_token), beforeSend: function(xhr) { var auth = btoa(self.user + ":" + self.session_token); xhr.setRequestHeader("Authorization", "Basic " + auth); } }); var deferred = $.Deferred(); ajax.done(function() { deferred.resolve(); }); ajax.fail(deferred.reject); return deferred.promise(); }, // Fetch Helix Sync projects from the server. // // syncProjects: function(options) { var ajax = $.get( this.urlTo('/sync/v1/projects') ) }, //------------------------------------------------------------------------- // Helper Methods //------------------------------------------------------------------------- // These methods shouldn't return Promise interfaces. urlTo: function(path) { var url = this.url || ""; if (this.prefix) { url += this.prefix; } url += path; return url; } }); module.exports = HelixWebServicesClient;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#11 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
#10 | 14177 | tjuricek | A wee bit of asciidoc conversion and some comment scoping | ||
#9 | 14176 | tjuricek |
Add a basic 'add member' function to the project details page. There appears to be some kind of funky caching issue with the components. The project data does get updated, so this UI is not 100% bug proof. Also, there's no autocomplete yet. |
||
#8 | 14175 | tjuricek |
Very basic read-only project details page. We're not going to display complete user detail information for a while. |
||
#7 | 14151 | tjuricek |
Add depot tree control and selection to the create projects page. Styling and error checking is kept to a minimum for the time being. Our goal is just internal workflow and feedback. |
||
#6 | 14108 | tjuricek |
Added models for handling Perforce server depot listing and traversal. This is not complete, however, the models are a start to making it easy to generate a tree control. (Most tree controls in the wild assume you know the tree structure from the start, which is not true in our case.) The tricky bit is making it easy to build the tree out given that you're visiting only one directory at a time. |
||
#5 | 14105 | tjuricek |
add 'listMy' and 'listAll' sync project variations to the JS API. Also, set up the project list to switch between the two project types. Also, setup each item in the project list to not be a grouped list item, but a custom view component. Not particularly useful, but it just displays a description now. |
||
#4 | 14002 | tjuricek | Some preliminary API documentation for the JavaScript SDK. | ||
#3 | 13999 | tjuricek |
Switching to use HWS JavaScript API for Store backend. Switching between node testing and browser testing environments isn't smooth yet. |
||
#2 | 13998 | tjuricek |
Add a basic ability for the JS SDK to create and list projects. Cleaned up some node madness on SDK initialization. |
||
#1 | 13976 | tjuricek |
Client SDK for JavaScript that logs in. This is currently tested via node using jasmine against a test environment, which requires some funky initialization. So this isn't a particularly useful client yet, but we'll need to add more error handling, etc, to smooth things out. |