Commit d669b2c7 authored by wubi's avatar wubi

完成测试模板接口对接

parent 2b1d95b8
......@@ -104,6 +104,9 @@ jQuery.propHooks.disabled = {
* See the License for the specific language governing permissions and
* limitations under the License.
**/
const HOST_IP = "http://192.168.0.82:8082";
var RED = (function() {
......@@ -324,12 +327,10 @@ var RED = (function() {
});
}
function loadFlows(done) {
function loadFlowsDeploy(done) {
loader.reportProgress(RED._("event.loadFlows"),80 )
let load_url = "flows";
if(getId()!=null){
load_url = `http://192.168.0.113:1909/getflows?id=${getId()}`
}
$.ajax({
headers: {
"Accept":"application/json",
......@@ -413,6 +414,150 @@ var RED = (function() {
});
}
// 获取当前时间并格式化YYYYMMDDHHmmss
function getFormattedTime() {
const now = new Date();
const padZero = (num) => num.toString().padStart(2, '0'); // 补零函数
const year = now.getFullYear();
const month = padZero(now.getMonth() + 1); // 月份需+1补正[1]()
const day = padZero(now.getDate());
const hours = padZero(now.getHours());
const minutes = padZero(now.getMinutes());
const seconds = padZero(now.getSeconds());
return `${year}${month}${day}${hours}${minutes}${seconds}`;
}
function loadFlows(done) {
loader.reportProgress(RED._("event.loadFlows"),80 )
let load_url = "flows";
let request_type = "GET";
const flowId = getId();
if(flowId!=null){
//load_url = `http://192.168.0.113:1909/getflows?id=${getId()}`
load_url = `${HOST_IP}/admin/wlp/testTemplate/findTemplateType`
request_type = "POST";
}else{
loadFlowsDeploy(done)
return;
}
$.ajax({
headers: {
'Authorization': sessionStorage.getItem("token"),
"Content-Type":"application/json",
},
type: request_type,
dataType: "text",
data: JSON.stringify({
"wlpTemplateDtoFilter": {
"templateType": 1,
"type": 1,
"templateNodeId":`${flowId}`
}
}),
cache: false,
url: load_url,
success: function(nodes) {
const templateIdMatch = nodes.match(/"templateId"\s*:\s*(\d+)/)
var tmpId = "";
if (templateIdMatch) {
tmpId = templateIdMatch[1]
}
nodes = JSON.parse(nodes);
if(nodes.data.length == 0){
nodes ={
"flows": [
{
"id": `${getNewID()}`,
"type": "tab",
"label": `${getFormattedTime()}`,
"disabled": false,
"info": "",
"env": []
}
]
}
}else{
RED.nodes.templateId = tmpId;
console.log(`122######templateId:${RED.nodes.templateId}`);
nodes = JSON.parse(nodes.data[0].templateConfig)
}
//console.log(nodes);
if (nodes) {
var currentHash = window.location.hash;
RED.nodes.version(nodes.rev);
loader.reportProgress(RED._("event.importFlows"),90 )
try {
RED.nodes.import(nodes.flows);
RED.nodes.dirty(false);
RED.view.redraw(true);
if (/^#(flow|node|group)\/.+$/.test(currentHash)) {
const hashParts = currentHash.split('/')
const showEditDialog = hashParts.length > 2 && hashParts[2] === 'edit'
if (hashParts[0] === '#flow') {
RED.workspaces.show(hashParts[1], true);
if (showEditDialog) {
RED.workspaces.edit()
}
} else if (hashParts[0] === '#node') {
const nodeToShow = RED.nodes.node(hashParts[1])
if (nodeToShow) {
setTimeout(() => {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
RED.view.select(nodeToShow.id)
if (showEditDialog) {
RED.editor.edit(nodeToShow)
}
}, 50)
}
} else if (hashParts[0] === '#group') {
const nodeToShow = RED.nodes.group(hashParts[1])
if (nodeToShow) {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
RED.view.select(nodeToShow.id)
if (showEditDialog) {
RED.editor.editGroup(nodeToShow)
}
}
}
}
if (RED.workspaces.count() > 0) {
const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");
const workspaces = RED.nodes.getWorkspaceOrder();
if (RED.workspaces.active() === 0) {
for (let index = 0; index < workspaces.length; index++) {
const ws = workspaces[index];
if (!hiddenTabs[ws]) {
RED.workspaces.show(ws);
break;
}
}
}
if (RED.workspaces.active() === 0) {
RED.workspaces.show(workspaces[0]);
}
}
RED.events.emit('flows:loaded')
} catch(err) {
console.warn(err);
RED.notify(
RED._("event.importError", {message: err.message}),
{
fixed: true,
type: 'error'
}
);
}
}
done();
}
});
}
function completeLoad(showProjectWelcome) {
var persistentNotifications = {};
RED.comms.subscribe("notification/#",function(topic,msg) {
......@@ -4431,6 +4576,7 @@ RED.nodes = (function() {
var initialLoad;
var dirty = false;
var templateId;
function setDirty(d) {
dirty = d;
......@@ -75414,15 +75560,72 @@ const saveNode=()=>{
console.log("save")
const nns = RED.nodes.createCompleteNodeSet();
const data = { id:nns[0].id,label:nns[0].label,flows: nns };
//先查询是否存在
$.ajax({
url: "http://192.168.0.113:1909/save",
headers: {
'Authorization': sessionStorage.getItem("token"),
"Content-Type":"application/json",
},
type: "POST",
data: JSON.stringify(data),
dataType: "json",
data: JSON.stringify({
"wlpTemplateDtoFilter": {
"templateType": 1,
"type": 1,
"templateNodeId":`${data.id}`
}
}),
cache: false,
url: `${HOST_IP}/admin/wlp/testTemplate/findTemplateType`,
success: function(nodes) {
var update_url = "";
var update_obj = "";
if(nodes.data.length == 0){
//新建
update_url = `${HOST_IP}/admin/wlp/testTemplate/addTemplateType`;
update_obj = {
"wlpTemplateDtoFilter": {
"templateType": 1,
"type": 1,
"templateConfig": JSON.stringify(data),
"templateName":`${data.label}`,
"templateNodeId": `${data.id}`,
}
}
}else{
//更新
update_url = `${HOST_IP}/admin/wlp/testTemplate/updateTemplateType`;
update_obj = {
"wlpTemplateDto": {
"templateId":RED.nodes.templateId,
"templateType": 1,
"type": 1,
"templateConfig": JSON.stringify(data),
"templateName":`${data.label}`,
"templateNodeId": `${data.id}`,
}
}
}
$.ajax({
url: update_url,
type: "POST",
headers:{
'Authorization': sessionStorage.getItem("token")
},
dataType:"text",
data: JSON.stringify(update_obj),
contentType: "application/json; charset=utf-8",
//headers: {
// "Node-RED-Deployment-Type": deploymentType
//}
}).done(function (data, textStatus, xhr) {
const templateIdMatch = data.match(/"data"\s*:\s*(\d+)/)
var tmpId = "";
if (templateIdMatch) {
tmpId = templateIdMatch[1]
RED.nodes.templateId = tmpId
console.log(`add id:${tmpId}`);
}
RED.nodes.dirty(false);
//RED.nodes.version(data.rev);
RED.nodes.originalFlow(nns);
......@@ -75504,4 +75707,7 @@ const saveNode=()=>{
RED.sidebar.config.refresh();
RED.events.emit("deploy");
})
}});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment