|
1 | 1 | // local storage access |
2 | 2 | import moment from "moment"; |
3 | 3 | import {Dictionary, DictType} from "./dictionary"; |
4 | | -export const version = "2.4.0"; |
| 4 | +export const version = "2.5.0"; |
5 | 5 |
|
6 | 6 | export function getData(key) { |
7 | 7 | let ls = null; |
@@ -67,6 +67,19 @@ export function getHttpProtocol(config) { |
67 | 67 | } |
68 | 68 | } |
69 | 69 |
|
| 70 | +export function getServerInfo(config) { |
| 71 | + if (config.servers && config.servers.length > 0) { |
| 72 | + let server = config.servers.filter((server) => server.default); |
| 73 | + if (server && server.length > 0) { |
| 74 | + return { address: server[0].address, port: server[0].port }; |
| 75 | + } else { |
| 76 | + return null; |
| 77 | + } |
| 78 | + } else { |
| 79 | + return null; |
| 80 | + } |
| 81 | +} |
| 82 | + |
70 | 83 | export function buildHttpProtocol(config) { |
71 | 84 | if (config.servers && config.servers.length > 0) { |
72 | 85 | let idx = 0; |
@@ -332,6 +345,25 @@ export function getParam(props, key) { |
332 | 345 | } |
333 | 346 | } |
334 | 347 |
|
| 348 | +export function setXlogfilterToUrl (props, filter) { |
| 349 | + |
| 350 | + let search = new URLSearchParams(props.location.search); |
| 351 | + |
| 352 | + if(filter === null) { |
| 353 | + search.delete("xlogfilter"); |
| 354 | + }else{ |
| 355 | + search.set("xlogfilter", JSON.stringify(filter)); |
| 356 | + } |
| 357 | + |
| 358 | + if (props.location.search !== ("?" + search.toString())) { |
| 359 | + props.history.replace({ |
| 360 | + pathname: props.location.pathname, |
| 361 | + search: "?" + search.toString() |
| 362 | + }); |
| 363 | + } |
| 364 | + |
| 365 | +} |
| 366 | + |
335 | 367 | export function setRangePropsToUrl (props, pathname, objects) { |
336 | 368 | let search = new URLSearchParams(props.location.search); |
337 | 369 |
|
@@ -363,6 +395,7 @@ export function setRangePropsToUrl (props, pathname, objects) { |
363 | 395 |
|
364 | 396 | search.set("from", from.format("YYYYMMDDHHmmss")); |
365 | 397 | search.set("to", to.format("YYYYMMDDHHmmss")); |
| 398 | + search.set("fromPast", props.range.fromPast); |
366 | 399 |
|
367 | 400 | if (props.location.search !== ("?" + search.toString())) { |
368 | 401 | if (pathname) { |
@@ -398,6 +431,94 @@ export function setTxidPropsToUrl (props, txiddate, txid) { |
398 | 431 | } |
399 | 432 | } |
400 | 433 |
|
| 434 | +export function setTargetServerToUrl (props, config, anotherParam) { |
| 435 | + const server = getServerInfo(config); |
| 436 | + if (server && server.address) { |
| 437 | + setTargetServerToUrl0(props, server.address, server.port, server.protocol, anotherParam); |
| 438 | + } |
| 439 | +} |
| 440 | + |
| 441 | +const ALL_OPTIONS_OF_SERVER_KEY = "allOptionsOfServer"; |
| 442 | + |
| 443 | +export function clearAllUrlParamOfPaper (props, config) { |
| 444 | + props.history.push({ |
| 445 | + pathname: props.location.pathname |
| 446 | + }); |
| 447 | +} |
| 448 | + |
| 449 | +export function replaceAllLocalSettingsForServerChange (currentServer, props, config) { |
| 450 | + if (currentServer && currentServer.address) { |
| 451 | + saveCurrentAllLocalSettings(currentServer, config); |
| 452 | + reloadAllLocalSettingsOfServer(props, config); |
| 453 | + } |
| 454 | +} |
| 455 | + |
| 456 | +export function saveCurrentAllLocalSettings (currentServer, config) { |
| 457 | + const serverKey = currentServer.address + ":" + currentServer.port; |
| 458 | + |
| 459 | + const option = { |
| 460 | + server: serverKey, |
| 461 | + options: { |
| 462 | + selectedObjects : getData("selectedObjects"), |
| 463 | + templateName : getData("templateName"), |
| 464 | + layouts : getData("layouts"), |
| 465 | + boxes : getData("boxes"), |
| 466 | + preset : getData("preset"), |
| 467 | + profileOptions : getData("profileOptions"), |
| 468 | + topologyPosition : getData("topologyPosition"), |
| 469 | + topologyOptions : getData("topologyOptions"), |
| 470 | + alert : getData("alert") |
| 471 | + } |
| 472 | + }; |
| 473 | + |
| 474 | + const allOptionsOfServer = getData(ALL_OPTIONS_OF_SERVER_KEY) || []; |
| 475 | + let allOptions = allOptionsOfServer.filter(option => option.server !== serverKey); |
| 476 | + allOptions.push(option); |
| 477 | + |
| 478 | + setData(ALL_OPTIONS_OF_SERVER_KEY, allOptions); |
| 479 | +} |
| 480 | + |
| 481 | +export function reloadAllLocalSettingsOfServer (props, config) { |
| 482 | + const server = getServerInfo(config); |
| 483 | + if (server && server.address) { |
| 484 | + const serverKey = server.address + ":" + server.port; |
| 485 | + const allOptionsOfServer = getData(ALL_OPTIONS_OF_SERVER_KEY) || []; |
| 486 | + const option = allOptionsOfServer.filter(option => option["server"] === serverKey); |
| 487 | + |
| 488 | + if (option && option[0] && option[0].options) { |
| 489 | + setData("selectedObjects", option[0].options["selectedObjects"]); |
| 490 | + setData("templateName", option[0].options["templateName"]); |
| 491 | + setData("layouts", option[0].options["layouts"]); |
| 492 | + setData("boxes", option[0].options["boxes"]); |
| 493 | + setData("preset", option[0].options["preset"]); |
| 494 | + setData("profileOptions", option[0].options["profileOptions"]); |
| 495 | + setData("topologyPosition", option[0].options["topologyPosition"]); |
| 496 | + setData("topologyOptions", option[0].options["topologyOptions"]); |
| 497 | + setData("alert", option[0].options["alert"]); |
| 498 | + } |
| 499 | + } |
| 500 | +} |
| 501 | + |
| 502 | +export function setTargetServerToUrl0 (props, serverAddr, serverPort, protocol, anotherParam) { |
| 503 | + let search = new URLSearchParams(props.location.search); |
| 504 | + |
| 505 | + search.set("address", serverAddr); |
| 506 | + search.set("port", serverPort); |
| 507 | + search.set("protocol", protocol || "http"); |
| 508 | + for (let key in anotherParam) { |
| 509 | + if (anotherParam[key]) { |
| 510 | + search.set(key, anotherParam[key]); |
| 511 | + } |
| 512 | + } |
| 513 | + |
| 514 | + if (props.location.search !== ("?" + search.toString())) { |
| 515 | + props.history.replace({ |
| 516 | + pathname: props.location.pathname, |
| 517 | + search: "?" + search.toString() |
| 518 | + }); |
| 519 | + } |
| 520 | +} |
| 521 | + |
401 | 522 | const table = [ |
402 | 523 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
403 | 524 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
|
0 commit comments