Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / debug / src / crashSource.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 var rw = require('utils/rw.js');
20 var API_SERVER = rw.getSearchParams(window.location).api_server;
21 var crashActions = require('./crashActions.js');
22 var Utils = require('utils/utils.js');
23 import $ from 'jquery';
24 var crashSource = {
25
26 get: function() {
27 return {
28 remote: function(state) {
29 return new Promise(function(resolve, reject) {
30 $.ajax({
31 url: 'api/crash-details?api_server=' + API_SERVER,
32 type:'GET',
33 beforeSend: Utils.addAuthorizationStub,
34 contentType: "application/json",
35 success: function(data) {
36 resolve(data);
37 },
38 error: function(error) {
39 console.log("There was an error getting the crash details: ", error);
40 reject(error);
41 }
42 }).fail(function(xhr){
43 console.log('fail')
44 //Authentication and the handling of fail states should be wrapped up into a connection class.
45 Utils.checkAuthentication(xhr.status);
46 });
47 }).catch(function(err){console.log(err)});
48 },
49 success: crashActions.getCrashDetailsSuccess,
50 loading: crashActions.getCrashDetailsLoading,
51 error: crashActions.getCrashDetailsFail
52 }
53 }
54 }
55 module.exports = crashSource;