diff --git a/src/app/components/edit-tool-group-resource/tool-group-resource.component.ts b/src/app/components/edit-tool-group-resource/tool-group-resource.component.ts index 4fbe26cc..dc202d01 100644 --- a/src/app/components/edit-tool-group-resource/tool-group-resource.component.ts +++ b/src/app/components/edit-tool-group-resource/tool-group-resource.component.ts @@ -1,5 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { UUID } from 'angular2-uuid'; import { ToolGroupService } from '../../service/tool-group/tool-group.service'; import { ResourceService } from '../../service/resource/resource.service'; import { Resource } from '../../models/resource'; @@ -51,12 +52,17 @@ export class ToolGroupResourceComponent implements OnInit { async createOrUpdate(): Promise { this.saving = true; + this.errorMessage = []; + const dataErrors = []; const promises = []; if (this.tools.length) { this.tools.forEach((tool) => { const isUpdate = !!this.initialTools.find( (item) => item.id === tool.id, ); + if (!tool.suggestionsWeight || tool.suggestionsWeight === '0') { + dataErrors.push(`${tool.tool.name} needs to have a Suggestions Weight larger than 0.`) + } promises.push( this.toolGroupService.addOrUpdateTool( this.toolGroup.id, @@ -69,6 +75,12 @@ export class ToolGroupResourceComponent implements OnInit { }); } + if (dataErrors.length) { + this.saving = false; + this.errorMessage = dataErrors; + return; + } + const results: PromisePayload[] = await Promise.all( promises.map((p) => p @@ -125,7 +137,7 @@ export class ToolGroupResourceComponent implements OnInit { } generateId(): string { - return Math.floor(Math.random() * 1000).toString(); + return UUID.UUID(); } cancel() { diff --git a/src/app/service/tool-group/tool-group.service.ts b/src/app/service/tool-group/tool-group.service.ts index 190c179e..f193010e 100644 --- a/src/app/service/tool-group/tool-group.service.ts +++ b/src/app/service/tool-group/tool-group.service.ts @@ -229,7 +229,7 @@ export class ToolGroupService extends AbstractService { data: { type: 'tool-group-tool', attributes: { - 'suggestions-weight': suggestionsWeight, + 'suggestions-weight': suggestionsWeight || '1.0', }, relationships: { tool: {