3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import guid
from '../libraries/guid'
20 import DropZone
from 'dropzone'
21 import Utils
from '../libraries/utils'
22 import CatalogPackageManagerActions
from '../actions/CatalogPackageManagerActions'
23 import ReactDOM
from 'react-dom'
24 import $ from 'jquery'
26 const API_SERVER
= Utils
.getSearchParams(window
.location
).api_server
;
31 export default class PackageManager
{
32 constructor(element
, button
, action
) {
38 this.stagingAreaMonitor
= null;
40 createStagingArea(type
, name
) {
42 url
: Utils
.getSearchParams(window
.location
).api_server
+ ':8008/api/operations/create-staging-area',
46 // Package type not important for package upload.
47 "package-type": type
|| "NSD",
48 "name": name
|| "Package Staging Area"
52 console
.log('Something went wrong creating the staging area: ', arguments
)
54 }).then(function(data
) {
58 "endpoint": "api/upload/85f8e2dc-638b-46e7-89cb-ee8de322066f",
63 const id
= data
.output
.endpoint
.split('/')[2];
64 const port
= data
.output
.port
;
65 this.stagingArea
.packages
.ids
.push(id
);
66 this.stagingArea
.packages
[id
] = {
72 monitoringStagingAreaSocket() {
74 if(self
.stagingAreaMonitor
) {
75 return self
.stagingAreaMonitor
;
77 new Promise(function(resolve
, reject
) {
79 url
: '/socket-polling',
81 beforeSend
: Utils
.addAuthorizationStub
,
83 url
: 'launchpad/api/nsr?api_server=' + API_SERVER
85 success: function(data
, textStatus
, jqXHR
) {
86 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
, self
.monitoringStagingAreaSocketHandler
);
93 monitoringStagingAreaSocketHandler(connection
) {
95 let ws
= window
.multiplexer
.channel(connection
);
96 if (!connection
) return;
97 self
.stagingAreaMonitor
= connection
;
98 ws
.onmessage = function(socket
) {
100 Utils
.checkAuthentication(data
.statusCode
, function() {
105 console
.log('An exception occurred in monitoringStagingAreaSocketHandler', e
)