You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "ocket8888 (via GitHub)" <gi...@apache.org> on 2023/02/23 17:10:39 UTC

[GitHub] [trafficcontrol] ocket8888 commented on a diff in pull request #7353: Traffic Portal v2 CDNs detail page

ocket8888 commented on code in PR #7353:
URL: https://github.com/apache/trafficcontrol/pull/7353#discussion_r1109014326


##########
experimental/traffic-portal/src/app/api/cdn.service.ts:
##########
@@ -48,4 +48,65 @@ export class CDNService extends APIService {
 		}
 		return this.get<Array<ResponseCDN>>(path).toPromise();
 	}
+
+	/**
+	 * Deletes a CDN.
+	 *
+	 * @param cdn The CDN to be deleted, or just its ID.
+	 */
+	public async deleteCDN(cdn: ResponseCDN | number): Promise<void> {
+		const id = typeof cdn === "number" ? cdn : cdn.id;
+		return this.delete(`cdns/${id}`).toPromise();
+	}
+
+	/**
+	 * Creates a new CDN.
+	 *
+	 * @param cdn The CDN to create.
+	 */
+	public async createCDN(cdn: RequestCDN): Promise<ResponseCDN> {
+		return this.post<ResponseCDN>("cdns", cdn).toPromise();
+	}
+
+	/**
+	 * Replaces an existing CDN with the provided new definition of a
+	 * CDN.
+	 *
+	 * @param id The if of the CDN being updated.
+	 * @param cdn The new definition of the CDN.
+	 */
+	public async updateCDN(id: number, cdn: RequestCDN): Promise<ResponseCDN>;
+	/**
+	 * Replaces an existing CDN with the provided new definition of a
+	 * CDN.
+	 *
+	 * @param cdn The full new definition of the CDN being
+	 * updated.
+	 */
+	public async updateCDN(cdn: ResponseCDN): Promise<ResponseCDN>;
+	/**
+	 * Replaces an existing CDN with the provided new definition of a
+	 * CDN.
+	 *
+	 * @param cdnOrID The full new definition of the CDN being
+	 * updated, or just its ID.
+	 * @param payload The new definition of the CDN. This is required if
+	 * `cdnOrID` is an ID, and ignored otherwise.
+	 */
+	public async updateCDN(cdnOrID: ResponseCDN | number, payload?: RequestCDN): Promise<ResponseCDN> {
+		let id;
+		let body;
+		if (typeof(cdnOrID) === "number") {
+			if (!payload) {
+				throw new TypeError("invalid call signature - missing request payload");
+			}
+			body = payload;
+			id = cdnOrID;
+		} else {
+			body = cdnOrID;
+			({id} = cdnOrID);
+		}
+
+		return this.put<ResponseCDN>(`cdns/${id}`, body).toPromise();
+	}

Review Comment:
   These new methods should also be added to the CDN testing service. You don't _need_ to add the overload signatures, or put JSDocs on them if the linter doesn't complain, but I do find it's generally easiest to just copy/paste everything and then fix up the function bodies.



##########
experimental/traffic-portal/src/app/core/cdns/cdn-detail/cdn-detail.component.ts:
##########
@@ -0,0 +1,139 @@
+/*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import { Location } from "@angular/common";
+import { Component, OnInit } from "@angular/core";
+import { MatDialog } from "@angular/material/dialog";
+import { ActivatedRoute } from "@angular/router";
+import { ResponseCDN } from "trafficops-types";
+
+import { CDNService } from "src/app/api";
+import {
+	DecisionDialogComponent,
+	DecisionDialogData,
+} from "src/app/shared/dialogs/decision-dialog/decision-dialog.component";
+import { NavigationService } from "src/app/shared/navigation/navigation.service";
+
+/**
+ * CDNDetailComponent is the controller for a CDN's "detail" page.
+ */
+@Component({
+	selector: "tp-cdn-detail",
+	styleUrls: ["./cdn-detail.component.scss"],
+	templateUrl: "./cdn-detail.component.html",
+})
+export class CDNDetailComponent implements OnInit {
+	public new = false;
+	public cdn: ResponseCDN = {
+		dnssecEnabled: false,
+		domainName: "",
+		id: -1,
+		lastUpdated: new Date(),
+		name: "",
+	};
+	public showErrors = false;
+	public cdns: Array<ResponseCDN> = [];
+
+	constructor(
+		private readonly route: ActivatedRoute,
+		private readonly api: CDNService,
+		private readonly location: Location,
+		private readonly dialog: MatDialog,
+		private readonly navSvc: NavigationService
+	) {
+	}
+
+	/**
+	 * Angular lifecycle hook where data is initialized.
+	 */
+	public async ngOnInit(): Promise<void> {
+		const ID = this.route.snapshot.paramMap.get("id");
+		if (ID === null) {
+			console.error("missing required route parameter 'id'");
+			return;
+		}
+
+		const cdnsPromise = this.api.getCDNs().then(cdns => this.cdns = cdns);
+		if (ID === "new") {
+			this.setTitle();
+			this.new = true;

Review Comment:
   These are being done backwards; this sets the title to a blank string



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org