diff --git a/pydatalab/pydatalab/blocks/blocks.py b/pydatalab/pydatalab/blocks/blocks.py index 11f2b4c17..9b263c78c 100644 --- a/pydatalab/pydatalab/blocks/blocks.py +++ b/pydatalab/pydatalab/blocks/blocks.py @@ -51,7 +51,7 @@ class DataBlock: cache: Optional[Dict[str, Any]] = None plot_functions: Optional[Sequence[Callable[[], None]]] = None # whether this datablock can operate on collection data, or just individual items - __supports_collections: bool = False + _supports_collections: bool = False def __init__( self, @@ -63,10 +63,11 @@ def __init__( if dictionary is None: dictionary = {} - if item_id is None and not self.__supports_collections: + if item_id is None and not self._supports_collections: + breakpoint() raise RuntimeError(f"Must supply `item_id` to make {self.__class__.__name__}.") - if collection_id is not None and not self.__supports_collections: + if collection_id is not None and not self._supports_collections: raise RuntimeError( f"This block ({self.__class__.__name__}) does not support collections." ) @@ -174,20 +175,20 @@ def update_from_web(self, data): class NotSupportedBlock(DataBlock): blocktype = "notsupported" description = "Block not supported" - __supports_collections = True + _supports_collections = True class CommentBlock(DataBlock): blocktype = "comment" description = "Comment" - __supports_collections = True + _supports_collections = True class MediaBlock(DataBlock): blocktype = "media" description = "Media" accepted_file_extensions = (".png", ".jpeg", ".jpg", ".tif", ".tiff", ".mp4", ".mov", ".webm") - __supports_collections = False + _supports_collections = False @property def plot_functions(self): @@ -216,7 +217,7 @@ class NMRBlock(DataBlock): description = "Simple NMR Block" accepted_file_extensions = ".zip" defaults = {"process number": 1} - __supports_collections = False + _supports_collections = False @property def plot_functions(self): diff --git a/pydatalab/pydatalab/routes/v0_1/blocks.py b/pydatalab/pydatalab/routes/v0_1/blocks.py index d64d0570a..511a90624 100644 --- a/pydatalab/pydatalab/routes/v0_1/blocks.py +++ b/pydatalab/pydatalab/routes/v0_1/blocks.py @@ -115,7 +115,7 @@ def add_collection_data_block(): ) # get the new display_order: - display_order_result = flask_mongo.db.items.find_one( + display_order_result = flask_mongo.db.collections.find_one( {"collection_id": collection_id, **get_default_permissions(user_only=True)}, {"display_order": 1}, ) @@ -130,6 +130,9 @@ def add_collection_data_block(): ) +add_collection_data_block.methods = ("POST",) # type: ignore + + def _save_block_to_db(block: DataBlock) -> bool: """Save data for a single block within an item to the database, overwriting previous data saved there. diff --git a/webapp/src/server_fetch_utils.js b/webapp/src/server_fetch_utils.js index 11ca23f58..5eedf1112 100644 --- a/webapp/src/server_fetch_utils.js +++ b/webapp/src/server_fetch_utils.js @@ -358,25 +358,6 @@ export function addABlock(item_id, block_type, index = null) { return block_id_promise; } -export function addACollectionBlock(collection_id, block_type, index = null) { - console.log("addACollectionBlock called with", collection_id, block_type); - var block_id_promise = fetch_post(`${API_URL}/add-collection-data-block/`, { - collection_id: collection_id, - block_type: block_type, - index: index, - }) - .then(function (response_json) { - store.commit("addACollectionBlock", { - collection_id: collection_id, - new_block_obj: response_json.new_block_obj, - new_block_insert_index: response_json.new_block_insert_index, - }); - return response_json.new_block_obj.block_id; - }) - .catch((error) => console.error("Error in addACollectionBlock:", error)); - return block_id_promise; -} - export function saveItem(item_id) { console.log("saveItem Called!"); var item_data = store.state.all_item_data[item_id]; diff --git a/webapp/src/store/index.js b/webapp/src/store/index.js index 7dc8f6207..ab1826c35 100644 --- a/webapp/src/store/index.js +++ b/webapp/src/store/index.js @@ -132,33 +132,6 @@ export default createStore({ state.all_item_data[item_id]["display_order"].push(new_block_id); } }, - addACollectionBlock(state, { collection_id, new_block_obj, new_block_insert_index }) { - // payload: item_id, new_block_obj, new_display_order - - // I should actually throw an error if this fails! - console.assert( - collection_id == new_block_obj.collection_id, - "The block has a different collection_id (%s) than the collection_id provided to addACollectionBlock (%s)", - collection_id, - new_block_obj.collection_id - ); - console.log( - `addACollectionBlock called with: ${collection_id}, ${new_block_obj}, ${new_block_insert_index}` - ); - let new_block_id = new_block_obj.block_id; - state.all_collection_data[collection_id]["blocks_obj"][new_block_id] = new_block_obj; - if (new_block_insert_index) { - state.all_collection_data[collection_id]["display_order"].splice( - new_block_insert_index, - 0, - new_block_id - ); - } - // if new_block_insert_index is None, then block is inserted at the end - else { - state.all_collection_data[collection_id]["display_order"].push(new_block_id); - } - }, updateBlockData(state, payload) { // requires the following fields in payload: // item_id, block_id, block_data diff --git a/webapp/src/views/CollectionPage.vue b/webapp/src/views/CollectionPage.vue index 6a9897c57..588248d73 100644 --- a/webapp/src/views/CollectionPage.vue +++ b/webapp/src/views/CollectionPage.vue @@ -10,35 +10,6 @@