2015-01-18 22:39:10 +00:00
|
|
|
angular.module('dockerui.services', ['ngResource'])
|
2015-09-14 06:06:34 +00:00
|
|
|
.factory('Container', ['$resource', 'Settings', function ContainerFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-09 01:20:29 +00:00
|
|
|
// Resource for interacting with the docker containers
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-1-containers
|
2014-07-28 16:09:05 +00:00
|
|
|
return $resource(Settings.url + '/containers/:id/:action', {
|
2014-10-19 02:41:26 +00:00
|
|
|
name: '@name'
|
2014-07-28 16:09:05 +00:00
|
|
|
}, {
|
2015-03-31 21:37:03 +00:00
|
|
|
query: {method: 'GET', params: {all: 0, action: 'json'}, isArray: true},
|
|
|
|
get: {method: 'GET', params: {action: 'json'}},
|
2013-06-09 23:56:54 +00:00
|
|
|
start: {method: 'POST', params: {id: '@id', action: 'start'}},
|
|
|
|
stop: {method: 'POST', params: {id: '@id', t: 5, action: 'stop'}},
|
2015-03-31 21:37:03 +00:00
|
|
|
restart: {method: 'POST', params: {id: '@id', t: 5, action: 'restart'}},
|
2014-10-19 02:41:26 +00:00
|
|
|
kill: {method: 'POST', params: {id: '@id', action: 'kill'}},
|
|
|
|
pause: {method: 'POST', params: {id: '@id', action: 'pause'}},
|
|
|
|
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
2015-03-31 21:37:03 +00:00
|
|
|
changes: {method: 'GET', params: {action: 'changes'}, isArray: true},
|
|
|
|
create: {method: 'POST', params: {action: 'create'}},
|
|
|
|
remove: {method: 'DELETE', params: {id: '@id', v: 0}},
|
2015-08-25 05:55:54 +00:00
|
|
|
rename: {method: 'POST', params: {id: '@id', action: 'rename'}, isArray: false},
|
2015-08-26 06:28:08 +00:00
|
|
|
stats: {method: 'GET', params: {id: '@id', stream: false, action: 'stats'}, timeout: 2000}
|
2013-06-09 01:20:29 +00:00
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ContainerCommit', ['$resource', '$http', 'Settings', function ContainerCommitFactory($resource, $http, Settings) {
|
2015-05-12 16:53:19 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#create-a-new-image-from-a-container-s-changes
|
2015-05-12 16:53:19 +00:00
|
|
|
return {
|
|
|
|
commit: function (params, callback) {
|
2015-08-25 05:59:54 +00:00
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: Settings.url + '/commit',
|
|
|
|
params: {
|
|
|
|
'container': params.id,
|
|
|
|
'repo': params.repo
|
|
|
|
}
|
|
|
|
}).success(callback).error(function (data, status, headers, config) {
|
|
|
|
console.log(error, data);
|
|
|
|
});
|
2015-05-12 16:53:19 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ContainerLogs', ['$resource', '$http', 'Settings', function ContainerLogsFactory($resource, $http, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#get-container-logs
|
2014-12-15 22:26:10 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
get: function (id, params, callback) {
|
2014-12-15 22:26:10 +00:00
|
|
|
$http({
|
|
|
|
method: 'GET',
|
2015-03-31 21:37:03 +00:00
|
|
|
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) {
|
2014-12-15 22:26:10 +00:00
|
|
|
console.log(error, data);
|
|
|
|
});
|
|
|
|
}
|
2015-01-04 00:39:40 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ContainerTop', ['$http', 'Settings', function ($http, Settings) {
|
2015-03-31 21:37:03 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#list-processes-running-inside-a-container
|
2015-03-31 21:37:03 +00:00
|
|
|
return {
|
|
|
|
get: function (id, params, callback, errorCallback) {
|
|
|
|
$http({
|
|
|
|
method: 'GET',
|
|
|
|
url: Settings.url + '/containers/' + id + '/top',
|
|
|
|
params: {
|
|
|
|
ps_args: params.ps_args
|
|
|
|
}
|
|
|
|
}).success(callback);
|
|
|
|
}
|
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('Image', ['$resource', 'Settings', function ImageFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-2-images
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/images/:id/:action', {}, {
|
2015-03-31 21:37:03 +00:00
|
|
|
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},
|
2015-08-25 05:59:54 +00:00
|
|
|
create: {
|
|
|
|
method: 'POST', isArray: true, transformResponse: [function f(data) {
|
|
|
|
var str = data.replace(/\n/g, " ").replace(/\}\W*\{/g, "}, {");
|
|
|
|
return angular.fromJson("[" + str + "]");
|
|
|
|
}],
|
|
|
|
params: {action: 'create', fromImage: '@fromImage', repo: '@repo', tag: '@tag', registry: '@registry'}
|
|
|
|
},
|
2015-03-31 21:37:03 +00:00
|
|
|
insert: {method: 'POST', params: {id: '@id', action: 'insert'}},
|
|
|
|
push: {method: 'POST', params: {id: '@id', action: 'push'}},
|
2015-11-27 06:19:38 +00:00
|
|
|
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}},
|
2014-10-19 02:41:26 +00:00
|
|
|
remove: {method: 'DELETE', params: {id: '@id'}, isArray: true}
|
2013-06-09 01:20:29 +00:00
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('Docker', ['$resource', 'Settings', function DockerFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#show-the-docker-version-information
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/version', {}, {
|
2013-06-10 01:31:05 +00:00
|
|
|
get: {method: 'GET'}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('Auth', ['$resource', 'Settings', function AuthFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#check-auth-configuration
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/auth', {}, {
|
2013-06-10 01:31:05 +00:00
|
|
|
get: {method: 'GET'},
|
|
|
|
update: {method: 'POST'}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('System', ['$resource', 'Settings', function SystemFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#display-system-wide-information
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/info', {}, {
|
2013-06-10 01:31:05 +00:00
|
|
|
get: {method: 'GET'}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2015-12-18 05:35:04 +00:00
|
|
|
.factory('Network', ['$resource', 'Settings', function NetworksFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-5-networks
|
2015-12-21 01:13:53 +00:00
|
|
|
return $resource(Settings.url + '/networks/:id/:action', {id: '@id'}, {
|
2015-12-18 05:35:04 +00:00
|
|
|
query: {method: 'GET', isArray: true},
|
|
|
|
get: {method: 'GET'},
|
|
|
|
create: {method: 'POST', params: {action: 'create'}},
|
2015-12-21 01:13:53 +00:00
|
|
|
remove: {method: 'DELETE'},
|
|
|
|
connect: {method: 'POST', params: {action: 'connect'}},
|
|
|
|
disconnect: {method: 'POST', params: {action: 'disconnect'}}
|
2015-12-18 05:35:04 +00:00
|
|
|
});
|
|
|
|
}])
|
2015-09-14 06:06:34 +00:00
|
|
|
.factory('Settings', ['DOCKER_ENDPOINT', 'DOCKER_PORT', 'DOCKER_API_VERSION', 'UI_VERSION', function SettingsFactory(DOCKER_ENDPOINT, DOCKER_PORT, DOCKER_API_VERSION, UI_VERSION) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-19 01:50:35 +00:00
|
|
|
var url = DOCKER_ENDPOINT;
|
|
|
|
if (DOCKER_PORT) {
|
|
|
|
url = url + DOCKER_PORT + '\\' + DOCKER_PORT;
|
|
|
|
}
|
2013-06-09 23:56:54 +00:00
|
|
|
return {
|
2013-06-10 12:59:57 +00:00
|
|
|
displayAll: false,
|
2013-06-11 00:10:43 +00:00
|
|
|
endpoint: DOCKER_ENDPOINT,
|
|
|
|
version: DOCKER_API_VERSION,
|
2013-06-19 03:01:22 +00:00
|
|
|
rawUrl: DOCKER_ENDPOINT + DOCKER_PORT + '/' + DOCKER_API_VERSION,
|
2013-06-19 01:50:35 +00:00
|
|
|
uiVersion: UI_VERSION,
|
2013-09-03 00:18:54 +00:00
|
|
|
url: url,
|
2015-01-04 00:39:40 +00:00
|
|
|
firstLoad: true
|
2013-06-19 01:50:35 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ViewSpinner', function ViewSpinnerFactory() {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-19 03:01:22 +00:00
|
|
|
var spinner = new Spinner();
|
|
|
|
var target = document.getElementById('view');
|
|
|
|
|
2014-10-19 02:41:26 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
spin: function () {
|
|
|
|
spinner.spin(target);
|
|
|
|
},
|
|
|
|
stop: function () {
|
|
|
|
spinner.stop();
|
|
|
|
}
|
2014-10-19 02:41:26 +00:00
|
|
|
};
|
2013-06-19 03:01:22 +00:00
|
|
|
})
|
2015-09-14 06:06:34 +00:00
|
|
|
.factory('Messages', ['$rootScope', function MessagesFactory($rootScope) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-20 02:40:58 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
send: function (title, text) {
|
2014-10-19 02:41:26 +00:00
|
|
|
$.gritter.add({
|
|
|
|
title: title,
|
|
|
|
text: text,
|
|
|
|
time: 2000,
|
2015-03-31 21:37:03 +00:00
|
|
|
before_open: function () {
|
|
|
|
if ($('.gritter-item-wrapper').length === 3) {
|
2013-08-08 19:18:51 +00:00
|
|
|
return false;
|
2015-03-31 21:37:03 +00:00
|
|
|
}
|
2013-08-08 19:18:51 +00:00
|
|
|
}
|
2015-03-31 21:37:03 +00:00
|
|
|
});
|
2014-10-19 02:41:26 +00:00
|
|
|
},
|
2015-03-31 21:37:03 +00:00
|
|
|
error: function (title, text) {
|
2013-08-08 19:18:51 +00:00
|
|
|
$.gritter.add({
|
|
|
|
title: title,
|
|
|
|
text: text,
|
2015-01-25 23:59:08 +00:00
|
|
|
time: 10000,
|
2015-03-31 21:37:03 +00:00
|
|
|
before_open: function () {
|
|
|
|
if ($('.gritter-item-wrapper').length === 4) {
|
2013-08-08 19:18:51 +00:00
|
|
|
return false;
|
2015-03-31 21:37:03 +00:00
|
|
|
}
|
2013-08-08 19:18:51 +00:00
|
|
|
}
|
|
|
|
});
|
2014-10-19 02:41:26 +00:00
|
|
|
}
|
2013-06-20 02:40:58 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('Dockerfile', ['Settings', function DockerfileFactory(Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#build-image-from-a-dockerfile
|
2015-03-31 21:37:03 +00:00
|
|
|
var url = Settings.rawUrl + '/build';
|
2013-06-19 01:50:35 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
build: function (file, callback) {
|
2014-10-19 02:41:26 +00:00
|
|
|
var data = new FormData();
|
2015-03-31 21:37:03 +00:00
|
|
|
var dockerfile = new Blob([file], {type: 'text/text'});
|
2014-10-19 02:41:26 +00:00
|
|
|
data.append('Dockerfile', dockerfile);
|
2013-06-19 01:50:35 +00:00
|
|
|
|
2014-10-19 02:41:26 +00:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = callback;
|
|
|
|
request.open('POST', url);
|
|
|
|
request.send(data);
|
|
|
|
}
|
2013-06-19 01:50:35 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('LineChart', ['Settings', function LineChartFactory(Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2014-11-29 06:06:06 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
build: function (id, data, getkey) {
|
2014-11-29 06:06:06 +00:00
|
|
|
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);
|
2015-03-31 21:37:03 +00:00
|
|
|
|
2014-11-29 06:06:06 +00:00
|
|
|
var count = map[key];
|
|
|
|
if (count === undefined) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
map[key] = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels = [];
|
2015-01-04 00:39:40 +00:00
|
|
|
data = [];
|
2014-11-29 06:06:06 +00:00
|
|
|
var keys = Object.keys(map);
|
2015-10-10 09:04:19 +00:00
|
|
|
var max = 1;
|
2014-11-29 06:06:06 +00:00
|
|
|
|
2015-01-04 00:39:40 +00:00
|
|
|
for (i = keys.length - 1; i > -1; i--) {
|
2014-11-29 06:06:06 +00:00
|
|
|
var k = keys[i];
|
|
|
|
labels.push(k);
|
|
|
|
data.push(map[k]);
|
2015-10-10 09:04:19 +00:00
|
|
|
if (map[k] > max) {
|
2015-12-21 01:13:53 +00:00
|
|
|
max = map[k];
|
2015-10-10 09:04:19 +00:00
|
|
|
}
|
2014-11-29 06:06:06 +00:00
|
|
|
}
|
|
|
|
var dataset = {
|
2015-03-31 21:37:03 +00:00
|
|
|
fillColor: "rgba(151,187,205,0.5)",
|
|
|
|
strokeColor: "rgba(151,187,205,1)",
|
|
|
|
pointColor: "rgba(151,187,205,1)",
|
|
|
|
pointStrokeColor: "#fff",
|
|
|
|
data: data
|
2014-11-29 06:06:06 +00:00
|
|
|
};
|
|
|
|
chart.Line({
|
2015-03-31 21:37:03 +00:00
|
|
|
labels: labels,
|
|
|
|
datasets: [dataset]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
scaleStepWidth: 1,
|
|
|
|
pointDotRadius: 1,
|
|
|
|
scaleOverride: true,
|
2015-10-10 09:04:19 +00:00
|
|
|
scaleSteps: max
|
2015-03-31 21:37:03 +00:00
|
|
|
});
|
2014-11-29 06:06:06 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}]);
|