/** * 3D Foundation Project * Copyright 2025 Smithsonian Institution * * 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 Popup, { customElement, html } from "@ff/ui/Popup"; import "@ff/ui/Button"; import "@ff/ui/TextEdit"; import CVLanguageManager from "client/components/CVLanguageManager"; import { EDerivativeQuality, TDerivativeQuality } from "client/schema/model"; import CVModel2 from "client/components/CVModel2"; import Notification from "@ff/ui/Notification"; //////////////////////////////////////////////////////////////////////////////// @customElement("sv-import-menu") export default class ImportMenu extends Popup { protected url: string; protected language: CVLanguageManager = null; protected filename: string = ""; protected errorString: string = ""; protected modelOptions: {name: string, id: string}[] = []; protected qualitySelection: EDerivativeQuality = null; protected parentSelection: {name: string, id: string} = null; static show(parent: HTMLElement, language: CVLanguageManager, filename: string): Promise<[EDerivativeQuality, string]> { const menu = new ImportMenu(language, filename); parent.appendChild(menu); return new Promise((resolve, reject) => { menu.on("confirm", () => resolve([menu.qualitySelection, menu.parentSelection.name])); menu.on("close", () => reject()); }); } constructor( language: CVLanguageManager, filename: string ) { super(); this.language = language; this.filename = filename; this.modelOptions = this.modelOptions.concat(language.getGraphComponents(CVModel2).map(model => ({name: model.node.name, id: model.id}))); this.position = "center"; this.modal = true; this.parentSelection = this.modelOptions.length > 0 ? this.modelOptions[0] : {name: "Model"+this.modelOptions.length.toString(), id: "-1"}; this.url = window.location.href; } close() { this.dispatchEvent(new CustomEvent("close")); this.remove(); } confirm() { if(this.qualitySelection === null) { this.errorString = this.language.getUILocalizedString("Please select derivative quality."); this.requestUpdate(); } else { this.dispatchEvent(new CustomEvent("confirm")); this.remove(); } } protected firstConnected() { super.firstConnected(); this.classList.add("sv-option-menu", "sv-import-menu"); } protected renderQualityEntry(quality: EDerivativeQuality, index: number) { return html`