Skip to content

Toolbar Should Use Axios for HTTP Requests #117

@HeriLFIU

Description

@HeriLFIU

var request = $.ajax({
async: true,
dataType: "json",
type: "POST",
contentType: "application/json",
data: JSON.stringify({"description": self.description,
"start": self.start,
"end": self.end,
"switches": filteredSwitches,
"links": filteredLinks,
"interfaces": filteredInterfaces,
"force": self.checked_list.includes("force"),
}),
url:this.$kytos_server_api + "kytos/maintenance/v1",
});
request.done(function(data) {
let notification = {
icon: 'gear',
title: 'Maintenance Window Created',
description: 'Maintenance Window with id ' + data.mw_id + ' was created.'
}
self.$kytos.eventBus.$emit("setNotification", notification);
// Clearing fields if POST is a success
self.forceRenderer();
}),
request.fail(function(jqXHR, status, error) {
var error_message = JSON.parse(jqXHR.responseText)
if (error_message.hasOwnProperty('response')) {
error_message = error_message.response
} else if (error_message.hasOwnProperty('description')) {
error_message = error_message.description
}
if(error_message.includes('%Y-%m-%dT%H:%M:%S%z') || (error_message.includes('start')) || (error_message.includes('past'))){
error_message += '. Remember that the actual format for time is YYY-MM-DDTHH:MM:SS-0000, for example, 2026-04-22T11:41:01-0000'
}
let notification = {
icon: 'gear',
title: 'Maintenance Window not created',
description: 'Maintenance Window was not created. Error: ' + error_message
}
self.$kytos.eventBus.$emit("setNotification", notification);
})
},
/*
Gets the Switch and Interface information using the GET api call from topology.
*/
loadNames: function() {
let _dpid_names = [];
let _interface_names = [];
var _this = this;
var request = $.ajax({
url: this.$kytos_server_api + "kytos/topology/v3/switches",
type: "GET",
data: JSON.stringify(),
dataType: "json",
contentType: "application/json; charset=utf-8"
});
request.done(function(data) {
let switches = data.switches;
$.each(switches, function(i, sw) {
if(sw.metadata.node_name){
_dpid_names.push({"value": sw.id, "description": sw.metadata.node_name})
}
else{
_dpid_names.push({"value": sw.id, "description": sw.id})
}
if(sw.interfaces){
$.each(sw.interfaces, function(j, k_interface){
if(!k_interface.metadata.port_name){
_interface_names.push({"value": k_interface.id, "description": k_interface.id})
}
else{
_interface_names.push({"value": k_interface.id, "description": k_interface.metadata.port_name})
}
});
}
});
_this.dpid_names = _dpid_names;
_this.interface_names = _interface_names;
});
request.fail(function( jqXHR, textStatus ) {
alert("Request failed: " + textStatus);
});
},
/*
Gets the Link information using the Get api call from the topology api.
*/
loadLinks: function(){
let _link_names = [];
var _this = this;
var request = $.ajax({
url: this.$kytos_server_api + "kytos/topology/v3/links",
type: "GET",
dataType: "json",
contentType: "application/json"
});
request.done(function(data) {
let links = data.links;
$.each(links, function(i, li) {
if(li.metadata.link_name){
_link_names.push({"value": li.id, "description": li.metadata.link_name})
}
else{
_link_names.push({"value": li.id, "description": li.id})
}
});
_this.link_names = _link_names;
});
request.fail(function( jqXHR, textStatus) {
alert("Request failed: " + textStatus)
});
},

jQuery AJAX should be replaced with Axios

Use as reference:
kytos-ng/mef_eline#659

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions