/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import _ from 'lodash' import i18n from '@/module/i18n' import store from '@/conf/home/store' /** * Node, to array */ const rtTargetarrArr = (id) => { let ids = $(`#${id}`).attr('data-targetarr') return ids ? ids.split(',') : [] } /** * Store node id to targetarr */ const saveTargetarr = (valId, domId) => { let $target = $(`#${domId}`) let targetStr = $target.attr('data-targetarr') ? $target.attr('data-targetarr') + `,${valId}` : `${valId}` $target.attr('data-targetarr', targetStr) } const rtBantpl = () => { return `` } /** * return node html */ const rtTasksTpl = ({ id, name, x, y, targetarr, isAttachment, taskType, runFlag }) => { let tpl = `` tpl += `
` tpl += `
` tpl += `
` tpl += `
` tpl += `${name}` tpl += `
` tpl += `
` tpl += `
` if (runFlag === 'FORBIDDEN') { tpl += rtBantpl() } tpl += `
` tpl += `
` return tpl } /** * Get all tasks nodes */ const tasksAll = () => { let a = [] $('#canvas .w').each(function (idx, elem) { let e = $(elem) a.push({ id: e.attr('id'), name: e.find('.name-p').text(), targetarr: e.attr('data-targetarr') || '', x: parseInt(e.css('left'), 10), y: parseInt(e.css('top'), 10) }) }) return a } /** * Determine if name is in the current dag map * rely dom / backfill */ const isNameExDag = (name, rely) => { if (rely === 'dom') { return _.findIndex(tasksAll(), v => v.name === name) !== -1 } else { return _.findIndex(store.state.dag.tasks, v => v.name === name) !== -1 } } /** * Change svg line color */ const setSvgColor = (e, color) => { // Traverse clear all colors $('.jtk-connector').each((i, o) => { _.map($(o)[0].childNodes, v => { $(v).attr('fill', '#555').attr('stroke', '#555').attr('stroke-width', 2) }) }) // Add color to the selection _.map($(e.canvas)[0].childNodes, (v, i) => { $(v).attr('fill', color).attr('stroke', color) if ($(v).attr('class')) { $(v).attr('stroke-width', 2) } }) } /** * Get all node ids */ const allNodesId = () => { let idArr = [] $('.w').each((i, o) => { let $obj = $(o) let $span = $obj.find('.name-p').text() if ($span) { idArr.push({ id: $obj.attr('id'), name: $span }) } }) return idArr } export { rtTargetarrArr, saveTargetarr, rtTasksTpl, tasksAll, isNameExDag, setSvgColor, allNodesId, rtBantpl }