From 2810ccd0a6550d890ebbee410fe622fb3e819e20 Mon Sep 17 00:00:00 2001 From: Leszek Pietrzak Date: Fri, 28 Dec 2018 19:10:49 +0100 Subject: [PATCH 1/5] cleanup project deletion flow plus display asset name during deletion --- jsapp/js/components/assetrow.es6 | 9 ++++---- jsapp/js/components/header.es6 | 2 +- .../components/modalForms/projectSettings.es6 | 1 + jsapp/js/mixins.es6 | 22 ++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/jsapp/js/components/assetrow.es6 b/jsapp/js/components/assetrow.es6 index 0111060db0..4ce09ffb84 100644 --- a/jsapp/js/components/assetrow.es6 +++ b/jsapp/js/components/assetrow.es6 @@ -424,10 +424,11 @@ class AssetRow extends React.Component { } {userCanEdit && + m={'delete'} + data-action={'delete'} + data-asset-type={this.props.kind} + data-asset-name={this.props.name} + > {t('Delete')} diff --git a/jsapp/js/components/header.es6 b/jsapp/js/components/header.es6 index 7c278da12c..34221ebc4d 100644 --- a/jsapp/js/components/header.es6 +++ b/jsapp/js/components/header.es6 @@ -270,7 +270,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} /> diff --git a/jsapp/js/components/modalForms/projectSettings.es6 b/jsapp/js/components/modalForms/projectSettings.es6 index bf1e447e0c..c820c927a0 100644 --- a/jsapp/js/components/modalForms/projectSettings.es6 +++ b/jsapp/js/components/modalForms/projectSettings.es6 @@ -234,6 +234,7 @@ class ProjectSettings extends React.Component { deleteProject() { this.deleteAsset( this.state.formAsset.uid, + this.state.formAsset.name, this.goToProjectsList.bind(this) ); } diff --git a/jsapp/js/mixins.es6 b/jsapp/js/mixins.es6 index a3a0351c26..491d6a4d5c 100644 --- a/jsapp/js/mixins.es6 +++ b/jsapp/js/mixins.es6 @@ -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({ @@ -513,11 +513,11 @@ 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'); + delete: function(uid, name, callback) { + const asset = stores.selectedAsset.asset || stores.allAssets.byUid[uid]; + let assetTypeLabel = ASSET_TYPES.survey.label; - if (asset.asset_type != 'survey') { + if (asset.asset_type != ASSET_TYPES.survey.id) { assetTypeLabel = t('library item'); } @@ -528,7 +528,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(); } @@ -537,7 +536,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.'); @@ -552,10 +551,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; } @@ -564,7 +566,7 @@ mixins.clickAssets = { }; } let opts = { - title: `${t('Delete')} ${assetTypeLabel}`, + title: `${t('Delete')} ${assetTypeLabel} "${name}"`, message: msg, labels: { ok: t('Delete'), From f52b4419a526a9f0df2dc2befaa76a7569992b68 Mon Sep 17 00:00:00 2001 From: Leszek Pietrzak Date: Fri, 28 Dec 2018 20:57:30 +0100 Subject: [PATCH 2/5] display asset type label instead of vague "library item" --- jsapp/js/mixins.es6 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/jsapp/js/mixins.es6 b/jsapp/js/mixins.es6 index 491d6a4d5c..8712260b4e 100644 --- a/jsapp/js/mixins.es6 +++ b/jsapp/js/mixins.es6 @@ -515,11 +515,7 @@ mixins.clickAssets = { }, delete: function(uid, name, callback) { const asset = stores.selectedAsset.asset || stores.allAssets.byUid[uid]; - let assetTypeLabel = ASSET_TYPES.survey.label; - - if (asset.asset_type != ASSET_TYPES.survey.id) { - assetTypeLabel = t('library item'); - } + let assetTypeLabel = ASSET_TYPES[asset.asset_type].label; let dialog = alertify.dialog('confirm'); let deployed = asset.has_deployment; From 356fae0b30264ceb8578f8043a5ed4f2949fb993 Mon Sep 17 00:00:00 2001 From: Leszek Pietrzak Date: Fri, 28 Dec 2018 21:10:43 +0100 Subject: [PATCH 3/5] pass firstQuestionName to assetRow and use it plus use ASSET_TYPES constant --- jsapp/js/components/searchcollectionlist.es6 | 14 ++++++++++++++ jsapp/js/ui.es6 | 1 + 2 files changed, 15 insertions(+) diff --git a/jsapp/js/components/searchcollectionlist.es6 b/jsapp/js/components/searchcollectionlist.es6 index 965a251ec3..5cc55b4acf 100644 --- a/jsapp/js/components/searchcollectionlist.es6 +++ b/jsapp/js/components/searchcollectionlist.es6 @@ -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) { @@ -78,6 +79,18 @@ 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 name + let firstQuestionName; + if ( + resource.asset_type !== ASSET_TYPES.survey.id && + resource.name === '' && + resource.summary && + resource.summary.labels && + resource.summary.labels.length > 0 + ) { + firstQuestionName = resource.summary.labels[0] + } + return ( ); diff --git a/jsapp/js/ui.es6 b/jsapp/js/ui.es6 index 178e668392..5a1be05a20 100644 --- a/jsapp/js/ui.es6 +++ b/jsapp/js/ui.es6 @@ -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; From b16d88ce774cd8a8df8e2f487493121cdd18b620 Mon Sep 17 00:00:00 2001 From: Leszek Pietrzak Date: Fri, 28 Dec 2018 21:10:58 +0100 Subject: [PATCH 4/5] forgot to commit file --- jsapp/js/components/assetrow.es6 | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/jsapp/js/components/assetrow.es6 b/jsapp/js/components/assetrow.es6 index 4ce09ffb84..0ebbdb3040 100644 --- a/jsapp/js/components/assetrow.es6 +++ b/jsapp/js/components/assetrow.es6 @@ -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.firstQuestionName; + if (this.props.has_deployment && this.props.deployment__submission_count && this.userCan('view_submissions', this.props)) { hrefTo = `/forms/${this.props.uid}/summary`; @@ -160,7 +162,7 @@ class AssetRow extends React.Component { - { 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 && {this.props.settings.description} @@ -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 && { selfowned ? ' ' : this.props.owner__username } } - { this.props.asset_type != 'survey' && + { this.props.asset_type != ASSET_TYPES.survey.id && {selfowned ? t('me') : this.props.owner__username} } {/* "date created" column for surveys */} - { this.props.asset_type == 'survey' && + { this.props.asset_type == ASSET_TYPES.survey.id && {/* "submission count" column for surveys */} - { this.props.asset_type == 'survey' && + { this.props.asset_type == ASSET_TYPES.survey.id && @@ -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} > @@ -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 && } - { 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 && } - { this.props.asset_type && this.props.asset_type === 'survey' && userCanEdit && + { this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && userCanEdit && ); })} - { 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 && {t('Move to')} } - { 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 && {ownedCollections.map((col)=>{ return ( @@ -401,7 +403,7 @@ class AssetRow extends React.Component { })} } - { 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 && } - { this.props.asset_type && this.props.asset_type === 'survey' && userCanEdit && + { this.props.asset_type && this.props.asset_type === ASSET_TYPES.survey.id && userCanEdit && {t('Create template')} @@ -427,7 +429,7 @@ class AssetRow extends React.Component { m={'delete'} data-action={'delete'} data-asset-type={this.props.kind} - data-asset-name={this.props.name} + data-asset-name={assetName} > {t('Delete')} From cbef0008e77edf1bd090e3f0d56650be9853a227 Mon Sep 17 00:00:00 2001 From: "John N. Milner" Date: Sun, 27 Jan 2019 22:02:28 -0500 Subject: [PATCH 5/5] Change `firstQuestionName` to `firstQuestionLabel` --- jsapp/js/components/assetrow.es6 | 2 +- jsapp/js/components/searchcollectionlist.es6 | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jsapp/js/components/assetrow.es6 b/jsapp/js/components/assetrow.es6 index 0ebbdb3040..5ab8c5bbb9 100644 --- a/jsapp/js/components/assetrow.es6 +++ b/jsapp/js/components/assetrow.es6 @@ -99,7 +99,7 @@ class AssetRow extends React.Component { const userCanEdit = this.userCan('change_asset', this.props); - const assetName = this.props.name || this.props.firstQuestionName; + const assetName = this.props.name || this.props.firstQuestionLabel; if (this.props.has_deployment && this.props.deployment__submission_count && this.userCan('view_submissions', this.props)) { diff --git a/jsapp/js/components/searchcollectionlist.es6 b/jsapp/js/components/searchcollectionlist.es6 index 5cc55b4acf..c3f6e4aea0 100644 --- a/jsapp/js/components/searchcollectionlist.es6 +++ b/jsapp/js/components/searchcollectionlist.es6 @@ -79,8 +79,8 @@ 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 name - let firstQuestionName; + // for unnamed assets, we try to display first question label + let firstQuestionLabel; if ( resource.asset_type !== ASSET_TYPES.survey.id && resource.name === '' && @@ -88,7 +88,7 @@ class SearchCollectionList extends Reflux.Component { resource.summary.labels && resource.summary.labels.length > 0 ) { - firstQuestionName = resource.summary.labels[0] + firstQuestionLabel = resource.summary.labels[0] } return ( @@ -98,7 +98,7 @@ class SearchCollectionList extends Reflux.Component { isSelected={isSelected} ownedCollections={ownedCollections} deleting={resource.deleting} - firstQuestionName={firstQuestionName} + firstQuestionLabel={firstQuestionLabel} {...resource} /> );