Skip to content

Commit

Permalink
Merge pull request #2144 from kobotoolbox/2136-delete-projects-simult…
Browse files Browse the repository at this point in the history
…aneous

Allow to delete projects simultaneously
  • Loading branch information
jnm authored Jan 28, 2019
2 parents e55f43e + cbef000 commit e05c088
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 35 deletions.
45 changes: 24 additions & 21 deletions jsapp/js/components/assetrow.es6
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ class AssetRow extends React.Component {
ownedCollections = [],
parent = undefined;

var isDeployable = this.props.asset_type && this.props.asset_type === 'survey' && this.props.deployed_version_id === null;
var isDeployable = this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && this.props.deployed_version_id === null;

const userCanEdit = this.userCan('change_asset', this.props);

const assetName = this.props.name || this.props.firstQuestionLabel;

if (this.props.has_deployment && this.props.deployment__submission_count &&
this.userCan('view_submissions', this.props)) {
hrefTo = `/forms/${this.props.uid}/summary`;
Expand Down Expand Up @@ -160,7 +162,7 @@ class AssetRow extends React.Component {
<bem.AssetRow__cell m='name'>
<ui.AssetName {...this.props} />
</bem.AssetRow__cell>
{ this.props.asset_type && this.props.asset_type === 'survey' && this.props.settings.description &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && this.props.settings.description &&
<bem.AssetRow__description>
{this.props.settings.description}
</bem.AssetRow__description>
Expand All @@ -187,19 +189,19 @@ class AssetRow extends React.Component {
key={'userlink'}
className={[
'mdl-cell',
this.props.asset_type == 'survey' ? 'mdl-cell--2-col mdl-cell--1-col-tablet mdl-cell--hide-phone' : 'mdl-cell--2-col mdl-cell--2-col-tablet mdl-cell--1-col-phone'
this.props.asset_type == ASSET_TYPES.survey.id ? 'mdl-cell--2-col mdl-cell--1-col-tablet mdl-cell--hide-phone' : 'mdl-cell--2-col mdl-cell--2-col-tablet mdl-cell--1-col-phone'
]}
>
{ this.props.asset_type == 'survey' &&
{ this.props.asset_type == ASSET_TYPES.survey.id &&
<span>{ selfowned ? ' ' : this.props.owner__username }</span>
}
{ this.props.asset_type != 'survey' &&
{ this.props.asset_type != ASSET_TYPES.survey.id &&
<span>{selfowned ? t('me') : this.props.owner__username}</span>
}
</bem.AssetRow__cell>

{/* "date created" column for surveys */}
{ this.props.asset_type == 'survey' &&
{ this.props.asset_type == ASSET_TYPES.survey.id &&
<bem.AssetRow__cell m={'date-created'}
key={'date-created'}
className='mdl-cell mdl-cell--2-col mdl-cell--hide-tablet mdl-cell--hide-phone'
Expand All @@ -217,7 +219,7 @@ class AssetRow extends React.Component {
</bem.AssetRow__cell>

{/* "submission count" column for surveys */}
{ this.props.asset_type == 'survey' &&
{ this.props.asset_type == ASSET_TYPES.survey.id &&
<bem.AssetRow__cell
m={'submission-count'}
key={'submisson-count'}
Expand Down Expand Up @@ -283,7 +285,7 @@ class AssetRow extends React.Component {
data-action='clone'
data-tip={t('Clone')}
data-asset-type={this.props.kind}
data-asset-name={this.props.name}
data-asset-name={assetName}
data-disabled={false}
>
<i className='k-icon-clone' />
Expand All @@ -298,7 +300,7 @@ class AssetRow extends React.Component {
data-action={'cloneAsSurvey'}
data-tip={t('Create project')}
data-asset-type={this.props.kind}
data-asset-name={this.props.name}
data-asset-name={assetName}
data-disabled={false}
>
<i className='k-icon-projects' />
Expand Down Expand Up @@ -327,7 +329,7 @@ class AssetRow extends React.Component {
clearPopover={this.state.clearPopover}
popoverSetVisible={this.popoverSetVisible}
>
{ this.props.asset_type && this.props.asset_type === 'survey' && userCanEdit && isDeployable &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && userCanEdit && isDeployable &&
<bem.PopoverMenu__link
m={'deploy'}
data-action={'deploy'}
Expand All @@ -336,7 +338,7 @@ class AssetRow extends React.Component {
{t('Deploy this project')}
</bem.PopoverMenu__link>
}
{ this.props.asset_type && this.props.asset_type === 'survey' && this.props.has_deployment && !this.props.deployment__active && userCanEdit &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && this.props.has_deployment && !this.props.deployment__active && userCanEdit &&
<bem.PopoverMenu__link
m={'unarchive'}
data-action={'unarchive'}
Expand All @@ -346,7 +348,7 @@ class AssetRow extends React.Component {
{t('Unarchive')}
</bem.PopoverMenu__link>
}
{ this.props.asset_type && this.props.asset_type === 'survey' && userCanEdit &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && userCanEdit &&
<bem.PopoverMenu__link
m={'refresh'}
data-action={'refresh'}
Expand Down Expand Up @@ -375,12 +377,12 @@ class AssetRow extends React.Component {
</bem.PopoverMenu__link>
);
})}
{ this.props.asset_type && this.props.asset_type != 'survey' && ownedCollections.length > 0 &&
{ this.props.asset_type && this.props.asset_type != ASSET_TYPES.survey.id && ownedCollections.length > 0 &&
<bem.PopoverMenu__heading>
{t('Move to')}
</bem.PopoverMenu__heading>
}
{ this.props.asset_type && this.props.asset_type != 'survey' && ownedCollections.length > 0 &&
{ this.props.asset_type && this.props.asset_type != ASSET_TYPES.survey.id && ownedCollections.length > 0 &&
<bem.PopoverMenu__moveTo>
{ownedCollections.map((col)=>{
return (
Expand All @@ -401,7 +403,7 @@ class AssetRow extends React.Component {
})}
</bem.PopoverMenu__moveTo>
}
{ this.props.asset_type && this.props.asset_type === 'survey' && this.props.has_deployment && this.props.deployment__active && userCanEdit &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && this.props.has_deployment && this.props.deployment__active && userCanEdit &&
<bem.PopoverMenu__link
m={'archive'}
data-action={'archive'}
Expand All @@ -411,23 +413,24 @@ class AssetRow extends React.Component {
{t('Archive')}
</bem.PopoverMenu__link>
}
{ this.props.asset_type && this.props.asset_type === 'survey' && userCanEdit &&
{ this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && userCanEdit &&
<bem.PopoverMenu__link
m={'cloneAsTemplate'}
data-action={'cloneAsTemplate'}
data-asset-type={this.props.kind}
data-asset-name={this.props.name}
data-asset-name={assetName}
>
<i className='k-icon-template' />
{t('Create template')}
</bem.PopoverMenu__link>
}
{userCanEdit &&
<bem.PopoverMenu__link
m={'delete'}
data-action={'delete'}
data-asset-type={this.props.kind}
>
m={'delete'}
data-action={'delete'}
data-asset-type={this.props.kind}
data-asset-name={assetName}
>
<i className='k-icon-trash' />
{t('Delete')}
</bem.PopoverMenu__link>
Expand Down
2 changes: 1 addition & 1 deletion jsapp/js/components/header.es6
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class MainHeader extends Reflux.Component {
name='title'
placeholder={t('Project title')}
value={this.state.asset.name ? this.state.asset.name : ''}
onChange={this.assetTitleChange}
onChange={this.assetTitleChange.bind(this)}
onKeyDown={this.assetTitleKeyDown}
disabled={!userCanEditAsset}
/>
Expand Down
1 change: 1 addition & 0 deletions jsapp/js/components/modalForms/projectSettings.es6
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class ProjectSettings extends React.Component {
deleteProject() {
this.deleteAsset(
this.state.formAsset.uid,
this.state.formAsset.name,
this.goToProjectsList.bind(this)
);
}
Expand Down
14 changes: 14 additions & 0 deletions jsapp/js/components/searchcollectionlist.es6
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import DocumentTitle from 'react-document-title';
import $ from 'jquery';
import Dropzone from 'react-dropzone';
import {t, validFileTypes} from '../utils';
import {ASSET_TYPES} from '../constants';

class SearchCollectionList extends Reflux.Component {
constructor(props) {
Expand Down Expand Up @@ -78,13 +79,26 @@ class SearchCollectionList extends Reflux.Component {
var isSelected = stores.selectedAsset.uid === resource.uid;
var ownedCollections = this.state.ownedCollections;

// for unnamed assets, we try to display first question label
let firstQuestionLabel;
if (
resource.asset_type !== ASSET_TYPES.survey.id &&
resource.name === '' &&
resource.summary &&
resource.summary.labels &&
resource.summary.labels.length > 0
) {
firstQuestionLabel = resource.summary.labels[0]
}

return (
<this.props.assetRowClass key={resource.uid}
currentUsername={currentUsername}
onActionButtonClick={this.onActionButtonClick}
isSelected={isSelected}
ownedCollections={ownedCollections}
deleting={resource.deleting}
firstQuestionLabel={firstQuestionLabel}
{...resource}
/>
);
Expand Down
24 changes: 11 additions & 13 deletions jsapp/js/mixins.es6
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ mixins.dmix = {
mixins.clickAssets.click.asset.unarchive(uid, callback);
}
},
deleteAsset (uid, callback) {
mixins.clickAssets.click.asset.delete(uid, callback);
deleteAsset (uid, name, callback) {
mixins.clickAssets.click.asset.delete(uid, name, callback);
},
toggleDeploymentHistory () {
this.setState({
Expand Down Expand Up @@ -513,13 +513,9 @@ mixins.clickAssets = {
else
hashHistory.push(`/forms/${uid}/edit`);
},
delete: function(uid, callback){
let asset = stores.selectedAsset.asset || stores.allAssets.byUid[uid];
var assetTypeLabel = t('project');

if (asset.asset_type != 'survey') {
assetTypeLabel = t('library item');
}
delete: function(uid, name, callback) {
const asset = stores.selectedAsset.asset || stores.allAssets.byUid[uid];
let assetTypeLabel = ASSET_TYPES[asset.asset_type].label;

let dialog = alertify.dialog('confirm');
let deployed = asset.has_deployment;
Expand All @@ -528,7 +524,6 @@ mixins.clickAssets = {
actions.resources.deleteAsset({uid: uid}, {
onComplete: ()=> {
notify(`${assetTypeLabel} ${t('deleted permanently')}`);
$('.alertify-toggle input').prop('checked', false);
if (typeof callback === 'function') {
callback();
}
Expand All @@ -537,7 +532,7 @@ mixins.clickAssets = {
};

if (!deployed) {
if (asset.asset_type != 'survey')
if (asset.asset_type != ASSET_TYPES.survey.id)
msg = t('You are about to permanently delete this item from your library.');
else
msg = t('You are about to permanently delete this draft.');
Expand All @@ -552,10 +547,13 @@ mixins.clickAssets = {
onshow = (evt) => {
let ok_button = dialog.elements.buttons.primary.firstChild;
let $els = $('.alertify-toggle input');

ok_button.disabled = true;
$els.each(function () {$(this).prop('checked', false);});

$els.change(function () {
ok_button.disabled = false;
$els.each(function ( index ) {
$els.each(function () {
if (!$(this).prop('checked')) {
ok_button.disabled = true;
}
Expand All @@ -564,7 +562,7 @@ mixins.clickAssets = {
};
}
let opts = {
title: `${t('Delete')} ${assetTypeLabel}`,
title: `${t('Delete')} ${assetTypeLabel} "${name}"`,
message: msg,
labels: {
ok: t('Delete'),
Expand Down
1 change: 1 addition & 0 deletions jsapp/js/ui.es6
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class AssetName extends React.Component {
var row_count;
if (!name) {
row_count = summary.row_count;
// for unnamed assets, we try to display first question name
name = summary.labels ? summary.labels[0] : false;
if (!name) {
isEmpty = true;
Expand Down

0 comments on commit e05c088

Please sign in to comment.