Merge pull request #601 from CartoDB/CDB-3522

Added shared count close to the privacy status in the table view
pull/605/head
Javier Álvarez Medina 10 years ago
commit d165c3793d

@ -223,17 +223,15 @@
&.share, &.data_download { font-weight:500; }
&.privacy {
padding: 0 14px 0 0;
padding: 0 9px 0 0;
text-shadow: none;
/*@include simple-transition(all, 150ms);*/
@include box-shadow(0px 0px 0px 3px rgba(#333, .1));
&.public i { background: rgba(#97C341, .5) sprite($table-sprites, lock_open, $offset-x: 12px, $offset-y: 4px) no-repeat; }
&.link_protected i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_open, $offset-x: 12px, $offset-y: 4px) no-repeat; }
&.password_protected i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_key, $offset-x: 12px, $offset-y: 4px) no-repeat; }
&.organization i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_user, $offset-x: 12px, $offset-y: 4px) no-repeat; }
&.private i { background: rgba(#FF7373, .5) sprite( $table-sprites, lock_closed, $offset-x: 12px, $offset-y: 4px) no-repeat; }
&.public i { background: rgba(#97C341, .5) sprite($table-sprites, lock_open, $offset-x: 8px, $offset-y: 4px) no-repeat; }
&.link_protected i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_open, $offset-x: 8px, $offset-y: 4px) no-repeat; }
&.password_protected i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_key, $offset-x: 8px, $offset-y: 4px) no-repeat; }
&.organization i { background: rgba(#FFA64D, .5) sprite( $table-sprites, lock_user, $offset-x: 8px, $offset-y: 4px) no-repeat; }
&.private i { background: rgba(#FF7373, .5) sprite( $table-sprites, lock_closed, $offset-x: 8px, $offset-y: 4px) no-repeat; }
&.public i:hover { background-color: rgba(#97C341, .65); }
&.link_protected i:hover { background-color: rgba(#FFA64D, .65); }
@ -243,26 +241,37 @@
span { vertical-align: middle; }
&:hover {
color: #1D4569;
@include box-shadow(0px 0px 0px 3px rgba(#333, .2));
}
i {
@include inline-block();
width: 30px; height: 20px;
margin: 0 10px 0 0;
background: rgba(#EEE, .5) sprite($table-sprites, lock_open, $offset-x: 12px, $offset-y: 4px) no-repeat;
width:auto;
min-width:22px;
height: 20px;
margin: 0 5px 0 0;
background: rgba(#EEE, .5) sprite($table-sprites, lock_open, $offset-x: 8px, $offset-y: 4px) no-repeat;
border-right: 1px solid rgba(#000, .15);
@include simple-transition(all, 150ms);
@include border-radius(25px 0 0 25px);
span.shared_users {
margin-left:23px;
}
&.disabled {
@include opacity(0.5);
&:hover { cursor:default }
}
}
// Hover styles
&:hover {
@include box-shadow(0px 0px 0px 3px rgba(#333, .2));
& > span {
color:#3474AF;
&:hover { color: #1D4569 }
}
}
}
}

@ -17,7 +17,9 @@
<ul class="options">
<li><%= link_to "options", "#/options", :class => "dropdown options" %></li>
<li>
<a class="privacy rounded share" href="#/visualize"><i></i><span>VISUALIZE</span></a>
<a class="privacy rounded share" href="#/visualize">
<i class="privacy-status"></i>
<span>VISUALIZE</span></a>
</li>
</ul>
</div>

@ -103,11 +103,12 @@ cdb.admin.Header = cdb.core.View.extend({
},
createBindings: function() {
this.model.bind('change:name', this._setName, this);
this.model.bind('change:description', this._setDescription, this);
this.model.bind('change:tags', this._setTags, this);
this.model.bind('change:type', this.setInfo, this);
this.model.bind('change:privacy', this._updatePrivacy, this);
this.model.bind('change:name', this._setName, this);
this.model.bind('change:description', this._setDescription, this);
this.model.bind('change:tags', this._setTags, this);
this.model.bind('change:type', this.setInfo, this);
this.model.bind('change:privacy', this._updatePrivacy, this);
this.model.bind('change:permission', this._updateSharedCount, this);
},
_openOptionsMenu: function(e) {
@ -205,6 +206,9 @@ cdb.admin.Header = cdb.core.View.extend({
_updatePrivacy: function() {
// Update shared count if it is neccessary
this._updateSharedCount();
var $share = this.$('a.share');
var privacy = this.model.get("privacy").toLowerCase();
@ -261,6 +265,34 @@ cdb.admin.Header = cdb.core.View.extend({
},
_updateSharedCount: function() {
var isOwner = this.model.permission.isOwner(this.options.user);
var $share = this.$('a.share i');
$share.empty();
if (isOwner) {
var $count = $('<span>').addClass('shared_users');
if (this.model.permission.acl.size() > 0) {
// Get total shared users or if the whole organization has access
var shared_users = 0;
var users_perm = this.model.permission.getUsersWithAnyPermission();
var org_perm = this.model.permission.getUsersWithPermission('org');
if (this.model.permission.getUsersWithPermission('org').length > 0) {
shared_users = 'ORG';
} else {
shared_users = users_perm.length;
}
$count.text( (shared_users !== 0) ? shared_users : '' );
$share.append($count);
}
}
},
/**
* Set layer sync info if it is needed
*/

@ -358,14 +358,25 @@ describe("Table/Visualization Header tests", function() {
expect($(this.header.el).find('.privacy').hasClass('public')).toBeFalsy();
})
it("should add disable class when user is not the owner of the table", function() {
//this.user.organization = new cdb.admin.Organization({ id:1, users:[1,2] });
it("should add the number of shared users if the table/vis is shared and you are the owner", function() {
this.vis.permission.owner = this.user;
this.vis.permission.acl.reset([{ entity: {}, type: 'user', access: 'r' }]);
expect(this.header.$('.privacy.share i span.shared_users').text()).toBe('1');
this.vis.permission.acl.reset([{ entity: {}, type: 'org', access: 'r' }]);
expect(this.header.$('.privacy.share i span.shared_users').text()).toBe('ORG');
this.vis.permission.acl.reset([{ entity: {}, type: 'user', access: 'r' }, { entity: {}, type: 'user', access: 'r' }]);
expect(this.header.$('.privacy.share i span.shared_users').text()).toBe('2');
});
it("shouldn't show shared-users count and add disable class when user is not the owner of the table", function() {
this.vis.permission.owner = this.user;
this.header.setInfo();
expect(this.header.$('.privacy.share i').hasClass('disabled')).toBeFalsy();
this.vis.permission.owner = new cdb.admin.User({ id: 'rambo2' });
this.vis.permission.acl.reset([{ entity: {}, type: 'user', access: 'r' }]);
this.header.setInfo();
expect(this.header.$('.privacy.share i').hasClass('disabled')).toBeTruthy();
expect(this.header.$('.privacy.share i span.shared_users').length).toBe(0);
})
it("shouldn't open 'privacy dialog' when user is not owner of the table/vis", function() {

Loading…
Cancel
Save