From 88576ae3ea1312b43399e4e47009477bf9bb9027 Mon Sep 17 00:00:00 2001 From: Nataliia Karmazina Date: Thu, 19 Oct 2023 11:46:17 +0200 Subject: [PATCH] code smells delete --- frontend/src/app/Services/block.service.ts | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/Services/block.service.ts b/frontend/src/app/Services/block.service.ts index 38effdde4..e404382e8 100644 --- a/frontend/src/app/Services/block.service.ts +++ b/frontend/src/app/Services/block.service.ts @@ -210,30 +210,46 @@ export class BlockService { else return 0; } - /** - * Сhecking whether the block is used as a reference - * @param blockReferenceId - * @param blocks - * @param stories - */ + /** + * Сhecking whether the block is used as a reference + * @param blockReferenceId + * @param blocks + * @param stories + */ checkBlockOnReference(blocks:Block[], stories: Story[], blockReferenceId){ + if (!this.isBlockReferencedInScenarios(blockReferenceId,stories)) { + this.updateBlockReferenceStatus(blockReferenceId, blocks); + } + } + + /** + * check if a block is referenced in any scenario step definitions + * @param blockReferenceId + * @param stories + */ + isBlockReferencedInScenarios(blockReferenceId: string, stories): boolean { this.searchReferences(stories); - let blockNoLongerRef = true; - for (const scen of this.referenceScenarios){ + for (const scen of this.referenceScenarios) { for (const prop in scen.stepDefinitions) { for (let i = scen.stepDefinitions[prop].length - 1; i >= 0; i--) { if (scen.stepDefinitions[prop][i]._blockReferenceId == blockReferenceId) { - blockNoLongerRef = false; + return true; } } } } - if (blockNoLongerRef){ - for (const block of blocks){ - if(block._id === blockReferenceId){ - block.usedAsReference = false; - this.referencesBlocks.push(block); - } + return false; + } + /** + * update block reference status + * @param blockReferenceId + * @param blocks + */ + updateBlockReferenceStatus(blockReferenceId: string, blocks): void { + for (const block of blocks) { + if (block._id === blockReferenceId) { + block.usedAsReference = false; + this.referencesBlocks.push(block); } } }