Sidebar-PumpsComponent.js 2.1 KB

(function () {
	// Adds Atlassian shapes
	// Pumps label
	Sidebar.prototype.addThingsKitPumpsPalette = function () {

		const gn = 'mxgraph.pumps';
		const dt = 'pumps';
		const label = mxResources.get('pump')
		const width = 66;
		const height = 74;
		const prefix = `image;image=${window?.PROJECT_ENV.base}/webapp/images/thingskit/libs/`
		const defaultStyle = ';imageAspect=0;'
		this.setCurrentSearchEntryLibrary(dt);

		const { COMPONENT_KEY, CATEGORY } = window.CellAttributeKeyEnum

		function createUserObject(attribute) {
			attribute = Object.assign({ [COMPONENT_KEY]: '', [CATEGORY]: '' }, attribute || {})
			var xmlElement = mxUtils.createXmlDocument().createElement('UserObject');

			Object.keys(attribute).forEach(key => {
				xmlElement.setAttribute(key, attribute[key]);
			})
			return xmlElement
		}

		// 自定义属性
		const cellAttribute = {
			[COMPONENT_KEY]: 'Image',
			[CATEGORY]: 'DEFAULT'
		}

		const graphPathLib = [
			{ name: mxResources.get('pump') + '1_OFF', path: 'Pumps/泵1_OFF.png' },
			{ name: mxResources.get('pump') + '1_ON', path: 'Pumps/泵1_ON.gif' },
			{ name: mxResources.get('pump') + '2_OFF', path: 'Pumps/泵2_OFF.png' },
			{ name: mxResources.get('pump') + '2_ON', path: 'Pumps/泵2_ON.gif' },
			{ name: mxResources.get('pump') + '3_OFF', path: 'Pumps/泵3_OFF.png' },
			{ name: mxResources.get('pump') + '3_ON', path: 'Pumps/泵3_ON.gif' },
			{ name: mxResources.get('pump') + '4_OFF', path: 'Pumps/泵4_OFF.png' },
			{ name: mxResources.get('pump') + '4_ON', path: 'Pumps/泵4_ON.gif' },
		]



		const fns = graphPathLib.map(item => {
			return this.addEntry(this.getTagsForStencil(gn, item.name, dt).join(' '), mxUtils.bind(this, function () {
				const cell = new mxCell(createUserObject(cellAttribute), new mxGeometry(0, 0, width, height), `${prefix}${item.path}${defaultStyle}`);
				cell.setVertex(true)

				return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, item.name);
			}));
		})


		this.setGalleryLib(dt, label, graphPathLib)

		this.addPaletteFunctions(dt, label, false, fns);

		this.setCurrentSearchEntryLibrary();
	};
})();