Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Commit fc3dbb6

Browse files
authored
Merge pull request #1004 from rajthilakmca/1.5
add take snapshot button and action also
2 parents b174523 + 68680c8 commit fc3dbb6

File tree

8 files changed

+211
-159
lines changed

8 files changed

+211
-159
lines changed

app/assets/javascripts/nilavu/components/file-uploader.js.es6

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export default Ember.Component.extend({
1818
objectIcon: null,
1919
signingUrl: '',
2020

21+
filekey: null,
22+
fileaccesskey: null,
23+
filepolicy: null,
24+
filesignature: null,
25+
2126
uploadPercentage: 0,
2227
progressPosition: 0,
2328
maxProgressPosition: 100,
@@ -56,71 +61,100 @@ export default Ember.Component.extend({
5661
return this.get('spinnerConnectIn');
5762
}.property('spinnerConnectIn'),
5863

59-
/* _bindUploadTarget() {
60-
//this._unbindUploadTarget(); // in case it's still bound, let's clean it up first
61-
const self = this;
62-
const $element = $("#fileformupload");
63-
$element.fileupload({
64-
url: "/b/put",
65-
autoUpload: true,
66-
add: function(e, data) {
67-
// Automatically upload the file once it is added to the queue
68-
var jqXHR = data.submit();
69-
},
70-
71-
progress: function(e, data) {
72-
// Calculate the completion percentage of the upload
73-
var progress = parseInt(data.loaded / data.total * 100, 10);
74-
console.log(progress);
75-
},
76-
77-
done: function(e, data) {
78-
console.log("success------------");
79-
console.log(data);
80-
console.log(e);
81-
},
82-
83-
fail: function(e, data) {
84-
console.log("fail------------");
85-
console.log(data);
86-
console.log(e);
87-
}
88-
});
89-
90-
},*/
91-
9264
_bindUploadTarget() {
9365
//this._unbindUploadTarget(); // in case it's still bound, let's clean it up first
9466
const self = this;
95-
const $element = this.$();
67+
const $element = this.$("#fileformupload");
9668
$element.fileupload({
97-
url: "http://192.168.0.115/woww",
69+
url: "",
9870
pasteZone: $element,
99-
forceIframeTransport: true,
71+
//forceIframeTransport: true,
10072
autoUpload: true,
73+
dataType: 'xml',
74+
type: 'POST',
75+
xhrFields: {
76+
withCredentials: false
77+
}
10178
});
10279

10380
$element.on('fileuploadsubmit', (e, data) => {
10481
var sign = generateSignature({
105-
"bucketName": "woww",
82+
"bucketName": "tron",
10683
"acl": this.get('storageACL'),
10784
"name": data.files[0].name,
10885
"contentType": data.files[0].type,
10986
"access_key": "",
11087
"secret_access_key": "",
11188
});
89+
90+
this.set('filekey', data.files[0].name);
91+
this.set('fileaccesskey', "");
92+
this.set('filecontenttype', data.files[0].type);
93+
this.set('filepolicy', sign.policy);
94+
this.set('filesignature', sign.signature);
95+
return true;
96+
});
97+
98+
$element.on("fileuploadprogress", (e, data) => {
99+
self.set("uploadPercentage", parseInt(data.loaded / data.total * 100, 10));
100+
});
101+
102+
$element.on("fileuploadsend", (e, data) => {
103+
if (data.xhr && data.originalFiles.length === 1) {
104+
self.set("isCancellable", true);
105+
self._xhr = data.xhr();
106+
}
107+
return true;
108+
});
109+
110+
$element.on("fileuploadfail", (e, data) => {
111+
//this._resetUpload(true);
112+
113+
//const userCancelled = this._xhr && this._xhr._userCancelled;
114+
//this._xhr = null;
115+
116+
//if (!userCancelled) {
117+
// Discourse.Utilities.displayErrorForUpload(data);
118+
//}
119+
120+
});
121+
122+
},
123+
124+
/*_bindUploadTarget() {
125+
//this._unbindUploadTarget(); // in case it's still bound, let's clean it up first
126+
const self = this;
127+
const $element = this.$();
128+
$element.fileupload({
129+
url: "",
130+
pasteZone: $element,
131+
//forceIframeTransport: true,
132+
//autoUpload: true,
133+
dataType: 'xml',
134+
type: 'POST',
135+
});
136+
137+
$element.on('fileuploadsubmit', (e, data) => {
138+
var sign = generateSignature({
139+
"bucketName": "tron",
140+
"acl": this.get('storageACL'),
141+
"name": data.files[0].name,
142+
"contentType": data.files[0].type,
143+
"access_key": "0RE8HB1CTEW0C13QIEEO",
144+
"secret_access_key": "nS05jbwXswx5x6st1uTy2alIZbwcfvFMQF5CYF0a",
145+
});
112146
data.formData = {
113147
key: data.files[0].name,
114148
acl: this.get('storageACL'),
115-
AWSAccessKeyId: "",
149+
AWSAccessKeyId: "0RE8HB1CTEW0C13QIEEO",
116150
"content-type": data.files[0].type,
117151
policy: sign.policy,
118152
signature: sign.signature
119153
};
120154
return true;
121155
});
122156
123-
$element.on("fileuploadprogressall", (e, data) => {
157+
$element.on("fileuploadprogress", (e, data) => {
124158
self.set("uploadPercentage", parseInt(data.loaded / data.total * 100, 10));
125159
});
126160
@@ -144,6 +178,6 @@ export default Ember.Component.extend({
144178
145179
});
146180
147-
},
181+
},*/
148182

149183
});

app/assets/javascripts/nilavu/components/vm-management-snapshots.js.es6

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
export default buildCategoryPanel('snapshots', {
1010

1111
showSnapshotSpinnerVisible: false,
12+
takeSnapShotSpinner: false,
1213
snapshots: [],
1314

1415
sortedSnapshots: Ember.computed.sort('snapshots', 'sortDefinition'),
@@ -51,6 +52,10 @@ export default buildCategoryPanel('snapshots', {
5152
return this.get("showSnapshotSpinnerVisible");
5253
}.property("showSnapshotSpinnerVisible"),
5354

55+
showTakeSnapshotSpinner: function() {
56+
return this.get("takeSnapShotSpinner");
57+
}.property("takeSnapShotSpinner"),
58+
5459
@observes('selectedTab')
5560
tabChanged() {
5661
if (Ember.isEqual(this.get('selectedTab'), "snapshots")) {
@@ -77,11 +82,45 @@ export default buildCategoryPanel('snapshots', {
7782
},
7883

7984
snapshotListEmpty: function() {
80-
if (Em.isEmpty(this.get('snapshots'))) {
81-
return true;
82-
} else {
83-
return false;
84-
}
85+
if (Em.isEmpty(this.get('snapshots'))) {
86+
return true;
87+
} else {
88+
return false;
89+
}
8590
}.property("snapshots"),
8691

92+
getData(reqAction) {
93+
return {
94+
id: this.get('model').id,
95+
cat_id: this.get('model').asms_id,
96+
name: this.get('model').name,
97+
req_action: reqAction,
98+
cattype: this.get('model').tosca_type.split(".")[1],
99+
category: "snapshot"
100+
};
101+
},
102+
103+
actions: {
104+
105+
takeSnapshot() {
106+
var self = this;
107+
this.set('takeSnapShotSpinner', true);
108+
Nilavu.ajax('/t/' + this.get('model').id + "/snapshot", {
109+
data: this.getData("disksaveas"),
110+
type: 'POST'
111+
}).then(function(result) {
112+
self.set('takeSnapShotSpinner', false);
113+
if (result.success) {
114+
self.notificationMessages.success(I18n.t("vm_management.take_snapshot_success"));
115+
} else {
116+
self.notificationMessages.error(I18n.t("vm_management.error"));
117+
}
118+
}).catch(function(e) {
119+
self.set('takeSnapShotSpinner', false);
120+
self.notificationMessages.error(I18n.t("vm_management.error"));
121+
});
122+
},
123+
124+
}
125+
87126
});

0 commit comments

Comments
 (0)