Sidebar-HeaterComponent.js 2.73 KB

(function () {
	// Adds Atlassian shapes
	// heater label
	Sidebar.prototype.addThingsKitHeaterPalette = function () {

		const gn = 'mxgraph.heater';
		const dt = 'heater';
		const label = mxResources.get('heater')
		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('heater1'), path: 'heater/加热器.svg' },
			{ name: mxResources.get('heater2'), path: 'heater/批烤箱.svg' },
			{ name: mxResources.get('heater3'), path: 'heater/换热器.svg' },
			{ name: mxResources.get('heater4'), path: 'heater/换热器2.svg' },
			{ name: mxResources.get('heater5'), path: 'heater/换热器3.svg' },
			{ name: mxResources.get('heater6'), path: 'heater/换热器4.svg' },
			{ name: mxResources.get('heater7'), path: 'heater/火焰锅炉.svg' },
			{ name: mxResources.get('heater8'), path: 'heater/热回收锅炉.svg' },
			{ name: mxResources.get('heater9'), path: 'heater/燃油锅炉.svg' },
			{ name: mxResources.get('heater10'), path: 'heater/燃煤锅炉.svg' },
			{ name: mxResources.get('heater11'), path: 'heater/蒸发器.svg' },
			{ name: mxResources.get('heater12'), path: 'heater/蒸汽混合器.svg' },
			{ name: mxResources.get('heater13'), path: 'heater/蒸汽混合器2.svg' },
			{ name: mxResources.get('heater14'), path: 'heater/蒸汽锅炉.svg' },
			{ name: mxResources.get('heater15'), path: 'heater/过热器.svg' },
			{ name: mxResources.get('heater16'), path: 'heater/锅炉.svg' },
			{ name: mxResources.get('heater17'), path: 'heater/锅炉2.svg' },
		]



		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();
	};
})();