File size: 10,358 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<template>
    <PluginComponent v-model="open" :infoPayload="infoPayload" cancelBtnTxt="Done" actionBtnTxt=""
        @onPopupDone="onPopupDone" @onUserArgChanged="onUserArgChanged" @onMolCountsChanged="onMolCountsChanged">
        <FilterInput :list="loadedPlugins" :extractTextToFilterFunc="extractTextToFilterFunc" @onFilter="onFilter"
            v-model="filterStr"></FilterInput>

        <span v-for="plugin of loadedPluginsToUse" :key="plugin.pluginId">
            <span v-if="plugin.title !== '' && plugin.menuPath !== null">
                <h6 class="mb-1">{{ plugin.title }}</h6>

                <p class="ms-2 mb-0 alert alert-light lh-1 p-0 inverse-indent">
                    <!-- <small v-html="menuPathToUse(plugin.menuPath)"></small> -->
                    <small>
                        Menu: <PluginPathLink :plugin="plugin"></PluginPathLink>
                        <TourLauncher v-if="hasTests(plugin)" :plugin="plugin" />
                    </small>
                </p>

                <p v-if="creditsToShow(plugin) !== ''" class="ms-2 mb-0 alert alert-light lh-1 p-0 inverse-indent">
                    <small v-html="creditsToShow(plugin)"></small>
                </p>

                <p v-if="citationsToShow(plugin) !== ''" class="ms-2 mb-0 alert alert-light lh-1 p-0 inverse-indent">
                    <small v-html="citationsToShow(plugin)"></small>
                </p>

                <p v-html="plugin.intro + ' ' + plugin.details" class="ms-2 mt-1"></p>
            </span>
        </span>
    </PluginComponent>
</template>

<script lang="ts">
import { Options } from "vue-class-component";
import { IContributorCredit, ISoftwareCredit } from "../PluginInterfaces";
import { Prop } from "vue-property-decorator";
import PluginComponent from "../Parents/PluginComponent/PluginComponent.vue";
import { PluginParentClass } from "../Parents/PluginParentClass/PluginParentClass";
import { UserArg } from "@/UI/Forms/FormFull/FormFullInterfaces";
import { ITest } from "@/Testing/TestInterfaces";
import { TestCmdList } from "@/Testing/TestCmdList";
import PluginPathLink from "@/UI/Navigation/PluginPathLink.vue";
import FilterInput from "@/UI/Components/FilterInput.vue";
import { citationsTxt } from "../Citations";
import { Tag, matchesTag } from "./ActivityFocus/ActivityFocusUtils";
import TourLauncher from "@/UI/Navigation/TourLauncher.vue";
import * as api from "@/Api";

/** HelpPlugin */
@Options({
    components: {
        PluginComponent,
        PluginPathLink,
        FilterInput,
        TourLauncher,
    },
})
export default class HelpPlugin extends PluginParentClass {
    @Prop({ required: true }) loadedPlugins!: PluginParentClass[];

    menuPath = ["Help", "[5] Plugin Info..."];
    title = "Plugin Info";
    softwareCredits: ISoftwareCredit[] = [];
    contributorCredits: IContributorCredit[] = [
        // {
        //     name: "Jacob D. Durrant",
        //     url: "http://durrantlab.com/",
        // },
    ];
    pluginId = "help";
    intro = "List information about each of the loaded plugins.";
    details = "This plugin provides a searchable list of all available plugins with descriptions of their functionality.";
    filterStr = "";  // Not used, but needed for FilterInput component.
    userArgDefaults: UserArg[] = [];

    logJob = false;
    tags = [Tag.All];

    filteredPlugins: PluginParentClass[] | null = null;

    /**
     * Checks if a plugin has any tests defined.
     *
     * @param {PluginParentClass} plugin The plugin to check.
     * @returns {boolean} True if the plugin has tests.
     */
    hasTests(plugin: PluginParentClass): boolean {
        const excludedPlugins = [
            'help',
            'about',
            'archivedversions',
            'documentationlink',
            'errorreporting',
            'statcollection',
            'fetcherpermission',
            'datawindow',
            'informationwindow',
            'jobswindow',
            'logwindow',
            'navigatorwindow',
            'resetlayout',
            'styleswindow',
            'viewerwindow',
            'simplemsg',
            'simplesvgpopup',
            'simpletabledata',
            'simplevideo',
            'yesno'
        ];
        return !excludedPlugins.includes(plugin.pluginId);
    }

    /**
 * Starts a tour for the given plugin.
 *
 * @param {PluginParentClass} plugin The plugin for which to start a tour.
 */
    startTour(plugin: PluginParentClass) {
        this.closePopup();
        setTimeout(() => {
            api.tour.startTour(plugin);
        }, 300); // Delay to allow the help popup to close
    }

    /**
     * Gets the text to use for filtering the plugins.
     *
     * @param {PluginParentClass} plugin  The plugin to get the text for.
     * @returns {string} The text to use for filtering the plugins. This is the
     *                   text that is searched for in the filter box.
     */
    extractTextToFilterFunc(plugin: PluginParentClass): string {
        return plugin.title + " " + plugin.intro;
    }

    /**
     * Filters the plugins based on the user's input (filter text).
     *
     * @param {PluginParentClass[]}  plugins  The list of filtered plugins
     *                                        emitted by the component.
     * @returns {PluginParentClass[]} The list of plugins to display (filtered).
     */
    filterByTags(plugins: PluginParentClass[]): PluginParentClass[] {
        return plugins.filter(p => matchesTag(p.tags));
    }

    /**
     * Gets the plugins to display. If the user has entered text in the
     * filter box, then this will be the filtered list. Otherwise, it will
     * be the full list.
     *
     * @returns {PluginParentClass[]} The list of plugins to display.
     */
    get loadedPluginsToUse(): PluginParentClass[] {
        if (this.filteredPlugins === null) {
            return this.filterByTags(this.loadedPlugins);
        }

        return this.filterByTags(this.filteredPlugins);
    }

    /**
     * Filters the plugins based on the user's input (filter text).
     *
     * @param {PluginParentClass[]}  plugins  The list of filtered plugins
     *                                        emitted by the component.
     */
    onFilter(plugins: PluginParentClass[]): void {
        this.filteredPlugins = plugins;
    }

    /**
     * Runs when the popup closes via done button. Here, does nothing.
     */
    onPopupDone() {
        return;
    }

    /**
     * Every plugin runs some job. This is the function that does the
     * job running. About plugin does not have a job.
     * 
     * @returns {Promise<void>}  Resolves when the job is done.
     */
    runJobInBrowser(): Promise<void> {
        return Promise.resolve();
    }

    // @Watch("loadedPlugins")
    // onLoadedPluginsChange(newVal: PluginParentClass[]) {
    // }

    /**
     * Gets the citations to display, html formatted.
     *
     * @param {PluginParentClass}  plugin The plugin to get the citations for.
     * @returns {string} The citations to display, html formatted.
     */
    citationsToShow(plugin: PluginParentClass): string {
        return citationsTxt(plugin.infoPayload, false);
    }

    /**
     * Gets the credits to display, html formatted.
     *
     * @param {PluginParentClass}  plugin The plugin to get the credits for.
     * @returns {string} The credits to display, html formatted.
     */
    creditsToShow(plugin: PluginParentClass): string {
        if (
            plugin.softwareCredits.length + plugin.contributorCredits.length ===
            0
        ) {
            return "";
        }

        const items: string[] = [];

        for (const credit of plugin.contributorCredits) {
            if (credit.url) {
                items.push(
                    `<a href="${credit.url}" target="_blank">${credit.name}</a>`
                );
            } else {
                items.push(credit.name);
            }
        }

        for (const credit of plugin.softwareCredits) {
            if (credit.url) {
                items.push(
                    `<a href="${credit.url}" target="_blank">${credit.name}</a>`
                );
            } else {
                items.push(credit.name);
            }
        }

        let html = items.join(", ");
        html = items.length === 1 ? "Credit: " + html : "Credits: " + html;

        return html;
    }

    // /**
    //  * Gets the menu path to display for the plugin.
    //  *
    //  * @param {string | string[] | null}  menuPath The menu path to display.
    //  * @returns {string} The menu path to display, formatted as a string.
    //  */
    // menuPathToUse(menuPath: string | string[] | null): string {
    //     // If null, return ""
    //     if (menuPath === null) {
    //         return "";
    //     }

    //     // If it's an array, convert it to a string.
    //     if (Array.isArray(menuPath)) {
    //         menuPath = menuPath.join("/");
    //     }

    //     // Remove anything like [#], where # is a number
    //     menuPath = menuPath.replace(/\[\d+\] /g, "");

    //     menuPath = menuPath.replace(/\//g, " &rarr; ");

    //     return "Menu: " + menuPath;
    // }

    /**
     * Gets the test commands for the plugin. For advanced use.
     *
     * @gooddefault
     * @document
     * @returns {ITest}  The selenium test commands.
     */
    async getTests(): Promise<ITest[]> {
        const filterTest: ITest = {
            pluginOpen: () => new TestCmdList()
                .waitUntilRegex(`#modal-${this.pluginId}`, "About") // Wait for "About" to be visible
                .text(`#modal-${this.pluginId} input[type="text"]`, "Quit") // Filter for "Quit"
                .waitUntilNotRegex(`#modal-${this.pluginId}`, "About"), // "About" should now be hidden
            closePlugin: () => new TestCmdList().pressPopupButton(
                ".cancel-btn",
                this.pluginId
            ),
        };
        const basicTest: ITest = {
            closePlugin: () => new TestCmdList().pressPopupButton(
                ".cancel-btn",
                this.pluginId
            ),
        };
        return [filterTest, basicTest];
    }
}
</script>

<style scoped lang="scss">
.inverse-indent {
    text-indent: -1em;
    padding-left: 1em !important;
}
</style>