diff --git a/__tests__/generate-2.js b/__tests__/generate-2.js index 9d313a9..34e5b65 100644 --- a/__tests__/generate-2.js +++ b/__tests__/generate-2.js @@ -2,7 +2,7 @@ const path = require('path'); const helpers = require('yeoman-test'); const child_process = require('child_process'); -describe('generator test 2: result-options webplugin project in ECMAScript', () => { +describe('generator test 2: legacy result-options webplugin project in ECMAScript', () => { /** @type {helpers.RunResult} */ let runResult; diff --git a/__tests__/generate-3.js b/__tests__/generate-3.js new file mode 100644 index 0000000..af9d33f --- /dev/null +++ b/__tests__/generate-3.js @@ -0,0 +1,70 @@ +const path = require('path'); +const helpers = require('yeoman-test'); +const child_process = require('child_process'); + +describe('generator test 3: result-batch webplugin project in TypeScript', () => { + /** @type {helpers.RunResult} */ + let runResult; + + beforeEach(async () => { + runResult = await helpers + .create(path.join(__dirname, '..')) + .withPrompts({ + appname: "plugin3", + description: "A test plugin (#3)", + slotId: "result-batch", + caption: "Test3", + minimumVersion: "3.3.2", + projectType: "typescript", + license: "MIT", + authorName: "John Doe", + authorEmail: "doe.j@nowhere", + authorGithub: "", + }) + .run(); + }); + afterEach(() => { + if (runResult) { + runResult.restore(); + } + }); + + it('generates correctly', () => { + // contains package.json + runResult.assertJsonFileContent('package.json', { + name: "plugin3", + description: "A test plugin (#3)", + license: "MIT", + scripts: { + "build": /.+/, + }, + dicoogle: { + "slot-id": "result-batch", + "caption": "Test3", + "module-file": "module.js" + }, + devDependencies: { + webpack: /.+/, + } + }); + + // has source files and build files + runResult.assertFile([ + 'src/index.ts', + 'webpack.common.js', + 'webpack.dev.js', + 'webpack.prod.js', + '.gitignore', + 'README.md', + ]); + + runResult.assertFileContent('src/index.ts', 'export default class MyPlugin'); + runResult.assertFileContent('src/index.ts', "slot.addEventListener('result-selection-ready', (ev) => {"); + + // force running npm install on target directory + child_process.execSync('npm install --no-audit', {cwd: runResult.cwd}); + + // has the output file module.js via `prepare` + runResult.assertFileContent('module.js', 'module.exports'); + }); +}); diff --git a/app/index.js b/app/index.js index c69424f..b269841 100644 --- a/app/index.js +++ b/app/index.js @@ -87,11 +87,11 @@ module.exports = class WebpluginGenerator extends Generator { name: 'minimumVersion', message: 'Please specify the minimum version of Dicoogle required for this plugin.', choices: [ + {name: '3.3.2', value: '3.3.2'}, {name: '3.1.0', value: '3.1.0'}, {name: '2.5.0 (legacy)', value: '2.5.0'}, - {name: '2.4.0 (legacy, more compatible)', value: '2.4.0'} ], - default: '3.1.0' + default: '3.3.2' }, { type: 'list', diff --git a/app/templates/src/_index.js b/app/templates/src/_index.js index 17879a7..ef31c03 100644 --- a/app/templates/src/_index.js +++ b/app/templates/src/_index.js @@ -17,7 +17,11 @@ export default class MyPlugin { parent.appendChild(div);<% if (dicoogle.slotId === 'query') { %> // dispatch a query with `Dicoogle.issueQuery`: // Dicoogle.issueQuery('CT'); -<% } %> +<% } %><% if (dicoogle.slotId === 'result-batch') { %> + // act on results selected + slot.addEventListener('result-selection-ready', (ev) => { + // use ev.detail + });<% } %> } <% if (dicoogle.slotId === 'result') { %> onResult(results) { diff --git a/app/templates/src/_index.ts b/app/templates/src/_index.ts index 4516781..bf04390 100644 --- a/app/templates/src/_index.ts +++ b/app/templates/src/_index.ts @@ -17,7 +17,11 @@ export default class MyPlugin { parent.appendChild(div);<% if (dicoogle.slotId === 'query') { %> // dispatch a query with `Dicoogle.issueQuery`: // Dicoogle.issueQuery('CT'); -<% } %> +<% } %><% if (dicoogle.slotId === 'result-batch') { %> + // act on results selected + slot.addEventListener('result-selection-ready', (ev) => { + // use ev.detail + });<% } %> } <% if (dicoogle.slotId === 'result') { %> onResult(results: SearchPatientResult[]) { // TODO show results here diff --git a/app/templates/src/_webcore.ts b/app/templates/src/_webcore.ts index e3c54c2..88d38cd 100644 --- a/app/templates/src/_webcore.ts +++ b/app/templates/src/_webcore.ts @@ -3,7 +3,7 @@ import {SearchPatientResult} from 'dicoogle-client'; export type WebPluginType = string; -export type WebcoreEvent = 'load' | 'result' | string; +export type WebcoreEvent = 'load' | 'result' | 'result-selection-ready' | string; export interface WebPlugin { name: string, @@ -35,9 +35,33 @@ export interface PluginData { results?: SearchPatientResult[]; [att: string]: any; } +<% if (semver.get(minimumVersion, '3.1.0')) { %> +export interface ResultSelectionReadyEvent { + detail: ResultSelectionData; +} +<% if (semver.get(minimumVersion, '3.3.2')) { %> +export type ResultSelectionData = {search: {data: SearchDetails}, selected: ResultSelection}; + +export interface SearchDetails { + results: SearchPatientResult[], + elapsedTime: number, + numResults: number, +} +<% } else { %> +export type ResultSelectionData = ResultSelection; +<% } %><% } %> + +export interface ResultSelection { + contents: object[], + level: string, +} export interface SlotHTMLElement extends HTMLElement { slotId: string; pluginName: string; data?: PluginData; +<% if (semver.get(minimumVersion, '3.1.0')) { %> + addEventListener(eventName: 'result-selection-ready', listener: (ev: ResultSelectionReadyEvent) => void): void; +<% } %> + addEventListener(eventName: string, listener: (ev: Event) => void): void; }