Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.0.1 Support - Updated to new HApi structure. #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "kibana_api",
"version": "0.6.2",
"description": "This plugin allow you to crete visualization dynamiclly",
"description": "This plugin allow you to crete visualization dynamically",
"main": "index.js",
"kibana": {
"version": "6.5.2"
"version": "7.0.1"
},
"repository": {
"type": "git",
Expand Down
92 changes: 45 additions & 47 deletions server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ export default function (server) {

path: '/api/visStructure',
method: 'GET',
handler(req, reply) {
handler(req, h) {

var file = __dirname + '/visStruct.json';
jsonfile.readFile(file, function (err, obj) {
if (err)
console.dir(err)
reply(obj);

})
return new Promise((resolve, reject) => {
jsonfile.readFile(file, (err, obj) => {
if(err)
reject(err);
else
resolve(obj);
});

})
}
});

Expand All @@ -43,10 +46,8 @@ export default function (server) {

path: '/api/getIndexPatternId',
method: 'POST',
handler(req, reply) {
getIndexPatternId(req).then((indexPattern) => {
reply(indexPattern);
});
handler(req, h) {
return getIndexPatternId(req);
}
});

Expand All @@ -55,15 +56,9 @@ export default function (server) {

path: '/api/createVis/createVisByVisState',
method: 'POST',
handler(req, reply) {
handler(req, h) {

callWithRequest(req, 'bulk', {body: getBulkBody(req.payload, server.config().get('kibana.index'))}).then(function (response) {
reply(response);
},
function (error) {
reply(error);
}
);
return callWithRequest(req, 'bulk', {body: getBulkBody(req.payload, server.config().get('kibana.index'))});

}
});
Expand All @@ -72,61 +67,64 @@ export default function (server) {

path: '/api/createIndexPattern',
method: 'POST',
handler(req, reply) {
getIndexPatternId(req).then((indexPattern) => {
handler(req, h) {
return getIndexPatternId(req)
.then((indexPattern) => {
if (indexPattern.length == 0) {
let options = {
headers: {'content-type': 'application/json', 'kbn-version': getKibanVersion()},
url: req.headers.referer.split('app')[0] + 'api/saved_objects/index-pattern',
json: {attributes: {timeFieldName: req.payload.timeFieldName, title: req.payload.title}}
};
request.post(options, function (error, response, body) {
try {
if (error) {
console.log(error);
reply(error);
}
else {
reply(body);
return new Promise((resolve, reject) => {
request.post(options, function (error, response, body) {
try {
if (error) {
console.log(error);
reject(error);
}
else {
resolve(body);
}
} catch (e) {
console.log(e);
return reject(e);

}
} catch (e) {
console.log(e);
reply(e);

}
});
});
}
else {
reply({});
return Promise.resolve({});
}
})


}
});

server.route({

path: '/api/setIndexPattern',
method: 'POST',
handler(req, reply) {
getIndexPatternId(req).then((indexPattern) => {
handler(req, h) {
return getIndexPatternId(req).then((indexPattern) => {
let urlHeader = req.headers.referer.split('app')[0] + 'api/';
let url = urlHeader + 'kibana/settings/defaultIndex';
let options = {
headers: {'content-type': 'application/json', 'kbn-version': getKibanVersion()},
url: url,
json: {value: indexPattern[0].id}
};
request.post(options, function (error, response, body) {
if (error) {
console.log(error);
reply(error);
}
console.log(body);

reply(body);

return new Promise((resolve, reject) => {
request.post(options, function (error, response, body) {
if (error) {
console.log(error);
reject(error);
}
console.log(body);

resolve(body);

});
});
});

Expand Down