1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

Add Docker top feature

This commit is contained in:
Houssem BELHADJ AHMED 2015-03-31 23:37:03 +02:00
parent c971189286
commit ede37e2e79
8 changed files with 307 additions and 182 deletions

View file

@ -1,56 +1,75 @@
angular.module('dockerui.services', ['ngResource'])
.factory('Container', function($resource, Settings) {
.factory('Container', function ($resource, Settings) {
'use strict';
// Resource for interacting with the docker containers
// http://docs.docker.io/en/latest/api/docker_remote_api.html#containers
return $resource(Settings.url + '/containers/:id/:action', {
name: '@name'
}, {
query: {method: 'GET', params:{ all: 0, action: 'json'}, isArray: true},
get: {method: 'GET', params: { action:'json'}},
query: {method: 'GET', params: {all: 0, action: 'json'}, isArray: true},
get: {method: 'GET', params: {action: 'json'}},
start: {method: 'POST', params: {id: '@id', action: 'start'}},
stop: {method: 'POST', params: {id: '@id', t: 5, action: 'stop'}},
restart: {method: 'POST', params: {id: '@id', t: 5, action: 'restart' }},
restart: {method: 'POST', params: {id: '@id', t: 5, action: 'restart'}},
kill: {method: 'POST', params: {id: '@id', action: 'kill'}},
pause: {method: 'POST', params: {id: '@id', action: 'pause'}},
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
changes: {method: 'GET', params: {action:'changes'}, isArray: true},
create: {method: 'POST', params: {action:'create'}},
remove: {method: 'DELETE', params: {id: '@id', v:0}},
changes: {method: 'GET', params: {action: 'changes'}, isArray: true},
create: {method: 'POST', params: {action: 'create'}},
remove: {method: 'DELETE', params: {id: '@id', v: 0}},
rename: {method: 'POST', params: {id: '@id', action: 'rename'}, isArray: false}
});
})
.factory('ContainerLogs', function($resource, $http, Settings) {
.factory('ContainerLogs', function ($resource, $http, Settings) {
'use strict';
return {
get: function(id, params, callback) {
get: function (id, params, callback) {
$http({
method: 'GET',
url: Settings.url + '/containers/'+id+'/logs',
params: {'stdout': params.stdout || 0, 'stderr': params.stderr || 0, 'timestamps': params.timestamps || 0, 'tail': params.tail || 'all'}
}).success(callback).error(function(data, status, headers, config) {
url: Settings.url + '/containers/' + id + '/logs',
params: {
'stdout': params.stdout || 0,
'stderr': params.stderr || 0,
'timestamps': params.timestamps || 0,
'tail': params.tail || 'all'
}
}).success(callback).error(function (data, status, headers, config) {
console.log(error, data);
});
}
};
})
.factory('Image', function($resource, Settings) {
.factory('ContainerTop', function ($http, Settings) {
'use strict';
return {
get: function (id, params, callback, errorCallback) {
$http({
method: 'GET',
url: Settings.url + '/containers/' + id + '/top',
params: {
ps_args: params.ps_args
}
}).success(callback);
}
};
})
.factory('Image', function ($resource, Settings) {
'use strict';
// Resource for docker images
// http://docs.docker.io/en/latest/api/docker_remote_api.html#images
return $resource(Settings.url + '/images/:id/:action', {}, {
query: {method: 'GET', params:{ all: 0, action: 'json'}, isArray: true},
get: {method: 'GET', params: { action:'json'}},
search: {method: 'GET', params: { action:'search'}},
history: {method: 'GET', params: { action:'history'}, isArray: true},
create: {method: 'POST', params: {action:'create'}},
insert: {method: 'POST', params: {id: '@id', action:'insert'}},
push: {method: 'POST', params: {id: '@id', action:'push'}},
tag: {method: 'POST', params: {id: '@id', action:'tag', force: 0, repo: '@repo'}},
query: {method: 'GET', params: {all: 0, action: 'json'}, isArray: true},
get: {method: 'GET', params: {action: 'json'}},
search: {method: 'GET', params: {action: 'search'}},
history: {method: 'GET', params: {action: 'history'}, isArray: true},
create: {method: 'POST', params: {action: 'create'}},
insert: {method: 'POST', params: {id: '@id', action: 'insert'}},
push: {method: 'POST', params: {id: '@id', action: 'push'}},
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo'}},
remove: {method: 'DELETE', params: {id: '@id'}, isArray: true}
});
})
.factory('Docker', function($resource, Settings) {
.factory('Docker', function ($resource, Settings) {
'use strict';
// Information for docker
// http://docs.docker.io/en/latest/api/docker_remote_api.html#display-system-wide-information
@ -58,7 +77,7 @@ angular.module('dockerui.services', ['ngResource'])
get: {method: 'GET'}
});
})
.factory('Auth', function($resource, Settings) {
.factory('Auth', function ($resource, Settings) {
'use strict';
// Auto Information for docker
// http://docs.docker.io/en/latest/api/docker_remote_api.html#set-auth-configuration
@ -67,7 +86,7 @@ angular.module('dockerui.services', ['ngResource'])
update: {method: 'POST'}
});
})
.factory('System', function($resource, Settings) {
.factory('System', function ($resource, Settings) {
'use strict';
// System for docker
// http://docs.docker.io/en/latest/api/docker_remote_api.html#display-system-wide-information
@ -75,7 +94,7 @@ angular.module('dockerui.services', ['ngResource'])
get: {method: 'GET'}
});
})
.factory('Settings', function(DOCKER_ENDPOINT, DOCKER_PORT, DOCKER_API_VERSION, UI_VERSION) {
.factory('Settings', function (DOCKER_ENDPOINT, DOCKER_PORT, DOCKER_API_VERSION, UI_VERSION) {
'use strict';
var url = DOCKER_ENDPOINT;
if (DOCKER_PORT) {
@ -91,52 +110,56 @@ angular.module('dockerui.services', ['ngResource'])
firstLoad: true
};
})
.factory('ViewSpinner', function() {
.factory('ViewSpinner', function () {
'use strict';
var spinner = new Spinner();
var target = document.getElementById('view');
return {
spin: function() { spinner.spin(target); },
stop: function() { spinner.stop(); }
spin: function () {
spinner.spin(target);
},
stop: function () {
spinner.stop();
}
};
})
.factory('Messages', function($rootScope) {
.factory('Messages', function ($rootScope) {
'use strict';
return {
send: function(title, text) {
send: function (title, text) {
$.gritter.add({
title: title,
text: text,
time: 2000,
before_open: function() {
if($('.gritter-item-wrapper').length === 3) {
before_open: function () {
if ($('.gritter-item-wrapper').length === 3) {
return false;
}
}
}
});
});
},
error: function(title, text) {
error: function (title, text) {
$.gritter.add({
title: title,
text: text,
time: 10000,
before_open: function() {
if($('.gritter-item-wrapper').length === 4) {
before_open: function () {
if ($('.gritter-item-wrapper').length === 4) {
return false;
}
}
}
});
}
};
})
.factory('Dockerfile', function(Settings) {
.factory('Dockerfile', function (Settings) {
'use strict';
var url = Settings.rawUrl + '/build';
var url = Settings.rawUrl + '/build';
return {
build: function(file, callback) {
build: function (file, callback) {
var data = new FormData();
var dockerfile = new Blob([file], { type: 'text/text' });
var dockerfile = new Blob([file], {type: 'text/text'});
data.append('Dockerfile', dockerfile);
var request = new XMLHttpRequest();
@ -146,18 +169,18 @@ angular.module('dockerui.services', ['ngResource'])
}
};
})
.factory('LineChart', function(Settings) {
.factory('LineChart', function (Settings) {
'use strict';
var url = Settings.rawUrl + '/build';
var url = Settings.rawUrl + '/build';
return {
build: function(id, data, getkey){
build: function (id, data, getkey) {
var chart = new Chart($(id).get(0).getContext("2d"));
var map = {};
for (var i = 0; i < data.length; i++) {
var c = data[i];
var key = getkey(c);
var count = map[key];
if (count === undefined) {
count = 0;
@ -176,22 +199,22 @@ angular.module('dockerui.services', ['ngResource'])
data.push(map[k]);
}
var dataset = {
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : data
fillColor: "rgba(151,187,205,0.5)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
data: data
};
chart.Line({
labels: labels,
datasets: [dataset]
},
{
scaleStepWidth: 1,
pointDotRadius:1,
scaleOverride: true,
scaleSteps: labels.length
});
labels: labels,
datasets: [dataset]
},
{
scaleStepWidth: 1,
pointDotRadius: 1,
scaleOverride: true,
scaleSteps: labels.length
});
}
};
});