Initial commit
This commit is contained in:
+172
@@ -0,0 +1,172 @@
|
||||
var _ = require('underscore');
|
||||
var moment = require('moment');
|
||||
var ConfirmationView = require('builder/components/modals/confirmation/modal-confirmation-view');
|
||||
var VisDefinitionModel = require('builder/data/vis-definition-model');
|
||||
var MapcardPreview = require('builder/helpers/mapcard-preview');
|
||||
var ErrorView = require('builder/components/error/error-view');
|
||||
var renderLoading = require('builder/components/loading/render-loading');
|
||||
var tableDeleteOperation = require('builder/dataset/operations/table-delete-operation');
|
||||
var template = require('./remove-dataset.tpl');
|
||||
var errorParser = require('builder/helpers/error-parser');
|
||||
var REQUIRED_OPTS = [
|
||||
'modalModel',
|
||||
'userModel',
|
||||
'visModel',
|
||||
'tableModel',
|
||||
'configModel'
|
||||
];
|
||||
var AFFECTED_VIS_COUNT = 3;
|
||||
var AFFECTED_ENTITIES_SAMPLE_COUNT = 20;
|
||||
|
||||
/**
|
||||
* Remove dataset modal dialog
|
||||
*/
|
||||
module.exports = ConfirmationView.extend({
|
||||
className: 'Dialog-content',
|
||||
|
||||
initialize: function (opts) {
|
||||
_.each(REQUIRED_OPTS, function (item) {
|
||||
if (!opts[item]) throw new Error(item + ' is required');
|
||||
this['_' + item] = opts[item];
|
||||
}, this);
|
||||
|
||||
this._acl = this._visModel._permissionModel.acl;
|
||||
},
|
||||
|
||||
render: function () {
|
||||
var affectedVisData = this._tableModel.get('accessible_dependent_derived_maps');
|
||||
var affectedEntitiesData = this._prepareVisibleAffectedEntities();
|
||||
|
||||
this.clearSubViews();
|
||||
|
||||
this.$el.html(
|
||||
template({
|
||||
modalModel: this._modalModel,
|
||||
tableName: this._tableModel.getUnquotedName(),
|
||||
affectedVisCount: affectedVisData.length,
|
||||
visibleAffectedVis: this._prepareVisibleAffectedVis(affectedVisData.slice(0, AFFECTED_VIS_COUNT)),
|
||||
organizationAffected: affectedEntitiesData.organizationAffected,
|
||||
affectedEntitiesCount: affectedEntitiesData.count,
|
||||
visibleAffectedEntities: affectedEntitiesData.data.slice(0, AFFECTED_ENTITIES_SAMPLE_COUNT),
|
||||
maxVisCount: AFFECTED_VIS_COUNT,
|
||||
maxEntitiesCount: AFFECTED_ENTITIES_SAMPLE_COUNT
|
||||
})
|
||||
);
|
||||
return this;
|
||||
},
|
||||
|
||||
_prepareVisibleAffectedVis: function (visibleAffectedVisData) {
|
||||
return visibleAffectedVisData.map(function (visData) {
|
||||
var vis = new VisDefinitionModel(visData, {
|
||||
configModel: this._configModel
|
||||
});
|
||||
var owner = vis._permissionModel.get('owner');
|
||||
|
||||
return {
|
||||
visId: vis.get('id'),
|
||||
name: vis.get('name'),
|
||||
url: vis.builderURL(),
|
||||
ownerName: owner.username,
|
||||
timeDiff: moment(vis.get('updated_at')).fromNow(),
|
||||
previewUrl: MapcardPreview.urlForStaticMap(this._configModel.get('maps_api_template'), vis, 304, 96)
|
||||
};
|
||||
}, this);
|
||||
},
|
||||
|
||||
_prepareVisibleAffectedEntities: function () {
|
||||
var types = this._acl.pluck('type');
|
||||
var affectedEntities = {
|
||||
organizationAffected: false,
|
||||
count: 0,
|
||||
data: []
|
||||
};
|
||||
var organization;
|
||||
|
||||
if (types.indexOf('org') > -1) {
|
||||
organization = this._userModel.getOrganization();
|
||||
affectedEntities.organizationAffected = true;
|
||||
affectedEntities.count = organization.get('user_count') - 1;
|
||||
if (organization.get('avatar_url')) {
|
||||
affectedEntities.data.push({
|
||||
avatarUrl: organization.get('avatar_url'),
|
||||
username: organization.get('display_name')
|
||||
});
|
||||
}
|
||||
} else {
|
||||
var users = [];
|
||||
var uniqueUsers = [];
|
||||
var userName = this._userModel.get('username');
|
||||
|
||||
// Grab all ids from every group
|
||||
_.each(this._acl.where({type: 'group'}), function (group) {
|
||||
var entity = group.get('entity');
|
||||
var groupUsers = _.map(entity.users.models, function (user) {
|
||||
return {
|
||||
username: user.get('username'),
|
||||
avatarUrl: user.get('avatar_url')
|
||||
};
|
||||
});
|
||||
users = users.concat(groupUsers);
|
||||
}, this);
|
||||
|
||||
// Grab all ids from every user
|
||||
_.each(this._acl.where({type: 'user'}), function (group) {
|
||||
var entity = group.get('entity');
|
||||
users.push({
|
||||
username: entity.get('username'),
|
||||
avatarUrl: entity.get('avatar_url')
|
||||
});
|
||||
}, this);
|
||||
|
||||
// remove current user id because it can be part of a group
|
||||
users = _.filter(users, function (user) {
|
||||
return user.username !== userName;
|
||||
});
|
||||
|
||||
// return only uniques
|
||||
uniqueUsers = _.uniq(users, function (item) {
|
||||
return item.username;
|
||||
});
|
||||
|
||||
affectedEntities.count = uniqueUsers.length;
|
||||
affectedEntities.data = uniqueUsers;
|
||||
}
|
||||
|
||||
return affectedEntities;
|
||||
},
|
||||
|
||||
_runAction: function () {
|
||||
this._renderLoadingView();
|
||||
|
||||
tableDeleteOperation({
|
||||
onSuccess: this._onSuccessDestroyDataset.bind(this, this._modalModel),
|
||||
onError: this._onErrorDestroyDataset.bind(this),
|
||||
visModel: this._visModel
|
||||
});
|
||||
},
|
||||
|
||||
_renderLoadingView: function () {
|
||||
this.$el.html(
|
||||
renderLoading({
|
||||
title: _t('dataset.delete.loading', { tableName: this._tableModel.getUnquotedName() })
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
_onSuccessDestroyDataset: function () {
|
||||
window.location = this._configModel.get('base_url') + '/dashboard';
|
||||
},
|
||||
|
||||
_onErrorDestroyDataset: function (mdl, e) {
|
||||
var errorMessage = errorParser(e);
|
||||
var errorView = new ErrorView({
|
||||
title: _t('dataset.delete.error', {
|
||||
tableName: this._tableModel.getUnquotedName(),
|
||||
error: errorMessage
|
||||
}),
|
||||
desc: errorMessage || _t('components.error.default-desc')
|
||||
});
|
||||
this.$el.html(errorView.render().el);
|
||||
this.addView(errorView);
|
||||
}
|
||||
});
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
<div class="u-flex u-justifyCenter">
|
||||
<div class="Modal-inner u-flex u-justifyCenter">
|
||||
<div class="Modal-icon">
|
||||
<svg width="24px" height="25px" viewbox="521 436 24 25" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<path d="M524.5,440 L540.5,440 L540.5,460 L524.5,460 L524.5,440 Z M528.5,437 L536.5,437 L536.5,440 L528.5,440 L528.5,437 Z M522,440 L544,440 L522,440 Z M528.5,443.5 L528.5,455.5 L528.5,443.5 Z M532.5,443.5 L532.5,455.5 L532.5,443.5 Z M536.5,443.5 L536.5,455.5 L536.5,443.5 Z" id="Shape" stroke="#F19243" stroke-width="1" fill="none"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h2 class="CDB-Text CDB-Size-huge is-light u-bSpace--xl">
|
||||
<%= _t('dataset.delete.title', { tableName: tableName }) %>
|
||||
</h2>
|
||||
<p class="CDB-Text CDB-Size-large u-secondaryTextColor"><%- _t('dataset.delete.desc') %></p>
|
||||
|
||||
<% if (affectedVisCount > 0) { %>
|
||||
<div class="Modal-listActions js-affectedVis">
|
||||
<p class="CDB-Text CDB-Size-large u-altTextColor">
|
||||
<% if (affectedVisCount > maxVisCount) {%>
|
||||
<%= _t('dataset.delete.affected-vis-count-extended', {affectedVisCount: affectedVisCount}) %>
|
||||
<% } else { %>
|
||||
<%= _t('dataset.delete.affected-vis-count', {smart_count: affectedVisCount}) %>
|
||||
<% } %>
|
||||
</p>
|
||||
|
||||
<ul class="u-flex u-justifyStart u-tSpace-xl">
|
||||
<% visibleAffectedVis.forEach(function(vis) { %>
|
||||
<li class="MapsList-item MapsList-item--wRightMargins">
|
||||
<div class="MapCard" data-vis-id="<%- vis.visId %>" data-vis-owner-name="<%- vis.ownerName %>">
|
||||
<a href="<%- vis.url %>" target="_blank" class="MapCard-header MapCard-header--mCompact js-header">
|
||||
<img class="MapCard-preview" src="<%- vis.previewUrl %>" style="display: inline;">
|
||||
<div class="MapCard-loader"></div>
|
||||
</a>
|
||||
<div class="MapCard-content MapCard-content--compact">
|
||||
<div class="MapCard-contentBody">
|
||||
<div class="MapCard-contentBodyRow MapCard-contentBodyRow--flex">
|
||||
<h3 class="CDB-Text CDB-Size-large u-bSpace u-ellipsis">
|
||||
<a href="<%- vis.url %>" target="_blank" title="<%- vis.name %>" class="u-mainTextColor"><%- vis.name %></a>
|
||||
</h3>
|
||||
</div>
|
||||
<p class="MapCard-contentBodyTimeDiff DefaultTimeDiff CDB-Text CDB-Size-medium u-altTextColor">
|
||||
<%- vis.timeDiff %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<% }); %>
|
||||
</ul>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (affectedEntitiesCount > 0 || organizationAffected) { %>
|
||||
<div class="Modal-listActions js-affectedEntities">
|
||||
<p class="CDB-Text CDB-Size-large u-altTextColor">
|
||||
<% if (organizationAffected) { %>
|
||||
<%= _t('dataset.delete.whole-organization-affected') %>
|
||||
<% } else if (affectedEntitiesCount > maxEntitiesCount && visibleAffectedEntities.length > 0) {%>
|
||||
<%= _t('dataset.delete.affected-entities-count-extended', {affectedEntitiesCount: affectedEntitiesCount}) %>
|
||||
<% } else { %>
|
||||
<%= _t('dataset.delete.affected-entities-count', {smart_count: affectedEntitiesCount}) %>
|
||||
<% } %>
|
||||
</p>
|
||||
|
||||
<ul class="u-flex u-justifyStart u-tSpace-xl">
|
||||
<% visibleAffectedEntities.forEach(function(entity) { %>
|
||||
<% if (entity.avatarUrl) { %>
|
||||
<li class="u-rSpace--m">
|
||||
<div class="Share-user Share-user--medium" style="background-image: url(<%- entity.avatarUrl %>)" data-username="<%- entity.username %>" title="<%- entity.username %>"></div>
|
||||
</li>
|
||||
<% } %>
|
||||
<% }); %>
|
||||
</ul>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<ul class="Modal-listActions u-flex u-alignCenter">
|
||||
<li class="Modal-listActionsitem">
|
||||
<button class="CDB-Button CDB-Button--secondary CDB-Button--medium js-cancel">
|
||||
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">
|
||||
<%- _t('dataset.delete.cancel') %>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
<li class="Modal-listActionsitem">
|
||||
<button class="CDB-Button CDB-Button--primary CDB-Button--medium js-confirm">
|
||||
<span class="CDB-Button-Text CDB-Text is-semibold CDB-Size-small u-upperCase">
|
||||
<%- _t('dataset.delete.confirm') %>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user