mirror of https://github.com/portainer/portainer
feat(templates): support templates versioning (#3729)
* feat(templates): Support templates versioning format * Update app/portainer/models/template.js Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io>pull/3802/head
parent
d765af143d
commit
49391623b8
|
@ -1,32 +1,44 @@
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
|
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
|
||||||
|
|
||||||
export function TemplateViewModel(data) {
|
export class TemplateViewModel {
|
||||||
this.Id = data.Id;
|
constructor(data, version) {
|
||||||
this.Title = data.title;
|
switch (version) {
|
||||||
this.Type = data.type;
|
case '2':
|
||||||
this.Description = data.description;
|
this.setTemplatesV2(data);
|
||||||
this.AdministratorOnly = data.AdministratorOnly;
|
break;
|
||||||
this.Name = data.name;
|
default:
|
||||||
this.Note = data.note;
|
throw new Error('Unsupported template version');
|
||||||
this.Categories = data.categories ? data.categories : [];
|
}
|
||||||
this.Platform = data.platform ? data.platform : '';
|
}
|
||||||
this.Logo = data.logo;
|
|
||||||
this.Repository = data.repository;
|
setTemplatesV2(data) {
|
||||||
this.Hostname = data.hostname;
|
this.Id = data.Id;
|
||||||
this.RegistryModel = new PorImageRegistryModel();
|
this.Title = data.title;
|
||||||
this.RegistryModel.Image = data.image;
|
this.Type = data.type;
|
||||||
this.RegistryModel.Registry.URL = data.registry || '';
|
this.Description = data.description;
|
||||||
this.Command = data.command ? data.command : '';
|
this.AdministratorOnly = data.AdministratorOnly;
|
||||||
this.Network = data.network ? data.network : '';
|
this.Name = data.name;
|
||||||
this.Privileged = data.privileged ? data.privileged : false;
|
this.Note = data.note;
|
||||||
this.Interactive = data.interactive ? data.interactive : false;
|
this.Categories = data.categories ? data.categories : [];
|
||||||
this.RestartPolicy = data.restart_policy ? data.restart_policy : 'always';
|
this.Platform = data.platform ? data.platform : '';
|
||||||
this.Labels = data.labels ? data.labels : [];
|
this.Logo = data.logo;
|
||||||
this.Hosts = data.hosts ? data.hosts : [];
|
this.Repository = data.repository;
|
||||||
this.Env = templateEnv(data);
|
this.Hostname = data.hostname;
|
||||||
this.Volumes = templateVolumes(data);
|
this.RegistryModel = new PorImageRegistryModel();
|
||||||
this.Ports = templatePorts(data);
|
this.RegistryModel.Image = data.image;
|
||||||
|
this.RegistryModel.Registry.URL = data.registry || '';
|
||||||
|
this.Command = data.command ? data.command : '';
|
||||||
|
this.Network = data.network ? data.network : '';
|
||||||
|
this.Privileged = data.privileged ? data.privileged : false;
|
||||||
|
this.Interactive = data.interactive ? data.interactive : false;
|
||||||
|
this.RestartPolicy = data.restart_policy ? data.restart_policy : 'always';
|
||||||
|
this.Labels = data.labels ? data.labels : [];
|
||||||
|
this.Hosts = data.hosts ? data.hosts : [];
|
||||||
|
this.Env = templateEnv(data);
|
||||||
|
this.Volumes = templateVolumes(data);
|
||||||
|
this.Ports = templatePorts(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function templatePorts(data) {
|
function templatePorts(data) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import _ from 'lodash-es';
|
||||||
import { TemplateViewModel } from '../../models/template';
|
import { TemplateViewModel } from '../../models/template';
|
||||||
|
|
||||||
angular.module('portainer.app').factory('TemplateService', [
|
angular.module('portainer.app').factory('TemplateService', [
|
||||||
|
@ -13,7 +14,7 @@ angular.module('portainer.app').factory('TemplateService', [
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
service.templates = function () {
|
service.templates = function () {
|
||||||
var deferred = $q.defer();
|
const deferred = $q.defer();
|
||||||
|
|
||||||
$q.all({
|
$q.all({
|
||||||
templates: Templates.query().$promise,
|
templates: Templates.query().$promise,
|
||||||
|
@ -21,12 +22,17 @@ angular.module('portainer.app').factory('TemplateService', [
|
||||||
dockerhub: DockerHubService.dockerhub(),
|
dockerhub: DockerHubService.dockerhub(),
|
||||||
})
|
})
|
||||||
.then(function success(data) {
|
.then(function success(data) {
|
||||||
const templates = data.templates.templates.map(function (item) {
|
const version = data.templates.version;
|
||||||
const res = new TemplateViewModel(item);
|
const templates = _.map(data.templates.templates, (item) => {
|
||||||
const registry = RegistryService.retrievePorRegistryModelFromRepositoryWithRegistries(res.RegistryModel.Registry.URL, data.registries, data.dockerhub);
|
try {
|
||||||
registry.Image = res.RegistryModel.Image;
|
const template = new TemplateViewModel(item, version);
|
||||||
res.RegistryModel = registry;
|
const registry = RegistryService.retrievePorRegistryModelFromRepositoryWithRegistries(template.RegistryModel.Registry.URL, data.registries, data.dockerhub);
|
||||||
return res;
|
registry.Image = template.RegistryModel.Image;
|
||||||
|
template.RegistryModel = registry;
|
||||||
|
return template;
|
||||||
|
} catch (err) {
|
||||||
|
deferred.reject({ msg: 'Unable to retrieve templates', err: err });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
deferred.resolve(templates);
|
deferred.resolve(templates);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue