2 * STANDARD_RIFT_IO_COPYRIGHT
4 import $ from 'jquery';
5 var Utils
= require('utils/utils.js');
6 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).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;
12 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
16 let Projects
= mockProjects();
17 let Users
= mockUsers();
20 module
.exports = function(Alt
) {
25 return new Promise(function(resolve
, reject
) {
26 // setTimeout(function() {
30 url
: `/user?api_server=${API_SERVER}`,
32 beforeSend
: Utils
.addAuthorizationStub
,
33 success: function(data
, textStatus
, jqXHR
) {
36 }).fail(function(xhr
){
37 //Authentication and the handling of fail states should be wrapped up into a connection class.
38 Utils
.checkAuthentication(xhr
.status
);
39 let msg
= xhr
.responseText
;
40 if(xhr
.errorMessage
) {
41 msg
= xhr
.errorMessage
47 interceptResponse
: interceptResponse({
48 'error': 'There was an error retrieving the resource orchestrator information.'
50 success
: Alt
.actions
.global
.getPlatformRoleUsersSuccess
,
51 loading
: Alt
.actions
.global
.showScreenLoader
,
52 error
: Alt
.actions
.global
.showNotification
56 return new Promise(function(resolve
, reject
) {
57 // setTimeout(function() {
61 url
: `/platform?api_server=${API_SERVER}`,
63 beforeSend
: Utils
.addAuthorizationStub
,
64 success: function(data
, textStatus
, jqXHR
) {
65 resolve(data
.platform
);
67 }).fail(function(xhr
){
68 //Authentication and the handling of fail states should be wrapped up into a connection class.
69 Utils
.checkAuthentication(xhr
.status
);
70 let msg
= xhr
.responseText
;
71 if(xhr
.errorMessage
) {
72 msg
= xhr
.errorMessage
78 interceptResponse
: interceptResponse({
79 'error': 'There was an error retrieving the resource orchestrator information.'
81 success
: Alt
.actions
.global
.getPlatformSuccess
,
82 loading
: Alt
.actions
.global
.showScreenLoader
,
83 error
: Alt
.actions
.global
.showNotification
86 remote: function(state
, project
) {
87 return new Promise(function(resolve
, reject
) {
89 url
: `/platform?api_server=${API_SERVER}`,
92 beforeSend
: Utils
.addAuthorizationStub
,
93 success: function(data
, textStatus
, jqXHR
) {
96 }).fail(function(xhr
){
97 //Authentication and the handling of fail states should be wrapped up into a connection class.
98 Utils
.checkAuthentication(xhr
.status
);
99 let msg
= xhr
.responseText
;
100 if(xhr
.errorMessage
) {
101 msg
= xhr
.errorMessage
107 interceptResponse
: interceptResponse({
108 'error': 'There was an error updating the project.'
110 success
: Alt
.actions
.global
.updateProjectSuccess
,
111 loading
: Alt
.actions
.global
.showScreenLoader
,
112 error
: Alt
.actions
.global
.showNotification
115 remote: function(state
, project
) {
116 return new Promise(function(resolve
, reject
) {
117 // setTimeout(function() {
121 url
: `/project/${project['name']}?api_server=${API_SERVER}`,
123 beforeSend
: Utils
.addAuthorizationStub
,
124 success: function(data
, textStatus
, jqXHR
) {
127 }).fail(function(xhr
){
128 //Authentication and the handling of fail states should be wrapped up into a connection class.
129 Utils
.checkAuthentication(xhr
.status
);
130 let msg
= xhr
.responseText
;
131 if(xhr
.errorMessage
) {
132 msg
= xhr
.errorMessage
138 interceptResponse
: interceptResponse({
139 'error': 'There was an error deleting the user.'
141 success
: Alt
.actions
.global
.deleteProjectSuccess
,
142 loading
: Alt
.actions
.global
.showScreenLoader
,
143 error
: Alt
.actions
.global
.showNotification
146 remote: function(state
, project
) {
148 return new Promise(function(resolve
, reject
) {
149 // setTimeout(function() {
153 url
: `/project?api_server=${API_SERVER}`,
156 beforeSend
: Utils
.addAuthorizationStub
,
157 success: function(data
, textStatus
, jqXHR
) {
160 }).fail(function(xhr
){
161 //Authentication and the handling of fail states should be wrapped up into a connection class.
162 Utils
.checkAuthentication(xhr
.status
);
163 let msg
= xhr
.responseText
;
164 if(xhr
.errorMessage
) {
165 msg
= xhr
.errorMessage
171 interceptResponse
: interceptResponse({
172 'error': 'There was an error updating the account.'
174 success
: Alt
.actions
.global
.createProjectSuccess
,
175 loading
: Alt
.actions
.global
.showScreenLoader
,
176 error
: Alt
.actions
.global
.showNotification
181 function interceptResponse (responses
) {
182 return function(data
, action
, args
) {
183 if(responses
.hasOwnProperty(data
)) {
194 function mockProjects() {
197 for(let i
= 0; i
< 3; i
++) {
199 name
: `Test Project ${i}`,
200 description
: 'Some description',
201 roles
: ['Some-Role', 'Some-Other-Role'],
204 'user-name': 'Some-User',
205 'user-domain': 'system',
209 'key-set' : 'some key'
212 'role': 'Some-Other-Role',
213 'key-set' : 'some key'
218 'user-name': 'Some-User',
219 'user-domain': 'system',
223 'key-set' : 'some key'
232 function mockUsers() {
235 for(let i
= 0; i
< 10; i
++) {
237 'user-name': `Tester ${i}`,
238 'user-domain': 'Some Domain',
241 platform_admin
: false,