var $ = require('jquery'); var AppConstants = require('../constants/AppConstants'); var AppDispatcher = require('../dispatchers/AppDispatcher'); var EventEmitter = require('events').EventEmitter; var HelixWebServicesClient = require('helix_web_services_client'); var React = require('react'); var assign = require('object-assign'); var LOGGED_IN = 'logged_in'; var LOGGED_OUT = 'logged_out'; // The session store handles our security token session. var Session = assign({}, EventEmitter.prototype, { hasSession: function() { return this.getSession() != null; }, getSession: function() { return JSON.parse(localStorage.getItem('session')); }, getClient: function() { if (this.client == null && this.hasSession()) { var session = this.getSession(); this.client = new HelixWebServicesClient({ prefix: '/hws', user: session.user, session_token: session.token }); var self = this; this.client.addSessionExpiredHandler(function() { localStorage.removeItem('session'); self.client = null; self.emitLoggedOut(); }); } return this.client; }, logIn: function(user, password) { var client = new HelixWebServicesClient({ prefix: '/hws', user: user }); var ajax = client.logIn(password); var self = this; ajax.done(function(token, status) { localStorage.setItem('session', JSON.stringify({ user: user, token: token })); self.emitLoggedIn(); }); ajax.fail(function() { console.log('fail!', arguments); }); }, logOut: function() { var client = this.getClient(); if (client) { var ajax = client.logOut(); var self = this; var finish = function() { localStorage.removeItem('session'); self.client = null; self.emitLoggedOut(); }; ajax.done(finish); ajax.fail(finish); } }, emitLoggedIn: function() { this.emit(LOGGED_IN); }, emitLoggedOut: function() { this.emit(LOGGED_OUT); }, addLoggedInListener: function(callback) { this.on(LOGGED_IN, callback); }, removeLoggedInListener: function(callback) { this.removeListener(LOGGED_IN, callback); }, addLoggedOutListener: function(cb) { this.on(LOGGED_OUT, cb); }, removeLoggedOutListener: function(cb) { this.removeListener(LOGGED_OUT, cb); } }); AppDispatcher.register(function(action) { switch(action.actionType) { case AppConstants.LOG_IN: Session.logIn(action.user, action.password); break; case AppConstants.LOG_OUT: Session.logOut(); break; default: // Do nothing } }); module.exports = Session;
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/source/helix_web_components/project_management/stores/Session.js | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_components/project_management/stores/Session.js | |||||
#4 | 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. |
||
#3 | 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. |
||
#2 | 13999 | tjuricek |
Switching to use HWS JavaScript API for Store backend. Switching between node testing and browser testing environments isn't smooth yet. |
||
#1 | 13974 | tjuricek |
Moving 'ui/static' to 'helix_web_components' project, and altering some notes. Also, removed obsolete top-level Rake tasks. The "Helix Web Components" project will likely get moved elsewhere in the future. |
||
//guest/perforce_software/helix-web-services/main/ui/static/project_management/stores/Session.js | |||||
#4 | 13962 | tjuricek |
Add 'location' store and integrate "Jest" for unit testing. The location will trigger different views of the main ProjectManagement component. The Jest framework allows us to create headless tests of the React component logic. It's a little tricky, and right now has a dependency on node 0.10. |
||
#3 | 13960 | tjuricek |
Setup a development config for nginx /hws points to the new monolithic helix_web_serivces instance / points to a static directory This static directory may end up getting moved around into other projects, I'm not sure where that location should be. |
||
#2 | 13769 | tjuricek | Add a trivial 'Header' component with a log out method. | ||
#1 | 13707 | tjuricek |
Infrastructure for including a "project management" React application. This attempts to create a fairly simple installer that creates a 'static' folder based on ui/static that gets hosted by the nginx front end. Right now, it's the only app, so the default page is this application. It was called "pws2" during a prototyping phase. Another prototype, "pws" and the related "project" module, is removed since that was a Sinatra-based approach that will be much more difficult to integrate into anything else. I'm running into a couple of issues with notifications setup, it's still not 100%, so I'm disabling this for now from the default 'god' configuration. (The service isn't 100% functional yet, anyway.) |
||
//guest/perforce_software/helix-web-services/main/ui/static/pms2/stores/Session.js | |||||
#1 | 13645 | tjuricek |
React.js + Flux prototype This just logs in and displays a list of projects (create one with the other app for now). |