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

feat(templates): new templates capabilities (#862)

This commit is contained in:
Anthony Lapenna 2017-05-18 23:00:08 +02:00 committed by GitHub
parent c3363604ac
commit 0579251c70
10 changed files with 276 additions and 159 deletions

View file

@ -19,7 +19,7 @@ function ($scope, $state, Settings, Config, EndpointService, StateManager, Endpo
$state.go('dashboard');
})
.catch(function error(err) {
Notifications.error("Failure", err, "Unable to connect to the Docker endpoint");
Notifications.error('Failure', err, 'Unable to connect to the Docker endpoint');
EndpointProvider.setEndpointID(activeEndpointID);
EndpointProvider.setEndpointPublicURL(activeEndpointPublicURL);
StateManager.updateEndpointState(true)

View file

@ -1,4 +1,4 @@
<rd-header>
<rd-header id="view-top">
<rd-header-title title="Application templates list">
<a data-toggle="tooltip" title="Refresh" ui-sref="templates" ui-sref-opts="{reload: true}">
<i class="fa fa-refresh" aria-hidden="true"></i>
@ -7,34 +7,52 @@
</rd-header-title>
<rd-header-content>Templates</rd-header-content>
</rd-header>
<div id="selectedTemplate" class="row" ng-if="state.selectedTemplate">
<div class="col-lg-12 col-md-12 col-xs-12">
<div class="row" style="height: 90%">
<div class="col-sm-12" ng-if="state.selectedTemplate">
<rd-widget>
<rd-widget-custom-header icon="state.selectedTemplate.Logo" title="state.selectedTemplate.Image">
<div class="pull-right">
<button type="button" class="btn btn-sm btn-primary" ng-click="unselectTemplate()">Hide</button>
</div>
</rd-widget-custom-header>
<rd-widget-body classes="padding">
<form class="form-horizontal">
<!-- description -->
<div class="form-group" ng-if="state.selectedTemplate.Note">
<div class="col-sm-12">
<span class="small" style="margin-left: 5px;" ng-bind-html="state.selectedTemplate.Note"></span>
<div ng-if="state.selectedTemplate.Note">
<div class="col-sm-12 form-section-title">
Information
</div>
<div class="form-group">
<div class="col-sm-12">
<span class="template-note" ng-bind-html="state.selectedTemplate.Note"></span>
</div>
</div>
</div>
<!-- !description -->
<!-- name-and-network-inputs -->
<div class="col-sm-12 form-section-title">
Configuration
</div>
<!-- name-input -->
<div class="form-group">
<label for="container_name" class="col-sm-1 control-label text-left">Name</label>
<div class="col-sm-5">
<label for="container_name" class="col-sm-2 control-label text-left">Name</label>
<div class="col-sm-10">
<input type="text" name="container_name" class="form-control" ng-model="formValues.name" placeholder="e.g. web (optional)">
</div>
<label for="container_network" class="col-sm-2 col-lg-1 control-label text-right">Network</label>
<div class="col-sm-4 col-lg-5">
</div>
<!-- !name-input -->
<!-- network-input -->
<div class="form-group">
<label for="container_network" class="col-sm-2 control-label text-left">Network</label>
<div class="col-sm-10">
<select class="form-control" ng-options="net.Name for net in availableNetworks" ng-model="formValues.network">
<option disabled hidden value="">Select a network</option>
</select>
</div>
</div>
<!-- !name-and-network-inputs -->
<!-- !network-input -->
<!-- env -->
<div ng-repeat="var in state.selectedTemplate.Env" ng-if="!var.set" class="form-group">
<label for="field_{{ $index }}" class="col-sm-2 control-label text-left">{{ var.label }}</label>
@ -63,6 +81,7 @@
</div>
</div>
<!-- !ownership -->
<!-- advanced-options -->
<div class="form-group">
<div class="col-sm-12">
<a class="small interactive" ng-if="!state.showAdvancedOptions" ng-click="state.showAdvancedOptions = true;">
@ -73,7 +92,6 @@
</a>
</div>
</div>
<!-- advanced-options -->
<div ng-if="state.showAdvancedOptions">
<!-- port-mapping -->
<div class="form-group" >
@ -120,7 +138,6 @@
</div>
</div>
</div>
</div>
<!-- !port-mapping-input-list -->
<!-- volume-mapping -->
@ -192,6 +209,7 @@
<!-- !volume-mapping -->
</div>
<!-- !advanced-options -->
<!-- actions -->
<div class="form-group">
<div class="col-sm-12">
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!formValues.network" ng-click="createTemplate()">Create</button>
@ -205,45 +223,90 @@
</span>
</div>
</div>
<!-- !actions -->
</form>
</rd-widget-body>
</rd-widget>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12">
<rd-widget>
<rd-widget-header icon="fa-rocket" title="Available templates">
<div class="pull-right">
Items per page:
<select ng-model="state.pagination_count" ng-change="changePaginationCount()">
<option value="0">All</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<div class="col-sm-12" style="height: 100%">
<rd-template-widget>
<rd-widget-header icon="fa-rocket" title="Templates">
<div ng-if="availableCategories.length > 0" class="pull-right">
Category
<select ng-model="state.filters.Categories">
<option value="!">All</option>
<option ng-repeat="category in availableCategories" value="{{ category }}">{{ category }}</option>
</select>
</div>
</rd-widget-header>
<rd-widget-body classes="padding">
<rd-widget-taskbar>
<div>
<!-- Platform -->
<span class="btn-group btn-group-sm" style="margin-right: 15px;">
<label class="btn btn-primary" ng-model="state.filters.Platform" uib-btn-radio="'!'">
All
</label>
<label class="btn btn-primary" ng-model="state.filters.Platform" uib-btn-radio="'windows'">
<i class="fa fa-windows" aria-hidden="true"></i>
Windows
</label>
<label class="btn btn-primary" ng-model="state.filters.Platform" uib-btn-radio="'linux'">
<i class="fa fa-linux" aria-hidden="true"></i>
Linux
</label>
</span>
</div>
</rd-widget-taskbar>
<rd-widget-body classes="padding template-widget-body">
<div class="template-list">
<div dir-paginate="tpl in templates | itemsPerPage: state.pagination_count" class="container-template hvr-underline-from-center" id="template_{{ tpl.index }}" ng-click="selectTemplate(tpl.index)">
<img class="logo" ng-src="{{ tpl.Logo }}" />
<div class="title">{{ tpl.Title }}</div>
<div class="description" ng-if="tpl.Description && !state.hideDescriptions">{{ tpl.Description }}</div>
<!-- template -->
<div dir-paginate="tpl in templates | filter:state.filters:true | itemsPerPage: state.pagination_count" class="template-container" id="template_{{ tpl.index }}" ng-click="selectTemplate(tpl.index, $index)">
<div class="template-main">
<!-- template-image -->
<span class="">
<img class="template-logo" ng-src="{{ tpl.Logo }}" />
</span>
<!-- !template-image -->
<!-- template-details -->
<span class="col-sm-12">
<!-- template-line1 -->
<div class="template-line">
<span class="template-title">
{{ tpl.Title }}
</span>
<span>
<i class="fa fa-windows" aria-hidden="true" ng-if="tpl.Platform === 'windows'"></i>
<i class="fa fa-linux" aria-hidden="true" ng-if="tpl.Platform === 'linux'"></i>
<!-- Arch / Platform -->
</span>
</div>
<!-- !template-line1 -->
<!-- template-line2 -->
<div class="template-line">
<span class="template-description">
{{ tpl.Description }}
</span>
<span class="small text-muted" ng-if="tpl.Categories.length > 0">
{{ tpl.Categories.join(', ') }}
</span>
</div>
<!-- !template-line2 -->
</span>
<!-- !template-details -->
</div>
<!-- !template -->
</div>
<div ng-if="!templates" class="text-center text-muted">
Loading...
</div>
<div ng-if="templates.length == 0" class="text-center text-muted">
<div ng-if="(templates | filter:state.filters:true | itemsPerPage: state.pagination_count).length == 0" class="text-center text-muted">
No templates available.
</div>
</div>
<div ng-if="templates">
<dir-pagination-controls></dir-pagination-controls>
</div>
</rd-widget-body>
</rd-widget>
</rd-template-widget>
</div>
</div>

View file

@ -1,16 +1,20 @@
angular.module('templates', [])
.controller('TemplatesController', ['$scope', '$q', '$state', '$stateParams', '$anchorScroll', 'Config', 'ContainerService', 'ContainerHelper', 'ImageService', 'NetworkService', 'TemplateService', 'TemplateHelper', 'VolumeService', 'Notifications', 'Pagination', 'ResourceControlService', 'Authentication',
function ($scope, $q, $state, $stateParams, $anchorScroll, Config, ContainerService, ContainerHelper, ImageService, NetworkService, TemplateService, TemplateHelper, VolumeService, Notifications, Pagination, ResourceControlService, Authentication) {
.controller('TemplatesController', ['$scope', '$q', '$state', '$stateParams', '$anchorScroll', '$filter', 'Config', 'ContainerService', 'ContainerHelper', 'ImageService', 'NetworkService', 'TemplateService', 'TemplateHelper', 'VolumeService', 'Notifications', 'Pagination', 'ResourceControlService', 'Authentication',
function ($scope, $q, $state, $stateParams, $anchorScroll, $filter, Config, ContainerService, ContainerHelper, ImageService, NetworkService, TemplateService, TemplateHelper, VolumeService, Notifications, Pagination, ResourceControlService, Authentication) {
$scope.state = {
selectedTemplate: null,
showAdvancedOptions: false,
hideDescriptions: $stateParams.hide_descriptions,
pagination_count: Pagination.getPaginationCount('templates')
pagination_count: Pagination.getPaginationCount('templates'),
filters: {
Categories: '!',
Platform: '!'
}
};
$scope.formValues = {
Ownership: $scope.applicationState.application.authentication ? 'private' : '',
network: "",
name: "",
network: '',
name: ''
};
$scope.changePaginationCount = function() {
@ -74,32 +78,38 @@ function ($scope, $q, $state, $stateParams, $anchorScroll, Config, ContainerServ
});
};
var selectedItem = -1;
$scope.selectTemplate = function(idx) {
$('#template_' + idx).toggleClass("container-template--selected");
if (selectedItem === idx) {
unselectTemplate();
$scope.unselectTemplate = function() {
var currentTemplateIndex = $scope.state.selectedTemplate.index;
$('#template_' + currentTemplateIndex).toggleClass('template-container--selected');
$scope.state.selectedTemplate = null;
};
$scope.selectTemplate = function(index, pos) {
if ($scope.state.selectedTemplate && $scope.state.selectedTemplate.index !== index) {
$scope.unselectTemplate();
}
var templates = $filter('filter')($scope.templates, $scope.state.filters, true);
var template = templates[pos];
if (template === $scope.state.selectedTemplate) {
$scope.unselectTemplate();
} else {
selectTemplate(idx);
selectTemplate(index, pos, templates);
}
};
function unselectTemplate() {
selectedItem = -1;
$scope.state.selectedTemplate = null;
}
function selectTemplate(idx) {
$('#template_' + selectedItem).toggleClass("container-template--selected");
selectedItem = idx;
var selectedTemplate = $scope.templates[idx];
function selectTemplate(index, pos, filteredTemplates) {
$('#template_' + index).toggleClass('template-container--selected');
var selectedTemplate = filteredTemplates[pos];
$scope.state.selectedTemplate = selectedTemplate;
if (selectedTemplate.Network) {
$scope.formValues.network = _.find($scope.availableNetworks, function(o) { return o.Name === selectedTemplate.Network; });
} else {
$scope.formValues.network = _.find($scope.availableNetworks, function(o) { return o.Name === "bridge"; });
$scope.formValues.network = _.find($scope.availableNetworks, function(o) { return o.Name === 'bridge'; });
}
$anchorScroll('selectedTemplate');
$anchorScroll('view-top');
}
function createTemplateConfiguration(template) {
@ -114,7 +124,7 @@ function ($scope, $q, $state, $stateParams, $anchorScroll, Config, ContainerServ
var containerMapping = 'BY_CONTAINER_IP';
if (endpointProvider === 'DOCKER_SWARM' && network.Scope === 'global') {
containerMapping = 'BY_SWARM_CONTAINER_NAME';
} else if (network.Name !== "bridge") {
} else if (network.Name !== 'bridge') {
containerMapping = 'BY_CONTAINER_NAME';
}
return containerMapping;
@ -144,18 +154,19 @@ function ($scope, $q, $state, $stateParams, $anchorScroll, Config, ContainerServ
volumes: VolumeService.getVolumes()
})
.then(function success(data) {
var templates = data.templates;
if (templatesKey === 'linuxserver.io') {
templates = TemplateService.filterLinuxServerIOTemplates(templates);
}
$scope.templates = templates;
$scope.templates = data.templates;
var availableCategories = [];
angular.forEach($scope.templates, function(template) {
availableCategories = availableCategories.concat(template.Categories);
});
$scope.availableCategories = _.sortBy(_.uniq(availableCategories));
$scope.runningContainers = data.containers;
$scope.availableNetworks = filterNetworksBasedOnProvider(data.networks);
$scope.availableVolumes = data.volumes.Volumes;
})
.catch(function error(err) {
$scope.templates = [];
Notifications.error("Failure", err, "An error occured during apps initialization.");
Notifications.error('Failure', err, 'An error occured during apps initialization.');
})
.finally(function final(){
$('#loadTemplatesSpinner').hide();