// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var UserStore = require('../stores/user_store.jsx'); var AsyncClient = require('../utils/async_client.jsx'); var Utils = require('../utils/utils.jsx'); function getStateFromStoresForAudits() { return { audits: UserStore.getAudits() }; } module.exports = React.createClass({ componentDidMount: function() { UserStore.addAuditsChangeListener(this._onChange); AsyncClient.getAudits(); var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { self.setState({ moreInfo: [] }); }); }, componentWillUnmount: function() { UserStore.removeAuditsChangeListener(this._onChange); }, _onChange: function() { this.setState(getStateFromStoresForAudits()); }, handleMoreInfo: function(index) { var newMoreInfo = this.state.moreInfo; newMoreInfo[index] = true; this.setState({ moreInfo: newMoreInfo }); }, getInitialState: function() { var initialState = getStateFromStoresForAudits(); initialState.moreInfo = []; return initialState; }, render: function() { var accessList = []; var currentHistoryDate = null; for (var i = 0; i < this.state.audits.length; i++) { var currentAudit = this.state.audits[i]; var newHistoryDate = new Date(currentAudit.create_at); var newDate = null; if (!currentHistoryDate || currentHistoryDate.toLocaleDateString() !== newHistoryDate.toLocaleDateString()) { currentHistoryDate = newHistoryDate; newDate = (
{currentHistoryDate.toDateString()}
); } accessList[i] = (
{newDate}
{newHistoryDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute:'2-digit'})}
{"IP: " + currentAudit.ip_address}
{ this.state.moreInfo[i] ?
{"Session ID: " + currentAudit.session_id}
{"URL: " + currentAudit.action.replace("/api/v1", "")}
: More info }
{i < this.state.audits.length - 1 ?
: null }
); } return (
); } });