public/js/views/mixins/tabs.js in conjur-asset-ui-1.3.0 vs public/js/views/mixins/tabs.js in conjur-asset-ui-1.3.1

- old
+ new

@@ -1,114 +1,154 @@ /** @jsx React.DOM */ +/* global conjur, React, ReactBootstrap, _ */ -(function(conjur, ReactBootstrap) { +(function(conjur, React, ReactBootstrap, _) { 'use strict'; - var TabbedArea = ReactBootstrap.TabbedArea, - TabPane = ReactBootstrap.TabPane, - OwnedResources = conjur.views.OwnedResources; + var TabPane = ReactBootstrap.TabPane, + OwnedResources = conjur.views.OwnedResources, + RoleLink = conjur.views.RoleLink, + AnnotationsBox = conjur.views.AnnotationsBox, + Permissions = conjur.views.Permissions; // we can't create custom TabPanes as components, // because they won't be recognized by TabbedArea as tabs // that's why we just generalize their constructors - conjur.views.mixins.Tab = { - lexical_sorter: function(a,b) { - + this.Tab = { + containsOwnedItems: function() { + return ( + this.props.data.owned && + this.props.data.owned.length && + this.props.data.owned.length > 0 + ); }, - contains_owned_items: function() { - return (this.props.data.owned && this.props.data.owned.length && this.props.data.owned.length > 0 ); - }, - - owned_ids: function() { - if (this.contains_owned_items()) { - return this.props.data.owned.map(function(owned_item) { - return owned_item.id; + ownedIds: function() { + if (this.containsOwnedItems()) { + return this.props.data.owned.map(function(ownedItem) { + return ownedItem.id; }); } return []; }, - owned_tab: function() { - if (this.contains_owned_items()) { - var result = - <TabPane key="owned" tab={get_tabname("Owned resources",this.props.data.owned)}> - <OwnedResources owned={this.props.data.owned} tabview={true} /> - </TabPane>; + ownedTab: function() { + if (this.containsOwnedItems()) { + var result = ( + <TabPane key="owned" + tab={conjur.utils.getTabname('Owned resources', this.props.data.owned)}> + <OwnedResources owned={this.props.data.owned} tabview={true} /> + </TabPane> + ); return result; } return null; }, - contains_nontrivial_roles: function() { - return (this.props.data.roles && this.props.data.roles.length && this.props.data.roles.length>1); + containsNontrivialRoles: function() { + return ( + this.props.data.roles && + this.props.data.roles.length && + this.props.data.roles.length > 1 + ); }, - external_roles: function( own_id ) { - if (!this.contains_nontrivial_roles()) { + externalRoles: function(ownId) { + if (!this.containsNontrivialRoles()) { return []; } - var owned_ids = this.owned_ids(); + var ownedIds = this.ownedIds(); return this.props.data.roles.filter(function(roleid) { // do not show themself - return roleid!=own_id; + return roleid !== ownId; }).filter(function(roleid) { // do not show internal roles - return ! (roleid.split(':')[1]=='@') ; + return roleid.split(':')[1] !== '@'; }).filter(function(roleid) { // do not show owned groups - return ! _.contains(owned_ids, roleid); + return ! _.contains(ownedIds, roleid); }); }, - memberships_tab: function( own_id ) { - if (!this.contains_nontrivial_roles()) { + membershipsTab: function(ownId) { + if (!this.containsNontrivialRoles()) { return null; } - var membership_links = this.external_roles(own_id) - .sort( function(a,b) { return a.toLowerCase().localeCompare(b.toLowerCase());} ) - .map ( function(roleid) { return <li className="list-group-item list-group-item-noborder"><RoleLink id={roleid}/></li> }); + var membershipLinks = this.externalRoles(ownId) + .sort(function(a, b) { + return a.toLowerCase().localeCompare(b.toLowerCase()); + }) + .map(function(roleid) { + return ( + <li className="list-group-item list-group-item-noborder"> + <RoleLink id={roleid} /> + </li> + ); + }); - if (membership_links.length==0) { return null; } + if (membershipLinks.length === 0) { + return null; + } - var result = - <TabPane key="memberships" tab={get_tabname("Explicit memberships", membership_links)}> - <ul className="list-group">{membership_links}</ul> - </TabPane>; + var result = ( + <TabPane key="memberships" + tab={conjur.utils.getTabname('Explicit memberships', membershipLinks)}> + <ul className="list-group"> + {membershipLinks} + </ul> + </TabPane> + ); return result; - } , + }, - contains_annotations: function() { - return (this.props.data.annotations && this.props.data.annotations.length && this.props.data.annotations.length>0); + containsAnnotations: function() { + return ( + this.props.data.annotations && + this.props.data.annotations.length && + this.props.data.annotations.length > 0 + ); }, - annotations_tab: function() { - if (!this.contains_annotations()) { + annotationsTab: function() { + if (!this.containsAnnotations()) { return null; } - var result = - <TabPane key="annotations" tab={get_tabname("Annotations",this.props.data.annotations)}> - <AnnotationsBox annotations={this.props.data.annotations}/> - </TabPane>; + var result = ( + <TabPane key="annotations" + tab={conjur.utils.getTabname('Annotations', this.props.data.annotations)}> + <AnnotationsBox annotations={this.props.data.annotations} /> + </TabPane> + ); return result; }, - permissions_tab: function(roleid) { - var result = - <TabPane key="permissions" tab="Permissions held"> - <Permissions owned={this.props.data.owned} roles={this.props.data.roles} role={roleid} tabview={true}/> - </TabPane>; + permissionsTab: function(roleid) { + var result = ( + <TabPane key="permissions" tab="Permissions held"> + <Permissions owned={this.props.data.owned} + roles={this.props.data.roles} + role={roleid} + tabview={true} /> + </TabPane> + ); return result; } }; -})(conjur, ReactBootstrap); + +}).bind(conjur.views.mixins) +( + conjur, + React, + ReactBootstrap, + _ +);