X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Fstores%2FCatalogDataStore.js;h=9179f21471de6343debc934f96eff7b7815f7c10;hb=2ca25ec2b7511d2418432a04772a82137006cfbe;hp=1098f0e2342132e0c3f5beb4ca2bd2f8c24d1a13;hpb=7a89e546697979b07b160a15fbcafe7442468892;p=osm%2FUI.git diff --git a/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js b/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js index 1098f0e23..9179f2147 100644 --- a/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js +++ b/skyquake/plugins/composer/src/src/stores/CatalogDataStore.js @@ -1,6 +1,6 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,9 @@ */ 'use strict'; -import _ from 'lodash' +import _pick from 'lodash/pick' +import _isEqual from 'lodash/isEqual' +import _cloneDeep from 'lodash/cloneDeep' import cc from 'change-case' import alt from '../alt' import UID from '../libraries/UniqueId' @@ -34,7 +36,6 @@ import ComposerAppActions from '../actions/ComposerAppActions' import CatalogDataSource from '../sources/CatalogDataSource' import ComposerAppStore from '../stores/ComposerAppStore' import SelectionManager from '../libraries/SelectionManager' -import ExportSelectorDialog from '../components/ExportSelectorDialog' const defaults = { catalogs: [], @@ -44,9 +45,9 @@ const defaults = { const areCatalogItemsMetaDataEqual = function (a, b) { const metaProps = ['id', 'name', 'short-name', 'description', 'vendor', 'version']; - const aMetaData = _.pick(a, metaProps); - const bMetaData = _.pick(b, metaProps); - return _.isEqual(aMetaData, bMetaData); + const aMetaData = _pick(a, metaProps); + const bMetaData = _pick(b, metaProps); + return _isEqual(aMetaData, bMetaData); }; function createItem (type) { @@ -56,7 +57,6 @@ function createItem (type) { UID.assignUniqueId(newItem.uiState); newItem.uiState.isNew = true; newItem.uiState.modified = true; - newItem.uiState['instance-ref-count'] = 0; } return newItem; } @@ -188,7 +188,6 @@ class CatalogDataStore { }); updatedCatalogs.filter(d => d.type === 'nsd').forEach(catalog => { catalog.descriptors = catalog.descriptors.map(descriptor => { - const instanceRefCount = parseInt(descriptor.uiState['instance-ref-count'], 10); if (descriptor['constituent-vnfd']) { descriptor.vnfd = descriptor['constituent-vnfd'].map(d => { const vnfdId = d['vnfd-id-ref']; @@ -196,12 +195,8 @@ class CatalogDataStore { if (!vnfd) { throw new ReferenceError('no VNFD found in the VNFD Catalog for the constituent-vnfd: ' + d); } - if (!isNaN(instanceRefCount) && instanceRefCount > 0) { - // this will notify user that this item cannot be updated when/if they make a change to it - vnfd.uiState['instance-ref-count'] = instanceRefCount; - } // create an instance of this vnfd to carry transient ui state properties - const instance = _.cloneDeep(vnfd); + const instance = _cloneDeep(vnfd); instance.uiState['member-vnf-index'] = d['member-vnf-index']; instance['vnf-configuration'] = d['vnf-configuration']; instance['start-by-default'] = d['start-by-default']; @@ -318,17 +313,9 @@ class CatalogDataStore { // compare just the catalog uiState data (id, name, short-name, description, etc.) const modified = !areCatalogItemsMetaDataEqual(d, item); if (modified) { - if (d.uiState['instance-ref-count'] > 0) { - console.log('cannot edit NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot edit NSD/VNFD with references to instantiated Network Services' - }); - return _.cloneDeep(d); - } else { - item.uiState.modified = modified; - requiresSave = true; - this.addSnapshot(item); - } + item.uiState.modified = modified; + requiresSave = true; + this.addSnapshot(item); } return item; } @@ -352,17 +339,9 @@ class CatalogDataStore { // replace the old descriptor with the updated one catalog.descriptors = catalog.descriptors.map(d => { if (d.id === descriptorId) { - if (d.uiState['instance-ref-count'] > 0) { - console.log('cannot edit NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot edit NSD/VNFD with references to instantiated Network Services' - }); - return _.cloneDeep(d); - } else { - itemDescriptor.model.uiState.modified = true; - this.addSnapshot(itemDescriptor.model); - return itemDescriptor.model; - } + itemDescriptor.model.uiState.modified = true; + this.addSnapshot(itemDescriptor.model); + return itemDescriptor.model; } return d; }); @@ -414,27 +393,19 @@ class CatalogDataStore { if (item.uiState.isNew) { CatalogDataStore.confirmDelete(remove, confirmDeleteCancel); } else { - if (item.uiState['instance-ref-count'] > 0) { - console.log('cannot delete NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot delete NSD/VNFD with references to instantiated Network Services' - }); - undo(); - } else { - const confirmDeleteOK = event => { - event.preventDefault(); - item.uiState.deleted = true; - this.setState({catalogs: this.getCatalogs()}); - ModalOverlayActions.showModalOverlay.defer(); - this.getInstance().deleteCatalogItem(item.uiState.type, item.id) - .then(remove, undo) - .then(ModalOverlayActions.hideModalOverlay, ModalOverlayActions.hideModalOverlay) - .catch(function() { - console.log('overcoming ES6 unhandled rejection red herring'); - }); - }; - CatalogDataStore.confirmDelete(confirmDeleteOK, confirmDeleteCancel); - } + const confirmDeleteOK = event => { + event.preventDefault(); + item.uiState.deleted = true; + this.setState({catalogs: this.getCatalogs()}); + ModalOverlayActions.showModalOverlay.defer(); + this.getInstance().deleteCatalogItem(item.uiState.type, item.id) + .then(remove, undo) + .then(ModalOverlayActions.hideModalOverlay, ModalOverlayActions.hideModalOverlay) + .catch(function() { + console.log('overcoming ES6 unhandled rejection red herring'); + }); + }; + CatalogDataStore.confirmDelete(confirmDeleteOK, confirmDeleteCancel); } } } @@ -459,27 +430,10 @@ class CatalogDataStore { } duplicateSelectedCatalogItem() { - const item = this.getFirstSelectedCatalogItem(); - if (item) { - const newItem = _.cloneDeep(item); - newItem.name = newItem.name + ' Copy'; - newItem.id = guid(); - UID.assignUniqueId(newItem.uiState); - const nsd = this.addNewItemToCatalog(newItem); - this.selectCatalogItem(nsd); - nsd.uiState.isNew = true; - nsd.uiState.modified = true; - nsd.uiState['instance-ref-count'] = 0; - // note duplicated items get a new id, map the layout position - // of the old id to the new id in order to preserve the layout - if (nsd.uiState.containerPositionMap) { - nsd.uiState.containerPositionMap[nsd.id] = nsd.uiState.containerPositionMap[item.id]; - delete nsd.uiState.containerPositionMap[item.id]; - } - setTimeout(() => { - this.selectCatalogItem(nsd); - CatalogItemsActions.editCatalogItem.defer(nsd); - }, 200); + // make request to backend to duplicate an item + const srcItem = this.getFirstSelectedCatalogItem(); + if (srcItem) { + CatalogPackageManagerActions.copyCatalogPackage.defer(srcItem); } } @@ -544,13 +498,6 @@ class CatalogDataStore { saveItem(item) { if (item) { - if (item.uiState['instance-ref-count'] > 0) { - console.log('cannot save NSD/VNFD with references to instantiated Network Services'); - ComposerAppActions.showError.defer({ - errorMessage: 'Cannot save NSD/VNFD with references to instantiated Network Services' - }); - return; - } const success = () => { delete item.uiState.modified; if (item.uiState.isNew) { @@ -579,61 +526,24 @@ class CatalogDataStore { } exportSelectedCatalogItems(draggedItem) { - const onSelectFormat = (selectedFormat, event) => { - this.setState({ - selectedFormat: selectedFormat - }); - }; - - const onSelectGrammar = (selectedGrammar, event) => { - this.setState({ - selectedGrammar: selectedGrammar - }); - } - - - const onCancel = () => { - this.resetSelectionState(); - ModalOverlayActions.hideModalOverlay(); - }; - - const onDownload = (event) => { + // collect the selected items and delegate to the catalog package manager action creator + const selectedItems = this.getAllSelectedCatalogItems(); + if (selectedItems.length) { CatalogPackageManagerActions.downloadCatalogPackage.defer({ selectedItems: selectedItems, - selectedFormat: this.selectedFormat, - selectedGrammar: this.selectedGrammar + selectedFormat: 'mano', + selectedGrammar: 'osm' }); this.resetSelectionState(); - ModalOverlayActions.hideModalOverlay(); - return; - } - - if (draggedItem) { - // if item is given make sure it is also selected - //draggedItem.uiState.selected = true; - SelectionManager.addSelection(draggedItem); - this.updateCatalogItem(draggedItem); - } - // collect the selected items and delegate to the catalog package manager action creator - const selectedItems = this.getAllSelectedCatalogItems(); - if (selectedItems.length) { - CatalogDataStore.chooseExportFormat(onSelectFormat, onSelectGrammar, onDownload, onCancel); } } - - static chooseExportFormat(onSelectFormat, onSelectGrammar, onDownload, onCancel) { - ModalOverlayActions.showModalOverlay.defer( - - ); + saveCatalogItemError(data){ + let error = JSON.parse(data.error.responseText); + const errorMsg = error && error.body && error.body['rpc-reply'] && JSON.stringify(error.body['rpc-reply']['rpc-error'], null, ' ') + ComposerAppActions.showError.defer({ + errorMessage: 'Unable to save the descriptor.\n' + errorMsg + }); } - } export default alt.createStore(CatalogDataStore, 'CatalogDataStore');