// Generated by LiveScript 1.2.0 (function(){ var ref$, table, div, th, tr, td, thead, tbody, section, h3, time, map, each, unique, isType, join, fields, AuditTableHeader, Timestamp, wrapArray, AuditEntry, newEventSet, AuditTable, GlobalAudit, urlOfRole, urlOfResource, AuditBox, out$ = typeof exports != 'undefined' && exports || this; ref$ = React.DOM, table = ref$.table, div = ref$.div, th = ref$.th, tr = ref$.tr, td = ref$.td, thead = ref$.thead, tbody = ref$.tbody, section = ref$.section, h3 = ref$.h3, time = ref$.time; ref$ = require('prelude-ls'), map = ref$.map, each = ref$.each, unique = ref$.unique, isType = ref$.isType, join = ref$.join; fields = ['timestamp', 'user', 'acting_as', 'action', 'kind', 'entity', 'privilege']; AuditTableHeader = React.createClass({ displayName: 'AuditTableHeader', render: function(){ return thead({}, tr({}, map(function(it){ return th({ key: it }, it.replace('_', ' ')); })( fields))); } }); Timestamp = React.createClass({ displayName: 'Timestamp', render: function(){ var ts; ts = moment(this.props.time); return time({ datetime: ts.format(), title: ts.calendar() }, [ts.fromNow()]); } }); wrapArray = function(it){ if (isType('Array', it)) { return it; } else { return [it]; } }; AuditEntry = React.createClass({ displayName: 'AuditEntry', transformedProps: function(){ var ref$; return ref$ = clone$(this.props), ref$.entity = this.props.resource || this.props.role, ref$; }, transformField: function(key, value){ switch (false) { case !!value: return value; case key !== 'user' && key !== 'acting_as': return RoleLink({ id: value }); case key !== 'entity': return ResourceLink({ data: value }); case key !== 'timestamp': return Timestamp({ time: value }); default: return value; } }, render: function(){ var props, this$ = this; props = this.transformedProps(); return tr({ className: this.props.action }, map(function(it){ return td({ key: it }, [this$.transformField(it, props[it])]); })( fields)); } }); newEventSet = function(){ var evts; evts = new SortedSet({ comparator: function(a, b){ return a && b && b.id - a.id; } }); evts.containsLike = function(item){ var existing; existing = this.findIterator(item).value(); if (existing != null) { return this.priv.comparator(existing, item) === 0; } }; return evts; }; AuditTable = React.createClass({ displayName: 'AuditTable', getInitialState: function(){ return { events: newEventSet() }; }, render: function(){ return section({ className: 'audit' }, [ h3({}, this.props.caption), table({ className: 'audit-table' }, [ AuditTableHeader({ key: 'thead' }), tbody({ key: 'tbody' }, this.state.events.map(function(it){ var ref$; return new AuditEntry((ref$ = clone$(it), ref$.key = it.id, ref$)); })) ]) ]); }, componentDidMount: function(){ return each(this.addSource)( wrapArray( this.props.src)); }, componentWillUnmount: function(){ return each(function(it){ console.log("closing event source ", it); return it.close(); })( this.sources); }, addEvent: function(arg$){ var data, event; data = arg$.data; event = JSON.parse(data); if (event.action === "check" && event.privilege === "read" && event.allowed) { return true; } else { if (!this.state.events.containsLike(event)) { this.state.events.insert(event); return this.forceUpdate(); } } }, addSource: function(url){ var evtSrc; console.log("opening eventsource to " + url); evtSrc = new EventSource(url); console.log(evtSrc); evtSrc.onmessage = this.addEvent; evtSrc.onerror = function(a, b, c, d){ return console.log(a, b, c, d); }; return (this.sources || (this.sources = [])).push(evtSrc); } }); out$.GlobalAudit = GlobalAudit = React.createClass({ displayName: 'GlobalAudit', render: function(){ return AuditTable({ src: '/api/audit/all', caption: 'All recent audit events' }); } }); urlOfRole = function(role){ return "/api/audit/roles/" + encodeURIComponent(role); }; urlOfResource = function(resource){ return "/api/audit/resources/" + encodeURIComponent(resource); }; out$.AuditBox = AuditBox = React.createClass({ displayName: 'AuditBox', render: function(){ var roles, resources, roleSrcs, resSrcs, things; roles = this.props.roles || []; resources = this.props.resources || []; roleSrcs = map(urlOfRole)( roles); resSrcs = map(urlOfResource)( resources); things = join(', ')( unique( roles.concat(resources))); return AuditTable({ src: roleSrcs.concat(resSrcs), caption: "Recent audit events for " + things }); } }); function clone$(it){ function fun(){} fun.prototype = it; return new fun; } }).call(this);