gbkannan89 commented on code in PR #7532: URL: https://github.com/apache/trafficcontrol/pull/7532#discussion_r1214478007
########## experimental/traffic-portal/src/app/shared/import-json-edit-txt/import-json-edit-txt.component.ts: ########## @@ -0,0 +1,125 @@ +/* +* 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 { DatePipe } from "@angular/common"; +import { Component, HostListener } from "@angular/core"; +import { MatDialogRef } from "@angular/material/dialog"; +import { AlertLevel } from "trafficops-types"; + +import { AlertService } from "../alert/alert.service"; + +/** + * Component + */ +@Component({ + selector: "tp-import-json-edit-txt", + styleUrls: ["./import-json-edit-txt.component.scss"], + templateUrl: "./import-json-edit-txt.component.html", +}) +export class ImportJsonEditTxtComponent { + + /** + * Title for the dialog window + */ + public title = "Import Profile"; + + /** + * Allowed import file types + */ + public allowedType: string[] = ["application/json", "text/plain"]; + + /** Text editor value */ + public inputTxt = ""; + + /** File data imported */ + public fileData = ""; + + /** Monitor whether any file is being drag over the dialog */ + public dragOn = false; + + /** + * Creates an instance of import json edit txt component. + * + * @param dialogRef Dialog manager + * @param alertService Alert service manager + * @param datePipe Default angular date pipe for formating date + */ + constructor( + private readonly dialogRef: MatDialogRef<ImportJsonEditTxtComponent>, + private readonly alertService: AlertService, + private readonly datePipe: DatePipe) { } + + /** + * Emits the json value for import as profile data + */ + public submit(): void { + this.dialogRef.close(this.inputTxt); + } + + /** + * Hosts listener for drag over + * + * @param evt Drag events data + */ + @HostListener("dragover", ["$event"]) public onDragOver(evt: DragEvent): void { + evt.preventDefault(); + evt.stopPropagation(); + + this.dragOn = true; + } + + /** + * Hosts listener for drag leave + * + * @param evt Drag events data + */ + @HostListener("dragleave", ["$event"]) public onDragLeave(evt: DragEvent): void { + evt.preventDefault(); + evt.stopPropagation(); + + this.dragOn = false; + } + + /** + * Hosts listener for drop + * + * @param evt Drag events data + */ + @HostListener("drop", ["$event"]) public onDrop(evt: DragEvent): void { + evt.preventDefault(); + evt.stopPropagation(); + + this.dragOn = false; + + const file = evt.dataTransfer?.files[0]; Review Comment: yes so only we have added a return statement, checking for "!file". -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
