Skip to content

Commit 7845372

Browse files
committed
Add a forget button, which detach the instance from demoinstance without deleting it
cf #19
1 parent 4c4d24b commit 7845372

6 files changed

Lines changed: 58 additions & 2 deletions

File tree

backend/demoinstance/demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ def check_user_own_instance(self, token,
324324
else:
325325
return False
326326

327+
def detach_instance(self, instance):
328+
self.database_insert_server(instance, status='DELETED')
329+
330+
327331
def check_user_own_instance_type(self, token, image_key):
328332
query = self.database.query(Instance).filter(
329333
Instance.image_key == image_key,

backend/demoinstance/http.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def send_file(self, file):
5555
f.close()
5656
return
5757

58+
def detach_instance(self, instance):
59+
self.demo.detach_instance(instance)
60+
self.send_http_message()
61+
5862
def instance_create(self, image_key, time=None):
5963
id = self.demo.create_instance(
6064
image_key,
@@ -244,6 +248,14 @@ def do_GET(self):
244248
self.instance_info(match.group(1))
245249
return
246250

251+
match = re.match("/api/forget/instance/(.*)", self.path)
252+
if match:
253+
if not self.demo.auth.is_admin(self.user.login):
254+
self.send_http_error(404, 'No action')
255+
return
256+
self.detach_instance(match.group(1))
257+
return
258+
247259
match = re.match("/api/image/(.*)", self.path)
248260
if match:
249261
self.image_info(match.group(1))

frontend/js/controller/admin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ demoApp.controller('adminController', function($scope, $http, $location, instanc
7171
);
7272
};
7373

74+
$scope.forgetInstance = function(id) {
75+
instanceService.forgetInstance(
76+
id,
77+
$scope.refresh,
78+
errorCallback
79+
);
80+
};
81+
7482
$scope.addTimeInstance = function(instance) {
7583
instanceService.setTimeInstance(
7684
instance.id,

frontend/js/service/instanceService.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ demoApp.factory('instanceService', function($http, $location) {
99
success(success).
1010
error(fail);
1111
};
12+
13+
var forgetInstance = function(id, success, fail) {
14+
if (typeof(success)==='undefined') success = empty;
15+
if (typeof(fail)==='undefined') fail = empty;
16+
$http.get('/api/forget/instance/'+ id).
17+
success(success).
18+
error(fail);
19+
};
1220

1321
var addTimeInstance = function(id, time, success, fail) {
1422
if (typeof(success)==='undefined') success = empty;
@@ -37,6 +45,7 @@ demoApp.factory('instanceService', function($http, $location) {
3745
return {
3846
deleteInstance : deleteInstance,
3947
addTimeInstance : addTimeInstance,
40-
setTimeInstance : setTimeInstance
48+
setTimeInstance : setTimeInstance,
49+
forgetInstance : forgetInstance
4150
};
42-
});
51+
});

frontend/pages/admin.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<td data-title="'action'">
7474
<span ng-show="instance.status != 'DELETED'" ng-click="setInstance(instance)" data-toggle="modal" data-target="#modalDestroy" class="glyphicon glyphicon-remove"></span>
7575
<span ng-show="instance.status != 'DELETED'" ng-click="go_to_instance(instance)" class="glyphicon glyphicon glyphicon-eye-open"></span>
76+
<span ng-show="instance.status != 'DELETED'" ng-click="setInstance(instance)" data-toggle="modal" data-target="#modalForget" class="glyphicon glyphicon glyphicon-log-out"></span>
7677
</td>
7778
</tr>
7879
</tbody>
@@ -139,4 +140,22 @@ <h4 class="modal-title" id="myModalLabel">{{ 'DESTROY' | translate }}</h4>
139140
</div>
140141
</div>
141142
</div>
143+
<div class="in modal fade" id="modalForget" tabindex="-1" role="dialog" aria-labelledby="myForgetModalLabel" aria-hidden="true">
144+
<div class="modal-dialog">
145+
<div class="modal-content">
146+
<div class="modal-header">
147+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
148+
<h4 class="modal-title" id="myForgetModalLabel">{{ 'FORGET' | translate }}</h4>
149+
</div>
150+
<div class="modal-body">
151+
{{ 'FORGETTING_INSTANCE'|translate }}.
152+
{{ 'ARE_YOU_SURE' | translate}}
153+
</div>
154+
<div class="modal-footer">
155+
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'CANCEL' | translate }}</button>
156+
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="forgetInstance(instance.id);">{{ 'SUBMIT' | translate }}</button>
157+
</div>
158+
</div>
159+
</div>
160+
</div>
142161
</div>

frontend/script.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
NEW_INSTANCE: 'Instances',
9292
CREATING_INSTANCE: 'Creating instance',
9393
DESTROYING_INSTANCE: 'Your instance will be permanently destroyed',
94+
FORGETTING_INSTANCE: 'Your instance will be detached and will not be destroyed automatically',
9495
STARTING_INSTANCE: 'Starting instance',
9596
STARTING_SYSTEM: 'Starting system',
9697
CREATE_INSTANCE_OF: 'Create instance of ',
@@ -107,6 +108,7 @@
107108
SUBMIT: 'Submit',
108109
CANCEL: 'Cancel',
109110
DESTROY: 'Destroy instance',
111+
FORGET: 'Forgetting instance',
110112

111113
LOGIN:'Please log in',
112114
DISCONNECT: 'disconnect',
@@ -134,6 +136,7 @@
134136
NEW_INSTANCE: 'Instances',
135137
CREATING_INSTANCE: 'Cr&eacute;ation de votre environnement de d&eacute;monstration',
136138
DESTROYING_INSTANCE: 'Votre instance sera détruite pour toujours',
139+
FORGETTING_INSTANCE: 'Votre instance sera détachée et ne sera pas supprimée automatiquement',
137140
STARTING_INSTANCE: 'D&eacute;marrage de votre environnement de d&eacute;monstration',
138141
STARTING_SYSTEM: 'Configuration de votre environnement de d&eacute;monstration',
139142
CREATE_INSTANCE_OF: 'Cr&eacute;ation de l\'instance ',
@@ -150,6 +153,7 @@
150153
SUBMIT: 'Valider',
151154
CANCEL: 'Annuler',
152155
DESTROY: 'Détruire l\'instance',
156+
FORGET: 'Détacher l\'instance',
153157

154158
LOGIN:'Connectez vous',
155159
DISCONNECT: 'Déconnection',

0 commit comments

Comments
 (0)