Commit 13986f47 authored by Steve Laskaridis's avatar Steve Laskaridis
Browse files

Merge pull request #213 from efikalti/ember-delete

Delete app/instance 
parents 3c4ee220 9d428bcd
...@@ -2,6 +2,10 @@ import Ember from "ember"; ...@@ -2,6 +2,10 @@ import Ember from "ember";
export default Ember.Controller.extend({ export default Ember.Controller.extend({
failure: false, failure: false,
session: Ember.inject.service('session'),
failed_delete: false,
success_delete: false,
message: '',
actions: { actions: {
withdraw: function() withdraw: function()
{ {
...@@ -21,7 +25,50 @@ export default Ember.Controller.extend({ ...@@ -21,7 +25,50 @@ export default Ember.Controller.extend({
close_alert: function() close_alert: function()
{ {
var alert = document.getElementById('alert'); var alert = document.getElementById('alert');
this.set('failed_delete', false);
alert.hidden=true; alert.hidden=true;
} },
delete_app: function(app_id) {
if (confirm("Are you sure you want to delete this application?")) {
var _this = this;
var host = this.store.adapterFor('upload-app').get('host'),
namespace = this.store.adapterFor('upload-app').namespace,
postUrl = [ host, namespace].join('/');
postUrl = postUrl + app_id + '/';
const headers = {};
this.get('session').authorize('authorizer:django', (headerName, headerValue) => {
headers[headerName] = headerValue;
});
Ember.$.ajax({
url: postUrl,
headers: headers,
method: 'DELETE',
processData: false,
contentType: false,
success: function(){
_this.store.unloadAll('lambda-app');
_this.set('message', 'Your request to delete the application was successfully sent to the server.');
_this.set("success_delete", true);
Ember.run.later((function () {
_this.set("success_delete", false);
_this.transitionToRoute('dashboard');
}), 3000);
},
statusCode: {
500: function() {
_this.set('failed_delete', true);
_this.set('message', "Your request to delete the application was rejected.Please try again later when the status of the instance has changed.");
}
},
error: function(response) {
_this.set('failed_delete', true);
_this.set('message', response.responseJSON.errors[0].detail);
}
});
}
},
}, },
}); });
...@@ -2,6 +2,11 @@ import Ember from 'ember'; ...@@ -2,6 +2,11 @@ import Ember from 'ember';
import pagedArray from 'ember-cli-pagination/computed/paged-array'; import pagedArray from 'ember-cli-pagination/computed/paged-array';
export default Ember.ArrayController.extend({ export default Ember.ArrayController.extend({
success_delete: false,
failed_delete: false,
message: '',
error: false,
session: Ember.inject.service('session'),
queryParams: ["page", "perPage"], queryParams: ["page", "perPage"],
page: 1, page: 1,
...@@ -21,4 +26,54 @@ export default Ember.ArrayController.extend({ ...@@ -21,4 +26,54 @@ export default Ember.ArrayController.extend({
pagedContent: pagedArray('content', {pageBinding: "page", perPageBinding: "perPage"}), pagedContent: pagedArray('content', {pageBinding: "page", perPageBinding: "perPage"}),
totalPagesBinding: "pagedContent.totalPages", totalPagesBinding: "pagedContent.totalPages",
actions:{
delete_app: function(app_id) {
if (confirm("Are you sure you want to delete this application?")) {
var _this = this;
var host = this.store.adapterFor('upload-app').get('host'),
namespace = this.store.adapterFor('upload-app').namespace,
postUrl = [ host, namespace].join('/');
postUrl = postUrl + app_id + '/';
const headers = {};
this.get('session').authorize('authorizer:django', (headerName, headerValue) => {
headers[headerName] = headerValue;
});
Ember.$.ajax({
url: postUrl,
headers: headers,
method: 'DELETE',
processData: false,
contentType: false,
success: function(){
_this.set('success_delete', true);
_this.set('message', 'Your request to delete the application was successfully sent to the server.');
_this.store.unloadAll('lambda-app');
Ember.run.later((function () {
_this.set("success_delete", false);
}), 4000);
},
statusCode: {
500: function() {
_this.set('failed_delete', true);
_this.set('message', "Your request to delete the application was rejected.Please try again later when the status of the instance has changed.");
}
},
error: function(response) {
_this.set('failed_delete', true);
_this.set('message', response.responseJSON.errors[0].detail);
}
});
}
},
close_alert: function()
{
var alert = document.getElementById('alert');
alert.hidden=true;
this.set('failed_delete', false);
}
},
}); });
import Ember from "ember"; import Ember from "ember";
export default Ember.Controller.extend({ export default Ember.Controller.extend({
session: Ember.inject.service('session'),
failed_delete: false,
success_delete: false,
message: '',
actions: { actions: {
close_alert: function() close_alert: function()
{ {
var alert = document.getElementById('alert'); var alert = document.getElementById('alert');
alert.hidden=true; alert.hidden=true;
this.set('failed_delete', false);
}, },
close_app_alert: function() close_app_alert: function()
{ {
...@@ -29,5 +34,45 @@ export default Ember.Controller.extend({ ...@@ -29,5 +34,45 @@ export default Ember.Controller.extend({
_this.set("app_request", false); _this.set("app_request", false);
}), 3000); }), 3000);
}, },
delete_instance: function(instance_id) {
if (confirm("Are you sure you want to delete this lambda instance?")) {
var _this = this;
var host = this.store.adapterFor('upload-app').get('host'),
postUrl = host + '/api/lambda-instances/' + instance_id + '/';
const headers = {};
this.get('session').authorize('authorizer:django', (headerName, headerValue) => {
headers[headerName] = headerValue;
});
Ember.$.ajax({
url: postUrl,
headers: headers,
method: 'DELETE',
processData: false,
contentType: false,
success: function(){
_this.store.unloadAll('lambda-instance');
_this.set('success_delete', true);
_this.set('message', 'Your request to delete the lambda instance was successfully sent to the server.');
Ember.run.later((function () {
_this.set("success_delete", false);
_this.transitionToRoute('dashboard');
}), 3000);
},
statusCode: {
500: function() {
_this.set('failed_delete', true);
_this.set('message', "Your request to delete the instance was rejected.Please try again later when the status of the instance has changed.");
}
},
error: function(response) {
_this.set('failed_delete', true);
_this.set('message', response.responseJSON.errors[0].detail);
}
});
}
},
} }
}); });
...@@ -2,6 +2,10 @@ import Ember from 'ember'; ...@@ -2,6 +2,10 @@ import Ember from 'ember';
import pagedArray from 'ember-cli-pagination/computed/paged-array'; import pagedArray from 'ember-cli-pagination/computed/paged-array';
export default Ember.ArrayController.extend({ export default Ember.ArrayController.extend({
success_delete: false,
failed_delete: false,
session: Ember.inject.service('session'),
message: '',
queryParams: ["page", "perPage"], queryParams: ["page", "perPage"],
page: 1, page: 1,
...@@ -23,6 +27,7 @@ export default Ember.ArrayController.extend({ ...@@ -23,6 +27,7 @@ export default Ember.ArrayController.extend({
totalPagesBinding: "pagedContent.totalPages", totalPagesBinding: "pagedContent.totalPages",
actions: { actions: {
start_stop: function() start_stop: function()
{ {
var _this = this; var _this = this;
...@@ -30,11 +35,52 @@ export default Ember.ArrayController.extend({ ...@@ -30,11 +35,52 @@ export default Ember.ArrayController.extend({
_this.set("request", false); _this.set("request", false);
}), 4000); }), 4000);
}, },
delete_instance: function(instance_id) {
if (confirm("Are you sure you want to delete this lambda instance?")) {
var _this = this;
var host = this.store.adapterFor('upload-app').get('host'),
postUrl = host + '/api/lambda-instances/' + instance_id + '/';
const headers = {};
this.get('session').authorize('authorizer:django', (headerName, headerValue) => {
headers[headerName] = headerValue;
});
Ember.$.ajax({
url: postUrl,
headers: headers,
method: 'DELETE',
processData: false,
contentType: false,
success: function(){
_this.store.unloadAll('lambda-instance');
_this.set('success_delete', true);
_this.set('message', 'Your request to delete the lambda instance was successfully sent to the server.');
Ember.run.later((function () {
_this.set("success_delete", false);
}), 4000);
},
statusCode: {
500: function() {
_this.set('failed_delete', true);
_this.set('message', "Your request to delete the instance was rejected.Please try again later when the status of the instance has changed.");
}
},
error: function(response) {
_this.set('failed_delete', true);
_this.set('message', response.responseJSON.errors[0].detail);
}
});
}
},
close_alert: function() close_alert: function()
{ {
var alert = document.getElementById('alert'); var alert = document.getElementById('alert');
alert.hidden=true; alert.hidden=true;
this.set('failed_delete', false);
}, },
}, },
}); });
...@@ -3,13 +3,19 @@ import ENV from 'frontend/config/environment'; ...@@ -3,13 +3,19 @@ import ENV from 'frontend/config/environment';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, { export default Ember.Route.extend(AuthenticatedRouteMixin, {
beforeModel: function (transition) {
this._super(transition);
this.store.unloadAll('lambda-app');
},
model: function(params) { model: function(params) {
this.poll = Ember.run.later(this, function () { this.poll = Ember.run.later(this, function () {
this.model(params).then(function () { this.model(params).then(function () {
}.bind(this)); }.bind(this));
}, ENV.refresh_interval); }, ENV.refresh_interval);
return this.store.findAll('lambda-app', params); return this.store.findAll('lambda-app', params, { reload: true });
}, },
deactivate: function () { deactivate: function () {
......
...@@ -18,7 +18,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { ...@@ -18,7 +18,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
}, ENV.refresh_interval); }, ENV.refresh_interval);
var hash = { var hash = {
instances: this.store.findAll('lambda-instance', params), instances: this.store.findAll('lambda-instance', params, { reload: true }),
apps: this.store.peekAll('lambda-app'), apps: this.store.peekAll('lambda-app'),
}; };
if (this.store.peekAll('instance-action').get('length') === 0) { if (this.store.peekAll('instance-action').get('length') === 0) {
......
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Dashboard
<small>Lambda Application Details</small>
</h1>
</section>
<!-- Main content --> <!-- Main content -->
<section class="content"> <section class="content">
<section class="content-header">
<h1>
Dashboard
<small>Lambda Application Details</small>
</h1>
</section>
{{#if failed_delete}}
<div class="alert alert-dismissable alert-danger" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
{{#if success_delete}}
<div class="alert alert-dismissable alert-success" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
<!-- TOP DATA --> <!-- TOP DATA -->
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
...@@ -20,6 +35,7 @@ ...@@ -20,6 +35,7 @@
<small>ID: {{model.application.id}}</small> <small>ID: {{model.application.id}}</small>
</div> </div>
</div> </div>
<!-- /.box-header --> <!-- /.box-header -->
<div class="box-body"> <div class="box-body">
<div class="row "> <div class="row ">
...@@ -34,8 +50,7 @@ ...@@ -34,8 +50,7 @@
actions you may take depending on the <i>status</i> of the Application. actions you may take depending on the <i>status</i> of the Application.
</div> </div>
<a href="delete-application.html" class="btn btn-danger pull-right" <button name="del-btn" id="del-btn" class="btn btn-danger btn-primary pull-right" {{action "delete_app" model.application.id}}>Delete</button>
style="margin-right: 15px;"><i class="fa fa-close"></i> Delete</a>
{{#if (compare model.application.status_code '==' '0')}} {{#if (compare model.application.status_code '==' '0')}}
{{#link-to 'deploy-app-1' model.application.id}} {{#link-to 'deploy-app-1' model.application.id}}
<button class="btn btn-primary pull-right" <button class="btn btn-primary pull-right"
......
...@@ -45,6 +45,20 @@ ...@@ -45,6 +45,20 @@
</div><!--col-xs-12--> </div><!--col-xs-12-->
</div> </div>
{{#if failed_delete}}
<div class="alert alert-dismissable alert-danger" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
{{#if success_delete}}
<div class="alert alert-dismissable alert-success" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="box"> <div class="box">
...@@ -93,14 +107,14 @@ ...@@ -93,14 +107,14 @@
<td>{{lambda-application.status_detail}}</td> <td>{{lambda-application.status_detail}}</td>
<td>{{lower-case lambda-application.app_type}}</td> <td>{{lower-case lambda-application.app_type}}</td>
<td>
<button name="del-btn" id="del-btn" class="btn btn-danger btn-xs" {{action "delete_app" lambda-application.id}}>Delete</button>
</td>
<td> <td>
{{#link-to 'lambda-app' lambda-application.id}} {{#link-to 'lambda-app' lambda-application.id}}
<button class="btn btn-info btn-xs"><i class="fa fa-file-code-o"></i> Details</button> <button class="btn btn-info btn-xs"><i class="fa fa-file-code-o"></i> Details</button>
{{/link-to}} {{/link-to}}
</td> </td>
<td>
{{delete-lambda-app lambdaApp=lambda-application}}
</td>
<td> <td>
{{#if (compare lambda-application.status_code '==' '0')}} {{#if (compare lambda-application.status_code '==' '0')}}
{{#link-to 'deploy-app-1' lambda-application.id}} {{#link-to 'deploy-app-1' lambda-application.id}}
......
...@@ -23,6 +23,18 @@ ...@@ -23,6 +23,18 @@
{{message}} {{message}}
</div> </div>
{{/if}} {{/if}}
{{#if failed_delete}}
<div class="alert alert-dismissable alert-danger" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
{{#if success_delete}}
<div class="alert alert-dismissable alert-success" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
<!-- TOP DATA --> <!-- TOP DATA -->
<div class="row"> <div class="row">
...@@ -45,7 +57,8 @@ ...@@ -45,7 +57,8 @@
actions you may take depending on the <i>status</i> of the lambda instance. actions you may take depending on the <i>status</i> of the lambda instance.
</div> </div>
<a href="delete-instance.html" class="btn btn-danger pull-right" style="margin-right: 15px;"><i class="fa fa-close"></i> Delete</a>
<button name="del-btn" id="del-btn" class="btn btn-danger btn-primary pull-right" {{action "delete_instance" model.instance.id}}>Delete</button>
{{#if (compare model.instance.status_code '==' '0')}} {{#if (compare model.instance.status_code '==' '0')}}
{{#link-to 'deploy-app-2' model.instance.id}} {{#link-to 'deploy-app-2' model.instance.id}}
<button class="btn btn-primary pull-right" <button class="btn btn-primary pull-right"
......
...@@ -45,20 +45,34 @@ ...@@ -45,20 +45,34 @@
</div><!--col-xs-12--> </div><!--col-xs-12-->
</div> </div>
{{#if failure}} {{#if failure}}
{{#each instance_action.errors as |error|}} {{#each instance_action.errors as |error|}}
<div class="alert alert-dismissable alert-danger" id="alert"> <div class="alert alert-dismissable alert-danger" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button> <button type="button" class="close" {{action "close_alert"}}>×</button>
{{error.message}} {{error.message}}
</div> </div>
{{/each}} {{/each}}
{{/if}} {{/if}}
{{#if request}} {{#if request}}
<div class="alert alert-dismissable alert-success" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
{{#if failed_delete}}
<div class="alert alert-dismissable alert-danger" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}}
</div>
{{/if}}
{{#if success_delete}}
<div class="alert alert-dismissable alert-success" id="alert"> <div class="alert alert-dismissable alert-success" id="alert">
<button type="button" class="close" {{action "close_alert"}}>×</button> <button type="button" class="close" {{action "close_alert"}}>×</button>
{{message}} {{message}}
</div> </div>
{{/if}} {{/if}}
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
...@@ -112,7 +126,9 @@ ...@@ -112,7 +126,9 @@
<a class="btn btn-info btn-xs" title="View Details" alt="View Details"><i class="fa fa-file-code-o"></i> Details</a> <a class="btn btn-info btn-xs" title="View Details" alt="View Details"><i class="fa fa-file-code-o"></i> Details</a>
{{/link-to}} {{/link-to}}
</td> </td>
<td>{{delete-lambda-instance lambdaInstance=lambda-instance}}</td> <td>
<button name="del-btn" id="del-btn" class="btn btn-danger btn-xs" {{action "delete_instance" lambda-instance.id}}>Delete</button>
</td>
{{#if (compare lambda-instance.status_code '==' '0')}} {{#if (compare lambda-instance.status_code '==' '0')}}
{{#tool-tip}} {{#tool-tip}}
<td> <td>
......