conjur-asset-ui 1.4.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -3
- data/CHANGELOG.md +10 -0
- data/Makefile +19 -0
- data/README.md +0 -3
- data/Rakefile +22 -17
- data/TODO.md +0 -23
- data/app/.csscomb.json +304 -0
- data/app/.eslintignore +3 -0
- data/app/.eslintrc +265 -0
- data/app/config/preprocessor.js +19 -0
- data/app/config/webpack.js +124 -0
- data/app/gulpfile.js +96 -0
- data/app/package.json +86 -0
- data/app/src/actions.js +550 -0
- data/app/src/app.js +83 -0
- data/app/src/clients/audit.js +34 -0
- data/app/src/clients/auth.js +24 -0
- data/app/src/clients/generic.js +52 -0
- data/app/src/clients/graph.js +7 -0
- data/app/src/clients/layer_members.js +18 -0
- data/app/src/clients/list.js +31 -0
- data/app/src/clients/members.js +20 -0
- data/app/src/clients/request.js +531 -0
- data/app/src/clients/search.js +5 -0
- data/app/src/components/app/__tests__/app-test.js +22 -0
- data/app/src/components/app/app.js +36 -0
- data/app/src/components/app/wrapper.js +17 -0
- data/app/src/components/audit/__tests__/table_header-test.js +22 -0
- data/app/src/components/audit/box.js +9 -0
- data/app/src/components/audit/constants.js +5 -0
- data/app/src/components/audit/entry.js +105 -0
- data/app/src/components/audit/fields_mixin.js +11 -0
- data/app/src/components/audit/humanize_event.js +213 -0
- data/app/src/components/audit/table.js +64 -0
- data/app/src/components/audit/table_header.js +37 -0
- data/app/src/components/audit/timestamp.js +28 -0
- data/app/src/components/auth/login.js +177 -0
- data/app/src/components/auth/login.less +71 -0
- data/app/src/components/auth/logout.js +42 -0
- data/app/src/components/auth/logout.less +21 -0
- data/app/src/components/chart/chart.js +540 -0
- data/app/src/components/chart/chart_helper_mixin.js +78 -0
- data/app/src/components/custom/list.js +3 -0
- data/app/src/components/custom/view.js +81 -0
- data/app/src/components/dashboard/activity.js +144 -0
- data/app/src/components/dashboard/dashboard.js +46 -0
- data/app/src/components/flash/flash.js +98 -0
- data/app/src/components/flash/flash.less +3 -0
- data/app/src/components/generic/__tests__/time-test.js +42 -0
- data/app/src/components/generic/annotations.js +39 -0
- data/app/src/components/generic/breadcrumbs.js +57 -0
- data/app/src/components/generic/foldable_audit_section.js +204 -0
- data/app/src/components/generic/list.js +141 -0
- data/app/src/components/generic/list_factory.js +41 -0
- data/app/src/components/generic/resource_link.js +64 -0
- data/app/src/components/generic/role_link.js +66 -0
- data/app/src/components/generic/tab_mixin.js +146 -0
- data/app/src/components/generic/time.js +32 -0
- data/app/src/components/graph/__tests__/collapse-test.js +133 -0
- data/app/src/components/graph/__tests__/edges-from-vertices-test.js +48 -0
- data/app/src/components/graph/__tests__/new-vertex-set-test.js +16 -0
- data/app/src/components/graph/__tests__/next-id-test.js +27 -0
- data/app/src/components/graph/__tests__/role-kind-from-id-test.js +24 -0
- data/app/src/components/graph/__tests__/vertices-from-edges-test.js +72 -0
- data/app/src/components/graph/graph.js +449 -0
- data/app/src/components/graph/graph.less +39 -0
- data/app/src/components/graph/helpers.js +368 -0
- data/app/src/components/group/list.js +3 -0
- data/app/src/components/group/view.js +153 -0
- data/app/src/components/host/activity.js +111 -0
- data/app/src/components/host/details.js +28 -0
- data/app/src/components/host/executors.js +77 -0
- data/app/src/components/host/host_link.js +18 -0
- data/app/src/components/host/list.js +3 -0
- data/app/src/components/host/updaters.js +77 -0
- data/app/src/components/host/view.js +145 -0
- data/app/src/components/layer/list.js +3 -0
- data/app/src/components/layer/view.js +197 -0
- data/app/src/components/navbar/__tests__/navbar-test.js +21 -0
- data/app/src/components/navbar/nav_search_form.js +40 -0
- data/app/src/components/navbar/navbar.js +96 -0
- data/app/src/components/notfound/notfound.js +35 -0
- data/app/src/components/notfound/notfound.less +21 -0
- data/app/src/components/owned_resources/owned_resources.js +84 -0
- data/app/src/components/owned_resources/owned_resources_box.js +101 -0
- data/app/src/components/permissions/permissions.js +138 -0
- data/app/src/components/permissions/permissions_table.js +101 -0
- data/app/src/components/policy/list.js +3 -0
- data/app/src/components/policy/view.js +107 -0
- data/app/src/components/refresh/refresh.js +29 -0
- data/app/src/components/refresh/refresh.less +15 -0
- data/app/src/components/search/group.js +43 -0
- data/app/src/components/search/group_heading.js +50 -0
- data/app/src/components/search/group_title.js +37 -0
- data/app/src/components/search/result_item.js +55 -0
- data/app/src/components/search/search.js +118 -0
- data/app/src/components/user/activity.js +112 -0
- data/app/src/components/user/details.js +30 -0
- data/app/src/components/user/list.js +3 -0
- data/app/src/components/user/pubkeys.js +118 -0
- data/app/src/components/user/pubkeys.less +56 -0
- data/app/src/components/user/view.js +143 -0
- data/app/src/components/variable/activity.js +101 -0
- data/app/src/components/variable/details.js +46 -0
- data/app/src/components/variable/fetchers.js +77 -0
- data/app/src/components/variable/list.js +3 -0
- data/app/src/components/variable/updaters.js +77 -0
- data/app/src/components/variable/view.js +115 -0
- data/app/src/constants.js +36 -0
- data/{public → app/src}/images/conjur-logo.svg +0 -0
- data/{public → app/src}/images/icon-client-pc.svg +0 -0
- data/{public → app/src}/images/icon-environment.png +0 -0
- data/{public → app/src}/images/icon-person.svg +0 -0
- data/{public → app/src}/images/icon-policy.png +0 -0
- data/{public → app/src}/images/icon-resource.png +0 -0
- data/{public → app/src}/images/icon-service-dots.svg +0 -0
- data/{public → app/src}/images/icon-variable.png +0 -0
- data/app/src/pages/index.html +27 -0
- data/app/src/routes.js +64 -0
- data/app/src/stores/app_store.js +35 -0
- data/app/src/stores/audit_store.js +143 -0
- data/app/src/stores/graph_store.js +51 -0
- data/app/src/stores/group_store.js +104 -0
- data/app/src/stores/host_store.js +111 -0
- data/app/src/stores/layer_store.js +115 -0
- data/app/src/stores/policy_store.js +88 -0
- data/app/src/stores/resources_store.js +115 -0
- data/app/src/stores/route_store.js +21 -0
- data/app/src/stores/search_store.js +77 -0
- data/app/src/stores/user_store.js +109 -0
- data/app/src/stores/variable_store.js +93 -0
- data/app/src/styles/bootstrap.less +54 -0
- data/{public/css → app/src/styles}/styles.less +26 -82
- data/app/src/utils.js +38 -0
- data/app/src/vendor/pace.js +2 -0
- data/conjur-asset-ui.gemspec +3 -4
- data/docker/assets-build/Dockerfile +12 -0
- data/docker/conjur-ui/Dockerfile +33 -0
- data/docker/conjur-ui/README.md +38 -0
- data/docker/conjur-ui/mime.types +90 -0
- data/docker/conjur-ui/nginx.conf +110 -0
- data/docker/conjur-ui/start.py +72 -0
- data/docker/conjur-ui/start.sh +18 -0
- data/docker/conjur-ui/test.env +8 -0
- data/lib/conjur-asset-ui-version.rb +1 -1
- data/lib/conjur/command/ui.rb +10 -2
- data/lib/conjur/webserver/home.rb +3 -3
- data/lib/conjur/webserver/login.rb +1 -1
- data/lib/conjur/webserver/server.rb +16 -4
- data/public/js/views/roleGraph.js +91 -0
- metadata +167 -105
- data/.jshintrc +0 -41
- data/bower.json +0 -98
- data/gulpfile.js +0 -139
- data/package.json +0 -47
- data/preprocessor.js +0 -7
- data/public/_client_libs.html +0 -9
- data/public/index.html.erb +0 -63
- data/public/js/init.js +0 -196
- data/public/js/lib/pace.js +0 -2
- data/public/js/lib/sorted-set.no-require.js +0 -1145
- data/public/js/lib/sorted-set.no-require.js.txt +0 -6
- data/public/js/models/groupRecord.js +0 -72
- data/public/js/models/hostRecord.js +0 -60
- data/public/js/models/layerRecord.js +0 -79
- data/public/js/models/namespace.js +0 -12
- data/public/js/models/policyList.js +0 -16
- data/public/js/models/policyRecord.js +0 -54
- data/public/js/models/record.js +0 -117
- data/public/js/models/resourceList.js +0 -87
- data/public/js/models/userList.js +0 -25
- data/public/js/models/userRecord.js +0 -75
- data/public/js/models/variableList.js +0 -27
- data/public/js/models/variableRecord.js +0 -77
- data/public/js/routers.js +0 -242
- data/public/js/views/annotations.js +0 -47
- data/public/js/views/audit.js +0 -369
- data/public/js/views/breadcrumbs.js +0 -62
- data/public/js/views/chart.js +0 -617
- data/public/js/views/dashboard.js +0 -146
- data/public/js/views/generic.js +0 -122
- data/public/js/views/group.js +0 -109
- data/public/js/views/groups.js +0 -26
- data/public/js/views/host.js +0 -200
- data/public/js/views/hosts.js +0 -26
- data/public/js/views/layer.js +0 -146
- data/public/js/views/layers.js +0 -26
- data/public/js/views/mixins/search.js +0 -22
- data/public/js/views/mixins/tabs.js +0 -154
- data/public/js/views/namespaces.js +0 -40
- data/public/js/views/navSearch.js +0 -36
- data/public/js/views/owned.js +0 -184
- data/public/js/views/permissions.js +0 -254
- data/public/js/views/policies.js +0 -26
- data/public/js/views/policy.js +0 -70
- data/public/js/views/resource.js +0 -59
- data/public/js/views/role.js +0 -63
- data/public/js/views/searchResults.js +0 -212
- data/public/js/views/sections.js +0 -226
- data/public/js/views/time.js +0 -39
- data/public/js/views/user.js +0 -297
- data/public/js/views/users.js +0 -26
- data/public/js/views/variable.js +0 -310
- data/public/js/views/variables.js +0 -26
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/support/jasmine.yml +0 -112
- data/spec/javascripts/support/jasmine_helper.rb +0 -22
- data/spec/javascripts/support/run.html.erb +0 -23
- data/spec/javascripts/views/AuditSpec.js +0 -22
- data/spec/javascripts/views/AuditSpec.ls +0 -18
@@ -0,0 +1,41 @@
|
|
1
|
+
var React = require('react'),
|
2
|
+
Fluxxor = require('fluxxor');
|
3
|
+
|
4
|
+
var FluxMixin = Fluxxor.FluxMixin(React),
|
5
|
+
StoreWatchMixin = Fluxxor.StoreWatchMixin;
|
6
|
+
|
7
|
+
var GenericList = require('./list'),
|
8
|
+
Refresh = require('../refresh/refresh');
|
9
|
+
|
10
|
+
export default function listFactory(kind, title) {
|
11
|
+
return React.createClass({
|
12
|
+
displayName: title + 'List',
|
13
|
+
|
14
|
+
mixins: [FluxMixin, StoreWatchMixin('resources')],
|
15
|
+
|
16
|
+
getStateFromFlux() {
|
17
|
+
var resources = this.getFlux().store('resources').getResources(kind);
|
18
|
+
|
19
|
+
return {
|
20
|
+
loading: resources.loading,
|
21
|
+
error: resources.error,
|
22
|
+
resources: resources.data
|
23
|
+
};
|
24
|
+
},
|
25
|
+
|
26
|
+
render() {
|
27
|
+
return (
|
28
|
+
<div className="variableBox">
|
29
|
+
<div className="variableList">
|
30
|
+
<h2>{title}<Refresh show={this.state.loading} /></h2>
|
31
|
+
<GenericList data={{kind: kind, members: this.state.resources}} />
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
);
|
35
|
+
},
|
36
|
+
|
37
|
+
componentDidMount() {
|
38
|
+
this.getFlux().actions.resources.load(kind);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
var React = require('react'),
|
2
|
+
Link = require('react-router').Link;
|
3
|
+
|
4
|
+
import {includes} from 'lodash';
|
5
|
+
|
6
|
+
/**
|
7
|
+
Renders a link to the resource with id given by this.props.data.
|
8
|
+
|
9
|
+
Includes a slick little icon for the following kinds:
|
10
|
+
TODO which kinds?
|
11
|
+
**/
|
12
|
+
export default React.createClass({
|
13
|
+
displayName: 'ResourceLink',
|
14
|
+
|
15
|
+
knownTypes: ['user', 'group', 'layer', 'host', 'variable', 'policy'],
|
16
|
+
|
17
|
+
render() {
|
18
|
+
var resourceId = this.props.id;
|
19
|
+
|
20
|
+
// guard against misuse such as https://github.com/conjurinc/conjur-asset-ui/issues/78
|
21
|
+
if (typeof resourceId === 'undefined') {
|
22
|
+
return (
|
23
|
+
<em>undefined</em>
|
24
|
+
);
|
25
|
+
}
|
26
|
+
|
27
|
+
var tokens = resourceId.split(':'),
|
28
|
+
kind = tokens[1],
|
29
|
+
id = tokens[tokens.length - 1],
|
30
|
+
text = this.props.text || id;
|
31
|
+
|
32
|
+
var resourceIsKnown = includes(this.knownTypes, kind),
|
33
|
+
classes = ['resource-link'];
|
34
|
+
|
35
|
+
if (!this.props.noIcon) {
|
36
|
+
if (resourceIsKnown) {
|
37
|
+
classes.push(kind);
|
38
|
+
} else {
|
39
|
+
classes.push('abstract');
|
40
|
+
|
41
|
+
if (text === id) {
|
42
|
+
text = [kind, text].join(':'); // prepend kind to id
|
43
|
+
}
|
44
|
+
}
|
45
|
+
} else if (text === id) {
|
46
|
+
text = [kind, text].join(':'); // prepend kind to id
|
47
|
+
}
|
48
|
+
|
49
|
+
if (resourceIsKnown) {
|
50
|
+
return (
|
51
|
+
<Link to={kind} params={{id: window.encodeURIComponent(id)}}
|
52
|
+
className={classes.join(' ')}>
|
53
|
+
{text}
|
54
|
+
</Link>
|
55
|
+
);
|
56
|
+
} else {
|
57
|
+
return (
|
58
|
+
<a href="#" className={classes.join(' ')}>
|
59
|
+
{text}
|
60
|
+
</a>
|
61
|
+
);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
});
|
@@ -0,0 +1,66 @@
|
|
1
|
+
var React = require('react'),
|
2
|
+
Router = require('react-router');
|
3
|
+
|
4
|
+
import {includes} from 'lodash';
|
5
|
+
|
6
|
+
var Link = Router.Link;
|
7
|
+
|
8
|
+
/** render a link to the role represented by this.props.id
|
9
|
+
Example: <RoleLink id='ci:user:jon'/>
|
10
|
+
*/
|
11
|
+
export default React.createClass({
|
12
|
+
displayName: 'RoleLink',
|
13
|
+
|
14
|
+
knownTypes: ['user', 'group', 'layer', 'host', 'policy'],
|
15
|
+
|
16
|
+
render() {
|
17
|
+
// guard against misuse such as https://github.com/conjurinc/conjur-asset-ui/issues/78
|
18
|
+
if (typeof this.props.id === 'undefined') {
|
19
|
+
return (
|
20
|
+
<em>undefined</em>
|
21
|
+
);
|
22
|
+
}
|
23
|
+
|
24
|
+
var tokens = this.props.id.split(':'),
|
25
|
+
kind = tokens[1],
|
26
|
+
id = tokens[tokens.length-1];
|
27
|
+
|
28
|
+
if (tokens.length === 1) { // just username
|
29
|
+
kind = 'user';
|
30
|
+
id = tokens[0];
|
31
|
+
}
|
32
|
+
|
33
|
+
var kindIsKnown = includes(this.knownTypes, kind),
|
34
|
+
text = id,
|
35
|
+
classes = ['role-link'];
|
36
|
+
|
37
|
+
if (!this.props.noIcon) {
|
38
|
+
if (kindIsKnown) {
|
39
|
+
classes.push(kind);
|
40
|
+
} else {
|
41
|
+
classes.push('abstract'); // we have no picture for abstract role yet
|
42
|
+
|
43
|
+
if (text === id) {
|
44
|
+
text = [kind, text].join(':'); // prepend kind to id
|
45
|
+
}
|
46
|
+
}
|
47
|
+
} else if (text === id) {
|
48
|
+
text = [kind, text].join(':'); // prepend kind to id
|
49
|
+
}
|
50
|
+
|
51
|
+
if (kindIsKnown) {
|
52
|
+
return (
|
53
|
+
<Link to={kind} params={{id: window.encodeURIComponent(id)}}
|
54
|
+
className={classes.join(' ')} style={this.props.style}>
|
55
|
+
{text}
|
56
|
+
</Link>
|
57
|
+
);
|
58
|
+
} else {
|
59
|
+
return (
|
60
|
+
<a href="#" className={classes.join(' ')} style={this.props.style}>
|
61
|
+
{text}
|
62
|
+
</a>
|
63
|
+
);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
});
|
@@ -0,0 +1,146 @@
|
|
1
|
+
var React = require('react');
|
2
|
+
|
3
|
+
var TabPane = require('react-bootstrap/lib/TabPane');
|
4
|
+
|
5
|
+
var OwnedResources = require('../owned_resources/owned_resources'),
|
6
|
+
RoleLink = require('./role_link'),
|
7
|
+
Annotations = require('./annotations'),
|
8
|
+
Permissions = require('../permissions/permissions');
|
9
|
+
|
10
|
+
import {getTabname} from '../../utils';
|
11
|
+
import {includes} from 'lodash';
|
12
|
+
|
13
|
+
// we can't create custom TabPanes as components,
|
14
|
+
// because they won't be recognized by TabbedArea as tabs
|
15
|
+
// that's why we just generalize their constructors
|
16
|
+
export default {
|
17
|
+
containsOwnedItems() {
|
18
|
+
return (
|
19
|
+
this.state.owned &&
|
20
|
+
this.state.owned.length &&
|
21
|
+
this.state.owned.length > 0
|
22
|
+
);
|
23
|
+
},
|
24
|
+
|
25
|
+
ownedIds() {
|
26
|
+
if (this.containsOwnedItems()) {
|
27
|
+
return this.state.owned.map(function(ownedItem) {
|
28
|
+
return ownedItem.id;
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
return [];
|
33
|
+
},
|
34
|
+
|
35
|
+
ownedTab() {
|
36
|
+
if (this.containsOwnedItems()) {
|
37
|
+
var result = (
|
38
|
+
<TabPane eventKey="owned"
|
39
|
+
tab={getTabname('Owned resources', this.state.owned)}>
|
40
|
+
<OwnedResources owned={this.state.owned} tabview={true} />
|
41
|
+
</TabPane>
|
42
|
+
);
|
43
|
+
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
|
47
|
+
return null;
|
48
|
+
},
|
49
|
+
|
50
|
+
containsNontrivialRoles() {
|
51
|
+
return (
|
52
|
+
this.state.roles &&
|
53
|
+
this.state.roles.length &&
|
54
|
+
this.state.roles.length > 1
|
55
|
+
);
|
56
|
+
},
|
57
|
+
|
58
|
+
externalRoles(ownId) {
|
59
|
+
if (!this.containsNontrivialRoles()) {
|
60
|
+
return [];
|
61
|
+
}
|
62
|
+
|
63
|
+
var ownedIds = this.ownedIds();
|
64
|
+
|
65
|
+
return this.state.roles.filter(function(roleid) {
|
66
|
+
// do not show themself
|
67
|
+
return roleid !== ownId;
|
68
|
+
}).filter(function(roleid) {
|
69
|
+
// do not show internal roles
|
70
|
+
return roleid.split(':')[1] !== '@';
|
71
|
+
}).filter(function(roleid) {
|
72
|
+
// do not show owned groups
|
73
|
+
return !includes(ownedIds, roleid);
|
74
|
+
});
|
75
|
+
},
|
76
|
+
|
77
|
+
membershipsTab(ownId) {
|
78
|
+
if (!this.containsNontrivialRoles()) {
|
79
|
+
return null;
|
80
|
+
}
|
81
|
+
|
82
|
+
var membershipLinks = this.externalRoles(ownId)
|
83
|
+
.sort(function(a, b) {
|
84
|
+
return a.toLowerCase().localeCompare(b.toLowerCase());
|
85
|
+
})
|
86
|
+
.map(function(roleid) {
|
87
|
+
return (
|
88
|
+
<li className="list-group-item list-group-item-noborder">
|
89
|
+
<RoleLink id={roleid} />
|
90
|
+
</li>
|
91
|
+
);
|
92
|
+
});
|
93
|
+
|
94
|
+
if (membershipLinks.length === 0) {
|
95
|
+
return null;
|
96
|
+
}
|
97
|
+
|
98
|
+
var result = (
|
99
|
+
<TabPane eventKey="memberships"
|
100
|
+
tab={getTabname('Explicit memberships', membershipLinks)}>
|
101
|
+
<ul className="list-group">
|
102
|
+
{membershipLinks}
|
103
|
+
</ul>
|
104
|
+
</TabPane>
|
105
|
+
);
|
106
|
+
|
107
|
+
return result;
|
108
|
+
},
|
109
|
+
|
110
|
+
containsAnnotations() {
|
111
|
+
return (
|
112
|
+
this.state.annotations &&
|
113
|
+
this.state.annotations.length &&
|
114
|
+
this.state.annotations.length > 0
|
115
|
+
);
|
116
|
+
},
|
117
|
+
|
118
|
+
annotationsTab() {
|
119
|
+
if (!this.containsAnnotations()) {
|
120
|
+
return null;
|
121
|
+
}
|
122
|
+
|
123
|
+
var result = (
|
124
|
+
<TabPane eventKey="annotations"
|
125
|
+
tab={getTabname('Annotations', this.state.annotations)}>
|
126
|
+
<Annotations annotations={this.state.annotations} />
|
127
|
+
</TabPane>
|
128
|
+
);
|
129
|
+
|
130
|
+
return result;
|
131
|
+
},
|
132
|
+
|
133
|
+
permissionsTab(roleid) {
|
134
|
+
var result = (
|
135
|
+
<TabPane eventKey="permissions" tab="Permissions held">
|
136
|
+
<Permissions owned={this.state.owned}
|
137
|
+
roles={this.state.roles}
|
138
|
+
role={roleid}
|
139
|
+
resources={this.state.resources}
|
140
|
+
tabview={true} />
|
141
|
+
</TabPane>
|
142
|
+
);
|
143
|
+
|
144
|
+
return result;
|
145
|
+
}
|
146
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var React = require('react'),
|
2
|
+
moment = require('moment');
|
3
|
+
|
4
|
+
// render a <time> tag. props.timestamp should be a timestamp
|
5
|
+
// that moment can parse, props.format should be one of the
|
6
|
+
// format strings accepted by moment (optional).
|
7
|
+
export default React.createClass({
|
8
|
+
displayName: 'Time',
|
9
|
+
|
10
|
+
render() {
|
11
|
+
var timestamp = this.props.timestamp,
|
12
|
+
tsFormat = this.props.tsFormat || '',
|
13
|
+
format = this.props.format || 'lll',
|
14
|
+
m = moment(timestamp, tsFormat),
|
15
|
+
date;
|
16
|
+
|
17
|
+
switch (this.props.relative) {
|
18
|
+
case 'time from now':
|
19
|
+
date = m.fromNow();
|
20
|
+
break;
|
21
|
+
case 'calendar time':
|
22
|
+
date = m.calendar();
|
23
|
+
break;
|
24
|
+
default:
|
25
|
+
date = m.format(format);
|
26
|
+
}
|
27
|
+
|
28
|
+
return (
|
29
|
+
<time dateTime={m.format()}>{date}</time>
|
30
|
+
);
|
31
|
+
}
|
32
|
+
});
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/* global jest, describe, it, expect */
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
|
5
|
+
jest.dontMock('lodash');
|
6
|
+
jest.dontMock('collections/set');
|
7
|
+
jest.dontMock('../helpers');
|
8
|
+
|
9
|
+
var {find} = require('lodash');
|
10
|
+
var Set = require('collections/set');
|
11
|
+
var {collapse, edgesFromVertices, __test__:{SingleVertex}} = require('../helpers');
|
12
|
+
|
13
|
+
/*
|
14
|
+
The graph has the following structure:
|
15
|
+
|
16
|
+
user:admin -> group:a group:b group:c group:d user:a user:b layer:e
|
17
|
+
group:a, group:b, group:c -> user:c, user:d
|
18
|
+
group:d -> user:e
|
19
|
+
user:c, user:d -> user:e
|
20
|
+
|
21
|
+
When collapsed it should look like
|
22
|
+
|
23
|
+
user:admin -> [3 groups (a,b,c)], group:d, [2 users (a,b)], layer:e
|
24
|
+
[3 groups(a,b,c)] -> [2 users(c,d)]
|
25
|
+
[2 users(c,d)] -> user:e
|
26
|
+
group:d -> user:e
|
27
|
+
|
28
|
+
*/
|
29
|
+
|
30
|
+
|
31
|
+
// helpers
|
32
|
+
function shouldContain(set_, predicate){
|
33
|
+
expect(find(set_.toArray(), predicate)).toBe(true);
|
34
|
+
}
|
35
|
+
|
36
|
+
function shouldHaveChild(vertex, predicate){
|
37
|
+
shouldContain(vertex.out, predicate);
|
38
|
+
}
|
39
|
+
|
40
|
+
function shouldHaveParent(vertex, predicate){
|
41
|
+
shouldContain(vertex.in, predicate);
|
42
|
+
}
|
43
|
+
|
44
|
+
function shouldContainMultis(set_, idLists){
|
45
|
+
idLists.forEach(
|
46
|
+
(idList) => {
|
47
|
+
expect(find(set_.toArray(),
|
48
|
+
(v) => {
|
49
|
+
if(v.isSingle()) return false;
|
50
|
+
return v.members.equals(new Set(idList));
|
51
|
+
}
|
52
|
+
)).toBeTruthy()
|
53
|
+
}
|
54
|
+
);
|
55
|
+
}
|
56
|
+
|
57
|
+
function shouldContainSingles(set_, ids){
|
58
|
+
ids.forEach(
|
59
|
+
(id) => {
|
60
|
+
expect(set_.has(new SingleVertex(id))).toBeTruthy();
|
61
|
+
}
|
62
|
+
)
|
63
|
+
}
|
64
|
+
|
65
|
+
class GraphBuilder {
|
66
|
+
constructor(){
|
67
|
+
this._vs = {}; // maps id to vertex
|
68
|
+
}
|
69
|
+
|
70
|
+
connect(parentIds, childIds){
|
71
|
+
parentIds = typeof parentIds === 'string' ? [parentIds] : parentIds;
|
72
|
+
childIds = typeof childIds === 'string' ? [childIds] : childIds;
|
73
|
+
parentIds.forEach(
|
74
|
+
(pId) => {
|
75
|
+
var p = this._vertex(pId);
|
76
|
+
childIds.forEach(
|
77
|
+
(cId) => {
|
78
|
+
p.addChild(this._vertex(cId));
|
79
|
+
}
|
80
|
+
);
|
81
|
+
}
|
82
|
+
);
|
83
|
+
return this;
|
84
|
+
}
|
85
|
+
|
86
|
+
vertices(){
|
87
|
+
return Object.values(this._vs);
|
88
|
+
}
|
89
|
+
|
90
|
+
edges(){
|
91
|
+
return edgesFromVertices(this.vertices());
|
92
|
+
}
|
93
|
+
|
94
|
+
_vertex(id){
|
95
|
+
return this._vs[id] || (this._vs[id] = new SingleVertex(id));
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
describe("collapsing a simple graph", ()=>{
|
101
|
+
var initialGraph = new GraphBuilder()
|
102
|
+
.connect('user:admin', ['group:a', 'group:b', 'group:c', 'group:d',
|
103
|
+
'user:a', 'user:b',
|
104
|
+
'layer:e'])
|
105
|
+
.connect(['group:a', 'group:b', 'group:c'], ['user:c', 'user:d'])
|
106
|
+
.connect('group:d', 'user:e')
|
107
|
+
.connect(['user:c', 'user:d'], 'user:e')
|
108
|
+
.vertices();
|
109
|
+
|
110
|
+
var collapsed = collapse(initialGraph, 1);
|
111
|
+
})
|
112
|
+
|
113
|
+
|
114
|
+
//console.dir(collapsed.map((v) => v.toString()));
|
115
|
+
//collapsed.forEach(
|
116
|
+
// (v) => {
|
117
|
+
// console.log('v = ' + v.toString());
|
118
|
+
// console.log(' in: ');
|
119
|
+
// v.in.forEach(
|
120
|
+
// (vIn) => {
|
121
|
+
// console.log(' ' + vIn.toString())
|
122
|
+
// }
|
123
|
+
// );
|
124
|
+
// console.log(' out: ');
|
125
|
+
// v.out.forEach(
|
126
|
+
// (vOut) => {
|
127
|
+
// console.log(' ' + vOut.toString())
|
128
|
+
// }
|
129
|
+
// );
|
130
|
+
// console.log('-----------------');
|
131
|
+
// console.log('');
|
132
|
+
// }
|
133
|
+
//);
|