All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nz.ac.auckland.lmz.controlpanel.panels.GroovyShellContolpanel.groovy Maven / Gradle / Ivy

There is a newer version: 3.3
Show newest version
package nz.ac.auckland.lmz.controlpanel.panels

import groovy.transform.CompileStatic
import nz.ac.auckland.common.stereotypes.UniversityComponent
import nz.ac.auckland.lmz.controlpanel.DefaultControlPanelAssets
import nz.ac.auckland.lmz.controlpanel.bus.GroovyShellExecEventHandler
import nz.ac.auckland.lmz.controlpanel.core.ControlPanel
import nz.ac.auckland.lmz.controlpanel.core.ControlPanelAssets
import nz.ac.auckland.lmz.controlpanel.core.ControlPanelMetadata
import nz.ac.auckland.stencil.LinkBuilder

import javax.annotation.PostConstruct
import javax.inject.Inject


@UniversityComponent
@CompileStatic
class GroovyShellContolpanel implements ControlPanel {

	@Inject LinkBuilder linkBuilder
	@Inject DefaultControlPanelAssets defaultControlPanelAssets

	/**
	 * @return the control panel meta data
	 */
	@Override
	ControlPanelMetadata getMetadata() {

		return new ControlPanelMetadata(
				title: "Groovy Admin Console",
				description: "Admin console for running groovy script",
				uri: "admin-console",
				assets: new ControlPanelAssets(
						javascripts: ['/groovyshell/js/groovyshell.js'],
						stylesheets: ['/groovyshell/css/groovyshell.css'],
						embeds: [defaultControlPanelAssets as ControlPanelAssets])
		);
	}

	/**
	 * @return the template to render
	 */
	@Override
	String getTemplate() {
		return "/groovyshell/jsp/groovyshell.jsp";
	}

	/**
	 * @return current user information and table of available fake users
	 */
	@Override
	Map getViewModel() {
		String hinttext = """
// Groovy Code here

// Implicit variables include:
//    ctx: spring context
"""
		GroovyShellExecEventHandler.defaultBeans.each { String beanName, List data ->
			hinttext += "\n//     ${beanName}: ${data[1]}"
		}

		hinttext += "\n\n// Hint:\n// use listBeans() to see all available beans\n"
		hinttext += "// use listBeanMethods(bean) to see method names\n"

		return [hinttext:hinttext]
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy