From e992d68a64d6d6489eb43b3fa1bf644ca1f3a303 Mon Sep 17 00:00:00 2001
From: "Janet L. Goldstein" <jgoldste@nrao.edu>
Date: Tue, 11 Jan 2022 10:53:11 -0700
Subject: [PATCH] WS-858: in front end, use selectedVersion object rather than
 selectedVersion.version_number

---
 .../capability-request/capability-request.component.ts   | 6 ++++++
 .../request-operations/request-operations.component.html | 3 ++-
 .../workspaces/services/capability-launcher.service.ts   | 9 +++++----
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/apps/web/src/app/workspaces/components/capability-request/capability-request.component.ts b/apps/web/src/app/workspaces/components/capability-request/capability-request.component.ts
index 28b6a46b7..fca17d466 100644
--- a/apps/web/src/app/workspaces/components/capability-request/capability-request.component.ts
+++ b/apps/web/src/app/workspaces/components/capability-request/capability-request.component.ts
@@ -49,6 +49,12 @@ export class CapabilityRequestComponent implements OnInit, OnDestroy {
   private capabilityRequestObserver = {
     next: (request) => {
       this.capabilityRequest = request;
+       if (this.latestVersion === undefined) {
+         this.latestVersion = this.capabilityRequest.versions[this.capabilityRequest.versions.length - 1]
+       }
+       if (this.currentVersion === undefined) {
+         this.currentVersion = this.latestVersion
+       }
       if (this.currentVersion.current_execution !== null) {
         this.capabilityExecution = this.currentVersion.current_execution;
       } else {
diff --git a/apps/web/src/app/workspaces/components/capability-request/components/request-operations/request-operations.component.html b/apps/web/src/app/workspaces/components/capability-request/components/request-operations/request-operations.component.html
index 8d7bc76a5..1a198160f 100644
--- a/apps/web/src/app/workspaces/components/capability-request/components/request-operations/request-operations.component.html
+++ b/apps/web/src/app/workspaces/components/capability-request/components/request-operations/request-operations.component.html
@@ -4,6 +4,7 @@
       <app-create-new-version-form
         id="create-new-version-form"
         class="d-flex align-self-center"
+        [capabilityRequest]="capabilityRequest"
         [selectedVersion]="selectedVersion"
       ></app-create-new-version-form>
     </div>
@@ -21,7 +22,7 @@
         class="btn btn-warning"
         (click)="
           capabilityLauncherService
-            .createImageRequestFromPreviousCal('std_cms_imaging', capabilityRequest.id, selectedVersion.version_number)
+            .createImageRequestFromPreviousCal('std_cms_imaging', capabilityRequest.id, selectedVersion)
             .subscribe(followonRequestObserver)
         "
       >
diff --git a/apps/web/src/app/workspaces/services/capability-launcher.service.ts b/apps/web/src/app/workspaces/services/capability-launcher.service.ts
index bbf79060b..25402cf0d 100644
--- a/apps/web/src/app/workspaces/services/capability-launcher.service.ts
+++ b/apps/web/src/app/workspaces/services/capability-launcher.service.ts
@@ -22,6 +22,7 @@ import { Observable } from "rxjs";
 import { CapabilityRequest } from "../model/capability-request";
 import { CapabilityExecution } from "../model/capability-execution";
 import { JsonObject } from "@angular/compiler-cli/ngcc/src/packages/entry_point";
+import {CapabilityVersion} from "../model/capability-version";
 
 @Injectable({
   providedIn: "root",
@@ -42,19 +43,19 @@ export class CapabilityLauncherService {
   }
 
   /**
-   * Create standard CMS imaging request from previously exeuted calibration request and send it to capability service
+   * Create standard CMS imaging request from previously executed calibration request and send it to capability service
    * @param: capabilityName  Name of capability to create request for
    * @param: requestId Id of calibration request to image
    */
   createImageRequestFromPreviousCal(
     followonType: string,
     requestId: string,
-    versionNumber: number,
+    selectedVersion: CapabilityVersion,
   ): Observable<CapabilityRequest> {
-    const url = this.endpoint + "request/" + requestId + + "/version/" + versionNumber + "/followon/" + followonType;
+
+    const url = this.endpoint + "request/" + requestId + "/version/" + selectedVersion.version_number + "/followon/" + followonType;
     return this.httpClient.post<CapabilityRequest>(url, null);
   }
-
   /**
    * Submit capability request
    * @param: requestId  ID of capability request to submit
-- 
GitLab