From ca0791414adeab6786f8fc5df8bd8ef712cbfb5c Mon Sep 17 00:00:00 2001 From: Kurt Junghanns Date: Fri, 26 Oct 2018 18:02:41 +0200 Subject: [PATCH 01/19] [SWIK-907_delete_deck_and_transfer_ownership] Started to work on feature - first modal and structure. --- actions/deckedit/deckDeletion.js | 14 ++ .../DeckEditPanel/DeckPropertiesEditor.js | 59 ++++++++ .../DeckEditPanel/TransferOwnership.js | 132 ++++++++++++++++++ services/deck.js | 26 +++- stores/DeckEditStore.js | 21 ++- 5 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 actions/deckedit/deckDeletion.js create mode 100644 components/Deck/ContentPanel/DeckModes/DeckEditPanel/TransferOwnership.js diff --git a/actions/deckedit/deckDeletion.js b/actions/deckedit/deckDeletion.js new file mode 100644 index 000000000..b4a56953b --- /dev/null +++ b/actions/deckedit/deckDeletion.js @@ -0,0 +1,14 @@ +const log = require('../log/clog'); + +export default function deckDeletion(context, payload, done) { + log.info(context); + context.service.delete('deck.delete', payload, { timeout: 20 * 1000 }, (err, res) => { + if (err) { + context.dispatch('DELETE_DECK_ERROR', err); + } + else { + context.dispatch('DELETE_DECK_SUCCESS', res); + } + done(); + }); +} diff --git a/components/Deck/ContentPanel/DeckModes/DeckEditPanel/DeckPropertiesEditor.js b/components/Deck/ContentPanel/DeckModes/DeckEditPanel/DeckPropertiesEditor.js index 479ea2aee..de069476e 100644 --- a/components/Deck/ContentPanel/DeckModes/DeckEditPanel/DeckPropertiesEditor.js +++ b/components/Deck/ContentPanel/DeckModes/DeckEditPanel/DeckPropertiesEditor.js @@ -21,6 +21,7 @@ import TagsStore from '../../../../../stores/TagsStore'; import PermissionsStore from '../../../../../stores/PermissionsStore'; import updateTheme from '../../../../../actions/updateTheme'; import {showGroupDetailsModal} from '../../../../../actions/deckedit/functionsForGroupDetailsModal'; +import deckDeletion from '../../../../../actions/deckedit/deckDeletion'; import {educationLevels} from '../../../../../lib/isced'; import TagInput from '../../../ContentModulesPanel/TagsPanel/TagInput'; @@ -237,6 +238,60 @@ class DeckPropertiesEditor extends React.Component { } } + handleDelete(evt) { + evt.preventDefault(); + + if ( this.props.DeckEditStore.roots && this.props.DeckEditStore.roots.length < 1 ) { + // not used in other decks + + if (this.state.editors.length < 1 && this.state.groups.length < 1) { + // no editors - could just be deleted + this.context.executeAction(deckDeletion, {id: this.props.DeckEditStore.deckProps.sid.split('-')[0]}); + } + else { + // transfer ownership + + } + } + else { + // is included as subdeck in one other deck and could not just deleted + // show modal with 2 options: delete and remove + + const parentRootDecks = this.props.DeckEditStore.roots.map(deck => `${deck.id}`); + swal({ + title: 'Deck is in use', + html: 'The deck you want to delete is used as a subdeck in the following decks:
' + + parentRootDecks.join('
') + + '

You could remove your deck as a subdeck from the listed ones or delete the deck complete which also removes it as subdeck.', + type: 'question', + showCancelButton: true, + confirmButtonText: 'Remove as subdeck', + confirmButtonClass: 'ui button', + cancelButtonText: 'Delete whole deck', + cancelButtonClass: 'negative ui button', + allowEscapeKey: true, + allowOutsideClick: false, + buttonsStyling: false + }) + .then((result) => { + console.log(result); + // confirm btn + // remove deck as node from the parent deck + }) + .catch(() => { + // cancel btn + if (this.state.editors.length < 1 && this.state.groups.length < 1) { + // no editors - could just be deleted + this.context.executeAction(deckDeletion, {id: this.props.DeckEditStore.deckProps.sid.split('-')[0]}); + } + else { + // transfer ownership + + } + }); + } + } + handleChange(fieldName, event) { let stateChange = {}; stateChange[fieldName] = event.target.value; @@ -392,6 +447,7 @@ class DeckPropertiesEditor extends React.Component { } render() { + console.log('render edit: published and roots', this.state.published, this.props.DeckEditStore.roots); //CSS let titleFieldClass = classNames({ 'required': true, @@ -485,6 +541,9 @@ class DeckPropertiesEditor extends React.Component { +