File size: 2,929 Bytes
71174bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | <template>
<a :class="linkClass" @click.prevent="goToMenuPath" v-html="titleToUse"></a>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
import { Prop } from "vue-property-decorator";
import MenuLevel1 from "./Menu/MenuLevel1.vue";
import { PluginParentClass } from "@/Plugins/Parents/PluginParentClass/PluginParentClass";
import { loadedPlugins } from "@/Plugins/LoadedPlugins";
import { messagesApi } from "@/Api/Messages";
import { pluginsApi } from "@/Api/Plugins";
import { delayForPopupOpenClose } from "@/Core/GlobalVars";
/**
* PluginPathLink component
*/
@Options({
components: {
MenuLevel1,
},
})
export default class PluginPathLink extends Vue {
@Prop({ required: true }) plugin!: PluginParentClass | string;
@Prop({ default: undefined }) title!: string | undefined;
@Prop({ default: "link-primary" }) linkClass!: string;
pluginToUse: PluginParentClass | null = null;
/**
* Gets the menu path to display for the plugin.
*
* @returns {string} The menu path to display, formatted as a string.
*/
get titleToUse(): string {
if (this.pluginToUse === null) {
// Not read yet.
return "";
}
if (this.title !== undefined) {
return this.title;
}
// If null, return ""
if (this.pluginToUse.menuPath === null) {
return "";
}
// If it's an array, convert it to a string.
let menuPath = Array.isArray(this.pluginToUse.menuPath)
? this.pluginToUse.menuPath.join("/")
: this.pluginToUse.menuPath;
// Remove anything like [#], where # is a number
menuPath = menuPath.replace(/\[\d+\] /g, "");
menuPath = menuPath.replace(/\//g, " → ");
return menuPath;
}
/**
* Open the plugin specified by the component menu path.
*/
goToMenuPath() {
pluginsApi.closeAllPlugins();
const waitId = messagesApi.startWaitSpinner();
setTimeout(() => {
if (this.pluginToUse !== null) {
this.pluginToUse.menuOpenPlugin();
messagesApi.stopWaitSpinner(waitId);
}
}, delayForPopupOpenClose);
}
/**
* When the component is mounted.
*/
mounted() {
if (typeof this.plugin === "string") {
// Keep checking until plugin is available.
const interval = setInterval(() => {
const plugin = loadedPlugins[this.plugin as string];
if (plugin !== undefined) {
this.pluginToUse = plugin;
clearInterval(interval);
}
}, 100);
} else {
this.pluginToUse = this.plugin;
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss"></style>
|