Merge "Bug 44 fixed."
[osm/UI.git] / skyquake / plugins / config / src / dashboard / configSource.js
1 /*
2 * STANDARD_RIFT_IO_COPYRIGHT
3 */
4 import $ from 'jquery';
5 var Utils = require('utils/utils.js');
6 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
7 let HOST = API_SERVER;
8 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
9 let DEV_MODE = require('utils/rw.js').getSearchParams(window.location).dev_mode || false;
10
11 if (DEV_MODE) {
12 HOST = window.location.protocol + '//' + window.location.hostname;
13 }
14
15
16 module.exports = function(Alt) {
17 return {
18 getResourceOrchestrator: {
19 remote: function() {
20 return new Promise(function(resolve, reject) {
21 $.ajax({
22 url: 'passthrough/data/api/running/resource-orchestrator' + '?api_server=' + API_SERVER,
23 type: 'GET',
24 beforeSend: Utils.addAuthorizationStub,
25 contentType: "application/json",
26 success: function(data) {
27 resolve(data["rw-launchpad:resource-orchestrator"]);
28 },
29 error: function(error) {
30 console.log("There was an error updating the account: ", arguments);
31
32 }
33 }).fail(function(xhr){
34 //Authentication and the handling of fail states should be wrapped up into a connection class.
35 Utils.checkAuthentication(xhr.status);
36 return reject('error');
37 });
38 });
39 },
40 interceptResponse: interceptResponse({
41 'error': 'There was an error retrieving the resource orchestrator information.'
42 }),
43 success: Alt.actions.global.getResourceOrchestratorSuccess,
44 loading: Alt.actions.global.showScreenLoader,
45 error: Alt.actions.global.showNotification
46 },
47 update: {
48 remote: function(state, account) {
49
50 return new Promise(function(resolve, reject) {
51 $.ajax({
52 url: 'resource-orchestrator' + '?api_server=' + API_SERVER,
53 type:'PUT',
54 beforeSend: Utils.addAuthorizationStub,
55 data: JSON.stringify(account),
56 contentType: "application/json",
57 success: function(data) {
58 resolve({data});
59 },
60 error: function(error) {
61 console.log("There was an error updating the account: ", arguments);
62 return null;
63 }
64 }).fail(function(xhr){
65 //Authentication and the handling of fail states should be wrapped up into a connection class.
66 Utils.checkAuthentication(xhr.status);
67 return reject('error');
68 });
69
70 });
71 },
72 interceptResponse: interceptResponse({
73 'error': 'There was an error updating the account.'
74 }),
75 success: Alt.actions.global.updateResourceOrchestratorSuccess,
76 loading: Alt.actions.global.showScreenLoader,
77 error: Alt.actions.global.showNotification
78 }
79 }
80 }
81
82 function interceptResponse (responses) {
83 return function(data, action, args) {
84 if(responses.hasOwnProperty(data)) {
85 return {
86 type: data,
87 msg: responses[data]
88 }
89 } else {
90 return data;
91 }
92 }
93 }